|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
41 #include "table/strings.h"
43 #include <unordered_set>
69 static const uint16_t _ship_sprites[] = {0x0E5D, 0x0E55, 0x0E65, 0x0E6D};
72 bool IsValidImageIndex<VEH_SHIP>(uint8_t image_index)
74 return image_index <
lengthof(_ship_sprites);
85 uint8_t spritenum = e->u.ship.image_index;
87 if (is_custom_sprite(spritenum)) {
88 GetCustomVehicleIcon(engine,
DIR_W, image_type, result);
89 if (result->IsValid())
return;
94 assert(IsValidImageIndex<VEH_SHIP>(spritenum));
95 result->Set(
DIR_W + _ship_sprites[spritenum]);
101 GetShipIcon(engine, image_type, &seq);
105 preferred_x =
Clamp(preferred_x,
124 GetShipIcon(engine, image_type, &seq);
142 GetCustomVehicleSprite(
this,
direction, image_type, result);
143 if (result->IsValid())
return;
148 assert(IsValidImageIndex<VEH_SHIP>(
spritenum));
152 static const Depot *FindClosestShipDepot(
const Vehicle *v, uint max_distance)
154 const int max_region_distance = (max_distance / WATER_REGION_EDGE_LENGTH) + 1;
156 static std::unordered_set<int> visited_patch_hashes;
157 static std::deque<WaterRegionPatchDesc> patches_to_search;
158 visited_patch_hashes.clear();
159 patches_to_search.clear();
163 patches_to_search.push_back(start_patch);
166 while (!patches_to_search.empty()) {
169 patches_to_search.pop_front();
172 TVisitWaterRegionPatchCallBack visitFunc = [&](
const WaterRegionPatchDesc &water_region_patch) {
174 if (
std::abs(water_region_patch.x - start_patch.
x) > max_region_distance ||
175 std::abs(water_region_patch.y - start_patch.
y) > max_region_distance)
return;
178 if (visited_patch_hashes.count(hash) == 0) {
179 visited_patch_hashes.insert(hash);
180 patches_to_search.push_back(water_region_patch);
188 const Depot *best_depot =
nullptr;
189 uint best_dist_sq = std::numeric_limits<uint>::max();
194 if (dist_sq < best_dist_sq && dist_sq <= max_distance * max_distance &&
196 best_dist_sq = dist_sq;
205 static void CheckIfShipNeedsService(
Vehicle *v)
217 default: NOT_REACHED();
220 const Depot *depot = FindClosestShipDepot(v, max_distance);
222 if (depot ==
nullptr) {
231 v->SetDestTile(depot->xy);
273 CheckVehicleBreakdown(
this);
274 CheckIfShipNeedsService(
this);
316 void Ship::PlayLeaveStationSound(
bool force)
const
319 SndPlayVehicleFx(ShipVehInfo(this->
engine_type)->sfx,
this);
322 TileIndex Ship::GetOrderStationLocation(StationID station)
337 static const int8_t _delta_xy_table[8][4] = {
349 const int8_t *bb = _delta_xy_table[this->
rotation];
356 if (this->direction != this->
rotation) {
374 static bool CheckReverseShip(
const Ship *v,
Trackdir *trackdir =
nullptr)
377 bool reverse =
false;
381 default: NOT_REACHED();
386 static bool CheckShipLeaveDepot(
Ship *v)
417 if (north_tracks && south_tracks) {
424 }
else if (south_tracks) {
441 v->PlayLeaveStationSound();
468 assert(remainder <= std::numeric_limits<byte>::max());
469 v->
progress =
static_cast<byte>(remainder);
470 return number_of_steps;
481 if (!(st->had_vehicle_of_type &
HVOT_SHIP)) {
486 STR_NEWS_FIRST_SHIP_ARRIVAL,
510 bool path_found =
true;
521 if (!v->
path.empty()) {
524 if (
HasBit(tracks, track)) {
537 default: NOT_REACHED();
619 if ((v->
x_pos & 0xF) != 8 || (v->
y_pos & 0xF) != 8)
return 0;
642 if (dz == 0)
return false;
681 static void ReverseShipIntoTrackdir(
Ship *v,
Trackdir trackdir)
683 static constexpr
Direction _trackdir_to_direction[] = {
688 v->
direction = _trackdir_to_direction[trackdir];
702 static void ReverseShip(
Ship *v)
716 static void ShipController(
Ship *v)
725 if (
ProcessOrders(v) && CheckReverseShip(v))
return ReverseShip(v);
731 if (CheckShipLeaveDepot(v))
return;
750 for (uint i = 0; i < number_of_steps; ++i) {
787 if ((gp.x & 0xF) == 8 && (gp.
y & 0xF) == 8) {
816 CheckReverseShip(v, &trackdir);
818 return ReverseShipIntoTrackdir(v, trackdir);
874 if (!v->
path.empty()) v->
path.pop_front();
892 ShipController(
this);
@ VSE_START
Vehicle starting, i.e. leaving, the station.
static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
Runs the pathfinder to choose a track to continue along.
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.
@ TRACK_BIT_WORMHOLE
Bitflag for a wormhole (used for tunnels)
NPFSettings npf
pathfinder settings for the new pathfinder
static int ShipTestUpDownOnLock(const Ship *v)
Test if a ship is in the centre of a lock and should move up or down.
#define TILE_ADD(x, y)
Adds two tiles together.
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.
@ TRACK_BIT_NONE
No 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 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.
Direction
Defines the 8 directions on the map.
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.
@ NT_ARRIVAL_OTHER
First vehicle arrived for competitor.
@ DIRDIFF_45LEFT
Angle of 45 degrees left.
@ 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.
byte GetLockPart(Tile t)
Get the part of a lock.
uint16_t reliability_spd_dec
Speed of reliability decay between services (per day).
@ DIRDIFF_SAME
Both directions faces to the same direction.
byte y_extent
y-extent of vehicle bounding box
Axis
Allow incrementing of DiagDirDiff variables.
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.
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.
@ DIAGDIR_END
Used for iterations.
@ VPF_YAPF
Yet Another PathFinder.
@ VS_DEFPAL
Use default vehicle palette.
Tindex index
Index of this pool item.
byte acceleration
used by train & aircraft
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 (.
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.
byte running_ticks
Number of ticks this vehicle was not stopped this day.
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.
@ TRANSPORT_WATER
Transport over water.
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.
Owner owner
Which company owns the vehicle?
@ DC_EXEC
execute the given command
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.
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
byte x_subcoord
New X sub-coordinate on the new tile.
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.
void UpdateCache()
Update the caches of this ship.
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.
@ NT_ARRIVAL_COMPANY
First vehicle arrived for company.
@ 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.
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.
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
@ 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.
Track YapfShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, ShipPathCache &path_cache)
Finds the best path for given ship using YAPF.
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.
@ 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)
@ WATER_CLASS_CANAL
Canal.
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
@ 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.
@ HVOT_SHIP
Station has seen a ship.
@ 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.
bool YapfShipCheckReverse(const Ship *v, Trackdir *trackdir)
Returns true if it is better to reverse the ship before leaving depot using YAPF.
@ VS_STOPPED
Vehicle is stopped by the player.
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.
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.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
@ 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.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
DirDiff
Allow incrementing of Direction variables.
DiagDirection
Enumeration for diagonal directions.
void HandleLoading(bool mode=false)
Handle the loading of the vehicle; when not it skips through dummy orders and does nothing in all oth...
@ FACIL_DOCK
Station with a dock.
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.
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.
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.
Direction direction
facing
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
@ TRACK_BIT_DEPOT
Bitflag for a depot.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
@ TRACK_END
Used for iterations.
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
byte x_extent
x-extent of vehicle bounding box
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.
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.
TimerGameCalendar::Date max_age
Maximum age.
byte tick_counter
Increased by one for each tick.
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".
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.
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.
@ DIRDIFF_45RIGHT
Angle of 45 degrees right.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
byte z_extent
z-extent of vehicle bounding box
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.
static Vehicle * EnsureNoMovingShipProc(Vehicle *v, void *)
Test-procedure for HasVehicleOnPos to check for any ships which are visible and not stopped by the pl...
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.
static const int NPF_TILE_LENGTH
Length (penalty) of one tile with NPF.
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_BEGIN
Used for iterations.
TileIndex xy
Base tile of the station.
Track NPFShipChooseTrack(const Ship *v, bool &path_found)
Finds the best path for given ship using NPF.
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.
TrackBits
Allow incrementing of Track variables.
TileIndex GetShipDepotNorthTile(Tile t)
Get the most northern tile of a ship depot.
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
byte day_counter
Increased by one for each day.
#define lengthof(x)
Return the length of an fixed size array.
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.
byte progress
The percentage (if divided by 256) this vehicle already crossed the tile unit.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
void OnNewCalendarDay() override
Calendar day handler.
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 NPFShipCheckReverse(const Ship *v, Trackdir *best_td)
Returns true if it is better to reverse the ship before leaving depot using NPF.
byte spritenum
currently displayed sprite index 0xfd == custom sprite, 0xfe == custom second head sprite 0xff == res...
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.
Trackdir
Enumeration for tracks and directions.
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.
uint32_t maximum_go_to_depot_penalty
What is the maximum penalty that may be endured for going to a depot.
void UpdatePosition()
Update the position of the vehicle.
byte flags
Flags of the engine.
@ INVALID_DIR
Flag for an invalid direction.
Track
These are used to specify a single track.
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
uint8_t pathfinder_for_ships
the pathfinder to use for ships
@ VEH_SHIP
Ship vehicle type.
Specification of a rectangle with absolute coordinates of all edges.
byte y_subcoord
New Y sub-coordinate on the new tile.
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.
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)
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.
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.
@ EXPENSES_SHIP_RUN
Running costs ships.
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.
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.
@ INVALID_TRACK
Flag for an invalid track.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.