38 #include "table/strings.h" 42 static const uint16 _roadveh_images[] = {
43 0xCD4, 0xCDC, 0xCE4, 0xCEC, 0xCF4, 0xCFC, 0xD0C, 0xD14,
44 0xD24, 0xD1C, 0xD2C, 0xD04, 0xD1C, 0xD24, 0xD6C, 0xD74,
45 0xD7C, 0xC14, 0xC1C, 0xC24, 0xC2C, 0xC34, 0xC3C, 0xC4C,
46 0xC54, 0xC64, 0xC5C, 0xC6C, 0xC44, 0xC5C, 0xC64, 0xCAC,
47 0xCB4, 0xCBC, 0xD94, 0xD9C, 0xDA4, 0xDAC, 0xDB4, 0xDBC,
48 0xDCC, 0xDD4, 0xDE4, 0xDDC, 0xDEC, 0xDC4, 0xDDC, 0xDE4,
49 0xE2C, 0xE34, 0xE3C, 0xC14, 0xC1C, 0xC2C, 0xC3C, 0xC4C,
50 0xC5C, 0xC64, 0xC6C, 0xC74, 0xC84, 0xC94, 0xCA4
53 static const uint16 _roadveh_full_adder[] = {
54 0, 88, 0, 0, 0, 0, 48, 48,
55 48, 48, 0, 0, 64, 64, 0, 16,
56 16, 0, 88, 0, 0, 0, 0, 48,
57 48, 48, 48, 0, 0, 64, 64, 0,
58 16, 16, 0, 88, 0, 0, 0, 0,
59 48, 48, 48, 48, 0, 0, 64, 64,
60 0, 16, 16, 0, 8, 8, 8, 8,
66 bool IsValidImageIndex<VEH_ROAD>(uint8 image_index)
68 return image_index <
lengthof(_roadveh_images);
92 int reference_width = ROADVEHINFO_DEFAULT_VEHICLE_WIDTH;
94 if (offset !=
nullptr) {
106 if (is_custom_sprite(spritenum)) {
107 GetCustomVehicleIcon(engine,
DIR_W, image_type, result);
113 assert(IsValidImageIndex<VEH_ROAD>(spritenum));
114 result->
Set(
DIR_W + _roadveh_images[spritenum]);
121 if (is_custom_sprite(spritenum)) {
122 GetCustomVehicleSprite(
this, (
Direction)(direction + 4 * IS_CUSTOM_SECONDHEAD_SPRITE(spritenum)), image_type, result);
128 assert(IsValidImageIndex<VEH_ROAD>(spritenum));
148 GetRoadVehIcon(engine, image_type, &seq);
152 preferred_x =
Clamp(preferred_x,
171 GetRoadVehIcon(engine, image_type, &seq);
176 width =
UnScaleGUI(rect.right - rect.left + 1);
177 height =
UnScaleGUI(rect.bottom - rect.top + 1);
193 if (e->
GetGRF() !=
nullptr && e->
GetGRF()->grf_version >= 8) {
226 assert(u->First() == v);
236 u->gcache.cached_veh_length = veh_len;
240 u->UpdateVisualEffect();
279 v->
z_pos = GetSlopePixelZ(x, y);
297 _new_vehicle_id = v->
index;
320 u->cargo_cap = u->GetEngine()->DetermineCapacity(u);
323 u->InvalidateNewGRFCache();
345 default: NOT_REACHED();
354 if (location !=
nullptr) *location = rfdd.
tile;
377 if (ret.
Failed())
return ret;
393 if (flags &
DC_EXEC) v->reverse_ctr = 180;
410 static const int8 _delta_xy_table[8][10] = {
412 {3, 3, -1, -1, 0, 0, -1, -1, -1, -1},
413 {3, 7, -1, -3, 0, -1, 0, -1, 0, 0},
414 {3, 3, -1, -1, 0, 0, 1, -1, 1, -1},
415 {7, 3, -3, -1, -1, 0, 0, 0, 1, 0},
416 {3, 3, -1, -1, 0, 0, 1, 1, 1, 1},
417 {3, 7, -1, -3, 0, -1, 0, 0, 0, 1},
418 {3, 3, -1, -1, 0, 0, -1, 1, -1, 1},
419 {7, 3, -3, -1, -1, 0, -1, 0, 0, 0},
425 const int8 *bb = _delta_xy_table[this->
direction];
426 this->
x_bb_offs = bb[5] + bb[9] * shorten;
427 this->
y_bb_offs = bb[4] + bb[8] * shorten;;
430 this->
x_extent = bb[1] + bb[7] * shorten;
431 this->
y_extent = bb[0] + bb[6] * shorten;
449 }
else if ((u->direction & 1) == 0) {
471 for (; v->
Next() !=
nullptr; v = v->
Next()) u = v;
481 static void RoadVehSetRandomDirection(
RoadVehicle *v)
483 static const DirDiff delta[] = {
492 }
while ((v = v->
Next()) !=
nullptr);
506 if ((v->
tick_counter & 7) == 0) RoadVehSetRandomDirection(v);
508 bool ret = v->
Next() !=
nullptr;
549 uint pass = v->
Crash();
552 Game::NewEvent(
new ScriptEventVehicleCrashed(v->
index, v->
tile, ScriptEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING));
557 STR_NEWS_ROAD_VEHICLE_CRASH_DRIVER : STR_NEWS_ROAD_VEHICLE_CRASH,
562 ModifyStationRatingAround(v->
tile, v->
owner, -160, 22);
598 static void StartRoadVehSound(
const RoadVehicle *v)
602 if (s == SND_19_BUS_START_PULL_AWAY && (v->
tick_counter & 3) == 0) {
603 s = SND_1A_BUS_START_PULL_AWAY_WITH_HORN;
605 SndPlayVehicleFx(s, v);
620 static const int8 dist_x[] = { -4, -8, -4, -1, 4, 8, 4, 1 };
621 static const int8 dist_y[] = { -4, -1, 4, 8, 4, 1, -4, -8 };
625 short x_diff = v->
x_pos - rvf->x;
626 short y_diff = v->
y_pos - rvf->y;
637 uint diff =
abs(x_diff) +
abs(y_diff);
639 if (diff < rvf->best_diff || (diff == rvf->best_diff && v->
index < rvf->best->
index)) {
641 rvf->best_diff = diff;
653 if (front->reverse_ctr != 0)
return nullptr;
659 rvf.best_diff = UINT_MAX;
672 if (rvf.best_diff == UINT_MAX) {
673 front->blocked_ctr = 0;
677 if (update_blocked_ctr && ++front->blocked_ctr > 1480)
return nullptr;
691 if (!(st->had_vehicle_of_type &
HVOT_BUS)) {
692 st->had_vehicle_of_type |=
HVOT_BUS;
695 RoadTypeIsRoad(v->
roadtype) ? STR_NEWS_FIRST_BUS_ARRIVAL : STR_NEWS_FIRST_PASSENGER_TRAM_ARRIVAL,
705 if (!(st->had_vehicle_of_type &
HVOT_TRUCK)) {
709 RoadTypeIsRoad(v->
roadtype) ? STR_NEWS_FIRST_TRUCK_ARRIVAL : STR_NEWS_FIRST_CARGO_TRAM_ARRIVAL,
730 default: NOT_REACHED();
741 static const Direction _roadveh_new_dir[] = {
747 x = x - v->
x_pos + 1;
748 y = y - v->
y_pos + 1;
750 if ((uint)x > 2 || (uint)y > 2)
return v->
direction;
751 return _roadveh_new_dir[y * 4 + x];
756 Direction new_dir = RoadVehGetNewDirection(v, x, y);
760 if (new_dir == old_dir)
return old_dir;
772 static Vehicle *EnumFindVehBlockingOvertake(
Vehicle *v,
void *data)
776 return (v->
type ==
VEH_ROAD && v->
First() == v && v != od->u && v != od->v) ? v :
nullptr;
808 if (RoadTypeIsTram(v->
roadtype))
return;
852 static void RoadZPosAffectSpeed(
RoadVehicle *v,
int old_z)
856 if (old_z < v->
z_pos) {
864 static int PickRandomBit(uint bits)
869 for (i = 0; !(bits & 1) || (
int)--num >= 0; bits >>= 1, i++) {}
883 #define return_track(x) { best_track = (Trackdir)x; goto found_best_track; } 887 bool path_found =
true;
930 if (!v->
path.empty()) v->
path.clear();
932 return_track(_road_reverse_table[enterdir]);
935 if (v->reverse_ctr != 0) {
942 reverse = ((rb & straight) == straight) ||
947 if (v->
tile != tile) {
948 return_track(_road_reverse_table[enterdir]);
956 return_track(PickRandomBit(trackdirs));
969 if (!v->
path.empty()) {
976 if (
HasBit(trackdirs, trackdir)) {
977 v->
path.td.pop_front();
978 v->
path.tile.pop_front();
979 return_track(trackdir);
991 default: NOT_REACHED();
1031 if (RoadVehFindCloseTo(v, x, y, v->
direction,
false) !=
nullptr)
return true;
1035 StartRoadVehSound(v);
1043 v->frame = RVC_DEPOT_START_FRAME;
1057 if (prev->
tile == v->
tile && !already_reversed) {
1060 return _road_reverse_table[entry_dir];
1063 byte prev_state = prev->
state;
1078 if (already_reversed && prev->
tile != tile) {
1108 static const RoadBits required_roadbits[] = {
1112 RoadBits required = required_roadbits[dir & 0x07];
1208 dir = FollowPreviousRoadVehicle(v, prev, tile, (
DiagDirection)(rd.x & 3),
false);
1218 uint start_frame = RVC_DEFAULT_START_FRAME;
1229 default: NOT_REACHED();
1262 start_frame = RVC_TURN_AROUND_START_FRAME_SHORT_TRAM;
1282 Direction new_dir = RoadVehGetSlidingDirection(v, x, y);
1284 Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
1298 dir = _road_reverse_table[rd.x & 3];
1332 v->
state = (byte)dir;
1333 v->frame = start_frame;
1334 RoadTramType rtt = GetRoadTramType(v->
roadtype);
1335 if (GetRoadType(old_tile, rtt) != GetRoadType(tile, rtt)) {
1356 uint turn_around_start_frame = RVC_TURN_AROUND_START_FRAME;
1368 turn_around_start_frame = RVC_START_FRAME_AFTER_LONG_TRAM;
1369 switch (rd.x & 0x3) {
1370 default: NOT_REACHED();
1381 dir = FollowPreviousRoadVehicle(v, prev, v->
tile, (
DiagDirection)(rd.x & 3),
true);
1395 Direction new_dir = RoadVehGetSlidingDirection(v, x, y);
1396 if (v->
IsFrontEngine() && RoadVehFindCloseTo(v, x, y, new_dir) !=
nullptr)
return false;
1405 v->frame = turn_around_start_frame;
1424 RoadVehLeaveDepot(v->
Next(),
false);
1429 int x = (v->
x_pos & ~15) + (rd.x & 15);
1430 int y = (v->
y_pos & ~15) + (rd.y & 15);
1432 Direction new_dir = RoadVehGetSlidingDirection(v, x, y);
1437 RoadVehicle *u = RoadVehFindCloseTo(v, x, y, new_dir);
1442 if (v->
overtaking == 0) RoadVehCheckOvertake(v, u);
1460 if (new_dir != old_dir) {
1483 v->frame == RVC_DRIVE_THROUGH_STOP_FRAME))) {
1530 StartRoadVehSound(v);
1560 if (v->reverse_ctr != 0) v->reverse_ctr--;
1576 if (v->
IsInDepot() && RoadVehLeaveDepot(v,
true))
return true;
1584 bool blocked =
false;
1585 while (j >= adv_spd) {
1589 for (
RoadVehicle *prev =
nullptr; u !=
nullptr; prev = u, u = u->
Next()) {
1590 if (!IndividualRoadVehicleController(u, prev)) {
1601 if (j >= adv_spd && RoadVehCheckTrainCrash(v))
break;
1623 if (e->u.road.running_cost_class == INVALID_PRICE)
return 0;
1626 if (cost_factor == 0)
return 0;
1628 return GetPrice(e->u.road.running_cost_class, cost_factor, e->
GetGRF());
1639 return RoadVehController(
this);
1645 void RoadVehicle::SetDestTile(
TileIndex tile)
1652 static void CheckIfRoadVehNeedsService(
RoadVehicle *v)
1665 default: NOT_REACHED();
1691 v->SetDestTile(rfdd.
tile);
1702 if (this->blocked_ctr == 0) CheckVehicleBreakdown(
this);
1704 CheckIfRoadVehNeedsService(
this);
Functions related to OTTD's strings.
Owner
Enum for all companies/owners.
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
void DrawRoadVehEngine(int left, int right, int preferred_x, int y, EngineID engine, PaletteID pal, EngineImageType image_type)
Draw a road vehicle engine.
VehicleSettings vehicle
options for vehicles
This vehicle is in the exclusive preview stage, either being used or being offered to a company...
uint16 reliability
Current reliability of the engine.
static bool HasTileAnyRoadType(TileIndex t, RoadTypes rts)
Check if a tile has one of the specified road types.
uint32 PaletteID
The number of the palette.
Vehicle is stopped by the player.
First vehicle arrived for competitor.
int GetDisplayImageWidth(Point *offset=nullptr) const
Get the width of a road vehicle image in the GUI.
VehicleCargoList cargo
The cargo this vehicle is carrying.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition of stuff that is very close to a company, like the company struct itself.
static bool IsDiagonalDirection(Direction dir)
Checks if a given Direction is diagonal.
uint16 DepotID
Type for the unique identifier of depots.
static Vehicle * EnumCheckRoadVehCrashTrain(Vehicle *v, void *data)
Check routine whether a road and a train vehicle have collided.
int GetAcceleration() const
Calculates the acceleration of the vehicle under its current conditions.
void DecreaseVehicleValue(Vehicle *v)
Decrease the value of a vehicle.
static const int DAYS_IN_YEAR
days per year
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
bool IsEntranceBusy() const
Checks whether the entrance of the road stop is occupied by a vehicle.
A standard stop for trucks.
bool Tick()
Calls the tick handler of the vehicle.
Direction direction
facing
void ShowVisualEffect() const
Draw visual effects (smoke and/or sparks) for a vehicle chain.
(Road vehicle) reverse direction south-west
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
static DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
static const uint RDE_TURNED
We just finished turning.
Base class for roadstops.
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
static bool IsReversingRoadTrackdir(Trackdir dir)
Checks whether the trackdir means that we are reversing.
uint32 maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
void CheckOrders(const Vehicle *v)
Check the orders of a vehicle, to see if there are invalid orders and stuff.
void SetFrontEngine()
Set front engine state.
RoadBits GetAnyRoadBits(TileIndex tile, RoadTramType rtt, bool straight_tunnel_bridge_entrance)
Returns the RoadBits on an arbitrary tile Special behaviour:
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 blo...
Lower track and direction to west.
static RoadStopType GetRoadStopType(TileIndex t)
Get the road stop type of this tile.
The vehicle is at the opposite side of the road.
static Titem * Get(size_t index)
Returns Titem with given index.
Functions related to dates.
Angle of 45 degrees left.
uint DoUpdateSpeed(uint accel, int min_speed, int max_speed)
Update the speed of the vehicle.
int GetCurrentMaxSpeed() const
Calculates the maximum speed of the vehicle under its current conditions.
Use default vehicle palette.
The vehicle is in a drive-through road stop.
void AddArticulatedParts(Vehicle *first)
Add the remaining articulated parts to the given vehicle.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
AccelStatus GetAccelerationStatus() const
Checks the current acceleration status of this vehicle.
void Leave(RoadVehicle *rv)
Leave the road stop.
Trackdir
Enumeration for tracks and directions.
uint16 cur_speed
current speed
A tile with road (or tram tracks)
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Depot view; Window numbers:
Full road along the x-axis (south-west + north-east)
Types for recording game performance data.
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
Both directions faces to the same direction.
fluid_settings_t * settings
FluidSynth settings handle.
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded...
TileIndex dest_tile
Heading for this tile.
RoadVehicle()
We don't want GCC to zero our struct! It already is zeroed and has an index!
static bool IsRoadStop(TileIndex t)
Is the station at t a road station?
NPFSettings npf
pathfinder settings for the new pathfinder
Functions related to vehicles.
void IncrementRealOrderIndex()
Advanced cur_real_order_index to the next real order, keeps care of the wrap-around and invalidates t...
uint32 current_order_time
How many ticks have passed since this order started.
static const uint RDE_NEXT_TILE
State information about the Road Vehicle controller.
static uint TileX(TileIndex tile)
Get the X component of a tile.
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it...
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
A standard stop for buses.
PathfinderSettings pf
settings for all pathfinders
Only used when retrieving move data.
static uint GetRoadVehLength(const RoadVehicle *v)
Get length of a road vehicle.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
Tindex index
Index of this pool item.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
uint16 speed
maximum travel speed (1 unit = 1/1.6 mph = 1 km-ish/h)
void SetNext(Vehicle *next)
Set the next vehicle of this vehicle.
T * First() const
Get the first vehicle in the chain.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
StationID last_station_visited
The last station we stopped at.
uint16 reliability_spd_dec
Reliability decrease speed.
Upper track and direction to west.
static DiagDirection GetRoadDepotDirection(TileIndex t)
Get the direction of the exit of a road depot.
Money GetCost() const
The costs as made up to this moment.
void HandlePathfindingResult(bool path_found)
Handle the pathfinding result, especially the lost status.
bool IsChainInDepot() const override
Check whether the whole vehicle chain is in the depot.
Flag for an invalid DiagDirection.
void CargoChanged()
Recalculates the cached weight of a vehicle and its parts.
Common return value for all commands.
FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penalty)
Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using NPF...
static TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction...
static bool IsStandardRoadStopTile(TileIndex t)
Is tile t a standard (non-drive through) road stop station?
static bool HasExactlyOneBit(T value)
Test whether value has exactly 1 bit set.
RoadType
The different roadtypes we support.
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
EngineImageType
Visualisation contexts of vehicles and engines.
byte flags
Flags of the engine.
Year _cur_year
Current year, starting at 0.
uint StoredCount() const
Returns sum of cargo on board the vehicle (ie not only reserved).
byte overtaking
Set to RVSB_DRIVE_SIDE when overtaking, otherwise 0.
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
uint16 cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
static const uint TILE_SIZE
Tile size in world coordinates.
Entry point for OpenTTD to YAPF.
byte VehicleRandomBits()
Get a value for a vehicle's random_bits.
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
RoadStopType
Types of RoadStops.
VehicleSpriteSeq sprite_seq
Vehicle appearance.
static bool IsStraightRoadTrackdir(Trackdir dir)
Checks whether the given trackdir is a straight road.
int8 x_bb_offs
x offset of vehicle bounding box
uint32 GetGRFID() const
Retrieve the GRF ID of the NewGRF the engine is tied to.
static bool HasRoadWorks(TileIndex t)
Check if a tile has road works.
EngineID first_engine
Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
Class to backup a specific variable and restore it later.
RoadType roadtype
Road type.
Pseudo random number generator.
int8 y_bb_offs
y offset of vehicle bounding box
Angle of 45 degrees right.
byte breakdown_ctr
Counter for managing breakdown events.
(Road vehicle) reverse direction north-east
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Buses, trucks and trams belong to this class.
bool ShouldStopAtStation(const Vehicle *v, StationID station) const
Check whether the given vehicle should stop at the given station based on this order and the non-stop...
CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
Build a road vehicle.
Station has seen a truck.
uint16 cargo_cap
total capacity
RoadType roadtype
Roadtype of this vehicle.
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 bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Map related accessors for depots.
static bool RoadVehIsCrashed(RoadVehicle *v)
Road vehicle chain has crashed.
static RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Vehicle is a prototype (accepted as exclusive preview).
None of the directions are disallowed.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
uint16 reliability_spd_dec
Speed of reliability decay between services (per day).
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst)
Subtract money from a company, including the money fraction.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power ...
int y
x and y position of the vehicle after moving
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
bool IsValid() const
Check whether the sequence contains any sprites.
static RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
int UpdateSpeed()
This function looks at the vehicle and updates its speed (cur_speed and subspeed) variables...
SoundSettings sound
sound effect settings
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
Right track and direction to south.
bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle in on a specific location.
void MakeDummy()
Makes this order a Dummy order.
byte road_side
the side of the road vehicles drive on
int8 y_offs
y offset for vehicle sprite
void OnNewDay()
Calls the new day handler of the vehicle.
static DiagDirection GetRoadStopDir(TileIndex t)
Gets the direction the road stop entrance points towards.
Time spend processing road vehicles.
bool IsType(OrderType type) const
Check whether this order is of the given type.
The vehicle is in a tunnel and/or bridge.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
DoCommandFlag
List of flags for a command.
T * Next() const
Get next vehicle in the chain.
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).
ClientSettings _settings_client
The current settings for this game.
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
bool Succeeded() const
Did this command succeed?
Definition of base types and functions in a cross-platform compatible way.
void SetEntranceBusy(bool busy)
Makes an entrance occupied or free.
static const BridgeSpec * GetBridgeSpec(BridgeType i)
Get the specification of a bridge type.
Trackdir GetVehicleTrackdir() const
Returns the Trackdir on which the vehicle is currently located.
static const uint VEHICLE_LENGTH
The length of a vehicle in tile units.
A number of safeguards to prevent using unsafe methods.
byte x_extent
x-extent of vehicle bounding box
uint best_length
The distance towards the depot in penalty, or UINT_MAX if not found.
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle) ...
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
Direction
Defines the 8 directions on the map.
Flag for an invalid trackdir.
Max. speed: 1 unit = 1/0.8 mph = 2 km-ish/h.
DirDiff
Enumeration for the difference between two directions.
byte z_extent
z-extent of vehicle bounding box
RoadBits
Enumeration for the road parts on a tile.
static bool IsRoadDepotTile(TileIndex t)
Return whether a tile is a road depot tile.
Vehicle starting, i.e. leaving, the station.
The vehicle is in a depot.
static TrackdirBits TrackStatusToRedSignals(TrackStatus ts)
Returns the red-signal-information of a TrackStatus.
CargoID cargo_type
type of cargo this vehicle is carrying
Vehicle view; Window numbers:
TrackBits
Bitfield corresponding to Track.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
don't allow building on water
Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
Finds the best path for given road vehicle using NPF.
CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Turn a roadvehicle around.
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
TileIndex tile
Current tile index.
Road vehicle list; Window numbers:
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Functions to access the new pathfinder.
bool HasArticulatedPart() const
Check if an engine has an articulated part.
static Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
virtual bool IsInDepot() const
Check whether the vehicle is in the depot.
const byte _road_stop_stop_frame[]
Table of road stop stop frames, when to stop at a road stop.
static DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
static Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
int8 x_offs
x offset for vehicle sprite
Owner owner
Which company owns the vehicle?
Sprite sequence for a vehicle part.
Left track and direction to south.
#define lengthof(x)
Return the length of an fixed size array.
uint Crash(bool flooded=false)
Crash the (whole) vehicle chain.
static T min(const T a, const T b)
Returns the minimum of two values.
static bool IsCargoInClass(CargoID c, CargoClass cc)
Does cargo c have cargo class cc?
(Road vehicle) reverse direction south-east
uint16 refit_cap
Capacity left over from before last refit.
byte random_bits
Bits used for determining which randomized variational spritegroups to use when drawing.
Functions related to sound.
uint16 reliability
Reliability.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
bool roadveh_queue
buggy road vehicle queueing
Functions to cache sprites in memory.
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Vehicle * First() const
Get the first vehicle of this vehicle chain.
bool Failed() const
Did this command fail?
byte tick_counter
Increased by one for each tick.
EffectVehicle * CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, EffectVehicleType type)
Create an effect vehicle above a particular vehicle.
uint16 crashed_ctr
Animation counter when the vehicle has crashed.
Upper track and direction to east.
static DepotID GetDepotIndex(TileIndex t)
Get the index of which depot is attached to the tile.
Year build_year
Year the vehicle has been built.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
Checks whether a NewGRF wants to play a different vehicle sound effect.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
bool IsInDepot() const
Check whether the vehicle is in the depot.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void MarkDirty()
Marks the vehicles to be redrawn and updates cached variables.
Flag for an invalid direction.
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
static void DeleteLastRoadVeh(RoadVehicle *v)
Delete last vehicle of a chain road vehicles.
TileIndex tile
The tile of the depot.
static BridgeType GetBridgeType(TileIndex t)
Determines the type of bridge on a tile.
void UpdateDeltaXY()
Updates the x and y offsets and the size of the sprite used for this vehicle.
static const byte RV_OVERTAKE_TIMEOUT
The number of ticks a vehicle has for overtaking.
The vehicle is in a drive-through road stop.
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
uint Crash(bool flooded) override
Common code executed for crashed ground vehicles.
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
execute the given command
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
Functions related to companies.
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing...
void UpdatePosition()
Update the position of the vehicle.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
void CheckConsistencyOfArticulatedVehicle(const Vehicle *v)
Checks whether the specs of freshly build articulated vehicles are consistent with the information sp...
static T KillFirstBit(T value)
Clear the first bit in an integer.
bool IsBus() const
Check whether a roadvehicle is a bus.
Functions related to articulated vehicles.
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
Information about a road vehicle.
T * Previous() const
Get previous vehicle in the chain.
Tunnel entry/exit and bridge heads.
DestinationID GetDestination() const
Gets the destination of this order.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
void VehicleServiceInDepot(Vehicle *v)
Service a vehicle and all subsequent vehicles in the consist.
Only bits 0 and 3 are used to encode the trackdir for road stops.
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CT_NO_REFIT)
Makes this order a Go To Depot order.
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds, and ending the breakdown when appropriate.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadType rt, RoadBits r)
Can a tram track build without destruction on the given tile?
uint16 EngineID
Unique identification number of an engine.
uint32 TileIndex
The index/ID of a Tile.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
uint GetAdvanceDistance()
Determines the vehicle "progress" needed for moving a step.
Helper container to find a depot.
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
Date date_of_last_service
Last date the vehicle had a service at a depot.
Position information of a vehicle after it moved.
static bool IsLevelCrossingTile(TileIndex t)
Return whether a tile is a level crossing tile.
First vehicle arrived for company.
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc)
Find a vehicle from a specific location.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Only set when a vehicle has entered the stop.
Trackdir YapfRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found, RoadVehPathCache &path_cache)
Finds the best path for given road vehicle using YAPF.
void Free()
'Free' the order
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
void RoadVehUpdateCache(RoadVehicle *v, bool same_length)
Update the cache of a road vehicle.
static T abs(const T a)
Returns the absolute value of (scalar) variable.
TileIndex xy
Base tile of the station.
uint16 cached_total_length
Length of the whole vehicle (valid only for the first engine).
Functions related to zooming.
VehicleType type
Type of vehicle.
static uint8 FindFirstBit2x64(const int value)
Finds the position of the first non-zero bit in an integer.
static Station * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
Money GetRunningCost() const
Gets the running cost of a vehicle.
bool disaster
Play disaster and accident sounds.
uint16 cached_max_track_speed
Maximum consist speed (in internal units) limited by track type (valid only for the first engine)...
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Transport by road vehicle.
Number of ticks before carried cargo is aged.
The vehicle will not stop at any stations it passes except the destination.
The vehicle is in a road stop.
Vehicle details; Window numbers:
static uint CountBits(T value)
Counts the number of set bits in a variable.
Base functions for all Games.
RoadTypes compatible_roadtypes
Roadtypes this consist is powered on.
Functions related to commands.
Coordinates of a point in 2D.
A Stop for a Road Vehicle.
An accident or disaster has occurred.
static bool IsDriveThroughRoadStopContinuation(TileIndex rs, TileIndex next)
Checks whether the 'next' tile is still part of the road same drive through stop 'rs' in the same dir...
CompanyID _current_company
Company currently doing an action.
uint32 maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
byte shorten_factor
length on main map for this type is 8 - shorten_factor
static bool CheckRoadBlockedForOvertaking(OvertakeData *od)
Check if overtaking is possible on a piece of track.
The mask used to extract track dirs.
Functions that have tunnels and bridges in common.
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
static DisallowedRoadDirections GetDisallowedRoadDirections(TileIndex t)
Gets the disallowed directions.
static TileIndex TileAddByDir(TileIndex tile, Direction dir)
Adds a Direction to a tile.
void SetLastSpeed()
Update the GUI variant of the current speed of the vehicle.
uint8 cached_veh_length
Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can b...
uint8 original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
uint8 roadveh_acceleration_model
realistic acceleration for road vehicles
byte running_ticks
Number of ticks this vehicle was not stopped this day.
RoadVehPathCache path
Cached path.
byte y_extent
y-extent of vehicle bounding box
(Road vehicle) reverse direction north-west
EngineID engine_type
The type of engine used for this vehicle.
uint16 vehicle_flags
Used for gradual loading and other miscellaneous things (.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Functions related to NewGRF provided sounds.
void Restore()
Restore the variable.
DiagDirection
Enumeration for diagonal directions.
Base functions for all AIs.
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
The vehicle cannot enter the tile.
Northeast, upper right on your monitor.
Specification of a rectangle with absolute coordinates of all edges.
Full road along the y-axis (north-west + south-east)
uint16 GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination...
bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
static TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Vehicle length, returns the amount of 1/8's the vehicle is shorter for trains and RVs...
static void RoadVehArrivesAt(const RoadVehicle *v, Station *st)
A road vehicle arrives at a station.
One direction is the opposite of the other one.
FindDepotData YapfRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penalty)
Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF...
Left track and direction to north.
int UpdateInclination(bool new_tile, bool update_delta)
Checks if the vehicle is in a slope and sets the required flags in that case.
Right track and direction to north.
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
Running costs road vehicles.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Functions related to news.
Base classes/functions for stations.
VehicleCache vcache
Cache of often used vehicle values.
static Station * Get(size_t index)
Gets station with given index.
Date _date
Current date in days (day counter)
TileIndex new_tile
Tile of the vehicle after moving.
Vehicle * first
NOSAVE: pointer to the first vehicle in the chain.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Data about how a road vehicle must drive on a tile.
This depot order is because of the servicing limit.
void HandleLoading(bool mode=false)
Handle the loading of the vehicle; when not it skips through dummy orders and does nothing in all oth...
static TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
void GetImage(Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) const
Gets the sprite to show for the given direction.
Class for backupping variables and making sure they are restored later.
Functions related to effect vehicles.
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
static bool IsRoadDepot(TileIndex t)
Return whether a tile is a road depot.
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
Disable insertion and removal of automatic orders until the vehicle completes the real order...
static RoadBits AxisToRoadBits(Axis a)
Create the road-part which belongs to the given Axis.
Lower track and direction to east.
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
byte day_counter
Increased by one for each day.
Order current_order
The current order (+ status, like: loading)
static Direction DiagDirToDir(DiagDirection dir)
Convert a DiagDirection to a Direction.
static RoadStop * GetByTile(TileIndex tile, RoadStopType type)
Find a roadstop at given tile.
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
GroundVehicleCache gcache
Cache of often calculated values.
byte overtaking_ctr
The length of the current overtake attempt.
SpriteID colourmap
NOSAVE: cached colour mapping.
static RoadVehicle * GetIfValid(size_t index)
Returns vehicle if the index is a valid index for this vehicle type.
uint8 pathfinder_for_roadvehs
the pathfinder to use for roadvehicles
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
Base for the NewGRF implementation.