Base implementations of all vehicles. More...
#include "stdafx.h"
#include "error.h"
#include "roadveh.h"
#include "ship.h"
#include "spritecache.h"
#include "timetable.h"
#include "viewport_func.h"
#include "news_func.h"
#include "command_func.h"
#include "company_func.h"
#include "train.h"
#include "aircraft.h"
#include "newgrf_debug.h"
#include "newgrf_sound.h"
#include "newgrf_station.h"
#include "group_gui.h"
#include "strings_func.h"
#include "zoom_func.h"
#include "date_func.h"
#include "vehicle_func.h"
#include "autoreplace_func.h"
#include "autoreplace_gui.h"
#include "station_base.h"
#include "ai/ai.hpp"
#include "depot_func.h"
#include "network/network.h"
#include "core/pool_func.hpp"
#include "economy_base.h"
#include "articulated_vehicles.h"
#include "roadstop_base.h"
#include "core/random_func.hpp"
#include "core/backup_type.hpp"
#include "order_backup.h"
#include "sound_func.h"
#include "effectvehicle_func.h"
#include "effectvehicle_base.h"
#include "vehiclelist.h"
#include "bridge_map.h"
#include "tunnel_map.h"
#include "depot_map.h"
#include "gamelog.h"
#include "table/strings.h"
Go to the source code of this file.
Defines | |
#define | GEN_HASH(x, y) ((GB((y), 6 + ZOOM_LVL_SHIFT, 6) << 6) + GB((x), 7 + ZOOM_LVL_SHIFT, 6)) |
Typedefs | |
typedef SmallMap< Vehicle *, bool, 4 > | AutoreplaceMap |
List of vehicles that should check for autoreplace this tick. | |
Functions | |
void | VehicleServiceInDepot (Vehicle *v) |
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. | |
void | VehicleLengthChanged (const Vehicle *u) |
Logs a bug in GRF and shows a warning message if this is for the first time this happened. | |
byte | VehicleRandomBits () |
Get a value for a vehicle's random_bits. | |
static Vehicle * | VehicleFromTileHash (int xl, int yl, int xu, int yu, void *data, VehicleFromPosProc *proc, bool find_first) |
static Vehicle * | VehicleFromPosXY (int x, int y, void *data, VehicleFromPosProc *proc, bool find_first) |
Helper function for FindVehicleOnPos/HasVehicleOnPos. | |
void | FindVehicleOnPosXY (int x, int y, void *data, VehicleFromPosProc *proc) |
Find a vehicle from a specific location. | |
bool | HasVehicleOnPosXY (int x, int y, void *data, VehicleFromPosProc *proc) |
Checks whether a vehicle in on a specific location. | |
static Vehicle * | VehicleFromPos (TileIndex tile, void *data, VehicleFromPosProc *proc, bool find_first) |
Helper function for FindVehicleOnPos/HasVehicleOnPos. | |
void | FindVehicleOnPos (TileIndex tile, void *data, VehicleFromPosProc *proc) |
Find a vehicle from a specific location. | |
bool | HasVehicleOnPos (TileIndex tile, void *data, VehicleFromPosProc *proc) |
Checks whether a vehicle is on a specific location. | |
static Vehicle * | EnsureNoVehicleProcZ (Vehicle *v, void *data) |
Callback that returns 'real' vehicles lower or at height * (int*)data . | |
CommandCost | EnsureNoVehicleOnGround (TileIndex tile) |
Ensure there is no vehicle at the ground at the given position. | |
static Vehicle * | GetVehicleTunnelBridgeProc (Vehicle *v, void *data) |
Procedure called for every vehicle found in tunnel/bridge in the hash map. | |
CommandCost | TunnelBridgeIsFree (TileIndex tile, TileIndex endtile, const Vehicle *ignore) |
Finds vehicle in tunnel / bridge. | |
static Vehicle * | EnsureNoTrainOnTrackProc (Vehicle *v, void *data) |
CommandCost | EnsureNoTrainOnTrackBits (TileIndex tile, TrackBits track_bits) |
Tests if a vehicle interacts with the specified track bits. | |
static void | UpdateVehicleTileHash (Vehicle *v, bool remove) |
static void | UpdateVehicleViewportHash (Vehicle *v, int x, int y) |
void | ResetVehicleHash () |
void | ResetVehicleColourMap () |
void | InitializeVehicles () |
uint | CountVehiclesInChain (const Vehicle *v) |
void | VehicleEnteredDepotThisTick (Vehicle *v) |
Adds a vehicle to the list of vehicles that visited a depot this tick. | |
static void | RunVehicleDayProc () |
Increases the day counter for all vehicles and calls 1-day and 32-day handlers. | |
void | CallVehicleTicks () |
static void | DoDrawVehicle (const Vehicle *v) |
Add vehicle sprite for drawing to the screen. | |
void | ViewportAddVehicles (DrawPixelInfo *dpi) |
Add the vehicle sprites that should be drawn at a part of the screen. | |
Vehicle * | CheckClickOnVehicle (const ViewPort *vp, int x, int y) |
Find the vehicle close to the clicked coordinates. | |
void | DecreaseVehicleValue (Vehicle *v) |
Decrease the value of a vehicle. | |
void | CheckVehicleBreakdown (Vehicle *v) |
void | AgeVehicle (Vehicle *v) |
Update age of a vehicle. | |
uint8 | CalcPercentVehicleFilled (const Vehicle *front, StringID *colour) |
Calculates how full a vehicle is. | |
void | VehicleEnterDepot (Vehicle *v) |
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it, etc. | |
void | VehicleUpdatePosition (Vehicle *v) |
Update the position of the vehicle. | |
void | VehicleUpdateViewport (Vehicle *v, bool dirty) |
Update the vehicle on the viewport, updating the right hash and setting the new coordinates. | |
void | VehicleUpdatePositionAndViewport (Vehicle *v) |
Update the position of the vehicle, and update the viewport. | |
void | MarkSingleVehicleDirty (const Vehicle *v) |
Marks viewports dirty where the vehicle's image is. | |
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) |
VehicleEnterTileStatus | VehicleEnterTile (Vehicle *v, TileIndex tile, int x, int y) |
Call the tile callback function for a vehicle entering a tile. | |
UnitID | GetFreeUnitNumber (VehicleType type) |
Get an unused unit number for a vehicle (if allowed). | |
bool | CanBuildVehicleInfrastructure (VehicleType type) |
Check whether we can build infrastructure for the given vehicle type. | |
LiveryScheme | GetEngineLiveryScheme (EngineID engine_type, EngineID parent_engine_type, const Vehicle *v) |
Determines the LiveryScheme for a vehicle. | |
const Livery * | GetEngineLivery (EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting) |
Determines the livery for a vehicle. | |
static PaletteID | GetEngineColourMap (EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v) |
PaletteID | GetEnginePalette (EngineID engine_type, CompanyID company) |
Get the colour map for an engine. | |
PaletteID | GetVehiclePalette (const Vehicle *v) |
Get the colour map for a vehicle. | |
void | VehiclesYearlyLoop () |
bool | CanVehicleUseStation (EngineID engine_type, const Station *st) |
Can this station be used by the given engine type? | |
bool | CanVehicleUseStation (const Vehicle *v, const Station *st) |
Can this station be used by the given vehicle? | |
void | GetVehicleSet (VehicleSet &set, Vehicle *v, uint8 num_vehicles) |
Calculates the set of vehicles that will be affected by a given selection. | |
Variables | |
VehicleID | _new_vehicle_id |
uint16 | _returned_refit_capacity |
Stores the capacity after a refit operation. | |
uint16 | _returned_mail_refit_capacity |
Stores the mail capacity after a refit operation (Aircraft only). | |
VehiclePool | _vehicle_pool ("Vehicle") |
The pool with all our precious vehicles. | |
const int | HASH_BITS = 7 |
const int | HASH_SIZE = 1 << HASH_BITS |
const int | HASH_MASK = HASH_SIZE - 1 |
const int | TOTAL_HASH_SIZE = 1 << (HASH_BITS * 2) |
const int | TOTAL_HASH_MASK = TOTAL_HASH_SIZE - 1 |
const int | HASH_RES = 0 |
static Vehicle * | _vehicle_tile_hash [TOTAL_HASH_SIZE] |
static Vehicle * | _vehicle_viewport_hash [0x1000] |
static AutoreplaceMap | _vehicles_to_autoreplace |
static const byte | _breakdown_chance [64] |
static const Direction | _new_direction_table [] |
static const int8 | _vehicle_smoke_pos [8] |
Base implementations of all vehicles.
Definition in file vehicle.cpp.
typedef SmallMap<Vehicle *, bool, 4> AutoreplaceMap |
List of vehicles that should check for autoreplace this tick.
Mapping of vehicle -> leave depot immediately after autoreplace.
Definition at line 606 of file vehicle.cpp.
void AgeVehicle | ( | Vehicle * | v | ) |
Update age of a vehicle.
v | Vehicle to update. |
Definition at line 1196 of file vehicle.cpp.
References _local_company, AddVehicleAdviceNewsItem(), Vehicle::age, Engine::company_avail, DAYS_IN_LEAP_YEAR, SpecializedVehicle< Train, Type >::From(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Vehicle::GetEngine(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, GroundVehicle< T, Type >::IsEngine(), Vehicle::IsPrimaryVehicle(), Vehicle::max_age, MAX_DAY, Vehicle::owner, Vehicle::Previous(), Vehicle::reliability_spd_dec, SetDParam(), SetWindowDirty(), BaseVehicle::type, VEH_TRAIN, VEHICLE_PROFIT_MIN_AGE, GroupStatistics::VehicleReachedProfitAge(), Vehicle::vehstatus, and WC_VEHICLE_DETAILS.
Referenced by Train::OnNewDay(), Ship::OnNewDay(), RoadVehicle::OnNewDay(), and Aircraft::OnNewDay().
Calculates how full a vehicle is.
front | The front vehicle of the consist to check. | |
colour | The string to show depending on if we are unloading or loading |
Definition at line 1240 of file vehicle.cpp.
References GoodsEntry::acceptance_pickup, Vehicle::cargo, Vehicle::cargo_cap, Vehicle::cargo_type, Vehicle::current_order, GoodsEntry::GES_PICKUP, SpecializedStation< Station, false >::GetIfValid(), Order::GetLoadType(), Station::goods, HasBit(), Order::IsType(), Vehicle::last_station_visited, max(), Vehicle::Next(), VehicleCargoList::OnboardCount(), BaseConsist::vehicle_flags, VF_CARGO_UNLOADING, VF_LOADING_FINISHED, and VF_STOP_LOADING.
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 1613 of file vehicle.cpp.
References _local_company, _settings_client, _settings_game, Engine::company_avail, GUISettings::disable_unsuitable_building, FOR_ALL_VEHICLES, ClientSettings::gui, HasBit(), IsCompanyBuildableVehicleType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), VehicleSettings::max_aircraft, VehicleSettings::max_roadveh, VehicleSettings::max_ships, VehicleSettings::max_trains, Vehicle::owner, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and GameSettings::vehicle.
Referenced by BuildRoadToolbarWindow::OnClick(), BuildDocksToolbarWindow::OnClick(), BuildRoadToolbarWindow::OnInvalidateData(), BuildDocksToolbarWindow::OnInvalidateData(), MainToolbarWindow::OnKeyPress(), and MainToolbarWindow::OnPaint().
Can this station be used by the given engine type?
engine_type | the type of vehicles to test | |
st | the station to test for |
Definition at line 2626 of file vehicle.cpp.
References AIR_CTOL, AirportFTAClass::AIRPLANES, Station::airport, FACIL_AIRPORT, FACIL_BUS_STOP, FACIL_DOCK, FACIL_TRAIN, FACIL_TRUCK_STOP, BaseStation::facilities, AirportFTAClass::flags, Airport::GetFTA(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetIfValid(), AircraftVehicleInfo::subtype, Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Referenced by CanVehicleUseStation(), CheckOrders(), CmdBuildAircraft(), CmdCloneOrder(), CmdInsertOrder(), and RoadVehicle::GetOrderStationLocation().
Can this station be used by the given vehicle?
v | the vehicle to test | |
st | the station to test for |
Definition at line 2659 of file vehicle.cpp.
References CanVehicleUseStation(), Vehicle::engine_type, SpecializedVehicle< RoadVehicle, Type >::From(), BaseVehicle::type, and VEH_ROAD.
Find the vehicle close to the clicked coordinates.
vp | Viewport clicked in. | |
x | X coordinate in the viewport. | |
y | Y coordinate in the viewport. |
NULL
if none found. Definition at line 1038 of file vehicle.cpp.
References abs(), FOR_ALL_VEHICLES, ViewPort::height, ViewPort::left, max(), ScaleByZoom(), ViewPort::top, ViewPort::virtual_left, ViewPort::virtual_top, VS_HIDDEN, VS_UNCLICKABLE, ViewPort::width, and ViewPort::zoom.
void DecreaseVehicleValue | ( | Vehicle * | v | ) |
Decrease the value of a vehicle.
v | Vehicle to devaluate. |
Definition at line 1072 of file vehicle.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, SetWindowDirty(), Vehicle::value, and WC_VEHICLE_DETAILS.
Referenced by Train::OnNewDay(), Ship::OnNewDay(), RoadVehicle::OnNewDay(), and Aircraft::OnNewDay().
static void DoDrawVehicle | ( | const Vehicle * | v | ) | [static] |
Add vehicle sprite for drawing to the screen.
v | Vehicle to draw. |
Definition at line 955 of file vehicle.cpp.
References AddSortableSpriteToDraw(), Vehicle::cur_image, SpecializedVehicle< EffectVehicle, VEH_EFFECT >::From(), EffectVehicle::GetTransparencyOption(), GetVehiclePalette(), IsInvisibilitySet(), IsTransparencySet(), PALETTE_CRASH, TO_INVALID, BaseVehicle::type, VEH_EFFECT, Vehicle::vehstatus, VS_DEFPAL, Vehicle::x_bb_offs, Vehicle::x_extent, Vehicle::x_offs, Vehicle::x_pos, Vehicle::y_bb_offs, Vehicle::y_extent, Vehicle::y_offs, Vehicle::y_pos, Vehicle::z_extent, and Vehicle::z_pos.
Referenced by ViewportAddVehicles().
CommandCost EnsureNoTrainOnTrackBits | ( | TileIndex | tile, | |
TrackBits | track_bits | |||
) |
Tests if a vehicle interacts with the specified track bits.
All track bits interact except parallel TRACK_BIT_HORZ or TRACK_BIT_VERT.
tile | The tile. | |
track_bits | The track bits. |
true
if no train that interacts, is found. false
if a train is found. Definition at line 516 of file vehicle.cpp.
References return_cmd_error, BaseVehicle::type, and VehicleFromPos().
Referenced by EnsureNoTrainOnTrack(), and ExploreSegment().
CommandCost EnsureNoVehicleOnGround | ( | TileIndex | tile | ) |
Ensure there is no vehicle at the ground at the given position.
tile | Position to examine. |
Definition at line 454 of file vehicle.cpp.
References EnsureNoVehicleProcZ(), GetTileMaxPixelZ(), return_cmd_error, BaseVehicle::type, and VehicleFromPos().
Referenced by CheckBuildableTile(), CheckIfIndustryTilesAreFree(), CmdBuildObject(), CmdBuildRoad(), CmdBuildSingleRail(), CmdConvertRail(), CmdRemoveSingleRail(), DoBuildLock(), IsValidTileForWaypoint(), RemoveAirport(), RemoveBuoy(), RemoveDock(), RemoveFromRailBaseStation(), RemoveLock(), RemoveRailStation(), RemoveRoad(), and RemoveRoadStop().
Callback that returns 'real' vehicles lower or at height *
(int*)data .
v | Vehicle to examine. | |
data | Pointer to height data. |
NULL
. Definition at line 439 of file vehicle.cpp.
References AIR_SHADOW, Vehicle::subtype, BaseVehicle::type, VEH_AIRCRAFT, VEH_DISASTER, and Vehicle::z_pos.
Referenced by EnsureNoVehicleOnGround().
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 413 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 353 of file vehicle.cpp.
References VehicleFromPosXY().
Referenced by CheckTrainCollision().
const Livery* GetEngineLivery | ( | EngineID | engine_type, | |
CompanyID | company, | |||
EngineID | parent_engine_type, | |||
const Vehicle * | v, | |||
byte | livery_setting | |||
) | [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. | |
livery_setting | The livery settings to use for acquiring the livery information. |
Definition at line 1746 of file vehicle.cpp.
References _local_company, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), GetEngineLiveryScheme(), Livery::in_use, LIT_ALL, and LIT_COMPANY.
Referenced by LiveryHelper().
LiveryScheme GetEngineLiveryScheme | ( | EngineID | engine_type, | |
EngineID | parent_engine_type, | |||
const Vehicle * | v | |||
) |
Determines the LiveryScheme for a vehicle.
engine_type | Engine of the vehicle. | |
parent_engine_type | Engine of the front vehicle, INVALID_ENGINE if vehicle is at front itself. | |
v | the vehicle, NULL if in purchase list etc. |
Definition at line 1656 of file vehicle.cpp.
References AIR_CTOL, Vehicle::cargo_type, CC_PASSENGERS, CT_INVALID, EC_DIESEL, EC_ELECTRIC, EC_MAGLEV, EC_MONORAIL, EC_STEAM, EF_RAIL_IS_MU, EF_ROAD_TRAM, Vehicle::First(), CargoSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), HasBit(), INVALID_ENGINE, Vehicle::IsArticulatedPart(), IsCargoInClass(), RAILVEH_WAGON, UsesWagonOverride(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Referenced by FinaliseEngineArray(), and GetEngineLivery().
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 1814 of file vehicle.cpp.
References INVALID_ENGINE.
Referenced by DrawEngineList(), NewsWindow::DrawWidget(), and EnginePreviewWindow::DrawWidget().
UnitID GetFreeUnitNumber | ( | VehicleType | type | ) |
Get an unused unit number for a vehicle (if allowed).
type | Type of vehicle |
UINT16_MAX
. Definition at line 1584 of file vehicle.cpp.
References _current_company, _settings_game, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Company::group_all, VehicleSettings::max_aircraft, VehicleSettings::max_roadveh, VehicleSettings::max_ships, VehicleSettings::max_trains, FreeUnitIDGenerator::NextID(), GroupStatistics::num_vehicle, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and GameSettings::vehicle.
Referenced by CheckNewTrain(), CmdBuildVehicle(), and NormaliseTrainHead().
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 1478 of file vehicle.cpp.
References Vehicle::direction, GetNewVehiclePosResult::new_tile, GetNewVehiclePosResult::old_tile, Vehicle::tile, TileVirtXY(), Vehicle::x_pos, GetNewVehiclePosResult::y, and Vehicle::y_pos.
Referenced by AircraftController(), DisasterTick_Aircraft(), DisasterTick_Big_Ufo(), DisasterTick_Big_Ufo_Destroyer(), DisasterTick_Submarine(), DisasterTick_Ufo(), DisasterTick_Zeppeliner(), TrainController(), and UpdateOldAircraft().
Get the colour map for a vehicle.
v | Vehicle to get colour map for |
Definition at line 1824 of file vehicle.cpp.
References Vehicle::engine_type, GroundVehicleCache::first_engine, Vehicle::GetGroundVehicleCache(), INVALID_ENGINE, Vehicle::IsGroundVehicle(), and Vehicle::owner.
Referenced by DepotWindow::DepotClick(), DoDrawVehicle(), DrawAircraftImage(), DrawRoadVehImage(), DrawShipImage(), DrawTrainDetails(), DrawTrainImage(), and VehicleGroupWindow::OnClick().
void GetVehicleSet | ( | VehicleSet & | set, | |
Vehicle * | v, | |||
uint8 | num_vehicles | |||
) |
Calculates the set of vehicles that will be affected by a given selection.
set | [inout] Set of affected vehicles. | |
v | First vehicle of the selection. | |
num_vehicles | Number of vehicles in the selection (not counting articulated parts). |
Definition at line 2734 of file vehicle.cpp.
References SpecializedVehicle< Train, Type >::From(), SpecializedVehicle< T, Type >::GetFirstEnginePart(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Vehicle::IsArticulatedPart(), GroundVehicle< T, Type >::IsMultiheaded(), SpecializedVehicle< T, Type >::Next(), BaseVehicle::type, and VEH_TRAIN.
Referenced by RefitWindow::BuildRefitList(), RefitWindow::DrawWidget(), and RefitVehicle().
bool HasVehicleOnPos | ( | TileIndex | tile, | |
void * | data, | |||
VehicleFromPosProc * | proc | |||
) |
Checks whether a vehicle is 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 428 of file vehicle.cpp.
References VehicleFromPos().
Referenced by CheckRoadBlockedForOvertaking(), ExploreSegment(), TrainApproachingCrossing(), TrainController(), 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 369 of file vehicle.cpp.
References VehicleFromPosXY().
void MarkSingleVehicleDirty | ( | const Vehicle * | v | ) |
Marks viewports dirty where the vehicle's image is.
v | vehicle to mark dirty |
Definition at line 1468 of file vehicle.cpp.
References Vehicle::coord, and MarkAllViewportsDirty().
Referenced by Vehicle::Crash(), VehicleUpdateViewport(), and Vehicle::~Vehicle().
static void RunVehicleDayProc | ( | ) | [static] |
Increases the day counter for all vehicles and calls 1-day and 32-day handlers.
Each tick, it processes vehicles with "index % DAY_TICKS == _date_fract", so each day, all vehicles are processes in DAY_TICKS steps.
Definition at line 827 of file vehicle.cpp.
References _date_fract, CALLBACK_FAILED, CBID_VEHICLE_32DAY_CALLBACK, Vehicle::colourmap, Vehicle::day_counter, DAY_TICKS, Vehicle::engine_type, ErrorUnknownCallbackResult(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Vehicle::GetGRFID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetPoolSize(), GetVehicleCallback(), HasBit(), Vehicle::HasEngineType(), Vehicle::MarkDirty(), and Vehicle::OnNewDay().
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 218 of file vehicle.cpp.
References _networking, CMD_PAUSE, DC_EXEC, DEBUG, DoCommand(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetGRFConfig(), Engine::GetGRFID(), GRFConfig::GetName(), GRFConfig::grf_bugs, HasBit(), lastof, PM_PAUSED_ERROR, PM_PAUSED_NORMAL, SetBit(), SetDParam(), SetDParamStr(), ShowErrorMessage(), and WL_CRITICAL.
Referenced by CheckConsistencyOfArticulatedVehicle(), Vehicle::UpdateVisualEffect(), and VehicleLengthChanged().
CommandCost TunnelBridgeIsFree | ( | TileIndex | tile, | |
TileIndex | endtile, | |||
const Vehicle * | ignore | |||
) |
Finds vehicle in tunnel / bridge.
tile | first end | |
endtile | second end | |
ignore | Ignore this vehicle when searching |
Definition at line 483 of file vehicle.cpp.
References GetVehicleTunnelBridgeProc(), return_cmd_error, BaseVehicle::type, and VehicleFromPos().
Referenced by ClearPathReservation(), CmdBuildRoad(), CmdConvertRail(), DoClearBridge(), DoClearTunnel(), and RemoveRoad().
void VehicleEnterDepot | ( | Vehicle * | v | ) |
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it, etc.
v | Vehicle that entered a depot. |
Definition at line 1293 of file vehicle.cpp.
References _current_company, _local_company, _settings_client, AddVehicleAdviceNewsItem(), ClrBit(), Train::ConsistChanged(), BaseConsist::cur_real_order_index, Vehicle::cur_speed, Vehicle::current_order, Vehicle::DeleteUnreachedImplicitOrders(), Vehicle::dest_tile, DoCommand(), CommandCost::Failed(), Vehicle::First(), SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< Ship, VEH_SHIP >::From(), SpecializedVehicle< Train, Type >::From(), CommandCost::GetCost(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Order::GetDestination(), Vehicle::GetOrder(), Order::GetRefitCargo(), Order::GetRefitSubtype(), GetStationIndex(), ClientSettings::gui, HandleAircraftEnterHangar(), Vehicle::IncrementImplicitOrderIndex(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_DIAGDIR, InvalidateWindowData(), Order::IsRefit(), Order::IsType(), Order::MakeDummy(), Vehicle::MarkDirty(), MarkTileDirtyByTile(), AI::NewEvent(), Vehicle::owner, Vehicle::profit_this_year, Backup< T >::Restore(), SetDepotReservation(), SetDParam(), SetWindowClassesDirty(), SetWindowDirty(), GUISettings::show_track_reservation, ShowCostOrIncomeAnimation(), Ship::state, Vehicle::tile, BaseVehicle::type, Ship::UpdateCache(), UpdateSignalsOnSegment(), UpdateVehicleTimetable(), SpecializedVehicle< T, Type >::UpdateViewport(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, Vehicle::vehstatus, VRF_TOGGLE_REVERSE, Train::wait_counter, WC_AIRCRAFT_LIST, WC_ROADVEH_LIST, WC_SHIPS_LIST, WC_TRAINS_LIST, WC_VEHICLE_DEPOT, WC_VEHICLE_VIEW, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.
Referenced by AircraftEventHandler_EnterHangar(), AircraftEventHandler_InHangar(), CheckTrainStayInDepot(), and VehicleEnter_Track().
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 809 of file vehicle.cpp.
References Vehicle::vehstatus.
VehicleEnterTileStatus VehicleEnterTile | ( | Vehicle * | v, | |
TileIndex | tile, | |||
int | x, | |||
int | y | |||
) |
Call the tile callback function for a vehicle entering a tile.
Definition at line 1532 of file vehicle.cpp.
References _tile_type_procs, GetTileType(), and TileTypeProcs::vehicle_enter_tile_proc.
Referenced by TrainController(), and UpdateStatusAfterSwap().
static Vehicle* VehicleFromPos | ( | TileIndex | tile, | |
void * | data, | |||
VehicleFromPosProc * | proc, | |||
bool | find_first | |||
) | [static] |
Helper function for FindVehicleOnPos/HasVehicleOnPos.
tile | The location on the map | |
data | Arbitrary data passed to proc. | |
proc | The proc that determines whether a vehicle will be "found". | |
find_first | Whether to return on the first found or iterate over all vehicles |
Definition at line 384 of file vehicle.cpp.
References GB(), Vehicle::hash_tile_next, Vehicle::tile, TileX(), and TileY().
Referenced by EnsureNoTrainOnTrackBits(), EnsureNoVehicleOnGround(), FindVehicleOnPos(), HasVehicleOnPos(), and TunnelBridgeIsFree().
static Vehicle* VehicleFromPosXY | ( | int | x, | |
int | y, | |||
void * | data, | |||
VehicleFromPosProc * | proc, | |||
bool | find_first | |||
) | [static] |
Helper function for FindVehicleOnPos/HasVehicleOnPos.
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". | |
find_first | Whether to return on the first found or iterate over all vehicles |
Definition at line 326 of file vehicle.cpp.
References GB(), and TILE_SIZE.
Referenced by FindVehicleOnPosXY(), and HasVehicleOnPosXY().
void VehicleLengthChanged | ( | const Vehicle * | u | ) |
Logs a bug in GRF and shows a warning message if this is for the first time this happened.
u | first vehicle of chain |
Definition at line 248 of file vehicle.cpp.
References Vehicle::engine_type, GamelogGRFBugReverse(), GBUG_VEH_LENGTH, Vehicle::GetEngine(), GetGRFConfig(), GRFConfig::grf_bugs, Engine::grf_prop, GRFFilePropsBase< Tcnt >::grffile, HasBit(), GRFFilePropsBase< Tcnt >::local_id, and ShowNewGrfVehicleError().
Referenced by Train::ConsistChanged(), and RoadVehUpdateCache().
byte VehicleRandomBits | ( | ) |
Get a value for a vehicle's random_bits.
Definition at line 278 of file vehicle.cpp.
References GB().
Referenced by AddArticulatedParts(), CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVehicle(), and CmdBuildShip().
void VehicleUpdatePosition | ( | Vehicle * | v | ) |
Update the position of the vehicle.
This will update the hash that tells which vehicles are on a tile.
v | The vehicle to update. |
Definition at line 1412 of file vehicle.cpp.
Referenced by AddArticulatedParts(), AfterLoadVehicles(), ChangeTrainDirRandomly(), CheckTrainStayInDepot(), CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVehicle(), CmdBuildShip(), SetAircraftPosition(), TrainController(), UpdateStatusAfterSwap(), and VehicleUpdatePositionAndViewport().
void VehicleUpdatePositionAndViewport | ( | Vehicle * | v | ) |
Update the position of the vehicle, and update the viewport.
v | The vehicle to update. |
Definition at line 1458 of file vehicle.cpp.
References VehicleUpdatePosition(), and VehicleUpdateViewport().
Referenced by CreateEffectVehicle(), DisasterTick_Helicopter_Rotors(), InitializeDisasterVehicle(), and SetAircraftPosition().
void VehicleUpdateViewport | ( | Vehicle * | v, | |
bool | dirty | |||
) |
Update the vehicle on the viewport, updating the right hash and setting the new coordinates.
v | The vehicle to update. | |
dirty | Mark the (new and old) coordinates of the vehicle as dirty. |
Definition at line 1423 of file vehicle.cpp.
References Vehicle::coord, Vehicle::cur_image, Sprite::height, INVALID_COORD, MarkAllViewportsDirty(), MarkSingleVehicleDirty(), max(), min(), RemapCoords(), ST_NORMAL, Sprite::width, Sprite::x_offs, Vehicle::x_offs, Vehicle::x_pos, Sprite::y_offs, Vehicle::y_offs, Vehicle::y_pos, and Vehicle::z_pos.
Referenced by AfterLoadVehicles(), TrainController(), SpecializedVehicle< RoadVehicle, Type >::UpdateViewport(), and VehicleUpdatePositionAndViewport().
void ViewportAddVehicles | ( | DrawPixelInfo * | dpi | ) |
Add the vehicle sprites that should be drawn at a part of the screen.
dpi | Rectangle being drawn. |
Definition at line 980 of file vehicle.cpp.
References Vehicle::coord, DoDrawVehicle(), GB(), Vehicle::hash_viewport_next, Vehicle::vehstatus, and VS_HIDDEN.
const byte _breakdown_chance[64] [static] |
{ 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 13, 13, 13, 13, 14, 15, 16, 17, 19, 21, 25, 28, 31, 34, 37, 40, 44, 48, 52, 56, 60, 64, 68, 72, 80, 90, 100, 110, 120, 130, 140, 150, 170, 190, 210, 230, 250, 250, 250, }
Definition at line 1078 of file vehicle.cpp.
const Direction _new_direction_table[] [static] |
{ DIR_N, DIR_NW, DIR_W, DIR_NE, DIR_SE, DIR_SW, DIR_E, DIR_SE, DIR_S }
Definition at line 1496 of file vehicle.cpp.
VehiclePool _vehicle_pool("Vehicle") |
The pool with all our precious vehicles.
const int8 _vehicle_smoke_pos[8] [static] |
{ 1, 1, 1, 0, -1, -1, -1, 0 }
Definition at line 2363 of file vehicle.cpp.