OpenTTD
order_gui.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "stdafx.h"
13 #include "command_func.h"
14 #include "viewport_func.h"
15 #include "depot_map.h"
16 #include "roadveh.h"
17 #include "timetable.h"
18 #include "strings_func.h"
19 #include "company_func.h"
20 #include "widgets/dropdown_type.h"
21 #include "widgets/dropdown_func.h"
22 #include "textbuf_gui.h"
23 #include "string_func.h"
24 #include "tilehighlight_func.h"
25 #include "network/network.h"
26 #include "station_base.h"
27 #include "industry.h"
28 #include "waypoint_base.h"
29 #include "core/geometry_func.hpp"
30 #include "hotkeys.h"
31 #include "aircraft.h"
32 #include "engine_func.h"
33 
34 #include "widgets/order_widget.h"
35 
36 #include "safeguards.h"
37 
38 
40 static const StringID _station_load_types[][5][5] = {
41  {
42  /* No refitting. */
43  {
44  STR_EMPTY,
46  STR_ORDER_FULL_LOAD,
47  STR_ORDER_FULL_LOAD_ANY,
48  STR_ORDER_NO_LOAD,
49  }, {
50  STR_ORDER_UNLOAD,
52  STR_ORDER_UNLOAD_FULL_LOAD,
53  STR_ORDER_UNLOAD_FULL_LOAD_ANY,
54  STR_ORDER_UNLOAD_NO_LOAD,
55  }, {
56  STR_ORDER_TRANSFER,
58  STR_ORDER_TRANSFER_FULL_LOAD,
59  STR_ORDER_TRANSFER_FULL_LOAD_ANY,
60  STR_ORDER_TRANSFER_NO_LOAD,
61  }, {
62  /* Unload and transfer do not work together. */
67  }, {
68  STR_ORDER_NO_UNLOAD,
70  STR_ORDER_NO_UNLOAD_FULL_LOAD,
71  STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
72  STR_ORDER_NO_UNLOAD_NO_LOAD,
73  }
74  }, {
75  /* With auto-refitting. No loading and auto-refitting do not work together. */
76  {
77  STR_ORDER_AUTO_REFIT,
79  STR_ORDER_FULL_LOAD_REFIT,
80  STR_ORDER_FULL_LOAD_ANY_REFIT,
82  }, {
83  STR_ORDER_UNLOAD_REFIT,
85  STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
86  STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
88  }, {
89  STR_ORDER_TRANSFER_REFIT,
91  STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
92  STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
94  }, {
95  /* Unload and transfer do not work together. */
100  }, {
101  STR_ORDER_NO_UNLOAD_REFIT,
103  STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
104  STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
106  }
107  }
108 };
109 
110 static const StringID _order_non_stop_drowdown[] = {
111  STR_ORDER_GO_TO,
112  STR_ORDER_GO_NON_STOP_TO,
113  STR_ORDER_GO_VIA,
114  STR_ORDER_GO_NON_STOP_VIA,
116 };
117 
118 static const StringID _order_full_load_drowdown[] = {
119  STR_ORDER_DROP_LOAD_IF_POSSIBLE,
120  STR_EMPTY,
121  STR_ORDER_DROP_FULL_LOAD_ALL,
122  STR_ORDER_DROP_FULL_LOAD_ANY,
123  STR_ORDER_DROP_NO_LOADING,
125 };
126 
127 static const StringID _order_unload_drowdown[] = {
128  STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
129  STR_ORDER_DROP_UNLOAD,
130  STR_ORDER_DROP_TRANSFER,
131  STR_EMPTY,
132  STR_ORDER_DROP_NO_UNLOADING,
134 };
135 
136 static const StringID _order_goto_dropdown[] = {
137  STR_ORDER_GO_TO,
138  STR_ORDER_GO_TO_NEAREST_DEPOT,
139  STR_ORDER_CONDITIONAL,
140  STR_ORDER_SHARE,
142 };
143 
144 static const StringID _order_goto_dropdown_aircraft[] = {
145  STR_ORDER_GO_TO,
146  STR_ORDER_GO_TO_NEAREST_HANGAR,
147  STR_ORDER_CONDITIONAL,
148  STR_ORDER_SHARE,
150 };
151 
158  OCV_AGE,
162 };
163 
164 static const StringID _order_conditional_condition[] = {
165  STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS,
166  STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS,
167  STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN,
168  STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS,
169  STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN,
170  STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS,
171  STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE,
172  STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE,
174 };
175 
176 extern uint ConvertSpeedToDisplaySpeed(uint speed);
177 extern uint ConvertDisplaySpeedToSpeed(uint speed);
178 
179 static const StringID _order_depot_action_dropdown[] = {
180  STR_ORDER_DROP_GO_ALWAYS_DEPOT,
181  STR_ORDER_DROP_SERVICE_DEPOT,
182  STR_ORDER_DROP_HALT_DEPOT,
184 };
185 
186 static int DepotActionStringIndex(const Order *order)
187 {
188  if (order->GetDepotActionType() & ODATFB_HALT) {
189  return DA_STOP;
190  } else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
191  return DA_SERVICE;
192  } else {
193  return DA_ALWAYS_GO;
194  }
195 }
196 
197 static const StringID _order_refit_action_dropdown[] = {
198  STR_ORDER_DROP_REFIT_AUTO,
199  STR_ORDER_DROP_REFIT_AUTO_ANY,
201 };
202 
215 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
216 {
217  bool rtl = _current_text_dir == TD_RTL;
218 
219  SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT;
220  Dimension sprite_size = GetSpriteSize(sprite);
221  if (v->cur_real_order_index == order_index) {
222  DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
223  DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
224  } else if (v->cur_implicit_order_index == order_index) {
225  DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2);
226  }
227 
228  TextColour colour = TC_BLACK;
229  if (order->IsType(OT_IMPLICIT)) {
230  colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
231  } else if (selected) {
232  colour = TC_WHITE;
233  }
234 
235  SetDParam(0, order_index + 1);
236  DrawString(left, rtl ? right - 2 * sprite_size.width - 3 : middle, y, STR_ORDER_INDEX, colour, SA_RIGHT | SA_FORCE);
237 
238  SetDParam(5, STR_EMPTY);
239  SetDParam(8, STR_EMPTY);
240 
241  /* Check range for aircraft. */
242  if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
243  const Order *next = order->next != NULL ? order->next : v->GetFirstOrder();
244  if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) SetDParam(8, STR_ORDER_OUT_OF_RANGE);
245  }
246 
247  switch (order->GetType()) {
248  case OT_DUMMY:
249  SetDParam(0, STR_INVALID_ORDER);
250  SetDParam(1, order->GetDestination());
251  break;
252 
253  case OT_IMPLICIT:
254  SetDParam(0, STR_ORDER_GO_TO_STATION);
255  SetDParam(1, STR_ORDER_GO_TO);
256  SetDParam(2, order->GetDestination());
257  SetDParam(3, timetable ? STR_EMPTY : STR_ORDER_IMPLICIT);
258  break;
259 
260  case OT_GOTO_STATION: {
261  OrderLoadFlags load = order->GetLoadType();
262  OrderUnloadFlags unload = order->GetUnloadType();
263 
264  SetDParam(0, STR_ORDER_GO_TO_STATION);
265  SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
266  SetDParam(2, order->GetDestination());
267 
268  if (timetable) {
269  SetDParam(3, STR_EMPTY);
270 
271  if (order->GetWaitTime() > 0) {
272  SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_STAY_FOR : STR_TIMETABLE_STAY_FOR_ESTIMATED);
273  SetTimetableParams(6, 7, order->GetWaitTime());
274  }
275  } else {
276  SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
277  if (order->IsRefit()) {
278  SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
279  }
280  if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
281  SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
282  }
283  }
284  break;
285  }
286 
287  case OT_GOTO_DEPOT:
288  if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
289  SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT);
290  if (v->type == VEH_AIRCRAFT) {
291  SetDParam(2, STR_ORDER_NEAREST_HANGAR);
292  SetDParam(3, STR_EMPTY);
293  } else {
294  SetDParam(2, STR_ORDER_NEAREST_DEPOT);
295  SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type);
296  }
297  } else {
298  SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT);
299  SetDParam(2, v->type);
300  SetDParam(3, order->GetDestination());
301  }
302 
303  if (order->GetDepotOrderType() & ODTFB_SERVICE) {
304  SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_SERVICE_NON_STOP_AT : STR_ORDER_SERVICE_AT);
305  } else {
306  SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
307  }
308 
309  if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
310  SetDParam(5, STR_ORDER_STOP_ORDER);
311  }
312 
313  if (!timetable && order->IsRefit()) {
314  SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER);
315  SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name);
316  }
317  break;
318 
319  case OT_GOTO_WAYPOINT:
320  SetDParam(0, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO_WAYPOINT : STR_ORDER_GO_TO_WAYPOINT);
321  SetDParam(1, order->GetDestination());
322  break;
323 
324  case OT_CONDITIONAL:
325  SetDParam(1, order->GetConditionSkipToOrder() + 1);
326  if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
327  SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
328  } else {
330  SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
331  SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
332  SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
333 
334  uint value = order->GetConditionValue();
335  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
336  SetDParam(4, value);
337  }
338 
339  if (timetable && order->GetWaitTime() > 0) {
340  SetDParam(5, order->IsWaitTimetabled() ? STR_TIMETABLE_AND_TRAVEL_FOR : STR_TIMETABLE_AND_TRAVEL_FOR_ESTIMATED);
341  SetTimetableParams(6, 7, order->GetWaitTime());
342  } else {
343  SetDParam(5, STR_EMPTY);
344  }
345  break;
346 
347  default: NOT_REACHED();
348  }
349 
350  DrawString(rtl ? left : middle, rtl ? middle : right, y, STR_ORDER_TEXT, colour);
351 }
352 
360 {
361  /* Hack-ish; unpack order 0, so everything gets initialised with either zero
362  * or a suitable default value for the variable. Then also override the index
363  * as it is not coming from a pool, so would be initialised. */
364  Order order(0);
365  order.index = 0;
366 
367  /* check depot first */
368  if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
369  order.MakeGoToDepot(v->type == VEH_AIRCRAFT ? GetStationIndex(tile) : GetDepotIndex(tile),
372 
374 
375  return order;
376  }
377 
378  /* check rail waypoint */
379  if (IsRailWaypointTile(tile) &&
380  v->type == VEH_TRAIN &&
381  IsTileOwner(tile, _local_company)) {
382  order.MakeGoToWaypoint(GetStationIndex(tile));
384  return order;
385  }
386 
387  /* check buoy (no ownership) */
388  if (IsBuoyTile(tile) && v->type == VEH_SHIP) {
389  order.MakeGoToWaypoint(GetStationIndex(tile));
390  return order;
391  }
392 
393  /* check for station or industry with neutral station */
394  if (IsTileType(tile, MP_STATION) || IsTileType(tile, MP_INDUSTRY)) {
395  const Station *st = nullptr;
396 
397  if (IsTileType(tile, MP_INDUSTRY)) {
398  const Industry *in = Industry::GetByTile(tile);
399  tile = in->location.tile;
400  }
401 
402  if (IsTileType(tile, MP_STATION)) st = Station::GetByTile(tile);
403 
404  if (st != nullptr && (st->owner == _local_company || st->owner == OWNER_NONE)) {
405  byte facil;
406  (facil = FACIL_DOCK, v->type == VEH_SHIP) ||
407  (facil = FACIL_TRAIN, v->type == VEH_TRAIN) ||
408  (facil = FACIL_AIRPORT, v->type == VEH_AIRCRAFT) ||
409  (facil = FACIL_BUS_STOP, v->type == VEH_ROAD && RoadVehicle::From(v)->IsBus()) ||
410  (facil = FACIL_TRUCK_STOP, 1);
411  if (st->facilities & facil) {
412  StationID st_index = GetStationIndex(st->xy);
413  order.MakeGoToStation(st_index);
417  return order;
418  }
419  }
420  }
421 
422  /* not found */
423  order.Free();
424  return order;
425 }
426 
428 enum {
429  OHK_SKIP,
430  OHK_DELETE,
431  OHK_GOTO,
432  OHK_NONSTOP,
433  OHK_FULLLOAD,
434  OHK_UNLOAD,
435  OHK_NEAREST_DEPOT,
436  OHK_ALWAYS_SERVICE,
437  OHK_TRANSFER,
438  OHK_NO_UNLOAD,
439  OHK_NO_LOAD,
440 };
441 
482 struct OrdersWindow : public Window {
483 private:
486  OPOS_NONE,
487  OPOS_GOTO,
488  OPOS_CONDITIONAL,
489  OPOS_SHARE,
490  OPOS_END,
491  };
492 
494  enum DisplayPane {
495  /* WID_O_SEL_TOP_ROW_GROUNDVEHICLE */
498 
499  /* WID_O_SEL_TOP_LEFT */
502 
503  /* WID_O_SEL_TOP_MIDDLE */
506 
507  /* WID_O_SEL_TOP_RIGHT */
510 
511  /* WID_O_SEL_TOP_ROW */
515 
516  /* WID_O_SEL_BOTTOM_MIDDLE */
519  };
520 
521  int selected_order;
523  OrderPlaceObjectState goto_type;
524  const Vehicle *vehicle;
525  Scrollbar *vscroll;
528 
535  {
536  int num = this->selected_order;
537  return (num >= 0 && num < vehicle->GetNumOrders()) ? num : vehicle->GetNumOrders();
538  }
539 
549  {
550  NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
551  int sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
552 
553  if ((uint)sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
554 
555  sel += this->vscroll->GetPosition();
556 
557  return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
558  }
559 
564  {
565  assert(type > OPOS_NONE && type < OPOS_END);
566 
567  static const HighLightStyle goto_place_style[OPOS_END - 1] = {
568  HT_RECT | HT_VEHICLE, // OPOS_GOTO
569  HT_NONE, // OPOS_CONDITIONAL
570  HT_VEHICLE, // OPOS_SHARE
571  };
572  SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
573  this->goto_type = type;
574  this->SetWidgetDirty(WID_O_GOTO);
575  }
576 
581  void OrderClick_FullLoad(int load_type)
582  {
583  VehicleOrderID sel_ord = this->OrderGetSel();
584  const Order *order = this->vehicle->GetOrder(sel_ord);
585 
586  if (order == NULL || order->GetLoadType() == load_type) return;
587 
588  if (load_type < 0) {
590  }
591  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (load_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
592  }
593 
598  {
600  }
601 
605  void OrderClick_Service(int i)
606  {
607  VehicleOrderID sel_ord = this->OrderGetSel();
608 
609  if (i < 0) {
610  const Order *order = this->vehicle->GetOrder(sel_ord);
611  if (order == NULL) return;
613  }
614  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_DEPOT_ACTION | (i << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
615  }
616 
621  {
622  Order order;
623  order.next = NULL;
624  order.index = 0;
628 
629  DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
630  }
631 
635  void OrderClick_Unload(int unload_type)
636  {
637  VehicleOrderID sel_ord = this->OrderGetSel();
638  const Order *order = this->vehicle->GetOrder(sel_ord);
639 
640  if (order == NULL || order->GetUnloadType() == unload_type) return;
641 
642  if (unload_type < 0) {
644  }
645 
646  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_UNLOAD | (unload_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
647 
648  /* Transfer orders with leave empty as default */
649  if (unload_type == OUFB_TRANSFER) {
650  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
652  }
653  }
654 
659  {
661  }
662 
667  {
669  }
670 
675  void OrderClick_Nonstop(int non_stop)
676  {
677  if (!this->vehicle->IsGroundVehicle()) return;
678 
679  VehicleOrderID sel_ord = this->OrderGetSel();
680  const Order *order = this->vehicle->GetOrder(sel_ord);
681 
682  if (order == NULL || order->GetNonStopType() == non_stop) return;
683 
684  /* Keypress if negative, so 'toggle' to the next */
685  if (non_stop < 0) {
687  }
688 
690  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_NON_STOP | non_stop << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
691  }
692 
698  {
699  /* Don't skip when there's nothing to skip */
700  if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
701  if (this->vehicle->GetNumOrders() <= 1) return;
702 
703  DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()),
704  CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
705  }
706 
711  {
712  /* When networking, move one order lower */
713  int selected = this->selected_order + (int)_networking;
714 
715  if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
716  this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
717  this->UpdateButtonState();
718  }
719  }
720 
728  {
729  /* Don't try to stop sharing orders if 'End of Shared Orders' isn't selected. */
730  if (!this->vehicle->IsOrderListShared() || this->selected_order != this->vehicle->GetNumOrders()) return;
731  /* If Ctrl is pressed, delete the order list as if we clicked the 'Delete' button. */
732  if (_ctrl_pressed) {
733  this->OrderClick_Delete();
734  return;
735  }
736 
737  /* Get another vehicle that share orders with this vehicle. */
738  Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
739  /* Copy the order list of the other vehicle. */
740  if (DoCommandP(this->vehicle->tile, this->vehicle->index | CO_COPY << 30, other_shared->index, CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST))) {
741  this->UpdateButtonState();
742  }
743  }
744 
751  void OrderClick_Refit(int i, bool auto_refit)
752  {
753  if (_ctrl_pressed) {
754  /* Cancel refitting */
755  DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
756  } else {
757  if (i == 1) { // Auto-refit to available cargo type.
758  DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
759  } else {
760  ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
761  }
762  }
763  }
764 
767  {
768  this->can_do_refit = false;
769  this->can_do_autorefit = false;
770  for (const Vehicle *w = this->vehicle; w != NULL; w = w->IsGroundVehicle() ? w->Next() : NULL) {
771  if (IsEngineRefittable(w->engine_type)) this->can_do_refit = true;
772  if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
773  }
774  }
775 
776 public:
777  OrdersWindow(WindowDesc *desc, const Vehicle *v) : Window(desc)
778  {
779  this->vehicle = v;
780 
781  this->CreateNestedTree();
782  this->vscroll = this->GetScrollbar(WID_O_SCROLLBAR);
783  this->FinishInitNested(v->index);
784  if (v->owner == _local_company) {
785  this->DisableWidget(WID_O_EMPTY);
786  }
787 
788  this->selected_order = -1;
789  this->order_over = INVALID_VEH_ORDER_ID;
790  this->goto_type = OPOS_NONE;
791  this->owner = v->owner;
792 
793  this->UpdateAutoRefitState();
794 
796  /* If there are less than 2 station, make Go To active. */
797  int station_orders = 0;
798  const Order *order;
799  FOR_VEHICLE_ORDERS(v, order) {
800  if (order->IsType(OT_GOTO_STATION)) station_orders++;
801  }
802 
803  if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
804  }
806  }
807 
808  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
809  {
810  switch (widget) {
811  case WID_O_ORDER_LIST:
812  resize->height = FONT_HEIGHT_NORMAL;
813  size->height = 6 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
814  break;
815 
816  case WID_O_COND_VARIABLE: {
817  Dimension d = {0, 0};
818  for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
819  d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
820  }
821  d.width += padding.width;
822  d.height += padding.height;
823  *size = maxdim(*size, d);
824  break;
825  }
826 
827  case WID_O_COND_COMPARATOR: {
828  Dimension d = {0, 0};
829  for (int i = 0; _order_conditional_condition[i] != INVALID_STRING_ID; i++) {
830  d = maxdim(d, GetStringBoundingBox(_order_conditional_condition[i]));
831  }
832  d.width += padding.width;
833  d.height += padding.height;
834  *size = maxdim(*size, d);
835  break;
836  }
837  }
838  }
839 
845  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
846  {
849 
850  switch (data) {
851  case VIWD_AUTOREPLACE:
852  /* Autoreplace replaced the vehicle */
853  this->vehicle = Vehicle::Get(this->window_number);
854  FALLTHROUGH;
855 
857  /* Vehicle composition was changed. */
858  this->UpdateAutoRefitState();
859  break;
860 
862  /* Removed / replaced all orders (after deleting / sharing) */
863  if (this->selected_order == -1) break;
864 
865  this->DeleteChildWindows();
866  HideDropDownMenu(this);
867  this->selected_order = -1;
868  break;
869 
870  case VIWD_MODIFY_ORDERS:
871  /* Some other order changes */
872  break;
873 
874  default:
875  if (data < 0) break;
876 
877  if (gui_scope) break; // only do this once; from command scope
878  from = GB(data, 0, 8);
879  to = GB(data, 8, 8);
880  /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
881  * the order is being created / removed */
882  if (this->selected_order == -1) break;
883 
884  if (from == to) break; // no need to change anything
885 
886  if (from != this->selected_order) {
887  /* Moving from preceding order? */
888  this->selected_order -= (int)(from <= this->selected_order);
889  /* Moving to preceding order? */
890  this->selected_order += (int)(to <= this->selected_order);
891  break;
892  }
893 
894  /* Now we are modifying the selected order */
895  if (to == INVALID_VEH_ORDER_ID) {
896  /* Deleting selected order */
897  this->DeleteChildWindows();
898  HideDropDownMenu(this);
899  this->selected_order = -1;
900  break;
901  }
902 
903  /* Moving selected order */
904  this->selected_order = to;
905  break;
906  }
907 
908  this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
909  if (gui_scope) this->UpdateButtonState();
910 
911  /* Scroll to the new order. */
912  if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {
913  this->vscroll->ScrollTowards(to);
914  }
915  }
916 
917  void UpdateButtonState()
918  {
919  if (this->vehicle->owner != _local_company) return; // No buttons are displayed with competitor order windows.
920 
921  bool shared_orders = this->vehicle->IsOrderListShared();
922  VehicleOrderID sel = this->OrderGetSel();
923  const Order *order = this->vehicle->GetOrder(sel);
924 
925  /* Second row. */
926  /* skip */
927  this->SetWidgetDisabledState(WID_O_SKIP, this->vehicle->GetNumOrders() <= 1);
928 
929  /* delete / stop sharing */
930  NWidgetStacked *delete_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_BOTTOM_MIDDLE);
931  if (shared_orders && this->selected_order == this->vehicle->GetNumOrders()) {
932  /* The 'End of Shared Orders' order is selected, show the 'stop sharing' button. */
934  } else {
935  /* The 'End of Shared Orders' order isn't selected, show the 'delete' button. */
936  delete_sel->SetDisplayedPlane(DP_BOTTOM_MIDDLE_DELETE);
938  (uint)this->vehicle->GetNumOrders() + ((shared_orders || this->vehicle->GetNumOrders() != 0) ? 1 : 0) <= (uint)this->selected_order);
939 
940  /* Set the tooltip of the 'delete' button depending on whether the
941  * 'End of Orders' order or a regular order is selected. */
942  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_O_DELETE);
943  if (this->selected_order == this->vehicle->GetNumOrders()) {
944  nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_ALL_TOOLTIP);
945  } else {
946  nwi->SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP);
947  }
948  }
949 
950  /* First row. */
952  this->RaiseWidget(WID_O_UNLOAD);
953  this->RaiseWidget(WID_O_SERVICE);
954 
955  /* Selection widgets. */
956  /* Train or road vehicle. */
957  NWidgetStacked *train_row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW_GROUNDVEHICLE);
958  NWidgetStacked *left_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_LEFT);
959  NWidgetStacked *middle_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_MIDDLE);
960  NWidgetStacked *right_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_RIGHT);
961  /* Ship or airplane. */
962  NWidgetStacked *row_sel = this->GetWidget<NWidgetStacked>(WID_O_SEL_TOP_ROW);
963  assert(row_sel != NULL || (train_row_sel != NULL && left_sel != NULL && middle_sel != NULL && right_sel != NULL));
964 
965 
966  if (order == NULL) {
967  if (row_sel != NULL) {
968  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
969  } else {
971  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
972  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
973  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
976  }
980  } else {
983 
984  switch (order->GetType()) {
985  case OT_GOTO_STATION:
986  if (row_sel != NULL) {
987  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
988  } else {
990  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
991  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
992  right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
995  }
998 
999  /* Can only do refitting when stopping at the destination and loading cargo.
1000  * Also enable the button if a refit is already set to allow clearing it. */
1003  ((!this->can_do_refit || !this->can_do_autorefit) && !order->IsRefit()));
1004 
1005  break;
1006 
1007  case OT_GOTO_WAYPOINT:
1008  if (row_sel != NULL) {
1009  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1010  } else {
1012  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1013  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1014  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1017  }
1019  this->DisableWidget(WID_O_UNLOAD);
1021  break;
1022 
1023  case OT_GOTO_DEPOT:
1024  if (row_sel != NULL) {
1025  row_sel->SetDisplayedPlane(DP_ROW_DEPOT);
1026  } else {
1028  left_sel->SetDisplayedPlane(DP_LEFT_REFIT);
1029  middle_sel->SetDisplayedPlane(DP_MIDDLE_SERVICE);
1030  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1033  }
1034  /* Disable refit button if the order is no 'always go' order.
1035  * However, keep the service button enabled for refit-orders to allow clearing refits (without knowing about ctrl). */
1037  (order->GetDepotOrderType() & ODTFB_SERVICE) || (order->GetDepotActionType() & ODATFB_HALT) ||
1038  (!this->can_do_refit && !order->IsRefit()));
1040  break;
1041 
1042  case OT_CONDITIONAL: {
1043  if (row_sel != NULL) {
1044  row_sel->SetDisplayedPlane(DP_ROW_CONDITIONAL);
1045  } else {
1047  }
1049  /* Set the strings for the dropdown boxes. */
1050  this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv;
1051  this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order->GetConditionComparator()];
1054  break;
1055  }
1056 
1057  default: // every other order
1058  if (row_sel != NULL) {
1059  row_sel->SetDisplayedPlane(DP_ROW_LOAD);
1060  } else {
1062  left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
1063  middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
1064  right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
1066  }
1068  this->DisableWidget(WID_O_UNLOAD);
1070  break;
1071  }
1072  }
1073 
1074  /* Disable list of vehicles with the same shared orders if there is no list */
1075  this->SetWidgetDisabledState(WID_O_SHARED_ORDER_LIST, !shared_orders);
1076 
1077  this->SetDirty();
1078  }
1079 
1080  virtual void OnPaint()
1081  {
1082  if (this->vehicle->owner != _local_company) {
1083  this->selected_order = -1; // Disable selection any selected row at a competitor order window.
1084  } else {
1085  this->SetWidgetLoweredState(WID_O_GOTO, this->goto_type != OPOS_NONE);
1086  }
1087  this->DrawWidgets();
1088  }
1089 
1090  virtual void DrawWidget(const Rect &r, int widget) const
1091  {
1092  if (widget != WID_O_ORDER_LIST) return;
1093 
1094  bool rtl = _current_text_dir == TD_RTL;
1095  SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
1096  int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
1097  int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
1098 
1099  int y = r.top + WD_FRAMERECT_TOP;
1100  int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
1101 
1102  int i = this->vscroll->GetPosition();
1103  const Order *order = this->vehicle->GetOrder(i);
1104  /* First draw the highlighting underground if it exists. */
1105  if (this->order_over != INVALID_VEH_ORDER_ID) {
1106  while (order != NULL) {
1107  /* Don't draw anything if it extends past the end of the window. */
1108  if (!this->vscroll->IsVisible(i)) break;
1109 
1110  if (i != this->selected_order && i == this->order_over) {
1111  /* Highlight dragged order destination. */
1112  int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
1113  int bottom = min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
1114  top = max(top - 3, r.top + WD_FRAMERECT_TOP);
1115  GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
1116  break;
1117  }
1118  y += line_height;
1119 
1120  i++;
1121  order = order->next;
1122  }
1123 
1124  /* Reset counters for drawing the orders. */
1125  y = r.top + WD_FRAMERECT_TOP;
1126  i = this->vscroll->GetPosition();
1127  order = this->vehicle->GetOrder(i);
1128  }
1129 
1130  /* Draw the orders. */
1131  while (order != NULL) {
1132  /* Don't draw anything if it extends past the end of the window. */
1133  if (!this->vscroll->IsVisible(i)) break;
1134 
1135  DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
1136  y += line_height;
1137 
1138  i++;
1139  order = order->next;
1140  }
1141 
1142  if (this->vscroll->IsVisible(i)) {
1143  StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
1144  DrawString(rtl ? r.left + WD_FRAMETEXT_LEFT : middle, rtl ? middle : r.right - WD_FRAMETEXT_RIGHT, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
1145  }
1146  }
1147 
1148  virtual void SetStringParameters(int widget) const
1149  {
1150  switch (widget) {
1151  case WID_O_COND_VALUE: {
1152  VehicleOrderID sel = this->OrderGetSel();
1153  const Order *order = this->vehicle->GetOrder(sel);
1154 
1155  if (order != NULL && order->IsType(OT_CONDITIONAL)) {
1156  uint value = order->GetConditionValue();
1157  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1158  SetDParam(0, value);
1159  }
1160  break;
1161  }
1162 
1163  case WID_O_CAPTION:
1164  SetDParam(0, this->vehicle->index);
1165  break;
1166  }
1167  }
1168 
1169  virtual void OnClick(Point pt, int widget, int click_count)
1170  {
1171  switch (widget) {
1172  case WID_O_ORDER_LIST: {
1173  if (this->goto_type == OPOS_CONDITIONAL) {
1174  VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
1175  if (order_id != INVALID_VEH_ORDER_ID) {
1176  Order order;
1177  order.next = NULL;
1178  order.index = 0;
1179  order.MakeConditional(order_id);
1180 
1181  DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
1182  }
1184  break;
1185  }
1186 
1187  VehicleOrderID sel = this->GetOrderFromPt(pt.y);
1188 
1189  if (_ctrl_pressed && sel < this->vehicle->GetNumOrders()) {
1190  TileIndex xy = this->vehicle->GetOrder(sel)->GetLocation(this->vehicle);
1191  if (xy != INVALID_TILE) ScrollMainWindowToTile(xy);
1192  return;
1193  }
1194 
1195  /* This order won't be selected any more, close all child windows and dropdowns */
1196  this->DeleteChildWindows();
1197  HideDropDownMenu(this);
1198 
1199  if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
1200  /* Deselect clicked order */
1201  this->selected_order = -1;
1202  } else if (sel == this->selected_order) {
1203  if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
1204  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
1205  MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
1206  CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1207  }
1208  } else {
1209  /* Select clicked order */
1210  this->selected_order = sel;
1211 
1212  if (this->vehicle->owner == _local_company) {
1213  /* Activate drag and drop */
1214  SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
1215  }
1216  }
1217 
1218  this->UpdateButtonState();
1219  break;
1220  }
1221 
1222  case WID_O_SKIP:
1223  this->OrderClick_Skip();
1224  break;
1225 
1226  case WID_O_DELETE:
1227  this->OrderClick_Delete();
1228  break;
1229 
1230  case WID_O_STOP_SHARING:
1231  this->OrderClick_StopSharing();
1232  break;
1233 
1234  case WID_O_NON_STOP:
1235  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1236  this->OrderClick_Nonstop(-1);
1237  } else {
1238  const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1239  ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
1240  o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
1241  }
1242  break;
1243 
1244  case WID_O_GOTO:
1245  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1246  if (this->goto_type != OPOS_NONE) {
1248  } else {
1249  this->OrderClick_Goto(OPOS_GOTO);
1250  }
1251  } else {
1252  int sel;
1253  switch (this->goto_type) {
1254  case OPOS_NONE: sel = -1; break;
1255  case OPOS_GOTO: sel = 0; break;
1256  case OPOS_CONDITIONAL: sel = 2; break;
1257  case OPOS_SHARE: sel = 3; break;
1258  default: NOT_REACHED();
1259  }
1260  ShowDropDownMenu(this, this->vehicle->type == VEH_AIRCRAFT ? _order_goto_dropdown_aircraft : _order_goto_dropdown, sel, WID_O_GOTO, 0, 0);
1261  }
1262  break;
1263 
1264  case WID_O_FULL_LOAD:
1265  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1266  this->OrderClick_FullLoad(-1);
1267  } else {
1268  ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
1269  }
1270  break;
1271 
1272  case WID_O_UNLOAD:
1273  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1274  this->OrderClick_Unload(-1);
1275  } else {
1276  ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
1277  }
1278  break;
1279 
1280  case WID_O_REFIT:
1281  this->OrderClick_Refit(0, false);
1282  break;
1283 
1284  case WID_O_SERVICE:
1285  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1286  this->OrderClick_Service(-1);
1287  } else {
1288  ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(this->vehicle->GetOrder(this->OrderGetSel())), WID_O_SERVICE, 0, 0);
1289  }
1290  break;
1291 
1292  case WID_O_REFIT_DROPDOWN:
1293  if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
1294  this->OrderClick_Refit(0, true);
1295  } else {
1296  ShowDropDownMenu(this, _order_refit_action_dropdown, 0, WID_O_REFIT_DROPDOWN, 0, 0);
1297  }
1298  break;
1299 
1300  case WID_O_TIMETABLE_VIEW:
1301  ShowTimetableWindow(this->vehicle);
1302  break;
1303 
1304  case WID_O_COND_VARIABLE: {
1305  DropDownList *list = new DropDownList();
1306  for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
1307  *list->Append() = new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false);
1308  }
1309  ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), WID_O_COND_VARIABLE);
1310  break;
1311  }
1312 
1313  case WID_O_COND_COMPARATOR: {
1314  const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
1315  ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0);
1316  break;
1317  }
1318 
1319  case WID_O_COND_VALUE: {
1320  const Order *order = this->vehicle->GetOrder(this->OrderGetSel());
1321  uint value = order->GetConditionValue();
1322  if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
1323  SetDParam(0, value);
1324  ShowQueryString(STR_JUST_INT, STR_ORDER_CONDITIONAL_VALUE_CAPT, 5, this, CS_NUMERAL, QSF_NONE);
1325  break;
1326  }
1327 
1329  ShowVehicleListWindow(this->vehicle);
1330  break;
1331  }
1332  }
1333 
1334  virtual void OnQueryTextFinished(char *str)
1335  {
1336  if (!StrEmpty(str)) {
1337  VehicleOrderID sel = this->OrderGetSel();
1338  uint value = atoi(str);
1339 
1340  switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
1341  case OCV_MAX_SPEED:
1342  value = ConvertDisplaySpeedToSpeed(value);
1343  break;
1344 
1345  case OCV_RELIABILITY:
1346  case OCV_LOAD_PERCENTAGE:
1347  value = Clamp(value, 0, 100);
1348  break;
1349 
1350  default:
1351  break;
1352  }
1353  DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20), MOF_COND_VALUE | Clamp(value, 0, 2047) << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1354  }
1355  }
1356 
1357  virtual void OnDropdownSelect(int widget, int index)
1358  {
1359  switch (widget) {
1360  case WID_O_NON_STOP:
1361  this->OrderClick_Nonstop(index);
1362  break;
1363 
1364  case WID_O_FULL_LOAD:
1365  this->OrderClick_FullLoad(index);
1366  break;
1367 
1368  case WID_O_UNLOAD:
1369  this->OrderClick_Unload(index);
1370  break;
1371 
1372  case WID_O_GOTO:
1373  switch (index) {
1374  case 0: this->OrderClick_Goto(OPOS_GOTO); break;
1375  case 1: this->OrderClick_NearestDepot(); break;
1376  case 2: this->OrderClick_Goto(OPOS_CONDITIONAL); break;
1377  case 3: this->OrderClick_Goto(OPOS_SHARE); break;
1378  default: NOT_REACHED();
1379  }
1380  break;
1381 
1382  case WID_O_SERVICE:
1383  this->OrderClick_Service(index);
1384  break;
1385 
1386  case WID_O_REFIT_DROPDOWN:
1387  this->OrderClick_Refit(index, true);
1388  break;
1389 
1390  case WID_O_COND_VARIABLE:
1391  DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_VARIABLE | index << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1392  break;
1393 
1394  case WID_O_COND_COMPARATOR:
1395  DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_COMPARATOR | index << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
1396  break;
1397  }
1398  }
1399 
1400  virtual void OnDragDrop(Point pt, int widget)
1401  {
1402  switch (widget) {
1403  case WID_O_ORDER_LIST: {
1404  VehicleOrderID from_order = this->OrderGetSel();
1405  VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1406 
1407  if (!(from_order == to_order || from_order == INVALID_VEH_ORDER_ID || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_VEH_ORDER_ID || to_order > this->vehicle->GetNumOrders()) &&
1408  DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
1409  this->selected_order = -1;
1410  this->UpdateButtonState();
1411  }
1412  break;
1413  }
1414 
1415  case WID_O_DELETE:
1416  this->OrderClick_Delete();
1417  break;
1418 
1419  case WID_O_STOP_SHARING:
1420  this->OrderClick_StopSharing();
1421  break;
1422  }
1423 
1425 
1426  if (this->order_over != INVALID_VEH_ORDER_ID) {
1427  /* End of drag-and-drop, hide dragged order destination highlight. */
1428  this->order_over = INVALID_VEH_ORDER_ID;
1430  }
1431  }
1432 
1433  virtual EventState OnHotkey(int hotkey)
1434  {
1435  if (this->vehicle->owner != _local_company) return ES_NOT_HANDLED;
1436 
1437  switch (hotkey) {
1438  case OHK_SKIP: this->OrderClick_Skip(); break;
1439  case OHK_DELETE: this->OrderClick_Delete(); break;
1440  case OHK_GOTO: this->OrderClick_Goto(OPOS_GOTO); break;
1441  case OHK_NONSTOP: this->OrderClick_Nonstop(-1); break;
1442  case OHK_FULLLOAD: this->OrderClick_FullLoad(-1); break;
1443  case OHK_UNLOAD: this->OrderClick_Unload(-1); break;
1444  case OHK_NEAREST_DEPOT: this->OrderClick_NearestDepot(); break;
1445  case OHK_ALWAYS_SERVICE: this->OrderClick_Service(-1); break;
1446  case OHK_TRANSFER: this->OrderHotkey_Transfer(); break;
1447  case OHK_NO_UNLOAD: this->OrderHotkey_NoUnload(); break;
1448  case OHK_NO_LOAD: this->OrderHotkey_NoLoad(); break;
1449  default: return ES_NOT_HANDLED;
1450  }
1451  return ES_HANDLED;
1452  }
1453 
1454  virtual void OnPlaceObject(Point pt, TileIndex tile)
1455  {
1456  if (this->goto_type == OPOS_GOTO) {
1457  const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
1458  if (cmd.IsType(OT_NOTHING)) return;
1459 
1460  if (DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), cmd.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER))) {
1461  /* With quick goto the Go To button stays active */
1463  }
1464  }
1465  }
1466 
1467  virtual bool OnVehicleSelect(const Vehicle *v)
1468  {
1469  /* v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet.
1470  * We disallow copying orders of other vehicles if we already have at least one order entry
1471  * ourself as it easily copies orders of vehicles within a station when we mean the station.
1472  * Obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
1473  * TODO: give a warning message */
1474  bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
1475  if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
1476 
1477  if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index,
1478  share_order ? CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_COPY_ORDER_LIST))) {
1479  this->selected_order = -1;
1481  }
1482  return true;
1483  }
1484 
1485  virtual void OnPlaceObjectAbort()
1486  {
1487  this->goto_type = OPOS_NONE;
1488  this->SetWidgetDirty(WID_O_GOTO);
1489 
1490  /* Remove drag highlighting if it exists. */
1491  if (this->order_over != INVALID_VEH_ORDER_ID) {
1492  this->order_over = INVALID_VEH_ORDER_ID;
1494  }
1495  }
1496 
1497  virtual void OnMouseDrag(Point pt, int widget)
1498  {
1499  if (this->selected_order != -1 && widget == WID_O_ORDER_LIST) {
1500  /* An order is dragged.. */
1501  VehicleOrderID from_order = this->OrderGetSel();
1502  VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
1503  uint num_orders = this->vehicle->GetNumOrders();
1504 
1505  if (from_order != INVALID_VEH_ORDER_ID && from_order <= num_orders) {
1506  if (to_order != INVALID_VEH_ORDER_ID && to_order <= num_orders) { // ..over an existing order.
1507  this->order_over = to_order;
1508  this->SetWidgetDirty(widget);
1509  } else if (from_order != to_order && this->order_over != INVALID_VEH_ORDER_ID) { // ..outside of the order list.
1510  this->order_over = INVALID_VEH_ORDER_ID;
1511  this->SetWidgetDirty(widget);
1512  }
1513  }
1514  }
1515  }
1516 
1517  virtual void OnResize()
1518  {
1519  /* Update the scroll bar */
1520  this->vscroll->SetCapacityFromWidget(this, WID_O_ORDER_LIST);
1521  }
1522 
1523  static HotkeyList hotkeys;
1524 };
1525 
1526 static Hotkey order_hotkeys[] = {
1527  Hotkey('D', "skip", OHK_SKIP),
1528  Hotkey('F', "delete", OHK_DELETE),
1529  Hotkey('G', "goto", OHK_GOTO),
1530  Hotkey('H', "nonstop", OHK_NONSTOP),
1531  Hotkey('J', "fullload", OHK_FULLLOAD),
1532  Hotkey('K', "unload", OHK_UNLOAD),
1533  Hotkey((uint16)0, "nearest_depot", OHK_NEAREST_DEPOT),
1534  Hotkey((uint16)0, "always_service", OHK_ALWAYS_SERVICE),
1535  Hotkey((uint16)0, "transfer", OHK_TRANSFER),
1536  Hotkey((uint16)0, "no_unload", OHK_NO_UNLOAD),
1537  Hotkey((uint16)0, "no_load", OHK_NO_LOAD),
1538  HOTKEY_LIST_END
1539 };
1540 HotkeyList OrdersWindow::hotkeys("order", order_hotkeys);
1541 
1545  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1546  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1547  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1548  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1549  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1550  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1551  EndContainer(),
1553  NWidget(WWT_PANEL, COLOUR_GREY, WID_O_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR), EndContainer(),
1554  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1555  EndContainer(),
1556 
1557  /* First button row. */
1561  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_NON_STOP), SetMinimalSize(93, 12), SetFill(1, 0),
1562  SetDataTip(STR_ORDER_NON_STOP, STR_ORDER_TOOLTIP_NON_STOP), SetResize(1, 0),
1563  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_LEFT),
1564  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1565  SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1566  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(93, 12), SetFill(1, 0),
1567  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1568  EndContainer(),
1569  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_MIDDLE),
1570  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(93, 12), SetFill(1, 0),
1571  SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1572  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(93, 12), SetFill(1, 0),
1573  SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1574  EndContainer(),
1575  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_RIGHT),
1576  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
1577  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1579  SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1580  EndContainer(),
1581  EndContainer(),
1583  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1584  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1585  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1586  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1587  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1588  SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1589  EndContainer(),
1590  EndContainer(),
1591  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_O_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
1592  EndContainer(),
1593 
1594  /* Second button row. */
1597  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1598  SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1600  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1601  SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1602  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1603  SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1604  EndContainer(),
1605  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1606  SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1607  EndContainer(),
1608  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1609  EndContainer(),
1610 };
1611 
1612 static WindowDesc _orders_train_desc(
1613  WDP_AUTO, "view_vehicle_orders_train", 384, 100,
1616  _nested_orders_train_widgets, lengthof(_nested_orders_train_widgets),
1617  &OrdersWindow::hotkeys
1618 );
1619 
1623  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1624  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1625  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1626  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1627  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1628  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1629  EndContainer(),
1631  NWidget(WWT_PANEL, COLOUR_GREY, WID_O_ORDER_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR), EndContainer(),
1632  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1633  EndContainer(),
1634 
1635  /* First button row. */
1637  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_TOP_ROW),
1638  /* Load + unload + refit buttons. */
1640  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1641  SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
1642  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
1643  SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
1645  SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
1646  EndContainer(),
1647  /* Refit + service buttons. */
1649  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_REFIT), SetMinimalSize(186, 12), SetFill(1, 0),
1650  SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
1651  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_SERVICE), SetMinimalSize(124, 12), SetFill(1, 0),
1652  SetDataTip(STR_ORDER_SERVICE, STR_ORDER_SERVICE_TOOLTIP), SetResize(1, 0),
1653  EndContainer(),
1654 
1655  /* Buttons for setting a condition. */
1657  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_VARIABLE), SetMinimalSize(124, 12), SetFill(1, 0),
1658  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
1659  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
1660  SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
1661  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
1662  SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
1663  EndContainer(),
1664  EndContainer(),
1665 
1666  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_O_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
1667  EndContainer(),
1668 
1669  /* Second button row. */
1671  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_SKIP), SetMinimalSize(124, 12), SetFill(1, 0),
1672  SetDataTip(STR_ORDERS_SKIP_BUTTON, STR_ORDERS_SKIP_TOOLTIP), SetResize(1, 0),
1674  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_DELETE), SetMinimalSize(124, 12), SetFill(1, 0),
1675  SetDataTip(STR_ORDERS_DELETE_BUTTON, STR_ORDERS_DELETE_TOOLTIP), SetResize(1, 0),
1676  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_STOP_SHARING), SetMinimalSize(124, 12), SetFill(1, 0),
1677  SetDataTip(STR_ORDERS_STOP_SHARING_BUTTON, STR_ORDERS_STOP_SHARING_TOOLTIP), SetResize(1, 0),
1678  EndContainer(),
1679  NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, WID_O_GOTO), SetMinimalSize(124, 12), SetFill(1, 0),
1680  SetDataTip(STR_ORDERS_GO_TO_BUTTON, STR_ORDERS_GO_TO_TOOLTIP), SetResize(1, 0),
1681  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1682  EndContainer(),
1683 };
1684 
1685 static WindowDesc _orders_desc(
1686  WDP_AUTO, "view_vehicle_orders", 384, 100,
1689  _nested_orders_widgets, lengthof(_nested_orders_widgets),
1690  &OrdersWindow::hotkeys
1691 );
1692 
1696  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1697  NWidget(WWT_CAPTION, COLOUR_GREY, WID_O_CAPTION), SetDataTip(STR_ORDERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1698  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_TIMETABLE_VIEW), SetMinimalSize(61, 14), SetDataTip(STR_ORDERS_TIMETABLE_VIEW, STR_ORDERS_TIMETABLE_VIEW_TOOLTIP),
1699  NWidget(WWT_SHADEBOX, COLOUR_GREY),
1700  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1701  NWidget(WWT_STICKYBOX, COLOUR_GREY),
1702  EndContainer(),
1704  NWidget(WWT_PANEL, COLOUR_GREY, WID_O_ORDER_LIST), SetMinimalSize(372, 72), SetDataTip(0x0, STR_ORDERS_LIST_TOOLTIP), SetResize(1, 1), SetScrollbar(WID_O_SCROLLBAR), EndContainer(),
1706  NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_O_SCROLLBAR),
1707  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1708  EndContainer(),
1709  EndContainer(),
1710 };
1711 
1712 static WindowDesc _other_orders_desc(
1713  WDP_AUTO, "view_vehicle_orders_competitor", 384, 86,
1716  _nested_other_orders_widgets, lengthof(_nested_other_orders_widgets),
1717  &OrdersWindow::hotkeys
1718 );
1719 
1720 void ShowOrdersWindow(const Vehicle *v)
1721 {
1724  if (BringWindowToFrontById(WC_VEHICLE_ORDERS, v->index) != NULL) return;
1725 
1726  /* Using a different WindowDescs for _local_company causes problems.
1727  * Due to this we have to close order windows in ChangeWindowOwner/DeleteCompanyWindows,
1728  * because we cannot change switch the WindowDescs and keeping the old WindowDesc results
1729  * in crashed due to missing widges.
1730  * TODO Rewrite the order GUI to not use different WindowDescs.
1731  */
1732  if (v->owner != _local_company) {
1733  new OrdersWindow(&_other_orders_desc, v);
1734  } else {
1735  new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);
1736  }
1737 }
OrderConditionVariable
Variables (of a vehicle) to &#39;cause&#39; skipping on.
Definition: order_type.h:118
EventState
State of handling an event.
Definition: window_type.h:713
void OrderClick_NearestDepot()
Handle the click on the service in nearest depot button.
Definition: order_gui.cpp:620
NWID_SELECTION widget for the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:38
Functions related to OTTD&#39;s strings.
Display the row for normal/depot orders in the top row of the train/rv order window.
Definition: order_gui.cpp:496
Road vehicle states.
static const StringID _station_load_types[][5][5]
Order load types that could be given to station orders.
Definition: order_gui.cpp:40
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
uint ConvertSpeedToDisplaySpeed(uint speed)
Convert the given (internal) speed to the display speed.
Definition: strings.cpp:727
bool _networking
are we in networking mode?
Definition: network.cpp:56
Passes an OrderUnloadType.
Definition: order_type.h:152
ResizeInfo resize
Resize information.
Definition: window_gui.h:324
void OrderClick_StopSharing()
Handle the click on the &#39;stop sharing&#39; button.
Definition: order_gui.cpp:727
bool quick_goto
Allow quick access to &#39;goto button&#39; in vehicle orders window.
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:731
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Goto non-stop to destination.
Definition: order_widget.h:24
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1851
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
Definition: gfx.cpp:113
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:394
Point pos
logical mouse position
Definition: gfx_type.h:119
Stop sharing orders.
Definition: order_widget.h:23
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:455
Load as long as there is cargo that fits in the train.
Definition: order_type.h:69
void OrderClick_Skip()
Handle the click on the skip button.
Definition: order_gui.cpp:697
Delete selected order.
Definition: order_widget.h:22
bool IsGotoOrder() const
Is this a &#39;goto&#39; order with a real destination?
Definition: order_base.h:86
OrderConditionComparator GetConditionComparator() const
What is the comparator to use?
Definition: order_base.h:143
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition: order_gui.cpp:845
All data for a single hotkey.
Definition: hotkeys.h:24
High level window description.
Definition: window_gui.h:168
Open list of shared vehicles.
Definition: order_widget.h:41
Part of an industry.
Definition: tile_type.h:51
Functions related to time tabling.
static const NWidgetPart _nested_other_orders_widgets[]
Nested widget definition for competitor orders.
Definition: order_gui.cpp:1694
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:604
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Hotkey related functions.
static const NWidgetPart _nested_orders_widgets[]
Nested widget definition for "your" orders (non-train).
Definition: order_gui.cpp:1621
void OrderClick_Refit(int i, bool auto_refit)
Handle the click on the refit button.
Definition: order_gui.cpp:751
Scrollbar data structure.
Definition: widget_type.h:589
Vehicle composition was changed.
Definition: vehicle_gui.h:36
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:405
VehicleOrderID GetConditionSkipToOrder() const
Get the order to skip to.
Definition: order_base.h:145
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:581
virtual void OnDragDrop(Point pt, int widget)
A dragged &#39;object&#39; has been released.
Definition: order_gui.cpp:1400
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Definition: order_type.h:23
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
Other order modifications.
Definition: vehicle_gui.h:35
Horizontal container.
Definition: widget_type.h:75
The passed event is not handled.
Definition: window_type.h:715
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:53
void SetDepotOrderType(OrderDepotTypeFlags depot_order_type)
Set the cause to go to the depot.
Definition: order_base.h:158
void OrderClick_Unload(int unload_type)
Handle the click on the unload button.
Definition: order_gui.cpp:635
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1064
NWID_SELECTION widget for right part of the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:37
void SetDepotActionType(OrderDepotActionFlags depot_service_type)
Set what we are going to do in the depot.
Definition: order_base.h:160
uint8 stop_location
what is the default stop location of trains?
Definition: settings_type.h:92
Select service (at depot).
Definition: order_widget.h:29
const Vehicle * vehicle
Vehicle owning the orders being displayed and manipulated.
Definition: order_gui.cpp:524
Placeholder for refit dropdown when not owner.
Definition: order_widget.h:30
Selects the OrderDepotAction.
Definition: order_type.h:154
Skip if the variable is true.
Definition: order_type.h:140
Skip based on the reliability.
Definition: order_type.h:120
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
A comparator changes.
Definition: order_type.h:156
Vehicle data structure.
Definition: vehicle_base.h:212
int top
y position of top edge of the window
Definition: window_gui.h:320
Unload all cargo that the station accepts.
Definition: order_type.h:59
Defines the internal data of a functional industry.
Definition: industry.h:41
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
Close box (at top-left of a window)
Definition: widget_type.h:69
bool can_do_autorefit
Vehicle chain can be auto-refitted.
Definition: order_gui.cpp:527
Display &#39;refit&#39; in the left button of the top row of the train/rv order window.
Definition: order_gui.cpp:501
Base for aircraft.
static bool IsRailWaypointTile(TileIndex t)
Is this tile a station tile and a rail waypoint?
Definition: station_map.h:124
void OrderClick_Nonstop(int non_stop)
Handle the click on the nonstop button.
Definition: order_gui.cpp:675
clone (and share) an order
Definition: command_type.h:271
Stuff related to the text buffer GUI.
void UpdateAutoRefitState()
Cache auto-refittability of the vehicle chain.
Definition: order_gui.cpp:766
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:404
Automatically choose cargo type when doing auto refitting.
Definition: cargo_type.h:68
void OrderClick_Goto(OrderPlaceObjectState type)
Handle the click on the goto button.
Definition: order_gui.cpp:563
Display &#39;refit&#39; / &#39;service&#39; buttons in the top row of the ship/airplane order window.
Definition: order_gui.cpp:513
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
Skip based on the age.
Definition: order_type.h:122
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:485
TileIndex GetLocation(const Vehicle *v, bool airport=false) const
Returns a tile somewhat representing the order destination (not suitable for pathfinding).
Definition: order_cmd.cpp:671
Common string list item.
Definition: dropdown_type.h:41
NWID_SELECTION widget for the middle part of the bottom row of the &#39;your train&#39; order window...
Definition: order_widget.h:40
static Aircraft * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1812
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
Definition: cargo_type.h:69
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
Definition: order_base.h:139
skip an order to the next of specific one
Definition: command_type.h:227
The vehicle will stop at any station it passes except the destination.
Definition: order_type.h:81
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
Definition: order_gui.cpp:1454
uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth)
Get the distance between two orders of a vehicle.
Definition: order_cmd.cpp:698
T * Append(uint to_add=1)
Append an item and return it.
Order * next
Pointer to next order. If NULL, end of list.
Definition: order_base.h:51
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:675
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
Force the alignment, i.e. don&#39;t swap for RTL languages.
Definition: gfx_func.h:110
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
bool IsAutoRefit() const
Is this order a auto-refit order.
Definition: order_base.h:117
Functions related to (drawing on) viewports.
Select refit.
Definition: order_widget.h:28
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Definition: order_gui.cpp:1357
Display &#39;load&#39; in the left button of the top row of the train/rv order window.
Definition: order_gui.cpp:500
bool IsEngineRefittable(EngineID engine)
Check if an engine is refittable.
Definition: engine.cpp:1110
Data structure for an opened window.
Definition: window_gui.h:278
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:36
Stop at the far end of the platform.
Definition: order_type.h:92
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1828
The vehicle will stop at any station it passes and the destination.
Definition: order_type.h:79
Autoreplace replaced the vehicle.
Definition: vehicle_gui.h:37
virtual void OnResize()
Called after the window got resized.
Definition: order_gui.cpp:1517
Types related to the order widgets.
void MakeConditional(VehicleOrderID order)
Makes this order an conditional order.
Definition: order_cmd.cpp:145
dragging items in the depot windows
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:216
Passes an OrderStopLocation.
Definition: order_type.h:151
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
Definition: order_base.h:137
Vehicle orders; Window numbers:
Definition: window_type.h:207
Aircraft vehicle type.
Definition: vehicle_type.h:29
DisplayPane
Displayed planes of the NWID_SELECTION widgets.
Definition: order_gui.cpp:494
Map related accessors for depots.
Functions related to low-level strings.
OrderConditionVariable GetConditionVariable() const
What variable do we have to compare?
Definition: order_base.h:141
Display the row for conditional orders in the top row of the train/rv order window.
Definition: order_gui.cpp:497
Caption of the window.
Definition: order_widget.h:17
Only numeric ones.
Definition: string_type.h:28
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
void SetNonStopType(OrderNonStopFlags non_stop_type)
Set whether we must stop at stations or not.
Definition: order_base.h:154
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
Draws an order in order or timetable GUI.
Definition: order_gui.cpp:215
uint pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:178
void OrderClick_Service(int i)
Handle the click on the service.
Definition: order_gui.cpp:605
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
void SetDataTip(uint32 widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:894
bool IsRefit() const
Is this order a refit order.
Definition: order_base.h:110
The vehicle will not stop at any stations it passes including the destination.
Definition: order_type.h:82
Functions related to engines.
bool can_do_refit
Vehicle chain can be refitted in depot.
Definition: order_gui.cpp:526
static bool IsDepotTypeTile(TileIndex tile, TransportType type)
Check if a tile is a depot and it is a depot of the given type.
Definition: depot_map.h:20
Do not load anything.
Definition: order_type.h:72
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
Show the refit window for a vehicle.
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:63
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
Simple vector template class, with automatic delete.
Station with truck stops.
Definition: station_type.h:55
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Definition of base types and functions in a cross-platform compatible way.
Select unload.
Definition: order_widget.h:27
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: order_gui.cpp:1090
NWID_SELECTION widget for middle part of the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:36
Removed / replaced all orders (after deleting / sharing).
Definition: vehicle_gui.h:34
A number of safeguards to prevent using unsafe methods.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
List of hotkeys for a window.
Definition: hotkeys.h:42
static const CursorID ANIMCURSOR_PICKSTATION
716 - 718 - goto-order icon
Definition: sprites.h:1481
Always skip.
Definition: order_type.h:124
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
Base of waypoints.
Geometry functions.
rectangle (stations, depots, ...)
Simple depressed panel.
Definition: widget_type.h:50
Order list panel.
Definition: order_widget.h:19
void DeleteChildWindows(WindowClass wc=WC_INVALID) const
Delete all children a window might have in a head-recursive manner.
Definition: window.cpp:1056
VehicleOrderID OrderGetSel() const
Return the memorised selected order.
Definition: order_gui.cpp:534
void OrderHotkey_Transfer()
Handle the transfer hotkey.
Definition: order_gui.cpp:658
TileArea location
Location of the industry.
Definition: industry.h:42
insert a new order
Definition: command_type.h:229
OrderPlaceObjectState
Under what reason are we using the PlaceObject functionality?
Definition: order_gui.cpp:485
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:317
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:311
uint16 GetRange() const
Get the range of this aircraft.
Definition: aircraft.h:135
Vehicle view; Window numbers:
Definition: window_type.h:334
Order window code for all vehicles.
Definition: order_gui.cpp:482
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition: order_base.h:176
virtual void OnMouseDrag(Point pt, int widget)
An &#39;object&#39; is being dragged at the provided position, highlight the target if possible.
Definition: order_gui.cpp:1497
TileIndex tile
Current tile index.
Definition: vehicle_base.h:230
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
Definition: order_gui.cpp:1485
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
Display &#39;stop sharing&#39; in the middle button of the bottom row of the vehicle order window...
Definition: order_gui.cpp:518
The tile has no ownership.
Definition: company_type.h:27
Vehicle timetable; Window numbers:
Definition: window_type.h:219
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
OrderConditionComparator
Comparator for the skip reasoning.
Definition: order_type.h:133
Baseclass for nested widgets.
Definition: widget_type.h:126
Button with a drop-down.
Definition: widget_type.h:82
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:500
Always go to the depot.
Definition: order_type.h:167
OrderLoadFlags GetLoadType() const
How must the consist be loaded?
Definition: order_base.h:129
static const OrderConditionVariable _order_conditional_variable[]
Variables for conditional orders; this defines the order of appearance in the dropdown box...
Definition: order_gui.cpp:153
Skip current order.
Definition: order_widget.h:21
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
Definition: order_gui.cpp:1334
Basic functions/variables used all over the place.
Service the vehicle and then halt it.
Definition: order_type.h:110
StationFacilityByte facilities
The facilities that this station has.
Right offset of the text of the frame.
Definition: window_gui.h:73
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:531
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
Road vehicle type.
Definition: vehicle_type.h:27
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:167
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
Service only if needed.
Definition: order_type.h:168
Left offset of the text of the frame.
Definition: window_gui.h:72
Station with a dock.
Definition: station_type.h:58
Display the conditional order buttons in the top row of the ship/airplane order window.
Definition: order_gui.cpp:514
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition: vehicle_base.h:654
The value to set the condition to.
Definition: order_type.h:157
Skip based on the remaining lifetime.
Definition: order_type.h:125
static DepotID GetDepotIndex(TileIndex t)
Get the index of which depot is attached to the tile.
Definition: depot_map.h:54
NWID_SELECTION widget for left part of the top row of the &#39;your train&#39; order window.
Definition: order_widget.h:35
Transfer all cargo onto the platform.
Definition: order_type.h:61
Ship vehicle type.
Definition: vehicle_type.h:28
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:139
OrderUnloadFlags GetUnloadType() const
How must the consist be unloaded?
Definition: order_base.h:131
VehicleOrderID GetOrderFromPt(int y)
Calculate the selected order.
Definition: order_gui.cpp:548
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:968
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:641
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: order_gui.cpp:808
void SetLoadType(OrderLoadFlags load_type)
Set how the consist must be loaded.
Definition: order_base.h:150
Skip when the vehicle requires service.
Definition: order_type.h:123
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
OwnerByte owner
The owner of this station.
OrderUnloadFlags
Flags related to the unloading order.
Definition: order_type.h:58
uint16 GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not)...
Definition: order_base.h:185
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1146
Open refit options.
Definition: order_widget.h:31
Display &#39;delete&#39; in the middle button of the bottom row of the vehicle order window.
Definition: order_gui.cpp:517
void OrderClick_FullLoad(int load_type)
Handle the click on the full load button.
Definition: order_gui.cpp:581
A conditional variable changes.
Definition: order_type.h:155
Functions related to companies.
default
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:29
OrderStopLocation
Where to stop the trains.
Definition: order_type.h:89
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
Definition: viewport.cpp:3025
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:81
Goto destination.
Definition: order_widget.h:25
Passes an OrderNonStopFlags.
Definition: order_type.h:150
Automatic refitting is allowed.
Definition: engine_type.h:158
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: order_gui.cpp:1148
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:471
VehicleOrderID order_over
Order over which another order is dragged, INVALID_VEH_ORDER_ID if none.
Definition: order_gui.cpp:522
GUISettings gui
settings related to the GUI
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:96
void ShowTimetableWindow(const Vehicle *v)
Show the timetable for a given vehicle.
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CT_NO_REFIT)
Makes this order a Go To Depot order.
Definition: order_cmd.cpp:92
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
Toggle timetable view.
Definition: order_widget.h:18
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
OrderStopLocation GetStopLocation() const
Where must we stop at the platform?
Definition: order_base.h:135
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:118
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
OrderLoadFlags
Flags related to the loading order.
Definition: order_type.h:68
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: order_gui.cpp:1169
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
void OrderHotkey_NoLoad()
Handle the &#39;no loading&#39; hotkey.
Definition: order_gui.cpp:597
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Definition: vehicle_base.h:669
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:108
Send the vehicle to the nearest depot.
Definition: order_type.h:111
void Free()
&#39;Free&#39; the order
Definition: order_cmd.cpp:65
Vertical container.
Definition: widget_type.h:77
OwnerByte owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
uint16 GetConditionValue() const
Get the value to base the skip on.
Definition: order_base.h:147
TileIndex xy
Base tile of the station.
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Do not add shading to this text colour.
Definition: gfx_type.h:271
A tile of a station.
Definition: tile_type.h:48
Skip based on the amount of load.
Definition: order_type.h:119
void SetTimetableParams(int param1, int param2, Ticks ticks)
Set the timetable parameters in the format as described by the setting.
change the refit information of an order (for "goto depot" )
Definition: command_type.h:270
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
uint ConvertDisplaySpeedToSpeed(uint speed)
Convert the given display speed to the (internal) speed.
Definition: strings.cpp:740
Display &#39;load&#39; / &#39;unload&#39; / &#39;refit&#39; buttons in the top row of the ship/airplane order window...
Definition: order_gui.cpp:512
Station with train station.
Definition: station_type.h:54
Totally no unloading will be done.
Definition: order_type.h:62
The vehicle will not stop at any stations it passes except the destination.
Definition: order_type.h:80
Skip based on the maximum speed.
Definition: order_type.h:121
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2133
Vehicle details; Window numbers:
Definition: window_type.h:195
Display &#39;service&#39; in the middle button of the top row of the train/rv order window.
Definition: order_gui.cpp:505
Functions related to commands.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:769
Passes an OrderLoadType.
Definition: order_type.h:153
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1084
Drop down list.
Definition: widget_type.h:70
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:622
Station with bus stops.
Definition: station_type.h:56
Order * GetOrder(int index) const
Returns order &#39;index&#39; of a vehicle or NULL when it doesn&#39;t exists.
Definition: vehicle_base.h:860
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:19
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Definition: window_gui.h:326
HighLightStyle
Highlighting draw styles.
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:687
Base of all industries.
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:681
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
Definition: order_cmd.cpp:106
vehicle is accepted as target as well (bitmask)
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
virtual void OnPaint()
The window must be repainted.
Definition: order_gui.cpp:1080
Choose condition variable.
Definition: order_widget.h:32
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:17
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Select full load.
Definition: order_widget.h:26
Order list scrollbar.
Definition: order_widget.h:20
Choose condition value.
Definition: order_widget.h:34
uint32 Pack() const
Pack this order into a 32 bits integer, or actually only the type, flags and destination.
Definition: order_cmd.cpp:200
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:369
OrderType GetType() const
Get the type of order of this order.
Definition: order_base.h:69
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget. ...
Definition: widget.cpp:1973
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3088
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:84
bool new_nonstop
ttdpatch compatible nonstop handling
Definition: settings_type.h:91
The passed event is handled.
Definition: window_type.h:714
Text is written right-to-left by default.
Definition: strings_type.h:26
Right align the text (must be a single bit).
Definition: gfx_func.h:100
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:314
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
Definition: industry.h:112
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:663
Functions related to tile highlights.
Find a place automatically.
Definition: window_gui.h:156
Force unloading all cargo onto the platform, possibly not getting paid.
Definition: order_type.h:60
static const NWidgetPart _nested_orders_train_widgets[]
Nested widget definition for "your" train orders.
Definition: order_gui.cpp:1543
Display an empty panel in the right button of the top row of the train/rv order window.
Definition: order_gui.cpp:508
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80
This depot order is because of a regular order.
Definition: order_type.h:102
Go to the depot and stop there.
Definition: order_type.h:169
static const CursorID SPR_CURSOR_MOUSE
Cursor sprite numbers.
Definition: sprites.h:1360
Base classes/functions for stations.
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
Get the order command a vehicle can do in a given tile.
Definition: order_gui.cpp:359
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
Definition: base_consist.h:30
move an order
Definition: command_type.h:327
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
Full load a single cargo of the consist.
Definition: order_type.h:71
This depot order is because of the servicing limit.
Definition: order_type.h:101
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:29
VehicleTypeByte type
Type of vehicle.
Definition: vehicle_type.h:56
Skip if the variable is false.
Definition: order_type.h:141
Dimensions (a width and height) of a rectangle in 2D.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:429
Skip based on the maximum reliability.
Definition: order_type.h:126
void SetStopLocation(OrderStopLocation stop_location)
Set where we must stop at the platform.
Definition: order_base.h:156
Station data structure.
Definition: station_base.h:446
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1243
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:133
Display &#39;refit&#39; in the right button of the top row of the train/rv order window.
Definition: order_gui.cpp:509
NWID_SELECTION widget for the top row of the &#39;your non-trains&#39; order window.
Definition: order_widget.h:39
modify an order (like set full-load)
Definition: command_type.h:226
Station with an airport.
Definition: station_type.h:57
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:834
delete an order
Definition: command_type.h:228
Choose condition type.
Definition: order_widget.h:33
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: order_gui.cpp:1433
Display &#39;unload&#39; in the middle button of the top row of the train/rv order window.
Definition: order_gui.cpp:504
void MakeGoToStation(StationID destination)
Makes this order a Go To Station order.
Definition: order_cmd.cpp:77
OrderDepotTypeFlags
Reasons that could cause us to go to the depot.
Definition: order_type.h:99
void EnableWidget(byte widget_index)
Sets a widget to Enabled.
Definition: window_gui.h:413
CargoID GetRefitCargo() const
Get the cargo to to refit to.
Definition: order_base.h:124
(Toggle) Button with text
Definition: widget_type.h:55
void OrderHotkey_NoUnload()
Handle the &#39;no unload&#39; hotkey.
Definition: order_gui.cpp:666
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
Train vehicle type.
Definition: vehicle_type.h:26
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:284
void OrderClick_Delete()
Handle the click on the delete button.
Definition: order_gui.cpp:710