author | rubidium |
Sat, 20 Oct 2007 17:11:02 +0000 | |
changeset 8261 | ed2ea3ac3edc |
parent 7562 | f6f62814907b |
child 8305 | c8b7592ae94b |
permissions | -rw-r--r-- |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
1 |
/* $Id$ */ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
2 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
3 |
/** @file timetable_cmd.cpp */ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
4 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
6 |
#include "openttd.h" |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
7 |
#include "functions.h" |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
8 |
#include "variables.h" |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
9 |
#include "table/strings.h" |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
10 |
#include "command.h" |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
11 |
#include "date.h" |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
12 |
#include "player.h" |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
13 |
#include "vehicle.h" |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
14 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
15 |
|
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
16 |
static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 time, bool is_journey) |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
17 |
{ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
18 |
Order *order = GetVehicleOrder(v, order_number); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
19 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
20 |
if (is_journey) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
21 |
order->travel_time = time; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
22 |
} else { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
23 |
order->wait_time = time; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
24 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
25 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
26 |
if (v->cur_order_index == order_number && HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
27 |
if (is_journey) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
28 |
v->current_order.travel_time = time; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
29 |
} else { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
30 |
v->current_order.wait_time = time; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
31 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
32 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
33 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
34 |
InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
35 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
36 |
|
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
37 |
/** |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
38 |
* Add or remove waiting times from an order. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
39 |
* @param tile Not used. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
40 |
* @param flags Operation to perform. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
41 |
* @param p1 Various bitstuffed elements |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
42 |
* - p1 = (bit 0-15) - Vehicle with the orders to change. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
43 |
* - p1 = (bit 16-23) - Order index to modify. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
44 |
* - p1 = (bit 24) - Whether to change the waiting time or the travelling |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
45 |
* time. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
46 |
* @param p2 The amount of time to wait. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
47 |
*/ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
48 |
CommandCost CmdChangeTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
49 |
{ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
50 |
if (!_patches.timetabling) return CMD_ERROR; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
51 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
52 |
VehicleID veh = GB(p1, 0, 16); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
53 |
if (!IsValidVehicleID(veh)) return CMD_ERROR; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
54 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
55 |
Vehicle *v = GetVehicle(veh); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
56 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
57 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
58 |
VehicleOrderID order_number = GB(p1, 16, 8); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
59 |
Order *order = GetVehicleOrder(v, order_number); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
60 |
if (order == NULL) return CMD_ERROR; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
61 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
62 |
bool is_journey = HASBIT(p1, 24); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
63 |
if (!is_journey) { |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
64 |
if (order->type != OT_GOTO_STATION) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
65 |
if (_patches.new_nonstop && (order->flags & OF_NON_STOP)) return_cmd_error(STR_TIMETABLE_NOT_STOPPING_HERE); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
66 |
} |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
67 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
68 |
if (flags & DC_EXEC) { |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
69 |
ChangeTimetable(v, order_number, p2, is_journey); |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
70 |
} |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
71 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
72 |
return CommandCost(); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
73 |
} |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
74 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
75 |
/** |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
76 |
* Clear the lateness counter to make the vehicle on time. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
77 |
* @param tile Not used. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
78 |
* @param flags Operation to perform. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
79 |
* @param p1 Various bitstuffed elements |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
80 |
* - p1 = (bit 0-15) - Vehicle with the orders to change. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
81 |
*/ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
82 |
CommandCost CmdSetVehicleOnTime(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
83 |
{ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
84 |
if (!_patches.timetabling) return CMD_ERROR; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
85 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
86 |
VehicleID veh = GB(p1, 0, 16); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
87 |
if (!IsValidVehicleID(veh)) return CMD_ERROR; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
88 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
89 |
Vehicle *v = GetVehicle(veh); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
90 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
91 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
92 |
if (flags & DC_EXEC) { |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
93 |
v->lateness_counter = 0; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
94 |
} |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
95 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
96 |
return CommandCost(); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
97 |
} |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
98 |
|
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
99 |
/** |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
100 |
* Start or stop filling the timetable automatically from the time the vehicle |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
101 |
* actually takes to complete it. When starting to autofill the current times |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
102 |
* are cleared and the timetable will start again from scratch. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
103 |
* @param tile Not used. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
104 |
* @param flags Operation to perform. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
105 |
* @param p1 Vehicle index. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
106 |
* @param p2 Set to 1 to enable, 0 to disable. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
107 |
*/ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
108 |
CommandCost CmdAutofillTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
109 |
{ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
110 |
if (!_patches.timetabling) return CMD_ERROR; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
111 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
112 |
VehicleID veh = GB(p1, 0, 16); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
113 |
if (!IsValidVehicleID(veh)) return CMD_ERROR; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
114 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
115 |
Vehicle *v = GetVehicle(veh); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
116 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
117 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
118 |
if (flags & DC_EXEC) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
119 |
if (p2 == 1) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
120 |
/* Start autofilling the timetable, which clears all the current |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
121 |
* timings and clears the "timetable has started" bit. */ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
122 |
SETBIT(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
123 |
CLRBIT(v->vehicle_flags, VF_TIMETABLE_STARTED); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
124 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
125 |
for (Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
126 |
order->wait_time = 0; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
127 |
order->travel_time = 0; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
128 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
129 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
130 |
v->current_order.wait_time = 0; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
131 |
v->current_order.travel_time = 0; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
132 |
} else { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
133 |
CLRBIT(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
134 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
135 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
136 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
137 |
return CommandCost(); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
138 |
} |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
139 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
140 |
void UpdateVehicleTimetable(Vehicle *v, bool travelling) |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
141 |
{ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
142 |
uint timetabled = travelling ? v->current_order.travel_time : v->current_order.wait_time; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
143 |
uint time_taken = v->current_order_time; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
144 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
145 |
v->current_order_time = 0; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
146 |
|
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
147 |
if (!_patches.timetabling) return; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
148 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
149 |
/* Make sure the timetable only starts when the vehicle reaches the first |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
150 |
* order, not when travelling from the depot to the first station. */ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
151 |
if (v->cur_order_index == 0 && !HASBIT(v->vehicle_flags, VF_TIMETABLE_STARTED)) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
152 |
SETBIT(v->vehicle_flags, VF_TIMETABLE_STARTED); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
153 |
return; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
154 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
155 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
156 |
if (!HASBIT(v->vehicle_flags, VF_TIMETABLE_STARTED)) return; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
157 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
158 |
if (HASBIT(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
159 |
if (timetabled == 0) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
160 |
/* Round the time taken up to the nearest day, as this will avoid |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
161 |
* confusion for people who are timetabling in days, and can be |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
162 |
* adjusted later by people who aren't. */ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
163 |
time_taken = (((time_taken - 1) / DAY_TICKS) + 1) * DAY_TICKS; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
164 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
165 |
ChangeTimetable(v, v->cur_order_index, time_taken, travelling); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
166 |
return; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
167 |
} else if (v->cur_order_index == 0) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
168 |
/* Otherwise if we're at the beginning and it already has a value, |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
169 |
* assume that autofill is finished and turn it off again. */ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
170 |
CLRBIT(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
171 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
172 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
173 |
|
7558
ca45ff710b35
(svn r10327) -Fix (r10236) [FS#934]: Vehicles wait at stations when they arrive early even
maedhros
parents:
7477
diff
changeset
|
174 |
/* Vehicles will wait at stations if they arrive early even if they are not |
ca45ff710b35
(svn r10327) -Fix (r10236) [FS#934]: Vehicles wait at stations when they arrive early even
maedhros
parents:
7477
diff
changeset
|
175 |
* timetabled to wait there, so make sure the lateness counter is updated |
ca45ff710b35
(svn r10327) -Fix (r10236) [FS#934]: Vehicles wait at stations when they arrive early even
maedhros
parents:
7477
diff
changeset
|
176 |
* when this happens. */ |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
177 |
if (timetabled == 0 && (travelling || v->lateness_counter >= 0)) return; |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
178 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
179 |
v->lateness_counter -= (timetabled - time_taken); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
180 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
181 |
InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
182 |
} |