OpenTTD Source  13.0-beta1
build_vehicle_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 "engine_base.h"
12 #include "engine_func.h"
13 #include "station_base.h"
14 #include "network/network.h"
15 #include "articulated_vehicles.h"
16 #include "textbuf_gui.h"
17 #include "command_func.h"
18 #include "company_func.h"
19 #include "vehicle_gui.h"
20 #include "newgrf_engine.h"
21 #include "newgrf_text.h"
22 #include "group.h"
23 #include "string_func.h"
24 #include "strings_func.h"
25 #include "window_func.h"
26 #include "date_func.h"
27 #include "vehicle_func.h"
28 #include "widgets/dropdown_func.h"
29 #include "engine_gui.h"
30 #include "cargotype.h"
31 #include "core/geometry_func.hpp"
32 #include "autoreplace_func.h"
33 #include "engine_cmd.h"
34 #include "train_cmd.h"
35 #include "vehicle_cmd.h"
36 
38 
39 #include "table/strings.h"
40 
41 #include "safeguards.h"
42 
49 {
51 }
52 
53 static const NWidgetPart _nested_build_vehicle_widgets[] = {
55  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
56  NWidget(WWT_CAPTION, COLOUR_GREY, WID_BV_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
57  NWidget(WWT_SHADEBOX, COLOUR_GREY),
58  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
59  NWidget(WWT_STICKYBOX, COLOUR_GREY),
60  EndContainer(),
61  NWidget(WWT_PANEL, COLOUR_GREY),
64  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
65  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
66  EndContainer(),
69  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA),
70  EndContainer(),
71  EndContainer(),
72  EndContainer(),
73  /* Vehicle list. */
75  NWidget(WWT_MATRIX, COLOUR_GREY, WID_BV_LIST), SetResize(1, 1), SetFill(1, 0), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_BV_SCROLLBAR),
77  EndContainer(),
78  /* Panel with details. */
79  NWidget(WWT_PANEL, COLOUR_GREY, WID_BV_PANEL), SetMinimalSize(240, 122), SetResize(1, 0), EndContainer(),
80  /* Build/rename buttons, resize button. */
82  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BV_BUILD_SEL),
83  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_BUILD), SetResize(1, 0), SetFill(1, 0),
84  EndContainer(),
85  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDE), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_NULL),
86  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_RENAME), SetResize(1, 0), SetFill(1, 0),
87  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
88  EndContainer(),
89 };
90 
92 static const CargoID CF_ANY = CT_NO_REFIT;
93 static const CargoID CF_NONE = CT_INVALID;
95 
97 byte _engine_sort_last_criteria[] = {0, 0, 0, 0};
98 bool _engine_sort_last_order[] = {false, false, false, false};
99 bool _engine_sort_show_hidden_engines[] = {false, false, false, false};
101 
108 static bool EngineNumberSorter(const EngineID &a, const EngineID &b)
109 {
110  int r = Engine::Get(a)->list_position - Engine::Get(b)->list_position;
111 
112  return _engine_sort_direction ? r > 0 : r < 0;
113 }
114 
121 static bool EngineIntroDateSorter(const EngineID &a, const EngineID &b)
122 {
123  const int va = Engine::Get(a)->intro_date;
124  const int vb = Engine::Get(b)->intro_date;
125  const int r = va - vb;
126 
127  /* Use EngineID to sort instead since we want consistent sorting */
128  if (r == 0) return EngineNumberSorter(a, b);
129  return _engine_sort_direction ? r > 0 : r < 0;
130 }
131 
132 /* cached values for EngineNameSorter to spare many GetString() calls */
133 static EngineID _last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
134 
141 static bool EngineNameSorter(const EngineID &a, const EngineID &b)
142 {
143  static char last_name[2][64] = { "", "" };
144 
145  if (a != _last_engine[0]) {
146  _last_engine[0] = a;
147  SetDParam(0, a);
148  GetString(last_name[0], STR_ENGINE_NAME, lastof(last_name[0]));
149  }
150 
151  if (b != _last_engine[1]) {
152  _last_engine[1] = b;
153  SetDParam(0, b);
154  GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
155  }
156 
157  int r = strnatcmp(last_name[0], last_name[1]); // Sort by name (natural sorting).
158 
159  /* Use EngineID to sort instead since we want consistent sorting */
160  if (r == 0) return EngineNumberSorter(a, b);
161  return _engine_sort_direction ? r > 0 : r < 0;
162 }
163 
170 static bool EngineReliabilitySorter(const EngineID &a, const EngineID &b)
171 {
172  const int va = Engine::Get(a)->reliability;
173  const int vb = Engine::Get(b)->reliability;
174  const int r = va - vb;
175 
176  /* Use EngineID to sort instead since we want consistent sorting */
177  if (r == 0) return EngineNumberSorter(a, b);
178  return _engine_sort_direction ? r > 0 : r < 0;
179 }
180 
187 static bool EngineCostSorter(const EngineID &a, const EngineID &b)
188 {
189  Money va = Engine::Get(a)->GetCost();
190  Money vb = Engine::Get(b)->GetCost();
191  int r = ClampToI32(va - vb);
192 
193  /* Use EngineID to sort instead since we want consistent sorting */
194  if (r == 0) return EngineNumberSorter(a, b);
195  return _engine_sort_direction ? r > 0 : r < 0;
196 }
197 
204 static bool EngineSpeedSorter(const EngineID &a, const EngineID &b)
205 {
206  int va = Engine::Get(a)->GetDisplayMaxSpeed();
207  int vb = Engine::Get(b)->GetDisplayMaxSpeed();
208  int r = va - vb;
209 
210  /* Use EngineID to sort instead since we want consistent sorting */
211  if (r == 0) return EngineNumberSorter(a, b);
212  return _engine_sort_direction ? r > 0 : r < 0;
213 }
214 
221 static bool EnginePowerSorter(const EngineID &a, const EngineID &b)
222 {
223  int va = Engine::Get(a)->GetPower();
224  int vb = Engine::Get(b)->GetPower();
225  int r = va - vb;
226 
227  /* Use EngineID to sort instead since we want consistent sorting */
228  if (r == 0) return EngineNumberSorter(a, b);
229  return _engine_sort_direction ? r > 0 : r < 0;
230 }
231 
238 static bool EngineTractiveEffortSorter(const EngineID &a, const EngineID &b)
239 {
240  int va = Engine::Get(a)->GetDisplayMaxTractiveEffort();
241  int vb = Engine::Get(b)->GetDisplayMaxTractiveEffort();
242  int r = va - vb;
243 
244  /* Use EngineID to sort instead since we want consistent sorting */
245  if (r == 0) return EngineNumberSorter(a, b);
246  return _engine_sort_direction ? r > 0 : r < 0;
247 }
248 
255 static bool EngineRunningCostSorter(const EngineID &a, const EngineID &b)
256 {
257  Money va = Engine::Get(a)->GetRunningCost();
258  Money vb = Engine::Get(b)->GetRunningCost();
259  int r = ClampToI32(va - vb);
260 
261  /* Use EngineID to sort instead since we want consistent sorting */
262  if (r == 0) return EngineNumberSorter(a, b);
263  return _engine_sort_direction ? r > 0 : r < 0;
264 }
265 
272 static bool EnginePowerVsRunningCostSorter(const EngineID &a, const EngineID &b)
273 {
274  const Engine *e_a = Engine::Get(a);
275  const Engine *e_b = Engine::Get(b);
276  uint p_a = e_a->GetPower();
277  uint p_b = e_b->GetPower();
278  Money r_a = e_a->GetRunningCost();
279  Money r_b = e_b->GetRunningCost();
280  /* Check if running cost is zero in one or both engines.
281  * If only one of them is zero then that one has higher value,
282  * else if both have zero cost then compare powers. */
283  if (r_a == 0) {
284  if (r_b == 0) {
285  /* If it is ambiguous which to return go with their ID */
286  if (p_a == p_b) return EngineNumberSorter(a, b);
287  return _engine_sort_direction != (p_a < p_b);
288  }
289  return !_engine_sort_direction;
290  }
291  if (r_b == 0) return _engine_sort_direction;
292  /* Using double for more precision when comparing close values.
293  * This shouldn't have any major effects in performance nor in keeping
294  * the game in sync between players since it's used in GUI only in client side */
295  double v_a = (double)p_a / (double)r_a;
296  double v_b = (double)p_b / (double)r_b;
297  /* Use EngineID to sort if both have same power/running cost,
298  * since we want consistent sorting.
299  * Also if both have no power then sort with reverse of running cost to simulate
300  * previous sorting behaviour for wagons. */
301  if (v_a == 0 && v_b == 0) return !EngineRunningCostSorter(a, b);
302  if (v_a == v_b) return EngineNumberSorter(a, b);
303  return _engine_sort_direction != (v_a < v_b);
304 }
305 
306 /* Train sorting functions */
307 
314 static bool TrainEngineCapacitySorter(const EngineID &a, const EngineID &b)
315 {
316  const RailVehicleInfo *rvi_a = RailVehInfo(a);
317  const RailVehicleInfo *rvi_b = RailVehInfo(b);
318 
319  int va = GetTotalCapacityOfArticulatedParts(a) * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
320  int vb = GetTotalCapacityOfArticulatedParts(b) * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1);
321  int r = va - vb;
322 
323  /* Use EngineID to sort instead since we want consistent sorting */
324  if (r == 0) return EngineNumberSorter(a, b);
325  return _engine_sort_direction ? r > 0 : r < 0;
326 }
327 
334 static bool TrainEnginesThenWagonsSorter(const EngineID &a, const EngineID &b)
335 {
336  int val_a = (RailVehInfo(a)->railveh_type == RAILVEH_WAGON ? 1 : 0);
337  int val_b = (RailVehInfo(b)->railveh_type == RAILVEH_WAGON ? 1 : 0);
338  int r = val_a - val_b;
339 
340  /* Use EngineID to sort instead since we want consistent sorting */
341  if (r == 0) return EngineNumberSorter(a, b);
342  return _engine_sort_direction ? r > 0 : r < 0;
343 }
344 
345 /* Road vehicle sorting functions */
346 
353 static bool RoadVehEngineCapacitySorter(const EngineID &a, const EngineID &b)
354 {
357  int r = va - vb;
358 
359  /* Use EngineID to sort instead since we want consistent sorting */
360  if (r == 0) return EngineNumberSorter(a, b);
361  return _engine_sort_direction ? r > 0 : r < 0;
362 }
363 
364 /* Ship vehicle sorting functions */
365 
372 static bool ShipEngineCapacitySorter(const EngineID &a, const EngineID &b)
373 {
374  const Engine *e_a = Engine::Get(a);
375  const Engine *e_b = Engine::Get(b);
376 
377  int va = e_a->GetDisplayDefaultCapacity();
378  int vb = e_b->GetDisplayDefaultCapacity();
379  int r = va - vb;
380 
381  /* Use EngineID to sort instead since we want consistent sorting */
382  if (r == 0) return EngineNumberSorter(a, b);
383  return _engine_sort_direction ? r > 0 : r < 0;
384 }
385 
386 /* Aircraft sorting functions */
387 
394 static bool AircraftEngineCargoSorter(const EngineID &a, const EngineID &b)
395 {
396  const Engine *e_a = Engine::Get(a);
397  const Engine *e_b = Engine::Get(b);
398 
399  uint16 mail_a, mail_b;
400  int va = e_a->GetDisplayDefaultCapacity(&mail_a);
401  int vb = e_b->GetDisplayDefaultCapacity(&mail_b);
402  int r = va - vb;
403 
404  if (r == 0) {
405  /* The planes have the same passenger capacity. Check mail capacity instead */
406  r = mail_a - mail_b;
407 
408  if (r == 0) {
409  /* Use EngineID to sort instead since we want consistent sorting */
410  return EngineNumberSorter(a, b);
411  }
412  }
413  return _engine_sort_direction ? r > 0 : r < 0;
414 }
415 
422 static bool AircraftRangeSorter(const EngineID &a, const EngineID &b)
423 {
424  uint16 r_a = Engine::Get(a)->GetRange();
425  uint16 r_b = Engine::Get(b)->GetRange();
426 
427  int r = r_a - r_b;
428 
429  /* Use EngineID to sort instead since we want consistent sorting */
430  if (r == 0) return EngineNumberSorter(a, b);
431  return _engine_sort_direction ? r > 0 : r < 0;
432 }
433 
436  /* Trains */
448 }, {
449  /* Road vehicles */
461 }, {
462  /* Ships */
471 }, {
472  /* Aircraft */
482 }};
483 
486  /* Trains */
487  STR_SORT_BY_ENGINE_ID,
488  STR_SORT_BY_COST,
489  STR_SORT_BY_MAX_SPEED,
490  STR_SORT_BY_POWER,
491  STR_SORT_BY_TRACTIVE_EFFORT,
492  STR_SORT_BY_INTRO_DATE,
493  STR_SORT_BY_NAME,
494  STR_SORT_BY_RUNNING_COST,
495  STR_SORT_BY_POWER_VS_RUNNING_COST,
496  STR_SORT_BY_RELIABILITY,
497  STR_SORT_BY_CARGO_CAPACITY,
499 }, {
500  /* Road vehicles */
501  STR_SORT_BY_ENGINE_ID,
502  STR_SORT_BY_COST,
503  STR_SORT_BY_MAX_SPEED,
504  STR_SORT_BY_POWER,
505  STR_SORT_BY_TRACTIVE_EFFORT,
506  STR_SORT_BY_INTRO_DATE,
507  STR_SORT_BY_NAME,
508  STR_SORT_BY_RUNNING_COST,
509  STR_SORT_BY_POWER_VS_RUNNING_COST,
510  STR_SORT_BY_RELIABILITY,
511  STR_SORT_BY_CARGO_CAPACITY,
513 }, {
514  /* Ships */
515  STR_SORT_BY_ENGINE_ID,
516  STR_SORT_BY_COST,
517  STR_SORT_BY_MAX_SPEED,
518  STR_SORT_BY_INTRO_DATE,
519  STR_SORT_BY_NAME,
520  STR_SORT_BY_RUNNING_COST,
521  STR_SORT_BY_RELIABILITY,
522  STR_SORT_BY_CARGO_CAPACITY,
524 }, {
525  /* Aircraft */
526  STR_SORT_BY_ENGINE_ID,
527  STR_SORT_BY_COST,
528  STR_SORT_BY_MAX_SPEED,
529  STR_SORT_BY_INTRO_DATE,
530  STR_SORT_BY_NAME,
531  STR_SORT_BY_RUNNING_COST,
532  STR_SORT_BY_RELIABILITY,
533  STR_SORT_BY_CARGO_CAPACITY,
534  STR_SORT_BY_RANGE,
536 }};
537 
539 static bool CDECL CargoAndEngineFilter(const EngineID *eid, const CargoID cid)
540 {
541  if (cid == CF_ANY) {
542  return true;
543  } else if (cid == CF_ENGINES) {
544  return Engine::Get(*eid)->GetPower() != 0;
545  } else {
546  CargoTypes refit_mask = GetUnionOfArticulatedRefitMasks(*eid, true) & _standard_cargo_mask;
547  return (cid == CF_NONE ? refit_mask == 0 : HasBit(refit_mask, cid));
548  }
549 }
550 
551 static GUIEngineList::FilterFunction * const _filter_funcs[] = {
553 };
554 
555 static int DrawCargoCapacityInfo(int left, int right, int y, EngineID engine, TestedEngineDetails &te)
556 {
557  CargoArray cap;
558  CargoTypes refits;
559  GetArticulatedVehicleCargoesAndRefits(engine, &cap, &refits, te.cargo, te.capacity);
560 
561  for (CargoID c = 0; c < NUM_CARGO; c++) {
562  if (cap[c] == 0) continue;
563 
564  SetDParam(0, c);
565  SetDParam(1, cap[c]);
566  SetDParam(2, HasBit(refits, c) ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
567  DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
568  y += FONT_HEIGHT_NORMAL;
569  }
570 
571  return y;
572 }
573 
574 /* Draw rail wagon specific details */
575 static int DrawRailWagonPurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
576 {
577  const Engine *e = Engine::Get(engine_number);
578 
579  /* Purchase cost */
580  if (te.cost != 0) {
581  SetDParam(0, e->GetCost() + te.cost);
582  SetDParam(1, te.cost);
583  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
584  } else {
585  SetDParam(0, e->GetCost());
586  DrawString(left, right, y, STR_PURCHASE_INFO_COST);
587  }
588  y += FONT_HEIGHT_NORMAL;
589 
590  /* Wagon weight - (including cargo) */
591  uint weight = e->GetDisplayWeight();
592  SetDParam(0, weight);
593  uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->weight * te.capacity / 16 : 0);
594  SetDParam(1, cargo_weight + weight);
595  DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
596  y += FONT_HEIGHT_NORMAL;
597 
598  /* Wagon speed limit, displayed if above zero */
600  uint max_speed = e->GetDisplayMaxSpeed();
601  if (max_speed > 0) {
602  SetDParam(0, max_speed);
603  DrawString(left, right, y, STR_PURCHASE_INFO_SPEED);
604  y += FONT_HEIGHT_NORMAL;
605  }
606  }
607 
608  /* Running cost */
609  if (rvi->running_cost_class != INVALID_PRICE) {
610  SetDParam(0, e->GetRunningCost());
611  DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
612  y += FONT_HEIGHT_NORMAL;
613  }
614 
615  return y;
616 }
617 
618 /* Draw locomotive specific details */
619 static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi, TestedEngineDetails &te)
620 {
621  const Engine *e = Engine::Get(engine_number);
622 
623  /* Purchase Cost - Engine weight */
624  if (te.cost != 0) {
625  SetDParam(0, e->GetCost() + te.cost);
626  SetDParam(1, te.cost);
627  SetDParam(2, e->GetDisplayWeight());
628  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_WEIGHT);
629  } else {
630  SetDParam(0, e->GetCost());
631  SetDParam(1, e->GetDisplayWeight());
632  DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
633  }
634  y += FONT_HEIGHT_NORMAL;
635 
636  /* Max speed - Engine power */
637  SetDParam(0, e->GetDisplayMaxSpeed());
638  SetDParam(1, e->GetPower());
639  DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
640  y += FONT_HEIGHT_NORMAL;
641 
642  /* Max tractive effort - not applicable if old acceleration or maglev */
643  if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(rvi->railtype)->acceleration_type != 2) {
645  DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
646  y += FONT_HEIGHT_NORMAL;
647  }
648 
649  /* Running cost */
650  if (rvi->running_cost_class != INVALID_PRICE) {
651  SetDParam(0, e->GetRunningCost());
652  DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
653  y += FONT_HEIGHT_NORMAL;
654  }
655 
656  /* Powered wagons power - Powered wagons extra weight */
657  if (rvi->pow_wag_power != 0) {
658  SetDParam(0, rvi->pow_wag_power);
659  SetDParam(1, rvi->pow_wag_weight);
660  DrawString(left, right, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT);
661  y += FONT_HEIGHT_NORMAL;
662  }
663 
664  return y;
665 }
666 
667 /* Draw road vehicle specific details */
668 static int DrawRoadVehPurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
669 {
670  const Engine *e = Engine::Get(engine_number);
671 
673  /* Purchase Cost */
674  if (te.cost != 0) {
675  SetDParam(0, e->GetCost() + te.cost);
676  SetDParam(1, te.cost);
677  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
678  } else {
679  SetDParam(0, e->GetCost());
680  DrawString(left, right, y, STR_PURCHASE_INFO_COST);
681  }
682  y += FONT_HEIGHT_NORMAL;
683 
684  /* Road vehicle weight - (including cargo) */
685  int16 weight = e->GetDisplayWeight();
686  SetDParam(0, weight);
687  uint cargo_weight = (e->CanCarryCargo() ? CargoSpec::Get(te.cargo)->weight * te.capacity / 16 : 0);
688  SetDParam(1, cargo_weight + weight);
689  DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
690  y += FONT_HEIGHT_NORMAL;
691 
692  /* Max speed - Engine power */
693  SetDParam(0, e->GetDisplayMaxSpeed());
694  SetDParam(1, e->GetPower());
695  DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
696  y += FONT_HEIGHT_NORMAL;
697 
698  /* Max tractive effort */
700  DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
701  y += FONT_HEIGHT_NORMAL;
702  } else {
703  /* Purchase cost - Max speed */
704  if (te.cost != 0) {
705  SetDParam(0, e->GetCost() + te.cost);
706  SetDParam(1, te.cost);
707  SetDParam(2, e->GetDisplayMaxSpeed());
708  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
709  } else {
710  SetDParam(0, e->GetCost());
711  SetDParam(1, e->GetDisplayMaxSpeed());
712  DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
713  }
714  y += FONT_HEIGHT_NORMAL;
715  }
716 
717  /* Running cost */
718  SetDParam(0, e->GetRunningCost());
719  DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
720  y += FONT_HEIGHT_NORMAL;
721 
722  return y;
723 }
724 
725 /* Draw ship specific details */
726 static int DrawShipPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
727 {
728  const Engine *e = Engine::Get(engine_number);
729 
730  /* Purchase cost - Max speed */
731  uint raw_speed = e->GetDisplayMaxSpeed();
732  uint ocean_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, true);
733  uint canal_speed = e->u.ship.ApplyWaterClassSpeedFrac(raw_speed, false);
734 
735  if (ocean_speed == canal_speed) {
736  if (te.cost != 0) {
737  SetDParam(0, e->GetCost() + te.cost);
738  SetDParam(1, te.cost);
739  SetDParam(2, ocean_speed);
740  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
741  } else {
742  SetDParam(0, e->GetCost());
743  SetDParam(1, ocean_speed);
744  DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
745  }
746  y += FONT_HEIGHT_NORMAL;
747  } else {
748  if (te.cost != 0) {
749  SetDParam(0, e->GetCost() + te.cost);
750  SetDParam(1, te.cost);
751  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
752  } else {
753  SetDParam(0, e->GetCost());
754  DrawString(left, right, y, STR_PURCHASE_INFO_COST);
755  }
756  y += FONT_HEIGHT_NORMAL;
757 
758  SetDParam(0, ocean_speed);
759  DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_OCEAN);
760  y += FONT_HEIGHT_NORMAL;
761 
762  SetDParam(0, canal_speed);
763  DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_CANAL);
764  y += FONT_HEIGHT_NORMAL;
765  }
766 
767  /* Cargo type + capacity */
768  SetDParam(0, te.cargo);
769  SetDParam(1, te.capacity);
770  SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
771  DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
772  y += FONT_HEIGHT_NORMAL;
773 
774  /* Running cost */
775  SetDParam(0, e->GetRunningCost());
776  DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
777  y += FONT_HEIGHT_NORMAL;
778 
779  return y;
780 }
781 
791 static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
792 {
793  const Engine *e = Engine::Get(engine_number);
794 
795  /* Purchase cost - Max speed */
796  if (te.cost != 0) {
797  SetDParam(0, e->GetCost() + te.cost);
798  SetDParam(1, te.cost);
799  SetDParam(2, e->GetDisplayMaxSpeed());
800  DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
801  } else {
802  SetDParam(0, e->GetCost());
803  SetDParam(1, e->GetDisplayMaxSpeed());
804  DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
805  }
806  y += FONT_HEIGHT_NORMAL;
807 
808  /* Cargo capacity */
809  if (te.mail_capacity > 0) {
810  SetDParam(0, te.cargo);
811  SetDParam(1, te.capacity);
812  SetDParam(2, CT_MAIL);
813  SetDParam(3, te.mail_capacity);
814  DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY);
815  } else {
816  /* Note, if the default capacity is selected by the refit capacity
817  * callback, then the capacity shown is likely to be incorrect. */
818  SetDParam(0, te.cargo);
819  SetDParam(1, te.capacity);
820  SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
821  DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
822  }
823  y += FONT_HEIGHT_NORMAL;
824 
825  /* Running cost */
826  SetDParam(0, e->GetRunningCost());
827  DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
828  y += FONT_HEIGHT_NORMAL;
829 
830  /* Aircraft type */
832  DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_TYPE);
833  y += FONT_HEIGHT_NORMAL;
834 
835  /* Aircraft range, if available. */
836  uint16 range = e->GetRange();
837  if (range != 0) {
838  SetDParam(0, range);
839  DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_RANGE);
840  y += FONT_HEIGHT_NORMAL;
841  }
842 
843  return y;
844 }
845 
854 static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
855 {
856  uint16 callback = GetVehicleCallback(CBID_VEHICLE_ADDITIONAL_TEXT, 0, 0, engine, nullptr);
857  if (callback == CALLBACK_FAILED || callback == 0x400) return y;
858  const GRFFile *grffile = Engine::Get(engine)->GetGRF();
859  if (callback > 0x400) {
860  ErrorUnknownCallbackResult(grffile->grfid, CBID_VEHICLE_ADDITIONAL_TEXT, callback);
861  return y;
862  }
863 
864  StartTextRefStackUsage(grffile, 6);
865  uint result = DrawStringMultiLine(left, right, y, INT32_MAX, GetGRFStringID(grffile->grfid, 0xD000 + callback), TC_BLACK);
867  return result;
868 }
869 
876 int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
877 {
878  const Engine *e = Engine::Get(engine_number);
879  YearMonthDay ymd;
880  ConvertDateToYMD(e->intro_date, &ymd);
881  bool refittable = IsArticulatedVehicleRefittable(engine_number);
882  bool articulated_cargo = false;
883 
884  switch (e->type) {
885  default: NOT_REACHED();
886  case VEH_TRAIN:
887  if (e->u.rail.railveh_type == RAILVEH_WAGON) {
888  y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
889  } else {
890  y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
891  }
892  articulated_cargo = true;
893  break;
894 
895  case VEH_ROAD:
896  y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
897  articulated_cargo = true;
898  break;
899 
900  case VEH_SHIP:
901  y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
902  break;
903 
904  case VEH_AIRCRAFT:
905  y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable, te);
906  break;
907  }
908 
909  if (articulated_cargo) {
910  /* Cargo type + capacity, or N/A */
911  int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, te);
912 
913  if (new_y == y) {
914  SetDParam(0, CT_INVALID);
915  SetDParam(2, STR_EMPTY);
916  DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
917  y += FONT_HEIGHT_NORMAL;
918  } else {
919  y = new_y;
920  }
921  }
922 
923  /* Draw details that apply to all types except rail wagons. */
924  if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) {
925  /* Design date - Life length */
926  SetDParam(0, ymd.year);
928  DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
929  y += FONT_HEIGHT_NORMAL;
930 
931  /* Reliability */
933  DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY);
934  y += FONT_HEIGHT_NORMAL;
935  }
936 
937  if (refittable) y = ShowRefitOptionsList(left, right, y, engine_number);
938 
939  /* Additional text from NewGRF */
940  y = ShowAdditionalText(left, right, y, engine_number);
941 
942  /* The NewGRF's name which the vehicle comes from */
943  const GRFConfig *config = GetGRFConfig(e->GetGRFID());
944  if (_settings_client.gui.show_newgrf_name && config != nullptr)
945  {
946  DrawString(left, right, y, config->GetName(), TC_BLACK);
947  y += FONT_HEIGHT_NORMAL;
948  }
949 
950  return y;
951 }
952 
966 void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
967 {
968  static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
969 
970  /* Obligatory sanity checks! */
971  assert(max <= eng_list->size());
972 
973  bool rtl = _current_text_dir == TD_RTL;
974  int step_size = GetEngineListHeight(type);
975  int sprite_left = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_left;
976  int sprite_right = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_right;
977  int sprite_width = sprite_left + sprite_right;
978 
979  int sprite_x = rtl ? r - sprite_right - 1 : l + sprite_left + 1;
980  int sprite_y_offset = sprite_y_offsets[type] + step_size / 2;
981 
982  Dimension replace_icon = {0, 0};
983  int count_width = 0;
984  if (show_count) {
985  replace_icon = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
987  count_width = GetStringBoundingBox(STR_TINY_BLACK_COMA).width;
988  }
989 
990  int text_left = l + (rtl ? WD_FRAMERECT_LEFT + replace_icon.width + 8 + count_width : sprite_width + WD_FRAMETEXT_LEFT);
991  int text_right = r - (rtl ? sprite_width + WD_FRAMETEXT_RIGHT : WD_FRAMERECT_RIGHT + replace_icon.width + 8 + count_width);
992  int replace_icon_left = rtl ? l + WD_FRAMERECT_LEFT : r - WD_FRAMERECT_RIGHT - replace_icon.width;
993  int count_left = l;
994  int count_right = rtl ? text_left : r - WD_FRAMERECT_RIGHT - replace_icon.width - 8;
995 
996  int normal_text_y_offset = (step_size - FONT_HEIGHT_NORMAL) / 2;
997  int small_text_y_offset = step_size - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1;
998  int replace_icon_y_offset = (step_size - replace_icon.height) / 2 - 1;
999 
1000  for (; min < max; min++, y += step_size) {
1001  const EngineID engine = (*eng_list)[min];
1002  /* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_company here. */
1003  const uint num_engines = GetGroupNumEngines(_local_company, selected_group, engine);
1004 
1005  const Engine *e = Engine::Get(engine);
1006  bool hidden = HasBit(e->company_hidden, _local_company);
1007  StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
1008  TextColour tc = (engine == selected_id) ? TC_WHITE : (TC_NO_SHADE | (hidden ? TC_GREY : TC_BLACK));
1009 
1010  SetDParam(0, engine);
1011  DrawString(text_left, text_right, y + normal_text_y_offset, str, tc);
1012  DrawVehicleEngine(l, r, sprite_x, y + sprite_y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company), EIT_PURCHASE);
1013  if (show_count) {
1014  SetDParam(0, num_engines);
1015  DrawString(count_left, count_right, y + small_text_y_offset, STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
1016  if (EngineHasReplacementForCompany(Company::Get(_local_company), engine, selected_group)) DrawSprite(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, replace_icon_left, y + replace_icon_y_offset);
1017  }
1018  }
1019 }
1020 
1028 void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, int button)
1029 {
1030  uint32 hidden_mask = 0;
1031  /* Disable sorting by power or tractive effort when the original acceleration model for road vehicles is being used. */
1032  if (vehicle_type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL) {
1033  SetBit(hidden_mask, 3); // power
1034  SetBit(hidden_mask, 4); // tractive effort
1035  SetBit(hidden_mask, 8); // power by running costs
1036  }
1037  /* Disable sorting by tractive effort when the original acceleration model for trains is being used. */
1038  if (vehicle_type == VEH_TRAIN && _settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) {
1039  SetBit(hidden_mask, 4); // tractive effort
1040  }
1041  ShowDropDownMenu(w, _engine_sort_listing[vehicle_type], selected, button, 0, hidden_mask);
1042 }
1043 
1047  union {
1050  } filter;
1057  GUIEngineList eng_list;
1062  Scrollbar *vscroll;
1064 
1065  void SetBuyVehicleText()
1066  {
1067  NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_BUILD);
1068 
1069  bool refit = this->sel_engine != INVALID_ENGINE && this->cargo_filter[this->cargo_filter_criteria] != CF_ANY && this->cargo_filter[this->cargo_filter_criteria] != CF_NONE;
1070  if (refit) refit = Engine::Get(this->sel_engine)->GetDefaultCargoType() != this->cargo_filter[this->cargo_filter_criteria];
1071 
1072  if (refit) {
1073  widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type;
1074  widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_TOOLTIP + this->vehicle_type;
1075  } else {
1076  widget->widget_data = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type;
1077  widget->tool_tip = STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_TOOLTIP + this->vehicle_type;
1078  }
1079  }
1080 
1081  BuildVehicleWindow(WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc)
1082  {
1083  this->vehicle_type = type;
1084  this->listview_mode = tile == INVALID_TILE;
1085  this->window_number = this->listview_mode ? (int)type : (int)tile;
1086 
1087  this->sel_engine = INVALID_ENGINE;
1088 
1089  this->sort_criteria = _engine_sort_last_criteria[type];
1090  this->descending_sort_order = _engine_sort_last_order[type];
1091  this->show_hidden_engines = _engine_sort_show_hidden_engines[type];
1092 
1093  this->UpdateFilterByTile();
1094 
1095  this->CreateNestedTree();
1096 
1097  this->vscroll = this->GetScrollbar(WID_BV_SCROLLBAR);
1098 
1099  /* If we are just viewing the list of vehicles, we do not need the Build button.
1100  * So we just hide it, and enlarge the Rename button by the now vacant place. */
1101  if (this->listview_mode) this->GetWidget<NWidgetStacked>(WID_BV_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE);
1102 
1103  NWidgetCore *widget = this->GetWidget<NWidgetCore>(WID_BV_LIST);
1104  widget->tool_tip = STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type;
1105 
1106  widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDE);
1107  widget->tool_tip = STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type;
1108 
1109  widget = this->GetWidget<NWidgetCore>(WID_BV_RENAME);
1110  widget->widget_data = STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type;
1111  widget->tool_tip = STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type;
1112 
1113  widget = this->GetWidget<NWidgetCore>(WID_BV_SHOW_HIDDEN_ENGINES);
1114  widget->widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type;
1115  widget->tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type;
1116  widget->SetLowered(this->show_hidden_engines);
1117 
1118  this->details_height = ((this->vehicle_type == VEH_TRAIN) ? 10 : 9);
1119 
1120  this->FinishInitNested(tile == INVALID_TILE ? (int)type : (int)tile);
1121 
1122  this->owner = (tile != INVALID_TILE) ? GetTileOwner(tile) : _local_company;
1123 
1124  this->eng_list.ForceRebuild();
1125  this->GenerateBuildList(); // generate the list, since we need it in the next line
1126  /* Select the first engine in the list as default when opening the window */
1127  if (this->eng_list.size() > 0) {
1128  this->SelectEngine(this->eng_list[0]);
1129  } else {
1130  this->SelectEngine(INVALID_ENGINE);
1131  }
1132  }
1133 
1136  {
1137  switch (this->vehicle_type) {
1138  default: NOT_REACHED();
1139  case VEH_TRAIN:
1140  if (this->listview_mode) {
1141  this->filter.railtype = INVALID_RAILTYPE;
1142  } else {
1143  this->filter.railtype = GetRailType(this->window_number);
1144  }
1145  break;
1146 
1147  case VEH_ROAD:
1148  if (this->listview_mode) {
1149  this->filter.roadtype = INVALID_ROADTYPE;
1150  } else {
1151  this->filter.roadtype = GetRoadTypeRoad(this->window_number);
1152  if (this->filter.roadtype == INVALID_ROADTYPE) {
1153  this->filter.roadtype = GetRoadTypeTram(this->window_number);
1154  }
1155  }
1156  break;
1157 
1158  case VEH_SHIP:
1159  case VEH_AIRCRAFT:
1160  break;
1161  }
1162  }
1163 
1166  {
1167  uint filter_items = 0;
1168 
1169  /* Add item for disabling filtering. */
1170  this->cargo_filter[filter_items] = CF_ANY;
1171  this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ALL_TYPES;
1172  filter_items++;
1173 
1174  /* Specific filters for trains. */
1175  if (this->vehicle_type == VEH_TRAIN) {
1176  /* Add item for locomotives only in case of trains. */
1177  this->cargo_filter[filter_items] = CF_ENGINES;
1178  this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ENGINES_ONLY;
1179  filter_items++;
1180 
1181  /* Add item for vehicles not carrying anything, e.g. train engines.
1182  * This could also be useful for eyecandy vehicles of other types, but is likely too confusing for joe, */
1183  this->cargo_filter[filter_items] = CF_NONE;
1184  this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_NONE;
1185  filter_items++;
1186  }
1187 
1188  /* Collect available cargo types for filtering. */
1189  for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
1190  this->cargo_filter[filter_items] = cs->Index();
1191  this->cargo_filter_texts[filter_items] = cs->name;
1192  filter_items++;
1193  }
1194 
1195  /* Terminate the filter list. */
1196  this->cargo_filter_texts[filter_items] = INVALID_STRING_ID;
1197 
1198  /* If not found, the cargo criteria will be set to all cargoes. */
1199  this->cargo_filter_criteria = 0;
1200 
1201  /* Find the last cargo filter criteria. */
1202  for (uint i = 0; i < filter_items; i++) {
1203  if (this->cargo_filter[i] == _engine_sort_last_cargo_criteria[this->vehicle_type]) {
1204  this->cargo_filter_criteria = i;
1205  break;
1206  }
1207  }
1208 
1209  this->eng_list.SetFilterFuncs(_filter_funcs);
1210  this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
1211  }
1212 
1213  void SelectEngine(EngineID engine)
1214  {
1215  CargoID cargo = this->cargo_filter[this->cargo_filter_criteria];
1216  if (cargo == CF_ANY) cargo = CF_NONE;
1217 
1218  this->sel_engine = engine;
1219  this->SetBuyVehicleText();
1220 
1221  if (this->sel_engine == INVALID_ENGINE) return;
1222 
1223  const Engine *e = Engine::Get(this->sel_engine);
1224  if (!e->CanCarryCargo()) {
1225  this->te.cost = 0;
1226  this->te.cargo = CT_INVALID;
1227  return;
1228  }
1229 
1230  if (!this->listview_mode) {
1231  /* Query for cost and refitted capacity */
1232  auto [ret, veh_id, refit_capacity, refit_mail] = Command<CMD_BUILD_VEHICLE>::Do(DC_QUERY_COST, this->window_number, this->sel_engine, true, cargo, INVALID_CLIENT_ID);
1233  if (ret.Succeeded()) {
1234  this->te.cost = ret.GetCost() - e->GetCost();
1235  this->te.capacity = refit_capacity;
1236  this->te.mail_capacity = refit_mail;
1237  this->te.cargo = (cargo == CT_INVALID) ? e->GetDefaultCargoType() : cargo;
1238  return;
1239  }
1240  }
1241 
1242  /* Purchase test was not possible or failed, fill in the defaults instead. */
1243  this->te.cost = 0;
1244  this->te.capacity = e->GetDisplayDefaultCapacity(&this->te.mail_capacity);
1245  this->te.cargo = e->GetDefaultCargoType();
1246  }
1247 
1248  void OnInit() override
1249  {
1250  this->SetCargoFilterArray();
1251  }
1252 
1255  {
1256  this->eng_list.Filter(this->cargo_filter[this->cargo_filter_criteria]);
1257  if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine
1258  this->SelectEngine(INVALID_ENGINE);
1259  } else if (std::find(this->eng_list.begin(), this->eng_list.end(), this->sel_engine) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list
1260  this->SelectEngine(this->eng_list[0]);
1261  }
1262  }
1263 
1266  {
1267  CargoID filter_type = this->cargo_filter[this->cargo_filter_criteria];
1268  return CargoAndEngineFilter(&eid, filter_type);
1269  }
1270 
1271  /* Figure out what train EngineIDs to put in the list */
1272  void GenerateBuildTrainList()
1273  {
1274  EngineID sel_id = INVALID_ENGINE;
1275  int num_engines = 0;
1276  int num_wagons = 0;
1277 
1278  this->eng_list.clear();
1279 
1280  /* Make list of all available train engines and wagons.
1281  * Also check to see if the previously selected engine is still available,
1282  * and if not, reset selection to INVALID_ENGINE. This could be the case
1283  * when engines become obsolete and are removed */
1284  for (const Engine *e : Engine::IterateType(VEH_TRAIN)) {
1285  if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
1286  EngineID eid = e->index;
1287  const RailVehicleInfo *rvi = &e->u.rail;
1288 
1289  if (this->filter.railtype != INVALID_RAILTYPE && !HasPowerOnRail(rvi->railtype, this->filter.railtype)) continue;
1290  if (!IsEngineBuildable(eid, VEH_TRAIN, _local_company)) continue;
1291 
1292  /* Filter now! So num_engines and num_wagons is valid */
1293  if (!FilterSingleEngine(eid)) continue;
1294 
1295  this->eng_list.push_back(eid);
1296 
1297  if (rvi->railveh_type != RAILVEH_WAGON) {
1298  num_engines++;
1299  } else {
1300  num_wagons++;
1301  }
1302 
1303  if (eid == this->sel_engine) sel_id = eid;
1304  }
1305 
1306  this->SelectEngine(sel_id);
1307 
1308  /* invalidate cached values for name sorter - engine names could change */
1309  _last_engine[0] = _last_engine[1] = INVALID_ENGINE;
1310 
1311  /* make engines first, and then wagons, sorted by selected sort_criteria */
1312  _engine_sort_direction = false;
1313  EngList_Sort(&this->eng_list, TrainEnginesThenWagonsSorter);
1314 
1315  /* and then sort engines */
1317  EngList_SortPartial(&this->eng_list, _engine_sort_functions[0][this->sort_criteria], 0, num_engines);
1318 
1319  /* and finally sort wagons */
1320  EngList_SortPartial(&this->eng_list, _engine_sort_functions[0][this->sort_criteria], num_engines, num_wagons);
1321  }
1322 
1323  /* Figure out what road vehicle EngineIDs to put in the list */
1324  void GenerateBuildRoadVehList()
1325  {
1326  EngineID sel_id = INVALID_ENGINE;
1327 
1328  this->eng_list.clear();
1329 
1330  for (const Engine *e : Engine::IterateType(VEH_ROAD)) {
1331  if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
1332  EngineID eid = e->index;
1333  if (!IsEngineBuildable(eid, VEH_ROAD, _local_company)) continue;
1334  if (this->filter.roadtype != INVALID_ROADTYPE && !HasPowerOnRoad(e->u.road.roadtype, this->filter.roadtype)) continue;
1335 
1336  this->eng_list.push_back(eid);
1337 
1338  if (eid == this->sel_engine) sel_id = eid;
1339  }
1340  this->SelectEngine(sel_id);
1341  }
1342 
1343  /* Figure out what ship EngineIDs to put in the list */
1344  void GenerateBuildShipList()
1345  {
1346  EngineID sel_id = INVALID_ENGINE;
1347  this->eng_list.clear();
1348 
1349  for (const Engine *e : Engine::IterateType(VEH_SHIP)) {
1350  if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
1351  EngineID eid = e->index;
1352  if (!IsEngineBuildable(eid, VEH_SHIP, _local_company)) continue;
1353  this->eng_list.push_back(eid);
1354 
1355  if (eid == this->sel_engine) sel_id = eid;
1356  }
1357  this->SelectEngine(sel_id);
1358  }
1359 
1360  /* Figure out what aircraft EngineIDs to put in the list */
1361  void GenerateBuildAircraftList()
1362  {
1363  EngineID sel_id = INVALID_ENGINE;
1364 
1365  this->eng_list.clear();
1366 
1367  const Station *st = this->listview_mode ? nullptr : Station::GetByTile(this->window_number);
1368 
1369  /* Make list of all available planes.
1370  * Also check to see if the previously selected plane is still available,
1371  * and if not, reset selection to INVALID_ENGINE. This could be the case
1372  * when planes become obsolete and are removed */
1373  for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) {
1374  if (!this->show_hidden_engines && e->IsHidden(_local_company)) continue;
1375  EngineID eid = e->index;
1376  if (!IsEngineBuildable(eid, VEH_AIRCRAFT, _local_company)) continue;
1377  /* First VEH_END window_numbers are fake to allow a window open for all different types at once */
1378  if (!this->listview_mode && !CanVehicleUseStation(eid, st)) continue;
1379 
1380  this->eng_list.push_back(eid);
1381  if (eid == this->sel_engine) sel_id = eid;
1382  }
1383 
1384  this->SelectEngine(sel_id);
1385  }
1386 
1387  /* Generate the list of vehicles */
1388  void GenerateBuildList()
1389  {
1390  if (!this->eng_list.NeedRebuild()) return;
1391 
1392  /* Update filter type in case the road/railtype of the depot got converted */
1393  this->UpdateFilterByTile();
1394 
1395  switch (this->vehicle_type) {
1396  default: NOT_REACHED();
1397  case VEH_TRAIN:
1398  this->GenerateBuildTrainList();
1399  this->eng_list.shrink_to_fit();
1400  this->eng_list.RebuildDone();
1401  return; // trains should not reach the last sorting
1402  case VEH_ROAD:
1403  this->GenerateBuildRoadVehList();
1404  break;
1405  case VEH_SHIP:
1406  this->GenerateBuildShipList();
1407  break;
1408  case VEH_AIRCRAFT:
1409  this->GenerateBuildAircraftList();
1410  break;
1411  }
1412 
1413  this->FilterEngineList();
1414 
1416  EngList_Sort(&this->eng_list, _engine_sort_functions[this->vehicle_type][this->sort_criteria]);
1417 
1418  this->eng_list.shrink_to_fit();
1419  this->eng_list.RebuildDone();
1420  }
1421 
1422  void OnClick(Point pt, int widget, int click_count) override
1423  {
1424  switch (widget) {
1426  this->descending_sort_order ^= true;
1428  this->eng_list.ForceRebuild();
1429  this->SetDirty();
1430  break;
1431 
1433  this->show_hidden_engines ^= true;
1435  this->eng_list.ForceRebuild();
1436  this->SetWidgetLoweredState(widget, this->show_hidden_engines);
1437  this->SetDirty();
1438  break;
1439 
1440  case WID_BV_LIST: {
1441  uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BV_LIST);
1442  size_t num_items = this->eng_list.size();
1443  this->SelectEngine((i < num_items) ? this->eng_list[i] : INVALID_ENGINE);
1444  this->SetDirty();
1445  if (_ctrl_pressed) {
1446  this->OnClick(pt, WID_BV_SHOW_HIDE, 1);
1447  } else if (click_count > 1 && !this->listview_mode) {
1448  this->OnClick(pt, WID_BV_BUILD, 1);
1449  }
1450  break;
1451  }
1452 
1453  case WID_BV_SORT_DROPDOWN: // Select sorting criteria dropdown menu
1454  DisplayVehicleSortDropDown(this, this->vehicle_type, this->sort_criteria, WID_BV_SORT_DROPDOWN);
1455  break;
1456 
1457  case WID_BV_CARGO_FILTER_DROPDOWN: // Select cargo filtering criteria dropdown menu
1458  ShowDropDownMenu(this, this->cargo_filter_texts, this->cargo_filter_criteria, WID_BV_CARGO_FILTER_DROPDOWN, 0, 0);
1459  break;
1460 
1461  case WID_BV_SHOW_HIDE: {
1462  const Engine *e = (this->sel_engine == INVALID_ENGINE) ? nullptr : Engine::Get(this->sel_engine);
1463  if (e != nullptr) {
1465  }
1466  break;
1467  }
1468 
1469  case WID_BV_BUILD: {
1470  EngineID sel_eng = this->sel_engine;
1471  if (sel_eng != INVALID_ENGINE) {
1472  CargoID cargo = this->cargo_filter[this->cargo_filter_criteria];
1473  if (cargo == CF_ANY || cargo == CF_ENGINES) cargo = CF_NONE;
1474  if (this->vehicle_type == VEH_TRAIN && RailVehInfo(sel_eng)->railveh_type == RAILVEH_WAGON) {
1475  Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildWagon, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
1476  } else {
1477  Command<CMD_BUILD_VEHICLE>::Post(GetCmdBuildVehMsg(this->vehicle_type), CcBuildPrimaryVehicle, this->window_number, sel_eng, true, cargo, INVALID_CLIENT_ID);
1478  }
1479  }
1480  break;
1481  }
1482 
1483  case WID_BV_RENAME: {
1484  EngineID sel_eng = this->sel_engine;
1485  if (sel_eng != INVALID_ENGINE) {
1486  this->rename_engine = sel_eng;
1487  SetDParam(0, sel_eng);
1488  ShowQueryString(STR_ENGINE_NAME, STR_QUERY_RENAME_TRAIN_TYPE_CAPTION + this->vehicle_type, MAX_LENGTH_ENGINE_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
1489  }
1490  break;
1491  }
1492  }
1493  }
1494 
1500  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1501  {
1502  if (!gui_scope) return;
1503  /* When switching to original acceleration model for road vehicles, clear the selected sort criteria if it is not available now. */
1504  if (this->vehicle_type == VEH_ROAD &&
1506  this->sort_criteria > 7) {
1507  this->sort_criteria = 0;
1509  }
1510  this->eng_list.ForceRebuild();
1511  }
1512 
1513  void SetStringParameters(int widget) const override
1514  {
1515  switch (widget) {
1516  case WID_BV_CAPTION:
1517  if (this->vehicle_type == VEH_TRAIN && !this->listview_mode) {
1518  const RailtypeInfo *rti = GetRailTypeInfo(this->filter.railtype);
1519  SetDParam(0, rti->strings.build_caption);
1520  } else if (this->vehicle_type == VEH_ROAD && !this->listview_mode) {
1521  const RoadTypeInfo *rti = GetRoadTypeInfo(this->filter.roadtype);
1522  SetDParam(0, rti->strings.build_caption);
1523  } else {
1524  SetDParam(0, (this->listview_mode ? STR_VEHICLE_LIST_AVAILABLE_TRAINS : STR_BUY_VEHICLE_TRAIN_ALL_CAPTION) + this->vehicle_type);
1525  }
1526  break;
1527 
1528  case WID_BV_SORT_DROPDOWN:
1529  SetDParam(0, _engine_sort_listing[this->vehicle_type][this->sort_criteria]);
1530  break;
1531 
1533  SetDParam(0, this->cargo_filter_texts[this->cargo_filter_criteria]);
1534  break;
1535 
1536  case WID_BV_SHOW_HIDE: {
1537  const Engine *e = (this->sel_engine == INVALID_ENGINE) ? nullptr : Engine::Get(this->sel_engine);
1538  if (e != nullptr && e->IsHidden(_local_company)) {
1539  SetDParam(0, STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type);
1540  } else {
1541  SetDParam(0, STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1542  }
1543  break;
1544  }
1545  }
1546  }
1547 
1548  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1549  {
1550  switch (widget) {
1551  case WID_BV_LIST:
1552  resize->height = GetEngineListHeight(this->vehicle_type);
1553  size->height = 3 * resize->height;
1554  size->width = std::max(size->width, GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_left + GetVehicleImageCellSize(this->vehicle_type, EIT_PURCHASE).extend_right + 165);
1555  break;
1556 
1557  case WID_BV_PANEL:
1558  size->height = FONT_HEIGHT_NORMAL * this->details_height + padding.height;
1559  break;
1560 
1562  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
1563  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
1564  d.height += padding.height;
1565  *size = maxdim(*size, d);
1566  break;
1567  }
1568 
1569  case WID_BV_BUILD:
1570  *size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_VEHICLE_BUTTON + this->vehicle_type);
1571  *size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_BUY_REFIT_VEHICLE_BUTTON + this->vehicle_type));
1572  size->width += padding.width;
1573  size->height += padding.height;
1574  break;
1575 
1576  case WID_BV_SHOW_HIDE:
1577  *size = GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1578  *size = maxdim(*size, GetStringBoundingBox(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type));
1579  size->width += padding.width;
1580  size->height += padding.height;
1581  break;
1582  }
1583  }
1584 
1585  void DrawWidget(const Rect &r, int widget) const override
1586  {
1587  switch (widget) {
1588  case WID_BV_LIST:
1590  this->vehicle_type,
1591  r.left + WD_FRAMERECT_LEFT,
1592  r.right - WD_FRAMERECT_RIGHT,
1593  r.top + WD_FRAMERECT_TOP,
1594  &this->eng_list,
1595  this->vscroll->GetPosition(),
1596  static_cast<uint16>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size())),
1597  this->sel_engine,
1598  false,
1600  );
1601  break;
1602 
1604  this->DrawSortButtonState(WID_BV_SORT_ASCENDING_DESCENDING, this->descending_sort_order ? SBS_DOWN : SBS_UP);
1605  break;
1606  }
1607  }
1608 
1609  void OnPaint() override
1610  {
1611  this->GenerateBuildList();
1612  this->vscroll->SetCount((uint)this->eng_list.size());
1613 
1615 
1616  /* Disable renaming engines in network games if you are not the server. */
1617  this->SetWidgetDisabledState(WID_BV_RENAME, this->sel_engine == INVALID_ENGINE || (_networking && !_network_server));
1618 
1619  this->DrawWidgets();
1620 
1621  if (!this->IsShaded()) {
1622  int needed_height = this->details_height;
1623  /* Draw details panels. */
1624  if (this->sel_engine != INVALID_ENGINE) {
1625  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_BV_PANEL);
1627  nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine, this->te);
1628  needed_height = std::max(needed_height, (text_end - (int)nwi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL);
1629  }
1630  if (needed_height != this->details_height) { // Details window are not high enough, enlarge them.
1631  int resize = needed_height - this->details_height;
1632  this->details_height = needed_height;
1633  this->ReInit(0, resize * FONT_HEIGHT_NORMAL);
1634  return;
1635  }
1636  }
1637  }
1638 
1639  void OnQueryTextFinished(char *str) override
1640  {
1641  if (str == nullptr) return;
1642 
1643  Command<CMD_RENAME_ENGINE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, str);
1644  }
1645 
1646  void OnDropdownSelect(int widget, int index) override
1647  {
1648  switch (widget) {
1649  case WID_BV_SORT_DROPDOWN:
1650  if (this->sort_criteria != index) {
1651  this->sort_criteria = index;
1653  this->eng_list.ForceRebuild();
1654  }
1655  break;
1656 
1657  case WID_BV_CARGO_FILTER_DROPDOWN: // Select a cargo filter criteria
1658  if (this->cargo_filter_criteria != index) {
1659  this->cargo_filter_criteria = index;
1660  _engine_sort_last_cargo_criteria[this->vehicle_type] = this->cargo_filter[this->cargo_filter_criteria];
1661  /* deactivate filter if criteria is 'Show All', activate it otherwise */
1662  this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] != CF_ANY);
1663  this->eng_list.ForceRebuild();
1664  this->SelectEngine(this->sel_engine);
1665  }
1666  break;
1667  }
1668  this->SetDirty();
1669  }
1670 
1671  void OnResize() override
1672  {
1673  this->vscroll->SetCapacityFromWidget(this, WID_BV_LIST);
1674  }
1675 };
1676 
1677 static WindowDesc _build_vehicle_desc(
1678  WDP_AUTO, "build_vehicle", 240, 268,
1681  _nested_build_vehicle_widgets, lengthof(_nested_build_vehicle_widgets)
1682 );
1683 
1684 void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
1685 {
1686  /* We want to be able to open both Available Train as Available Ships,
1687  * so if tile == INVALID_TILE (Available XXX Window), use 'type' as unique number.
1688  * As it always is a low value, it won't collide with any real tile
1689  * number. */
1690  uint num = (tile == INVALID_TILE) ? (int)type : (int)tile;
1691 
1692  assert(IsCompanyBuildableVehicleType(type));
1693 
1695 
1696  new BuildVehicleWindow(&_build_vehicle_desc, tile, type);
1697 }
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:423
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
_engine_sort_functions
EngList_SortTypeFunction *const _engine_sort_functions[][11]
Sort functions for the vehicle sort criteria, for each vehicle type.
Definition: build_vehicle_gui.cpp:435
BuildVehicleWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: build_vehicle_gui.cpp:1500
Engine::GetDisplayDefaultCapacity
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
Definition: engine_base.h:103
_standard_cargo_mask
CargoTypes _standard_cargo_mask
Bitmask of real cargo types available.
Definition: cargotype.cpp:33
EngineCostSorter
static bool EngineCostSorter(const EngineID &a, const EngineID &b)
Determines order of engines by purchase cost.
Definition: build_vehicle_gui.cpp:187
INVALID_ENGINE
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Definition: engine_type.h:175
IsCompanyBuildableVehicleType
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
Definition: vehicle_func.h:89
BuildVehicleWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: build_vehicle_gui.cpp:1609
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
WID_BV_SORT_DROPDOWN
@ WID_BV_SORT_DROPDOWN
Criteria of sorting dropdown.
Definition: build_vehicle_widget.h:17
Engine::GetGRFID
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
Definition: engine.cpp:150
RoadTypeInfo
Definition: road.h:75
WID_BV_SHOW_HIDE
@ WID_BV_SHOW_HIDE
Button to hide or show the selected engine.
Definition: build_vehicle_widget.h:24
ClampToI32
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Definition: math_func.hpp:141
RailVehicleInfo::pow_wag_weight
byte pow_wag_weight
Extra weight applied to consist if wagon should be powered.
Definition: engine_type.h:56
Engine::IterateType
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
Definition: engine_base.h:161
Pool::PoolItem<&_engine_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
vehicle_gui.h
BuildVehicleWindow::te
TestedEngineDetails te
Tested cost and capacity after refit.
Definition: build_vehicle_gui.cpp:1063
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1190
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition: network_type.h:48
VehicleSettings::train_acceleration_model
uint8 train_acceleration_model
realistic acceleration for trains
Definition: settings_type.h:483
GUISettings::show_newgrf_name
bool show_newgrf_name
Show the name of the NewGRF in the build vehicle window.
Definition: settings_type.h:172
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
command_func.h
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:670
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:320
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
dropdown_func.h
BuildVehicleWindow::vehicle_type
VehicleType vehicle_type
Type of vehicles shown in the window.
Definition: build_vehicle_gui.cpp:1046
EngineSpeedSorter
static bool EngineSpeedSorter(const EngineID &a, const EngineID &b)
Determines order of engines by speed.
Definition: build_vehicle_gui.cpp:204
EngineIntroDateSorter
static bool EngineIntroDateSorter(const EngineID &a, const EngineID &b)
Determines order of engines by introduction date.
Definition: build_vehicle_gui.cpp:121
WID_BV_SHOW_HIDDEN_ENGINES
@ WID_BV_SHOW_HIDDEN_ENGINES
Toggle whether to display the hidden vehicles.
Definition: build_vehicle_widget.h:19
Window::ReInit
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:1004
TestedEngineDetails::mail_capacity
uint16 mail_capacity
Mail capacity if available.
Definition: vehicle_gui.h:43
_engine_sort_last_order
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
Definition: build_vehicle_gui.cpp:98
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: window_gui.h:80
RoadVehEngineCapacitySorter
static bool RoadVehEngineCapacitySorter(const EngineID &a, const EngineID &b)
Determines order of road vehicles by capacity.
Definition: build_vehicle_gui.cpp:353
BuildVehicleWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: build_vehicle_gui.cpp:1639
GetTotalCapacityOfArticulatedParts
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
Get the capacity of an engine with articulated parts.
Definition: engine_gui.cpp:164
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Station
Station data structure.
Definition: station_base.h:454
_engine_sort_direction
bool _engine_sort_direction
false = descending, true = ascending.
Definition: build_vehicle_gui.cpp:96
GUIList< EngineID, CargoID >
_network_server
bool _network_server
network-server is active
Definition: network.cpp:59
Engine::GetDisplayMaxTractiveEffort
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
Definition: engine.cpp:417
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1760
CF_ENGINES
static const CargoID CF_ENGINES
Show only engines (for rail vehicles only)
Definition: build_vehicle_gui.cpp:94
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
CargoSpec::Get
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
Definition: cargotype.h:118
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
EIT_PURCHASE
@ EIT_PURCHASE
Vehicle drawn in purchase list, autoreplace gui, ...
Definition: vehicle_type.h:91
HasPowerOnRail
static bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
Definition: rail.h:332
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:82
DrawEngineList
void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
Engine drawing loop.
Definition: build_vehicle_gui.cpp:966
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
CargoAndEngineFilter
static bool CDECL CargoAndEngineFilter(const EngineID *eid, const CargoID cid)
Filters vehicles by cargo and engine (in case of rail vehicle).
Definition: build_vehicle_gui.cpp:539
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:57
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
INVALID_TILE
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:108
TrainEnginesThenWagonsSorter
static bool TrainEnginesThenWagonsSorter(const EngineID &a, const EngineID &b)
Determines order of train engines by engine / wagon.
Definition: build_vehicle_gui.cpp:334
Engine::GetRunningCost
Money GetRunningCost() const
Return how much the running costs of this engine are.
Definition: engine.cpp:272
RailtypeInfo
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:124
group.h
VehicleSettings::wagon_speed_limits
bool wagon_speed_limits
enable wagon speed limits
Definition: settings_type.h:487
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:712
WID_BV_CAPTION
@ WID_BV_CAPTION
Caption of window.
Definition: build_vehicle_widget.h:15
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:995
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:821
TestedEngineDetails::cargo
CargoID cargo
Cargo type.
Definition: vehicle_gui.h:41
WID_BV_BUILD_SEL
@ WID_BV_BUILD_SEL
Build button.
Definition: build_vehicle_widget.h:25
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
DrawString
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:645
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:57
VehicleCellSize::extend_right
uint extend_right
Extend of the cell to the right.
Definition: vehicle_gui.h:80
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:319
Engine::GetLifeLengthInDays
Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
Definition: engine.cpp:434
EngineRunningCostSorter
static bool EngineRunningCostSorter(const EngineID &a, const EngineID &b)
Determines order of engines by running costs.
Definition: build_vehicle_gui.cpp:255
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:336
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:838
BuildVehicleWindow::descending_sort_order
bool descending_sort_order
Sort direction,.
Definition: build_vehicle_gui.cpp:1051
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:330
Engine
Definition: engine_base.h:27
BuildVehicleWindow::FilterEngineList
void FilterEngineList()
Filter the engine list against the currently selected cargo filter.
Definition: build_vehicle_gui.cpp:1254
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:369
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Engine::GetDefaultCargoType
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
Definition: engine_base.h:83
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2138
Engine::company_hidden
CompanyMask company_hidden
Bit for each company whether the engine is normally hidden in the build gui for that company.
Definition: engine_base.h:44
RoadVehicleInfo::roadtype
RoadType roadtype
Road type.
Definition: engine_type.h:126
BuildVehicleWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: build_vehicle_gui.cpp:1585
ShipEngineCapacitySorter
static bool ShipEngineCapacitySorter(const EngineID &a, const EngineID &b)
Determines order of ships by capacity.
Definition: build_vehicle_gui.cpp:372
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:631
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1160
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:72
GetEnginePalette
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
Definition: vehicle.cpp:2052
SetDParam
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:196
GetVehicleImageCellSize
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
Definition: depot_gui.cpp:159
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
_engine_sort_show_hidden_engines
bool _engine_sort_show_hidden_engines[]
Last set 'show hidden engines' setting for each vehicle type.
Definition: build_vehicle_gui.cpp:99
INVALID_ROADTYPE
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition: road_type.h:27
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1109
WID_BV_BUILD
@ WID_BV_BUILD
Build panel.
Definition: build_vehicle_widget.h:23
engine_cmd.h
NWidgetCore::widget_data
uint32 widget_data
Data of the widget.
Definition: widget_type.h:335
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:891
GUIList::SetFilterFuncs
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
Definition: sortlist_type.h:341
textbuf_gui.h
TestedEngineDetails::capacity
uint capacity
Cargo capacity.
Definition: vehicle_gui.h:42
train_cmd.h
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:790
DisplayVehicleSortDropDown
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, int button)
Display the dropdown for the vehicle sort criteria.
Definition: build_vehicle_gui.cpp:1028
QSF_LEN_IN_CHARS
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition: textbuf_gui.h:22
CBID_VEHICLE_ADDITIONAL_TEXT
@ CBID_VEHICLE_ADDITIONAL_TEXT
This callback is called from vehicle purchase lists.
Definition: newgrf_callbacks.h:93
WID_BV_SORT_ASCENDING_DESCENDING
@ WID_BV_SORT_ASCENDING_DESCENDING
Sort direction.
Definition: build_vehicle_widget.h:16
WID_BV_PANEL
@ WID_BV_PANEL
Button panel.
Definition: build_vehicle_widget.h:22
BuildVehicleWindow::show_hidden_engines
bool show_hidden_engines
State of the 'show hidden engines' button.
Definition: build_vehicle_gui.cpp:1053
WindowDesc
High level window description.
Definition: window_gui.h:168
GetRailTypeInfo
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
Engine::GetDisplayMaxSpeed
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
Definition: engine.cpp:349
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:21
BuildVehicleWindow::cargo_filter_criteria
byte cargo_filter_criteria
Selected cargo filter.
Definition: build_vehicle_gui.cpp:1060
RailVehicleInfo
Information about a rail vehicle.
Definition: engine_type.h:42
_engine_sort_listing
const StringID _engine_sort_listing[][12]
Dropdown menu strings for the vehicle sort criteria.
Definition: build_vehicle_gui.cpp:485
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:156
GUIList::SetFilterState
void SetFilterState(bool state)
Enable or disable the filter.
Definition: sortlist_type.h:302
RailType
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:317
GetUnionOfArticulatedRefitMasks
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Definition: articulated_vehicles.cpp:255
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:155
newgrf_engine.h
BuildVehicleWindow::listview_mode
bool listview_mode
If set, only display the available vehicles and do not show a 'build' button.
Definition: build_vehicle_gui.cpp:1054
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:993
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
FS_SMALL
@ FS_SMALL
Index of the small font in the font tables.
Definition: gfx_type.h:208
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
MAX_LENGTH_ENGINE_NAME_CHARS
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
Definition: engine_type.h:173
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
SetMatrixDataTip
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1127
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:54
AircraftEngineCargoSorter
static bool AircraftEngineCargoSorter(const EngineID &a, const EngineID &b)
Determines order of aircraft by cargo.
Definition: build_vehicle_gui.cpp:394
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:340
Engine::GetDisplayWeight
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
Definition: engine.cpp:399
ConvertDateToYMD
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
Definition: date.cpp:94
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:386
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
CF_NONE
static const CargoID CF_NONE
Show only vehicles which do not carry cargo (e.g. train engines)
Definition: build_vehicle_gui.cpp:93
safeguards.h
DrawAircraftPurchaseInfo
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
Draw aircraft specific details in the buy window.
Definition: build_vehicle_gui.cpp:791
ShowQueryString
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:1125
BuildVehicleWindow::rename_engine
EngineID rename_engine
Engine being renamed.
Definition: build_vehicle_gui.cpp:1056
vehicle_cmd.h
DEFAULT_GROUP
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Definition: group_type.h:17
TestedEngineDetails
Extra information about refitted cargo and capacity.
Definition: vehicle_gui.h:39
GetGRFStringID
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:601
CargoSpec::weight
uint8 weight
Weight of a single unit of this cargo type in 1/16 ton (62.5 kg).
Definition: cargotype.h:62
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition: gfx_type.h:274
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:58
DrawSprite
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:1044
EnginePowerVsRunningCostSorter
static bool EnginePowerVsRunningCostSorter(const EngineID &a, const EngineID &b)
Determines order of engines by running costs.
Definition: build_vehicle_gui.cpp:272
newgrf_text.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
BuildVehicleWindow::cargo_filter
CargoID cargo_filter[NUM_CARGO+3]
Available cargo filters; CargoID or CF_ANY or CF_NONE or CF_ENGINES.
Definition: build_vehicle_gui.cpp:1058
BuildVehicleWindow::details_height
int details_height
Minimal needed height of the details panels, in text lines (found so far).
Definition: build_vehicle_gui.cpp:1061
build_vehicle_widget.h
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:480
WID_BV_CARGO_FILTER_DROPDOWN
@ WID_BV_CARGO_FILTER_DROPDOWN
Cargo filter dropdown.
Definition: build_vehicle_widget.h:18
DAYS_IN_LEAP_YEAR
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Definition: date_type.h:30
Engine::GetCost
Money GetCost() const
Return how much a new engine costs.
Definition: engine.cpp:309
BuildVehicleWindow::sort_criteria
byte sort_criteria
Current sort criterium.
Definition: build_vehicle_gui.cpp:1052
date_func.h
WID_BV_RENAME
@ WID_BV_RENAME
Rename button.
Definition: build_vehicle_widget.h:26
EnginePowerSorter
static bool EnginePowerSorter(const EngineID &a, const EngineID &b)
Determines order of engines by power.
Definition: build_vehicle_gui.cpp:221
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:73
stdafx.h
_engine_sort_last_criteria
byte _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
Definition: build_vehicle_gui.cpp:97
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
BuildVehicleWindow::FilterSingleEngine
bool FilterSingleEngine(EngineID eid)
Filter a single engine.
Definition: build_vehicle_gui.cpp:1265
RailVehicleInfo::pow_wag_power
uint16 pow_wag_power
Extra power applied to consist if wagon should be powered.
Definition: engine_type.h:55
IsArticulatedVehicleRefittable
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Definition: articulated_vehicles.cpp:203
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:27
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition: engine_type.h:29
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
FONT_HEIGHT_SMALL
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Definition: gfx_func.h:165
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:979
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
EngineTractiveEffortSorter
static bool EngineTractiveEffortSorter(const EngineID &a, const EngineID &b)
Determines order of engines by tractive effort.
Definition: build_vehicle_gui.cpp:238
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:362
EngList_SortPartial
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
Sort selected range of items (on indices @ <begin, begin+num_items-1>)
Definition: engine_gui.cpp:340
YearMonthDay::year
Year year
Year (0...)
Definition: date_type.h:105
string_func.h
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition: newgrf_callbacks.h:404
RailtypeInfo::acceleration_type
uint8 acceleration_type
Acceleration type of this rail type.
Definition: rail.h:223
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
_engine_sort_last_cargo_criteria
static CargoID _engine_sort_last_cargo_criteria[]
Last set filter criteria, for each vehicle type.
Definition: build_vehicle_gui.cpp:100
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:226
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
vehicle_func.h
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1094
station_base.h
WID_BV_SCROLLBAR
@ WID_BV_SCROLLBAR
Scrollbar of list.
Definition: build_vehicle_widget.h:21
PALETTE_CRASH
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Definition: sprites.h:1596
engine_gui.h
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
_sorted_standard_cargo_specs
span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:153
Engine::IsHidden
bool IsHidden(CompanyID c) const
Check whether the engine is hidden in the GUI for the given company.
Definition: engine_base.h:123
Engine::CanCarryCargo
bool CanCarryCargo() const
Determines whether an engine can carry something.
Definition: engine.cpp:161
GroupID
uint16 GroupID
Type for all group identifiers.
Definition: group_type.h:13
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:520
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:189
WC_BUILD_VEHICLE
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
Definition: window_type.h:375
WIDGET_LIST_END
static const int WIDGET_LIST_END
indicate the end of widgets' list for vararg functions
Definition: widget_type.h:20
EngineReliabilitySorter
static bool EngineReliabilitySorter(const EngineID &a, const EngineID &b)
Determines order of engines by reliability.
Definition: build_vehicle_gui.cpp:170
VehicleSettings::roadveh_acceleration_model
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
Definition: settings_type.h:484
Engine::GetPower
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
Definition: engine.cpp:381
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:168
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1209
BuildVehicleWindow::UpdateWidgetSize
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: build_vehicle_gui.cpp:1548
geometry_func.hpp
GUIList< EngineID, CargoID >::FilterFunction
bool CDECL FilterFunction(const EngineID *, CargoID)
Signature of filter function.
Definition: sortlist_type.h:49
BuildVehicleWindow::roadtype
RoadType roadtype
Road type to show, or INVALID_ROADTYPE.
Definition: build_vehicle_gui.cpp:1049
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1012
BuildVehicleWindow
GUI for building vehicles.
Definition: build_vehicle_gui.cpp:1045
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition: engine_type.h:28
CcBuildPrimaryVehicle
void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16)
This is the Callback method after the construction attempt of a primary vehicle.
Definition: vehicle_gui.cpp:3129
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
Window::SetWidgetsDisabledState
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:547
GetRailType
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
BuildVehicleWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: build_vehicle_gui.cpp:1422
CT_AUTO_REFIT
@ CT_AUTO_REFIT
Automatically choose cargo type when doing auto refitting.
Definition: cargo_type.h:67
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:65
SpecializedStation< Station, false >::GetByTile
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Definition: base_station_base.h:238
CF_ANY
static const CargoID CF_ANY
Special cargo filter criteria.
Definition: build_vehicle_gui.cpp:92
BuildVehicleWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: build_vehicle_gui.cpp:1646
cargotype.h
RailtypeInfo::build_caption
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition: rail.h:176
EngList_Sort
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
Definition: engine_gui.cpp:327
TestedEngineDetails::cost
Money cost
Refit cost.
Definition: vehicle_gui.h:40
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:224
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
GUIList::Filter
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
Definition: sortlist_type.h:318
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1776
BuildVehicleWindow::railtype
RailType railtype
Rail type to show, or INVALID_RAILTYPE.
Definition: build_vehicle_gui.cpp:1048
GetGroupNumEngines
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
Get the number of engines with EngineID id_e in the group with GroupID id_g and its sub-groups.
Definition: group_cmd.cpp:757
company_func.h
ShowRefitOptionsList
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
Display list of cargo types of the engine, for the purchase information window.
Definition: vehicle_gui.cpp:1130
BuildVehicleWindow::sel_engine
EngineID sel_engine
Currently selected engine, or INVALID_ENGINE.
Definition: build_vehicle_gui.cpp:1055
BuildVehicleWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: build_vehicle_gui.cpp:1248
network.h
CommandHelper
Definition: command_func.h:94
WID_BV_LIST
@ WID_BV_LIST
List of vehicles.
Definition: build_vehicle_widget.h:20
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: window_gui.h:81
window_func.h
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:370
BuildVehicleWindow::cargo_filter_texts
StringID cargo_filter_texts[NUM_CARGO+4]
Texts for filter_cargo, terminated by INVALID_STRING_ID.
Definition: build_vehicle_gui.cpp:1059
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
YearMonthDay
Data structure to convert between Date and triplet (year, month, and day).
Definition: date_type.h:104
Scrollbar::SetCapacityFromWidget
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:2212
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:690
OverflowSafeInt< int64 >
AircraftRangeSorter
static bool AircraftRangeSorter(const EngineID &a, const EngineID &b)
Determines order of aircraft by range.
Definition: build_vehicle_gui.cpp:422
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1176
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:190
ToPercent16
static uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
Definition: math_func.hpp:238
HasPowerOnRoad
static bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
Definition: road.h:239
engine_base.h
TrainEngineCapacitySorter
static bool TrainEngineCapacitySorter(const EngineID &a, const EngineID &b)
Determines order of train engines by capacity.
Definition: build_vehicle_gui.cpp:314
BuildVehicleWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: build_vehicle_gui.cpp:1513
BuildVehicleWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: build_vehicle_gui.cpp:1671
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:736
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1078
CcBuildWagon
void CcBuildWagon(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16, TileIndex tile, EngineID, bool, CargoID, ClientID)
Callback for building wagons.
Definition: train_gui.cpp:30
BuildVehicleWindow::UpdateFilterByTile
void UpdateFilterByTile()
Set the filter type according to the depot type.
Definition: build_vehicle_gui.cpp:1135
articulated_vehicles.h
GameSettings::vehicle
VehicleSettings vehicle
options for vehicles
Definition: settings_type.h:589
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition: newgrf_commons.cpp:516
ShowAdditionalText
static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
Display additional text from NewGRF in the purchase information window.
Definition: build_vehicle_gui.cpp:854
Window
Data structure for an opened window.
Definition: window_gui.h:279
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:380
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
RailtypeInfo::strings
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:636
GetArticulatedVehicleCargoesAndRefits
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint cargo_capacity)
Get the default cargoes and refits of an articulated vehicle.
Definition: articulated_vehicles.cpp:172
EngList_SortTypeFunction
bool EngList_SortTypeFunction(const EngineID &, const EngineID &)
argument type for EngList_Sort.
Definition: engine_gui.h:20
EngineNumberSorter
static bool EngineNumberSorter(const EngineID &a, const EngineID &b)
Determines order of engines by engineID.
Definition: build_vehicle_gui.cpp:108
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:352
Engine::GetRange
uint16 GetRange() const
Get the range of an aircraft type.
Definition: engine.cpp:444
autoreplace_func.h
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:227
CanVehicleUseStation
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Definition: vehicle.cpp:2861
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
CT_INVALID
@ CT_INVALID
Invalid cargo type.
Definition: cargo_type.h:69
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:311
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
CT_NO_REFIT
@ CT_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
Definition: cargo_type.h:68
RoadTypeInfo::build_caption
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition: road.h:103
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:186
ShipVehicleInfo::ApplyWaterClassSpeedFrac
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
Definition: engine_type.h:79
EngineHasReplacementForCompany
static bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
Definition: autoreplace_func.h:51
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
SetDParamMaxDigits
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:110
DrawVehiclePurchaseInfo
int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te)
Draw the purchase info details of a vehicle at a given location.
Definition: build_vehicle_gui.cpp:876
IsEngineBuildable
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
Definition: engine.cpp:1105
GetEngineListHeight
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
Definition: build_vehicle_gui.cpp:48
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:447
Engine::intro_date
Date intro_date
Date of introduction of the engine.
Definition: engine_base.h:29
Engine::GetAircraftTypeText
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
Definition: engine.cpp:458
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
GetGRFConfig
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
Definition: newgrf_config.cpp:771
DrawVehicleEngine
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
Definition: engine_gui.cpp:297
VehicleCellSize::extend_left
uint extend_left
Extend of the cell to the left.
Definition: vehicle_gui.h:79
BuildVehicleWindow::filter
union BuildVehicleWindow::@0 filter
Filter to apply.
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:105
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:598
Engine::reliability
uint16 reliability
Current reliability of the engine.
Definition: engine_base.h:31
Engine::type
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
Definition: engine_base.h:46
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
BuildVehicleWindow::SetCargoFilterArray
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
Definition: build_vehicle_gui.cpp:1165
GRFConfig::GetName
const char * GetName() const
Get the name of this grf.
Definition: newgrf_config.cpp:105
engine_func.h
RoadTypeInfo::strings
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
EngineNameSorter
static bool EngineNameSorter(const EngineID &a, const EngineID &b)
Determines order of engines by name.
Definition: build_vehicle_gui.cpp:141
INVALID_RAILTYPE
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition: rail_type.h:34
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62