#include "stdafx.h"
#include "gui.h"
#include "openttd.h"
#include "debug.h"
#include "roadveh.h"
#include "ship.h"
#include "spritecache.h"
#include "landscape.h"
#include "timetable.h"
#include "viewport_func.h"
#include "news_func.h"
#include "command_func.h"
#include "company_func.h"
#include "vehicle_gui.h"
#include "train.h"
#include "aircraft.h"
#include "newgrf_engine.h"
#include "newgrf_sound.h"
#include "newgrf_station.h"
#include "group.h"
#include "group_gui.h"
#include "strings_func.h"
#include "zoom_func.h"
#include "functions.h"
#include "date_func.h"
#include "window_func.h"
#include "vehicle_func.h"
#include "autoreplace_func.h"
#include "autoreplace_gui.h"
#include "oldpool_func.h"
#include "ai/ai.hpp"
#include "core/smallmap_type.hpp"
#include "depot_func.h"
#include "settings_type.h"
#include "network/network.h"
#include "economy_base.h"
#include "table/sprites.h"
#include "table/strings.h"
Go to the source code of this file.
Defines | |
#define | GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 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. | |
StringID | VehicleInTheWayErrMsg (const Vehicle *v) |
static Vehicle * | EnsureNoVehicleProcZ (Vehicle *v, void *data) |
bool | EnsureNoVehicleOnGround (TileIndex tile) |
static Vehicle * | GetVehicleTunnelBridgeProc (Vehicle *v, void *data) |
Procedure called for every vehicle found in tunnel/bridge in the hash map. | |
bool | HasVehicleOnTunnelBridge (TileIndex tile, TileIndex endtile, const Vehicle *ignore) |
Finds vehicle in tunnel / bridge. | |
byte | VehicleRandomBits () |
Get a value for a vehicle's random_bits. | |
static Vehicle * | VehicleFromHash (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 in on a specific location. | |
static void | UpdateNewVehiclePosHash (Vehicle *v, bool remove) |
static void | UpdateVehiclePosHash (Vehicle *v, int x, int y) |
void | ResetVehiclePosHash () |
void | ResetVehicleColourMap () |
void | InitializeVehicles () |
Vehicle * | GetLastVehicleInChain (Vehicle *v) |
const Vehicle * | GetLastVehicleInChain (const Vehicle *v) |
uint | CountVehiclesInChain (const Vehicle *v) |
bool | IsEngineCountable (const Vehicle *v) |
Check if a vehicle is counted in num_engines in each company struct. | |
void | VehicleEnteredDepotThisTick (Vehicle *v) |
Adds a vehicle to the list of vehicles, that visited a depot this tick. | |
void | CallVehicleTicks () |
bool | CanRefitTo (EngineID engine_type, CargoID cid_to) |
Check if a given engine type can be refitted to a given cargo. | |
CargoID | FindFirstRefittableCargo (EngineID engine_type) |
Find the first cargo type that an engine can be refitted to. | |
CommandCost | GetRefitCost (EngineID engine_type) |
Learn the price of refitting a certain engine. | |
static void | DoDrawVehicle (const Vehicle *v) |
void | ViewportAddVehicles (DrawPixelInfo *dpi) |
Vehicle * | CheckClickOnVehicle (const ViewPort *vp, int x, int y) |
void | CheckVehicle32Day (Vehicle *v) |
void | DecreaseVehicleValue (Vehicle *v) |
void | CheckVehicleBreakdown (Vehicle *v) |
void | AgeVehicle (Vehicle *v) |
uint8 | CalcPercentVehicleFilled (const Vehicle *v, StringID *colour) |
Calculates how full a vehicle is. | |
void | VehicleEnterDepot (Vehicle *v) |
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);. | |
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) |
Trackdir | GetVehicleTrackdir (const Vehicle *v) |
Returns the Trackdir on which the vehicle is currently located. | |
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) |
bool | CanBuildVehicleInfrastructure (VehicleType type) |
Check whether we can build infrastructure for the given vehicle type. | |
const Livery * | GetEngineLivery (EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v) |
static SpriteID | GetEngineColourMap (EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v) |
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. | |
void | StopAllVehicles () |
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? | |
Variables | |
VehicleID | _vehicle_id_ctr_day |
const Vehicle * | _place_clicked_vehicle |
VehicleID | _new_vehicle_id |
uint16 | _returned_refit_capacity |
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 * | _new_vehicle_position_hash [TOTAL_HASH_SIZE] |
static Vehicle * | _vehicle_position_hash [0x1000] |
static AutoreplaceMap | _vehicles_to_autoreplace |
static const byte | _breakdown_chance [64] |
static const Direction | _new_direction_table [] |
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 immediatelly after autoreplace.
Definition at line 477 of file vehicle.cpp.
uint8 CalcPercentVehicleFilled | ( | const Vehicle * | v, | |
StringID * | colour | |||
) |
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 956 of file vehicle.cpp.
References Station::goods, HasBit(), max(), and OLFB_NO_LOAD.
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 1306 of file vehicle.cpp.
References _settings_client, _settings_game, GUISettings::always_build_infrastructure, ClientSettings::gui, HasBit(), max(), VehicleSettings::max_aircraft, VehicleSettings::max_roadveh, VehicleSettings::max_ships, VehicleSettings::max_trains, and GameSettings::vehicle.
Check if a given engine type can be refitted to a given cargo.
engine_type | Engine type to check | |
cid_to | check refit to this cargo-type |
Definition at line 705 of file vehicle.cpp.
References HasBit().
Referenced by AIEngine::CanRefitCargo(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), and CmdRefitShip().
bool CanVehicleUseStation | ( | const Vehicle * | v, | |
const Station * | st | |||
) |
Can this station be used by the given vehicle?
v | the vehicle to test | |
st | the station to test for |
Definition at line 1808 of file vehicle.cpp.
References CanVehicleUseStation(), and Station::GetPrimaryRoadStop().
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 1775 of file vehicle.cpp.
References AIR_CTOL, Station::Airport(), Station::facilities, and AirportFTAClass::flags.
Referenced by CanVehicleUseStation(), CmdBuildAircraft(), CmdCloneOrder(), and CmdInsertOrder().
Find the first cargo type that an engine can be refitted to.
engine_type | Which engine to find cargo for. |
Definition at line 714 of file vehicle.cpp.
References HasBit().
Referenced by CalculateRefitMasks().
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!
Use this when you have the intention that all vehicles should be iterated over.
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 356 of file vehicle.cpp.
References VehicleFromPos().
Referenced by CheckTrainCollision(), CmdConvertRail(), DeleteLastWagon(), FloodVehicles(), GetTrainForReservation(), 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!
Use this when you have the intention that all vehicles should be iterated over.
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 296 of file vehicle.cpp.
References VehicleFromPosXY().
Referenced by CheckTrainCollision().
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 1484 of file vehicle.cpp.
Referenced by DrawEngineList().
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 1154 of file vehicle.cpp.
References GetNewVehiclePosResult::new_tile, GetNewVehiclePosResult::old_tile, GetNewVehiclePosResult::x, and GetNewVehiclePosResult::y.
Referenced by AircraftController(), DisasterTick_Airplane(), DisasterTick_Big_Ufo(), DisasterTick_Big_Ufo_Destroyer(), DisasterTick_Helicopter(), DisasterTick_Submarine(), DisasterTick_Ufo(), DisasterTick_Zeppeliner(), UpdateAirplanesOnNewStation(), and UpdateOldAircraft().
CommandCost GetRefitCost | ( | EngineID | engine_type | ) |
Learn the price of refitting a certain engine.
engine_type | Which engine to refit |
Definition at line 731 of file vehicle.cpp.
References RAILVEH_WAGON.
Referenced by CmdCloneVehicle(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), and CmdRefitShip().
SpriteID GetVehiclePalette | ( | const Vehicle * | v | ) |
Get the colour map for a vehicle.
v | Vehicle to get colour map for |
Definition at line 1489 of file vehicle.cpp.
Trackdir GetVehicleTrackdir | ( | const Vehicle * | v | ) |
Returns the Trackdir on which the vehicle is currently located.
Works for trains and ships. Currently works only sortof for road vehicles, since they have a fuzzy concept of being "on" a trackdir. Dunno really what it returns for a road vehicle that is halfway a tile, never really understood that part. For road vehicles that are at the beginning or end of the tile, should just return the diagonal trackdir on which they are driving. I _think_. For other vehicles types, or vehicles with no clear trackdir (such as those in depots), returns 0xFF.
Definition at line 1199 of file vehicle.cpp.
References DiagDirToDiagTrackdir(), DirToDiagDir(), FindFirstTrack(), GetRailDepotDirection(), GetRoadStopDir(), INVALID_TRACKDIR, IsReversingRoadTrackdir(), RVSB_TRACKDIR_MASK, TRACK_BIT_DEPOT, TRACK_BIT_WORMHOLE, and TrackDirectionToTrackdir().
Referenced by CheckNextTrainTile(), ChooseShipTrack(), CmdBuildRailroadStation(), CmdRemoveFromRailroadStation(), FindClosestTrainDepot(), FollowTrainReservation(), FreeTrainTrackReservation(), YapfCheckReverseTrain(), YapfFindNearestRailDepotTwoWay(), and YapfFindNearestRoadDepot().
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 371 of file vehicle.cpp.
References VehicleFromPos().
Referenced by CheckRoadBlockedForOvertaking(), EnsureNoTrainOnTrack(), ExploreSegment(), FollowTrainReservation(), 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 312 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 184 of file vehicle.cpp.
References GetVehicleTunnelBridgeProc(), and HasVehicleOnPos().
Referenced by ClearPathReservation(), CmdBuildRoad(), CmdConvertRail(), and RemoveRoad().
bool IsEngineCountable | ( | const Vehicle * | v | ) |
Check if a vehicle is counted in num_engines in each company struct.
*v | Vehicle to test |
Definition at line 517 of file vehicle.cpp.
References IsArticulatedPart(), IsNormalAircraft(), and IsRearDualheaded().
Referenced by CmdAddVehicleGroup(), SetCachedEngineCounts(), SetTrainGroupID(), and UpdateTrainGroupID().
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 |
EndVehicleMove()
Definition at line 1145 of file vehicle.cpp.
References MarkAllViewportsDirty().
Referenced by DisasterTick_Ufo(), and InitializeDisasterVehicle().
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 114 of file vehicle.cpp.
References GRFConfig::grf_bugs, HasBit(), lastof, GRFConfig::name, SetBit(), and SetDParamStr().
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 609 of file vehicle.cpp.
VehicleEnterTileStatus VehicleEnterTile | ( | Vehicle * | v, | |
TileIndex | tile, | |||
int | x, | |||
int | y | |||
) |
Call the tile callback function for a vehicle entering a tile.
v | Vehicle entering the tile | |
tile | Tile entered | |
x | X position | |
y | Y position |
Definition at line 1251 of file vehicle.cpp.
References _tile_type_procs, GetTileType(), and TileTypeProcs::vehicle_enter_tile_proc.
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 327 of file vehicle.cpp.
References GB(), TileX(), and TileY().
Referenced by FindVehicleOnPos(), and HasVehicleOnPos().
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 269 of file vehicle.cpp.
References GB(), and TILE_SIZE.
Referenced by FindVehicleOnPosXY(), and HasVehicleOnPosXY().
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 1110 of file vehicle.cpp.
References Rect::bottom, Rect::left, MarkAllViewportsDirty(), max(), min(), Rect::right, ST_NORMAL, Rect::top, Point::x, and Point::y.
Referenced by AfterLoadVehicles(), CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVeh(), CmdBuildShip(), DisasterTick_Helicopter_Rotors(), and InitializeDisasterVehicle().
byte VehicleRandomBits | ( | ) |
Get a value for a vehicle's random_bits.
Definition at line 205 of file vehicle.cpp.
References GB().
Referenced by CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVeh(), and CmdBuildShip().
const byte _breakdown_chance[64] [static] |
Initial value:
{ 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 870 of file vehicle.cpp.
const Direction _new_direction_table[] [static] |