Mercurial > hg > openttd
annotate src/timetable_cmd.cpp @ 13767:3b79b87a3fcb draft
(svn r18292) -Codechange: add a command to set the start date of a timetable. Based on work by PhilSophus.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 25 Nov 2009 23:37:15 +0000 |
parents | cf82bbe70093 |
children | c94cddea6802 |
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()) { |
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
|
36 if (v->cur_order_index == order_number && v->current_order.Equals(*order)) { |
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 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
52 * - p1 = (bit 0-15) - Vehicle with the orders to change. |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
53 * - p1 = (bit 16-23) - Order index to modify. |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
54 * - p1 = (bit 24) - Whether to change the waiting time or the travelling |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
55 * time. |
8650
2fa51e7b4d1f
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx <glx@openttd.org>
parents:
8302
diff
changeset
|
56 * - p1 = (bit 25) - Whether p2 contains waiting and travelling time. |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
57 * @param p2 The amount of time to wait. |
8650
2fa51e7b4d1f
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx <glx@openttd.org>
parents:
8302
diff
changeset
|
58 * - p2 = (bit 0-15) - Waiting or travelling time as specified by p1 bit 24 if p1 bit 25 is not set, |
2fa51e7b4d1f
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx <glx@openttd.org>
parents:
8302
diff
changeset
|
59 * Travelling time if p1 bit 25 is set. |
2fa51e7b4d1f
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx <glx@openttd.org>
parents:
8302
diff
changeset
|
60 * - p2 = (bit 16-31) - Waiting time if p1 bit 25 is set |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
61 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
62 * @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
|
63 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11042
diff
changeset
|
64 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
|
65 { |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9354
diff
changeset
|
66 if (!_settings_game.order.timetabling) 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
|
67 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
68 VehicleID veh = GB(p1, 0, 16); |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
69 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
70 Vehicle *v = Vehicle::GetIfValid(veh); |
13765
cf82bbe70093
(svn r18290) -Codechange: be more strict about what vehicles may use timetables
rubidium <rubidium@openttd.org>
parents:
13186
diff
changeset
|
71 if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) 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
|
72 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
73 VehicleOrderID order_number = GB(p1, 16, 8); |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11949
diff
changeset
|
74 Order *order = v->GetOrder(order_number); |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
75 if (order == NULL) return CMD_ERROR; |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
76 |
8650
2fa51e7b4d1f
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx <glx@openttd.org>
parents:
8302
diff
changeset
|
77 bool packed_time = HasBit(p1, 25); |
2fa51e7b4d1f
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx <glx@openttd.org>
parents:
8302
diff
changeset
|
78 bool is_journey = HasBit(p1, 24) || packed_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
|
79 |
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
|
80 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
|
81 int travel_time = order->travel_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
|
82 if (packed_time) { |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
83 travel_time = GB(p2, 0, 16); |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
84 wait_time = GB(p2, 16, 16);; |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
85 } else if (is_journey) { |
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 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
|
87 } 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
|
88 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
|
89 } |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
90 |
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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
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 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
|
98 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
|
99 |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
11991
diff
changeset
|
100 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
|
101 } |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
102 } |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
103 |
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
|
104 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
|
105 |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
106 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
|
107 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
|
108 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
|
109 } |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
110 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
111 return CommandCost(); |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
112 } |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
113 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
114 /** |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
115 * 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
|
116 * @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
|
117 * @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
|
118 * @param p1 Various bitstuffed elements |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
119 * - p1 = (bit 0-15) - Vehicle with the orders to change. |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
120 * @param p2 unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
121 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
122 * @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
|
123 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11042
diff
changeset
|
124 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
|
125 { |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9354
diff
changeset
|
126 if (!_settings_game.order.timetabling) 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
|
127 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
128 VehicleID veh = GB(p1, 0, 16); |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
129 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
130 Vehicle *v = Vehicle::GetIfValid(veh); |
13765
cf82bbe70093
(svn r18290) -Codechange: be more strict about what vehicles may use timetables
rubidium <rubidium@openttd.org>
parents:
13186
diff
changeset
|
131 if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) 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
|
132 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 } |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
137 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
138 return CommandCost(); |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
139 } |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
140 |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
141 /** |
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
|
142 * 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
|
143 * @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
|
144 * @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
|
145 * @param p1 Vehicle id. |
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 * @param p2 The timetable start date in ticks. |
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
|
147 */ |
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
|
148 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
|
149 { |
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
|
150 if (!_settings_game.order.timetabling) 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
|
151 |
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 Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 16)); |
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 if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) 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
|
154 |
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 /* 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 |
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 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
|
162 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
|
163 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
|
164 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
|
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 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
|
167 } |
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 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
|
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 |
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
|
172 |
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
|
173 /** |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
174 * 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
|
175 * 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
|
176 * 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
|
177 * @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
|
178 * @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
|
179 * @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
|
180 * @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
|
181 * - 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
|
182 * - 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
|
183 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
184 * @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
|
185 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11042
diff
changeset
|
186 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
|
187 { |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9354
diff
changeset
|
188 if (!_settings_game.order.timetabling) return CMD_ERROR; |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
189 |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
190 VehicleID veh = GB(p1, 0, 16); |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
191 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
192 Vehicle *v = Vehicle::GetIfValid(veh); |
13765
cf82bbe70093
(svn r18290) -Codechange: be more strict about what vehicles may use timetables
rubidium <rubidium@openttd.org>
parents:
13186
diff
changeset
|
193 if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR; |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
194 |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
195 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
|
196 if (HasBit(p2, 0)) { |
10677
698932d19cc4
(svn r14986) -Doc: small error in a comment (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10546
diff
changeset
|
197 /* 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
|
198 * "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
|
199 * 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
|
200 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
|
201 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
|
202 |
10677
698932d19cc4
(svn r14986) -Doc: small error in a comment (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10546
diff
changeset
|
203 /* 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
|
204 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
|
205 |
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
|
206 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
|
207 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
|
208 } 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
|
209 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
|
210 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
|
211 } |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
212 } |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
213 |
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
|
214 for (Vehicle *v2 = v->FirstShared(); v2 != NULL; v2 = v2->NextShared()) { |
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
|
215 if (v2 != v) { |
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
|
216 /* Stop autofilling; only one vehicle at a time can perform autofill */ |
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
|
217 ClrBit(v2->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
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
|
218 ClrBit(v2->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME); |
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 } |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12778
diff
changeset
|
220 SetWindowDirty(WC_VEHICLE_TIMETABLE, v2->index); |
7809
0b3ee8b9289c
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents:
7066
diff
changeset
|
221 } |
0b3ee8b9289c
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents:
7066
diff
changeset
|
222 |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
223 return CommandCost(); |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
224 } |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
225 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
226 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
|
227 { |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
228 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
|
229 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
|
230 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
231 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
|
232 |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9354
diff
changeset
|
233 if (!_settings_game.order.timetabling) return; |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
234 |
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
|
235 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
|
236 |
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
|
237 /* This vehicle is arriving at the first destination in 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
|
238 if (v->cur_order_index == 0 && travelling) { |
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
|
239 /* 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
|
240 * 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
|
241 * 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
|
242 * 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
|
243 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
|
244 |
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 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
|
246 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
|
247 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
|
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 |
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
|
250 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
|
251 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
|
252 } |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
253 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7809
diff
changeset
|
254 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
|
255 |
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 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
|
257 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
|
258 /* 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
|
259 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
|
260 } |
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 |
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 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
|
263 |
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 /* 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
|
265 * 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
|
266 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
|
267 /* 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
|
268 * confusion for people who are timetabling in days, and can be |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
269 * adjusted later by people who aren't. */ |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
270 time_taken = (((time_taken - 1) / DAY_TICKS) + 1) * DAY_TICKS; |
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
271 |
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
|
272 ChangeTimetable(v, v->cur_order_index, time_taken, travelling); |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
273 } |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
274 |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
275 if (v->cur_order_index == 0 && travelling) { |
3f3ad0911cdc
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10227
diff
changeset
|
276 /* 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
|
277 * 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
|
278 * 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
|
279 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
|
280 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
|
281 } |
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
|
282 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
|
283 } |
7066
bd6373f5acf4
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents:
7062
diff
changeset
|
284 |
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
|
285 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
|
286 |
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
|
287 /* 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
|
288 * 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
|
289 * 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
|
290 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
|
291 |
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
292 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
|
293 |
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
|
294 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
|
295 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
|
296 } |
6981
ba2c96d43e77
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff
changeset
|
297 } |