author | tron |
Thu, 02 Dec 2004 22:53:07 +0000 | |
changeset 534 | 17ab2f22ff74 |
parent 507 | 8aa8100b0b22 |
child 543 | e3b43338096b |
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; |
|
18 |
int t; |
|
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) && |
|
26 |
sel != 0 && ((t=v->schedule_ptr[sel-1])&OT_MASK) == OT_GOTO_STATION) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
27 |
|
0 | 28 |
int dist = GetTileDist(DEREF_STATION(t >> 8)->xy, DEREF_STATION(p2 >> 8)->xy); |
29 |
if (dist >= 130) |
|
30 |
return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO); |
|
31 |
} |
|
32 |
||
33 |
if (flags & DC_EXEC) { |
|
34 |
uint16 *s1, *s2; |
|
35 |
Vehicle *u; |
|
36 |
||
37 |
s1 = &v->schedule_ptr[sel]; |
|
38 |
s2 = _ptr_to_next_order++; |
|
39 |
do s2[1] = s2[0]; while (--s2 >= s1); |
|
40 |
s1[0] = (uint16)p2; |
|
41 |
||
42 |
s1 = v->schedule_ptr; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
43 |
|
0 | 44 |
FOR_ALL_VEHICLES(u) { |
45 |
if (u->type != 0 && u->schedule_ptr != NULL) { |
|
46 |
if (s1 < u->schedule_ptr) { |
|
47 |
u->schedule_ptr++; |
|
48 |
} else if (s1 == u->schedule_ptr) { // handle shared orders |
|
49 |
u->num_orders++; |
|
50 |
||
51 |
if ((byte)sel <= u->cur_order_index) { |
|
52 |
sel++; |
|
53 |
if ((byte)sel < u->num_orders) |
|
54 |
u->cur_order_index = sel; |
|
55 |
} |
|
56 |
InvalidateWindow(WC_VEHICLE_VIEW, u->index); |
|
57 |
InvalidateWindow(WC_VEHICLE_ORDERS, u->index); |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
return 0; |
|
64 |
} |
|
65 |
||
66 |
static int32 DecloneOrder(Vehicle *dst, uint32 flags) |
|
67 |
{ |
|
68 |
if (_ptr_to_next_order == endof(_order_array)) |
|
69 |
return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); |
|
70 |
||
71 |
if (flags & DC_EXEC) { |
|
72 |
DeleteVehicleSchedule(dst); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
73 |
|
0 | 74 |
dst->num_orders = 0; |
75 |
*(dst->schedule_ptr = _ptr_to_next_order++) = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
76 |
|
0 | 77 |
InvalidateWindow(WC_VEHICLE_ORDERS, dst->index); |
78 |
} |
|
79 |
return 0; |
|
80 |
} |
|
81 |
||
82 |
/* p1 = vehicle |
|
83 |
* p2 = sel |
|
84 |
*/ |
|
85 |
int32 CmdDeleteOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
86 |
{ |
|
87 |
Vehicle *v = &_vehicles[p1], *u; |
|
88 |
uint sel = (uint)p2; |
|
89 |
||
90 |
_error_message = STR_EMPTY; |
|
91 |
if (sel >= v->num_orders) |
|
92 |
return DecloneOrder(v, flags); |
|
93 |
||
94 |
if (flags & DC_EXEC) { |
|
95 |
uint16 *s1; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
96 |
|
0 | 97 |
s1 = &v->schedule_ptr[sel]; |
98 |
||
99 |
// copy all orders to get rid of the hole |
|
100 |
do s1[0] = s1[1]; while (++s1 != _ptr_to_next_order); |
|
101 |
_ptr_to_next_order--; |
|
102 |
||
103 |
s1 = v->schedule_ptr; |
|
104 |
||
105 |
FOR_ALL_VEHICLES(u) { |
|
106 |
if (u->type != 0 && u->schedule_ptr != NULL) { |
|
107 |
if (s1 < u->schedule_ptr) { |
|
108 |
u->schedule_ptr--; |
|
109 |
} else if (s1 == u->schedule_ptr) {// handle shared orders |
|
110 |
u->num_orders--; |
|
111 |
if ((byte)sel < u->cur_order_index) |
|
112 |
u->cur_order_index--; |
|
113 |
||
114 |
if ((byte)sel == u->cur_order_index && (u->next_order&(OT_MASK|OF_NON_STOP)) == (OT_LOADING|OF_NON_STOP)) |
|
115 |
u->next_order = OT_LOADING; |
|
116 |
||
117 |
InvalidateWindow(WC_VEHICLE_VIEW, u->index); |
|
118 |
InvalidateWindow(WC_VEHICLE_ORDERS, u->index); |
|
119 |
} |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
123 |
|
0 | 124 |
return 0; |
125 |
} |
|
126 |
||
127 |
/* p1 = vehicle */ |
|
128 |
int32 CmdSkipOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
129 |
{ |
|
130 |
if (flags & DC_EXEC) { |
|
131 |
Vehicle *v = &_vehicles[p1]; |
|
132 |
||
133 |
{ |
|
134 |
byte b = v->cur_order_index + 1; |
|
135 |
if (b >= v->num_orders) b = 0; |
|
136 |
v->cur_order_index = b; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
137 |
|
0 | 138 |
if (v->type == VEH_Train) |
139 |
v->u.rail.days_since_order_progr = 0; |
|
140 |
} |
|
141 |
||
142 |
if ((v->next_order&(OT_MASK|OF_NON_STOP)) == (OT_LOADING|OF_NON_STOP)) |
|
143 |
v->next_order = OT_LOADING; |
|
144 |
||
145 |
InvalidateWindow(WC_VEHICLE_ORDERS, v->index); |
|
146 |
} |
|
147 |
return 0; |
|
148 |
} |
|
149 |
||
150 |
/* p1 = vehicle |
|
151 |
* p2&0xFF = sel |
|
152 |
* p2>>8 = mode |
|
153 |
*/ |
|
154 |
int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
155 |
{ |
|
156 |
Vehicle *v = &_vehicles[p1]; |
|
157 |
byte sel = (byte)p2; |
|
158 |
uint16 *sched; |
|
159 |
||
160 |
if (sel >= v->num_orders) |
|
161 |
return CMD_ERROR; |
|
162 |
||
163 |
sched = &v->schedule_ptr[sel]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
164 |
if (!((*sched & OT_MASK) == OT_GOTO_STATION || |
0 | 165 |
((*sched & OT_MASK) == OT_GOTO_DEPOT && (p2>>8) != 1))) |
166 |
return CMD_ERROR; |
|
167 |
||
168 |
if (flags & DC_EXEC) { |
|
169 |
switch(p2 >> 8) { |
|
170 |
case 0: // full load |
|
171 |
*sched ^= OF_FULL_LOAD; |
|
172 |
if ((*sched & OT_MASK) != OT_GOTO_DEPOT) |
|
173 |
*sched &= ~OF_UNLOAD; |
|
174 |
break; |
|
175 |
case 1: // unload |
|
176 |
*sched ^= OF_UNLOAD; |
|
177 |
*sched &= ~OF_FULL_LOAD; |
|
178 |
break; |
|
179 |
case 2: // non stop |
|
180 |
*sched ^= OF_NON_STOP; |
|
181 |
break; |
|
182 |
} |
|
183 |
sched = v->schedule_ptr; |
|
184 |
||
185 |
FOR_ALL_VEHICLES(v) { |
|
186 |
if (v->schedule_ptr == sched) |
|
187 |
InvalidateWindow(WC_VEHICLE_ORDERS, v->index); |
|
188 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
189 |
|
0 | 190 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
191 |
|
0 | 192 |
return 0; |
193 |
} |
|
194 |
||
195 |
// Clone an order |
|
196 |
// p1 & 0xFFFF is destination vehicle |
|
197 |
// p1 >> 16 is source vehicle |
|
198 |
||
199 |
// p2 is |
|
200 |
// 0 - clone |
|
201 |
// 1 - copy |
|
202 |
// 2 - unclone |
|
203 |
||
204 |
||
205 |
int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
206 |
{ |
|
207 |
Vehicle *dst = &_vehicles[p1 & 0xFFFF]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
208 |
|
0 | 209 |
if (!(dst->type && dst->owner == _current_player)) |
210 |
return CMD_ERROR; |
|
211 |
||
212 |
switch(p2) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
213 |
|
0 | 214 |
// share vehicle orders? |
215 |
case 0: { |
|
216 |
Vehicle *src = &_vehicles[p1 >> 16]; |
|
217 |
||
218 |
// sanity checks |
|
219 |
if (!(src->owner == _current_player && dst->type == src->type && dst != src)) |
|
220 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
221 |
|
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
|
222 |
// 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
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
} |
0 | 227 |
|
228 |
if (flags & DC_EXEC) { |
|
229 |
DeleteVehicleSchedule(dst); |
|
230 |
dst->schedule_ptr = src->schedule_ptr; |
|
231 |
dst->num_orders = src->num_orders; |
|
232 |
||
233 |
InvalidateWindow(WC_VEHICLE_ORDERS, src->index); |
|
234 |
InvalidateWindow(WC_VEHICLE_ORDERS, dst->index); |
|
235 |
} |
|
236 |
break; |
|
237 |
} |
|
238 |
||
239 |
// copy vehicle orders? |
|
240 |
case 1: { |
|
241 |
Vehicle *src = &_vehicles[p1 >> 16]; |
|
242 |
int delta; |
|
243 |
||
244 |
// sanity checks |
|
245 |
if (!(src->owner == _current_player && dst->type == src->type && dst != src)) |
|
246 |
return CMD_ERROR; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
247 |
|
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
|
248 |
// 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
|
249 |
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
|
250 |
uint16 ord; |
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
|
251 |
int i; |
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
|
252 |
Station *st; |
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
|
253 |
TileIndex required_dst; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
254 |
|
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
|
255 |
for (i=0; (ord = src->schedule_ptr[i]) != 0; i++) { |
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
|
256 |
if ( ( ord & OT_MASK ) == OT_GOTO_STATION ) { |
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
|
257 |
st = DEREF_STATION(ord >> 8); |
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
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
} |
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
|
262 |
} |
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
|
263 |
} |
0 | 264 |
|
265 |
// make sure there's orders available |
|
266 |
delta = IsScheduleShared(dst) ? src->num_orders + 1 : src->num_orders - dst->num_orders; |
|
267 |
if (delta > endof(_order_array) - _ptr_to_next_order) |
|
268 |
return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); |
|
269 |
||
270 |
if (flags & DC_EXEC) { |
|
271 |
DeleteVehicleSchedule(dst); |
|
272 |
dst->schedule_ptr = _ptr_to_next_order; |
|
273 |
dst->num_orders = src->num_orders; |
|
274 |
_ptr_to_next_order += src->num_orders + 1; |
|
275 |
memcpy(dst->schedule_ptr, src->schedule_ptr, (src->num_orders + 1) * sizeof(uint16)); |
|
276 |
||
277 |
InvalidateWindow(WC_VEHICLE_ORDERS, dst->index); |
|
278 |
} |
|
279 |
break; |
|
280 |
} |
|
281 |
||
282 |
// declone vehicle orders? |
|
283 |
case 2: return DecloneOrder(dst, flags); |
|
284 |
} |
|
285 |
||
286 |
return 0; |
|
287 |
} |
|
288 |
||
289 |
void BackupVehicleOrders(Vehicle *v, BackuppedOrders *bak) |
|
290 |
{ |
|
291 |
Vehicle *u = IsScheduleShared(v); |
|
292 |
uint16 *sched, ord, *os; |
|
293 |
||
294 |
bak->orderindex = v->cur_order_index; |
|
295 |
bak->service_interval = v->service_interval; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
296 |
|
0 | 297 |
if ((v->string_id & 0xF800) != 0x7800) { |
298 |
bak->name[0] = 0; |
|
299 |
} else { |
|
300 |
GetName(v->string_id & 0x7FF, bak->name); |
|
301 |
} |
|
302 |
||
303 |
os = bak->order; |
|
304 |
// stored shared orders in this special way? |
|
305 |
if (u) { |
|
306 |
os[0] = 0xFFFF; |
|
307 |
os[1] = u->index; |
|
308 |
return; |
|
309 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
310 |
|
0 | 311 |
sched = v->schedule_ptr; |
312 |
do { |
|
313 |
ord = *sched++; |
|
314 |
*os++ = ord; |
|
315 |
} while (ord != 0); |
|
316 |
} |
|
317 |
||
318 |
void RestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak) |
|
319 |
{ |
|
320 |
uint16 ord, *os; |
|
321 |
int ind; |
|
322 |
||
323 |
if (bak->name[0]) { |
|
324 |
strcpy((char*)_decode_parameters, bak->name); |
|
325 |
DoCommandP(0, v->index, 0, NULL, CMD_NAME_VEHICLE); |
|
326 |
} |
|
327 |
||
328 |
DoCommandP(0, v->index, bak->orderindex|(bak->service_interval<<16) , NULL, CMD_RESTORE_ORDER_INDEX | CMD_ASYNC); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
329 |
|
0 | 330 |
os = bak->order; |
331 |
if (os[0] == 0xFFFF) { |
|
332 |
DoCommandP(0, v->index | os[1]<<16, 0, NULL, CMD_CLONE_ORDER); |
|
333 |
return; |
|
334 |
} |
|
335 |
||
336 |
ind = 0; |
|
337 |
while ((ord = *os++) != 0) { |
|
338 |
if (!DoCommandP(0, v->index + (ind << 16), ord, NULL, CMD_INSERT_ORDER | CMD_ASYNC)) |
|
339 |
break; |
|
340 |
ind++; |
|
341 |
} |
|
342 |
} |
|
343 |
||
344 |
/* p1 = vehicle |
|
345 |
* upper 16 bits p2 = service_interval |
|
346 |
* lower 16 bits p2 = cur_order_index |
|
347 |
*/ |
|
348 |
int32 CmdRestoreOrderIndex(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
|
349 |
{ |
|
350 |
// nonsense to update the windows, since, train rebought will have its window deleted |
|
351 |
if (flags & DC_EXEC) { |
|
352 |
Vehicle *v = &_vehicles[p1]; |
|
353 |
v->service_interval = (uint16)(p2>>16); |
|
354 |
v->cur_order_index = (byte)(p2&0xFFFF); |
|
355 |
} |
|
356 |
return 0; |
|
357 |
} |
|
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
358 |
|
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
359 |
int CheckOrders(Vehicle *v) |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
360 |
{ |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
361 |
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
|
362 |
return 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
363 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
364 |
if ( (_patches.order_review_system == 1) && (v->vehstatus & VS_STOPPED) ) |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
365 |
return 0; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
366 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
367 |
/* 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
|
368 |
if ( ( ( v->day_counter % 20) == 0 ) && (v->owner == _local_player) ) { |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
369 |
|
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
370 |
uint16 order, old_order; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
371 |
int i, n_st, problem_type = -1; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
372 |
Station *st; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
373 |
int message=0; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
374 |
TileIndex required_tile=-1; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
375 |
|
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
376 |
/* check the order list */ |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
377 |
order = v->schedule_ptr[0]; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
378 |
n_st = 0; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
379 |
|
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
380 |
for (old_order = i = 0; order!=0; i++ ) { |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
381 |
order = v->schedule_ptr[i]; |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
382 |
if (order == old_order) { |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
383 |
problem_type = 2; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
384 |
break; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
385 |
} |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
386 |
if ( (order & OT_MASK) == OT_DUMMY ) { |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
387 |
problem_type = 1; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
388 |
break; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
389 |
} |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
390 |
if ( ( (order & OT_MASK) == OT_GOTO_STATION ) /*&& (order != old_order) */) { |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
391 |
//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
|
392 |
//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
|
393 |
n_st++; |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
394 |
st = DEREF_STATION(order >> 8); |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
395 |
required_tile = GetStationTileForVehicle(v,st); |
294
75aee285ca75
(svn r300) Fix: order checker now correctly detects station with invalid facilities
dominik
parents:
193
diff
changeset
|
396 |
if (!required_tile) problem_type = 3; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
397 |
} |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
398 |
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
|
399 |
} |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
400 |
|
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
401 |
//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
|
402 |
//as the last order is the end of order marker, jump back 2 |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
403 |
if ( (v->schedule_ptr[0] == v->schedule_ptr[i-2]) && ( i-2 != 0 ) ) { |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
404 |
problem_type = 2; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
405 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
406 |
|
340
57ae229c5402
(svn r516) Solved a little bug with the order checker.
celestar
parents:
294
diff
changeset
|
407 |
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
|
408 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
409 |
SetDParam(0, v->unitnumber); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
410 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
411 |
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
|
412 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
413 |
if (problem_type < 0) return 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
414 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
415 |
AddNewsItem( |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
416 |
message, |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
417 |
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
|
418 |
v->index, |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
419 |
0); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
420 |
} |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
421 |
// End of order check |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
422 |
|
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
423 |
return 1; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
424 |
} |