#include "stdafx.h"
#include "landscape.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 "vehicle_gui.h"
#include "articulated_vehicles.h"
#include "newgrf_engine.h"
#include "newgrf_sound.h"
#include "pathfinder/yapf/yapf.h"
#include "strings_func.h"
#include "tunnelbridge_map.h"
#include "functions.h"
#include "window_func.h"
#include "date_func.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "autoreplace_gui.h"
#include "gfx_func.h"
#include "ai/ai.hpp"
#include "depot_map.h"
#include "effectvehicle_func.h"
#include "roadstop_base.h"
#include "cargotype.h"
#include "spritecache.h"
#include "debug.h"
#include "table/strings.h"
#include "table/sprites.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) |
void | DrawRoadVehEngine (int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal) |
static uint | GetRoadVehLength (const RoadVehicle *v) |
void | RoadVehUpdateCache (RoadVehicle *v) |
CommandCost | CmdBuildRoadVeh (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Build a road vehicle. | |
CommandCost | CmdSellRoadVeh (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Sell a road vehicle. | |
static FindDepotData | FindClosestRoadDepot (const RoadVehicle *v, int max_distance) |
CommandCost | CmdSendRoadVehToDepot (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Send a road vehicle to the depot. | |
CommandCost | CmdTurnRoadVeh (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Turn a roadvehicle around. | |
static void | DeleteLastRoadVeh (RoadVehicle *v) |
static byte | SetRoadVehPosition (RoadVehicle *v, int x, int y, bool turned) |
static void | RoadVehSetRandomDirection (RoadVehicle *v) |
static bool | RoadVehIsCrashed (RoadVehicle *v) |
static Vehicle * | EnumCheckRoadVehCrashTrain (Vehicle *v, void *data) |
static void | RoadVehCrash (RoadVehicle *v) |
static bool | RoadVehCheckTrainCrash (RoadVehicle *v) |
static void | HandleBrokenRoadVeh (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) |
static int | RoadVehAccelerate (RoadVehicle *v) |
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) |
CommandCost | CmdRefitRoadVeh (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Refit a road vehicle to the specified cargo type. | |
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. | |
static const byte | _road_veh_data_1 [] |
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 1147 of file roadveh_cmd.cpp.
References CMD_BUILD_ROAD, CmdSucceeded(), DC_NONE, DoCommand(), and ROADTYPE_TRAM.
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 834 of file roadveh_cmd.cpp.
References GetTileTrackStatus(), HasBit(), HasVehicleOnPos(), TRACK_BIT_CROSS, TRACKDIR_BIT_NONE, TrackdirBitsToTrackBits(), TrackStatusToRedSignals(), TrackStatusToTrackdirBits(), and TRANSPORT_ROAD.
CommandCost CmdBuildRoadVeh | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Build a road vehicle.
tile | tile of depot where road vehicle is built | |
flags | operation to perform | |
p1 | bus/truck type being built (engine) | |
p2 | unused | |
text | unused |
Definition at line 198 of file roadveh_cmd.cpp.
References _cur_year, _date, _settings_game, RoadVehicleCache::cached_veh_length, CheckConsistencyOfArticulatedVehicle(), CMD_ERROR, RoadVehicle::compatible_roadtypes, CT_INVALID, DC_AUTOREPLACE, DC_EXEC, DC_QUERY_COST, DiagDirToDir(), EF_ROAD_TRAM, ENGINE_EXCLUSIVE_PREVIEW, RoadVehicleCache::first_engine, GetVehicleCapacity(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateAutoreplaceWindow(), InvalidateWindowClassesData(), InvalidateWindowData(), IsEngineBuildable(), IsTileOwner(), VehicleSettings::max_roadveh, SpecializedVehicle< T, Type >::Next(), RoadVehicle::rcache, return_cmd_error, RoadVehicle::roadtype, ROADTYPE_ROAD, ROADTYPE_TRAM, RoadTypeToRoadTypes(), RoadVehicle::RoadVehicle(), RVSB_IN_DEPOT, SetBit(), RoadVehicle::SetRoadVehFront(), SetWindowDirty(), RoadVehicle::state, TILE_SIZE, TileX(), TileY(), VEH_ROAD, GameSettings::vehicle, VehicleMove(), and VehicleRandomBits().
CommandCost CmdRefitRoadVeh | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Refit a road vehicle to the specified cargo type.
tile | unused | |
flags | operation to perform | |
p1 | Vehicle ID of the vehicle to refit | |
p2 | Bitstuffed elements
| |
text | unused |
Definition at line 1731 of file roadveh_cmd.cpp.
References CheckOwnership(), CMD_ERROR, DC_EXEC, SpecializedVehicle< T, Type >::First(), GB(), SpecializedVehicle< RoadVehicle, VEH_ROAD >::GetIfValid(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowClassesData(), RoadVehicle::IsStoppedInDepot(), NUM_CARGO, RefitVehicle(), return_cmd_error, and SetWindowDirty().
CommandCost CmdSellRoadVeh | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Sell a road vehicle.
tile | unused | |
flags | operation to perform | |
p1 | vehicle ID to be sold | |
p2 | unused | |
text | unused |
Definition at line 339 of file roadveh_cmd.cpp.
References CheckOwnership(), CMD_ERROR, DC_EXEC, SpecializedVehicle< RoadVehicle, VEH_ROAD >::GetIfValid(), RoadVehicle::IsStoppedInDepot(), and return_cmd_error.
CommandCost CmdSendRoadVehToDepot | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Send a road vehicle to the depot.
tile | unused | |
flags | operation to perform | |
p1 | vehicle ID to send to the depot | |
p2 | various bitmasked elements
| |
text | unused |
Definition at line 392 of file roadveh_cmd.cpp.
References CMD_ERROR, DEPOT_MASS_SEND, DEPOT_SERVICE, SpecializedVehicle< RoadVehicle, VEH_ROAD >::GetIfValid(), SendAllVehiclesToDepot(), and VEH_ROAD.
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 414 of file roadveh_cmd.cpp.
References CheckOwnership(), CMD_ERROR, DC_EXEC, DirToDiagDir(), DRD_NONE, GetDisallowedRoadDirections(), SpecializedVehicle< RoadVehicle, VEH_ROAD >::GetIfValid(), GetTunnelBridgeDirection(), RoadVehicle::IsInDepot(), IsTileType(), MP_TUNNELBRIDGE, RoadVehicle::overtaking, RoadVehicle::reverse_ctr, RVSB_WORMHOLE, and RoadVehicle::state.
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 929 of file roadveh_cmd.cpp.
References _road_enter_dir_to_reachable_trackdirs, _settings_game, AxisToRoadBits(), RoadVehicle::compatible_roadtypes, DiagDirToAxis(), DiagDirToRoadBits(), FindFirstBit2x64(), GetAnyRoadBits(), RoadStop::GetByTile(), GetRoadStopDir(), GetRoadStopType(), GetTileTrackStatus(), RoadVehicle::HasArticulatedPart(), HasBit(), INVALID_TRACKDIR, RoadVehicle::IsBus(), IsStandardRoadStopTile(), IsTileOwner(), IsTileType(), KillFirstBit(), MP_ROAD, MP_STATION, NPFRoadVehicleChooseTrack(), PathfinderSettings::pathfinder_for_roadvehs, GameSettings::pf, RoadVehicle::reverse_ctr, ROADSTOP_BUS, ROADSTOP_TRUCK, RoadVehicle::roadtype, ROADTYPE_TRAM, PathfinderSettings::roadveh_queue, TRACKDIR_BIT_NONE, TrackStatusToRedSignals(), TrackStatusToTrackdirBits(), TRANSPORT_ROAD, VPF_NPF, VPF_YAPF, and YapfRoadVehicleChooseTrack().
const TrackdirBits _road_enter_dir_to_reachable_trackdirs[DIAGDIR_END] [static] |
Initial value:
{ 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 }
Definition at line 68 of file roadveh_cmd.cpp.
Referenced by RoadFindPathToDest().
const Trackdir _road_reverse_table[DIAGDIR_END] [static] |
Initial value:
Definition at line 75 of file roadveh_cmd.cpp.
const byte _road_veh_data_1[] [static] |
Initial value:
{ 20, 20, 16, 16, 0, 0, 0, 0, 19, 19, 15, 15, 0, 0, 0, 0, 16, 16, 12, 12, 0, 0, 0, 0, 15, 15, 11, 11 }
Definition at line 1029 of file roadveh_cmd.cpp.
const Trackdir _roadveh_depot_exit_trackdir[DIAGDIR_END] [static] |
Initial value:
Converts the exit direction of a depot to trackdir the vehicle is going to drive to.
Definition at line 80 of file roadveh_cmd.cpp.
const uint16 _roadveh_full_adder[63] [static] |
Initial value:
{ 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 56 of file roadveh_cmd.cpp.
const uint16 _roadveh_images[63] [static] |
Initial value:
{ 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 45 of file roadveh_cmd.cpp.