209 |
209 |
210 extern uint ConvertSpeedToDisplaySpeed(uint speed); |
210 extern uint ConvertSpeedToDisplaySpeed(uint speed); |
211 extern uint ConvertDisplaySpeedToSpeed(uint speed); |
211 extern uint ConvertDisplaySpeedToSpeed(uint speed); |
212 |
212 |
213 |
213 |
|
214 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable) |
|
215 { |
|
216 StringID str = (v->cur_order_index == order_index) ? STR_8805 : STR_8804; |
|
217 SetDParam(6, STR_EMPTY); |
|
218 |
|
219 switch (order->GetType()) { |
|
220 case OT_DUMMY: |
|
221 SetDParam(1, STR_INVALID_ORDER); |
|
222 SetDParam(2, order->GetDestination()); |
|
223 break; |
|
224 |
|
225 case OT_GOTO_STATION: { |
|
226 OrderLoadFlags load = order->GetLoadType(); |
|
227 OrderUnloadFlags unload = order->GetUnloadType(); |
|
228 |
|
229 SetDParam(1, STR_GO_TO_STATION); |
|
230 SetDParam(2, STR_ORDER_GO_TO + ((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? order->GetNonStopType() : 0)); |
|
231 SetDParam(3, order->GetDestination()); |
|
232 |
|
233 if (timetable) { |
|
234 SetDParam(4, STR_EMPTY); |
|
235 |
|
236 if (order->wait_time > 0) { |
|
237 SetDParam(6, STR_TIMETABLE_STAY_FOR); |
|
238 SetTimetableParams(7, 8, order->wait_time); |
|
239 } |
|
240 } else { |
|
241 SetDParam(4, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[unload][load]); |
|
242 } |
|
243 } break; |
|
244 |
|
245 case OT_GOTO_DEPOT: |
|
246 if (v->type == VEH_AIRCRAFT) { |
|
247 if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { |
|
248 SetDParam(1, STR_GO_TO_NEAREST_DEPOT); |
|
249 SetDParam(3, STR_ORDER_NEAREST_HANGAR); |
|
250 } else { |
|
251 SetDParam(1, STR_GO_TO_HANGAR); |
|
252 SetDParam(3, order->GetDestination()); |
|
253 } |
|
254 SetDParam(4, STR_EMPTY); |
|
255 } else { |
|
256 if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { |
|
257 SetDParam(1, STR_GO_TO_NEAREST_DEPOT); |
|
258 SetDParam(3, STR_ORDER_NEAREST_DEPOT); |
|
259 } else { |
|
260 SetDParam(1, STR_GO_TO_DEPOT); |
|
261 SetDParam(3, GetDepot(order->GetDestination())->town_index); |
|
262 } |
|
263 |
|
264 switch (v->type) { |
|
265 case VEH_TRAIN: SetDParam(4, STR_ORDER_TRAIN_DEPOT); break; |
|
266 case VEH_ROAD: SetDParam(4, STR_ORDER_ROAD_DEPOT); break; |
|
267 case VEH_SHIP: SetDParam(4, STR_ORDER_SHIP_DEPOT); break; |
|
268 default: NOT_REACHED(); |
|
269 } |
|
270 } |
|
271 |
|
272 if (order->GetDepotOrderType() & ODTFB_SERVICE) { |
|
273 SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT); |
|
274 } else { |
|
275 SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO); |
|
276 } |
|
277 |
|
278 if (!timetable && order->IsRefit()) { |
|
279 SetDParam(6, STR_REFIT_ORDER); |
|
280 SetDParam(7, GetCargo(order->GetRefitCargo())->name); |
|
281 } |
|
282 break; |
|
283 |
|
284 case OT_GOTO_WAYPOINT: |
|
285 SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT); |
|
286 SetDParam(2, order->GetDestination()); |
|
287 break; |
|
288 |
|
289 case OT_CONDITIONAL: |
|
290 SetDParam(2, order->GetConditionSkipToOrder() + 1); |
|
291 if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) { |
|
292 SetDParam(1, STR_CONDITIONAL_UNCONDITIONAL); |
|
293 } else { |
|
294 OrderConditionComparator occ = order->GetConditionComparator(); |
|
295 SetDParam(1, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_CONDITIONAL_TRUE_FALSE : STR_CONDITIONAL_NUM); |
|
296 SetDParam(3, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable()); |
|
297 SetDParam(4, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ); |
|
298 |
|
299 uint value = order->GetConditionValue(); |
|
300 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value); |
|
301 SetDParam(5, value); |
|
302 } |
|
303 break; |
|
304 |
|
305 default: NOT_REACHED(); |
|
306 } |
|
307 |
|
308 SetDParam(0, order_index + 1); |
|
309 DrawString(2, y, str, selected ? TC_WHITE : TC_BLACK); |
|
310 } |
|
311 |
|
312 |
214 static void DrawOrdersWindow(Window *w) |
313 static void DrawOrdersWindow(Window *w) |
215 { |
314 { |
216 const Vehicle *v = GetVehicle(w->window_number); |
315 const Vehicle *v = GetVehicle(w->window_number); |
217 bool shared_orders = v->IsOrderListShared(); |
316 bool shared_orders = v->IsOrderListShared(); |
218 |
317 |
235 /* delete */ |
334 /* delete */ |
236 w->SetWidgetDisabledState(ORDER_WIDGET_DELETE, |
335 w->SetWidgetDisabledState(ORDER_WIDGET_DELETE, |
237 (uint)v->num_orders + ((shared_orders || v->num_orders != 0) ? 1 : 0) <= (uint)WP(w, order_d).sel); |
336 (uint)v->num_orders + ((shared_orders || v->num_orders != 0) ? 1 : 0) <= (uint)WP(w, order_d).sel); |
238 |
337 |
239 /* non-stop only for trains */ |
338 /* non-stop only for trains */ |
240 w->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP, v->type != VEH_TRAIN || order == NULL); |
339 w->SetWidgetDisabledState(ORDER_WIDGET_NON_STOP, (v->type != VEH_TRAIN && v->type != VEH_ROAD) || order == NULL); |
241 w->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD, order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load |
340 w->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD, order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load |
242 w->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD, order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload |
341 w->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD, order == NULL || (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload |
243 /* Disable list of vehicles with the same shared orders if there is no list */ |
342 /* Disable list of vehicles with the same shared orders if there is no list */ |
244 w->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders || v->orders == NULL); |
343 w->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders || v->orders == NULL); |
245 w->SetWidgetDisabledState(ORDER_WIDGET_REFIT, order == NULL); // Refit |
344 w->SetWidgetDisabledState(ORDER_WIDGET_REFIT, order == NULL); // Refit |
308 |
407 |
309 int i = w->vscroll.pos; |
408 int i = w->vscroll.pos; |
310 order = GetVehicleOrder(v, i); |
409 order = GetVehicleOrder(v, i); |
311 StringID str; |
410 StringID str; |
312 while (order != NULL) { |
411 while (order != NULL) { |
313 str = (v->cur_order_index == i) ? STR_8805 : STR_8804; |
412 /* Don't draw anything if it extends past the end of the window. */ |
314 SetDParam(6, STR_EMPTY); |
413 if (i - w->vscroll.pos >= w->vscroll.cap) break; |
315 |
414 |
316 if (i - w->vscroll.pos < w->vscroll.cap) { |
415 DrawOrderString(v, order, i, y, i == WP(w, order_d).sel, false); |
317 switch (order->GetType()) { |
416 y += 10; |
318 case OT_DUMMY: |
|
319 SetDParam(1, STR_INVALID_ORDER); |
|
320 SetDParam(2, order->GetDestination()); |
|
321 break; |
|
322 |
|
323 case OT_GOTO_STATION: { |
|
324 OrderLoadFlags load = order->GetLoadType(); |
|
325 OrderUnloadFlags unload = order->GetUnloadType(); |
|
326 |
|
327 SetDParam(1, STR_GO_TO_STATION); |
|
328 SetDParam(2, STR_ORDER_GO_TO + (v->type == VEH_TRAIN ? order->GetNonStopType() : 0)); |
|
329 SetDParam(3, order->GetDestination()); |
|
330 SetDParam(4, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[unload][load]); |
|
331 } break; |
|
332 |
|
333 case OT_GOTO_DEPOT: |
|
334 if (v->type == VEH_AIRCRAFT) { |
|
335 if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { |
|
336 SetDParam(1, STR_GO_TO_NEAREST_DEPOT); |
|
337 SetDParam(3, STR_ORDER_NEAREST_HANGAR); |
|
338 } else { |
|
339 SetDParam(1, STR_GO_TO_HANGAR); |
|
340 SetDParam(3, order->GetDestination()); |
|
341 } |
|
342 SetDParam(4, STR_EMPTY); |
|
343 } else { |
|
344 if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { |
|
345 SetDParam(1, STR_GO_TO_NEAREST_DEPOT); |
|
346 SetDParam(3, STR_ORDER_NEAREST_DEPOT); |
|
347 } else { |
|
348 SetDParam(1, STR_GO_TO_DEPOT); |
|
349 SetDParam(3, GetDepot(order->GetDestination())->town_index); |
|
350 } |
|
351 |
|
352 switch (v->type) { |
|
353 case VEH_TRAIN: SetDParam(4, STR_ORDER_TRAIN_DEPOT); break; |
|
354 case VEH_ROAD: SetDParam(4, STR_ORDER_ROAD_DEPOT); break; |
|
355 case VEH_SHIP: SetDParam(4, STR_ORDER_SHIP_DEPOT); break; |
|
356 default: NOT_REACHED(); |
|
357 } |
|
358 } |
|
359 |
|
360 if (order->GetDepotOrderType() & ODTFB_SERVICE) { |
|
361 SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT); |
|
362 } else { |
|
363 SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO); |
|
364 } |
|
365 |
|
366 if (order->IsRefit()) { |
|
367 SetDParam(6, STR_REFIT_ORDER); |
|
368 SetDParam(7, GetCargo(order->GetRefitCargo())->name); |
|
369 } |
|
370 break; |
|
371 |
|
372 case OT_GOTO_WAYPOINT: |
|
373 SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT); |
|
374 SetDParam(2, order->GetDestination()); |
|
375 break; |
|
376 |
|
377 case OT_CONDITIONAL: |
|
378 SetDParam(2, order->GetConditionSkipToOrder() + 1); |
|
379 if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) { |
|
380 SetDParam(1, STR_CONDITIONAL_UNCONDITIONAL); |
|
381 } else { |
|
382 OrderConditionComparator occ = order->GetConditionComparator(); |
|
383 SetDParam(1, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_CONDITIONAL_TRUE_FALSE : STR_CONDITIONAL_NUM); |
|
384 SetDParam(3, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable()); |
|
385 SetDParam(4, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ); |
|
386 |
|
387 uint value = order->GetConditionValue(); |
|
388 if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value); |
|
389 SetDParam(5, value); |
|
390 } |
|
391 break; |
|
392 |
|
393 default: NOT_REACHED(); |
|
394 } |
|
395 |
|
396 SetDParam(0, i + 1); |
|
397 DrawString(2, y, str, (i == WP(w, order_d).sel) ? TC_WHITE : TC_BLACK); |
|
398 |
|
399 y += 10; |
|
400 } |
|
401 |
417 |
402 i++; |
418 i++; |
403 order = order->next; |
419 order = order->next; |
404 } |
420 } |
405 |
421 |
420 switch (GetTileType(tile)) { |
436 switch (GetTileType(tile)) { |
421 case MP_RAILWAY: |
437 case MP_RAILWAY: |
422 if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_player)) { |
438 if (v->type == VEH_TRAIN && IsTileOwner(tile, _local_player)) { |
423 if (IsRailDepot(tile)) { |
439 if (IsRailDepot(tile)) { |
424 order.MakeGoToDepot(GetDepotByTile(tile)->index, ODTFB_PART_OF_ORDERS); |
440 order.MakeGoToDepot(GetDepotByTile(tile)->index, ODTFB_PART_OF_ORDERS); |
|
441 if (_patches.new_nonstop) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS); |
425 return order; |
442 return order; |
426 } |
443 } |
427 } |
444 } |
428 break; |
445 break; |
429 |
446 |
430 case MP_ROAD: |
447 case MP_ROAD: |
431 if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_player)) { |
448 if (IsRoadDepot(tile) && v->type == VEH_ROAD && IsTileOwner(tile, _local_player)) { |
432 order.MakeGoToDepot(GetDepotByTile(tile)->index, ODTFB_PART_OF_ORDERS); |
449 order.MakeGoToDepot(GetDepotByTile(tile)->index, ODTFB_PART_OF_ORDERS); |
|
450 if (_patches.new_nonstop) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS); |
433 return order; |
451 return order; |
434 } |
452 } |
435 break; |
453 break; |
436 |
454 |
437 case MP_STATION: |
455 case MP_STATION: |
461 if (IsTileType(tile, MP_RAILWAY) && |
479 if (IsTileType(tile, MP_RAILWAY) && |
462 v->type == VEH_TRAIN && |
480 v->type == VEH_TRAIN && |
463 IsTileOwner(tile, _local_player) && |
481 IsTileOwner(tile, _local_player) && |
464 IsRailWaypoint(tile)) { |
482 IsRailWaypoint(tile)) { |
465 order.MakeGoToWaypoint(GetWaypointByTile(tile)->index); |
483 order.MakeGoToWaypoint(GetWaypointByTile(tile)->index); |
|
484 if (_patches.new_nonstop) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS); |
466 return order; |
485 return order; |
467 } |
486 } |
468 |
487 |
469 if (IsTileType(tile, MP_STATION)) { |
488 if (IsTileType(tile, MP_STATION)) { |
470 StationID st_index = GetStationIndex(tile); |
489 StationID st_index = GetStationIndex(tile); |