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"

Go to the source code of this file.

Data Structures

struct  BuildVehicleWindow

Functions

uint GetEngineListHeight (VehicleType type)
 Get the height of a single 'entry' in the engine lists.
static int CDECL EngineNumberSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by engineID.
static int CDECL EngineIntroDateSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by introduction date.
static int CDECL EngineNameSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by name.
static int CDECL EngineReliabilitySorter (const EngineID *a, const EngineID *b)
 Determines order of engines by reliability.
static int CDECL EngineCostSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by purchase cost.
static int CDECL EngineSpeedSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by speed.
static int CDECL EnginePowerSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by power.
static int CDECL EngineTractiveEffortSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by tractive effort.
static int CDECL EngineRunningCostSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by running costs.
static int CDECL EnginePowerVsRunningCostSorter (const EngineID *a, const EngineID *b)
 Determines order of engines by running costs.
static int CDECL TrainEngineCapacitySorter (const EngineID *a, const EngineID *b)
 Determines order of train engines by capacity.
static int CDECL TrainEnginesThenWagonsSorter (const EngineID *a, const EngineID *b)
 Determines order of train engines by engine / wagon.
static int CDECL RoadVehEngineCapacitySorter (const EngineID *a, const EngineID *b)
 Determines order of road vehicles by capacity.
static int CDECL ShipEngineCapacitySorter (const EngineID *a, const EngineID *b)
 Determines order of ships by capacity.
static int CDECL AircraftEngineCargoSorter (const EngineID *a, const EngineID *b)
 Determines order of aircraft by cargo.
static int CDECL AircraftRangeSorter (const EngineID *a, const EngineID *b)
 Determines order of aircraft by range.
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)
static uint ShowAdditionalText (int left, int right, int y, EngineID engine)
 Display additional text from NewGRF in the purchase information window.
int DrawVehiclePurchaseInfo (int left, int right, int y, EngineID engine_number)
 Draw the purchase info details of a vehicle at a given location.
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.
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.
static const CargoID CF_NONE = CT_INVALID
 Show only vehicles which do not carry cargo (e.g. train engines).
static bool _internal_sort_order
 false = descending, true = ascending
static byte _last_sort_criteria [] = {0, 0, 0, 0}
static bool _last_sort_order [] = {false, false, false, false}
static CargoID _last_filter_criteria [] = {CF_ANY, CF_ANY, CF_ANY, CF_ANY}
static
EngList_SortTypeFunction
*const 
_sorter [][11]
static const StringID _sort_listing [][12]
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

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

Determines order of aircraft by cargo.

Parameters:
*a first engine to compare
*b second 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 375 of file build_vehicle_gui.cpp.

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

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

Determines order of aircraft by range.

Parameters:
*a first engine to compare.
*b second 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 403 of file build_vehicle_gui.cpp.

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

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:
type Type of vehicle (VEH_*)
l The left most location of the list
r The right most location of the list
y The top most location of the list
eng_list What engines to draw
min where to start in the list
max where in the list to end
selected_id what engine to highlight as selected, if any
show_count Whether to show the amount of engines or not
selected_group the group to list the engines of

Definition at line 874 of file build_vehicle_gui.cpp.

References _current_text_dir, _local_company, DrawSprite(), DrawString(), DrawVehicleEngine(), EIT_PURCHASE, EngineHasReplacementForCompany(), VehicleCellSize::extend_left, VehicleCellSize::extend_right, FONT_HEIGHT_SMALL, FS_SMALL, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), GetEngineListHeight(), GetEnginePalette(), GetGroupNumEngines(), GetSpriteSize(), GetStringBoundingBox(), GetVehicleImageCellSize(), PALETTE_CRASH, SA_FORCE, SA_RIGHT, SetDParam(), SetDParamMaxDigits(), WD_FRAMERECT_BOTTOM, WD_FRAMERECT_LEFT, WD_FRAMERECT_RIGHT, and WD_FRAMETEXT_RIGHT.

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

int DrawVehiclePurchaseInfo ( int  left,
int  right,
int  y,
EngineID  engine_number 
)
static int CDECL EngineCostSorter ( const EngineID a,
const EngineID b 
) [static]

Determines order of engines by purchase cost.

Parameters:
*a first engine to compare
*b second 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 182 of file build_vehicle_gui.cpp.

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

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

Determines order of engines by introduction date.

Parameters:
*a first engine to compare
*b second 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 115 of file build_vehicle_gui.cpp.

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

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

Determines order of engines by name.

Parameters:
*a first engine to compare
*b second 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 132 of file build_vehicle_gui.cpp.

References _internal_sort_order, EngineNumberSorter(), INVALID_ENGINE, lastof, SetDParam(), and strnatcmp().

static int CDECL EngineNumberSorter ( const EngineID a,
const EngineID b 
) [static]
static int CDECL EnginePowerSorter ( const EngineID a,
const EngineID b 
) [static]

Determines order of engines by power.

Parameters:
*a first engine to compare
*b second 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 216 of file build_vehicle_gui.cpp.

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

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

Determines order of engines by running costs.

Parameters:
*a first engine to compare
*b second 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 267 of file build_vehicle_gui.cpp.

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

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

Determines order of engines by reliability.

Parameters:
*a first engine to compare
*b second 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 165 of file build_vehicle_gui.cpp.

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

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

Determines order of engines by running costs.

Parameters:
*a first engine to compare
*b second 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 250 of file build_vehicle_gui.cpp.

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

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

Determines order of engines by speed.

Parameters:
*a first engine to compare
*b second 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 199 of file build_vehicle_gui.cpp.

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

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

Determines order of engines by tractive effort.

Parameters:
*a first engine to compare
*b second 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 233 of file build_vehicle_gui.cpp.

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

uint GetEngineListHeight ( VehicleType  type  ) 

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

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

Definition at line 45 of file build_vehicle_gui.cpp.

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

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

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

Determines order of road vehicles by capacity.

Parameters:
*a first engine to compare
*b second 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 334 of file build_vehicle_gui.cpp.

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

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

Determines order of ships by capacity.

Parameters:
*a first engine to compare
*b second 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 353 of file build_vehicle_gui.cpp.

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

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

Display additional text from NewGRF in the purchase information window.

Parameters:
left Left border of text bounding box
right Right border of text bounding box
y Top border of text bounding box
engine Engine to query the additional purchase information for
Returns:
Bottom border of text bounding box

Definition at line 770 of file build_vehicle_gui.cpp.

References CALLBACK_FAILED, CBID_VEHICLE_ADDITIONAL_TEXT, DrawStringMultiLine(), ErrorUnknownCallbackResult(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetGRFStringID(), GetVehicleCallback(), StartTextRefStackUsage(), and StopTextRefStackUsage().

Referenced by DrawVehiclePurchaseInfo().

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

Determines order of train engines by capacity.

Parameters:
*a first engine to compare
*b second 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 295 of file build_vehicle_gui.cpp.

References _internal_sort_order, EngineNumberSorter(), GetTotalCapacityOfArticulatedParts(), and RAILVEH_MULTIHEAD.

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

Determines order of train engines by engine / wagon.

Parameters:
*a first engine to compare
*b second 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 315 of file build_vehicle_gui.cpp.

References _internal_sort_order, EngineNumberSorter(), and RAILVEH_WAGON.


Variable Documentation

GUIEngineList::FilterFunction* const _filter_funcs[] [static]
Initial value:
 {
  &CargoFilter,
}

Definition at line 525 of file build_vehicle_gui.cpp.

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 88 of file build_vehicle_gui.cpp.

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