annotate src/timetable_cmd.cpp @ 11436:caf4456fbbf3 draft

(svn r15794) -Codechange: remove the DoDrawString part of the old text drawing API
author rubidium <rubidium@openttd.org>
date Sat, 21 Mar 2009 22:46:17 +0000
parents df23c4e04638
children 0a4b63f3f3c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
3 /** @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
4
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
5 #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
6 #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
7 #include "functions.h"
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
8 #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
9 #include "vehicle_base.h"
8270
5613b863190d (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium <rubidium@openttd.org>
parents: 8264
diff changeset
10 #include "settings_type.h"
6981
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
11
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
12 #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
13
7066
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
14 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
15 {
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
16 Order *order = GetVehicleOrder(v, 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
17 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
18
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
19 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
20 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
21 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
22 } 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
23 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
24 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
25 }
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
26 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
27
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
28 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
29 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
30 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
31 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
32 } 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
33 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
34 }
7066
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
35 }
7809
0b3ee8b9289c (svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents: 7066
diff changeset
36 InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index);
0b3ee8b9289c (svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents: 7066
diff changeset
37 }
7066
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
38 }
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
39
6981
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
40 /**
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
41 * 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
42 * @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
43 * @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
44 * @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
45 * - 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
46 * - 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
47 * - 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
48 * 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
49 * - 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
50 * @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
51 * - 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
52 * 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
53 * - p2 = (bit 16-31) - Waiting time if p1 bit 25 is set
6981
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
54 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11042
diff changeset
55 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
56 {
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
57 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
58
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
59 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
60 if (!IsValidVehicleID(veh)) 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
61
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
62 Vehicle *v = GetVehicle(veh);
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
63 if (!CheckOwnership(v->owner)) 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
64
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
65 VehicleOrderID order_number = GB(p1, 16, 8);
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
66 Order *order = GetVehicleOrder(v, order_number);
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
67 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
68
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
69 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
70 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
71
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
72 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
73 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
74 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
75 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
76 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
77 } 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
78 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
79 } 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
80 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
81 }
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
82
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
83 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
84 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
85 case OT_GOTO_STATION:
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 if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return_cmd_error(STR_TIMETABLE_NOT_STOPPING_HERE);
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 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
88
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 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
90 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
91
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 default: return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
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 }
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
94 }
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
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
96 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
97
6981
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
98 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
99 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
100 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
101 }
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
102
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
103 return CommandCost();
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
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 * 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
108 * @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
109 * @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
110 * @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
111 * - 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
112 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11042
diff changeset
113 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
114 {
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
115 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
116
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
117 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
118 if (!IsValidVehicleID(veh)) 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
119
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
120 Vehicle *v = GetVehicle(veh);
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
121 if (!CheckOwnership(v->owner)) 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
122
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
123 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
124 v->lateness_counter = 0;
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
125 }
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
126
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
127 return CommandCost();
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
128 }
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
129
7066
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
130 /**
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
131 * 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
132 * 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
133 * 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
134 * @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
135 * @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
136 * @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
137 * @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
138 * - 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
139 * - p2 = (bit 1) - Set to 1 to preserve waiting times in non-destructive mode
7066
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
140 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11042
diff changeset
141 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
142 {
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
143 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
144
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
145 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
146 if (!IsValidVehicleID(veh)) return CMD_ERROR;
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
147
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
148 Vehicle *v = GetVehicle(veh);
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
149 if (!CheckOwnership(v->owner)) return CMD_ERROR;
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
150
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
151 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
152 if (HasBit(p2, 0)) {
10677
698932d19cc4 (svn r14986) -Doc: small error in a comment (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10546
diff changeset
153 /* 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
154 * "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
155 * 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
156 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
157 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
158
10677
698932d19cc4 (svn r14986) -Doc: small error in a comment (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10546
diff changeset
159 /* 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
160 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
161
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
162 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
163 } 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
164 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
165 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
166 }
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
167 }
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
168
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
169 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
170 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
171 /* 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
172 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
173 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
174 }
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
175 InvalidateWindow(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
176 }
0b3ee8b9289c (svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents: 7066
diff changeset
177
7066
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
178 return CommandCost();
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
179 }
6981
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
180
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
181 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
182 {
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
183 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
184 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
185
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
186 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
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;
7066
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
189
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
190 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
191
7066
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
192 /* Make sure the timetable only starts when the vehicle reaches the first
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
193 * order, not when travelling from the depot to the first station. */
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
194 if (v->cur_order_index == 0 && !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
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
195 SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
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 just_started = true;
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
197 }
7066
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
198
7928
4e8dfd103163 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents: 7809
diff changeset
199 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
200
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
201 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
202 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
203 /* 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
204 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
205 }
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
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 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
208
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 /* 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
210 * 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
211 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
212 /* 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
213 * 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
214 * 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
215 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
216
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
217 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
218 }
3f3ad0911cdc (svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10227
diff changeset
219
3f3ad0911cdc (svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10227
diff changeset
220 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
221 /* 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
222 * 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
223 * 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
224 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
225 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
226 }
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
227 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
228 }
7066
bd6373f5acf4 (svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros <maedhros@openttd.org>
parents: 7062
diff changeset
229
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
230 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
231
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
232 /* 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
233 * 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
234 * 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
235 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
236
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
237 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
238
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
239 for (v = v->FirstShared(); v != NULL; v = v->NextShared()) {
7809
0b3ee8b9289c (svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents: 7066
diff changeset
240 InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index);
0b3ee8b9289c (svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium <rubidium@openttd.org>
parents: 7066
diff changeset
241 }
6981
ba2c96d43e77 (svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros <maedhros@openttd.org>
parents:
diff changeset
242 }