Handling of road vehicles. More...
#include "stdafx.h"
#include "roadveh.h"
#include "command_func.h"
#include "news_func.h"
#include "pathfinder/npf/npf_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 "date_func.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 "spritecache.h"
#include "core/random_func.hpp"
#include "company_base.h"
#include "core/backup_type.hpp"
#include "newgrf.h"
#include "zoom_func.h"
#include "table/strings.h"
#include "table/roadveh_movement.h"
Go to the source code of this file.
Data Structures | |
struct | RoadVehFindData |
struct | OvertakeData |
struct | RoadDriveEntry |
Defines | |
#define | MKIT(a, b, c, d) ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0) |
#define | return_track(x) { best_track = (Trackdir)x; goto found_best_track; } |
Functions | |
static SpriteID | GetRoadVehIcon (EngineID engine, EngineImageType image_type) |
void | DrawRoadVehEngine (int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type) |
Draw a road vehicle engine. | |
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 (TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret) |
Build a road vehicle. | |
static FindDepotData | FindClosestRoadDepot (const RoadVehicle *v, int max_distance) |
CommandCost | CmdTurnRoadVeh (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
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 Vehicle * | EnumCheckRoadVehCrashTrain (Vehicle *v, void *data) |
Check routine whether a road and a train vehicle have collided. | |
static void | RoadVehCrash (RoadVehicle *v) |
static bool | RoadVehCheckTrainCrash (RoadVehicle *v) |
static void | StartRoadVehSound (const RoadVehicle *v) |
static Vehicle * | EnumCheckRoadVehClose (Vehicle *v, void *data) |
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 Vehicle * | EnumFindVehBlockingOvertake (Vehicle *v, void *data) |
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, byte 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. | |
static 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, RoadBits r) |
Can a tram track build without destruction on the given tile? | |
static bool | IndividualRoadVehicleController (RoadVehicle *v, const RoadVehicle *prev) |
static bool | RoadVehController (RoadVehicle *v) |
static void | CheckIfRoadVehNeedsService (RoadVehicle *v) |
Variables | |
static const uint16 | _roadveh_images [63] |
static const uint16 | _roadveh_full_adder [63] |
static const TrackdirBits | _road_enter_dir_to_reachable_trackdirs [DIAGDIR_END] |
'Convert' the DiagDirection where a road vehicle enters to the trackdirs it can drive onto | |
static const Trackdir | _road_reverse_table [DIAGDIR_END] |
static const Trackdir | _roadveh_depot_exit_trackdir [DIAGDIR_END] |
Converts the exit direction of a depot to trackdir the vehicle is going to drive to. |
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. | |
r | the road bits needed. |
Definition at line 1058 of file roadveh_cmd.cpp.
References _current_company, CMD_BUILD_ROAD, DC_NONE, DoCommand(), Backup< T >::Restore(), ROADTYPE_TRAM, and CommandCost::Succeeded().
static bool CheckRoadBlockedForOvertaking | ( | OvertakeData * | od | ) | [static] |
Check if overtaking is possible on a piece of track.
od | Information about the tile and the involved vehicles |
Definition at line 745 of file roadveh_cmd.cpp.
References GetTileTrackStatus(), HasBit(), HasVehicleOnPos(), TRACK_BIT_CROSS, TRACKDIR_BIT_NONE, TrackdirBitsToTrackBits(), TrackStatusToRedSignals(), TrackStatusToTrackdirBits(), and TRANSPORT_ROAD.
CommandCost CmdBuildRoadVehicle | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
const Engine * | e, | |||
uint16 | data, | |||
Vehicle ** | ret | |||
) |
Build a road vehicle.
tile | tile of the depot where road vehicle is built. | |
flags | type of operation. | |
e | the engine to build. | |
data | unused. | |
ret[out] | the vehicle that has been built. |
Definition at line 238 of file roadveh_cmd.cpp.
References _cur_year, _current_company, _date, _settings_game, AddArticulatedParts(), Vehicle::build_year, GroundVehicleCache::cached_veh_length, Vehicle::cargo_cap, Vehicle::cargo_type, GroundVehicle< T, Type >::CargoChanged(), CheckConsistencyOfArticulatedVehicle(), Vehicle::cur_image, Vehicle::date_of_last_service, DC_EXEC, DiagDirToDir(), Vehicle::direction, EF_ROAD_TRAM, ENGINE_EXCLUSIVE_PREVIEW, Vehicle::engine_type, GroundVehicleCache::first_engine, Engine::flags, GroundVehicle< T, Type >::gcache, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Engine::GetDefaultCargoType(), Engine::GetLifeLengthInDays(), GetRoadDepotDirection(), HasBit(), HasTileRoadType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_ENGINE, Vehicle::InvalidateNewGRFCache(), Vehicle::InvalidateNewGRFCacheOfChain(), Vehicle::last_station_visited, Vehicle::max_age, EngineInfo::misc_flags, SpecializedVehicle< T, Type >::Next(), Vehicle::owner, Vehicle::random_bits, Engine::reliability, Vehicle::reliability, Engine::reliability_spd_dec, Vehicle::reliability_spd_dec, return_cmd_error, ROADTYPE_TRAM, RoadTypeToRoadTypes(), VehicleSettings::roadveh_acceleration_model, RoadVehUpdateCache(), Vehicle::service_interval, SetBit(), GroundVehicle< T, Type >::SetFrontEngine(), Vehicle::spritenum, RoadVehicle::state, Vehicle::tile, TILE_SIZE, TileX(), TileY(), GameSettings::vehicle, Vehicle::vehicle_flags, VEHICLE_LENGTH, VehicleRandomBits(), VehicleUpdatePosition(), Vehicle::vehstatus, VF_BUILT_AS_PROTOTYPE, VS_HIDDEN, VS_STOPPED, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.
Referenced by CmdBuildVehicle().
CommandCost CmdTurnRoadVeh | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Turn a roadvehicle around.
tile | unused | |
flags | operation to perform | |
p1 | vehicle ID to turn | |
p2 | unused | |
text | unused |
Definition at line 341 of file roadveh_cmd.cpp.
References Vehicle::breakdown_ctr, CheckOwnership(), CMD_ERROR, Vehicle::current_order, DC_EXEC, Vehicle::direction, DirToDiagDir(), CommandCost::Failed(), GetDisallowedRoadDirections(), SpecializedVehicle< RoadVehicle, Type >::GetIfValid(), GetTunnelBridgeDirection(), RoadVehicle::IsInDepot(), IsNormalRoadTile(), RoadVehicle::IsPrimaryVehicle(), IsTileType(), Order::IsType(), MP_TUNNELBRIDGE, RoadVehicle::overtaking, Vehicle::owner, RVSB_WORMHOLE, RoadVehicle::state, Vehicle::tile, Vehicle::vehstatus, and VS_STOPPED.
static void DeleteLastRoadVeh | ( | RoadVehicle * | v | ) | [static] |
Delete last vehicle of a chain road vehicles.
v | First roadvehicle. |
Definition at line 429 of file roadveh_cmd.cpp.
References RoadStop::GetByTile(), GetRoadStopType(), IsInsideMM(), 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 150 of file roadveh_cmd.cpp.
References Clamp(), DrawSprite(), ST_NORMAL, UnScaleByZoom(), Sprite::width, Sprite::x_offs, and ZOOM_LVL_GUI.
Referenced by DrawVehicleEngine().
Check routine whether a road and a train vehicle have collided.
v | Train vehicle to test. | |
data | Road vehicle to test. |
NULL
. Definition at line 482 of file roadveh_cmd.cpp.
References abs(), BaseVehicle::type, VEH_TRAIN, Vehicle::x_pos, Vehicle::y_pos, and Vehicle::z_pos.
static uint GetRoadVehLength | ( | const RoadVehicle * | v | ) | [static] |
Get length of a road vehicle.
v | Road vehicle to query length. |
Definition at line 163 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, RoadVehicleInfo::shorten_factor, and VEHICLE_LENGTH.
Referenced by RoadVehUpdateCache().
static Trackdir RoadFindPathToDest | ( | RoadVehicle * | v, | |
TileIndex | tile, | |||
DiagDirection | enterdir | |||
) | [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 836 of file roadveh_cmd.cpp.
References _road_enter_dir_to_reachable_trackdirs, _settings_game, AxisToRoadBits(), Vehicle::dest_tile, DiagDirToAxis(), DiagDirToRoadBits(), FindFirstBit2x64(), GetAnyRoadBits(), RoadStop::GetByTile(), GetRoadDepotDirection(), GetRoadStopDir(), GetRoadStopType(), GetRoadTypes(), GetTileTrackStatus(), Vehicle::HandlePathfindingResult(), Vehicle::HasArticulatedPart(), HasBit(), RoadVehicle::IsBus(), IsRoadDepot(), IsStandardRoadStopTile(), IsTileOwner(), IsTileType(), KillFirstBit(), MP_ROAD, MP_STATION, NPFRoadVehicleChooseTrack(), Vehicle::owner, PathfinderSettings::pathfinder_for_roadvehs, GameSettings::pf, ROADSTOP_BUS, ROADTYPE_TRAM, PathfinderSettings::roadveh_queue, Vehicle::tile, TRACKDIR_BIT_NONE, TrackStatusToRedSignals(), TrackStatusToTrackdirBits(), TRANSPORT_ROAD, VPF_NPF, VPF_YAPF, and YapfRoadVehicleChooseTrack().
static void RoadVehArrivesAt | ( | const RoadVehicle * | v, | |
Station * | st | |||
) | [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 647 of file roadveh_cmd.cpp.
References _local_company, AddVehicleNewsItem(), HVOT_BUS, HVOT_TRUCK, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, RoadVehicle::IsBus(), Game::NewEvent(), AI::NewEvent(), NS_ARRIVAL_COMPANY, NS_ARRIVAL_OTHER, Vehicle::owner, ROADTYPE_ROAD, and SetDParam().
static bool RoadVehIsCrashed | ( | RoadVehicle * | v | ) | [static] |
Road vehicle chain has crashed.
v | First roadvehicle. |
Definition at line 460 of file roadveh_cmd.cpp.
References RoadVehicle::crashed_ctr, CreateEffectVehicleRel(), DeleteLastRoadVeh(), EV_EXPLOSION_LARGE, SpecializedVehicle< T, Type >::Next(), and Vehicle::tick_counter.
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 191 of file roadveh_cmd.cpp.
References VehicleCache::cached_max_speed, GroundVehicleCache::cached_total_length, Vehicle::engine_type, GroundVehicle< T, Type >::gcache, GetRoadVehLength(), INVALID_ENGINE, Vehicle::InvalidateNewGRFCacheOfChain(), Vehicle::IsFrontEngine(), SpecializedVehicle< T, Type >::Next(), PROP_ROADVEH_CARGO_AGE_PERIOD, PROP_ROADVEH_SPEED, Vehicle::UpdateVisualEffect(), Vehicle::vcache, VEH_ROAD, and VehicleLengthChanged().
Referenced by AfterLoadVehicles(), CheckCaches(), CmdBuildRoadVehicle(), and CmdRefitVehicle().
const TrackdirBits _road_enter_dir_to_reachable_trackdirs[DIAGDIR_END] [static] |
{ TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_X_NE, TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_Y_SE, TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_X_SW | TRACKDIR_BIT_RIGHT_S, TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_Y_NW }
'Convert' the DiagDirection where a road vehicle enters to the trackdirs it can drive onto
Definition at line 64 of file roadveh_cmd.cpp.
Referenced by RoadFindPathToDest().
const Trackdir _road_reverse_table[DIAGDIR_END] [static] |
{ TRACKDIR_RVREV_NE, TRACKDIR_RVREV_SE, TRACKDIR_RVREV_SW, TRACKDIR_RVREV_NW }
Definition at line 71 of file roadveh_cmd.cpp.
const Trackdir _roadveh_depot_exit_trackdir[DIAGDIR_END] [static] |
{ TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW }
Converts the exit direction of a depot to trackdir the vehicle is going to drive to.
Definition at line 76 of file roadveh_cmd.cpp.
const uint16 _roadveh_full_adder[63] [static] |
{ 0, 88, 0, 0, 0, 0, 48, 48, 48, 48, 0, 0, 64, 64, 0, 16, 16, 0, 88, 0, 0, 0, 0, 48, 48, 48, 48, 0, 0, 64, 64, 0, 16, 16, 0, 88, 0, 0, 0, 0, 48, 48, 48, 48, 0, 0, 64, 64, 0, 16, 16, 0, 8, 8, 8, 8, 0, 0, 0, 8, 8, 8, 8 }
Definition at line 52 of file roadveh_cmd.cpp.
const uint16 _roadveh_images[63] [static] |
{ 0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14, 0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74, 0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C, 0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC, 0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC, 0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4, 0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C, 0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4 }
Definition at line 41 of file roadveh_cmd.cpp.