|
OpenTTD Source 20251116-master-g21329071df
|
Handling of road vehicles. More...
#include "stdafx.h"#include "roadveh.h"#include "command_func.h"#include "error_func.h"#include "news_func.h"#include "station_base.h"#include "company_func.h"#include "articulated_vehicles.h"#include "newgrf_sound.h"#include "pathfinder/yapf/yapf.h"#include "strings_func.h"#include "tunnelbridge_map.h"#include "timer/timer_game_calendar.h"#include "timer/timer_game_economy.h"#include "vehicle_func.h"#include "sound_func.h"#include "ai/ai.hpp"#include "game/game.hpp"#include "depot_map.h"#include "effectvehicle_func.h"#include "roadstop_base.h"#include "core/random_func.hpp"#include "company_base.h"#include "core/backup_type.hpp"#include "newgrf.h"#include "zoom_func.h"#include "framerate_type.h"#include "roadveh_cmd.h"#include "road_cmd.h"#include "newgrf_roadstop.h"#include "table/strings.h"#include "safeguards.h"#include "table/roadveh_movement.h"Go to the source code of this file.
Data Structures | |
| struct | RoadVehFindData |
| struct | OvertakeData |
| struct | RoadDriveEntry |
Macros | |
| #define | return_track(x) { best_track = (Trackdir)x; goto found_best_track; } |
Functions | |
| template<> | |
| bool | IsValidImageIndex< VEH_ROAD > (uint8_t image_index) |
| static void | GetRoadVehIcon (EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result) |
| void | DrawRoadVehEngine (int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type) |
| Draw a road vehicle engine. | |
| void | GetRoadVehSpriteSize (EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type) |
| Get the size of the sprite of a road vehicle sprite heading west (used for lists). | |
| static uint | GetRoadVehLength (const RoadVehicle *v) |
| Get length of a road vehicle. | |
| void | RoadVehUpdateCache (RoadVehicle *v, bool same_length) |
| Update the cache of a road vehicle. | |
| CommandCost | CmdBuildRoadVehicle (DoCommandFlags flags, TileIndex tile, const Engine *e, Vehicle **ret) |
| Build a road vehicle. | |
| static FindDepotData | FindClosestRoadDepot (const RoadVehicle *v, int max_distance) |
| CommandCost | CmdTurnRoadVeh (DoCommandFlags flags, VehicleID veh_id) |
| Turn a roadvehicle around. | |
| static void | DeleteLastRoadVeh (RoadVehicle *v) |
| Delete last vehicle of a chain road vehicles. | |
| static void | RoadVehSetRandomDirection (RoadVehicle *v) |
| static bool | RoadVehIsCrashed (RoadVehicle *v) |
| Road vehicle chain has crashed. | |
| static void | RoadVehCrash (RoadVehicle *v) |
| static bool | RoadVehCheckTrainCrash (RoadVehicle *v) |
| static void | StartRoadVehSound (const RoadVehicle *v) |
| static void | FindClosestBlockingRoadVeh (Vehicle *v, RoadVehFindData *rvf) |
| static RoadVehicle * | RoadVehFindCloseTo (RoadVehicle *v, int x, int y, Direction dir, bool update_blocked_ctr=true) |
| static void | RoadVehArrivesAt (const RoadVehicle *v, Station *st) |
| A road vehicle arrives at a station. | |
| static Direction | RoadVehGetNewDirection (const RoadVehicle *v, int x, int y) |
| static Direction | RoadVehGetSlidingDirection (const RoadVehicle *v, int x, int y) |
| static bool | CheckRoadBlockedForOvertaking (OvertakeData *od) |
| Check if overtaking is possible on a piece of track. | |
| static void | RoadVehCheckOvertake (RoadVehicle *v, RoadVehicle *u) |
| static void | RoadZPosAffectSpeed (RoadVehicle *v, int old_z) |
| static int | PickRandomBit (uint bits) |
| static Trackdir | RoadFindPathToDest (RoadVehicle *v, TileIndex tile, DiagDirection enterdir) |
| Returns direction to for a road vehicle to take or INVALID_TRACKDIR if the direction is currently blocked. | |
| bool | RoadVehLeaveDepot (RoadVehicle *v, bool first) |
| static Trackdir | FollowPreviousRoadVehicle (const RoadVehicle *v, const RoadVehicle *prev, TileIndex tile, DiagDirection entry_dir, bool already_reversed) |
| static bool | CanBuildTramTrackOnTile (CompanyID c, TileIndex t, RoadType rt, RoadBits r) |
| Can a tram track build without destruction on the given tile? | |
| bool | IndividualRoadVehicleController (RoadVehicle *v, const RoadVehicle *prev) |
| static bool | RoadVehController (RoadVehicle *v) |
| static void | CheckIfRoadVehNeedsService (RoadVehicle *v) |
Variables | |
| static const uint16_t | _roadveh_images [] |
| static const uint16_t | _roadveh_full_adder [] |
| static const Trackdir | _road_reverse_table [DIAGDIR_END] |
Handling of road vehicles.
Definition in file roadveh_cmd.cpp.
Can a tram track build without destruction on the given tile?
| c | the company that would be building the tram tracks |
| t | the tile to build on. |
| rt | the tram type to build. |
| r | the road bits needed. |
Definition at line 1132 of file roadveh_cmd.cpp.
References _current_company, DRD_NONE, NoWater, Backup< T >::Restore(), and CommandCost::Succeeded().
|
static |
Definition at line 1676 of file roadveh_cmd.cpp.
|
static |
Check if overtaking is possible on a piece of track.
| od | Information about the tile and the involved vehicles |
Definition at line 790 of file roadveh_cmd.cpp.
References RoadVehicle::compatible_roadtypes, GetTileTrackStatus(), HasBit(), HasTileAnyRoadType(), HasVehicleOnTile(), RoadVehicle::roadtype, TRACK_BIT_CROSS, TRACKDIR_BIT_NONE, TrackdirBitsToTrackBits(), TrackStatusToRedSignals(), TrackStatusToTrackdirBits(), and TRANSPORT_ROAD.
| CommandCost CmdBuildRoadVehicle | ( | DoCommandFlags | flags, |
| TileIndex | tile, | ||
| const Engine * | e, | ||
| Vehicle ** | ret | ||
| ) |
Build a road vehicle.
| flags | type of operation. | |
| tile | tile of the depot where road vehicle is built. | |
| e | the engine to build. | |
| [out] | ret | the vehicle that has been built. |
Definition at line 262 of file roadveh_cmd.cpp.
References _current_company, _settings_game, AddArticulatedParts(), BuiltAsPrototype, CheckConsistencyOfArticulatedVehicle(), TimerGameCalendar::date, TimerGameEconomy::date, DefaultPalette, DiagDirToDir(), Vehicle::direction, ExclusivePreview, Execute, Engine::flags, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), Engine::GetDefaultCargoType(), Engine::GetLifeLengthInDays(), GetRoadDepotDirection(), GetRoadTypeInfo(), GetSlopePixelZ(), HasTileAnyRoadType(), Hidden, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsValidCargoType(), SpecializedVehicle< T, Type >::Next(), Random, Engine::reliability, Engine::reliability_spd_dec, VehicleSettings::roadveh_acceleration_model, RoadVehUpdateCache(), RVSB_IN_DEPOT, settings, Stopped, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TILE_SIZE, TileX(), TileY(), GameSettings::vehicle, VEHICLE_LENGTH, and TimerGameCalendar::year.
Referenced by CmdBuildVehicle().
| CommandCost CmdTurnRoadVeh | ( | DoCommandFlags | flags, |
| VehicleID | veh_id | ||
| ) |
Turn a roadvehicle around.
| flags | operation to perform |
| veh_id | vehicle ID to turn |
Definition at line 362 of file roadveh_cmd.cpp.
References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Vehicle::breakdown_ctr, CheckOwnership(), CMD_ERROR, Vehicle::current_order, Vehicle::direction, DirToDiagDir(), DRD_NONE, Execute, CommandCost::Failed(), GetDisallowedRoadDirections(), SpecializedVehicle< T, Type >::GetIfValid(), GetTunnelBridgeDirection(), RoadVehicle::IsInDepot(), IsNormalRoadTile(), RoadVehicle::IsPrimaryVehicle(), IsTileType(), Order::IsType(), MP_TUNNELBRIDGE, RoadVehicle::overtaking, Vehicle::owner, BaseConsist::ResetDepotUnbunching(), RVSB_WORMHOLE, RoadVehicle::state, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Vehicle::tile, and Vehicle::vehstatus.
|
static |
Delete last vehicle of a chain road vehicles.
| v | First roadvehicle. |
Definition at line 491 of file roadveh_cmd.cpp.
References SpecializedVehicle< T, Type >::First(), RoadStop::GetByTile(), GetRoadStopType(), IsInsideMM(), Vehicle::last_station_visited, RoadStop::Leave(), SpecializedVehicle< T, Type >::Next(), RVSB_IN_ROAD_STOP, Vehicle::SetNext(), RoadVehicle::state, and Vehicle::tile.
Referenced by RoadVehIsCrashed().
| void DrawRoadVehEngine | ( | int | left, |
| int | right, | ||
| int | preferred_x, | ||
| int | y, | ||
| EngineID | engine, | ||
| PaletteID | pal, | ||
| EngineImageType | image_type | ||
| ) |
Draw a road vehicle engine.
| left | Left edge to draw within. |
| right | Right edge to draw within. |
| preferred_x | Preferred position of the engine. |
| y | Vertical position of the engine. |
| engine | Engine to draw |
| pal | Palette to use. |
Definition at line 149 of file roadveh_cmd.cpp.
References Clamp(), VehicleSpriteSeq::Draw(), VehicleSpriteSeq::GetBounds(), PALETTE_CRASH, and UnScaleGUI().
Referenced by DrawVehicleEngine().
|
static |
Definition at line 627 of file roadveh_cmd.cpp.
|
static |
Definition at line 341 of file roadveh_cmd.cpp.
|
static |
Definition at line 1058 of file roadveh_cmd.cpp.
|
static |
Definition at line 104 of file roadveh_cmd.cpp.
|
static |
Get length of a road vehicle.
| v | Road vehicle to query length. |
Definition at line 191 of file roadveh_cmd.cpp.
References CALLBACK_FAILED, CBID_VEHICLE_LENGTH, Clamp(), Vehicle::engine_type, ErrorUnknownCallbackResult(), Vehicle::GetEngine(), Engine::GetGRF(), Engine::GetGRFID(), GetVehicleCallback(), PROP_ROADVEH_SHORTEN_FACTOR, and VEHICLE_LENGTH.
Referenced by RoadVehUpdateCache().
| void GetRoadVehSpriteSize | ( | EngineID | engine, |
| uint & | width, | ||
| uint & | height, | ||
| int & | xoffs, | ||
| int & | yoffs, | ||
| EngineImageType | image_type | ||
| ) |
Get the size of the sprite of a road vehicle sprite heading west (used for lists).
| engine | The engine to get the sprite from. | |
| [out] | width | The width of the sprite. |
| [out] | height | The height of the sprite. |
| [out] | xoffs | Number of pixels to shift the sprite to the right. |
| [out] | yoffs | Number of pixels to shift the sprite downwards. |
| image_type | Context the sprite is used in. |
Definition at line 172 of file roadveh_cmd.cpp.
References VehicleSpriteSeq::GetBounds(), Rect::Height(), UnScaleGUI(), and Rect::Width().
Referenced by EnginePreviewWindow::UpdateWidgetSize().
| bool IndividualRoadVehicleController | ( | RoadVehicle * | v, |
| const RoadVehicle * | prev | ||
| ) |
Definition at line 1143 of file roadveh_cmd.cpp.
| bool IsValidImageIndex< VEH_ROAD > | ( | uint8_t | image_index | ) |
Definition at line 69 of file roadveh_cmd.cpp.
|
static |
Definition at line 871 of file roadveh_cmd.cpp.
|
static |
Returns direction to for a road vehicle to take or INVALID_TRACKDIR if the direction is currently blocked.
| v | the Vehicle to do the pathfinding for |
| tile | the where to start the pathfinding |
| enterdir | the direction the vehicle enters the tile from |
Definition at line 888 of file roadveh_cmd.cpp.
References _settings_game, AxisToRoadBits(), Bus, Vehicle::dest_tile, DiagdirReachesTrackdirs(), DiagDirToAxis(), DiagDirToRoadBits(), FindFirstBit(), GetAnyRoadBits(), GetBayRoadStopDir(), RoadStop::GetByTile(), GetRoadDepotDirection(), GetRoadStopType(), GetTileTrackStatus(), Vehicle::HandlePathfindingResult(), Vehicle::HasArticulatedPart(), HasBit(), INVALID_TRACKDIR, IsBayRoadStopTile(), RoadVehicle::IsBus(), IsRoadDepot(), IsTileOwner(), IsTileType(), KillFirstBit(), MP_ROAD, MP_STATION, Vehicle::owner, RoadVehicle::path, GameSettings::pf, RoadVehicle::roadtype, PathfinderSettings::roadveh_queue, RTT_TRAM, Vehicle::tile, TRACKDIR_BIT_NONE, TrackStatusToRedSignals(), TrackStatusToTrackdirBits(), TRANSPORT_ROAD, Truck, and YapfRoadVehicleChooseTrack().
|
static |
A road vehicle arrives at a station.
If it is the first time, create a news item.
| v | Road vehicle that arrived. |
| st | Station where the road vehicle arrived. |
Definition at line 701 of file roadveh_cmd.cpp.
References _local_company, AddVehicleNewsItem(), ArrivalCompany, ArrivalOther, GetEncodedString(), HVOT_BUS, HVOT_TRUCK, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, RoadVehicle::IsBus(), Game::NewEvent(), AI::NewEvent(), Vehicle::owner, and RoadVehicle::roadtype.
|
static |
Definition at line 807 of file roadveh_cmd.cpp.
|
static |
Definition at line 573 of file roadveh_cmd.cpp.
|
static |
Definition at line 1573 of file roadveh_cmd.cpp.
|
static |
Definition at line 555 of file roadveh_cmd.cpp.
|
static |
Definition at line 656 of file roadveh_cmd.cpp.
|
static |
Definition at line 751 of file roadveh_cmd.cpp.
|
static |
Definition at line 766 of file roadveh_cmd.cpp.
|
static |
Road vehicle chain has crashed.
| v | First roadvehicle. |
Definition at line 524 of file roadveh_cmd.cpp.
References RoadVehicle::crashed_ctr, CreateEffectVehicleRel(), DeleteLastRoadVeh(), EV_EXPLOSION_LARGE, SpecializedVehicle< T, Type >::Next(), and Vehicle::tick_counter.
| bool RoadVehLeaveDepot | ( | RoadVehicle * | v, |
| bool | first | ||
| ) |
Definition at line 1010 of file roadveh_cmd.cpp.
|
static |
Definition at line 505 of file roadveh_cmd.cpp.
| void RoadVehUpdateCache | ( | RoadVehicle * | v, |
| bool | same_length | ||
| ) |
Update the cache of a road vehicle.
| v | Road vehicle needing an update of its cache. |
| same_length | should length of vehicles stay the same? |
Definition at line 219 of file roadveh_cmd.cpp.
References VehicleCache::cached_max_speed, GroundVehicleCache::cached_total_length, EngineInfo::cargo_age_period, Vehicle::engine_type, GroundVehicle< T, Type >::gcache, GetRoadVehLength(), Vehicle::InvalidateNewGRFCacheOfChain(), Vehicle::IsFrontEngine(), RoadVehicleInfo::max_speed, SpecializedVehicle< T, Type >::Next(), PROP_ROADVEH_CARGO_AGE_PERIOD, PROP_ROADVEH_SPEED, BaseVehicle::type, Vehicle::vcache, VEH_ROAD, and VehicleLengthChanged().
Referenced by AfterLoadVehiclesPhase2(), CheckCaches(), CmdBuildRoadVehicle(), and CmdRefitVehicle().
|
static |
Definition at line 859 of file roadveh_cmd.cpp.
|
static |
Definition at line 607 of file roadveh_cmd.cpp.
|
static |
Definition at line 74 of file roadveh_cmd.cpp.
|
static |
Definition at line 56 of file roadveh_cmd.cpp.
|
static |
Definition at line 45 of file roadveh_cmd.cpp.