OpenTTD

timetable_cmd.cpp
Go to the documentation of this file.
1 /* $Id: timetable_cmd.cpp 27302 2015-06-20 12:04:30Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #include "stdafx.h"
13 #include "command_func.h"
14 #include "company_func.h"
15 #include "date_func.h"
16 #include "window_func.h"
17 #include "vehicle_base.h"
18 #include "cmd_helper.h"
19 #include "core/sort_func.hpp"
20
21 #include "table/strings.h"
22
23 #include "safeguards.h"
24
33 static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 val, ModifyTimetableFlags mtf, bool timetabled)
34 {
35 Order *order = v->GetOrder(order_number);
36 int total_delta = 0;
37 int timetable_delta = 0;
38
39 switch (mtf) {
40 case MTF_WAIT_TIME:
41 total_delta = val - order->GetWaitTime();
42 timetable_delta = (timetabled ? val : 0) - order->GetTimetabledWait();
43 order->SetWaitTime(val);
44 order->SetWaitTimetabled(timetabled);
45 break;
46
47 case MTF_TRAVEL_TIME:
48 total_delta = val - order->GetTravelTime();
49 timetable_delta = (timetabled ? val : 0) - order->GetTimetabledTravel();
50 order->SetTravelTime(val);
51 order->SetTravelTimetabled(timetabled);
52 break;
53
54 case MTF_TRAVEL_SPEED:
55 order->SetMaxSpeed(val);
56 break;
57
58 default:
59 NOT_REACHED();
60 }
61 v->orders.list->UpdateTotalDuration(total_delta);
62 v->orders.list->UpdateTimetableDuration(timetable_delta);
63
64 for (v = v->FirstShared(); v != NULL; v = v->NextShared()) {
65 if (v->cur_real_order_index == order_number && v->current_order.Equals(*order)) {
66 switch (mtf) {
67 case MTF_WAIT_TIME:
68 v->current_order.SetWaitTime(val);
69 v->current_order.SetWaitTimetabled(timetabled);
70 break;
71
72 case MTF_TRAVEL_TIME:
73 v->current_order.SetTravelTime(val);
74 v->current_order.SetTravelTimetabled(timetabled);
75 break;
76
77 case MTF_TRAVEL_SPEED:
78 v->current_order.SetMaxSpeed(val);
79 break;
80
81 default:
82 NOT_REACHED();
83 }
84 }
85 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
86 }
87 }
88
103 CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
104 {
105 VehicleID veh = GB(p1, 0, 20);
106
107 Vehicle *v = Vehicle::GetIfValid(veh);
108 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
109
110 CommandCost ret = CheckOwnership(v->owner);
111 if (ret.Failed()) return ret;
112
113 VehicleOrderID order_number = GB(p1, 20, 8);
114 Order *order = v->GetOrder(order_number);
115 if (order == NULL || order->IsType(OT_IMPLICIT)) return CMD_ERROR;
116
117 ModifyTimetableFlags mtf = Extract<ModifyTimetableFlags, 28, 2>(p1);
118 if (mtf >= MTF_END) return CMD_ERROR;
119
120 int wait_time = order->GetWaitTime();
121 int travel_time = order->GetTravelTime();
122 int max_speed = order->GetMaxSpeed();
123 switch (mtf) {
124 case MTF_WAIT_TIME:
125 wait_time = GB(p2, 0, 16);
126 break;
127
128 case MTF_TRAVEL_TIME:
129 travel_time = GB(p2, 0, 16);
130 break;
131
132 case MTF_TRAVEL_SPEED:
133 max_speed = GB(p2, 0, 16);
134 if (max_speed == 0) max_speed = UINT16_MAX; // Disable speed limit.
135 break;
136
137 default:
138 NOT_REACHED();
139 }
140
141 if (wait_time != order->GetWaitTime()) {
142 switch (order->GetType()) {
143 case OT_GOTO_STATION:
144 if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return_cmd_error(STR_ERROR_TIMETABLE_NOT_STOPPING_HERE);
145 break;
146
147 case OT_CONDITIONAL:
148 break;
149
150 default: return_cmd_error(STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
151 }
152 }
153
154 if (travel_time != order->GetTravelTime() && order->IsType(OT_CONDITIONAL)) return CMD_ERROR;
155 if (max_speed != order->GetMaxSpeed() && (order->IsType(OT_CONDITIONAL) || v->type == VEH_AIRCRAFT)) return CMD_ERROR;
156
157 if (flags & DC_EXEC) {
158 switch (mtf) {
159 case MTF_WAIT_TIME:
160 /* Set time if changing the value or confirming an estimated time as timetabled. */
161 if (wait_time != order->GetWaitTime() || (wait_time > 0 && !order->IsWaitTimetabled())) {
162 ChangeTimetable(v, order_number, wait_time, MTF_WAIT_TIME, wait_time > 0);
163 }
164 break;
165
166 case MTF_TRAVEL_TIME:
167 /* Set time if changing the value or confirming an estimated time as timetabled. */
168 if (travel_time != order->GetTravelTime() || (travel_time > 0 && !order->IsTravelTimetabled())) {
169 ChangeTimetable(v, order_number, travel_time, MTF_TRAVEL_TIME, travel_time > 0);
170 }
171 break;
172
173 case MTF_TRAVEL_SPEED:
174 if (max_speed != order->GetMaxSpeed()) {
175 ChangeTimetable(v, order_number, max_speed, MTF_TRAVEL_SPEED, max_speed != UINT16_MAX);
176 }
177 break;
178
179 default:
180 break;
181 }
182 }
183
184 return CommandCost();
185 }
186
197 CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
198 {
199 VehicleID veh = GB(p1, 0, 20);
200
201 Vehicle *v = Vehicle::GetIfValid(veh);
202 if (v == NULL || !v->IsPrimaryVehicle() || v->orders.list == NULL) return CMD_ERROR;
203
204 CommandCost ret = CheckOwnership(v->owner);
205 if (ret.Failed()) return ret;
206
207 if (flags & DC_EXEC) {
208 v->lateness_counter = 0;
209 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
210 }
211
212 return CommandCost();
213 }
214
223 static int CDECL VehicleTimetableSorter(Vehicle * const *ap, Vehicle * const *bp)
224 {
225 const Vehicle *a = *ap;
226 const Vehicle *b = *bp;
227
228 VehicleOrderID a_order = a->cur_real_order_index;
229 VehicleOrderID b_order = b->cur_real_order_index;
230 int j = (int)b_order - (int)a_order;
231
232 /* Are we currently at an ordered station (un)loading? */
233 bool a_load = a->current_order.IsType(OT_LOADING) && a->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE;
234 bool b_load = b->current_order.IsType(OT_LOADING) && b->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE;
235
236 /* If the current order is not loading at the ordered station, decrease the order index by one since we have
237 * not yet arrived at the station (and thus the timetable entry; still in the travelling of the previous one).
238 * Since the ?_order variables are unsigned the -1 will flow under and place the vehicles going to order #0 at
239 * the begin of the list with vehicles arriving at #0. */
240 if (!a_load) a_order--;
241 if (!b_load) b_order--;
242
243 /* First check the order index that accounted for loading, then just the raw one. */
244 int i = (int)b_order - (int)a_order;
245 if (i != 0) return i;
246 if (j != 0) return j;
247
248 /* Look at the time we spent in this order; the higher, the closer to its destination. */
249 i = b->current_order_time - a->current_order_time;
250 if (i != 0) return i;
251
252 /* If all else is equal, use some unique index to sort it the same way. */
253 return b->unitnumber - a->unitnumber;
254 }
255
267 CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
268 {
269 bool timetable_all = HasBit(p1, 20);
270 Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20));
271 if (v == NULL || !v->IsPrimaryVehicle() || v->orders.list == NULL) return CMD_ERROR;
272
273 CommandCost ret = CheckOwnership(v->owner);
274 if (ret.Failed()) return ret;
275
276 /* Don't let a timetable start more than 15 years into the future or 1 year in the past. */
277 Date start_date = (Date)p2;
278 if (start_date < 0 || start_date > MAX_DAY) return CMD_ERROR;
279 if (start_date - _date > 15 * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
280 if (_date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR;
281 if (timetable_all && !v->orders.list->IsCompleteTimetable()) return CMD_ERROR;
282
283 if (flags & DC_EXEC) {
284 SmallVector<Vehicle *, 8> vehs;
285
286 if (timetable_all) {
287 for (Vehicle *w = v->orders.list->GetFirstSharedVehicle(); w != NULL; w = w->NextShared()) {
288 *vehs.Append() = w;
289 }
290 } else {
291 *vehs.Append() = v;
292 }
293
294 int total_duration = v->orders.list->GetTimetableTotalDuration();
295 int num_vehs = vehs.Length();
296
297 if (num_vehs >= 2) {
298 QSortT(vehs.Begin(), vehs.Length(), &VehicleTimetableSorter);
299 }
300
301 int base = vehs.FindIndex(v);
302
303 for (Vehicle **viter = vehs.Begin(); viter != vehs.End(); viter++) {
304 int idx = (viter - vehs.Begin()) - base;
305 Vehicle *w = *viter;
306
307 w->lateness_counter = 0;
308 ClrBit(w->vehicle_flags, VF_TIMETABLE_STARTED);
309 /* Do multiplication, then division to reduce rounding errors. */
310 w->timetable_start = start_date + idx * total_duration / num_vehs / DAY_TICKS;
311 SetWindowDirty(WC_VEHICLE_TIMETABLE, w->index);
312 }
313
314 }
315
316 return CommandCost();
317 }
318
319
333 CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
334 {
335 VehicleID veh = GB(p1, 0, 20);
336
337 Vehicle *v = Vehicle::GetIfValid(veh);
338 if (v == NULL || !v->IsPrimaryVehicle() || v->orders.list == NULL) return CMD_ERROR;
339
340 CommandCost ret = CheckOwnership(v->owner);
341 if (ret.Failed()) return ret;
342
343 if (flags & DC_EXEC) {
344 if (HasBit(p2, 0)) {
345 /* Start autofilling the timetable, which clears the
346 * "timetable has started" bit. Times are not cleared anymore, but are
347 * overwritten when the order is reached now. */
348 SetBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
349 ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
350
351 /* Overwrite waiting times only if they got longer */
352 if (HasBit(p2, 1)) SetBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
353
354 v->timetable_start = 0;
355 v->lateness_counter = 0;
356 } else {
357 ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
358 ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
359 }
360
361 for (Vehicle *v2 = v->FirstShared(); v2 != NULL; v2 = v2->NextShared()) {
362 if (v2 != v) {
363 /* Stop autofilling; only one vehicle at a time can perform autofill */
364 ClrBit(v2->vehicle_flags, VF_AUTOFILL_TIMETABLE);
365 ClrBit(v2->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
366 }
367 SetWindowDirty(WC_VEHICLE_TIMETABLE, v2->index);
368 }
369 }
370
371 return CommandCost();
372 }
373
379 void UpdateVehicleTimetable(Vehicle *v, bool travelling)
380 {
381 uint time_taken = v->current_order_time;
382
383 v->current_order_time = 0;
384
385 if (v->current_order.IsType(OT_IMPLICIT)) return; // no timetabling of auto orders
386
387 if (v->cur_real_order_index >= v->GetNumOrders()) return;
388 Order *real_current_order = v->GetOrder(v->cur_real_order_index);
389
390 VehicleOrderID first_manual_order = 0;
391 for (Order *o = v->GetFirstOrder(); o != NULL && o->IsType(OT_IMPLICIT); o = o->next) {
392 ++first_manual_order;
393 }
394
395 bool just_started = false;
396
397 /* This vehicle is arriving at the first destination in the timetable. */
398 if (v->cur_real_order_index == first_manual_order && travelling) {
399 /* If the start date hasn't been set, or it was set automatically when
400 * the vehicle last arrived at the first destination, update it to the
401 * current time. Otherwise set the late counter appropriately to when
402 * the vehicle should have arrived. */
403 just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
404
405 if (v->timetable_start != 0) {
406 v->lateness_counter = (_date - v->timetable_start) * DAY_TICKS + _date_fract;
407 v->timetable_start = 0;
408 }
409
410 SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
411 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
412 }
413
414 if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
415
416 bool autofilling = HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
417 bool remeasure_wait_time = !real_current_order->IsWaitTimetabled() ||
418 (autofilling && !HasBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME));
419
420 if (travelling && remeasure_wait_time) {
421 /* We just finished travelling and want to remeasure the loading time,
422 * so do not apply any restrictions for the loading to finish. */
423 v->current_order.SetWaitTime(0);
424 }
425
426 if (just_started) return;
427
428 /* Before modifying waiting times, check whether we want to preserve bigger ones. */
429 if (!real_current_order->IsType(OT_CONDITIONAL) &&
430 (travelling || time_taken > real_current_order->GetWaitTime() || remeasure_wait_time)) {
431 /* Round the time taken up to the nearest day, as this will avoid
432 * confusion for people who are timetabling in days, and can be
433 * adjusted later by people who aren't.
434 * For trains/aircraft multiple movement cycles are done in one
435 * tick. This makes it possible to leave the station and process
436 * e.g. a depot order in the same tick, causing it to not fill
437 * the timetable entry like is done for road vehicles/ships.
438 * Thus always make sure at least one tick is used between the
439 * processing of different orders when filling the timetable. */
440 uint time_to_set = CeilDiv(max(time_taken, 1U), DAY_TICKS) * DAY_TICKS;
441
442 if (travelling && (autofilling || !real_current_order->IsTravelTimetabled())) {
443 ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_TRAVEL_TIME, autofilling);
444 } else if (!travelling && (autofilling || !real_current_order->IsWaitTimetabled())) {
445 ChangeTimetable(v, v->cur_real_order_index, time_to_set, MTF_WAIT_TIME, autofilling);
446 }
447 }
448
449 if (v->cur_real_order_index == first_manual_order && travelling) {
450 /* If we just started we would have returned earlier and have not reached
451 * this code. So obviously, we have completed our round: So turn autofill
452 * off again. */
453 ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
454 ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
455 }
456
457 if (autofilling) return;
458
459 uint timetabled = travelling ? real_current_order->GetTimetabledTravel() :
460 real_current_order->GetTimetabledWait();
461
462 /* Vehicles will wait at stations if they arrive early even if they are not
463 * timetabled to wait there, so make sure the lateness counter is updated
464 * when this happens. */
465 if (timetabled == 0 && (travelling || v->lateness_counter >= 0)) return;
466
467 v->lateness_counter -= (timetabled - time_taken);
468
469 /* When we are more late than this timetabled bit takes we (somewhat expensively)
470 * check how many ticks the (fully filled) timetable has. If a timetable cycle is
471 * shorter than the amount of ticks we are late we reduce the lateness by the
472 * length of a full cycle till lateness is less than the length of a timetable
473 * cycle. When the timetable isn't fully filled the cycle will be INVALID_TICKS. */
474 if (v->lateness_counter > (int)timetabled) {
475 Ticks cycle = v->orders.list->GetTimetableTotalDuration();
476 if (cycle != INVALID_TICKS && v->lateness_counter > cycle) {
477 v->lateness_counter %= cycle;
478 }
479 }
480
481 for (v = v->FirstShared(); v != NULL; v = v->NextShared()) {
482 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
483 }
484 }
MTF_TRAVEL_SPEED
Set max travel speed.
Definition: order_type.h:178
VehicleTimetableSorter
static int CDECL VehicleTimetableSorter(Vehicle *const *ap, Vehicle *const *bp)
Order vehicles based on their timetable.
Definition: timetable_cmd.cpp:223
Pool::PoolItem<&_vehicle_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:257
MTF_WAIT_TIME
Set wait time.
Definition: order_type.h:176
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:187
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3120
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:364
VF_TIMETABLE_STARTED
Whether the vehicle has started running on the timetable yet.
Definition: vehicle_base.h:47
date_func.h
Functions related to dates.
OrderList::UpdateTimetableDuration
void UpdateTimetableDuration(Ticks delta)
Must be called if an order&#39;s timetable is changed to update internal book keeping.
Definition: order_base.h:382
Order::SetWaitTime
void SetWaitTime(uint16 time)
Set the time in ticks to wait at the destination.
Definition: order_base.h:205
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:123
INVALID_TICKS
static const Ticks INVALID_TICKS
Representation of an invalid number of ticks.
Definition: date_type.h:111
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:25
Vehicle::list
OrderList * list
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:321
OrderList::IsCompleteTimetable
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
Definition: order_cmd.cpp:592
Order::IsTravelTimetabled
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
Definition: order_base.h:178
BaseConsist::current_order_time
uint32 current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:23
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:212
SmallVector::Begin
const T * Begin() const
Get the pointer to the first item (const)
Definition: smallvec_type.hpp:272
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
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:30
cmd_helper.h
Helper functions to extract data from command parameters.
SmallVector
Simple vector template class.
Definition: smallvec_type.hpp:29
BaseConsist::lateness_counter
int32 lateness_counter
How many ticks late (or early if negative) this vehicle is.
Definition: base_consist.h:24
ModifyTimetableFlags
ModifyTimetableFlags
Enumeration for the data to set in CmdChangeTimetable.
Definition: order_type.h:175
CommandCost
Common return value for all commands.
Definition: command_type.h:25
Order
Definition: order_base.h:34
max
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
OrderList::GetFirstSharedVehicle
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
Definition: order_base.h:337
SmallVector::End
const T * End() const
Get the pointer behind the last valid item (const)
Definition: smallvec_type.hpp:292
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:218
ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
Definition: order_type.h:81
CmdSetVehicleOnTime
CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clear the lateness counter to make the vehicle on time.
Definition: timetable_cmd.cpp:197
SmallVector::Append
T * Append(uint to_add=1)
Append an item and return it.
Definition: smallvec_type.hpp:134
Vehicle::FirstShared
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:676
MTF_TRAVEL_TIME
Set travel time.
Definition: order_type.h:177
ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
Definition: order_type.h:79
VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:434
Vehicle::unitnumber
UnitID unitnumber
unit number, for display purposes only
Definition: vehicle_base.h:291
SmallVector::Length
uint Length() const
Get the number of items in the list.
Definition: smallvec_type.hpp:262
_date_fract
DateFract _date_fract
Fractional part of the day.
Definition: date.cpp:29
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:18
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:63
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:340
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
safeguards.h
A number of safeguards to prevent using unsafe methods.
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:316
VF_AUTOFILL_TIMETABLE
Whether the vehicle should fill in the timetable automatically.
Definition: vehicle_base.h:48
Order::IsWaitTimetabled
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition: order_base.h:176
CmdChangeTimetable
CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change timetable data of an order.
Definition: timetable_cmd.cpp:103
Order::GetTimetabledTravel
uint16 GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it&#39;s not timetabled...
Definition: order_base.h:183
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:310
WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
Definition: window_type.h:219
Order::SetWaitTimetabled
void SetWaitTimetabled(bool timetabled)
Set if the wait time is explicitly timetabled (unless the order is conditional).
Definition: order_base.h:197
Order::Equals
bool Equals(const Order &other) const
Does this order have the same type, flags and destination?
Definition: order_cmd.cpp:176
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:161
BaseConsist::timetable_start
Date timetable_start
When the vehicle is supposed to start the timetable.
Definition: base_consist.h:25
Vehicle::GetFirstOrder
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition: vehicle_base.h:655
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:35
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:185
DC_EXEC
execute the given command
Definition: command_type.h:342
company_func.h
Functions related to companies.
Order::GetTimetabledWait
uint16 GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it&#39;s not timetabled.
Definition: order_base.h:181
SmallVector::FindIndex
int FindIndex(const T &item) const
Search for the first occurrence of an item.
Definition: smallvec_type.hpp:195
ClrBit
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:153
vehicle_base.h
Base class for all vehicles.
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
Ticks
int32 Ticks
The type to store ticks in.
Definition: date_type.h:18
Vehicle::owner
OwnerByte owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
Order::SetTravelTimetabled
void SetTravelTimetabled(bool timetabled)
Set if the travel time is explicitly timetabled (unless the order is conditional).
Definition: order_base.h:199
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:34
sort_func.hpp
Functions related to sorting operations.
CmdSetTimetableStart
CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Set the start date of the timetable.
Definition: timetable_cmd.cpp:267
MAX_DAY
#define MAX_DAY
The number of days till the last day.
Definition: date_type.h:97
OrderList::UpdateTotalDuration
void UpdateTotalDuration(Ticks delta)
Must be called if an order&#39;s timetable is changed to update internal book keeping.
Definition: order_base.h:388
command_func.h
Functions related to commands.
Vehicle::GetOrder
Order * GetOrder(int index) const
Returns order &#39;index&#39; of a vehicle or NULL when it doesn&#39;t exists.
Definition: vehicle_base.h:859
Vehicle::GetNumOrders
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:688
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:16
CmdAutofillTimetable
CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Start or stop filling the timetable automatically from the time the vehicle actually takes to complet...
Definition: timetable_cmd.cpp:333
BaseConsist::vehicle_flags
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
Definition: base_consist.h:32
VehicleOrderID
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:17
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
UpdateVehicleTimetable
void UpdateVehicleTimetable(Vehicle *v, bool travelling)
Update the timetable for the vehicle.
Definition: timetable_cmd.cpp:379
VF_AUTOFILL_PRES_WAIT_TIME
Whether non-destructive auto-fill should preserve waiting times.
Definition: vehicle_base.h:49
Order::GetType
OrderType GetType() const
Get the type of order of this order.
Definition: order_base.h:69
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:194
Vehicle::NextShared
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:664
window_func.h
Window functions not directly related to making/drawing windows.
Vehicle::orders
union Vehicle::@46 orders
The orders currently assigned to the vehicle.
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:33
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
Order::SetTravelTime
void SetTravelTime(uint16 time)
Set the time in ticks to take for travelling to the destination.
Definition: order_base.h:211
QSortT
static void QSortT(T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
Type safe qsort()
Definition: sort_func.hpp:28
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:29
BaseVehicle::type
VehicleTypeByte type
Type of vehicle.
Definition: vehicle_type.h:54
Order::GetNonStopType
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:133
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:318
DAYS_IN_LEAP_YEAR
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Definition: date_type.h:32