Mercurial > hg > openttd
annotate src/timetable_cmd.cpp @ 17232:5d82f4101601 draft
(svn r21972) -Fix: Replace 'None' industries in the generation window with more descriptive label.
author | alberth <alberth@openttd.org> |
---|---|
date | Sat, 05 Feb 2011 11:42:27 +0000 (2011-02-05) |
parents | 46deeeb7a878 |
children | f4995212309f |
rev | line source |
---|---|
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
2 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
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. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
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. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
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/>. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
9 |
9111
d48433370037
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
10 /** @file timetable_cmd.cpp Commands related to time tabling. */ |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
11 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
8116
9cc845deddfe
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents:
7931
diff
changeset
|
13 #include "command_func.h" |
8131
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8116
diff
changeset
|
14 #include "functions.h" |
13767
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
15 #include "date_func.h" |
8131
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8116
diff
changeset
|
16 #include "window_func.h" |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
17 #include "vehicle_base.h" |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
18 |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
19 #include "table/strings.h" |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
20 |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
21 static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 time, bool is_journey) |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
22 { |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11949
diff
changeset
|
23 Order *order = v->GetOrder(order_number); |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10499
diff
changeset
|
24 int delta; |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
25 |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
26 if (is_journey) { |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10499
diff
changeset
|
27 delta = time - order->travel_time; |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
28 order->travel_time = time; |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
29 } else { |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10499
diff
changeset
|
30 delta = time - order->wait_time; |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
31 order->wait_time = time; |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
32 } |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10499
diff
changeset
|
33 v->orders.list->UpdateOrderTimetable(delta); |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
34 |
10033
cb5901118b1c
(svn r14192) -Fix [FS#2236]: properly update the current timetable's travel/wait times instead of only doing it for one vehicle in the shared order chain and only when some bit has not been set (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
9941
diff
changeset
|
35 for (v = v->FirstShared(); v != NULL; v = v->NextShared()) { |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17095
diff
changeset
|
36 if (v->cur_real_order_index == order_number && v->current_order.Equals(*order)) { |
10033
cb5901118b1c
(svn r14192) -Fix [FS#2236]: properly update the current timetable's travel/wait times instead of only doing it for one vehicle in the shared order chain and only when some bit has not been set (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
9941
diff
changeset
|
37 if (is_journey) { |
cb5901118b1c
(svn r14192) -Fix [FS#2236]: properly update the current timetable's travel/wait times instead of only doing it for one vehicle in the shared order chain and only when some bit has not been set (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
9941
diff
changeset
|
38 v->current_order.travel_time = time; |
cb5901118b1c
(svn r14192) -Fix [FS#2236]: properly update the current timetable's travel/wait times instead of only doing it for one vehicle in the shared order chain and only when some bit has not been set (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
9941
diff
changeset
|
39 } else { |
cb5901118b1c
(svn r14192) -Fix [FS#2236]: properly update the current timetable's travel/wait times instead of only doing it for one vehicle in the shared order chain and only when some bit has not been set (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
9941
diff
changeset
|
40 v->current_order.wait_time = time; |
cb5901118b1c
(svn r14192) -Fix [FS#2236]: properly update the current timetable's travel/wait times instead of only doing it for one vehicle in the shared order chain and only when some bit has not been set (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
9941
diff
changeset
|
41 } |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
42 } |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12778
diff
changeset
|
43 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index); |
7809
0b3ee8b9289c
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents:
7066
diff
changeset
|
44 } |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
45 } |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
46 |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
47 /** |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
48 * Add or remove waiting times from an order. |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
49 * @param tile Not used. |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
50 * @param flags Operation to perform. |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
51 * @param p1 Various bitstuffed elements |
15888
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
52 * - p1 = (bit 0-19) - Vehicle with the orders to change. |
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
53 * - p1 = (bit 20-27) - Order index to modify. |
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
54 * - p1 = (bit 28) - Whether to change the waiting time or the travelling |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
55 * time. |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
56 * @param p2 The amount of time to wait. |
15888
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
57 * - p2 = (bit 0-15) - Waiting or travelling time as specified by p1 bit 28 |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
58 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
59 * @return the cost of this operation or an error |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
60 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11042
diff
changeset
|
61 CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
62 { |
15888
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
63 VehicleID veh = GB(p1, 0, 20); |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
64 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
65 Vehicle *v = Vehicle::GetIfValid(veh); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
66 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
67 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
68 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
69 if (ret.Failed()) return ret; |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
70 |
15888
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
71 VehicleOrderID order_number = GB(p1, 20, 8); |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11949
diff
changeset
|
72 Order *order = v->GetOrder(order_number); |
16907
e2be394e4714
(svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents:
15888
diff
changeset
|
73 if (order == NULL || order->IsType(OT_AUTOMATIC)) return CMD_ERROR; |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
74 |
15888
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
75 bool is_journey = HasBit(p1, 28); |
9665
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
76 |
10227
091840e3062d
(svn r14450) -Fix [FS#2337]: time table restoring did check too restrictively causing order backups not to be properly restored.
rubidium <rubidium@openttd.org>
parents:
10033
diff
changeset
|
77 int wait_time = order->wait_time; |
091840e3062d
(svn r14450) -Fix [FS#2337]: time table restoring did check too restrictively causing order backups not to be properly restored.
rubidium <rubidium@openttd.org>
parents:
10033
diff
changeset
|
78 int travel_time = order->travel_time; |
15887
708e732bb8a6
(svn r20569) -Cleanup: the change timetable command doesn't need the packed bit anymore
rubidium <rubidium@openttd.org>
parents:
15868
diff
changeset
|
79 if (is_journey) { |
9665
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
80 travel_time = GB(p2, 0, 16); |
9641
d6df5044bb40
(svn r13704) -Fix: make timetables work more sensible when used in conjunction with conditional orders, i.e. make it possibly to tell how long to travel to the next destination if you jump.
rubidium <rubidium@openttd.org>
parents:
9413
diff
changeset
|
81 } else { |
9665
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
82 wait_time = GB(p2, 0, 16); |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
83 } |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
84 |
10227
091840e3062d
(svn r14450) -Fix [FS#2337]: time table restoring did check too restrictively causing order backups not to be properly restored.
rubidium <rubidium@openttd.org>
parents:
10033
diff
changeset
|
85 if (wait_time != order->wait_time) { |
9665
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
86 switch (order->GetType()) { |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
87 case OT_GOTO_STATION: |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
11991
diff
changeset
|
88 if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return_cmd_error(STR_ERROR_TIMETABLE_NOT_STOPPING_HERE); |
9665
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
89 break; |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
90 |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
91 case OT_CONDITIONAL: |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
92 break; |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
93 |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
11991
diff
changeset
|
94 default: return_cmd_error(STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS); |
9665
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
95 } |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
96 } |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
97 |
10227
091840e3062d
(svn r14450) -Fix [FS#2337]: time table restoring did check too restrictively causing order backups not to be properly restored.
rubidium <rubidium@openttd.org>
parents:
10033
diff
changeset
|
98 if (travel_time != order->travel_time && order->IsType(OT_CONDITIONAL)) return CMD_ERROR; |
9665
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
99 |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
100 if (flags & DC_EXEC) { |
10227
091840e3062d
(svn r14450) -Fix [FS#2337]: time table restoring did check too restrictively causing order backups not to be properly restored.
rubidium <rubidium@openttd.org>
parents:
10033
diff
changeset
|
101 if (wait_time != order->wait_time) ChangeTimetable(v, order_number, wait_time, false); |
091840e3062d
(svn r14450) -Fix [FS#2337]: time table restoring did check too restrictively causing order backups not to be properly restored.
rubidium <rubidium@openttd.org>
parents:
10033
diff
changeset
|
102 if (travel_time != order->travel_time) ChangeTimetable(v, order_number, travel_time, true); |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
103 } |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
104 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
105 return CommandCost(); |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
106 } |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
107 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
108 /** |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
109 * Clear the lateness counter to make the vehicle on time. |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
110 * @param tile Not used. |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
111 * @param flags Operation to perform. |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
112 * @param p1 Various bitstuffed elements |
15888
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
113 * - p1 = (bit 0-19) - Vehicle with the orders to change. |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
114 * @param p2 unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
115 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
116 * @return the cost of this operation or an error |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
117 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11042
diff
changeset
|
118 CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
119 { |
15888
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
120 VehicleID veh = GB(p1, 0, 20); |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
121 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
122 Vehicle *v = Vehicle::GetIfValid(veh); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
123 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
124 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
125 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
126 if (ret.Failed()) return ret; |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
127 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
128 if (flags & DC_EXEC) { |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
129 v->lateness_counter = 0; |
13765
cf82bbe70093
(svn r18290) -Codechange: be more strict about what vehicles may use timetables
rubidium <rubidium@openttd.org>
parents:
13186
diff
changeset
|
130 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index); |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
131 } |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
132 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
133 return CommandCost(); |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
134 } |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
135 |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
136 /** |
13767
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
137 * Set the start date of the timetable. |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
138 * @param tile Not used. |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
139 * @param flags Operation to perform. |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
140 * @param p1 Vehicle id. |
15868
5d8e60ba4e28
(svn r20550) -Fix: documentation of CmdSetTimetableStart
rubidium <rubidium@openttd.org>
parents:
15050
diff
changeset
|
141 * @param p2 The timetable start date. |
5d8e60ba4e28
(svn r20550) -Fix: documentation of CmdSetTimetableStart
rubidium <rubidium@openttd.org>
parents:
15050
diff
changeset
|
142 * @param text Not used. |
5d8e60ba4e28
(svn r20550) -Fix: documentation of CmdSetTimetableStart
rubidium <rubidium@openttd.org>
parents:
15050
diff
changeset
|
143 * @return The error or cost of the operation. |
13767
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
144 */ |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
145 CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
146 { |
15888
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
147 Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20)); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
148 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
149 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
150 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
151 if (ret.Failed()) return ret; |
13767
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
152 |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
153 /* Don't let a timetable start more than 15 years into the future or 1 year in the past. */ |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
154 Date start_date = (Date)p2; |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
155 if (start_date < 0 || start_date > MAX_DAY) return CMD_ERROR; |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
156 if (start_date - _date > 15 * DAYS_IN_LEAP_YEAR) return CMD_ERROR; |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
157 if (_date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR; |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
158 |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
159 if (flags & DC_EXEC) { |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
160 v->lateness_counter = 0; |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
161 ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED); |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
162 v->timetable_start = start_date; |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
163 |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
164 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index); |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
165 } |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
166 |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
167 return CommandCost(); |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
168 } |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
169 |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
170 |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
171 /** |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
172 * Start or stop filling the timetable automatically from the time the vehicle |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
173 * actually takes to complete it. When starting to autofill the current times |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
174 * are cleared and the timetable will start again from scratch. |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
175 * @param tile Not used. |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
176 * @param flags Operation to perform. |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
177 * @param p1 Vehicle index. |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
178 * @param p2 Various bitstuffed elements |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
179 * - p2 = (bit 0) - Set to 1 to enable, 0 to disable autofill. |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
180 * - p2 = (bit 1) - Set to 1 to preserve waiting times in non-destructive mode |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
181 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
182 * @return the cost of this operation or an error |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
183 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11042
diff
changeset
|
184 CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
185 { |
15888
a16553398295
(svn r20570) -Codechange: free/reserve some bits in the timetable commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents:
15887
diff
changeset
|
186 VehicleID veh = GB(p1, 0, 20); |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
187 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
188 Vehicle *v = Vehicle::GetIfValid(veh); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
189 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
190 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
191 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14561
diff
changeset
|
192 if (ret.Failed()) return ret; |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
193 |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
194 if (flags & DC_EXEC) { |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
195 if (HasBit(p2, 0)) { |
10677
698932d19cc4
(svn r14986) -Doc: small error in a comment (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10546
diff
changeset
|
196 /* Start autofilling the timetable, which clears the |
698932d19cc4
(svn r14986) -Doc: small error in a comment (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10546
diff
changeset
|
197 * "timetable has started" bit. Times are not cleared anymore, but are |
698932d19cc4
(svn r14986) -Doc: small error in a comment (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10546
diff
changeset
|
198 * overwritten when the order is reached now. */ |
7931
44ff7a6d801f
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7929
diff
changeset
|
199 SetBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
200 ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED); |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
201 |
10677
698932d19cc4
(svn r14986) -Doc: small error in a comment (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10546
diff
changeset
|
202 /* Overwrite waiting times only if they got longer */ |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
203 if (HasBit(p2, 1)) SetBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
204 |
13767
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
205 v->timetable_start = 0; |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
206 v->lateness_counter = 0; |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
207 } else { |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
208 ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
209 ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
210 } |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
211 |
16925
caa4e23b1587
(svn r21660) -Fix [FS#4354]: autofill timetable had side effects in test mode, possibly causing desyncs in MP
rubidium <rubidium@openttd.org>
parents:
16907
diff
changeset
|
212 for (Vehicle *v2 = v->FirstShared(); v2 != NULL; v2 = v2->NextShared()) { |
caa4e23b1587
(svn r21660) -Fix [FS#4354]: autofill timetable had side effects in test mode, possibly causing desyncs in MP
rubidium <rubidium@openttd.org>
parents:
16907
diff
changeset
|
213 if (v2 != v) { |
caa4e23b1587
(svn r21660) -Fix [FS#4354]: autofill timetable had side effects in test mode, possibly causing desyncs in MP
rubidium <rubidium@openttd.org>
parents:
16907
diff
changeset
|
214 /* Stop autofilling; only one vehicle at a time can perform autofill */ |
caa4e23b1587
(svn r21660) -Fix [FS#4354]: autofill timetable had side effects in test mode, possibly causing desyncs in MP
rubidium <rubidium@openttd.org>
parents:
16907
diff
changeset
|
215 ClrBit(v2->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
caa4e23b1587
(svn r21660) -Fix [FS#4354]: autofill timetable had side effects in test mode, possibly causing desyncs in MP
rubidium <rubidium@openttd.org>
parents:
16907
diff
changeset
|
216 ClrBit(v2->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); |
caa4e23b1587
(svn r21660) -Fix [FS#4354]: autofill timetable had side effects in test mode, possibly causing desyncs in MP
rubidium <rubidium@openttd.org>
parents:
16907
diff
changeset
|
217 } |
caa4e23b1587
(svn r21660) -Fix [FS#4354]: autofill timetable had side effects in test mode, possibly causing desyncs in MP
rubidium <rubidium@openttd.org>
parents:
16907
diff
changeset
|
218 SetWindowDirty(WC_VEHICLE_TIMETABLE, v2->index); |
11042
3f6dbfd6e903
(svn r15382) -Fix [FS#2466]: multiple vehicles could be filling the timetable and only the data from one vehicle would be taken. Now only allow one to be filling at a time.
rubidium <rubidium@openttd.org>
parents:
10960
diff
changeset
|
219 } |
7809
0b3ee8b9289c
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents:
7066
diff
changeset
|
220 } |
0b3ee8b9289c
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents:
7066
diff
changeset
|
221 |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
222 return CommandCost(); |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
223 } |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
224 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
225 void UpdateVehicleTimetable(Vehicle *v, bool travelling) |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
226 { |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
227 uint timetabled = travelling ? v->current_order.travel_time : v->current_order.wait_time; |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
228 uint time_taken = v->current_order_time; |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
229 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
230 v->current_order_time = 0; |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
231 |
16907
e2be394e4714
(svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents:
15888
diff
changeset
|
232 if (v->current_order.IsType(OT_AUTOMATIC)) return; // no timetabling of auto orders |
e2be394e4714
(svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents:
15888
diff
changeset
|
233 |
e2be394e4714
(svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents:
15888
diff
changeset
|
234 VehicleOrderID first_manual_order = 0; |
e2be394e4714
(svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents:
15888
diff
changeset
|
235 for (Order *o = v->GetFirstOrder(); o != NULL && o->IsType(OT_AUTOMATIC); o = o->next) { |
e2be394e4714
(svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents:
15888
diff
changeset
|
236 ++first_manual_order; |
e2be394e4714
(svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents:
15888
diff
changeset
|
237 } |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
238 |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
239 bool just_started = false; |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
240 |
13767
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
241 /* This vehicle is arriving at the first destination in the timetable. */ |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17095
diff
changeset
|
242 if (v->cur_real_order_index == first_manual_order && travelling) { |
13767
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
243 /* If the start date hasn't been set, or it was set automatically when |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
244 * the vehicle last arrived at the first destination, update it to the |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
245 * current time. Otherwise set the late counter appropriately to when |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
246 * the vehicle should have arrived. */ |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
247 just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED); |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
248 |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
249 if (v->timetable_start != 0) { |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
250 v->lateness_counter = (_date - v->timetable_start) * DAY_TICKS + _date_fract; |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
251 v->timetable_start = 0; |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
252 } |
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
253 |
8970
3667cbc7dc1d
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium <rubidium@openttd.org>
parents:
8853
diff
changeset
|
254 SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED); |
13767
3b79b87a3fcb
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
rubidium <rubidium@openttd.org>
parents:
13765
diff
changeset
|
255 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index); |
8970
3667cbc7dc1d
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium <rubidium@openttd.org>
parents:
8853
diff
changeset
|
256 } |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
257 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7809
diff
changeset
|
258 if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return; |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
259 |
8970
3667cbc7dc1d
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium <rubidium@openttd.org>
parents:
8853
diff
changeset
|
260 if (HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) { |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
261 if (travelling && !HasBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME)) { |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
262 /* Need to clear that now as otherwise we are not able to reduce the wait time */ |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
263 v->current_order.wait_time = 0; |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
264 } |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
265 |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
266 if (just_started) return; |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
267 |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
268 /* Modify station waiting time only if our new value is larger (this is |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
269 * always the case when we cleared the timetable). */ |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
270 if (!v->current_order.IsType(OT_CONDITIONAL) && (travelling || time_taken > v->current_order.wait_time)) { |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
271 /* Round the time taken up to the nearest day, as this will avoid |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
272 * confusion for people who are timetabling in days, and can be |
17094
4154ccfd4d39
(svn r21831) -Fix [FS#4414]: service orders for trains/aircraft would (sometimes) not get a time when autofilling
rubidium <rubidium@openttd.org>
parents:
16925
diff
changeset
|
273 * adjusted later by people who aren't. |
4154ccfd4d39
(svn r21831) -Fix [FS#4414]: service orders for trains/aircraft would (sometimes) not get a time when autofilling
rubidium <rubidium@openttd.org>
parents:
16925
diff
changeset
|
274 * For trains/aircraft multiple movement cycles are done in one |
4154ccfd4d39
(svn r21831) -Fix [FS#4414]: service orders for trains/aircraft would (sometimes) not get a time when autofilling
rubidium <rubidium@openttd.org>
parents:
16925
diff
changeset
|
275 * tick. This makes it possible to leave the station and process |
4154ccfd4d39
(svn r21831) -Fix [FS#4414]: service orders for trains/aircraft would (sometimes) not get a time when autofilling
rubidium <rubidium@openttd.org>
parents:
16925
diff
changeset
|
276 * e.g. a depot order in the same tick, causing it to not fill |
4154ccfd4d39
(svn r21831) -Fix [FS#4414]: service orders for trains/aircraft would (sometimes) not get a time when autofilling
rubidium <rubidium@openttd.org>
parents:
16925
diff
changeset
|
277 * the timetable entry like is done for road vehicles/ships. |
4154ccfd4d39
(svn r21831) -Fix [FS#4414]: service orders for trains/aircraft would (sometimes) not get a time when autofilling
rubidium <rubidium@openttd.org>
parents:
16925
diff
changeset
|
278 * Thus always make sure at least one tick is used between the |
4154ccfd4d39
(svn r21831) -Fix [FS#4414]: service orders for trains/aircraft would (sometimes) not get a time when autofilling
rubidium <rubidium@openttd.org>
parents:
16925
diff
changeset
|
279 * processing of different orders when filling the timetable. */ |
4154ccfd4d39
(svn r21831) -Fix [FS#4414]: service orders for trains/aircraft would (sometimes) not get a time when autofilling
rubidium <rubidium@openttd.org>
parents:
16925
diff
changeset
|
280 time_taken = CeilDiv(max(time_taken, 1U), DAY_TICKS) * DAY_TICKS; |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
281 |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17095
diff
changeset
|
282 ChangeTimetable(v, v->cur_real_order_index, time_taken, travelling); |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
283 } |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
284 |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17095
diff
changeset
|
285 if (v->cur_real_order_index == first_manual_order && travelling) { |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
286 /* If we just started we would have returned earlier and have not reached |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
287 * this code. So obviously, we have completed our round: So turn autofill |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
288 * off again. */ |
7929
4d13dbed828c
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7928
diff
changeset
|
289 ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
290 ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
291 } |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
292 return; |
8970
3667cbc7dc1d
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium <rubidium@openttd.org>
parents:
8853
diff
changeset
|
293 } |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
294 |
10341
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
295 if (just_started) return; |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
296 |
7062
1a0ddc74cd95
(svn r10327) -Fix (r10236) [FS#934]: Vehicles wait at stations when they arrive early even
maedhros <maedhros@openttd.org>
parents:
6981
diff
changeset
|
297 /* Vehicles will wait at stations if they arrive early even if they are not |
1a0ddc74cd95
(svn r10327) -Fix (r10236) [FS#934]: Vehicles wait at stations when they arrive early even
maedhros <maedhros@openttd.org>
parents:
6981
diff
changeset
|
298 * timetabled to wait there, so make sure the lateness counter is updated |
1a0ddc74cd95
(svn r10327) -Fix (r10236) [FS#934]: Vehicles wait at stations when they arrive early even
maedhros <maedhros@openttd.org>
parents:
6981
diff
changeset
|
299 * when this happens. */ |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
300 if (timetabled == 0 && (travelling || v->lateness_counter >= 0)) return; |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
301 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
302 v->lateness_counter -= (timetabled - time_taken); |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
303 |
17095
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
304 /* When we are more late than this timetabled bit takes we (somewhat expensively) |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
305 * check how many ticks the (fully filled) timetable has. If a timetable cycle is |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
306 * shorter than the amount of ticks we are late we reduce the lateness by the |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
307 * length of a full cycle till lateness is less than the length of a timetable |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
308 * cycle. When the timetable isn't fully filled the cycle will be INVALID_TICKS. */ |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
309 if (v->lateness_counter > (int)timetabled) { |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
310 Ticks cycle = v->orders.list->GetTimetableTotalDuration(); |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
311 if (cycle != INVALID_TICKS && v->lateness_counter > cycle) { |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
312 v->lateness_counter %= cycle; |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
313 } |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
314 } |
f9112c03b14d
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
rubidium <rubidium@openttd.org>
parents:
17094
diff
changeset
|
315 |
9941
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9829
diff
changeset
|
316 for (v = v->FirstShared(); v != NULL; v = v->NextShared()) { |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12778
diff
changeset
|
317 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index); |
7809
0b3ee8b9289c
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents:
7066
diff
changeset
|
318 } |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
319 } |