author | rubidium |
Tue, 15 Jan 2008 18:44:22 +0000 | |
changeset 8798 | eea3a465bd86 |
parent 8766 | c86cfa3a7580 |
child 9146 | 2c8c94a75544 |
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 "variables.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8427
diff
changeset
|
8 |
#include "command_func.h" |
8627
448ebf3a8291
(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
parents:
8612
diff
changeset
|
9 |
#include "functions.h" |
448ebf3a8291
(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
parents:
8612
diff
changeset
|
10 |
#include "window_func.h" |
8640
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8636
diff
changeset
|
11 |
#include "vehicle_func.h" |
1e93b81e96d2
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents:
8636
diff
changeset
|
12 |
#include "vehicle_base.h" |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8760
diff
changeset
|
13 |
#include "settings_type.h" |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
14 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8750
diff
changeset
|
15 |
#include "table/strings.h" |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
16 |
|
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
17 |
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
|
18 |
{ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
19 |
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
|
20 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
21 |
if (is_journey) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
22 |
order->travel_time = time; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
23 |
} else { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
24 |
order->wait_time = time; |
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 |
|
8798
eea3a465bd86
(svn r11866) -Codechange: swap OFB_* and OF_* so it conceptually in sync with other cases of *B_* vs *_* like VETSB_* and VETS_*.
rubidium
parents:
8766
diff
changeset
|
27 |
if (v->cur_order_index == order_number && HasBit(v->current_order.flags, OF_PART_OF_ORDERS)) { |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
28 |
if (is_journey) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
29 |
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
|
30 |
} else { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
31 |
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
|
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 |
|
8305
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
35 |
for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) { |
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
36 |
InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index); |
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
37 |
} |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
38 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
39 |
|
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
40 |
/** |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
41 |
* 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
|
42 |
* @param tile Not used. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
43 |
* @param flags Operation to perform. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
44 |
* @param p1 Various bitstuffed elements |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
45 |
* - 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
|
46 |
* - 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
|
47 |
* - 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
|
48 |
* time. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
49 |
* @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
|
50 |
*/ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
51 |
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
|
52 |
{ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
53 |
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
|
54 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
58 |
Vehicle *v = GetVehicle(veh); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
59 |
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
|
60 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8305
diff
changeset
|
65 |
bool is_journey = HasBit(p1, 24); |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
66 |
if (!is_journey) { |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
67 |
if (order->type != OT_GOTO_STATION) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS); |
8798
eea3a465bd86
(svn r11866) -Codechange: swap OFB_* and OF_* so it conceptually in sync with other cases of *B_* vs *_* like VETSB_* and VETS_*.
rubidium
parents:
8766
diff
changeset
|
68 |
if (_patches.new_nonstop && (order->flags & OFB_NON_STOP)) return_cmd_error(STR_TIMETABLE_NOT_STOPPING_HERE); |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
69 |
} |
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 |
if (flags & DC_EXEC) { |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
72 |
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
|
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 |
return CommandCost(); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
76 |
} |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
77 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
78 |
/** |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
79 |
* 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
|
80 |
* @param tile Not used. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
81 |
* @param flags Operation to perform. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
82 |
* @param p1 Various bitstuffed elements |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
83 |
* - 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
|
84 |
*/ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
85 |
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
|
86 |
{ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
87 |
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
|
88 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
92 |
Vehicle *v = GetVehicle(veh); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
93 |
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
|
94 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
95 |
if (flags & DC_EXEC) { |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
96 |
v->lateness_counter = 0; |
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 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
99 |
return CommandCost(); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
100 |
} |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
101 |
|
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
102 |
/** |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
103 |
* 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
|
104 |
* 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
|
105 |
* 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
|
106 |
* @param tile Not used. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
107 |
* @param flags Operation to perform. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
108 |
* @param p1 Vehicle index. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
109 |
* @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
|
110 |
*/ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
111 |
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
|
112 |
{ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
113 |
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
|
114 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
118 |
Vehicle *v = GetVehicle(veh); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
119 |
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
|
120 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
121 |
if (flags & DC_EXEC) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
122 |
if (p2 == 1) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
123 |
/* 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
|
124 |
* timings and clears the "timetable has started" bit. */ |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8425
diff
changeset
|
125 |
SetBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
8425
72a71d480c5f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
126 |
ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED); |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
127 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
128 |
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
|
129 |
order->wait_time = 0; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
130 |
order->travel_time = 0; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
131 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
132 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
} else { |
8425
72a71d480c5f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
136 |
ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
137 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
138 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
139 |
|
8305
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
140 |
for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) { |
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
141 |
InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index); |
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
142 |
} |
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
143 |
|
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
144 |
return CommandCost(); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
145 |
} |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
146 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
147 |
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
|
148 |
{ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
149 |
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
|
150 |
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
|
151 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
152 |
v->current_order_time = 0; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
153 |
|
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
154 |
if (!_patches.timetabling) return; |
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 |
/* 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
|
157 |
* order, not when travelling from the depot to the first station. */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8305
diff
changeset
|
158 |
if (v->cur_order_index == 0 && !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) { |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8425
diff
changeset
|
159 |
SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED); |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
160 |
return; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
161 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
162 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8305
diff
changeset
|
163 |
if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return; |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
164 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8305
diff
changeset
|
165 |
if (HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) { |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
166 |
if (timetabled == 0) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
167 |
/* 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
|
168 |
* 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
|
169 |
* 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
|
170 |
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
|
171 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
172 |
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
|
173 |
return; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
174 |
} 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
|
175 |
/* 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
|
176 |
* assume that autofill is finished and turn it off again. */ |
8425
72a71d480c5f
(svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
177 |
ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE); |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
178 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
179 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
180 |
|
7558
ca45ff710b35
(svn r10327) -Fix (r10236) [FS#934]: Vehicles wait at stations when they arrive early even
maedhros
parents:
7477
diff
changeset
|
181 |
/* 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
|
182 |
* 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
|
183 |
* when this happens. */ |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
184 |
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
|
185 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
186 |
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
|
187 |
|
8305
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
188 |
for (v = GetFirstVehicleFromSharedList(v); v != NULL; v = v->next_shared) { |
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
189 |
InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index); |
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
190 |
} |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
191 |
} |