Functions related to vehicles. More...
#include "gfx_type.h"
#include "direction_type.h"
#include "command_type.h"
#include "vehicle_type.h"
#include "engine_type.h"
#include "transport_type.h"
#include "newgrf_config.h"
#include "company_type.h"
Go to the source code of this file.
Data Structures | |
struct | GetNewVehiclePosResult |
Position information of a vehicle after it moved. More... | |
Defines | |
#define | is_custom_sprite(x) (x >= 0xFD) |
#define | IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD) |
#define | IS_CUSTOM_SECONDHEAD_SPRITE(x) (x == 0xFE) |
Typedefs | |
typedef Vehicle * | VehicleFromPosProc (Vehicle *v, void *data) |
Functions | |
void | VehicleServiceInDepot (Vehicle *v) |
uint | CountVehiclesInChain (const Vehicle *v) |
void | FindVehicleOnPos (TileIndex tile, void *data, VehicleFromPosProc *proc) |
Find a vehicle from a specific location. | |
void | FindVehicleOnPosXY (int x, int y, void *data, VehicleFromPosProc *proc) |
Find a vehicle from a specific location. | |
bool | HasVehicleOnPos (TileIndex tile, void *data, VehicleFromPosProc *proc) |
Checks whether a vehicle in on a specific location. | |
bool | HasVehicleOnPosXY (int x, int y, void *data, VehicleFromPosProc *proc) |
Checks whether a vehicle in on a specific location. | |
void | CallVehicleTicks () |
uint8 | CalcPercentVehicleFilled (const Vehicle *v, StringID *colour) |
Calculates how full a vehicle is. | |
byte | VehicleRandomBits () |
Get a value for a vehicle's random_bits. | |
void | ResetVehiclePosHash () |
void | ResetVehicleColourMap () |
byte | GetBestFittingSubType (Vehicle *v_from, Vehicle *v_for) |
Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for. | |
CommandCost | RefitVehicle (Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags) |
Refits a vehicle (chain). | |
void | ViewportAddVehicles (DrawPixelInfo *dpi) |
void | ShowNewGrfVehicleError (EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical) |
Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking. | |
bool | HasVehicleOnTunnelBridge (TileIndex tile, TileIndex endtile, const Vehicle *ignore=NULL) |
Finds vehicle in tunnel / bridge. | |
void | DecreaseVehicleValue (Vehicle *v) |
void | CheckVehicleBreakdown (Vehicle *v) |
void | AgeVehicle (Vehicle *v) |
void | VehicleEnteredDepotThisTick (Vehicle *v) |
Adds a vehicle to the list of vehicles, that visited a depot this tick. | |
void | VehicleMove (Vehicle *v, bool update_viewport) |
Move a vehicle in the game state; that is moving it's position in the position hashes and marking it's location in the viewport dirty if requested. | |
void | MarkSingleVehicleDirty (const Vehicle *v) |
Marks viewports dirty where the vehicle's image is In fact, it equals BeginVehicleMove(v); EndVehicleMove(v);. | |
UnitID | GetFreeUnitNumber (VehicleType type) |
CommandCost | SendAllVehiclesToDepot (VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id) |
Send all vehicles of type to depots. | |
void | VehicleEnterDepot (Vehicle *v) |
bool | CanBuildVehicleInfrastructure (VehicleType type) |
Check whether we can build infrastructure for the given vehicle type. | |
GetNewVehiclePosResult | GetNewVehiclePos (const Vehicle *v) |
Get position information of a vehicle when moving one pixel in the direction it is facing. | |
Direction | GetDirectionTowards (const Vehicle *v, int x, int y) |
static bool | IsCompanyBuildableVehicleType (VehicleType type) |
static bool | IsCompanyBuildableVehicleType (const BaseVehicle *v) |
struct Livery * | GetEngineLivery (EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v) |
Determines the livery for a vehicle. | |
SpriteID | GetEnginePalette (EngineID engine_type, CompanyID company) |
Get the colour map for an engine. | |
SpriteID | GetVehiclePalette (const Vehicle *v) |
Get the colour map for a vehicle. | |
uint | GetVehicleCapacity (const Vehicle *v, uint16 *mail_capacity=NULL) |
Determines capacity of a given vehicle from scratch. | |
static uint32 | GetCmdBuildVeh (VehicleType type) |
static uint32 | GetCmdBuildVeh (const BaseVehicle *v) |
static uint32 | GetCmdSellVeh (VehicleType type) |
static uint32 | GetCmdSellVeh (const BaseVehicle *v) |
static uint32 | GetCmdRefitVeh (VehicleType type) |
static uint32 | GetCmdRefitVeh (const BaseVehicle *v) |
static uint32 | GetCmdSendToDepot (VehicleType type) |
static uint32 | GetCmdSendToDepot (const BaseVehicle *v) |
bool | EnsureNoVehicleOnGround (TileIndex tile) |
void | StopAllVehicles () |
bool | CanVehicleUseStation (EngineID engine_type, const struct Station *st) |
bool | CanVehicleUseStation (const Vehicle *v, const struct Station *st) |
void | ReleaseDisastersTargetingVehicle (VehicleID vehicle) |
Notify disasters that we are about to delete a vehicle. | |
Variables | |
const uint32 | _veh_build_proc_table [] |
const uint32 | _veh_sell_proc_table [] |
const uint32 | _veh_refit_proc_table [] |
const uint32 | _send_to_depot_proc_table [] |
VehicleID | _vehicle_id_ctr_day |
const Vehicle * | _place_clicked_vehicle |
VehicleID | _new_vehicle_id |
uint16 | _returned_refit_capacity |
byte | _age_cargo_skip_counter |
Skip aging of cargo? |
Functions related to vehicles.
Definition in file vehicle_func.h.
Calculates how full a vehicle is.
v | The Vehicle to check. For trains, use the first engine. | |
colour | The string to show depending on if we are unloading or loading |
Definition at line 950 of file vehicle.cpp.
References Vehicle::cargo, Vehicle::cargo_cap, Vehicle::cargo_type, CargoList< Tinst >::Count(), Vehicle::current_order, SpecializedStation< Station, false >::Get(), Order::GetLoadType(), Station::goods, HasBit(), max(), Vehicle::Next(), OLFB_NO_LOAD, and Vehicle::vehicle_flags.
Referenced by LoadUnloadVehicle(), and ProcessConditionalOrder().
bool CanBuildVehicleInfrastructure | ( | VehicleType | type | ) |
Check whether we can build infrastructure for the given vehicle type.
This to disable building stations etc. when you are not allowed/able to have the vehicle type yet.
type | the vehicle type to check this for |
Definition at line 1250 of file vehicle.cpp.
References _settings_client, _settings_game, GUISettings::always_build_infrastructure, ClientSettings::gui, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), max(), VehicleSettings::max_aircraft, VehicleSettings::max_roadveh, VehicleSettings::max_ships, VehicleSettings::max_trains, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and GameSettings::vehicle.
Referenced by MainToolbarWindow::OnKeyPress(), MainToolbarWindow::OnPaint(), and BuildDocksToolbarWindow::OnPaint().
void FindVehicleOnPos | ( | TileIndex | tile, | |
void * | data, | |||
VehicleFromPosProc * | proc | |||
) |
Find a vehicle from a specific location.
It will call proc for ALL vehicles on the tile and YOU must make SURE that the "best one" is stored in the data value and is ALWAYS the same regardless of the order of the vehicles where proc was called on! When you fail to do this properly you create an almost untraceable DESYNC!
tile | The location on the map | |
data | Arbitrary data passed to proc | |
proc | The proc that determines whether a vehicle will be "found". |
Definition at line 411 of file vehicle.cpp.
References VehicleFromPos().
Referenced by CheckTrainCollision(), CmdConvertRail(), DeleteLastWagon(), FloodVehicles(), FollowTrainReservation(), GetTrainForReservation(), RoadStop::Entry::Rebuild(), and RemoveRoadStop().
void FindVehicleOnPosXY | ( | int | x, | |
int | y, | |||
void * | data, | |||
VehicleFromPosProc * | proc | |||
) |
Find a vehicle from a specific location.
It will call proc for ALL vehicles on the tile and YOU must make SURE that the "best one" is stored in the data value and is ALWAYS the same regardless of the order of the vehicles where proc was called on! When you fail to do this properly you create an almost untraceable DESYNC!
x | The X location on the map | |
y | The Y location on the map | |
data | Arbitrary data passed to proc | |
proc | The proc that determines whether a vehicle will be "found". |
Definition at line 351 of file vehicle.cpp.
References VehicleFromPosXY().
Referenced by CheckTrainCollision().
Get the best fitting subtype when 'cloning'/'replacing' v_from with v_for.
Assuming they are going to carry the same cargo ofcourse!
v_from | the vehicle to match the subtype from | |
v_for | the vehicle to get the subtype for |
Definition at line 170 of file vehicle_gui.cpp.
References CALLBACK_FAILED, EngineInfo::callback_mask, Engine::CanCarryCargo(), Vehicle::cargo_subtype, Vehicle::cargo_type, CBID_VEHICLE_CARGO_SUFFIX, CBM_VEHICLE_CARGO_SUFFIX, Vehicle::First(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetCargoSubtypeText(), GetVehicleCallback(), HasBit(), and Vehicle::InvalidateNewGRFCache().
Referenced by BuildReplacementVehicle(), and CmdCloneVehicle().
struct Livery* GetEngineLivery | ( | EngineID | engine_type, | |
CompanyID | company, | |||
EngineID | parent_engine_type, | |||
const Vehicle * | v | |||
) | [read] |
Determines the livery for a vehicle.
engine_type | EngineID of the vehicle | |
company | Owner of the vehicle | |
parent_engine_type | EngineID of the front vehicle. INVALID_VEHICLE if vehicle is at front itself. | |
v | the vehicle. NULL if in purchase list etc. |
Definition at line 1294 of file vehicle.cpp.
References _settings_client, AIR_CTOL, Vehicle::cargo_type, CC_PASSENGERS, CT_INVALID, EF_RAIL_IS_MU, EF_ROAD_TRAM, RailVehicleInfo::engclass, Vehicle::First(), SpecializedVehicle< Train, VEH_TRAIN >::From(), CargoSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Engine::GetDefaultCargoType(), ClientSettings::gui, HasBit(), Livery::in_use, IsCargoInClass(), GUISettings::liveries, RAILVEH_WAGON, Engine::type, UsesWagonOverride(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Get the colour map for an engine.
This used for unbuilt engines in the user interface.
engine_type | ID of engine | |
company | ID of company |
Definition at line 1439 of file vehicle.cpp.
Referenced by DrawEngineList(), NewsWindow::DrawWidget(), and EnginePreviewWindow::DrawWidget().
GetNewVehiclePosResult GetNewVehiclePos | ( | const Vehicle * | v | ) |
Get position information of a vehicle when moving one pixel in the direction it is facing.
v | Vehicle to move |
Definition at line 1141 of file vehicle.cpp.
References GetNewVehiclePosResult::new_tile, GetNewVehiclePosResult::old_tile, Vehicle::tile, and GetNewVehiclePosResult::y.
Referenced by AircraftController(), DisasterTick_Aircraft(), DisasterTick_Big_Ufo(), DisasterTick_Big_Ufo_Destroyer(), DisasterTick_Submarine(), DisasterTick_Ufo(), DisasterTick_Zeppeliner(), UpdateAirplanesOnNewStation(), and UpdateOldAircraft().
uint GetVehicleCapacity | ( | const Vehicle * | v, | |
uint16 * | mail_capacity | |||
) |
Determines capacity of a given vehicle from scratch.
For aircraft the main capacity is determined. Mail might be present as well.
v | Vehicle of interest | |
mail_capacity | returns secondary cargo (mail) capacity of aircraft |
Definition at line 1463 of file vehicle.cpp.
References CALLBACK_FAILED, EngineInfo::callback_mask, Engine::CanCarryCargo(), RailVehicleInfo::capacity, Vehicle::cargo_subtype, Vehicle::cargo_type, CBID_VEHICLE_REFIT_CAPACITY, CBM_VEHICLE_REFIT_CAPACITY, CC_PASSENGERS, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetDefaultCargoType(), GetVehicleCallback(), HasBit(), IsCargoInClass(), PROP_ROADVEH_CARGO_CAPACITY, PROP_SHIP_CARGO_CAPACITY, PROP_TRAIN_CARGO_CAPACITY, Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Referenced by CmdBuildAircraft(), CmdBuildRoadVeh(), CmdBuildShip(), Train::ConsistChanged(), and RefitVehicle().
Get the colour map for a vehicle.
v | Vehicle to get colour map for |
Definition at line 1444 of file vehicle.cpp.
References RoadVehicleCache::first_engine, TrainCache::first_engine, SpecializedVehicle< RoadVehicle, VEH_ROAD >::From(), SpecializedVehicle< Train, VEH_TRAIN >::From(), RoadVehicle::rcache, BaseVehicle::type, VEH_ROAD, and VEH_TRAIN.
Referenced by DepotWindow::DepotClick(), DrawAircraftImage(), DrawRoadVehImage(), DrawShipImage(), DrawTrainDetails(), DrawTrainImage(), and VehicleGroupWindow::OnClick().
bool HasVehicleOnPos | ( | TileIndex | tile, | |
void * | data, | |||
VehicleFromPosProc * | proc | |||
) |
Checks whether a vehicle in on a specific location.
It will call proc for vehicles until it returns non-NULL.
tile | The location on the map | |
data | Arbitrary data passed to proc | |
proc | The proc that determines whether a vehicle will be "found". |
Definition at line 426 of file vehicle.cpp.
References VehicleFromPos().
Referenced by CheckRoadBlockedForOvertaking(), EnsureNoTrainOnTrack(), ExploreSegment(), HasVehicleOnTunnelBridge(), TrainApproachingCrossing(), and UpdateLevelCrossing().
bool HasVehicleOnPosXY | ( | int | x, | |
int | y, | |||
void * | data, | |||
VehicleFromPosProc * | proc | |||
) |
Checks whether a vehicle in on a specific location.
It will call proc for vehicles until it returns non-NULL.
x | The X location on the map | |
y | The Y location on the map | |
data | Arbitrary data passed to proc | |
proc | The proc that determines whether a vehicle will be "found". |
Definition at line 367 of file vehicle.cpp.
References VehicleFromPosXY().
Finds vehicle in tunnel / bridge.
tile | first end | |
endtile | second end | |
ignore | Ignore this vehicle when searching |
Definition at line 255 of file vehicle.cpp.
References GetVehicleTunnelBridgeProc(), and HasVehicleOnPos().
Referenced by ClearPathReservation(), CmdBuildRoad(), CmdConvertRail(), and RemoveRoad().
void MarkSingleVehicleDirty | ( | const Vehicle * | v | ) |
Marks viewports dirty where the vehicle's image is In fact, it equals BeginVehicleMove(v); EndVehicleMove(v);.
v | vehicle to mark dirty |
Definition at line 1132 of file vehicle.cpp.
References MarkAllViewportsDirty().
Referenced by Vehicle::Crash(), InitializeDisasterVehicle(), and Vehicle::~Vehicle().
CommandCost RefitVehicle | ( | Vehicle * | v, | |
bool | only_this, | |||
CargoID | new_cid, | |||
byte | new_subtype, | |||
DoCommandFlag | flags | |||
) |
Refits a vehicle (chain).
This is the vehicle-type independent part of the CmdRefitXXX functions.
v | The vehicle to refit. | |
only_this | Whether to only refit this vehicle, or the whole chain. | |
new_cid | Cargotype to refit to | |
new_subtype | Cargo subtype to refit to | |
flags | Command flags |
Definition at line 275 of file vehicle_cmd.cpp.
References Engine::CanCarryCargo(), Vehicle::cargo, Vehicle::cargo_cap, Vehicle::cargo_subtype, Vehicle::cargo_type, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Vehicle::GetExpenseType(), GetRefitCost(), GetVehicleCapacity(), HasBit(), Vehicle::InvalidateNewGRFCacheOfChain(), Vehicle::Next(), CargoList< Tinst >::Truncate(), BaseVehicle::type, and VEH_AIRCRAFT.
Referenced by CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), and CmdRefitShip().
void ReleaseDisastersTargetingVehicle | ( | VehicleID | vehicle | ) |
Notify disasters that we are about to delete a vehicle.
So make them head elsewhere.
vehicle | deleted vehicle |
Definition at line 948 of file disaster_cmd.cpp.
References Vehicle::current_order, Vehicle::dest_tile, Order::GetDestination(), RandomTile, Order::SetDestination(), and Vehicle::subtype.
Referenced by Vehicle::PreDestructor().
CommandCost SendAllVehiclesToDepot | ( | VehicleType | type, | |
DoCommandFlag | flags, | |||
bool | service, | |||
Owner | owner, | |||
uint16 | vlw_flag, | |||
uint32 | id | |||
) |
Send all vehicles of type to depots.
type | type of vehicle | |
flags | the flags used for DoCommand() | |
service | should the vehicles only get service in the depots | |
owner | owner of the vehicles to send | |
vlw_flag | tells what kind of list requested the goto depot | |
id | general purpose id whoms meaning is given by vlw_flag ; e.g. StationID for station lists |
Definition at line 576 of file vehicle_cmd.cpp.
References CMD_ERROR, DC_EXEC, DEPOT_DONT_CANCEL, DoCommand(), GenerateVehicleSortList(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, SmallVector< T, S >::Length(), CommandCost::Succeeded(), and Vehicle::tile.
Referenced by CmdSendAircraftToHangar(), CmdSendRoadVehToDepot(), CmdSendShipToDepot(), and CmdSendTrainToDepot().
void ShowNewGrfVehicleError | ( | EngineID | engine, | |
StringID | part1, | |||
StringID | part2, | |||
GRFBugs | bug_type, | |||
bool | critical | |||
) |
Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking.
engine | The engine that caused the problem | |
part1 | Part 1 of the error message, taking the grfname as parameter 1 | |
part2 | Part 2 of the error message, taking the engine as parameter 2 | |
bug_type | Flag to check and set in grfconfig | |
critical | Shall the "OpenTTD might crash"-message be shown when the player tries to unpause? |
Definition at line 195 of file vehicle.cpp.
References _networking, CMD_PAUSE, DC_EXEC, DoCommand(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GRFConfig::grf_bugs, HasBit(), lastof, GRFConfig::name, PM_PAUSED_ERROR, PM_PAUSED_NORMAL, SetBit(), SetDParam(), SetDParamStr(), and ShowErrorMessage().
Referenced by CheckConsistencyOfArticulatedVehicle(), and RailVehicleLengthChanged().
void VehicleEnteredDepotThisTick | ( | Vehicle * | v | ) |
Adds a vehicle to the list of vehicles, that visited a depot this tick.
*v | vehicle to add |
Definition at line 635 of file vehicle.cpp.
References Vehicle::vehstatus.
void VehicleMove | ( | Vehicle * | v, | |
bool | update_viewport | |||
) |
Move a vehicle in the game state; that is moving it's position in the position hashes and marking it's location in the viewport dirty if requested.
v | vehicle to move | |
update_viewport | whether to dirty the viewport |
Definition at line 1097 of file vehicle.cpp.
References Sprite::height, MarkAllViewportsDirty(), max(), min(), RemapCoords(), ST_NORMAL, Sprite::width, Sprite::x_offs, and Sprite::y_offs.
Referenced by AfterLoadVehicles(), CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVeh(), CmdBuildShip(), DisasterTick_Helicopter_Rotors(), InitializeDisasterVehicle(), and Vehicle::UpdateViewport().
byte VehicleRandomBits | ( | ) |
Get a value for a vehicle's random_bits.
Definition at line 276 of file vehicle.cpp.
References GB().
Referenced by CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVeh(), and CmdBuildShip().