|
OpenTTD Source 20260311-master-g511d3794ce
|
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 "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 "core/container_func.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 "linkgraph/linkgraph.h"#include "linkgraph/refresh.h"#include "framerate_type.h"#include "autoreplace_cmd.h"#include "misc_cmd.h"#include "train_cmd.h"#include "vehicle_cmd.h"#include "newgrf_roadstop.h"#include "timer/timer.h"#include "timer/timer_game_calendar.h"#include "timer/timer_game_economy.h"#include "timer/timer_game_tick.h"#include "table/strings.h"#include "safeguards.h"Go to the source code of this file.
Typedefs | |
| using | AutoreplaceMap = std::map<VehicleID, bool> |
| List of vehicles that should check for autoreplace this tick. | |
Functions | |
| static uint | GetViewportHashX (int x) |
| static uint | GetViewportHashY (int y) |
| static uint | GetViewportHash (int x, int y) |
| void | VehicleServiceInDepot (Vehicle *v) |
| Service a vehicle and all subsequent vehicles in the consist. | |
| void | ShowNewGrfVehicleError (EngineID engine, StringID part1, StringID part2, GRFBug 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. | |
| static uint | GetTileHash1D (uint p) |
| Compute hash for 1D tile coordinate. | |
| static uint | IncTileHash1D (uint h) |
| Increment 1D hash to next bucket. | |
| static uint | ComposeTileHash (uint hx, uint hy) |
| Compose two 1D hashes into 2D hash. | |
| static uint | GetTileHash (uint x, uint y) |
| Compute hash for tile coordinate. | |
| CommandCost | EnsureNoVehicleOnGround (TileIndex tile) |
| Ensure there is no vehicle at the ground at the given position. | |
| CommandCost | TunnelBridgeIsFree (TileIndex tile, TileIndex endtile, const Vehicle *ignore) |
| Finds vehicle in tunnel / bridge. | |
| 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, int old_x, int old_y) |
| void | ResetVehicleHash () |
| void | ResetVehicleColourMap () |
| void | InitializeVehicles () |
| uint | CountVehiclesInChain (const Vehicle *v) |
| static void | VehicleEnteredDepotThisTick (Vehicle *v) |
| Adds a vehicle to the list of vehicles that visited a depot this tick. | |
| void | RunVehicleCalendarDayProc () |
| Age all vehicles, spreading out the action using the current TimerGameCalendar::date_fract. | |
| static void | RunEconomyVehicleDayProc () |
| 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) |
| Periodic check for a vehicle to maybe break down. | |
| void | EconomyAgeVehicle (Vehicle *v) |
| Update economy age of a vehicle. | |
| void | AgeVehicle (Vehicle *v) |
| Update age of a vehicle. | |
| uint8_t | 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. | |
| 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) |
| VehicleEnterTileStates | 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, uint8_t subtype) |
| 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, uint8_t 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. | |
| static bool | PreviousOrderIsUnbunching (const Vehicle *v) |
| Check if the previous order is a depot unbunching order. | |
| static void | SpawnAdvancedVisualEffect (const Vehicle *v) |
| Call CBID_VEHICLE_SPAWN_VISUAL_EFFECT and spawn requested effects. | |
| static bool | IsBridgeAboveVehicle (const Vehicle *v) |
| Test if a bridge is above a vehicle. | |
| 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? | |
| StringID | GetVehicleCannotUseStationReason (const Vehicle *v, const Station *st) |
| Get reason string why this station can't be used by the given vehicle. | |
| void | GetVehicleSet (VehicleSet &set, Vehicle *v, uint8_t num_vehicles) |
| Calculates the set of vehicles that will be affected by a given selection. | |
| bool | VehiclesHaveSameEngineList (const Vehicle *v1, const Vehicle *v2) |
| Checks if two vehicle chains have the same list of engines. | |
| bool | VehiclesHaveSameOrderList (const Vehicle *v1, const Vehicle *v2) |
| Checks if two vehicles have the same list of orders. | |
Variables | |
| VehiclePool | _vehicle_pool ("Vehicle") |
| The pool with all our precious vehicles. | |
| constexpr uint | TILE_HASH_RES = 0 |
| Resolution of the hash, 0 = 1*1 tile, 1 = 2*2 tiles, 2 = 4*4 tiles, etc. | |
| static std::array< Vehicle *, TOTAL_TILE_HASH_SIZE > | _vehicle_tile_hash {} |
| static std::array< Vehicle *, 1<<(GEN_HASHX_BITS+GEN_HASHY_BITS)> | _vehicle_viewport_hash {} |
| static AutoreplaceMap | _vehicles_to_autoreplace |
| static const uint8_t | _breakdown_chance [64] |
| static const Direction | _new_direction_table [] |
| static const int8_t | _vehicle_smoke_pos [8] |
| static const IntervalTimer< TimerGameEconomy > | _economy_vehicles_yearly ({TimerGameEconomy::Trigger::Year, TimerGameEconomy::Priority::Vehicle}, [](auto) { for(Vehicle *v :Vehicle::Iterate()) { if(v->IsPrimaryVehicle()) { Money profit=v->GetDisplayProfitThisYear();if(v->economy_age >=VEHICLE_PROFIT_MIN_AGE &&profit< 0) { if(_settings_client.gui.vehicle_income_warn &&v->owner==_local_company) { AddVehicleAdviceNewsItem(AdviceType::VehicleUnprofitable, GetEncodedString(TimerGameEconomy::UsingWallclockUnits() ? STR_NEWS_VEHICLE_UNPROFITABLE_PERIOD :STR_NEWS_VEHICLE_UNPROFITABLE_YEAR, v->index, profit), v->index);} AI::NewEvent(v->owner, new ScriptEventVehicleUnprofitable(v->index));} v->profit_last_year=v->profit_this_year;v->profit_this_year=0;SetWindowDirty(WC_VEHICLE_DETAILS, v->index);} } GroupStatistics::UpdateProfits();SetWindowClassesDirty(WC_TRAINS_LIST);SetWindowClassesDirty(WC_SHIPS_LIST);SetWindowClassesDirty(WC_ROADVEH_LIST);SetWindowClassesDirty(WC_AIRCRAFT_LIST);}) |
| static const uint | GEN_HASHX_BITS = 6 |
| static const uint | GEN_HASHY_BITS = 6 |
| static const uint | GEN_HASHX_BUCKET_BITS = 7 |
| static const uint | GEN_HASHY_BUCKET_BITS = 6 |
| static const uint | GEN_HASHX_SIZE = 1 << (GEN_HASHX_BUCKET_BITS + GEN_HASHX_BITS + ZOOM_BASE_SHIFT) |
| static const uint | GEN_HASHY_SIZE = 1 << (GEN_HASHY_BUCKET_BITS + GEN_HASHY_BITS + ZOOM_BASE_SHIFT) |
| static const uint | GEN_HASHX_INC = 1 |
| static const uint | GEN_HASHY_INC = 1 << GEN_HASHX_BITS |
| static const uint | GEN_HASHX_MASK = (1 << GEN_HASHX_BITS) - 1 |
| static const uint | GEN_HASHY_MASK = ((1 << GEN_HASHY_BITS) - 1) << GEN_HASHX_BITS |
| constexpr uint | TILE_HASH_BITS = 7 |
| constexpr uint | TILE_HASH_SIZE = 1 << TILE_HASH_BITS |
| constexpr uint | TILE_HASH_MASK = TILE_HASH_SIZE - 1 |
| constexpr uint | TOTAL_TILE_HASH_SIZE = 1 << (TILE_HASH_BITS * 2) |
Base implementations of all vehicles.
Definition in file vehicle.cpp.
| using AutoreplaceMap = std::map<VehicleID, bool> |
List of vehicles that should check for autoreplace this tick.
Mapping of vehicle -> leave depot immediately after autoreplace.
Definition at line 694 of file vehicle.cpp.
| void AgeVehicle | ( | Vehicle * | v | ) |
Update age of a vehicle.
| v | Vehicle to update. |
Definition at line 1454 of file vehicle.cpp.
References _local_company, _settings_client, AddVehicleAdviceNewsItem(), Vehicle::age, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Engine::company_avail, TimerGame< struct Calendar >::DateAtStartOfYear(), TimerGameConst< struct Calendar >::DAYS_IN_LEAP_YEAR, CompanySettings::engine_renew, Vehicle::engine_type, EngineHasReplacementForCompany(), SpecializedVehicle< Train, Type >::From(), GetEncodedString(), Vehicle::GetEngine(), Vehicle::group_id, Vehicle::IsPrimaryVehicle(), Vehicle::max_age, TimerGameConst< struct Calendar >::MAX_DATE, Vehicle::owner, Vehicle::Previous(), Vehicle::reliability_spd_dec, CompanyProperties::settings, SetWindowDirty(), BaseVehicle::type, VEH_TRAIN, VehicleOld, Vehicle::vehstatus, and WC_VEHICLE_DETAILS.
Referenced by Aircraft::OnNewCalendarDay(), RoadVehicle::OnNewCalendarDay(), Ship::OnNewCalendarDay(), and Train::OnNewCalendarDay().
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 1505 of file vehicle.cpp.
References Vehicle::cargo, Vehicle::cargo_cap, Vehicle::cargo_type, CargoUnloading, CeilDiv(), Vehicle::current_order, SpecializedStation< Station, false >::GetIfValid(), Order::GetLoadType(), Station::goods, Order::IsFullLoadOrder(), Order::IsType(), Vehicle::last_station_visited, LoadingFinished, Vehicle::Next(), NoLoad, StopLoading, VehicleCargoList::StoredCount(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and BaseConsist::vehicle_flags.
Referenced by AfterLoadVehiclesPhase2(), Vehicle::LeaveStation(), LoadUnloadVehicle(), and ProcessConditionalOrder().
| void CallVehicleTicks | ( | ) |
Definition at line 983 of file vehicle.cpp.
| bool CanBuildVehicleInfrastructure | ( | VehicleType | type, |
| uint8_t | subtype ) |
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 |
| subtype | The vehicle's sub to to check this for. |
Definition at line 1944 of file vehicle.cpp.
References _local_company, _settings_game, SpecializedVehicle< RoadVehicle, Type >::From(), HasAnyRailTypesAvail(), HasAnyRoadTypesAvail(), IsCompanyBuildableVehicleType(), Engine::IterateType(), Vehicle::owner, RoadVehicleInfo::roadtype, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Referenced by BuildAirToolbarWindow::OnInvalidateData(), BuildDocksToolbarWindow::OnInvalidateData(), BuildRailToolbarWindow::OnInvalidateData(), BuildRoadToolbarWindow::OnInvalidateData(), and BuildRailToolbarWindow::OnTooltip().
Can this station be used by the given vehicle?
| v | the vehicle to test |
| st | the station to test for |
Definition at line 3122 of file vehicle.cpp.
References CanVehicleUseStation(), Vehicle::engine_type, SpecializedVehicle< RoadVehicle, Type >::From(), BaseVehicle::type, and VEH_ROAD.
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 3089 of file vehicle.cpp.
References AIR_CTOL, AirportFTAClass::Airplanes, Airport, Station::airport, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), BusStop, CanVehicleUseStation(), Dock, BaseStation::facilities, AirportFTAClass::flags, Airport::GetFTA(), AirportFTAClass::Helicopters, AircraftVehicleInfo::subtype, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Train, TruckStop, Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Referenced by AircraftEventHandler_Flying(), CanVehicleUseStation(), CanVehicleUseStation(), CheckOrders(), CmdBuildAircraft(), CmdCloneOrder(), CmdInsertOrder(), DrawOrderString(), Aircraft::FindClosestDepot(), BuildVehicleWindow::GenerateBuildAircraftList(), RoadVehicle::GetOrderStationLocation(), Ship::GetOrderStationLocation(), and UpdateAirplanesOnNewStation().
Find the vehicle close to the clicked coordinates.
| vp | Viewport clicked in. |
| x | X coordinate in the viewport. |
| y | Y coordinate in the viewport. |
nullptr if none found. Definition at line 1244 of file vehicle.cpp.
References abs(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Vehicle::coord, GEN_HASHX_INC, GEN_HASHX_MASK, GEN_HASHY_INC, GEN_HASHY_MASK, Vehicle::hash_viewport_next, Viewport::height, IsInsideMM(), Viewport::left, MAX_VEHICLE_PIXEL_X, MAX_VEHICLE_PIXEL_Y, ScaleByZoom(), Viewport::top, Vehicle::vehstatus, Viewport::virtual_left, Viewport::virtual_top, Viewport::width, and Viewport::zoom.
| void CheckVehicleBreakdown | ( | Vehicle * | v | ) |
Periodic check for a vehicle to maybe break down.
| v | The vehicle to consider breaking. |
Definition at line 1320 of file vehicle.cpp.
References _settings_game, Vehicle::breakdown_chance, Vehicle::breakdown_ctr, Vehicle::breakdown_delay, Chance16I(), ClampTo(), Vehicle::cur_speed, Vehicle::current_order, GB(), Order::IsType(), Vehicle::reliability, Vehicle::reliability_spd_dec, SetWindowDirty(), Stopped, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), BaseVehicle::type, VEH_SHIP, Vehicle::vehstatus, and WC_VEHICLE_DETAILS.
Referenced by Aircraft::OnNewEconomyDay(), RoadVehicle::OnNewEconomyDay(), Ship::OnNewEconomyDay(), and Train::OnNewEconomyDay().
|
inlinestatic |
Compose two 1D hashes into 2D hash.
| hx | The hash for the X-axis. |
| hy | The hash for the Y-axis. |
Definition at line 435 of file vehicle.cpp.
References TILE_HASH_BITS.
Referenced by GetTileHash(), VehiclesNearTileXY::Iterator::Iterator(), and VehiclesNearTileXY::Iterator::SkipEmptyBuckets().
| uint CountVehiclesInChain | ( | const Vehicle * | v | ) |
Definition at line 703 of file vehicle.cpp.
| void DecreaseVehicleValue | ( | Vehicle * | v | ) |
Decrease the value of a vehicle.
| v | Vehicle to devaluate. |
Definition at line 1299 of file vehicle.cpp.
References SetWindowDirty(), Vehicle::value, and WC_VEHICLE_DETAILS.
Referenced by Aircraft::OnNewEconomyDay(), RoadVehicle::OnNewEconomyDay(), Ship::OnNewEconomyDay(), and Train::OnNewEconomyDay().
|
static |
Add vehicle sprite for drawing to the screen.
| v | Vehicle to draw. |
Definition at line 1121 of file vehicle.cpp.
References AddSortableSpriteToDraw(), Vehicle::bounds, Crashed, DefaultPalette, EndSpriteCombine(), SpecializedVehicle< EffectVehicle, VEH_EFFECT >::From(), EffectVehicle::GetTransparencyOption(), GetVehiclePalette(), IsInvisibilitySet(), IsTransparencySet(), PALETTE_CRASH, Shadow, Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, StartSpriteCombine(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TO_INVALID, BaseVehicle::type, VEH_EFFECT, Vehicle::vehstatus, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.
Referenced by ViewportAddVehicles().
| void EconomyAgeVehicle | ( | Vehicle * | v | ) |
Update economy age of a vehicle.
| v | Vehicle to update. |
Definition at line 1442 of file vehicle.cpp.
References Vehicle::economy_age, Vehicle::IsPrimaryVehicle(), TimerGameConst< struct Economy >::MAX_DATE, VEHICLE_PROFIT_MIN_AGE, and GroupStatistics::VehicleReachedMinAge().
Referenced by Aircraft::OnNewEconomyDay(), RoadVehicle::OnNewEconomyDay(), Ship::OnNewEconomyDay(), and Train::OnNewEconomyDay().
| 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 604 of file vehicle.cpp.
References SpecializedVehicle< Train, Type >::From(), Train::track, TracksOverlap(), and VEH_TRAIN.
Referenced by CmdConvertRail(), 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 556 of file vehicle.cpp.
References AIR_SHADOW, GetTileMaxPixelZ(), VEH_AIRCRAFT, and VEH_DISASTER.
Referenced by CheckBuildableTile(), CheckIfIndustryTilesAreFree(), ClearTile_Rail(), ClearTile_Water(), CmdBuildObject(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdBuildTrainDepot(), CmdConvertRail(), CmdConvertRoad(), CmdRemoveSingleRail(), DoBuildLock(), IsValidTileForWaypoint(), RemoveAirport(), RemoveBuoy(), RemoveDock(), RemoveFromRailBaseStation(), RemoveLock(), RemoveRoad(), RemoveRoadStop(), RemoveRoadWaypointStop(), and TileLoop_Road().
Definition at line 1829 of file vehicle.cpp.
|
static |
Definition at line 2115 of file vehicle.cpp.
| const Livery * GetEngineLivery | ( | EngineID | engine_type, |
| CompanyID | company, | ||
| EngineID | parent_engine_type, | ||
| const Vehicle * | v, | ||
| uint8_t | livery_setting ) |
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. VehicleID::Invalid() if vehicle is at front itself. |
| v | the vehicle. nullptr if in purchase list etc. |
| livery_setting | The livery settings to use for acquiring the livery information. |
Definition at line 2086 of file vehicle.cpp.
References _local_company, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Vehicle::First(), GetEngineLiveryScheme(), Vehicle::group_id, Livery::in_use, LIT_ALL, LIT_COMPANY, Group::livery, and Group::parent.
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, EngineID::Invalid() if vehicle is at front itself. |
| v | the vehicle, nullptr if in purchase list etc. |
Definition at line 1992 of file vehicle.cpp.
References AIR_CTOL, Vehicle::cargo_type, EC_DIESEL, EC_ELECTRIC, EC_MAGLEV, EC_MONORAIL, EC_STEAM, RailVehicleInfo::engclass, Vehicle::First(), CargoSpec::Get(), Engine::GetDefaultCargoType(), Vehicle::IsArticulatedPart(), IsCargoInClass(), IsValidCargoType(), EngineInfo::misc_flags, Passengers, RailIsMU, RAILVEH_WAGON, RoadIsTram, AircraftVehicleInfo::subtype, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Engine::type, 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 2164 of file vehicle.cpp.
Referenced by DrawEngineList(), EnginePreviewWindow::DrawWidget(), and NewsWindow::DrawWidget().
| UnitID GetFreeUnitNumber | ( | VehicleType | type | ) |
Get an unused unit number for a vehicle (if allowed).
| type | Type of vehicle |
UINT16_MAX. Definition at line 1916 of file vehicle.cpp.
References _current_company, _settings_game, Company::group_all, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
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 1805 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().
|
inlinestatic |
Compute hash for tile coordinate.
| x | The X-coordinate. |
| y | The Y-coordinate. |
Definition at line 446 of file vehicle.cpp.
References ComposeTileHash(), and GetTileHash1D().
Referenced by VehiclesOnTile::Iterator::Iterator().
|
inlinestatic |
Compute hash for 1D tile coordinate.
| p | The value to 'hash'. |
Definition at line 414 of file vehicle.cpp.
References GB(), TILE_HASH_BITS, and TILE_HASH_RES.
Referenced by GetTileHash(), and VehiclesNearTileXY::Iterator::Iterator().
Get reason string why this station can't be used by the given vehicle.
| v | The vehicle to test. |
| st | The station to test for. |
Definition at line 3135 of file vehicle.cpp.
References AIR_CTOL, Airport, Bus, RoadVehicle::compatible_roadtypes, BaseStation::facilities, SpecializedVehicle< RoadVehicle, Type >::From(), Vehicle::GetEngine(), Vehicle::HasArticulatedPart(), HasTileAnyRoadType(), INVALID_STRING_ID, IsBayRoadStopTile(), RoadVehicle::IsBus(), RoadStop::next, RoadVehicle::roadtype, AircraftVehicleInfo::subtype, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Truck, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and RoadStop::xy.
Referenced by CmdCloneOrder(), and CmdInsertOrder().
Get the colour map for a vehicle.
| v | Vehicle to get colour map for |
Definition at line 2174 of file vehicle.cpp.
References Vehicle::engine_type, GroundVehicleCache::first_engine, Vehicle::GetGroundVehicleCache(), Vehicle::IsGroundVehicle(), and Vehicle::owner.
Referenced by DoDrawVehicle(), DrawAircraftImage(), DrawRoadVehImage(), DrawShipImage(), DrawTrainDetails(), DrawTrainImage(), and SetMouseCursorVehicle().
| void GetVehicleSet | ( | VehicleSet & | set, |
| Vehicle * | v, | ||
| uint8_t | num_vehicles ) |
Calculates the set of vehicles that will be affected by a given selection.
| [in,out] | set | 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 3249 of file vehicle.cpp.
References SpecializedVehicle< Train, Type >::From(), SpecializedVehicle< T, Type >::GetFirstEnginePart(), include(), Vehicle::IsArticulatedPart(), GroundVehicle< T, Type >::IsMultiheaded(), SpecializedVehicle< T, Type >::Next(), Train::other_multiheaded_part, BaseVehicle::type, and VEH_TRAIN.
Referenced by RefitWindow::BuildRefitList(), RefitWindow::DrawWidget(), and RefitVehicle().
|
inlinestatic |
Definition at line 91 of file vehicle.cpp.
|
inlinestatic |
Definition at line 81 of file vehicle.cpp.
|
inlinestatic |
Definition at line 86 of file vehicle.cpp.
|
inlinestatic |
Increment 1D hash to next bucket.
| h | The value to increment the hash for. |
Definition at line 424 of file vehicle.cpp.
References TILE_HASH_MASK.
Referenced by VehiclesNearTileXY::Iterator::SkipEmptyBuckets().
| void InitializeVehicles | ( | ) |
Definition at line 697 of file vehicle.cpp.
|
static |
Test if a bridge is above a vehicle.
| v | Vehicle to test. |
Definition at line 2805 of file vehicle.cpp.
References IsBridgeAbove(), IsBridgeTile(), Vehicle::tile, TileVirtXY(), Vehicle::x_pos, and Vehicle::y_pos.
Referenced by Vehicle::ShowVisualEffect().
|
static |
Check if the previous order is a depot unbunching order.
| v | The vehicle to consider. |
true iff the previous order is a depot order with the unbunch flag. Definition at line 2516 of file vehicle.cpp.
References BaseConsist::cur_implicit_order_index, Order::GetDepotActionType(), Vehicle::GetFirstOrder(), Vehicle::GetLastOrder(), Vehicle::GetOrder(), Order::IsType(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Unbunch.
Referenced by Vehicle::IsWaitingForUnbunching(), and Vehicle::LeaveUnbunchingDepot().
| void ResetVehicleColourMap | ( | ) |
Definition at line 685 of file vehicle.cpp.
| void ResetVehicleHash | ( | ) |
Definition at line 678 of file vehicle.cpp.
|
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 == TimerGameEconomy::date_fract", so each day, all vehicles are processes in DAY_TICKS steps.
Definition at line 953 of file vehicle.cpp.
References Callback32, CALLBACK_FAILED, CBID_VEHICLE_32DAY_CALLBACK, TimerGameEconomy::date_fract, Vehicle::day_counter, Ticks::DAY_TICKS, Vehicle::engine_type, ErrorUnknownCallbackResult(), Vehicle::First(), Vehicle::GetGRFID(), GetVehicleCallback(), HasBit(), Vehicle::HasEngineType(), Vehicle::MarkDirty(), and Vehicle::OnNewEconomyDay().
| void RunVehicleCalendarDayProc | ( | ) |
Age all vehicles, spreading out the action using the current TimerGameCalendar::date_fract.
Definition at line 936 of file vehicle.cpp.
References TimerGameCalendar::date_fract, Ticks::DAY_TICKS, and Vehicle::OnNewCalendarDay().
Referenced by StateGameLoop().
| void ShowNewGrfVehicleError | ( | EngineID | engine, |
| StringID | part1, | ||
| StringID | part2, | ||
| GRFBug | 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 337 of file vehicle.cpp.
References _networking, Debug, Error, Execute, GetEncodedString(), GetGRFConfig(), Engine::GetGRFID(), GRFConfig::GetName(), GetString(), GRFConfig::grf_bugs, Normal, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), ShowErrorMessage(), StrMakeValid(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and WL_CRITICAL.
Referenced by CheckConsistencyOfArticulatedVehicle(), Train::ConsistChanged(), Vehicle::UpdateVisualEffect(), and VehicleLengthChanged().
|
static |
Call CBID_VEHICLE_SPAWN_VISUAL_EFFECT and spawn requested effects.
| v | Vehicle to create effects for. |
Definition at line 2747 of file vehicle.cpp.
References GroundVehicleCache::cached_veh_length, CALLBACK_FAILED, CBID_VEHICLE_SPAWN_VISUAL_EFFECT, ChangeDir(), CreateEffectVehicleRel(), DIRDIFF_90RIGHT, Vehicle::direction, Vehicle::engine_type, EV_BREAKDOWN_SMOKE_AIRCRAFT, EV_DIESEL_SMOKE, EV_ELECTRIC_SPARK, EV_STEAM_SMOKE, Flipped, SpecializedVehicle< RoadVehicle, Type >::From(), SpecializedVehicle< Train, Type >::From(), GB(), GroundVehicle< T, Type >::gcache, GetVehicleCallback(), HasBit(), ReverseDir(), BaseVehicle::type, VEH_ROAD, VEH_TRAIN, and VEHICLE_LENGTH.
Referenced by Vehicle::ShowVisualEffect().
| 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 580 of file vehicle.cpp.
References VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Referenced by ClearPathReservation(), CmdBuildRoad(), CmdConvertRail(), CmdConvertRoad(), DoClearBridge(), DoClearTunnel(), and RemoveRoad().
|
static |
Definition at line 621 of file vehicle.cpp.
|
static |
Definition at line 654 of file vehicle.cpp.
| 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 1564 of file vehicle.cpp.
References _current_company, _local_company, _settings_client, AddVehicleAdviceNewsItem(), CCF_ARRANGE, Clamp(), ClampTo(), Train::ConsistChanged(), TimerGameTick::counter, BaseConsist::cur_real_order_index, Vehicle::cur_speed, Vehicle::current_order, Vehicle::DeleteUnreachedImplicitOrders(), Depot, BaseConsist::depot_unbunching_last_departure, Vehicle::dest_tile, Execute, CommandCost::Failed(), Vehicle::First(), Train::flags, Train::force_proceed, SpecializedVehicle< Aircraft, VEH_AIRCRAFT >::From(), SpecializedVehicle< Ship, VEH_SHIP >::From(), SpecializedVehicle< Train, Type >::From(), CommandCost::GetCost(), Order::GetDepotActionType(), Order::GetDepotOrderType(), Order::GetDestination(), GetEncodedString(), Vehicle::GetOrder(), Order::GetRefitCargo(), GetStationIndex(), Halt, HandleAircraftEnterHangar(), Hidden, Vehicle::IncrementImplicitOrderIndex(), INVALID_DIAGDIR, InvalidateWindowData(), Order::IsRefit(), Order::IsType(), Vehicle::last_loading_station, Order::MakeDummy(), Vehicle::MarkDirty(), MarkTileDirtyByTile(), NearestDepot, AI::NewEvent(), Vehicle::owner, PartOfOrders, Vehicle::profit_this_year, RefitFailed, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), BaseConsist::ResetDepotUnbunching(), Backup< T >::Restore(), Reversed, BaseConsist::round_trip_time, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetDepotReservation(), SetWindowClassesDirty(), SetWindowDirty(), ShowCostOrIncomeAnimation(), Ship::state, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TFP_NONE, Vehicle::tile, TRACK_BIT_DEPOT, BaseVehicle::type, Unbunch, Ship::UpdateCache(), UpdateSignalsOnSegment(), UpdateVehicleTimetable(), SpecializedVehicle< T, Type >::UpdateViewport(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, VehicleEnteredDepotThisTick(), VehicleServiceInDepot(), VehicleWaiting, Vehicle::vehstatus, 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(), CheckShipStayInDepot(), CheckTrainStayInDepot(), VehicleEnterTile_Rail(), and VehicleEnterTile_Road().
|
static |
Adds a vehicle to the list of vehicles that visited a depot this tick.
| *v | vehicle to add |
Definition at line 920 of file vehicle.cpp.
References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), Stopped, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Vehicle::vehstatus.
Referenced by VehicleEnterDepot().
Call the tile callback function for a vehicle entering a tile.
Definition at line 1859 of file vehicle.cpp.
References _tile_type_procs, and GetTileType().
Referenced by TrainController(), and UpdateStatusAfterSwap().
| 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 363 of file vehicle.cpp.
References _gamelog, Vehicle::engine_type, Vehicle::GetEngine(), GetGRFConfig(), GRFConfig::grf_bugs, Engine::grf_prop, GRFFilePropsBase::grfid, GRFFilePropsBase::local_id, ShowNewGrfVehicleError(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and VehLength.
Referenced by Train::ConsistChanged(), and RoadVehUpdateCache().
| void VehicleServiceInDepot | ( | Vehicle * | v | ) |
Service a vehicle and all subsequent vehicles in the consist.
| *v | The vehicle or vehicle chain being serviced |
Definition at line 187 of file vehicle.cpp.
References _settings_game, Vehicle::breakdown_chance, Vehicle::breakdowns_since_last_service, TimerGameCalendar::date, TimerGameEconomy::date, Vehicle::date_of_last_service, Vehicle::date_of_last_service_newgrf, Vehicle::GetEngine(), Vehicle::HasEngineType(), Vehicle::Next(), Engine::reliability, Vehicle::reliability, SetWindowDirty(), and WC_VEHICLE_DETAILS.
Referenced by AircraftLeaveHangar(), CheckIfTrainNeedsService(), CheckShipStayInDepot(), CheckTrainStayInDepot(), and VehicleEnterDepot().
Checks if two vehicle chains have the same list of engines.
| v1 | First vehicle chain. |
| v2 | Second vehicle chain. |
Definition at line 3303 of file vehicle.cpp.
References Vehicle::GetEngine(), and Vehicle::GetNextVehicle().
Referenced by DepotWindow::OnVehicleSelect().
Checks if two vehicles have the same list of orders.
| v1 | First vehicles. |
| v2 | Second vehicles. |
Definition at line 3320 of file vehicle.cpp.
Referenced by DepotWindow::OnVehicleSelect(), and OrdersWindow::OnVehicleSelect().
| 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 1150 of file vehicle.cpp.
References Vehicle::coord, Vehicle::direction, DoDrawVehicle(), EIT_ON_MAP, GEN_HASHX_INC, GEN_HASHX_MASK, GEN_HASHX_SIZE, GEN_HASHY_INC, GEN_HASHY_MASK, GEN_HASHY_SIZE, Vehicle::GetImage(), Vehicle::hash_viewport_next, Hidden, VehicleSpriteSeq::IsValid(), MAX_VEHICLE_PIXEL_X, MAX_VEHICLE_PIXEL_Y, MutableSpriteCache::revalidate_before_draw, Vehicle::sprite_cache, MutableSpriteCache::sprite_seq, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::UpdateBoundingBoxCoordinates(), and Vehicle::vehstatus.
|
static |
Definition at line 1305 of file vehicle.cpp.
|
static |
Definition at line 1823 of file vehicle.cpp.
|
static |
Definition at line 2739 of file vehicle.cpp.
|
static |
Definition at line 451 of file vehicle.cpp.
|
static |
Definition at line 652 of file vehicle.cpp.
|
static |
Definition at line 695 of file vehicle.cpp.
|
static |
Number of bits in the hash to use from each vehicle coord.
Definition at line 70 of file vehicle.cpp.
|
static |
Size of each hash bucket.
Definition at line 76 of file vehicle.cpp.
|
static |
Increments to reach next bucket in hash table.
Definition at line 104 of file vehicle.cpp.
Referenced by CheckClickOnVehicle(), and ViewportAddVehicles().
|
static |
Mask to wrap-around buckets.
Definition at line 110 of file vehicle.cpp.
Referenced by CheckClickOnVehicle(), and ViewportAddVehicles().
|
static |
Maximum size until hash repeats.
Definition at line 98 of file vehicle.cpp.
Referenced by ViewportAddVehicles().
|
static |
Number of bits in the hash to use from each vehicle coord.
Definition at line 71 of file vehicle.cpp.
|
static |
Size of each hash bucket.
Definition at line 77 of file vehicle.cpp.
|
static |
Increments to reach next bucket in hash table.
Definition at line 105 of file vehicle.cpp.
Referenced by CheckClickOnVehicle(), and ViewportAddVehicles().
|
static |
Mask to wrap-around buckets.
Definition at line 111 of file vehicle.cpp.
Referenced by CheckClickOnVehicle(), and ViewportAddVehicles().
|
static |
Maximum size until hash repeats.
Definition at line 99 of file vehicle.cpp.
Referenced by ViewportAddVehicles().
|
constexpr |
Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash lookup times at the expense of memory usage.
Definition at line 397 of file vehicle.cpp.
Referenced by ComposeTileHash(), and GetTileHash1D().
|
constexpr |
Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash lookup times at the expense of memory usage.
Definition at line 399 of file vehicle.cpp.
Referenced by IncTileHash1D(), and VehiclesNearTileXY::Iterator::Iterator().
|
constexpr |
Resolution of the hash, 0 = 1*1 tile, 1 = 2*2 tiles, 2 = 4*4 tiles, etc.
Profiling results show that 0 is fastest.
Definition at line 407 of file vehicle.cpp.
Referenced by GetTileHash1D().
|
constexpr |
Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash lookup times at the expense of memory usage.
Definition at line 398 of file vehicle.cpp.
|
constexpr |
Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash lookup times at the expense of memory usage.
Definition at line 400 of file vehicle.cpp.