47#include "table/strings.h"
61static constexpr std::initializer_list<NWidgetPart> _nested_build_vehicle_widgets = {
77 NWidget(
WWT_IMGBTN, COLOUR_GREY,
WID_BV_CONFIGURE_BADGES),
SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
SetResize(0, 0),
SetFill(0, 1),
SetSpriteTip(SPR_EXTRA_MENU, STR_BADGE_CONFIG_MENU_TOOLTIP),
80 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_BV_FILTER),
SetResize(1, 0),
SetFill(1, 0),
SetPadding(2),
SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
87 NWidget(
WWT_MATRIX, COLOUR_GREY,
WID_BV_LIST),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0),
SetScrollbar(
WID_BV_SCROLLBAR),
133 const auto r = va - vb;
141static EngineID _last_engine[2] = { EngineID::Invalid(), EngineID::Invalid() };
151 static std::string last_name[2] = { {}, {} };
180 const int r = va - vb;
301 double v_a = (double)p_a / (
double)r_a;
302 double v_b = (double)p_b / (
double)r_b;
344 int r = val_a - val_b;
405 uint16_t mail_a, mail_b;
493 STR_SORT_BY_ENGINE_ID,
495 STR_SORT_BY_MAX_SPEED,
497 STR_SORT_BY_TRACTIVE_EFFORT,
498 STR_SORT_BY_INTRO_DATE,
500 STR_SORT_BY_RUNNING_COST,
501 STR_SORT_BY_POWER_VS_RUNNING_COST,
502 STR_SORT_BY_RELIABILITY,
503 STR_SORT_BY_CARGO_CAPACITY,
506 STR_SORT_BY_ENGINE_ID,
508 STR_SORT_BY_MAX_SPEED,
510 STR_SORT_BY_TRACTIVE_EFFORT,
511 STR_SORT_BY_INTRO_DATE,
513 STR_SORT_BY_RUNNING_COST,
514 STR_SORT_BY_POWER_VS_RUNNING_COST,
515 STR_SORT_BY_RELIABILITY,
516 STR_SORT_BY_CARGO_CAPACITY,
519 STR_SORT_BY_ENGINE_ID,
521 STR_SORT_BY_MAX_SPEED,
522 STR_SORT_BY_INTRO_DATE,
524 STR_SORT_BY_RUNNING_COST,
525 STR_SORT_BY_RELIABILITY,
526 STR_SORT_BY_CARGO_CAPACITY,
529 STR_SORT_BY_ENGINE_ID,
531 STR_SORT_BY_MAX_SPEED,
532 STR_SORT_BY_INTRO_DATE,
534 STR_SORT_BY_RUNNING_COST,
535 STR_SORT_BY_RELIABILITY,
536 STR_SORT_BY_CARGO_CAPACITY,
561 if (cap[cargo] != 0) {
563 weight +=
CargoSpec::Get(cargo)->WeightOfNUnitsInTrain(cap[cargo]);
572static int DrawCargoCapacityInfo(
int left,
int right,
int y,
TestedEngineDetails &te,
bool refittable)
578 DrawString(left, right, y,
GetString(STR_PURCHASE_INFO_CAPACITY, cargo_type, te.
all_capacities[cargo_type], refittable ? STR_PURCHASE_INFO_REFITTABLE : STR_EMPTY));
636 std::string railtypes{};
642 if (!railtypes.empty()) railtypes += list_separator;
653 if (
_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL) {
654 bool is_maglev =
true;
684 if (
_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
729 uint ocean_speed = e->VehInfo<
ShipVehicleInfo>().ApplyWaterClassSpeedFrac(raw_speed,
true);
730 uint canal_speed = e->VehInfo<
ShipVehicleInfo>().ApplyWaterClassSpeedFrac(raw_speed,
false);
732 if (ocean_speed == canal_speed) {
823 std::array<int32_t, 16> regs100;
825 if (callback ==
CALLBACK_FAILED || callback == 0x400)
return std::nullopt;
827 assert(grffile !=
nullptr);
828 if (callback == 0x40F) {
831 if (callback > 0x400) {
854void TestedEngineDetails::FillDefaultCapacities(
const Engine *e)
885 bool articulated_cargo =
false;
888 default: NOT_REACHED();
891 y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->VehInfo<
RailVehicleInfo>(), te);
893 y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->VehInfo<
RailVehicleInfo>(), te);
895 articulated_cargo =
true;
899 y = DrawRoadVehPurchaseInfo(left, right, y, engine_number, te);
900 articulated_cargo =
true;
904 y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable, te);
912 if (articulated_cargo) {
914 int new_y = DrawCargoCapacityInfo(left, right, y, te, refittable);
917 DrawString(left, right, y,
GetString(STR_PURCHASE_INFO_CAPACITY, INVALID_CARGO, 0, STR_EMPTY));
971 static const std::array<int8_t, VehicleType::VEH_COMPANY_END> sprite_y_offsets = { 0, 0, -1, -1 };
979 int sprite_width = sprite_left + sprite_right;
983 auto badge_column_widths = badge_classes.GetColumnWidths();
993 uint biggest_num_engines = 0;
994 for (
auto it = first; it != last; ++it) {
996 biggest_num_engines = std::max(biggest_num_engines, num_engines);
1006 const int offset = (rtl ? -circle_width : circle_width) / 2;
1009 for (
auto it = first; it != last; ++it) {
1010 const auto &item = *it;
1021 if (item.indent > 0) {
1023 int tx = (rtl ? ir.right : ir.left) + offset;
1024 for (uint lvl = 1; lvl <= item.indent; ++lvl) {
1026 if (lvl < item.indent) tx += level_width;
1031 GfxDrawLine(tx, ycentre, tx + offset - (rtl ? -1 : 1), ycentre, linecolour,
WidgetDimensions::scaled.fullbevel.top);
1036 DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, fr.
WithY(textr),
SA_CENTER);
1045 if (badge_column_widths.size() >= 1 && badge_column_widths[0] > 0) {
1047 DrawEngineBadgeColumn(br, 0, badge_classes, e, pal);
1048 tr = tr.
Indent(badge_column_widths[0], rtl);
1051 int sprite_x = tr.
WithWidth(sprite_width, rtl).left + sprite_left;
1056 if (badge_column_widths.size() >= 2 && badge_column_widths[1] > 0) {
1058 DrawEngineBadgeColumn(br, 1, badge_classes, e, pal);
1059 tr = tr.
Indent(badge_column_widths[1], rtl);
1073 DrawSpriteIgnorePadding(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ?
PALETTE_CRASH : PAL_NONE, rr,
SA_CENTER);
1077 if (badge_column_widths.size() >= 3 && badge_column_widths[2] > 0) {
1079 DrawEngineBadgeColumn(br, 2, badge_classes, e, pal);
1080 tr = tr.
Indent(badge_column_widths[2], !rtl);
1084 StringID str = hidden ? STR_HIDDEN_ENGINE_NAME : STR_ENGINE_NAME;
1089 DrawString(tr.left, tr.right, textr.top + normal_text_y_offset,
GetString(str, engine_name), tc);
1104 uint32_t hidden_mask = 0;
1127 for (
const auto &item : src) {
1128 if (item.variant_id != parent || item.engine_id == parent)
continue;
1131 EngineDisplayFlags flags = item.flags;
1139 dst.emplace_back(item.engine_id, item.engine_id, EngineDisplayFlags{}, indent + 1);
1145 if (indent > 0 || dst.empty())
return;
1148 uint16_t level_mask = 0;
1149 for (
auto it = std::rbegin(dst); std::next(it) != std::rend(dst); ++it) {
1150 auto next_it = std::next(it);
1151 SB(level_mask, it->indent, 1, it->indent <= next_it->indent);
1152 next_it->level_mask = level_mask;
1169 GUIEngineList eng_list{};
1182 BadgeFilterChoices badge_filter_choices{};
1184 void SetBuyVehicleText()
1219 widget->
SetToolTip(STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type);
1222 widget->
SetToolTip(STR_BUY_VEHICLE_TRAIN_HIDE_SHOW_TOGGLE_TOOLTIP + type);
1225 widget->
SetStringTip(STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON + type, STR_BUY_VEHICLE_TRAIN_RENAME_TOOLTIP + type);
1228 widget->
SetStringTip(STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN + type, STR_SHOW_HIDDEN_ENGINES_VEHICLE_TRAIN_TOOLTIP + type);
1244 this->eng_list.ForceRebuild();
1245 this->GenerateBuildList();
1248 EngineID engine = EngineID::Invalid();
1250 if (it != this->eng_list.end()) engine = it->engine_id;
1251 this->SelectEngine(engine);
1257 switch (this->vehicle_type) {
1258 default: NOT_REACHED();
1260 if (this->listview_mode) {
1268 if (this->listview_mode) {
1286 switch (cargo_type) {
1307 CargoType cargo = this->cargo_filter_criteria;
1310 this->sel_engine = engine;
1311 this->SetBuyVehicleText();
1313 if (this->sel_engine == EngineID::Invalid())
return;
1317 if (!this->listview_mode) {
1320 if (ret.Succeeded()) {
1322 this->te.
capacity = refit_capacity;
1332 this->
te.FillDefaultCapacities(e);
1349 this->eng_list.
Filter(this->cargo_filter_criteria);
1350 if (0 == this->eng_list.size()) {
1351 this->SelectEngine(EngineID::Invalid());
1353 this->SelectEngine(this->eng_list[0].engine_id);
1368 if (this->string_filter.
IsEmpty())
return true;
1376 if (text) this->string_filter.AddLine(*text);
1378 return this->string_filter.
GetState();
1382 void GenerateBuildTrainList(GUIEngineList &list)
1385 EngineID sel_id = EngineID::Invalid();
1386 size_t num_engines = 0;
1408 if (!bdf.Filter(e->badges))
continue;
1411 if (!
FilterByText(e) && !btf.Filter(e->badges))
continue;
1427 for (
const auto &variant : variants) {
1431 if (e->VehInfo<RailVehicleInfo>().railveh_type !=
RAILVEH_WAGON) num_engines++;
1435 this->SelectEngine(sel_id);
1438 _last_engine[0] = _last_engine[1] = EngineID::Invalid();
1453 void GenerateBuildRoadVehList()
1455 EngineID sel_id = EngineID::Invalid();
1457 this->eng_list.clear();
1460 BadgeDropdownFilter bdf(this->badge_filter_choices);
1467 if (!bdf.Filter(e->badges))
continue;
1470 if (!
FilterByText(e) && !btf.Filter(e->badges))
continue;
1476 this->SelectEngine(sel_id);
1480 void GenerateBuildShipList()
1482 EngineID sel_id = EngineID::Invalid();
1483 this->eng_list.clear();
1486 BadgeDropdownFilter bdf(this->badge_filter_choices);
1492 if (!bdf.Filter(e->badges))
continue;
1495 if (!
FilterByText(e) && !btf.Filter(e->badges))
continue;
1501 this->SelectEngine(sel_id);
1505 void GenerateBuildAircraftList()
1507 EngineID sel_id = EngineID::Invalid();
1509 this->eng_list.clear();
1514 BadgeDropdownFilter bdf(this->badge_filter_choices);
1526 if (!bdf.Filter(e->badges))
continue;
1529 if (!
FilterByText(e) && !btf.Filter(e->badges))
continue;
1536 this->SelectEngine(sel_id);
1540 void GenerateBuildList()
1542 if (!this->eng_list.NeedRebuild())
return;
1547 this->eng_list.clear();
1552 default: NOT_REACHED();
1554 this->GenerateBuildTrainList(list);
1556 this->eng_list.RebuildDone();
1559 this->GenerateBuildRoadVehList();
1562 this->GenerateBuildShipList();
1565 this->GenerateBuildAircraftList();
1572 FlatSet<EngineID> variants;
1573 for (
const auto &item : this->eng_list) {
1580 for (
const auto &variant : variants) {
1590 this->eng_list.swap(list);
1592 this->eng_list.RebuildDone();
1613 list.push_back(MakeDropDownListIconItem(d, cs->GetCargoIcon(), PAL_NONE, cs->name, cs->Index()));
1621 static const auto separators = {STR_BADGE_CONFIG_PREVIEW, STR_BADGE_CONFIG_NAME};
1622 return BuildBadgeClassConfigurationList(this->badge_classes,
BADGE_COLUMNS, separators, COLOUR_GREY);
1628 if (sel_eng == EngineID::Invalid())
return;
1639 bool refresh =
false;
1641 while (
parent != EngineID::Invalid()) {
1658 this->descending_sort_order ^=
true;
1660 this->eng_list.ForceRebuild();
1665 this->show_hidden_engines ^=
true;
1667 this->eng_list.ForceRebuild();
1675 if (it != this->eng_list.end()) {
1676 const auto &item = *it;
1680 assert(item.
variant_id != EngineID::Invalid());
1690 this->SelectEngine(e);
1694 }
else if (click_count > 1 && !this->listview_mode) {
1705 ShowDropDownList(
this, this->BuildCargoDropDownList(), this->cargo_filter_criteria, widget);
1709 if (this->badge_classes.GetClasses().empty())
break;
1714 const Engine *e = (this->sel_engine == EngineID::Invalid()) ?
nullptr :
Engine::Get(this->sel_engine);
1722 this->BuildVehicle();
1726 EngineID sel_eng = this->sel_engine;
1727 if (sel_eng != EngineID::Invalid()) {
1728 this->rename_engine = sel_eng;
1735 if (
IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) {
1748 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1750 if (!gui_scope)
return;
1752 if (this->vehicle_type ==
VEH_ROAD &&
1753 _settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL &&
1754 this->sort_criteria > 7) {
1755 this->sort_criteria = 0;
1758 this->eng_list.ForceRebuild();
1765 if (this->vehicle_type ==
VEH_TRAIN && !this->listview_mode) {
1769 if (this->vehicle_type ==
VEH_ROAD && !this->listview_mode) {
1773 return GetString((this->listview_mode ? STR_VEHICLE_LIST_AVAILABLE_TRAINS : STR_BUY_VEHICLE_TRAIN_ALL_CAPTION) + this->vehicle_type);
1779 return GetString(this->GetCargoFilterLabel(this->cargo_filter_criteria));
1782 const Engine *e = (this->sel_engine == EngineID::Invalid()) ?
nullptr :
Engine::Get(this->sel_engine);
1784 return GetString(STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type);
1786 return GetString(STR_BUY_VEHICLE_TRAIN_HIDE_TOGGLE_BUTTON + this->vehicle_type);
1790 if (
IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) {
1803 size.height = 3 *
resize.height;
1814 d.height += padding.height;
1825 if (this->badge_classes.GetClasses().empty()) size = {0, 0};
1831 size.width += padding.width;
1832 size.height += padding.height;
1838 size.width += padding.width;
1839 size.height += padding.height;
1868 this->GenerateBuildList();
1869 this->vscroll->
SetCount(this->eng_list.size());
1879 int needed_height = this->details_height;
1881 if (this->sel_engine != EngineID::Invalid()) {
1886 if (needed_height != this->details_height) {
1887 int resize = needed_height - this->details_height;
1888 this->details_height = needed_height;
1897 if (!str.has_value())
return;
1899 Command<Commands::RenameEngine>::Post(STR_ERROR_CAN_T_RENAME_TRAIN_TYPE + this->vehicle_type, this->rename_engine, *str);
1906 if (this->sort_criteria != index) {
1907 this->sort_criteria = index;
1909 this->eng_list.ForceRebuild();
1914 if (this->cargo_filter_criteria != index) {
1915 this->cargo_filter_criteria = index;
1919 this->eng_list.ForceRebuild();
1920 this->SelectEngine(this->sel_engine);
1930 ReplaceDropDownList(
this, this->BuildBadgeConfigurationList(), -1);
1936 this->eng_list.ForceRebuild();
1941 if (
IsInsideMM(widget, this->badge_filters.first, this->badge_filters.second)) {
1947 this->eng_list.ForceRebuild();
1967 static inline HotkeyList hotkeys{
"buildvehicle", {
1973 WDP_AUTO,
"build_vehicle", 240, 268,
1976 _nested_build_vehicle_widgets,
1977 &BuildVehicleWindow::hotkeys
1986 uint num = (tile ==
INVALID_TILE) ? (
int)type : tile.base();
CargoTypes GetUnionOfArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type)
Ors the refit_masks of all articulated parts.
CargoArray GetCapacityOfArticulatedParts(EngineID engine)
Get the capacity of the parts of a given engine.
bool IsArticulatedVehicleRefittable(EngineID engine)
Checks whether any of the articulated parts is refittable.
Functions related to articulated vehicles.
Functions related to autoreplacing.
bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
Check if a company has a replacement set up for the given engine.
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
static bool EngineIntroDateSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by introduction date.
static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by purchase cost.
static CargoType _engine_sort_last_cargo_criteria[]
Last set filter criteria, for each vehicle type.
void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent, uint8_t indent)
Add children to GUI engine list to build a hierarchical tree.
static bool TrainEnginesThenWagonsSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines by engine / wagon.
void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group, const GUIBadgeClasses &badge_classes)
Engine drawing loop.
static bool CargoAndEngineFilter(const GUIEngineListItem *item, const CargoType cargo_type)
Filters vehicles by cargo and engine (in case of rail vehicle).
static std::optional< std::string > GetNewGRFAdditionalText(EngineID engine)
Try to get the NewGRF engine additional text callback as an optional std::string.
static bool AircraftEngineCargoSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by cargo.
bool _engine_sort_last_order[]
Last set direction of the sort order, for each vehicle type.
static bool EngineNumberSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by engineID.
uint GetEngineListHeight(VehicleType type)
Get the height of a single 'entry' in the engine lists.
static bool TrainEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of train engines 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.
static bool EnginePowerVsRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
static bool EngineReliabilitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by reliability.
const std::initializer_list< const StringID > _engine_sort_listing[]
Dropdown menu strings for the vehicle sort criteria.
uint8_t _engine_sort_last_criteria[]
Last set sort criteria, for each vehicle type.
static bool ShipEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of ships by capacity.
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.
static bool EngineTractiveEffortSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by tractive effort.
EngList_SortTypeFunction *const _engine_sort_functions[][11]
Sort functions for the vehicle sort criteria, for each vehicle type.
void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, WidgetID button)
Display the dropdown for the vehicle sort criteria.
static uint ShowAdditionalText(int left, int right, int y, EngineID engine)
Display additional text from NewGRF in the purchase information window.
static bool EngineSpeedSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by speed.
bool _engine_sort_direction
false = descending, true = ascending.
static bool EngineNameSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by name.
static bool EnginePowerSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by power.
static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of engines by running costs.
static bool AircraftRangeSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of aircraft by range.
static bool RoadVehEngineCapacitySorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
Determines order of road vehicles by capacity.
bool _engine_sort_show_hidden_engines[]
Last set 'show hidden engines' setting for each vehicle type.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
Dimension GetLargestCargoIconSize()
Get dimensions of largest cargo icon.
std::span< const CargoSpec * > _sorted_standard_cargo_specs
Standard cargo specifications sorted alphabetically by name.
CargoTypes _standard_cargo_mask
Bitmask of real cargo types available.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Types/functions related to cargoes.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Flip(Tvalue_type value)
Flip the value-th bit.
StringID GetAircraftTypeText() const
Get the name of the aircraft type for display purposes.
uint GetPower() const
Returns the power of the engine for display and sorting purposes.
uint16_t GetRange() const
Get the range of an aircraft type.
uint32_t GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
Money GetCost() const
Return how much a new engine costs.
TimerGameCalendar::Date intro_date
Date of introduction of the engine.
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
uint GetDisplayMaxSpeed() const
Returns max speed of the engine for display purposes.
EngineDisplayFlags display_flags
NOSAVE client-side-only display flags for build engine list.
uint GetDisplayWeight() const
Returns the weight of the engine for display purposes.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
bool IsVariantHidden(CompanyID c) const
Check whether the engine variant chain is hidden in the GUI for the given company.
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
uint GetDisplayDefaultCapacity(uint16_t *mail_capacity=nullptr) const
Determines the default cargo capacity of an engine for display purposes.
CargoType 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.
Money GetRunningCost() const
Return how much the running costs of this engine are.
uint16_t reliability
Current reliability of the engine.
uint GetDisplayMaxTractiveEffort() const
Returns the tractive effort of the engine for display purposes.
bool IsHidden(CompanyID c) const
Check whether the engine is hidden in the GUI for the given company.
EngineID display_last_variant
NOSAVE client-side-only last variant selected.
Flat set implementation that uses a sorted vector for storage.
std::pair< const_iterator, bool > insert(const Tkey &key)
Insert a key into the set, if it does not already exist.
bool Filter(FilterFunction *decide, F filter_data)
Filter the list.
void SetFilterState(bool state)
Enable or disable the filter.
bool(const GUIEngineListItem *, CargoType) FilterFunction
void SetFilterFuncs(std::span< FilterFunction *const > n_funcs)
Hand the filter function pointers to the GUIList.
This struct contains all the info that is needed to draw and construct tracks.
struct RailTypeInfo::@157247141350136173143103254227157213063052244122 strings
Strings associated with the rail type.
VehicleAccelerationModel acceleration_type
Acceleration type of this rail type.
StringID name
Name of this rail type.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
struct RoadTypeInfo::@070000167274302256150317022075324310363002361255 strings
Strings associated with the rail type.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static constexpr Year DateToYear(Date date)
Functions related to commands.
@ QueryCost
query cost only, don't build.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
VehicleCellSize GetVehicleImageCellSize(VehicleType type, EngineImageType image_type)
Get the GUI cell size for a vehicle image.
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options)
Show a drop down list.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
@ Persist
Set if this dropdown should stay open after an option is selected.
@ Invalid
Invalid base price.
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
Check if an engine is buildable.
@ HasVariants
Set if engine has variants.
@ IsFolded
Set if display of variants should be folded (hidden).
@ Shaded
Set if engine should be masked.
Command definitions related to engines.
Functions related to engines.
uint GetTotalCapacityOfArticulatedParts(EngineID engine)
Get the capacity of an engine with articulated parts.
void EngList_Sort(GUIEngineList &el, EngList_SortTypeFunction compare)
Sort all items using quick sort and given 'CompareItems' function.
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>).
void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw an engine.
Engine GUI functions, used by build_vehicle_gui and autoreplace_gui.
bool EngList_SortTypeFunction(const GUIEngineListItem &, const GUIEngineListItem &)
argument type for EngList_Sort.
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF > EngineID
Unique identification number of an engine.
uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data=0)
Combine an engine ID and a name context to an engine name dparam.
@ PurchaseList
Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
@ Generic
No specific context available.
@ AutoreplaceVehicleInUse
Name is show in the autoreplace window 'Vehicles in use' panel.
@ Maglev
Maglev acceleration model.
@ RAILVEH_WAGON
simple wagon, not motorized
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
bool _ctrl_pressed
Is Ctrl pressed?
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
@ SA_CENTER
Center both horizontally and vertically.
uint32_t PaletteID
The number of the palette.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ TC_FORCED
Ignore colour changes from strings.
@ TC_NO_SHADE
Do not add shading to this text colour.
Base class for groups and group functions.
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.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
static constexpr GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
Hotkey related functions.
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
static constexpr CargoType CF_NONE
Show only items which do not carry cargo (e.g. train engines).
static constexpr CargoType CF_ENGINES
Show only engines (for rail vehicles only).
static constexpr CargoType CF_ANY
Show all items independent of carried cargo (i.e. no filtering).
bool _networking
are we in networking mode?
bool _network_server
network-server is active
Basic functions/variables used all over the place.
@ INVALID_CLIENT_ID
Client is not part of anything.
Functions related to NewGRF badges.
Functions related to NewGRF badge configuration.
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
void DrawBadgeColumn(Rect r, int column_group, const GUIBadgeClasses &gui_classes, std::span< const BadgeID > badges, GrfSpecFeature feature, std::optional< TimerGameCalendar::Date > introduction_date, PaletteID remap)
Draw a badge column group.
std::pair< WidgetID, WidgetID > AddBadgeDropdownFilters(Window *window, WidgetID container_id, WidgetID widget, Colours colour, GrfSpecFeature feature)
Add badge drop down filter widgets.
bool HandleBadgeConfigurationDropDownClick(GrfSpecFeature feature, uint columns, int result, int click_result, BadgeFilterChoices &choices)
Handle the badge configuration drop down selection.
void SetBadgeFilter(BadgeFilterChoices &choices, BadgeID badge_index)
Set badge filter choice for a class.
void ResetBadgeFilter(BadgeFilterChoices &choices, BadgeClassID badge_class_index)
Reset badge filter choice for a class.
GUI functions related to NewGRF badges.
@ CBID_VEHICLE_ADDITIONAL_TEXT
This callback is called from vehicle purchase lists.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, std::span< int32_t > regs100)
Evaluate a newgrf callback for vehicles.
Functions for NewGRF engines.
std::string GetGRFStringWithTextStack(const struct GRFFile *grffile, GRFStringID grfstringid, std::span< const int32_t > textstack)
Format a GRF string using the text ref stack for parameters.
Header of Action 04 "universal holder" structure and functions.
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer > GRFStringID
Type for GRF-internal string IDs.
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Base for the GUIs that have an edit box in them.
std::vector< RailType > _sorted_railtypes
Sorted list of rail types.
bool HasPowerOnRail(RailType enginetype, RailType tiletype)
Checks if an engine of the given RailType got power on a tile with a given RailType.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
RailType
Enumeration for all possible railtypes.
@ INVALID_RAILTYPE
Flag for invalid railtype.
bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
RoadType
The different roadtypes we support.
@ INVALID_ROADTYPE
flag for invalid roadtype
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
Base classes/functions for stations.
Definition of base types and functions in a cross-platform compatible way.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Functions related to low-level strings.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Searching and filtering using a stringterm.
std::string_view GetListSeparator()
Get the list separator string for the current language.
void AppendStringInPlace(std::string &result, StringID string)
Resolve the given StringID and append in place into an existing std::string with formatting but no pa...
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
GUI for building vehicles.
VehicleType vehicle_type
Type of vehicles shown in the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static constexpr int BADGE_COLUMNS
Number of columns available for badges (0 = left of image, 1 = between image and name,...
bool FilterByText(const Engine *e)
Filter by name and NewGRF extra text.
void UpdateFilterByTile()
Set the filter type according to the depot type.
bool descending_sort_order
Sort direction,.
bool listview_mode
If set, only display the available vehicles and do not show a 'build' button.
void OnDropdownSelect(WidgetID widget, int index, int click_result) override
A dropdown option associated to this window has been selected.
CargoType cargo_filter_criteria
Selected cargo filter.
void SetCargoFilterArray()
Populate the filter list and set the cargo filter criteria.
RailType railtype
Rail type to show, or INVALID_RAILTYPE.
union BuildVehicleWindow::@015063063316140361220303015310112114302264111156 filter
Filter to apply.
void OnPaint() override
The window must be repainted.
int details_height
Minimal needed height of the details panels, in text lines (found so far).
QueryString vehicle_editbox
Filter editbox.
void OnResize() override
Called after the window got resized.
bool show_hidden_engines
State of the 'show hidden engines' button.
void FilterEngineList()
Filter the engine list against the currently selected cargo filter.
EngineID rename_engine
Engine being renamed.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
TestedEngineDetails te
Tested cost and capacity after refit.
std::pair< WidgetID, WidgetID > badge_filters
First and last widgets IDs of badge filters.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
StringFilter string_filter
Filter for vehicle name.
uint8_t sort_criteria
Current sort criterium.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
bool FilterSingleEngine(EngineID eid)
Filter a single engine.
EngineID sel_engine
Currently selected engine, or EngineID::Invalid().
RoadType roadtype
Road type to show, or INVALID_ROADTYPE.
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Class for storing amounts of cargo.
Specification of a cargo type.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
StringID name
Name of this type of cargo.
Dimensions (a width and height) of a rectangle in 2D.
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
TimerGameCalendar::Date base_intro
Basic date of engine introduction (without random parts).
Information about GRF, used in the game and (part of it) in savegames.
std::string GetName() const
Get the name of this grf.
Dynamic data of a loaded NewGRF.
EngineDisplayFlags flags
Flags for toggling/drawing (un)folded status and controlling indentation.
EngineID variant_id
Variant group of the engine.
EngineID engine_id
Engine to display in build purchase list.
uint8_t indent
Display indentation level.
List of hotkeys for a window.
All data for a single hotkey.
Colour for pixel/line drawing.
static Engine * Get(auto index)
Data stored about a string that can be modified in the GUI.
static const int ACTION_CLEAR
Clear editbox.
Information about a rail vehicle.
RailTypes railtypes
Railtypes, mangled if elrail is disabled.
uint16_t pow_wag_power
Extra power applied to consist if wagon should be powered.
uint8_t pow_wag_weight
Extra weight applied to consist if wagon should be powered.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
int Height() const
Get height of Rect.
Rect WithY(int new_top, int new_bottom) const
Create a new Rect, replacing the top and bottom coordiates.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Information about a ship vehicle.
bool IsEmpty() const
Check whether any filter words were entered.
void SetFilterTerm(std::string_view str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
bool GetState() const
Get the matching state of the current item.
Extra information about refitted cargo and capacity.
CargoType cargo
Cargo type.
CargoArray all_capacities
Capacities for all cargoes.
uint16_t mail_capacity
Mail capacity if available.
uint capacity
Cargo capacity.
std::string_view GetText() const
Get the current text.
uint extend_left
Extend of the cell to the left.
uint extend_right
Extend of the cell to the right.
High level window description.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Window * parent
Parent window.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
ResizeInfo resize
Resize information.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
bool IsShaded() const
Is window shaded currently?
WidgetLookup widget_lookup
Indexed access to the nested widget tree. Do not access directly, use Window::GetWidget() instead.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
std::unique_ptr< NWidgetBase > nested_root
Root of the nested tree.
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
Stuff related to the text buffer GUI.
@ EnableDefault
enable the 'Default' button ("\0" is returned)
@ LengthIsInChars
the length of the string is counted in characters
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition of the game-calendar-timer.
Command definitions related to trains.
void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray, TileIndex tile, EngineID, bool, CargoType, ClientID)
Callback for building wagons.
PaletteID GetEnginePalette(EngineID engine_type, CompanyID company)
Get the colour map for an engine.
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Command definitions for vehicles.
void CcBuildPrimaryVehicle(Commands, const CommandCost &result, VehicleID new_veh_id, uint, uint16_t, CargoArray)
This is the Callback method after the construction attempt of a primary vehicle.
Functions related to vehicles.
bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
uint ShowRefitOptionsList(int left, int right, int y, EngineID engine)
Display list of cargo types of the engine, for the purchase information window.
Functions related to the vehicle's GUIs.
@ EIT_PURCHASE
Vehicle drawn in purchase list, autoreplace gui, ...
VehicleType
Available vehicle types.
@ VEH_INVALID
Non-existing type of vehicle.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
static const uint MAX_LENGTH_VEHICLE_NAME_CHARS
The maximum length of a vehicle name in characters including '\0'.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
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-...
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...
Window functions not directly related to making/drawing windows.
@ Construction
This window is used for construction; close it whenever changing company.
@ SBS_DOWN
Sort ascending.
@ WDP_AUTO
Find a place automatically.
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
@ Station
station encountered (could be a target next time)
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.