OpenTTD
Data Structures | Functions | Variables
build_vehicle_gui.cpp File Reference

GUI for building vehicles. More...

#include "stdafx.h"
#include "engine_base.h"
#include "engine_func.h"
#include "station_base.h"
#include "network/network.h"
#include "articulated_vehicles.h"
#include "textbuf_gui.h"
#include "command_func.h"
#include "company_func.h"
#include "vehicle_gui.h"
#include "newgrf_engine.h"
#include "newgrf_text.h"
#include "group.h"
#include "string_func.h"
#include "strings_func.h"
#include "window_func.h"
#include "date_func.h"
#include "vehicle_func.h"
#include "widgets/dropdown_func.h"
#include "engine_gui.h"
#include "cargotype.h"
#include "core/geometry_func.hpp"
#include "autoreplace_func.h"
#include "widgets/build_vehicle_widget.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Data Structures

struct  BuildVehicleWindow
 GUI for building vehicles. More...
 

Functions

uint GetEngineListHeight (VehicleType type)
 Get the height of a single 'entry' in the engine lists. More...
 
static int CDECL EngineNumberSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by engineID. More...
 
static int CDECL EngineIntroDateSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by introduction date. More...
 
static int CDECL EngineNameSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by name. More...
 
static int CDECL EngineReliabilitySorter (const EngineID *a, const EngineID *b)
 Determines order of engines by reliability. More...
 
static int CDECL EngineCostSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by purchase cost. More...
 
static int CDECL EngineSpeedSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by speed. More...
 
static int CDECL EnginePowerSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by power. More...
 
static int CDECL EngineTractiveEffortSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by tractive effort. More...
 
static int CDECL EngineRunningCostSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by running costs. More...
 
static int CDECL EnginePowerVsRunningCostSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by running costs. More...
 
static int CDECL TrainEngineCapacitySorter (const EngineID *a, const EngineID *b)
 Determines order of train engines by capacity. More...
 
static int CDECL TrainEnginesThenWagonsSorter (const EngineID *a, const EngineID *b)
 Determines order of train engines by engine / wagon. More...
 
static int CDECL RoadVehEngineCapacitySorter (const EngineID *a, const EngineID *b)
 Determines order of road vehicles by capacity. More...
 
static int CDECL ShipEngineCapacitySorter (const EngineID *a, const EngineID *b)
 Determines order of ships by capacity. More...
 
static int CDECL AircraftEngineCargoSorter (const EngineID *a, const EngineID *b)
 Determines order of aircraft by cargo. More...
 
static int CDECL AircraftRangeSorter (const EngineID *a, const EngineID *b)
 Determines order of aircraft by range. More...
 
static bool CDECL CargoFilter (const EngineID *eid, const CargoID cid)
 Cargo filter functions.
 
static int DrawCargoCapacityInfo (int left, int right, int y, EngineID engine)
 
static int DrawRailWagonPurchaseInfo (int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
 
static int DrawRailEnginePurchaseInfo (int left, int right, int y, EngineID engine_number, const RailVehicleInfo *rvi)
 
static int DrawRoadVehPurchaseInfo (int left, int right, int y, EngineID engine_number)
 
static int DrawShipPurchaseInfo (int left, int right, int y, EngineID engine_number, bool refittable)
 
static int DrawAircraftPurchaseInfo (int left, int right, int y, EngineID engine_number, bool refittable)
 Draw aircraft specific details in the buy window. More...
 
static uint ShowAdditionalText (int left, int right, int y, EngineID engine)
 Display additional text from NewGRF in the purchase information window. More...
 
int DrawVehiclePurchaseInfo (int left, int right, int y, EngineID engine_number)
 Draw the purchase info details of a vehicle at a given location. More...
 
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. More...
 
void DisplayVehicleSortDropDown (Window *w, VehicleType vehicle_type, int selected, int button)
 Display the dropdown for the vehicle sort criteria. More...
 
void ShowBuildVehicleWindow (TileIndex tile, VehicleType type)
 

Variables

static const NWidgetPart _nested_build_vehicle_widgets []
 
static const CargoID CF_ANY = CT_NO_REFIT
 Special cargo filter criteria. More...
 
static const CargoID CF_NONE = CT_INVALID
 Show only vehicles which do not carry cargo (e.g. train engines)
 
bool _engine_sort_direction
 false = descending, true = ascending.
 
byte _engine_sort_last_criteria [] = {0, 0, 0, 0}
 Last set sort criteria, for each vehicle type.
 
bool _engine_sort_last_order [] = {false, false, false, false}
 Last set direction of the sort order, for each vehicle type.
 
bool _engine_sort_show_hidden_engines [] = {false, false, false, false}
 Last set 'show hidden engines' setting for each vehicle type.
 
static CargoID _engine_sort_last_cargo_criteria [] = {CF_ANY, CF_ANY, CF_ANY, CF_ANY}
 Last set filter criteria, for each vehicle type.
 
EngList_SortTypeFunction *const _engine_sort_functions [][11]
 Sort functions for the vehicle sort criteria, for each vehicle type. More...
 
const StringID _engine_sort_listing [][12]
 Dropdown menu strings for the vehicle sort criteria. More...
 
static GUIEngineList::FilterFunction *const _filter_funcs []
 
static WindowDesc _build_vehicle_desc (WDP_AUTO, "build_vehicle", 240, 268, WC_BUILD_VEHICLE, WC_NONE, WDF_CONSTRUCTION, _nested_build_vehicle_widgets, lengthof(_nested_build_vehicle_widgets))
 

Detailed Description

GUI for building vehicles.

Definition in file build_vehicle_gui.cpp.

Function Documentation

◆ AircraftEngineCargoSorter()

static int CDECL AircraftEngineCargoSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of aircraft by cargo.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 379 of file build_vehicle_gui.cpp.

References _engine_sort_direction, EngineNumberSorter(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), and Engine::GetDisplayDefaultCapacity().

◆ AircraftRangeSorter()

static int CDECL AircraftRangeSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of aircraft by range.

Parameters
*afirst engine to compare.
*bsecond engine to compare.
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal.

Definition at line 407 of file build_vehicle_gui.cpp.

References _engine_sort_direction, EngineNumberSorter(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

◆ DisplayVehicleSortDropDown()

void DisplayVehicleSortDropDown ( Window w,
VehicleType  vehicle_type,
int  selected,
int  button 
)

Display the dropdown for the vehicle sort criteria.

Parameters
wParent window (holds the dropdown button).
vehicle_typeVehicle type being sorted.
selectedCurrently selected sort criterium.
buttonWidget button.

Definition at line 956 of file build_vehicle_gui.cpp.

References _settings_game, VehicleSettings::roadveh_acceleration_model, VEH_ROAD, and GameSettings::vehicle.

Referenced by ReplaceVehicleWindow::OnClick(), and BuildVehicleWindow::OnClick().

◆ DrawAircraftPurchaseInfo()

static int DrawAircraftPurchaseInfo ( int  left,
int  right,
int  y,
EngineID  engine_number,
bool  refittable 
)
static

Draw aircraft specific details in the buy window.

Parameters
leftLeft edge of the window to draw in.
rightRight edge of the window to draw in.
yTop of the area to draw in.
engine_numberEngine to display.
refittableIf set, the aircraft can be refitted.
Returns
Bottom of the used area.

Definition at line 731 of file build_vehicle_gui.cpp.

◆ 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.

Parameters
typeType of vehicle (VEH_*)
lThe left most location of the list
rThe right most location of the list
yThe top most location of the list
eng_listWhat engines to draw
minwhere to start in the list
maxwhere in the list to end
selected_idwhat engine to highlight as selected, if any
show_countWhether to show the amount of engines or not
selected_groupthe group to list the engines of

Definition at line 894 of file build_vehicle_gui.cpp.

Referenced by BuildVehicleWindow::DrawWidget().

◆ DrawVehiclePurchaseInfo()

int DrawVehiclePurchaseInfo ( int  left,
int  right,
int  y,
EngineID  engine_number 
)

Draw the purchase info details of a vehicle at a given location.

Parameters
left,right,ylocation where to draw the info
engine_numberthe engine of which to draw the info of
Returns
y after drawing all the text

Definition at line 812 of file build_vehicle_gui.cpp.

Referenced by ReplaceVehicleWindow::OnPaint(), and BuildVehicleWindow::OnPaint().

◆ EngineCostSorter()

static int CDECL EngineCostSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of engines by purchase cost.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 186 of file build_vehicle_gui.cpp.

References _engine_sort_direction, ClampToI32(), EngineNumberSorter(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

◆ EngineIntroDateSorter()

static int CDECL EngineIntroDateSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of engines by introduction date.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 119 of file build_vehicle_gui.cpp.

References _engine_sort_direction, EngineNumberSorter(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

◆ EngineNameSorter()

static int CDECL EngineNameSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of engines by name.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 136 of file build_vehicle_gui.cpp.

References INVALID_ENGINE, and SetDParam().

◆ EngineNumberSorter()

static int CDECL EngineNumberSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of engines by engineID.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 106 of file build_vehicle_gui.cpp.

References _engine_sort_direction, and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

Referenced by AircraftEngineCargoSorter(), AircraftRangeSorter(), EngineCostSorter(), EngineIntroDateSorter(), EnginePowerSorter(), EnginePowerVsRunningCostSorter(), EngineReliabilitySorter(), EngineRunningCostSorter(), EngineSpeedSorter(), EngineTractiveEffortSorter(), RoadVehEngineCapacitySorter(), and ShipEngineCapacitySorter().

◆ EnginePowerSorter()

static int CDECL EnginePowerSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of engines by power.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 220 of file build_vehicle_gui.cpp.

References _engine_sort_direction, EngineNumberSorter(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

◆ EnginePowerVsRunningCostSorter()

static int CDECL EnginePowerVsRunningCostSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of engines by running costs.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 271 of file build_vehicle_gui.cpp.

References _engine_sort_direction, ClampToI32(), EngineNumberSorter(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetPower(), Engine::GetRunningCost(), and max().

◆ EngineReliabilitySorter()

static int CDECL EngineReliabilitySorter ( const EngineID a,
const EngineID b 
)
static

Determines order of engines by reliability.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 169 of file build_vehicle_gui.cpp.

References _engine_sort_direction, EngineNumberSorter(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

◆ EngineRunningCostSorter()

static int CDECL EngineRunningCostSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of engines by running costs.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 254 of file build_vehicle_gui.cpp.

References _engine_sort_direction, ClampToI32(), EngineNumberSorter(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

◆ EngineSpeedSorter()

static int CDECL EngineSpeedSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of engines by speed.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 203 of file build_vehicle_gui.cpp.

References _engine_sort_direction, EngineNumberSorter(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

◆ EngineTractiveEffortSorter()

static int CDECL EngineTractiveEffortSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of engines by tractive effort.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 237 of file build_vehicle_gui.cpp.

References _engine_sort_direction, EngineNumberSorter(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get().

◆ GetEngineListHeight()

uint GetEngineListHeight ( VehicleType  type)

Get the height of a single 'entry' in the engine lists.

Parameters
typethe vehicle type to get the height of
Returns
the height for the entry

Definition at line 47 of file build_vehicle_gui.cpp.

References EIT_PURCHASE, FONT_HEIGHT_NORMAL, GetVehicleImageCellSize(), VehicleCellSize::height, WD_MATRIX_BOTTOM, and WD_MATRIX_TOP.

Referenced by ReplaceVehicleWindow::UpdateWidgetSize(), and BuildVehicleWindow::UpdateWidgetSize().

◆ RoadVehEngineCapacitySorter()

static int CDECL RoadVehEngineCapacitySorter ( const EngineID a,
const EngineID b 
)
static

Determines order of road vehicles by capacity.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 338 of file build_vehicle_gui.cpp.

References _engine_sort_direction, EngineNumberSorter(), and GetTotalCapacityOfArticulatedParts().

◆ ShipEngineCapacitySorter()

static int CDECL ShipEngineCapacitySorter ( const EngineID a,
const EngineID b 
)
static

Determines order of ships by capacity.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 357 of file build_vehicle_gui.cpp.

References _engine_sort_direction, EngineNumberSorter(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), and Engine::GetDisplayDefaultCapacity().

◆ ShowAdditionalText()

static uint ShowAdditionalText ( int  left,
int  right,
int  y,
EngineID  engine 
)
static

Display additional text from NewGRF in the purchase information window.

Parameters
leftLeft border of text bounding box
rightRight border of text bounding box
yTop border of text bounding box
engineEngine to query the additional purchase information for
Returns
Bottom border of text bounding box

Definition at line 790 of file build_vehicle_gui.cpp.

◆ TrainEngineCapacitySorter()

static int CDECL TrainEngineCapacitySorter ( const EngineID a,
const EngineID b 
)
static

Determines order of train engines by capacity.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 299 of file build_vehicle_gui.cpp.

◆ TrainEnginesThenWagonsSorter()

static int CDECL TrainEnginesThenWagonsSorter ( const EngineID a,
const EngineID b 
)
static

Determines order of train engines by engine / wagon.

Parameters
*afirst engine to compare
*bsecond engine to compare
Returns
for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal

Definition at line 319 of file build_vehicle_gui.cpp.

Variable Documentation

◆ _engine_sort_functions

EngList_SortTypeFunction* const _engine_sort_functions[][11]

Sort functions for the vehicle sort criteria, for each vehicle type.

Definition at line 420 of file build_vehicle_gui.cpp.

◆ _engine_sort_listing

const StringID _engine_sort_listing[][12]

Dropdown menu strings for the vehicle sort criteria.

Definition at line 470 of file build_vehicle_gui.cpp.

Referenced by ReplaceVehicleWindow::SetStringParameters(), and BuildVehicleWindow::SetStringParameters().

◆ _filter_funcs

GUIEngineList::FilterFunction* const _filter_funcs[]
static
Initial value:
= {
}
static bool CDECL CargoFilter(const EngineID *eid, const CargoID cid)
Cargo filter functions.

Definition at line 531 of file build_vehicle_gui.cpp.

◆ CF_ANY

const CargoID CF_ANY = CT_NO_REFIT
static

Special cargo filter criteria.

Show all vehicles independent of carried cargo (i.e. no filtering)

Definition at line 91 of file build_vehicle_gui.cpp.

Referenced by CargoFilter(), BuildVehicleWindow::FilterSingleEngine(), BuildVehicleWindow::OnDropdownSelect(), and BuildVehicleWindow::SetCargoFilterArray().