OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
40 #include "table/strings.h"
42 #include <unordered_set>
68 static const uint16_t _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D};
71 bool IsValidImageIndex<VEH_SHIP>(uint8_t image_index)
73 return image_index <
lengthof(_ship_sprites);
84 uint8_t spritenum = e->u.ship.image_index;
86 if (is_custom_sprite(spritenum)) {
87 GetCustomVehicleIcon(engine,
DIR_W, image_type, result);
88 if (result->IsValid())
return;
93 assert(IsValidImageIndex<VEH_SHIP>(spritenum));
94 result->Set(
DIR_W + _ship_sprites[spritenum]);
100 GetShipIcon(engine, image_type, &seq);
104 preferred_x =
Clamp(preferred_x,
123 GetShipIcon(engine, image_type, &seq);
141 GetCustomVehicleSprite(
this,
direction, image_type, result);
142 if (result->IsValid())
return;
147 assert(IsValidImageIndex<VEH_SHIP>(
spritenum));
151 static const Depot *FindClosestShipDepot(
const Vehicle *v, uint max_distance)
153 const int max_region_distance = (max_distance / WATER_REGION_EDGE_LENGTH) + 1;
155 static std::unordered_set<int> visited_patch_hashes;
156 static std::deque<WaterRegionPatchDesc> patches_to_search;
157 visited_patch_hashes.clear();
158 patches_to_search.clear();
162 patches_to_search.push_back(start_patch);
165 while (!patches_to_search.empty()) {
168 patches_to_search.pop_front();
171 TVisitWaterRegionPatchCallBack visitFunc = [&](
const WaterRegionPatchDesc &water_region_patch) {
173 if (
std::abs(water_region_patch.x - start_patch.
x) > max_region_distance ||
174 std::abs(water_region_patch.y - start_patch.
y) > max_region_distance)
return;
177 if (visited_patch_hashes.count(hash) == 0) {
178 visited_patch_hashes.insert(hash);
179 patches_to_search.push_back(water_region_patch);
187 const Depot *best_depot =
nullptr;
188 uint best_dist_sq = std::numeric_limits<uint>::max();
193 if (dist_sq < best_dist_sq && dist_sq <= max_distance * max_distance &&
195 best_dist_sq = dist_sq;
204 static void CheckIfShipNeedsService(
Vehicle *v)
214 const Depot *depot = FindClosestShipDepot(v, max_distance);
216 if (depot ==
nullptr) {
225 v->SetDestTile(depot->xy);
269 CheckVehicleBreakdown(
this);
270 CheckIfShipNeedsService(
this);
312 void Ship::PlayLeaveStationSound(
bool force)
const
315 SndPlayVehicleFx(ShipVehInfo(this->
engine_type)->sfx,
this);
318 TileIndex Ship::GetOrderStationLocation(StationID station)
333 static const int8_t _delta_xy_table[8][4] = {
345 const int8_t *bb = _delta_xy_table[this->
rotation];
352 if (this->direction != this->
rotation) {
370 static bool CheckReverseShip(
const Ship *v,
Trackdir *trackdir =
nullptr)
376 static bool CheckShipLeaveDepot(
Ship *v)
407 if (north_tracks && south_tracks) {
414 }
else if (south_tracks) {
431 v->PlayLeaveStationSound();
458 assert(remainder <= std::numeric_limits<uint8_t>::max());
459 v->
progress =
static_cast<uint8_t
>(remainder);
460 return number_of_steps;
471 if (!(st->had_vehicle_of_type &
HVOT_SHIP)) {
476 STR_NEWS_FIRST_SHIP_ARRIVAL,
497 bool path_found =
true;
508 if (!v->
path.empty()) {
511 if (
HasBit(tracks, track)) {
602 if ((v->
x_pos & 0xF) != 8 || (v->
y_pos & 0xF) != 8)
return 0;
625 if (dz == 0)
return false;
664 static void ReverseShipIntoTrackdir(
Ship *v,
Trackdir trackdir)
666 static constexpr
Direction _trackdir_to_direction[] = {
671 v->
direction = _trackdir_to_direction[trackdir];
685 static void ReverseShip(
Ship *v)
699 static void ShipController(
Ship *v)
708 if (
ProcessOrders(v) && CheckReverseShip(v))
return ReverseShip(v);
714 if (CheckShipLeaveDepot(v))
return;
733 for (uint i = 0; i < number_of_steps; ++i) {
770 if ((gp.x & 0xF) == 8 && (gp.
y & 0xF) == 8) {
799 CheckReverseShip(v, &trackdir);
801 return ReverseShipIntoTrackdir(v, trackdir);
857 if (!v->
path.empty()) v->
path.pop_front();
875 ShipController(
this);
@ VSE_START
Vehicle starting, i.e. leaving, the station.
TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
virtual bool IsChainInDepot() const
Check whether the whole vehicle chain is in the depot.
StationFacility facilities
The facilities that this station has.
static int ShipTestUpDownOnLock(const Ship *v)
Test if a ship is in the centre of a lock and should move up or down.
TileArea docking_station
Tile area the docking tiles cover.
Direction ReverseDir(Direction d)
Return the reverse of a direction.
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-...
Money GetRunningCost() const override
Gets the running cost of a vehicle.
void MakeDummy()
Makes this order a Dummy order.
Direction last_direction
Last direction we obtained sprites for.
Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
uint16_t cached_cargo_age_period
Number of ticks before carried cargo is aged.
constexpr TileIndex TileAdd(TileIndex tile, TileIndexDiff offset)
Adds a given offset to a tile.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
bool IsType(OrderType type) const
Check whether this order is of the given type.
int Height() const
Get height of Rect.
static Titem * Get(size_t index)
Returns Titem with given index.
bool IsInDepot() const override
Check whether the vehicle is in the depot.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
VehicleSpriteSeq sprite_seq
Vehicle appearance.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Money GetPrice(Price index, uint cost_factor, const GRFFile *grf_file, int shift)
Determine a certain price.
uint16_t reliability_spd_dec
Reliability decrease speed.
@ DIRDIFF_45LEFT
Angle of 45 degrees left.
uint8_t GetLockPart(Tile t)
Get the part of a lock.
@ ODTFB_SERVICE
This depot order is because of the servicing limit.
uint16_t cargo_cap
total capacity
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
void CheckOrders(const Vehicle *v)
Check the orders of a vehicle, to see if there are invalid orders and stuff.
Describes a single interconnected patch of water within a particular water region.
void MakeLeaveStation()
Makes this order a Leave Station order.
Trackdir GetVehicleTrackdir() const override
Returns the Trackdir on which the vehicle is currently located.
@ FACIL_DOCK
Station with a dock.
uint16_t reliability_spd_dec
Speed of reliability decay between services (per day).
@ DIRDIFF_SAME
Both directions faces to the same direction.
@ TRANSPORT_WATER
Transport over water.
DestinationID GetDestination() const
Gets the destination of this order.
bool NeedsAutomaticServicing() const
Checks if the current order should be interrupted for a service-in-depot order.
Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
TimerGameCalendar::Date GetLifeLengthInDays() const
Returns the vehicle's (not model's!) life length in days.
void Set(SpriteID sprite)
Assign a single sprite to the sequence.
ShipPathCache path
Cached path.
TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
uint8_t spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
uint8_t y_extent
y-extent of vehicle bounding box
@ VS_DEFPAL
Use default vehicle palette.
Tindex index
Index of this pool item.
void Free()
'Free' the order
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Direction rotation
Visible direction.
bool IsOilRig(Tile t)
Is tile t part of an oilrig?
uint16_t vehicle_flags
Used for gradual loading and other miscellaneous things (.
@ EXPENSES_SHIP_RUN
Running costs ships.
CommandCost CmdBuildShip(DoCommandFlag flags, TileIndex tile, const Engine *e, Vehicle **ret)
Build a ship.
int y
The Y coordinate of the water region, i.e. Y=2 is the 3rd water region along the Y-axis.
static const uint TILE_SIZE
Tile size in world coordinates.
DiagDirection
Enumeration for diagonal directions.
static Station * Get(size_t index)
Gets station with given index.
void VehicleEnterDepot(Vehicle *v)
Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it,...
TimerGameTick::Ticks current_order_time
How many ticks have passed since this order started.
@ MP_INDUSTRY
Part of an industry.
static uint ShipAccelerate(Vehicle *v)
Accelerates the ship towards its target speed.
Direction ChangeDir(Direction d, DirDiff delta)
Change a direction by a given difference.
EngineImageType
Visualisation contexts of vehicles and engines.
Defines the internal data of a functional industry.
CargoID GetDefaultCargoType() const
Determines the default cargo type of an engine.
void Draw(int x, int y, PaletteID default_pal, bool force_pal) const
Draw the sprite sequence.
@ HVOT_SHIP
Station has seen a ship.
Owner owner
Which company owns the vehicle?
@ DC_EXEC
execute the given command
@ INVALID_DIR
Flag for an invalid direction.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
uint32_t PaletteID
The number of the palette.
static TrackBits GetAvailShipTracks(TileIndex tile, DiagDirection dir)
Get the available water tracks on a tile for a ship entering a tile.
DoCommandFlag
List of flags for a command.
void VehicleServiceInDepot(Vehicle *v)
Service a vehicle and all subsequent vehicles in the consist.
bool IsLock(Tile t)
Is there a lock on a given water tile?
Station * neutral_station
Associated neutral station.
@ TRACK_END
Used for iterations.
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
int32_t x_pos
x coordinate.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Structure for ship sub-coordinate data for moving into a new tile via a Diagdir onto a Track.
uint8_t flags
Flags of the engine.
void UpdateCache()
Update the caches of this ship.
@ TRACK_BIT_NONE
No track.
const GRFFile * GetGRF() const
Retrieve the NewGRF the engine is tied to.
TimerGameEconomy::Date date_of_last_service
Last economy date the vehicle had a service at a depot.
@ ENGINE_EXCLUSIVE_PREVIEW
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
uint16_t cached_max_speed
Maximum speed of the consist (minimum of the max speed of all vehicles in the consist).
uint DetermineCapacity(const Vehicle *v, uint16_t *mail_capacity=nullptr) const
Determines capacity of a given vehicle from scratch.
void BeginLoading()
Prepare everything to begin the loading when arriving at a station.
PathfinderSettings pf
settings for all pathfinders
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
WaterRegionPatchDesc GetWaterRegionPatchInfo(TileIndex tile)
Returns basic water region patch information for the provided tile.
@ VS_HIDDEN
Vehicle is not visible.
void UpdateVisualEffect(bool allow_power_change=true)
Update the cached visual effect.
DirDiff DirDifference(Direction d0, Direction d1)
Calculate the difference between two directions.
Track YapfShipChooseTrack(const Ship *v, TileIndex tile, bool &path_found, ShipPathCache &path_cache)
Finds the best path for given ship using YAPF.
TileIndex dest_tile
Heading for this tile.
void OnNewEconomyDay() override
Economy day handler.
void HandlePathfindingResult(bool path_found)
Handle the pathfinding result, especially the lost status.
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Common return value for all commands.
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
bool IsWaitingForUnbunching() const
Check whether a vehicle inside a depot is waiting for unbunching.
Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
@ NT_ARRIVAL_COMPANY
First vehicle arrived for company.
TrackBits
Allow incrementing of Track variables.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst)
Subtract money from a company, including the money fraction.
TileIndex tile
Current tile index.
@ EIT_ON_MAP
Vehicle drawn in viewport.
uint16_t random_bits
Bits used for randomized variational spritegroups.
EngineID engine_type
The type of engine used for this vehicle.
@ DIAGDIR_BEGIN
Used for iterations.
@ VS_CRASHED
Vehicle is crashed.
@ VETS_CANNOT_ENTER
The vehicle cannot enter the tile.
Sprite sequence for a vehicle part.
StationID last_station_visited
The last station we stopped at.
@ PFE_GL_SHIPS
Time spent processing ships.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Order current_order
The current order (+ status, like: loading)
@ VEH_SHIP
Ship vehicle type.
bool IsShipDepotTile(Tile t)
Is it a ship depot tile?
Direction DiagDirToDir(DiagDirection dir)
Convert a DiagDirection to a Direction.
DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
uint16_t cur_speed
current speed
static Track ChooseShipTrack(Ship *v, TileIndex tile, TrackBits tracks)
Runs the pathfinder to choose a track to continue along.
@ LOCK_PART_MIDDLE
Middle part of a lock.
ClosestDepot FindClosestDepot() override
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
int16_t rotation_y_pos
NOSAVE: Y Position before rotation.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
TimerGameCalendar::Year build_year
Year the vehicle has been built.
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
@ VS_STOPPED
Vehicle is stopped by the player.
bool YapfShipCheckReverse(const Ship *v, Trackdir *trackdir)
Returns true if it is better to reverse the ship before leaving depot using YAPF.
void ShowVisualEffect() const
Draw visual effects (smoke and/or sparks) for a vehicle chain.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
@ PROP_SHIP_CARGO_AGE_PERIOD
Number of ticks before carried cargo is aged.
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y)
Call the tile callback function for a vehicle entering a tile.
DiagDirection VehicleExitDir(Direction direction, TrackBits track)
Determine the side in which the vehicle will leave the tile.
TileIndex new_tile
Tile of the vehicle after moving.
#define lengthof(array)
Return the length of an fixed size array.
StationID last_loading_station
Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
Money GetCost() const
The costs as made up to this moment.
@ WC_SHIPS_LIST
Ships list; Window numbers:
DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Money profit_this_year
Profit this year << 8, low 8 bits are fract.
void VisitWaterRegionPatchNeighbors(const WaterRegionPatchDesc &water_region_patch, TVisitWaterRegionPatchCallBack &callback)
Calls the provided callback function on all accessible water region patches in each cardinal directio...
fluid_settings_t * settings
FluidSynth settings handle.
DiagDirection GetShipDepotDirection(Tile t)
Get the direction of the ship depot.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
DirDiff
Allow incrementing of Direction variables.
uint8_t running_ticks
Number of ticks this vehicle was not stopped this day.
void HandleLoading(bool mode=false)
Handle the loading of the vehicle; when not it skips through dummy orders and does nothing in all oth...
void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type)
Get the size of the sprite of a ship sprite heading west (used for lists).
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
@ NT_ARRIVAL_OTHER
First vehicle arrived for competitor.
Direction dir
New Direction to move in on the new track.
MutableSpriteCache sprite_cache
Cache of sprites and values related to recalculating them, see MutableSpriteCache.
DepotID GetDepotIndex(Tile t)
Get the index of which depot is attached to the tile.
int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc &water_region_patch)
Calculates a number that uniquely identifies the provided water region patch.
void AddVehicleNewsItem(StringID string, NewsType type, VehicleID vehicle, StationID station=INVALID_STATION)
Adds a newsitem referencing a vehicle.
uint16_t reliability
Current reliability of the engine.
uint8_t progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
SpriteID colourmap
NOSAVE: cached colour mapping.
@ PROP_SHIP_RUNNING_COST_FACTOR
Yearly runningcost.
bool HasTileWaterClass(Tile t)
Checks whether the tile has an waterclass associated.
void IncrementRealOrderIndex()
Advanced cur_real_order_index to the next real order, keeps care of the wrap-around and invalidates t...
int32_t z_pos
z coordinate.
@ VF_BUILT_AS_PROTOTYPE
Vehicle is a prototype (accepted as exclusive preview).
bool IsValidTile(Tile tile)
Checks if a tile is valid.
@ RAIL_GROUND_WATER
Grass with a fence and shore or water on the free halftile.
@ TRACK_BIT_WORMHOLE
Bitflag for a wormhole (used for tunnels)
Direction direction
facing
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
uint8_t tick_counter
Increased by one for each tick.
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
uint8_t acceleration
used by train & aircraft
bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
VehicleCache vcache
Cache of often used vehicle values.
All ships have this type.
CompanyID _current_company
Company currently doing an action.
Track
These are used to specify a single track.
DiagDirection DiagdirBetweenTiles(TileIndex tile_from, TileIndex tile_to)
Determines the DiagDirection to get from one tile to another.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static const PaletteID PALETTE_CRASH
Recolour sprite greying of crashed vehicles.
bool IsShipDestinationTile(TileIndex tile, StationID station)
Test if a tile is a docking tile for the given station.
bool IsDiagonalTrack(Track track)
Checks if a given Track is diagonal.
uint8_t day_counter
Increased by one for each day.
TimerGameCalendar::Date max_age
Maximum age.
constexpr int MAX_SHIP_DEPOT_SEARCH_DISTANCE
Max distance in tiles (as the crow flies) to search for depots when user clicks "go to depot".
@ WATER_CLASS_CANAL
Canal.
static const ShipSubcoordData _ship_subcoord[DIAGDIR_END][TRACK_END]
Ship sub-coordinate data for moving into a new tile via a Diagdir onto a Track.
Trackdir
Enumeration for tracks and directions.
bool IsDockingTile(Tile t)
Checks whether the tile is marked as a dockling tile.
static uint GetAdvanceSpeed(uint speed)
Determines the effective vehicle movement speed.
int8_t x_offs
x offset for vehicle sprite
void MarkDirty() override
Marks the vehicles to be redrawn and updates cached variables.
Axis
Allow incrementing of DiagDirDiff variables.
@ DIRDIFF_45RIGHT
Angle of 45 degrees right.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
TimerGameCalendar::Date date_of_last_service_newgrf
Last calendar date the vehicle had a service at a depot, unchanged by the date cheat to protect again...
void InvalidateNewGRFCacheOfChain()
Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
bool Tick() override
Calls the tick handler of the vehicle.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
uint8_t x_subcoord
New X sub-coordinate on the new tile.
static Vehicle * EnsureNoMovingShipProc(Vehicle *v, void *)
Test-procedure for HasVehicleOnPos to check for any ships which are moving.
uint8_t acceleration
Acceleration (1 unit = 1/3.2 mph per tick = 0.5 km-ish/h per tick)
uint16_t reliability
Reliability.
TrackBits state
The "track" the ship is following.
Position information of a vehicle after it moved.
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
@ MP_STATION
A tile of a station.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Information about a ship vehicle.
@ DIAGDIR_END
Used for iterations.
Direction
Defines the 8 directions on the map.
TileIndex xy
Base tile of the station.
static void ShipArrivesAt(const Vehicle *v, Station *st)
Ship arrives at a dock.
uint16_t GetMaxSpeed() const
Get the maxmimum speed in km-ish/h a vehicle is allowed to reach on the way to the destination.
TileIndex old_tile
Current tile of the vehicle.
bool IsDockWaterPart(Tile t)
Check whether a dock tile is the tile on water.
int32_t y_pos
y coordinate.
Structure to return information about the closest depot location, and whether it could be found.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force)
Checks whether a NewGRF wants to play a different vehicle sound effect.
TileIndex GetShipDepotNorthTile(Tile t)
Get the most northern tile of a ship depot.
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
uint8_t y_subcoord
New Y sub-coordinate on the new tile.
static bool ShipMoveUpDownOnLock(Ship *v)
Test and move a ship up or down in a lock.
YAPFSettings yapf
pathfinder settings for the yet another pathfinder
void AgeVehicle(Vehicle *v)
Update age of a vehicle.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_BASE.
void OnNewCalendarDay() override
Calendar day handler.
uint8_t x_extent
x-extent of vehicle bounding box
CargoID cargo_type
type of cargo this vehicle is carrying
uint16_t max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
uint8_t original_image_index
Original vehicle image index, thus the image index of the overridden vehicle.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
void UpdateDeltaXY() override
Updates the x and y offsets and the size of the sprite used for this vehicle.
static Date date
Current date in days (day counter).
uint16_t EngineID
Unique identification number of an engine.
bool IsDockTile(Tile t)
Is tile t a dock tile?
@ PROP_SHIP_SPEED
Max. speed: 1 unit = 1/3.2 mph = 0.5 km-ish/h.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
Maps a track and a full (8-way) direction to the trackdir that represents the track running in the gi...
uint GetAdvanceDistance()
Determines the vehicle "progress" needed for moving a step.
VehicleType type
Type of vehicle.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
void UpdatePosition()
Update the position of the vehicle.
int Width() const
Get width of Rect.
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
bool HandleBreakdown()
Handle all of the aspects of a vehicle breakdown This includes adding smoke and sounds,...
void DecreaseVehicleValue(Vehicle *v)
Decrease the value of a vehicle.
int y
x and y position of the vehicle after moving
void EconomyAgeVehicle(Vehicle *v)
Update economy age of a vehicle.
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Specification of a rectangle with absolute coordinates of all edges.
Axis GetShipDepotAxis(Tile t)
Get the axis of the ship depot.
static constexpr int DAYS_IN_YEAR
days per year
bool IsTileOwner(Tile tile, Owner owner)
Checks if a tile belongs to the given owner.
@ INVALID_TRACK
Flag for an invalid track.
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
void GetBounds(Rect *bounds) const
Determine shared bounds of all sprites.
Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_index)
Mark a particular widget in a particular window as dirty (in need of repainting)
@ TRACK_BIT_DEPOT
Bitflag for a depot.
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CARGO_NO_REFIT)
Makes this order a Go To Depot order.
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
void UpdateViewport(bool force_update, bool update_delta)
Update vehicle sprite- and position caches.
DiagDirection GetInclinedSlopeDirection(Slope s)
Returns the direction of an inclined slope.
void LeaveUnbunchingDepot()
Leave an unbunching depot and calculate the next departure time for shared order vehicles.
int16_t rotation_x_pos
NOSAVE: X Position before rotation.
WaterClass GetEffectiveWaterClass(TileIndex tile)
Determine the effective WaterClass for a ship travelling on a tile.
VehicleEnterTileStatus
The returned bits of VehicleEnterTile.
int8_t y_offs
y offset for vehicle sprite
bool Contains(TileIndex tile) const
Does this tile area contain a tile?
uint16_t refit_cap
Capacity left over from before last refit.
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
Get position information of a vehicle when moving one pixel in the direction it is facing.
uint32_t maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
uint8_t z_extent
z-extent of vehicle bounding box
int x
The X coordinate of the water region, i.e. X=2 is the 3rd water region along the X-axis.
static Year year
Current year, starting at 0.
@ VETS_ENTERED_WORMHOLE
The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/...
static Date date
Current date in days (day counter).
Track TrackToOppositeTrack(Track t)
Find the opposite track to a given track.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.