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