author | skidd13 |
Mon, 16 Jun 2008 17:10:55 +0000 | |
changeset 10981 | 20a58e431c29 |
parent 10775 | 7061477bfbcf |
child 11146 | fb7703b62a99 |
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 |
|
10429
1b99254f9607
(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
parents:
10230
diff
changeset
|
3 |
/** @file timetable_cmd.cpp Commands related to time tabling. */ |
7477
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 |
|
10079
99aba130db3c
(svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium
parents:
9344
diff
changeset
|
27 |
if (v->cur_order_index == order_number && v->current_order.GetDepotOrderType() & ODTFB_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. |
9146
2c8c94a75544
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8798
diff
changeset
|
49 |
* - p1 = (bit 25) - Whether p2 contains waiting and travelling time. |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
50 |
* @param p2 The amount of time to wait. |
9146
2c8c94a75544
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8798
diff
changeset
|
51 |
* - p2 = (bit 0-15) - Waiting or travelling time as specified by p1 bit 24 if p1 bit 25 is not set, |
2c8c94a75544
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8798
diff
changeset
|
52 |
* Travelling time if p1 bit 25 is set. |
2c8c94a75544
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8798
diff
changeset
|
53 |
* - p2 = (bit 16-31) - Waiting time if p1 bit 25 is set |
7477
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 |
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
|
56 |
{ |
10775
7061477bfbcf
(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
parents:
10703
diff
changeset
|
57 |
if (!_settings_game.order.timetabling) return CMD_ERROR; |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
58 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
59 |
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
|
60 |
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
|
61 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
62 |
Vehicle *v = GetVehicle(veh); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
63 |
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
|
64 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
|
9146
2c8c94a75544
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8798
diff
changeset
|
69 |
bool packed_time = HasBit(p1, 25); |
2c8c94a75544
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8798
diff
changeset
|
70 |
bool is_journey = HasBit(p1, 24) || packed_time; |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
71 |
if (!is_journey) { |
9332
2e120d0bd632
(svn r12584) -Codechange: do not access the order type directly.
rubidium
parents:
9146
diff
changeset
|
72 |
if (!order->IsType(OT_GOTO_STATION)) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS); |
9344
1be7ac6bd504
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium
parents:
9339
diff
changeset
|
73 |
if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) 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
|
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 |
if (flags & DC_EXEC) { |
9146
2c8c94a75544
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8798
diff
changeset
|
77 |
ChangeTimetable(v, order_number, GB(p2, 0, 16), is_journey); |
2c8c94a75544
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents:
8798
diff
changeset
|
78 |
if (packed_time) ChangeTimetable(v, order_number, GB(p2, 16, 16), false); |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
79 |
} |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
80 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
81 |
return CommandCost(); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
82 |
} |
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 |
/** |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
85 |
* 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
|
86 |
* @param tile Not used. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
87 |
* @param flags Operation to perform. |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
88 |
* @param p1 Various bitstuffed elements |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
89 |
* - 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
|
90 |
*/ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
91 |
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
|
92 |
{ |
10775
7061477bfbcf
(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
parents:
10703
diff
changeset
|
93 |
if (!_settings_game.order.timetabling) return CMD_ERROR; |
7477
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 |
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
|
96 |
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
|
97 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
98 |
Vehicle *v = GetVehicle(veh); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
99 |
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
|
100 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
101 |
if (flags & DC_EXEC) { |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
102 |
v->lateness_counter = 0; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
103 |
} |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
104 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
105 |
return CommandCost(); |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
106 |
} |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
107 |
|
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
108 |
/** |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
109 |
* 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
|
110 |
* 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
|
111 |
* 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
|
112 |
* @param tile Not used. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
113 |
* @param flags Operation to perform. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
114 |
* @param p1 Vehicle index. |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
115 |
* @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
|
116 |
*/ |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
117 |
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
|
118 |
{ |
10775
7061477bfbcf
(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
parents:
10703
diff
changeset
|
119 |
if (!_settings_game.order.timetabling) return CMD_ERROR; |
7562
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 |
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
|
122 |
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
|
123 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
124 |
Vehicle *v = GetVehicle(veh); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
125 |
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
|
126 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
127 |
if (flags & DC_EXEC) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
128 |
if (p2 == 1) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
129 |
/* 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
|
130 |
* 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
|
131 |
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
|
132 |
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
|
133 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
134 |
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
|
135 |
order->wait_time = 0; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
136 |
order->travel_time = 0; |
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 |
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
|
140 |
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
|
141 |
} 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
|
142 |
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
|
143 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
144 |
} |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
145 |
|
8305
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
146 |
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
|
147 |
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
|
148 |
} |
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
149 |
|
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
150 |
return CommandCost(); |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
151 |
} |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
152 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
153 |
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
|
154 |
{ |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
155 |
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
|
156 |
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
|
157 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
158 |
v->current_order_time = 0; |
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
159 |
|
10775
7061477bfbcf
(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
parents:
10703
diff
changeset
|
160 |
if (!_settings_game.order.timetabling) return; |
7562
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 |
/* Make sure the timetable only starts when the vehicle reaches the first |
10230
bf81856a1101
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents:
10079
diff
changeset
|
163 |
* order, not when travelling from the depot to the first station. */ |
bf81856a1101
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents:
10079
diff
changeset
|
164 |
if (v->cur_order_index == 0 && !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) { |
bf81856a1101
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents:
10079
diff
changeset
|
165 |
SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED); |
bf81856a1101
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents:
10079
diff
changeset
|
166 |
return; |
bf81856a1101
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents:
10079
diff
changeset
|
167 |
} |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
168 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
8305
diff
changeset
|
169 |
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
|
170 |
|
10230
bf81856a1101
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents:
10079
diff
changeset
|
171 |
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
|
172 |
if (timetabled == 0) { |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
173 |
/* 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
|
174 |
* 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
|
175 |
* 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
|
176 |
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
|
177 |
|
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
178 |
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
|
179 |
return; |
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
180 |
} 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
|
181 |
/* 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
|
182 |
* 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
|
183 |
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
|
184 |
} |
10230
bf81856a1101
(svn r12762) -Fix: tabs after the first non-tab character are generally not okay (or lines starting with a space and then tabs).
rubidium
parents:
10079
diff
changeset
|
185 |
} |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
186 |
|
7558
ca45ff710b35
(svn r10327) -Fix (r10236) [FS#934]: Vehicles wait at stations when they arrive early even
maedhros
parents:
7477
diff
changeset
|
187 |
/* 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
|
188 |
* 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
|
189 |
* when this happens. */ |
7562
f6f62814907b
(svn r10331) -Feature: Add the possibility of automatically filling in timetables based on
maedhros
parents:
7558
diff
changeset
|
190 |
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
|
191 |
|
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
192 |
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
|
193 |
|
8305
c8b7592ae94b
(svn r11359) -Fix [FS#1381]: shared timetables were not properly refreshed with autofill.
rubidium
parents:
7562
diff
changeset
|
194 |
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
|
195 |
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
|
196 |
} |
7477
1f22e188617e
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
maedhros
parents:
diff
changeset
|
197 |
} |