Go to the documentation of this file.
40 #include "table/strings.h"
54 static const NWidgetPart _nested_build_vehicle_widgets[] = {
76 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_BV_LIST),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_BV_SCROLLBAR),
126 const int r = va - vb;
144 static char last_name[2][64] = {
"",
"" };
150 GetString(last_name[0], STR_ENGINE_NAME,
lastof(last_name[0]));
156 GetString(last_name[1], STR_ENGINE_NAME,
lastof(last_name[1]));
159 int r =
strnatcmp(last_name[0], last_name[1]);
176 const int r = va - vb;
297 double v_a = (double)p_a / (
double)r_a;
298 double v_b = (double)p_b / (
double)r_b;
340 int r = val_a - val_b;
401 uint16 mail_a, mail_b;
489 STR_SORT_BY_ENGINE_ID,
491 STR_SORT_BY_MAX_SPEED,
493 STR_SORT_BY_TRACTIVE_EFFORT,
494 STR_SORT_BY_INTRO_DATE,
496 STR_SORT_BY_RUNNING_COST,
497 STR_SORT_BY_POWER_VS_RUNNING_COST,
498 STR_SORT_BY_RELIABILITY,
499 STR_SORT_BY_CARGO_CAPACITY,
503 STR_SORT_BY_ENGINE_ID,
505 STR_SORT_BY_MAX_SPEED,
507 STR_SORT_BY_TRACTIVE_EFFORT,
508 STR_SORT_BY_INTRO_DATE,
510 STR_SORT_BY_RUNNING_COST,
511 STR_SORT_BY_POWER_VS_RUNNING_COST,
512 STR_SORT_BY_RELIABILITY,
513 STR_SORT_BY_CARGO_CAPACITY,
517 STR_SORT_BY_ENGINE_ID,
519 STR_SORT_BY_MAX_SPEED,
520 STR_SORT_BY_INTRO_DATE,
522 STR_SORT_BY_RUNNING_COST,
523 STR_SORT_BY_RELIABILITY,
524 STR_SORT_BY_CARGO_CAPACITY,
528 STR_SORT_BY_ENGINE_ID,
530 STR_SORT_BY_MAX_SPEED,
531 STR_SORT_BY_INTRO_DATE,
533 STR_SORT_BY_RUNNING_COST,
534 STR_SORT_BY_RELIABILITY,
535 STR_SORT_BY_CARGO_CAPACITY,
549 return (cid ==
CF_NONE ? refit_mask == 0 :
HasBit(refit_mask, cid));
572 static int DrawCargoCapacityInfo(
int left,
int right,
int y,
TestedEngineDetails &te,
bool refittable)
579 SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
580 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
596 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
599 DrawString(left, right, y, STR_PURCHASE_INFO_COST);
607 DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
615 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED);
621 if (rvi->running_cost_class != INVALID_PRICE) {
623 DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
640 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_WEIGHT);
644 DrawString(left, right, y, STR_PURCHASE_INFO_COST_WEIGHT);
651 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
657 DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
662 if (rvi->running_cost_class != INVALID_PRICE) {
664 DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
672 DrawString(left, right, y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT);
689 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
692 DrawString(left, right, y, STR_PURCHASE_INFO_COST);
700 DrawString(left, right, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT);
706 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_POWER);
711 DrawString(left, right, y, STR_PURCHASE_INFO_MAX_TE);
719 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
723 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
730 DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
746 if (ocean_speed == canal_speed) {
751 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
755 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
762 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT);
765 DrawString(left, right, y, STR_PURCHASE_INFO_COST);
770 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_OCEAN);
774 DrawString(left, right, y, STR_PURCHASE_INFO_SPEED_CANAL);
781 SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
782 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
787 DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
811 DrawString(left, right, y, STR_PURCHASE_INFO_COST_REFIT_SPEED);
815 DrawString(left, right, y, STR_PURCHASE_INFO_COST_SPEED);
825 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY);
831 SetDParam(2, refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY);
832 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
838 DrawString(left, right, y, STR_PURCHASE_INFO_RUNNINGCOST);
843 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_TYPE);
850 DrawString(left, right, y, STR_PURCHASE_INFO_AIRCRAFT_RANGE);
870 if (callback > 0x400) {
881 void TestedEngineDetails::FillDefaultCapacities(
const Engine *e)
908 bool articulated_cargo =
false;
911 default: NOT_REACHED();
914 y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
916 y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail, te);
918 articulated_cargo =
true;
922 y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
923 articulated_cargo =
true;
927 y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
935 if (articulated_cargo) {
937 int new_y = DrawCargoCapacityInfo(left, right, y, te, refittable);
942 DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY);
954 DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE);
959 DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY);
992 static const int sprite_y_offsets[] = { -1, -1, -2, -2 };
995 assert(max <= eng_list.size());
1001 int sprite_width = sprite_left + sprite_right;
1009 int count_width = 0;
1023 int replace_icon_y_offset = (ir.
Height() - replace_icon.height) / 2;
1026 for (; min < max; min++, y += step_size) {
1027 const auto &item = eng_list[min];
1037 StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
1042 DrawString(itr.left, itr.right, y + normal_text_y_offset, str, tc);
1052 DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, y, fr.right, y + ir.
Height() - 1},
false,
SA_CENTER);
1058 bool continues = (min + 1U) < eng_list.size() && eng_list[min + 1].indent == item.indent;
1074 uint32 hidden_mask = 0;
1109 void SetBuyVehicleText()
1127 for (
const auto &item : source) {
1128 if (item.variant_id !=
parent || item.engine_id ==
parent)
continue;
1141 AddChildren(source, item.engine_id, indent + 1);
1148 this->vehicle_type = type;
1150 this->
window_number = this->listview_mode ? (int)type : (
int)tile;
1169 widget->
tool_tip = STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type;
1172 widget->
tool_tip = STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type;
1175 widget->
widget_data = STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type;
1176 widget->
tool_tip = STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type;
1179 widget->
widget_data = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type;
1180 widget->
tool_tip = STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type;
1181 widget->
SetLowered(this->show_hidden_engines);
1183 this->details_height = ((this->vehicle_type ==
VEH_TRAIN) ? 10 : 9);
1190 this->GenerateBuildList();
1194 auto it = std::find_if(this->eng_list.begin(), this->eng_list.end(), [&](
GUIEngineListItem &item){ return (item.flags & EngineDisplayFlags::Shaded) == EngineDisplayFlags::None; });
1195 if (it != this->eng_list.end()) engine = it->engine_id;
1196 this->SelectEngine(engine);
1202 switch (this->vehicle_type) {
1203 default: NOT_REACHED();
1205 if (this->listview_mode) {
1213 if (this->listview_mode) {
1232 uint filter_items = 0;
1235 this->cargo_filter[filter_items] =
CF_ANY;
1236 this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ALL_TYPES;
1242 this->cargo_filter[filter_items] =
CF_ENGINES;
1243 this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_ENGINES_ONLY;
1248 this->cargo_filter[filter_items] =
CF_NONE;
1249 this->cargo_filter_texts[filter_items] = STR_PURCHASE_INFO_NONE;
1255 this->cargo_filter[filter_items] = cs->Index();
1256 this->cargo_filter_texts[filter_items] = cs->name;
1264 this->cargo_filter_criteria = 0;
1267 for (uint i = 0; i < filter_items; i++) {
1269 this->cargo_filter_criteria = i;
1283 this->sel_engine = engine;
1284 this->SetBuyVehicleText();
1290 if (!this->listview_mode) {
1293 if (ret.Succeeded()) {
1295 this->te.
capacity = refit_capacity;
1305 this->te.FillDefaultCapacities(e);
1316 this->eng_list.
Filter(this->cargo_filter[this->cargo_filter_criteria]);
1317 if (0 == this->eng_list.size()) {
1319 }
else if (std::find(this->eng_list.begin(), this->eng_list.end(), this->sel_engine) == this->eng_list.end()) {
1320 this->SelectEngine(this->eng_list[0].engine_id);
1335 std::vector<EngineID> variants;
1337 size_t num_engines = 0;
1360 if (eid == this->sel_engine) sel_id = eid;
1364 for (
const auto &variant : variants) {
1365 if (std::find(list.begin(), list.end(), variant) == list.end()) {
1372 this->SelectEngine(sel_id);
1390 void GenerateBuildRoadVehList()
1394 this->eng_list.clear();
1404 if (eid == this->sel_engine) sel_id = eid;
1406 this->SelectEngine(sel_id);
1410 void GenerateBuildShipList()
1413 this->eng_list.clear();
1421 if (eid == this->sel_engine) sel_id = eid;
1423 this->SelectEngine(sel_id);
1427 void GenerateBuildAircraftList()
1431 this->eng_list.clear();
1447 if (eid == this->sel_engine) sel_id = eid;
1450 this->SelectEngine(sel_id);
1454 void GenerateBuildList()
1461 this->eng_list.clear();
1465 switch (this->vehicle_type) {
1466 default: NOT_REACHED();
1468 this->GenerateBuildTrainList(list);
1470 this->eng_list.shrink_to_fit();
1474 this->GenerateBuildRoadVehList();
1477 this->GenerateBuildShipList();
1480 this->GenerateBuildAircraftList();
1487 std::vector<EngineID> variants;
1488 for (
const auto &item : this->eng_list) {
1489 if (item.engine_id != item.variant_id && item.variant_id !=
INVALID_ENGINE) variants.push_back(item.variant_id);
1491 for (
const auto &variant : variants) {
1492 if (std::find(this->eng_list.begin(), this->eng_list.end(), variant) == this->eng_list.end()) {
1501 this->eng_list.swap(list);
1503 this->eng_list.shrink_to_fit();
1504 this->eng_list.RebuildDone();
1511 this->descending_sort_order ^=
true;
1513 this->eng_list.ForceRebuild();
1518 this->show_hidden_engines ^=
true;
1520 this->eng_list.ForceRebuild();
1527 size_t num_items = this->eng_list.size();
1529 if (i < num_items) {
1530 const auto &item = this->eng_list[i];
1544 this->SelectEngine(e);
1548 }
else if (click_count > 1 && !this->listview_mode) {
1582 bool refresh =
false;
1601 this->rename_engine = sel_eng;
1617 if (!gui_scope)
return;
1619 if (this->vehicle_type ==
VEH_ROAD &&
1621 this->sort_criteria > 7) {
1622 this->sort_criteria = 0;
1625 this->eng_list.ForceRebuild();
1632 if (this->vehicle_type ==
VEH_TRAIN && !this->listview_mode) {
1635 }
else if (this->vehicle_type ==
VEH_ROAD && !this->listview_mode) {
1639 SetDParam(0, (this->listview_mode ? STR_VEHICLE_LIST_AVAILABLE_TRAINS : STR_BUY_VEHICLE_TRAIN_ALL_CAPTION) + this->vehicle_type);
1648 SetDParam(0, this->cargo_filter_texts[this->cargo_filter_criteria]);
1654 SetDParam(0, STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type);
1656 SetDParam(0, STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1668 size->height = 3 *
resize->height;
1679 d.height += padding.height;
1680 *size =
maxdim(*size, d);
1687 size->width += padding.width;
1688 size->height += padding.height;
1694 size->width += padding.width;
1695 size->height += padding.height;
1709 static_cast<uint16
>(std::min<size_t>(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size())),
1724 this->GenerateBuildList();
1725 this->vscroll->
SetCount((uint)this->eng_list.size());
1742 if (needed_height != this->details_height) {
1744 this->details_height = needed_height;
1753 if (str ==
nullptr)
return;
1762 if (this->sort_criteria != index) {
1763 this->sort_criteria = index;
1765 this->eng_list.ForceRebuild();
1770 if (this->cargo_filter_criteria != index) {
1771 this->cargo_filter_criteria = index;
1774 this->eng_list.SetFilterState(this->cargo_filter[this->cargo_filter_criteria] !=
CF_ANY);
1775 this->eng_list.ForceRebuild();
1776 this->SelectEngine(this->sel_engine);
1790 WDP_AUTO,
"build_vehicle", 240, 268,
1793 _nested_build_vehicle_widgets,
lengthof(_nested_build_vehicle_widgets)
1802 uint num = (tile ==
INVALID_TILE) ? (
int)type : (int)tile;
@ VEH_AIRCRAFT
Aircraft vehicle type.
EngList_SortTypeFunction *const _engine_sort_functions[][11]
Sort functions for the vehicle sort criteria, for each vehicle type.
@ TC_FORCED
Ignore colour changes from strings.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
uint GetDisplayDefaultCapacity(uint16 *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
CargoTypes _standard_cargo_mask
Bitmask of real cargo types available.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
void OnPaint() override
The window must be repainted.
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
static constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by engineID.
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
byte pow_wag_weight
Extra weight applied to consist if wagon should be powered.
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
@ HasVariants
Set if engine has variants.
int Height() const
Get height of Rect.
static Titem * Get(size_t index)
Returns Titem with given index.
TestedEngineDetails te
Tested cost and capacity after refit.
@ INVALID_CLIENT_ID
Client is not part of anything.
uint8 train_acceleration_model
realistic acceleration for trains
bool show_newgrf_name
Show the name of the NewGRF in the build vehicle window.
Dimensions (a width and height) of a rectangle in 2D.
uint64 PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32 extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
CargoArray all_capacities
Capacities for all cargoes.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
VehicleType vehicle_type
Type of vehicles shown in the window.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
uint16 mail_capacity
Mail capacity if available.
bool EngList_SortTypeFunction(const GUIEngineListItem &, const GUIEngineListItem &)
argument type for EngList_Sort.
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
@ IsFolded
Set if display of variants should be folded (hidden).
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
Get the capacity of an engine with articulated parts.
bool _engine_sort_direction
false = descending, true = ascending.
bool _network_server
network-server is active
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
static const CargoID CF_ENGINES
Show only engines (for rail vehicles only)
Tindex index
Index of this pool item.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
@ EIT_PURCHASE
Vehicle drawn in purchase list, autoreplace gui, ...
static bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
Class for storing amounts of cargo.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Money GetRunningCost() const
Return how much the running costs of this engine are.
This struct contains all the info that is needed to draw and construct tracks.
static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by range.
bool wagon_speed_limits
enable wagon speed limits
bool _ctrl_pressed
Is Ctrl pressed?
static bool EngineTractiveEffortSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by tractive effort.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
ClientSettings _settings_client
The current settings for this game.
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.
Specification of a cargo type.
uint extend_right
Extend of the cell to the right.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
bool descending_sort_order
Sort direction,.
static bool RoadVehEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of road vehicles by capacity.
@ SA_RIGHT
Right align the text (must be a single bit).
void FilterEngineList()
Filter the engine list against the currently selected cargo filter.
@ VEH_ROAD
Road vehicle type.
byte GetCount() const
Get the amount of cargos that have an amount.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
CompanyMask company_hidden
Bit for each company whether the engine is normally hidden in the build gui for that company.
RoadType roadtype
Road type.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
bool _engine_sort_show_hidden_engines[]
Last set 'show hidden engines' setting for each vehicle type.
static bool EngineIntroDateSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by introduction date.
@ INVALID_ROADTYPE
flag for invalid roadtype
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
void SetFilterFuncs(FilterFunction *const *n_funcs)
Hand the array of filter function pointers to the sort list.
uint capacity
Cargo capacity.
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.
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, int button)
Display the dropdown for the vehicle sort criteria.
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
@ CBID_VEHICLE_ADDITIONAL_TEXT
This callback is called from vehicle purchase lists.
bool show_hidden_engines
State of the 'show hidden engines' button.
High level window description.
static bool EnginePowerVsRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
EngineID display_last_variant
NOSAVE client-side-only last variant selected.
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
uint16 EngineID
Unique identification number of an engine.
byte cargo_filter_criteria
Selected cargo filter.
Information about a rail vehicle.
const StringID _engine_sort_listing[][12]
Dropdown menu strings for the vehicle sort criteria.
@ WDP_AUTO
Find a place automatically.
void SetFilterState(bool state)
Enable or disable the filter.
RailType
Enumeration for all possible railtypes.
ResizeInfo resize
Resize information.
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
Information about GRF, used in the game and (part of it) in savegames.
static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by purchase cost.
bool listview_mode
If set, only display the available vehicles and do not show a 'build' button.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
@ FS_SMALL
Index of the small font in the font tables.
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
EngineDisplayFlags display_flags
NOSAVE client-side-only display flags for build engine list.
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
static int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
@ Shaded
Set if engine should be masked.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
void ConvertDateToYMD(Date date, YearMonthDay *ymd)
Converts a Date to a Year, Month & Day.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Window * parent
Parent window.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static const CargoID CF_NONE
Show only vehicles which do not carry cargo (e.g. train engines)
void CcBuildPrimaryVehicle(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16, CargoArray)
This is the Callback method after the construction attempt of a primary vehicle.
static bool ShipEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of ships by capacity.
static int DrawAircraftPurchaseInfo(int left, int right, int y, EngineID engine_number, bool refittable, TestedEngineDetails &te)
Draw aircraft specific details in the buy window.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
EngineID rename_engine
Engine being renamed.
WindowFlags flags
Window flags.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Extra information about refitted cargo and capacity.
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
@ TC_NO_SHADE
Do not add shading to this text colour.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
bool _networking
are we in networking mode?
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Coordinates of a point in 2D.
CargoID cargo_filter[NUM_CARGO+3]
Available cargo filters; CargoID or CF_ANY or CF_NONE or CF_ENGINES.
int details_height
Minimal needed height of the details panels, in text lines (found so far).
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.
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Money GetCost() const
Return how much a new engine costs.
byte sort_criteria
Current sort criterium.
byte _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
WindowNumber window_number
Window number within the window class.
VehicleType
Available vehicle types.
bool FilterSingleEngine(EngineID eid)
Filter a single engine.
uint16 pow_wag_power
Extra power applied to consist if wagon should be powered.
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ RAILVEH_WAGON
simple wagon, not motorized
EngineID engine_id
Engine to display in build purchase list.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
#define FONT_HEIGHT_SMALL
Height of characters in the small (FS_SMALL) font.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
bool NeedRebuild() const
Check if a rebuild is needed.
@ Generic
No specific context available.
static bool EngineReliabilitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by reliability.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
uint8 acceleration_type
Acceleration type of this rail type.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static CargoID _engine_sort_last_cargo_criteria[]
Last set filter criteria, for each vehicle type.
@ SBS_DOWN
Sort ascending.
CompanyID _current_company
Company currently doing an action.
static bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by engine / wagon.
static bool EnginePowerSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by power.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by capacity.
static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
bool IsHidden(CompanyID c) const
Check whether the engine is hidden in the GUI for the given company.
uint16 GroupID
Type for all group identifiers.
bool IsShaded() const
Is window shaded currently?
EngineDisplayFlags
Flags used client-side in the purchase/autorenew engine list.
static bool CDECL CargoAndEngineFilter(const GUIEngineListItem *item, const CargoID cid)
Filters vehicles by cargo and engine (in case of rail vehicle).
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
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.
bool CDECL FilterFunction(const GUIEngineListItem *, CargoID)
Signature of filter function.
RoadType roadtype
Road type to show, or INVALID_ROADTYPE.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
GUI for building vehicles.
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
@ CT_AUTO_REFIT
Automatically choose cargo type when doing auto refitting.
@ NUM_CARGO
Maximal number of cargo types in a game.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
static const CargoID CF_ANY
Special cargo filter criteria.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
RoadType
The different roadtypes we support.
RailType railtype
Railtype, mangled if elrail is disabled.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
RailType railtype
Rail type to show, or INVALID_RAILTYPE.
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.
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
Display list of cargo types of the engine, for the purchase information window.
EngineID sel_engine
Currently selected engine, or INVALID_ENGINE.
void OnInit() override
Notification that the nested widget tree gets initialized.
void ForceRebuild()
Force that a rebuild is needed.
@ SA_CENTER
Center both horizontally and vertically.
StringID cargo_filter_texts[NUM_CARGO+4]
Texts for filter_cargo, terminated by INVALID_STRING_ID.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
@ PurchaseList
Name is shown in the purchase list (including autoreplace window).
#define lengthof(x)
Return the length of an fixed size array.
Data structure to convert between Date and triplet (year, month, and day).
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
static bool AircraftEngineCargoSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by cargo.
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, size_t begin, size_t num_items)
Sort selected range of items (on indices @ <begin, begin+num_items-1>)
byte CargoID
Cargo slots to indicate a cargo type within a game.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
static uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
static bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
void OnResize() override
Called after the window got resized.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
static bool EngineNameSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by name.
void UpdateFilterByTile()
Set the filter type according to the depot type.
VehicleSettings vehicle
options for vehicles
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
Display additional text from NewGRF in the purchase information window.
Data structure for an opened window.
void RebuildDone()
Notify the sortlist that the rebuild is done.
@ VEH_TRAIN
Train vehicle type.
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
void DrawWidgets() const
Paint all widgets of a window.
static bool EngineSpeedSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by speed.
@ DC_QUERY_COST
query cost only, don't build.
uint16 GetRange() const
Get the range of an aircraft type.
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
@ CT_INVALID
Invalid cargo type.
@ VEH_SHIP
Ship vehicle type.
Specification of a rectangle with absolute coordinates of all edges.
@ CT_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
StringID build_caption
Caption of the build vehicle GUI for this rail type.
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
static bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
#define lastof(x)
Get the last element of an fixed size array.
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
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.
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, uint16 min, uint16 max, EngineID selected_id, bool show_count, GroupID selected_group)
Engine drawing loop.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Date intro_date
Date of introduction of the engine.
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
uint extend_left
Extend of the cell to the left.
union BuildVehicleWindow::@0 filter
Filter to apply.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Dynamic data of a loaded NewGRF.
GUISettings gui
settings related to the GUI
uint16 reliability
Current reliability of the engine.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
const char * GetName() const
Get the name of this grf.
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
@ INVALID_RAILTYPE
Flag for invalid railtype.
void CcBuildWagon(Commands cmd, const CommandCost &result, VehicleID new_veh_id, uint, uint16, CargoArray, TileIndex tile, EngineID, bool, CargoID, ClientID)
Callback for building wagons.