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