OpenTTD Source: src/timetable_cmd.cpp Source File

OpenTTD Source 13.2.1

timetable_cmd.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "command_func.h"
12 #include "company_func.h"
13 #include "date_func.h"
14 #include "window_func.h"
15 #include "vehicle_base.h"
16 #include "timetable_cmd.h"
17
18 #include "table/strings.h"
19
20 #include "safeguards.h"
21
30 static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val, ModifyTimetableFlags mtf, bool timetabled)
31 {
32 Order *order = v->GetOrder(order_number);
33 int total_delta = 0;
34 int timetable_delta = 0;
35
36 switch (mtf) {
37 case MTF_WAIT_TIME:
38 total_delta = val - order->GetWaitTime();
39 timetable_delta = (timetabled ? val : 0) - order->GetTimetabledWait();
40 order->SetWaitTime(val);
41 order->SetWaitTimetabled(timetabled);
42 break;
43
44 case MTF_TRAVEL_TIME:
45 total_delta = val - order->GetTravelTime();
46 timetable_delta = (timetabled ? val : 0) - order->GetTimetabledTravel();
47 order->SetTravelTime(val);
48 order->SetTravelTimetabled(timetabled);
49 break;
50
51 case MTF_TRAVEL_SPEED:
52 order->SetMaxSpeed(val);
53 break;
54
55 default:
56 NOT_REACHED();
57 }
58 v->orders->UpdateTotalDuration(total_delta);
59 v->orders->UpdateTimetableDuration(timetable_delta);
60
61 for (v = v->FirstShared(); v != nullptr; v = v->NextShared()) {
62 if (v->cur_real_order_index == order_number && v->current_order.Equals(*order)) {
63 switch (mtf) {
64 case MTF_WAIT_TIME:
65 v->current_order.SetWaitTime(val);
66 v->current_order.SetWaitTimetabled(timetabled);
67 break;
68
69 case MTF_TRAVEL_TIME:
70 v->current_order.SetTravelTime(val);
71 v->current_order.SetTravelTimetabled(timetabled);
72 break;
73
74 case MTF_TRAVEL_SPEED:
75 v->current_order.SetMaxSpeed(val);
76 break;
77
78 default:
79 NOT_REACHED();
80 }
81 }
82 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
83 }
84 }
85
96 CommandCost CmdChangeTimetable(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, ModifyTimetableFlags mtf, uint16 data)
97 {
98 Vehicle *v = Vehicle::GetIfValid(veh);
99 if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
100
101 CommandCost ret = CheckOwnership(v->owner);
102 if (ret.Failed()) return ret;
103
104 Order *order = v->GetOrder(order_number);
105 if (order == nullptr || order->IsType(OT_IMPLICIT)) return CMD_ERROR;
106
107 if (mtf >= MTF_END) return CMD_ERROR;
108
109 int wait_time = order->GetWaitTime();
110 int travel_time = order->GetTravelTime();
111 int max_speed = order->GetMaxSpeed();
112 switch (mtf) {
113 case MTF_WAIT_TIME:
114 wait_time = data;
115 break;
116
117 case MTF_TRAVEL_TIME:
118 travel_time = data;
119 break;
120
121 case MTF_TRAVEL_SPEED:
122 max_speed = data;
123 if (max_speed == 0) max_speed = UINT16_MAX; // Disable speed limit.
124 break;
125
126 default:
127 NOT_REACHED();
128 }
129
130 if (wait_time != order->GetWaitTime()) {
131 switch (order->GetType()) {
132 case OT_GOTO_STATION:
133 if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return_cmd_error(STR_ERROR_TIMETABLE_NOT_STOPPING_HERE);
134 break;
135
136 case OT_CONDITIONAL:
137 break;
138
139 default: return_cmd_error(STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
140 }
141 }
142
143 if (travel_time != order->GetTravelTime() && order->IsType(OT_CONDITIONAL)) return CMD_ERROR;
144 if (max_speed != order->GetMaxSpeed() && (order->IsType(OT_CONDITIONAL) || v->type == VEH_AIRCRAFT)) return CMD_ERROR;
145
146 if (flags & DC_EXEC) {
147 switch (mtf) {
148 case MTF_WAIT_TIME:
149 /* Set time if changing the value or confirming an estimated time as timetabled. */
150 if (wait_time != order->GetWaitTime() || (wait_time > 0 && !order->IsWaitTimetabled())) {
151 ChangeTimetable(v, order_number, wait_time, MTF_WAIT_TIME, wait_time > 0);
152 }
153 break;
154
155 case MTF_TRAVEL_TIME:
156 /* Set time if changing the value or confirming an estimated time as timetabled. */
157 if (travel_time != order->GetTravelTime() || (travel_time > 0 && !order->IsTravelTimetabled())) {
158 ChangeTimetable(v, order_number, travel_time, MTF_TRAVEL_TIME, travel_time > 0);
159 }
160 break;
161
162 case MTF_TRAVEL_SPEED:
163 if (max_speed != order->GetMaxSpeed()) {
164 ChangeTimetable(v, order_number, max_speed, MTF_TRAVEL_SPEED, max_speed != UINT16_MAX);
165 }
166 break;
167
168 default:
169 break;
170 }
171 }
172
173 return CommandCost();
174 }
175
185 CommandCost CmdBulkChangeTimetable(DoCommandFlag flags, VehicleID veh, ModifyTimetableFlags mtf, uint16 data)
186 {
187 Vehicle *v = Vehicle::GetIfValid(veh);
188 if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
189
190 CommandCost ret = CheckOwnership(v->owner);
191 if (ret.Failed()) return ret;
192
193 if (mtf >= MTF_END) return CMD_ERROR;
194
195 if (v->GetNumOrders() == 0) return CMD_ERROR;
196
197 if (flags & DC_EXEC) {
198 for (VehicleOrderID order_number = 0; order_number < v->GetNumOrders(); order_number++) {
199 Order *order = v->GetOrder(order_number);
200 if (order == nullptr || order->IsType(OT_IMPLICIT)) continue;
201
202 Command<CMD_CHANGE_TIMETABLE>::Do(DC_EXEC, v->index, order_number, mtf, data);
203 }
204 }
205
206 return CommandCost();
207 }
208
215 CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh)
216 {
217 Vehicle *v = Vehicle::GetIfValid(veh);
218 if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
219
220 CommandCost ret = CheckOwnership(v->owner);
221 if (ret.Failed()) return ret;
222
223 if (flags & DC_EXEC) {
224 v->lateness_counter = 0;
225 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
226 }
227
228 return CommandCost();
229 }
230
239 static bool VehicleTimetableSorter(Vehicle * const &a, Vehicle * const &b)
240 {
241 VehicleOrderID a_order = a->cur_real_order_index;
242 VehicleOrderID b_order = b->cur_real_order_index;
243 int j = (int)b_order - (int)a_order;
244
245 /* Are we currently at an ordered station (un)loading? */
246 bool a_load = a->current_order.IsType(OT_LOADING) && a->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE;
247 bool b_load = b->current_order.IsType(OT_LOADING) && b->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE;
248
249 /* If the current order is not loading at the ordered station, decrease the order index by one since we have
250 * not yet arrived at the station (and thus the timetable entry; still in the travelling of the previous one).
251 * Since the ?_order variables are unsigned the -1 will flow under and place the vehicles going to order #0 at
252 * the begin of the list with vehicles arriving at #0. */
253 if (!a_load) a_order--;
254 if (!b_load) b_order--;
255
256 /* First check the order index that accounted for loading, then just the raw one. */
257 int i = (int)b_order - (int)a_order;
258 if (i != 0) return i < 0;
259 if (j != 0) return j < 0;
260
261 /* Look at the time we spent in this order; the higher, the closer to its destination. */
262 i = b->current_order_time - a->current_order_time;
263 if (i != 0) return i < 0;
264
265 /* If all else is equal, use some unique index to sort it the same way. */
266 return b->unitnumber < a->unitnumber;
267 }
268
277 CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, Date start_date)
278 {
279 Vehicle *v = Vehicle::GetIfValid(veh_id);
280 if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
281
282 CommandCost ret = CheckOwnership(v->owner);
283 if (ret.Failed()) return ret;
284
285 int total_duration = v->orders->GetTimetableTotalDuration();
286
287 /* Don't let a timetable start more than 15 years into the future or 1 year in the past. */
288 if (start_date < 0 || start_date > MAX_DAY) return CMD_ERROR;
289 if (start_date - _date > 15 * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
290 if (_date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR;
291 if (timetable_all && !v->orders->IsCompleteTimetable()) return CommandCost(STR_ERROR_TIMETABLE_INCOMPLETE);
292 if (timetable_all && start_date + total_duration / DAY_TICKS > MAX_DAY) return CMD_ERROR;
293
294 if (flags & DC_EXEC) {
295 std::vector<Vehicle *> vehs;
296
297 if (timetable_all) {
298 for (Vehicle *w = v->orders->GetFirstSharedVehicle(); w != nullptr; w = w->NextShared()) {
299 vehs.push_back(w);
300 }
301 } else {
302 vehs.push_back(v);
303 }
304
305 int num_vehs = (uint)vehs.size();
306
307 if (num_vehs >= 2) {
308 std::sort(vehs.begin(), vehs.end(), &VehicleTimetableSorter);
309 }
310
311 int idx = 0;
312
313 for (Vehicle *w : vehs) {
314
315 w->lateness_counter = 0;
316 ClrBit(w->vehicle_flags, VF_TIMETABLE_STARTED);
317 /* Do multiplication, then division to reduce rounding errors. */
318 w->timetable_start = start_date + idx * total_duration / num_vehs / DAY_TICKS;
319 SetWindowDirty(WC_VEHICLE_TIMETABLE, w->index);
320 ++idx;
321 }
322
323 }
324
325 return CommandCost();
326 }
327
328
339 CommandCost CmdAutofillTimetable(DoCommandFlag flags, VehicleID veh, bool autofill, bool preserve_wait_time)
340 {
341 Vehicle *v = Vehicle::GetIfValid(veh);
342 if (v == nullptr || !v->IsPrimaryVehicle() || v->orders == nullptr) return CMD_ERROR;
343
344 CommandCost ret = CheckOwnership(v->owner);
345 if (ret.Failed()) return ret;
346
347 if (flags & DC_EXEC) {
348 if (autofill) {
349 /* Start autofilling the timetable, which clears the
350 * "timetable has started" bit. Times are not cleared anymore, but are
351 * overwritten when the order is reached now. */
352 SetBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
353 ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
354
355 /* Overwrite waiting times only if they got longer */
356 if (preserve_wait_time) SetBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
357
358 v->timetable_start = 0;
359 v->lateness_counter = 0;
360 } else {
361 ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
362 ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
363 }
364
365 for (Vehicle *v2 = v->FirstShared(); v2 != nullptr; v2 = v2->NextShared()) {
366 if (v2 != v) {
367 /* Stop autofilling; only one vehicle at a time can perform autofill */
368 ClrBit(v2->vehicle_flags, VF_AUTOFILL_TIMETABLE);
369 ClrBit(v2->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
370 }
371 SetWindowDirty(WC_VEHICLE_TIMETABLE, v2->index);
372 }
373 }
374
375 return CommandCost();
376 }
377
383 void UpdateVehicleTimetable(Vehicle *v, bool travelling)
384 {
385 uint time_taken = v->current_order_time;
386
387 v->current_order_time = 0;
388
389 if (v->current_order.IsType(OT_IMPLICIT)) return; // no timetabling of auto orders
390
391 if (v->cur_real_order_index >= v->GetNumOrders()) return;
392 Order *real_current_order = v->GetOrder(v->cur_real_order_index);
393
394 VehicleOrderID first_manual_order = 0;
395 for (Order *o = v->GetFirstOrder(); o != nullptr && o->IsType(OT_IMPLICIT); o = o->next) {
396 ++first_manual_order;
397 }
398
399 bool just_started = false;
400
401 /* This vehicle is arriving at the first destination in the timetable. */
402 if (v->cur_real_order_index == first_manual_order && travelling) {
403 /* If the start date hasn't been set, or it was set automatically when
404 * the vehicle last arrived at the first destination, update it to the
405 * current time. Otherwise set the late counter appropriately to when
406 * the vehicle should have arrived. */
407 just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
408
409 if (v->timetable_start != 0) {
410 v->lateness_counter = (_date - v->timetable_start) * DAY_TICKS + _date_fract;
411 v->timetable_start = 0;
412 }
413
414 SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
415 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
416 }
417
418 if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
419
420 bool autofilling = HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
421 bool remeasure_wait_time = !real_current_order->IsWaitTimetabled() ||
422 (autofilling && !HasBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME));
423
424 if (travelling && remeasure_wait_time) {
425 /* We just finished travelling and want to remeasure the loading time,
426 * so do not apply any restrictions for the loading to finish. */
427 v->current_order.SetWaitTime(0);
428 }
429
430 if (just_started) return;
431
432 /* Before modifying waiting times, check whether we want to preserve bigger ones. */
433 if (!real_current_order->IsType(OT_CONDITIONAL) &&
434 (travelling || time_taken > real_current_order->GetWaitTime() || remeasure_wait_time)) {
435 /* Round the time taken up to the nearest day, as this will avoid
436 * confusion for people who are timetabling in days, and can be
437 * adjusted later by people who aren't.
438 * For trains/aircraft multiple movement cycles are done in one
439 * tick. This makes it possible to leave the station and process
440 * e.g. a depot order in the same tick, causing it to not fill
441 * the timetable entry like is done for road vehicles/ships.
442 * Thus always make sure at least one tick is used between the
443 * processing of different orders when filling the timetable. */
444 uint time_to_set = CeilDiv(std::max(time_taken, 1U), DAY_TICKS) * DAY_TICKS;
445
446 if (travelling && (autofilling || !real_current_order->IsTravelTimetabled())) {
447 ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_TRAVEL_TIME, autofilling);
448 } else if (!travelling && (autofilling || !real_current_order->IsWaitTimetabled())) {
449 ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_WAIT_TIME, autofilling);
450 }
451 }
452
453 if (v->cur_real_order_index == first_manual_order && travelling) {
454 /* If we just started we would have returned earlier and have not reached
455 * this code. So obviously, we have completed our round: So turn autofill
456 * off again. */
457 ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
458 ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
459 }
460
461 if (autofilling) return;
462
463 uint timetabled = travelling ? real_current_order->GetTimetabledTravel() :
464 real_current_order->GetTimetabledWait();
465
466 /* Vehicles will wait at stations if they arrive early even if they are not
467 * timetabled to wait there, so make sure the lateness counter is updated
468 * when this happens. */
469 if (timetabled == 0 && (travelling || v->lateness_counter >= 0)) return;
470
471 v->lateness_counter -= (timetabled - time_taken);
472
473 /* When we are more late than this timetabled bit takes we (somewhat expensively)
474 * check how many ticks the (fully filled) timetable has. If a timetable cycle is
475 * shorter than the amount of ticks we are late we reduce the lateness by the
476 * length of a full cycle till lateness is less than the length of a timetable
477 * cycle. When the timetable isn't fully filled the cycle will be INVALID_TICKS. */
478 if (v->lateness_counter > (int)timetabled) {
479 Ticks cycle = v->orders->GetTimetableTotalDuration();
480 if (cycle != INVALID_TICKS && v->lateness_counter > cycle) {
481 v->lateness_counter %= cycle;
482 }
483 }
484
485 for (v = v->FirstShared(); v != nullptr; v = v->NextShared()) {
486 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
487 }
488 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
MTF_TRAVEL_SPEED
@ MTF_TRAVEL_SPEED
Set max travel speed.
Definition: order_type.h:173
CmdSetTimetableStart
CommandCost CmdSetTimetableStart(DoCommandFlag flags, VehicleID veh_id, bool timetable_all, Date start_date)
Set the start date of the timetable.
Definition: timetable_cmd.cpp:277
VehicleOrderID
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:15
Order::GetWaitTime
uint16 GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
Definition: order_base.h:193
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:71
Order::GetTimetabledWait
uint16 GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
Definition: order_base.h:189
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3156
command_func.h
MTF_WAIT_TIME
@ MTF_WAIT_TIME
Set wait time.
Definition: order_type.h:171
Pool::PoolItem<&_vehicle_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:348
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:28
ModifyTimetableFlags
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
Definition: order_type.h:170
OrderList::UpdateTimetableDuration
void UpdateTimetableDuration(Ticks delta)
Must be called if an order's timetable is changed to update internal book keeping.
Definition: order_base.h:392
_date_fract
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:29
Order::GetTimetabledTravel
uint16 GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
Definition: order_base.h:191
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
Order::SetTravelTimetabled
void SetTravelTimetabled(bool timetabled)
Set if the travel time is explicitly timetabled (unless the order is conditional).
Definition: order_base.h:207
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
vehicle_base.h
OrderList::IsCompleteTimetable
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
Definition: order_cmd.cpp:603
WC_VEHICLE_TIMETABLE
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
Definition: window_type.h:217
MAX_DAY
#define MAX_DAY
The number of days till the last day.
Definition: date_type.h:98
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:224
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:460
OrderList::GetTimetableTotalDuration
Ticks GetTimetableTotalDuration() const
Gets the total duration of the vehicles timetable or INVALID_TICKS is the timetable is not complete.
Definition: order_base.h:374
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:288
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:357
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:355
Order::GetType
OrderType GetType() const
Get the type of order of this order.
Definition: order_base.h:77
Order::GetMaxSpeed
uint16 GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
Definition: order_base.h:202
VehicleTimetableSorter
static bool VehicleTimetableSorter(Vehicle *const &a, Vehicle *const &b)
Order vehicles based on their timetable.
Definition: timetable_cmd.cpp:239
timetable_cmd.h
VF_AUTOFILL_TIMETABLE
@ VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
Definition: vehicle_base.h:50
Order::GetNonStopType
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:141
ChangeTimetable
static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val, ModifyTimetableFlags mtf, bool timetabled)
Change/update a particular timetable entry.
Definition: timetable_cmd.cpp:30
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:316
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:38
CommandCost
Common return value for all commands.
Definition: command_type.h:24
ONSF_STOP_EVERYWHERE
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
Definition: order_type.h:73
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
OrderList::GetFirstSharedVehicle
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
Definition: order_base.h:347
Order::GetTravelTime
uint16 GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
Definition: order_base.h:195
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:160
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:333
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
CmdSetVehicleOnTime
CommandCost CmdSetVehicleOnTime(DoCommandFlag flags, VehicleID veh)
Clear the lateness counter to make the vehicle on time.
Definition: timetable_cmd.cpp:215
CmdBulkChangeTimetable
CommandCost CmdBulkChangeTimetable(DoCommandFlag flags, VehicleID veh, ModifyTimetableFlags mtf, uint16 data)
Change timetable data of all orders of a vehicle.
Definition: timetable_cmd.cpp:185
safeguards.h
Order::SetTravelTime
void SetTravelTime(uint16 time)
Set the time in ticks to take for travelling to the destination.
Definition: order_base.h:219
Ticks
int32 Ticks
The type to store ticks in.
Definition: date_type.h:16
UpdateVehicleTimetable
void UpdateVehicleTimetable(Vehicle *v, bool travelling)
Update the timetable for the vehicle.
Definition: timetable_cmd.cpp:383
CmdChangeTimetable
CommandCost CmdChangeTimetable(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, ModifyTimetableFlags mtf, uint16 data)
Change timetable data of an order.
Definition: timetable_cmd.cpp:96
DAYS_IN_LEAP_YEAR
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Definition: date_type.h:30
date_func.h
stdafx.h
BaseConsist::vehicle_flags
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:31
INVALID_TICKS
static const Ticks INVALID_TICKS
Representation of an invalid number of ticks.
Definition: date_type.h:112
Order::IsTravelTimetabled
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
Definition: order_base.h:186
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:28
ONSF_NO_STOP_AT_DESTINATION_STATION
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
Definition: order_type.h:75
OrderList::UpdateTotalDuration
void UpdateTotalDuration(Ticks delta)
Must be called if an order's timetable is changed to update internal book keeping.
Definition: order_base.h:398
Vehicle::FirstShared
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:704
CmdAutofillTimetable
CommandCost CmdAutofillTimetable(DoCommandFlag flags, VehicleID veh, bool autofill, bool preserve_wait_time)
Start or stop filling the timetable automatically from the time the vehicle actually takes to complet...
Definition: timetable_cmd.cpp:339
BaseConsist::lateness_counter
int32 lateness_counter
How many ticks late (or early if negative) this vehicle is.
Definition: base_consist.h:23
Vehicle::GetFirstOrder
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition: vehicle_base.h:683
BaseConsist::current_order_time
uint32 current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:22
Vehicle::NextShared
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:692
BaseConsist::timetable_start
Date timetable_start
When the vehicle is supposed to start the timetable.
Definition: base_consist.h:24
Order::SetWaitTime
void SetWaitTime(uint16 time)
Set the time in ticks to wait at the destination.
Definition: order_base.h:213
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:305
company_func.h
VF_AUTOFILL_PRES_WAIT_TIME
@ VF_AUTOFILL_PRES_WAIT_TIME
Whether non-destructive auto-fill should preserve waiting times.
Definition: vehicle_base.h:51
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
VF_TIMETABLE_STARTED
@ VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Definition: vehicle_base.h:49
CommandHelper
Definition: command_func.h:94
window_func.h
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:280
Order::SetMaxSpeed
void SetMaxSpeed(uint16 speed)
Set the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
Definition: order_base.h:226
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
Vehicle::GetOrder
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Definition: vehicle_base.h:890
Vehicle::GetNumOrders
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:716
Vehicle::orders
OrderList * orders
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:336
Order
Definition: order_base.h:36
DAY_TICKS
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:28
Order::Equals
bool Equals(const Order &other) const
Does this order have the same type, flags and destination?
Definition: order_cmd.cpp:175
Order::IsWaitTimetabled
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition: order_base.h:184
MTF_TRAVEL_TIME
@ MTF_TRAVEL_TIME
Set travel time.
Definition: order_type.h:172
Order::SetWaitTimetabled
void SetWaitTimetabled(bool timetabled)
Set if the wait time is explicitly timetabled (unless the order is conditional).
Definition: order_base.h:205