OpenTTD: src/vehicle_gui.cpp File Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Data Structures | Typedefs | Enumerations | Functions | Variables
vehicle_gui.cpp File Reference

The base GUI for all vehicles. More...

`#include "stdafx.h"`
`#include "debug.h"`
`#include "company_func.h"`
`#include "gui.h"`
`#include "textbuf_gui.h"`
`#include "command_func.h"`
`#include "vehicle_gui_base.h"`
`#include "viewport_func.h"`
`#include "newgrf_text.h"`
`#include "newgrf_debug.h"`
`#include "roadveh.h"`
`#include "train.h"`
`#include "aircraft.h"`
`#include "depot_map.h"`
`#include "group_gui.h"`
`#include "strings_func.h"`
`#include "vehicle_func.h"`
`#include "autoreplace_gui.h"`
`#include "string_func.h"`
`#include "widgets/dropdown_func.h"`
`#include "timetable.h"`
`#include "articulated_vehicles.h"`
`#include "spritecache.h"`
`#include "core/geometry_func.hpp"`
`#include "company_base.h"`
`#include "engine_func.h"`
`#include "station_base.h"`
`#include "tilehighlight_func.h"`
`#include "zoom_func.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | RefitOption
| Option to refit a vehicle chain. More...
struct | RefitWindow
| Refit cargo window. More...
struct | VehicleListWindow
| Window for the (old) vehicle listing. More...
struct | VehicleDetailsWindow
| Class for managing the vehicle details window. More...
struct | VehicleViewWindow
| Window manager class for viewing a vehicle. More...

## Typedefs
typedef SmallVector < RefitOption, 32 > | SubtypeList
| List of refit subtypes associated to a cargo.

## Enumerations
enum | VehicleCommandTranslation { VCT_CMD_START_STOP = 0, VCT_CMD_CLONE_VEH, VCT_CMD_TURN_AROUND }
| Command indices for the _vehicle_command_translation_table. More...

## Functions
uint | GetUnitNumberDigits (VehicleList &vehicles)
| Get the number of digits the biggest unit number of a set of vehicles has.
void | DepotSortList (VehicleList *list)
static void | DrawVehicleProfitButton (const Vehicle *v, int x, int y)
| draw the vehicle profit button in the vehicle list window.
byte | GetBestFittingSubType (Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_type)
| Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
static void | DrawVehicleRefitWindow (const SubtypeList list[NUM_CARGO], const int sel[2], uint pos, uint rows, uint delta, const Rect &r)
| Draw the list of available refit options for a consist and highlight the selected refit option (if any).
void | ShowVehicleRefitWindow (const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit)
| Show the refit window for a vehicle.
uint | ShowRefitOptionsList (int left, int right, int y, EngineID engine)
| Display list of cargo types of the engine, for the purchase information window.
StringID | GetCargoSubtypeText (const Vehicle *v)
| Get the cargo subtype text from NewGRF for the vehicle details window.
static int CDECL | VehicleNumberSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by their number.
static int CDECL | VehicleNameSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by their name.
static int CDECL | VehicleAgeSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by their age.
static int CDECL | VehicleProfitThisYearSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by this year profit.
static int CDECL | VehicleProfitLastYearSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by last year profit.
static int CDECL | VehicleCargoSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by their cargo.
static int CDECL | VehicleReliabilitySorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by their reliability.
static int CDECL | VehicleMaxSpeedSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by their max speed.
static int CDECL | VehicleModelSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by model.
static int CDECL | VehicleValueSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by their value.
static int CDECL | VehicleLengthSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by their length.
static int CDECL | VehicleTimeToLiveSorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by the time they can still live.
static int CDECL | VehicleTimetableDelaySorter (const Vehicle *const *a, const Vehicle *const *b)
| Sort vehicles by the timetable delay.
void | InitializeGUI ()
static void | ChangeVehicleWindow (WindowClass window_class, VehicleID from_index, VehicleID to_index)
| Assign a vehicle window a new vehicle.
void | ChangeVehicleViewWindow (VehicleID from_index, VehicleID to_index)
| Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.
static void | DrawSmallOrderList (const Vehicle *v, int left, int right, int y, VehicleOrderID start=0)
void | DrawVehicleImage (const Vehicle *v, int left, int right, int y, VehicleID selection, EngineImageType image_type, int skip)
| Draws an image of a vehicle chain.
uint | GetVehicleListHeight (VehicleType type, uint divisor)
| Get the height of a vehicle in the vehicle list GUIs.
static void | ShowVehicleListWindowLocal (CompanyID company, VehicleListType vlt, VehicleType vehicle_type, uint32 unique_number)
void | ShowVehicleListWindow (CompanyID company, VehicleType vehicle_type)
void | ShowVehicleListWindow (const Vehicle *v)
void | ShowVehicleListWindow (CompanyID company, VehicleType vehicle_type, StationID station)
void | ShowVehicleListWindow (CompanyID company, VehicleType vehicle_type, TileIndex depot_tile)
| assert_compile (WID_VD_DETAILS_CARGO_CARRIED==WID_VD_DETAILS_CARGO_CARRIED+TDW_TAB_CARGO)
| assert_compile (WID_VD_DETAILS_TRAIN_VEHICLES==WID_VD_DETAILS_CARGO_CARRIED+TDW_TAB_INFO)
| assert_compile (WID_VD_DETAILS_CAPACITY_OF_EACH==WID_VD_DETAILS_CARGO_CARRIED+TDW_TAB_CAPACITY)
| assert_compile (WID_VD_DETAILS_TOTAL_CARGO==WID_VD_DETAILS_CARGO_CARRIED+TDW_TAB_TOTALS)
int | GetTrainDetailsWndVScroll (VehicleID veh_id, TrainDetailsWindowTabs det_tab)
| Determines the number of lines in the train details window.
void | DrawTrainDetails (const Train *v, int left, int right, int y, int vscroll_pos, uint16 vscroll_cap, TrainDetailsWindowTabs det_tab)
| Draw the details for the given vehicle at the given position.
void | DrawRoadVehDetails (const Vehicle *v, int left, int right, int y)
| Draw the details for the given vehicle at the given position.
void | DrawShipDetails (const Vehicle *v, int left, int right, int y)
| Draw the details for the given vehicle at the given position.
void | DrawAircraftDetails (const Aircraft *v, int left, int right, int y)
| Draw the details for the given vehicle at the given position.
static void | ShowVehicleDetailsWindow (const Vehicle *v)
| Shows the vehicle details window of the given vehicle.
| assert_compile (VEH_TRAIN==0)
| assert_compile (VEH_ROAD==1)
| assert_compile (VEH_SHIP==2)
| assert_compile (VEH_AIRCRAFT==3)
void | CcStartStopVehicle (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
| This is the Callback method after the cloning attempt of a vehicle.
void | StartStopVehicle (const Vehicle *v, bool texteffect)
| Executes CMD_START_STOP_VEHICLE for given vehicle.
static bool | IsVehicleRefitable (const Vehicle *v)
| Checks whether the vehicle may be refitted at the moment.
void | ShowVehicleViewWindow (const Vehicle *v)
| Shows the vehicle view window of the given vehicle.
bool | VehicleClicked (const Vehicle *v)
| Dispatch a "vehicle selected" event if any window waits for it.
void | StopGlobalFollowVehicle (const Vehicle *v)
void | CcBuildPrimaryVehicle (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
| This is the Callback method after the construction attempt of a primary vehicle.
int | GetSingleVehicleWidth (const Vehicle *v, EngineImageType image_type)
| Get the width of a vehicle (part) in pixels.
int | GetVehicleWidth (const Vehicle *v, EngineImageType image_type)
| Get the width of a vehicle (including all parts of the consist) in pixels.
void | SetMouseCursorVehicle (const Vehicle *v, EngineImageType image_type)
| Set the mouse cursor to look like a vehicle.

## Variables
Sorting | _sorting
static GUIVehicleList::SortFunction | VehicleNumberSorter
static GUIVehicleList::SortFunction | VehicleNameSorter
static GUIVehicleList::SortFunction | VehicleAgeSorter
static GUIVehicleList::SortFunction | VehicleProfitThisYearSorter
static GUIVehicleList::SortFunction | VehicleProfitLastYearSorter
static GUIVehicleList::SortFunction | VehicleCargoSorter
static GUIVehicleList::SortFunction | VehicleReliabilitySorter
static GUIVehicleList::SortFunction | VehicleMaxSpeedSorter
static GUIVehicleList::SortFunction | VehicleModelSorter
static GUIVehicleList::SortFunction | VehicleValueSorter
static GUIVehicleList::SortFunction | VehicleLengthSorter
static GUIVehicleList::SortFunction | VehicleTimeToLiveSorter
static GUIVehicleList::SortFunction | VehicleTimetableDelaySorter
static const Vehicle * | _last_vehicle [2] = { NULL, NULL }
static const uint | MAX_REFIT_CYCLE = 256
| Maximum number of refit cycles we try, to prevent infinite loops.
static const NWidgetPart | _nested_vehicle_refit_widgets []
static WindowDesc | _vehicle_refit_desc (WDP_AUTO,"view_vehicle_refit", 240, 174, WC_VEHICLE_REFIT, WC_VEHICLE_VIEW, WDF_CONSTRUCTION, _nested_vehicle_refit_widgets, lengthof(_nested_vehicle_refit_widgets))
static const NWidgetPart | _nested_vehicle_list []
static WindowDesc | _vehicle_list_other_desc (WDP_AUTO,"list_vehicles", 260, 246, WC_INVALID, WC_NONE, 0, _nested_vehicle_list, lengthof(_nested_vehicle_list))
static WindowDesc | _vehicle_list_train_desc (WDP_AUTO,"list_vehicles_train", 325, 246, WC_TRAINS_LIST, WC_NONE, 0, _nested_vehicle_list, lengthof(_nested_vehicle_list))
static const NWidgetPart | _nested_nontrain_vehicle_details_widgets []
| Vehicle details widgets (other than train).
static const NWidgetPart | _nested_train_vehicle_details_widgets []
| Train details widgets.
static StringID | _service_interval_dropdown []
static WindowDesc | _train_vehicle_details_desc (WDP_AUTO,"view_vehicle_details_train", 405, 178, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, _nested_train_vehicle_details_widgets, lengthof(_nested_train_vehicle_details_widgets))
| Vehicle details window descriptor.
static WindowDesc | _nontrain_vehicle_details_desc (WDP_AUTO,"view_vehicle_details", 405, 113, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, _nested_nontrain_vehicle_details_widgets, lengthof(_nested_nontrain_vehicle_details_widgets))
| Vehicle details window descriptor for other vehicles than a train.
static const NWidgetPart | _nested_vehicle_view_widgets []
| Vehicle view widgets.
static WindowDesc | _vehicle_view_desc (WDP_AUTO,"view_vehicle", 250, 116, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, lengthof(_nested_vehicle_view_widgets))
| Vehicle view window descriptor for all vehicles but trains.
static WindowDesc | _train_view_desc (WDP_AUTO,"view_vehicle_train", 250, 134, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, lengthof(_nested_vehicle_view_widgets))
| Vehicle view window descriptor for trains.
static const ZoomLevel | _vehicle_view_zoom_levels []
| Zoom levels for vehicle views indexed by vehicle type.
static const int | VV_INITIAL_VIEWPORT_WIDTH = 226
static const int | VV_INITIAL_VIEWPORT_HEIGHT = 84
static const int | VV_INITIAL_VIEWPORT_HEIGHT_TRAIN = 102
static const uint32 | _vehicle_command_translation_table [][4]
| Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type.

## Detailed Description

The base GUI for all vehicles.

Definition in file vehicle_gui.cpp.

## Enumeration Type Documentation

enum VehicleCommandTranslation

Command indices for the _vehicle_command_translation_table.

Definition at line 2344 of file vehicle_gui.cpp.

## Function Documentation

void CcBuildPrimaryVehicle | ( | const CommandCost & | result,
|  | TileIndex | tile,
|  | uint32 | p1,
|  | uint32 | p2
| ) |  |

This is the Callback method after the construction attempt of a primary vehicle.

Parameters

  result | indicates completion (or not) of the operation
  tile | unused
  p1 | unused
  p2 | unused

Definition at line 2821 of file vehicle_gui.cpp.

References CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), and ShowVehicleViewWindow().

Referenced by BuildVehicleWindow::OnClick().

void CcStartStopVehicle | ( | const CommandCost & | result,
|  | TileIndex | tile,
|  | uint32 | p1,
|  | uint32 | p2
| ) |  |

This is the Callback method after the cloning attempt of a vehicle.

Parameters

  result | the result of the cloning command
  tile | unused
  p1 | vehicle ID
  p2 | unused

Definition at line 2379 of file vehicle_gui.cpp.

References _local_company, DAY_TICKS, CommandCost::Failed(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), Vehicle::IsPrimaryVehicle(), Vehicle::owner, RemapCoords(), TE_RISING, Vehicle::vehstatus, VS_STOPPED, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.

Referenced by StartStopVehicle().

void ChangeVehicleViewWindow | ( | VehicleID | from_index,
|  | VehicleID | to_index
| ) |  |

Report a change in vehicle IDs (due to autoreplace) to affected vehicle windows.

Parameters

  from_index | the old vehicle ID
  to_index | the new vehicle ID

Definition at line 1243 of file vehicle_gui.cpp.

References ChangeVehicleWindow(), WC_VEHICLE_DETAILS, WC_VEHICLE_ORDERS, WC_VEHICLE_REFIT, WC_VEHICLE_TIMETABLE, and WC_VEHICLE_VIEW.

Referenced by CopyHeadSpecificThings().

static void ChangeVehicleWindow | ( | WindowClass | window_class,
|  | VehicleID | from_index,
|  | VehicleID | to_index
| ) |  |
| inlinestatic

Assign a vehicle window a new vehicle.

Parameters

  window_class | WindowClass to search for
  from_index | the old vehicle ID
  to_index | the new vehicle ID

Definition at line 1220 of file vehicle_gui.cpp.

References FindWindowById(), ViewportData::follow_vehicle, Window::InvalidateData(), Window::viewport, VIWD_AUTOREPLACE, TileHighlightData::window_class, TileHighlightData::window_number, and Window::window_number.

Referenced by ChangeVehicleViewWindow().

void DrawAircraftDetails | ( | const Aircraft * | v,
|  | int | left,
|  | int | right,
|  | int | y
| ) |  |

Draw the details for the given vehicle at the given position.

Parameters

  v | current vehicle
  left | The left most coordinate to draw
  right | The right most coordinate to draw
  y | The y coordinate

Definition at line 34 of file aircraft_gui.cpp.

References Vehicle::cargo_cap, DrawString(), FONT_HEIGHT_NORMAL, GetCargoSubtypeText(), SpecializedVehicle< T, Type >::Next(), and SetDParam().

Referenced by VehicleDetailsWindow::DrawVehicleDetails().

void DrawRoadVehDetails | ( | const Vehicle * | v,
|  | int | left,
|  | int | right,
|  | int | y
| ) |  |

Draw the details for the given vehicle at the given position.

Parameters

  v | current vehicle
  left | The left most coordinate to draw
  right | The right most coordinate to draw
  y | The y coordinate

Definition at line 32 of file roadveh_gui.cpp.

References Vehicle::build_year, Vehicle::cargo, Vehicle::cargo_cap, Vehicle::cargo_type, DrawString(), Vehicle::engine_type, VehicleCargoList::FeederShare(), FONT_HEIGHT_NORMAL, GetCargoSubtypeText(), Vehicle::HasArticulatedPart(), lastof, Vehicle::Next(), NUM_CARGO, ScaleGUITrad(), SetDParam(), VehicleCargoList::Source(), VehicleCargoList::StoredCount(), strecat(), and Vehicle::value.

Referenced by VehicleDetailsWindow::DrawVehicleDetails().

void DrawShipDetails | ( | const Vehicle * | v,
|  | int | left,
|  | int | right,
|  | int | y
| ) |  |

Draw the details for the given vehicle at the given position.

Parameters

  v | current vehicle
  left | The left most coordinate to draw
  right | The right most coordinate to draw
  y | The y coordinate

Definition at line 66 of file ship_gui.cpp.

References Vehicle::build_year, Vehicle::cargo, Vehicle::cargo_cap, Vehicle::cargo_type, DrawString(), Vehicle::engine_type, VehicleCargoList::FeederShare(), FONT_HEIGHT_NORMAL, GetCargoSubtypeText(), SetDParam(), VehicleCargoList::Source(), VehicleCargoList::StoredCount(), and Vehicle::value.

Referenced by VehicleDetailsWindow::DrawVehicleDetails().

void DrawTrainDetails | ( | const Train * | v,
|  | int | left,
|  | int | right,
|  | int | y,
|  | int | vscroll_pos,
|  | uint16 | vscroll_cap,
|  | TrainDetailsWindowTabs | det_tab
| ) |  |

Draw the details for the given vehicle at the given position.

Parameters

  v | current vehicle
  left | The left most coordinate to draw
  right | The right most coordinate to draw
  y | The y coordinate
  vscroll_pos | Position of scrollbar
  vscroll_cap | Number of lines currently displayed
  det_tab | Selected details tab

Definition at line 356 of file train_gui.cpp.

References _colour_gradient, _current_text_dir, _settings_game, DIR_E, DIR_W, VehicleSpriteSeq::Draw(), DrawString(), EIT_IN_DETAILS, Vehicle::engine_type, FONT_HEIGHT_NORMAL, VehicleSettings::freight_trains, FreightWagonMult(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetCargoSummaryOfArticulatedVehicle(), Train::GetDisplayImageWidth(), Engine::GetGRF(), Train::GetImage(), SpecializedVehicle< T, Type >::GetNextVehicle(), GetVehicleHeight(), GetVehiclePalette(), GfxFillRect(), Vehicle::IsArticulatedPart(), SmallVector< T, S >::Length(), max(), SpecializedVehicle< T, Type >::Next(), NUM_CARGO, PALETTE_CRASH, ScaleGUITrad(), SetDParam(), TD_RTL, TDW_TAB_CAPACITY, TDW_TAB_CARGO, TDW_TAB_INFO, TDW_TAB_TOTALS, TRAIN_DETAILS_MAX_INDENT, TRAIN_DETAILS_MIN_INDENT, TrainDetailsCapacityTab(), TrainDetailsCargoTab(), TrainDetailsInfoTab(), GRFFile::traininfo_vehicle_pitch, VEH_TRAIN, GameSettings::vehicle, Vehicle::vehstatus, VS_CRASHED, WD_MATRIX_BOTTOM, and WD_MATRIX_TOP.

Referenced by VehicleDetailsWindow::DrawVehicleDetails().

void DrawVehicleImage | ( | const Vehicle * | v,
|  | int | left,
|  | int | right,
|  | int | y,
|  | VehicleID | selection,
|  | EngineImageType | image_type,
|  | int | skip
| ) |  |

Draws an image of a vehicle chain.

Parameters

  v | Front vehicle
  left | The minimum horizontal position
  right | The maximum horizontal position
  y | Vertical position to draw at
  selection | Selected vehicle to draw a frame around
  skip | Number of pixels to skip at the front (for scrolling)

Definition at line 1333 of file vehicle_gui.cpp.

References DrawAircraftImage(), DrawRoadVehImage(), DrawShipImage(), DrawTrainImage(), SpecializedVehicle< Train, Type >::From(), BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by BaseVehicleListWindow::DrawVehicleListItems(), RefitWindow::DrawWidget(), and VehicleDetailsWindow::DrawWidget().

static void DrawVehicleProfitButton | ( | const Vehicle * | v,
|  | int | x,
|  | int | y
| ) |  |
| static

draw the vehicle profit button in the vehicle list window.

Definition at line 201 of file vehicle_gui.cpp.

References Vehicle::age, DrawSprite(), Vehicle::GetDisplayProfitLastYear(), VEHICLE_PROFIT_MIN_AGE, and VEHICLE_PROFIT_THRESHOLD.

Referenced by BaseVehicleListWindow::DrawVehicleListItems().

static void DrawVehicleRefitWindow | ( | const SubtypeList | list[NUM_CARGO],
|  | const int | sel[2],
|  | uint | pos,
|  | uint | rows,
|  | uint | delta,
|  | const Rect & | r
| ) |  |
| static

Draw the list of available refit options for a consist and highlight the selected refit option (if any).

Parameters

  list | List of subtype options for each (sorted) cargo.
  sel | Selected refit cargo-type in the window
  pos | Position of the selected item in caller widow
  rows | Number of rows(capacity) in caller window
  delta | Step height in caller window
  r | Rectangle of the matrix widget.

Definition at line 331 of file vehicle_gui.cpp.

References _colour_gradient, _current_text_dir, RefitOption::cargo, DrawSprite(), DrawString(), FONT_HEIGHT_NORMAL, CargoSpec::Get(), GetSpriteSize(), SmallVector< T, S >::Length(), max(), CargoSpec::name, NUM_CARGO, SetDParam(), RefitOption::string, RefitOption::subtype, TD_RTL, WD_MATRIX_LEFT, WD_MATRIX_RIGHT, and WD_MATRIX_TOP.

Referenced by RefitWindow::DrawWidget().

byte GetBestFittingSubType | ( | Vehicle * | v_from,
|  | Vehicle * | v_for,
|  | CargoID | dest_cargo_type
| ) |  |

Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.

All articulated parts of both vehicles are tested to find a possibly shared subtype. For v_for only vehicle refittable to dest_cargo_type are considered.

Parameters

  v_from | the vehicle to match the subtype from
  v_for | the vehicle to get the subtype for
  dest_cargo_type | Destination cargo type.

Returns
  the best sub type

Definition at line 230 of file vehicle_gui.cpp.

References EngineInfo::callback_mask, Engine::CanCarryCargo(), CBM_VEHICLE_CARGO_SUFFIX, SmallVector< T, S >::Clear(), SmallVector< T, S >::Contains(), GetCargoSubtypeText(), Vehicle::GetEngine(), Vehicle::GetFirstEnginePart(), Vehicle::GetNextArticulatedPart(), Vehicle::HasArticulatedPart(), HasBit(), SmallVector< T, S >::Include(), SmallVector< T, S >::Length(), and MAX_REFIT_CYCLE.

Referenced by BuildReplacementVehicle(), CmdCloneVehicle(), LinkRefresher::HandleRefit(), and RefitVehicle().

StringID GetCargoSubtypeText | ( | const Vehicle * | v | ) |

Get the cargo subtype text from NewGRF for the vehicle details window.

Definition at line 1072 of file vehicle_gui.cpp.

References CALLBACK_FAILED, CBID_VEHICLE_CARGO_SUFFIX, CBM_VEHICLE_CARGO_SUFFIX, Vehicle::engine_type, ErrorUnknownCallbackResult(), Vehicle::GetGRF(), Vehicle::GetGRFID(), GetGRFStringID(), GetVehicleCallback(), and HasBit().

Referenced by RefitWindow::BuildRefitList(), DrawAircraftDetails(), DrawRoadVehDetails(), DrawShipDetails(), GetBestFittingSubType(), and GetCargoSummaryOfArticulatedVehicle().

int GetSingleVehicleWidth | ( | const Vehicle * | v,
|  | EngineImageType | image_type
| ) |  |

Get the width of a vehicle (part) in pixels.

Parameters

  v | Vehicle to get the width for.

Returns
  Width of the vehicle.

Definition at line 2834 of file vehicle_gui.cpp.

References _current_text_dir, DIR_E, DIR_W, SpecializedVehicle< Train, Type >::From(), SpecializedVehicle< RoadVehicle, Type >::From(), VehicleSpriteSeq::GetBounds(), RoadVehicle::GetDisplayImageWidth(), Train::GetDisplayImageWidth(), Vehicle::GetImage(), TD_RTL, BaseVehicle::type, UnScaleGUI(), VEH_ROAD, and VEH_TRAIN.

Referenced by VehicleDetailsWindow::DrawWidget(), GetVehicleWidth(), and SetMouseCursorVehicle().

int GetTrainDetailsWndVScroll | ( | VehicleID | veh_id,
|  | TrainDetailsWindowTabs | det_tab
| ) |  |

Determines the number of lines in the train details window.

Parameters

  veh_id | Train
  det_tab | Selected details tab

Returns
  Number of line

Definition at line 313 of file train_gui.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), SpecializedVehicle< Train, Type >::Get(), GetCargoSummaryOfArticulatedVehicle(), GetLengthOfArticulatedVehicle(), SpecializedVehicle< T, Type >::GetNextVehicle(), SmallVector< T, S >::Length(), max(), NUM_CARGO, TDW_TAB_TOTALS, and TRAIN_DETAILS_MAX_INDENT.

Referenced by VehicleDetailsWindow::OnPaint().

uint GetUnitNumberDigits | ( | VehicleList & | vehicles | ) |

Get the number of digits the biggest unit number of a set of vehicles has.

Parameters

  vehicles | The list of vehicles.

Returns
  The number of digits to allocate space for.

Definition at line 106 of file vehicle_gui.cpp.

References SmallVector< T, S >::Begin(), and SmallVector< T, S >::End().

Referenced by DepotWindow::OnPaint().

uint GetVehicleListHeight | ( | VehicleType | type,
|  | uint | divisor
| ) |  |

Get the height of a vehicle in the vehicle list GUIs.

Parameters

  type | the vehicle type to look at
  divisor | the resulting height must be dividable by this

Returns
  the height

Definition at line 1350 of file vehicle_gui.cpp.

References FONT_HEIGHT_SMALL, GetVehicleHeight(), max(), ScaleGUITrad(), and VEH_SHIP.

Referenced by VehicleGroupWindow::UpdateWidgetSize(), and VehicleListWindow::UpdateWidgetSize().

int GetVehicleWidth | ( | const Vehicle * | v,
|  | EngineImageType | image_type
| ) |  |

Get the width of a vehicle (including all parts of the consist) in pixels.

Parameters

  v | Vehicle to get the width for.

Returns
  Width of the vehicle.

Definition at line 2858 of file vehicle_gui.cpp.

References GetSingleVehicleWidth(), SpecializedVehicle< T, Type >::Next(), BaseVehicle::type, VEH_ROAD, and VEH_TRAIN.

Referenced by RefitWindow::OnInvalidateData(), and RefitWindow::OnResize().

static bool IsVehicleRefitable | ( | const Vehicle * | v | ) |
| static

Checks whether the vehicle may be refitted at the moment.

Definition at line 2403 of file vehicle_gui.cpp.

References Vehicle::engine_type, IsEngineRefittable(), Vehicle::IsGroundVehicle(), Vehicle::IsStoppedInDepot(), and Vehicle::Next().

Referenced by VehicleViewWindow::OnPaint().

void SetMouseCursorVehicle | ( | const Vehicle * | v,
|  | EngineImageType | image_type
| ) |  |

Set the mouse cursor to look like a vehicle.

Parameters

  v | Vehicle
  image_type | Type of vehicle image to use.

Definition at line 2876 of file vehicle_gui.cpp.

References _current_text_dir, DIR_E, DIR_W, Vehicle::GetImage(), Vehicle::GetNextArticulatedPart(), GetSingleVehicleWidth(), GetVehiclePalette(), Vehicle::HasArticulatedPart(), lengthof, PalSpriteID::pal, PALETTE_CRASH, PalSpriteID::sprite, CursorVars::sprite_count, CursorVars::sprite_pos, CursorVars::sprite_seq, TD_RTL, UpdateCursorSize(), Vehicle::vehstatus, and VS_CRASHED.

Referenced by DepotWindow::DepotClick(), and VehicleGroupWindow::OnClick().

static void ShowVehicleDetailsWindow | ( | const Vehicle * | v | ) |
| static

Shows the vehicle details window of the given vehicle.

Definition at line 2252 of file vehicle_gui.cpp.

References _nontrain_vehicle_details_desc, _train_vehicle_details_desc, DeleteWindowById(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, BaseVehicle::type, VEH_TRAIN, WC_VEHICLE_ORDERS, and WC_VEHICLE_TIMETABLE.

Referenced by VehicleViewWindow::OnClick().

void ShowVehicleRefitWindow | ( | const Vehicle * | v,
|  | VehicleOrderID | order,
|  | Window * | parent,
|  | bool | auto_refit
| ) |  |

Show the refit window for a vehicle.

Parameters

  *v | The vehicle to show the refit window for
  order | of the vehicle to assign refit to, or INVALID_VEH_ORDER_ID to refit the vehicle now
  parent | the parent window of the refit window
  auto_refit | Choose cargo for auto-refitting

Definition at line 1035 of file vehicle_gui.cpp.

References DeleteWindowById(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Window::parent, and WC_VEHICLE_REFIT.

Referenced by VehicleViewWindow::OnClick(), and OrdersWindow::OrderClick_Refit().

void ShowVehicleViewWindow | ( | const Vehicle * | v | ) |

Shows the vehicle view window of the given vehicle.

Definition at line 2783 of file vehicle_gui.cpp.

References _train_view_desc, _vehicle_view_desc, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, BaseVehicle::type, and VEH_TRAIN.

Referenced by CcBuildPrimaryVehicle(), CcCloneVehicle(), DepotWindow::DepotClick(), NewsWindow::OnClick(), VehicleListWindow::OnClick(), and DepotWindow::OnDragDrop().

void StartStopVehicle | ( | const Vehicle * | v,
|  | bool | texteffect
| ) |  |

Executes CMD_START_STOP_VEHICLE for given vehicle.

Parameters

  v | Vehicle to start/stop
  texteffect | Should a texteffect be shown?

Definition at line 2396 of file vehicle_gui.cpp.

References CcStartStopVehicle(), DoCommandP(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsPrimaryVehicle(), Vehicle::tile, and BaseVehicle::type.

Referenced by DepotWindow::DepotClick(), and VehicleViewWindow::OnClick().

bool VehicleClicked | ( | const Vehicle * | v | ) |

Dispatch a "vehicle selected" event if any window waits for it.

Parameters

  v | selected vehicle;

Returns
  did any window accept vehicle selection?

Definition at line 2793 of file vehicle_gui.cpp.

References Vehicle::First(), TileHighlightData::GetCallbackWnd(), HT_VEHICLE, Vehicle::IsPrimaryVehicle(), Window::OnVehicleSelect(), and TileHighlightData::place_mode.

Referenced by DepotWindow::DepotClick(), VehicleGroupWindow::OnClick(), and VehicleListWindow::OnClick().

## Variable Documentation

const NWidgetPart _nested_nontrain_vehicle_details_widgets[]
| static

Initial value:
{
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY, WID_VD_CAPTION), SetDataTip(STR_VEHICLE_DETAILS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VD_RENAME_VEHICLE), SetMinimalSize(40, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_VEHICLE_NAME_BUTTON, STR_NULL ),
NWidget(WWT_SHADEBOX, COLOUR_GREY),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
NWidget(WWT_STICKYBOX, COLOUR_GREY),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_TOP_DETAILS), SetMinimalSize(405, 42), SetResize(1, 0), EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_MIDDLE_DETAILS), SetMinimalSize(405, 45), SetResize(1, 0), EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_VD_DECREASE_SERVICING_INTERVAL), SetFill(0, 1),
SetDataTip(AWV_DECREASE, STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_VD_INCREASE_SERVICING_INTERVAL), SetFill(0, 1),
SetDataTip(AWV_INCREASE, STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_VD_SERVICE_INTERVAL_DROPDOWN), SetFill(0, 1),
SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_SERVICING_INTERVAL), SetFill(1, 1), SetResize(1, 0), EndContainer(),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
EndContainer(),
}

Vehicle details widgets (other than train).

Definition at line 1791 of file vehicle_gui.cpp.

const NWidgetPart _nested_train_vehicle_details_widgets[]
| static

Train details widgets.

Definition at line 1815 of file vehicle_gui.cpp.

const NWidgetPart _nested_vehicle_refit_widgets[]
| static

Initial value:
{
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY, WID_VR_CAPTION), SetDataTip(STR_REFIT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
EndContainer(),
NWidget(NWID_VERTICAL),
NWidget(WWT_PANEL, COLOUR_GREY, WID_VR_VEHICLE_PANEL_DISPLAY), SetMinimalSize(228, 14), SetResize(1, 0), SetScrollbar(WID_VR_HSCROLLBAR), EndContainer(),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_VR_SHOW_HSCROLLBAR),
NWidget(NWID_HSCROLLBAR, COLOUR_GREY, WID_VR_HSCROLLBAR),
EndContainer(),
EndContainer(),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_VR_SELECT_HEADER), SetDataTip(STR_REFIT_TITLE, STR_NULL), SetResize(1, 0),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_MATRIX, COLOUR_GREY, WID_VR_MATRIX), SetMinimalSize(228, 112), SetResize(1, 14), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_VR_SCROLLBAR),
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_VR_SCROLLBAR),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_GREY, WID_VR_INFO), SetMinimalTextLines(2, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM), SetResize(1, 0), EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_VR_REFIT), SetFill(1, 0), SetResize(1, 0),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
EndContainer(),
}

Definition at line 995 of file vehicle_gui.cpp.

const NWidgetPart _nested_vehicle_view_widgets[]
| static

Vehicle view widgets.

Definition at line 2263 of file vehicle_gui.cpp.

WindowDesc _nontrain_vehicle_details_desc(WDP_AUTO,"view_vehicle_details", 405, 113, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, _nested_nontrain_vehicle_details_widgets, lengthof(_nested_nontrain_vehicle_details_widgets))
| static

Vehicle details window descriptor for other vehicles than a train.

Referenced by ShowVehicleDetailsWindow().

StringID _service_interval_dropdown[]
| static

Initial value:
{
STR_VEHICLE_DETAILS_DEFAULT,
STR_VEHICLE_DETAILS_DAYS,
STR_VEHICLE_DETAILS_PERCENT,
INVALID_STRING_ID,
}

Definition at line 1858 of file vehicle_gui.cpp.

WindowDesc _train_vehicle_details_desc(WDP_AUTO,"view_vehicle_details_train", 405, 178, WC_VEHICLE_DETAILS, WC_VEHICLE_VIEW, 0, _nested_train_vehicle_details_widgets, lengthof(_nested_train_vehicle_details_widgets))
| static

Vehicle details window descriptor.

Referenced by ShowVehicleDetailsWindow().

WindowDesc _train_view_desc(WDP_AUTO,"view_vehicle_train", 250, 134, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, lengthof(_nested_vehicle_view_widgets))
| static

Vehicle view window descriptor for trains.

Only minimum_height and default_height are different for train view.

Referenced by ShowVehicleViewWindow().

const uint32 _vehicle_command_translation_table[][4]
| static

Initial value:
{
{
CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_TRAIN),
CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE),
CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_SHIP),
CMD_START_STOP_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_STOP_START_AIRCRAFT)
},
{
CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN),
CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_ROAD_VEHICLE),
CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_SHIP),
CMD_CLONE_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_AIRCRAFT)
},
{
CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_ERROR_CAN_T_REVERSE_DIRECTION_TRAIN),
CMD_TURN_ROADVEH | CMD_MSG(STR_ERROR_CAN_T_MAKE_ROAD_VEHICLE_TURN),
0xffffffff,
0xffffffff
},
}

Command codes for the shared buttons indexed by VehicleCommandTranslation and vehicle type.

Definition at line 2351 of file vehicle_gui.cpp.

WindowDesc _vehicle_view_desc(WDP_AUTO,"view_vehicle", 250, 116, WC_VEHICLE_VIEW, WC_NONE, 0, _nested_vehicle_view_widgets, lengthof(_nested_vehicle_view_widgets))
| static

Vehicle view window descriptor for all vehicles but trains.

Referenced by ShowVehicleViewWindow().

const ZoomLevel _vehicle_view_zoom_levels[]
| static

Initial value:
{
ZOOM_LVL_TRAIN,
ZOOM_LVL_ROADVEH,
ZOOM_LVL_SHIP,
ZOOM_LVL_AIRCRAFT,
}

Zoom levels for vehicle views indexed by vehicle type.

Definition at line 2331 of file vehicle_gui.cpp.

const uint MAX_REFIT_CYCLE = 256
| static

Maximum number of refit cycles we try, to prevent infinite loops.

And we store only a byte anyway

Definition at line 219 of file vehicle_gui.cpp.

Referenced by RefitWindow::BuildRefitList(), and GetBestFittingSubType().