author | dominik |
Sat, 18 Dec 2004 21:11:45 +0000 | |
changeset 711 | 11819c4ef994 |
parent 588 | 1b60458bdc29 |
child 712 | 358ce49745f1 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
340
diff
changeset
|
3 |
#include "table/strings.h" |
0 | 4 |
#include "vehicle.h" |
5 |
#include "command.h" |
|
6 |
#include "station.h" |
|
7 |
#include "player.h" |
|
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
8 |
#include "news.h" |
0 | 9 |
|
10 |
/* p1 & 0xFFFF = vehicle |
|
11 |
* p1 >> 16 = index in order list |
|
12 |
* p2 = order command to insert |
|
13 |
*/ |
|
14 |
int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
15 |
{ |
|
16 |
Vehicle *v = &_vehicles[p1 & 0xFFFF]; |
|
17 |
int sel = p1 >> 16; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
18 |
Order new_order = UnpackOrder(p2); |
0 | 19 |
|
20 |
if (sel > v->num_orders) return_cmd_error(STR_EMPTY); |
|
21 |
if (_ptr_to_next_order == endof(_order_array)) return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); |
|
22 |
if (v->num_orders >= 40) return_cmd_error(STR_8832_TOO_MANY_ORDERS); |
|
23 |
||
24 |
// for ships, make sure that the station is not too far away from the previous destination. |
|
25 |
if (v->type == VEH_Ship && IS_HUMAN_PLAYER(v->owner) && |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
26 |
sel != 0 && v->schedule_ptr[sel - 1].type == OT_GOTO_STATION) { |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
27 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
28 |
int dist = GetTileDist( |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
29 |
DEREF_STATION(v->schedule_ptr[sel - 1].station)->xy, |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
30 |
DEREF_STATION(new_order.station)->xy |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
31 |
); |
0 | 32 |
if (dist >= 130) |
33 |
return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO); |
|
34 |
} |
|
35 |
||
36 |
if (flags & DC_EXEC) { |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
37 |
Order *s1; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
38 |
Order *s2; |
0 | 39 |
Vehicle *u; |
40 |
||
41 |
s1 = &v->schedule_ptr[sel]; |
|
42 |
s2 = _ptr_to_next_order++; |
|
43 |
do s2[1] = s2[0]; while (--s2 >= s1); |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
44 |
*s1 = new_order; |
0 | 45 |
|
46 |
s1 = v->schedule_ptr; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
47 |
|
0 | 48 |
FOR_ALL_VEHICLES(u) { |
49 |
if (u->type != 0 && u->schedule_ptr != NULL) { |
|
50 |
if (s1 < u->schedule_ptr) { |
|
51 |
u->schedule_ptr++; |
|
52 |
} else if (s1 == u->schedule_ptr) { // handle shared orders |
|
53 |
u->num_orders++; |
|
54 |
||
55 |
if ((byte)sel <= u->cur_order_index) { |
|
56 |
sel++; |
|
57 |
if ((byte)sel < u->num_orders) |
|
58 |
u->cur_order_index = sel; |
|
59 |
} |
|
60 |
InvalidateWindow(WC_VEHICLE_VIEW, u->index); |
|
61 |
InvalidateWindow(WC_VEHICLE_ORDERS, u->index); |
|
62 |
} |
|
63 |
} |
|
64 |
} |
|
588 | 65 |
|
66 |
RebuildVehicleLists(); |
|
0 | 67 |
} |
68 |
||
69 |
return 0; |
|
70 |
} |
|
71 |
||
72 |
static int32 DecloneOrder(Vehicle *dst, uint32 flags) |
|
73 |
{ |
|
74 |
if (_ptr_to_next_order == endof(_order_array)) |
|
75 |
return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); |
|
76 |
||
77 |
if (flags & DC_EXEC) { |
|
78 |
DeleteVehicleSchedule(dst); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
79 |
|
0 | 80 |
dst->num_orders = 0; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
81 |
_ptr_to_next_order->type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
82 |
_ptr_to_next_order->flags = 0; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
83 |
dst->schedule_ptr = _ptr_to_next_order++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
84 |
|
0 | 85 |
InvalidateWindow(WC_VEHICLE_ORDERS, dst->index); |
588 | 86 |
|
87 |
RebuildVehicleLists(); |
|
0 | 88 |
} |
89 |
return 0; |
|
90 |
} |
|
91 |
||
92 |
/* p1 = vehicle |
|
93 |
* p2 = sel |
|
94 |
*/ |
|
95 |
int32 CmdDeleteOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
96 |
{ |
|
97 |
Vehicle *v = &_vehicles[p1], *u; |
|
98 |
uint sel = (uint)p2; |
|
99 |
||
100 |
_error_message = STR_EMPTY; |
|
101 |
if (sel >= v->num_orders) |
|
102 |
return DecloneOrder(v, flags); |
|
103 |
||
104 |
if (flags & DC_EXEC) { |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
105 |
Order *s1 = &v->schedule_ptr[sel]; |
0 | 106 |
|
107 |
// copy all orders to get rid of the hole |
|
108 |
do s1[0] = s1[1]; while (++s1 != _ptr_to_next_order); |
|
109 |
_ptr_to_next_order--; |
|
110 |
||
111 |
s1 = v->schedule_ptr; |
|
112 |
||
113 |
FOR_ALL_VEHICLES(u) { |
|
114 |
if (u->type != 0 && u->schedule_ptr != NULL) { |
|
115 |
if (s1 < u->schedule_ptr) { |
|
116 |
u->schedule_ptr--; |
|
117 |
} else if (s1 == u->schedule_ptr) {// handle shared orders |
|
118 |
u->num_orders--; |
|
119 |
if ((byte)sel < u->cur_order_index) |
|
120 |
u->cur_order_index--; |
|
121 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
122 |
if ((byte)sel == u->cur_order_index && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
123 |
u->current_order.type == OT_LOADING && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
124 |
u->current_order.flags & OF_NON_STOP) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
125 |
u->current_order.flags = 0; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
126 |
} |
0 | 127 |
|
128 |
InvalidateWindow(WC_VEHICLE_VIEW, u->index); |
|
129 |
InvalidateWindow(WC_VEHICLE_ORDERS, u->index); |
|
130 |
} |
|
131 |
} |
|
132 |
} |
|
588 | 133 |
|
134 |
RebuildVehicleLists(); |
|
0 | 135 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
136 |
|
0 | 137 |
return 0; |
138 |
} |
|
139 |
||
140 |
/* p1 = vehicle */ |
|
141 |
int32 CmdSkipOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
142 |
{ |
|
143 |
if (flags & DC_EXEC) { |
|
144 |
Vehicle *v = &_vehicles[p1]; |
|
145 |
||
146 |
{ |
|
147 |
byte b = v->cur_order_index + 1; |
|
148 |
if (b >= v->num_orders) b = 0; |
|
149 |
v->cur_order_index = b; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
150 |
|
0 | 151 |
if (v->type == VEH_Train) |
152 |
v->u.rail.days_since_order_progr = 0; |
|
153 |
} |
|
154 |
||
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
155 |
if (v->current_order.type == OT_LOADING && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
156 |
v->current_order.flags & OF_NON_STOP) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
157 |
v->current_order.flags = 0; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
158 |
} |
0 | 159 |
|
160 |
InvalidateWindow(WC_VEHICLE_ORDERS, v->index); |
|
161 |
} |
|
162 |
return 0; |
|
163 |
} |
|
164 |
||
165 |
/* p1 = vehicle |
|
166 |
* p2&0xFF = sel |
|
167 |
* p2>>8 = mode |
|
168 |
*/ |
|
169 |
int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
170 |
{ |
|
171 |
Vehicle *v = &_vehicles[p1]; |
|
172 |
byte sel = (byte)p2; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
173 |
Order *sched; |
0 | 174 |
|
175 |
if (sel >= v->num_orders) |
|
176 |
return CMD_ERROR; |
|
177 |
||
178 |
sched = &v->schedule_ptr[sel]; |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
179 |
if (sched->type != OT_GOTO_STATION && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
180 |
(sched->type != OT_GOTO_DEPOT || (p2 >> 8) == 1)) |
0 | 181 |
return CMD_ERROR; |
182 |
||
183 |
if (flags & DC_EXEC) { |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
184 |
switch (p2 >> 8) { |
0 | 185 |
case 0: // full load |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
186 |
sched->flags ^= OF_FULL_LOAD; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
187 |
if (sched->type != OT_GOTO_DEPOT) sched->flags &= ~OF_UNLOAD; |
0 | 188 |
break; |
189 |
case 1: // unload |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
190 |
sched->flags ^= OF_UNLOAD; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
191 |
sched->flags &= ~OF_FULL_LOAD; |
0 | 192 |
break; |
193 |
case 2: // non stop |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
194 |
sched->flags ^= OF_NON_STOP; |
0 | 195 |
break; |
196 |
} |
|
197 |
sched = v->schedule_ptr; |
|
198 |
||
199 |
FOR_ALL_VEHICLES(v) { |
|
200 |
if (v->schedule_ptr == sched) |
|
201 |
InvalidateWindow(WC_VEHICLE_ORDERS, v->index); |
|
202 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
203 |
|
0 | 204 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
205 |
|
0 | 206 |
return 0; |
207 |
} |
|
208 |
||
209 |
// Clone an order |
|
210 |
// p1 & 0xFFFF is destination vehicle |
|
211 |
// p1 >> 16 is source vehicle |
|
212 |
||
213 |
// p2 is |
|
214 |
// 0 - clone |
|
215 |
// 1 - copy |
|
216 |
// 2 - unclone |
|
217 |
||
218 |
||
219 |
int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
220 |
{ |
|
221 |
Vehicle *dst = &_vehicles[p1 & 0xFFFF]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
222 |
|
0 | 223 |
if (!(dst->type && dst->owner == _current_player)) |
224 |
return CMD_ERROR; |
|
225 |
||
226 |
switch(p2) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
227 |
|
0 | 228 |
// share vehicle orders? |
229 |
case 0: { |
|
230 |
Vehicle *src = &_vehicles[p1 >> 16]; |
|
231 |
||
232 |
// sanity checks |
|
233 |
if (!(src->owner == _current_player && dst->type == src->type && dst != src)) |
|
234 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
235 |
|
29
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
236 |
// let's see what happens with road vehicles |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
237 |
if (src->type == VEH_Road) { |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
238 |
if (src->cargo_type != dst->cargo_type && (src->cargo_type == CT_PASSENGERS || dst->cargo_type == CT_PASSENGERS)) |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
239 |
return CMD_ERROR; |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
240 |
} |
0 | 241 |
|
242 |
if (flags & DC_EXEC) { |
|
243 |
DeleteVehicleSchedule(dst); |
|
244 |
dst->schedule_ptr = src->schedule_ptr; |
|
245 |
dst->num_orders = src->num_orders; |
|
246 |
||
247 |
InvalidateWindow(WC_VEHICLE_ORDERS, src->index); |
|
248 |
InvalidateWindow(WC_VEHICLE_ORDERS, dst->index); |
|
588 | 249 |
|
250 |
RebuildVehicleLists(); |
|
0 | 251 |
} |
252 |
break; |
|
253 |
} |
|
254 |
||
255 |
// copy vehicle orders? |
|
256 |
case 1: { |
|
257 |
Vehicle *src = &_vehicles[p1 >> 16]; |
|
258 |
int delta; |
|
259 |
||
260 |
// sanity checks |
|
261 |
if (!(src->owner == _current_player && dst->type == src->type && dst != src)) |
|
262 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
263 |
|
29
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
264 |
// let's see what happens with road vehicles |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
265 |
if (src->type == VEH_Road) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
266 |
const Order *i; |
29
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
267 |
TileIndex required_dst; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
268 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
269 |
for (i = src->schedule_ptr; i->type != OT_NOTHING; ++i) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
270 |
if (i->type == OT_GOTO_STATION) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
271 |
const Station *st = DEREF_STATION(i->station); |
29
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
272 |
required_dst = (dst->cargo_type == CT_PASSENGERS) ? st->bus_tile : st->lorry_tile; |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
273 |
if ( !required_dst ) |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
274 |
return CMD_ERROR; |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
275 |
} |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
276 |
} |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
277 |
} |
0 | 278 |
|
279 |
// make sure there's orders available |
|
280 |
delta = IsScheduleShared(dst) ? src->num_orders + 1 : src->num_orders - dst->num_orders; |
|
281 |
if (delta > endof(_order_array) - _ptr_to_next_order) |
|
282 |
return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); |
|
283 |
||
284 |
if (flags & DC_EXEC) { |
|
285 |
DeleteVehicleSchedule(dst); |
|
286 |
dst->schedule_ptr = _ptr_to_next_order; |
|
287 |
dst->num_orders = src->num_orders; |
|
288 |
_ptr_to_next_order += src->num_orders + 1; |
|
289 |
memcpy(dst->schedule_ptr, src->schedule_ptr, (src->num_orders + 1) * sizeof(uint16)); |
|
290 |
||
291 |
InvalidateWindow(WC_VEHICLE_ORDERS, dst->index); |
|
588 | 292 |
|
293 |
RebuildVehicleLists(); |
|
0 | 294 |
} |
295 |
break; |
|
296 |
} |
|
297 |
||
298 |
// declone vehicle orders? |
|
299 |
case 2: return DecloneOrder(dst, flags); |
|
300 |
} |
|
301 |
||
302 |
return 0; |
|
303 |
} |
|
304 |
||
305 |
void BackupVehicleOrders(Vehicle *v, BackuppedOrders *bak) |
|
306 |
{ |
|
307 |
Vehicle *u = IsScheduleShared(v); |
|
308 |
||
309 |
bak->orderindex = v->cur_order_index; |
|
310 |
bak->service_interval = v->service_interval; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
311 |
|
0 | 312 |
if ((v->string_id & 0xF800) != 0x7800) { |
313 |
bak->name[0] = 0; |
|
314 |
} else { |
|
315 |
GetName(v->string_id & 0x7FF, bak->name); |
|
316 |
} |
|
317 |
||
318 |
// stored shared orders in this special way? |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
319 |
if (u != NULL) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
320 |
bak->clone = u->index; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
321 |
} else { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
322 |
Order *sched = v->schedule_ptr; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
323 |
Order *os = bak->order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
324 |
|
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
325 |
bak->clone = INVALID_VEHICLE; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
326 |
|
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
327 |
do { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
328 |
*os++ = *sched++; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
329 |
} while (sched->type != OT_NOTHING); |
0 | 330 |
} |
331 |
} |
|
332 |
||
333 |
void RestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak) |
|
334 |
{ |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
335 |
int i; |
0 | 336 |
|
337 |
if (bak->name[0]) { |
|
338 |
strcpy((char*)_decode_parameters, bak->name); |
|
339 |
DoCommandP(0, v->index, 0, NULL, CMD_NAME_VEHICLE); |
|
340 |
} |
|
341 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
342 |
DoCommandP(0, v->index, bak->orderindex|(bak->service_interval<<16) , NULL, CMD_RESTORE_ORDER_INDEX); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
343 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
344 |
if (bak->clone != INVALID_VEHICLE) { |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
345 |
DoCommandP(0, v->index | bak->clone << 16, 0, NULL, CMD_CLONE_ORDER); |
0 | 346 |
return; |
347 |
} |
|
348 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
349 |
// CMD_NO_TEST_IF_IN_NETWORK is used here, because CMD_INSERT_ORDER checks if the |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
350 |
// order number is one more then the current amount of orders, and because |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
351 |
// in network the commands are queued before send, the second insert always |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
352 |
// fails in test mode. By bypassing the test-mode, that no longer is a problem. |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
353 |
for (i = 0; bak->order[i].type != OT_NOTHING; ++i) |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
354 |
if (!DoCommandP(0, v->index + (i << 16), PackOrder(&bak->order[i]), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) |
0 | 355 |
break; |
356 |
} |
|
357 |
||
358 |
/* p1 = vehicle |
|
359 |
* upper 16 bits p2 = service_interval |
|
360 |
* lower 16 bits p2 = cur_order_index |
|
361 |
*/ |
|
362 |
int32 CmdRestoreOrderIndex(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
363 |
{ |
|
364 |
// nonsense to update the windows, since, train rebought will have its window deleted |
|
365 |
if (flags & DC_EXEC) { |
|
366 |
Vehicle *v = &_vehicles[p1]; |
|
367 |
v->service_interval = (uint16)(p2>>16); |
|
368 |
v->cur_order_index = (byte)(p2&0xFFFF); |
|
369 |
} |
|
370 |
return 0; |
|
371 |
} |
|
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
372 |
|
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
373 |
int CheckOrders(Vehicle *v) |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
374 |
{ |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
375 |
if (!_patches.order_review_system) //User doesn't want things to be checked |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
376 |
return 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
377 |
|
711
11819c4ef994
(svn r1163) Fix: [ 1087403 ] Crashed trains aren't reported to have too few orders any more
dominik
parents:
588
diff
changeset
|
378 |
if ( (_patches.order_review_system == 1) && ((v->vehstatus & VS_STOPPED) || (v->vehstatus & VS_CRASHED)) ) |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
379 |
return 0; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
380 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
381 |
/* only check every 20 days, so that we don't flood the message log */ |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
382 |
if ( ( ( v->day_counter % 20) == 0 ) && (v->owner == _local_player) ) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
383 |
Order order; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
384 |
Order old_order; |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
385 |
int i, n_st, problem_type = -1; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
386 |
Station *st; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
387 |
int message=0; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
388 |
TileIndex required_tile=-1; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
389 |
|
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
390 |
/* check the order list */ |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
391 |
order = v->schedule_ptr[0]; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
392 |
n_st = 0; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
393 |
|
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
394 |
old_order.type = OT_NOTHING; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
395 |
old_order.flags = 0; |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
396 |
for (i = 0; order.type != OT_NOTHING; i++) { |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
397 |
order = v->schedule_ptr[i]; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
398 |
if (order.type == old_order.type && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
399 |
order.flags == old_order.flags && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
400 |
order.station == old_order.station) { |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
401 |
problem_type = 2; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
402 |
break; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
403 |
} |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
404 |
if (order.type == OT_DUMMY) { |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
405 |
problem_type = 1; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
406 |
break; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
407 |
} |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
408 |
if (order.type == OT_GOTO_STATION /*&& (order != old_order) */) { |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
409 |
//I uncommented this in order not to get two error messages |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
410 |
//when two identical entries are in the list |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
411 |
n_st++; |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
412 |
st = DEREF_STATION(order.station); |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
413 |
required_tile = GetStationTileForVehicle(v,st); |
294
75aee285ca75
(svn r300) Fix: order checker now correctly detects station with invalid facilities
dominik
parents:
193
diff
changeset
|
414 |
if (!required_tile) problem_type = 3; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
415 |
} |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
416 |
old_order = order; //store the old order |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
417 |
} |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
418 |
|
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
419 |
//Now, check the last and the first order |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
420 |
//as the last order is the end of order marker, jump back 2 |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
421 |
if (i > 2 && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
422 |
v->schedule_ptr[0].type == v->schedule_ptr[i - 2].type && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
423 |
v->schedule_ptr[0].flags == v->schedule_ptr[i - 2].flags && |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
424 |
v->schedule_ptr[0].station == v->schedule_ptr[i - 2].station) |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
425 |
problem_type = 2; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
426 |
|
340
57ae229c5402
(svn r516) Solved a little bug with the order checker.
celestar
parents:
294
diff
changeset
|
427 |
if ( (n_st < 2) && (problem_type == -1) ) problem_type = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
428 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
429 |
SetDParam(0, v->unitnumber); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
430 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
431 |
message = (STR_TRAIN_HAS_TOO_FEW_ORDERS) + (((v->type) - VEH_Train) << 2) + problem_type; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
432 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
433 |
if (problem_type < 0) return 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
434 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
435 |
AddNewsItem( |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
436 |
message, |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
437 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0), |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
438 |
v->index, |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
439 |
0); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
440 |
} |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
441 |
// End of order check |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
442 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
443 |
return 1; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
444 |
} |