41#include "table/strings.h"
55 _viewport_sign_kdtree.
Insert(ViewportSignKdtreeItem::MakeWaypoint(this->
index));
67 if (this->
xy == new_xy)
return;
69 this->BaseStation::MoveSign(new_xy);
86 if (!wp->IsInUse() && wp->string_id == str && wp->owner == cid &&
HasBit(wp->waypoint_flags,
WPF_ROAD) == is_road) {
89 if (cur_dist < thres) {
162 if (*waypoint == StationID::Invalid()) {
164 }
else if (*waypoint != wp) {
165 return CommandCost(STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING);
175 if (ret.
Failed())
return ret;
218 uint8_t count = axis ==
AXIS_X ? height : width;
223 bool reuse = (station_to_join != NEW_STATION);
224 if (!reuse) station_to_join = StationID::Invalid();
225 bool distant_join = (station_to_join != StationID::Invalid());
229 TileArea new_location(start_tile, width, height);
233 for (
TileIndex cur_tile : new_location) {
245 for (
auto [i, it, tile] = std::make_tuple(0, stl.begin(), start_tile); i < count; ++i, ++it, tile += offset) {
247 if (ret.
Failed())
return ret;
250 if (ret.
Failed())
return ret;
255 if (ret.
Failed())
return ret;
258 TileIndex center_tile = start_tile + (count / 2) * offset;
268 if (ret.
Failed())
return ret;
271 ret = wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
272 if (ret.
Failed())
return ret;
280 if (!specindex.has_value())
return CommandCost(STR_ERROR_TOO_MANY_STATION_SPECS);
291 wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
305 for (
auto [i, it, tile] = std::make_tuple(0, stl.begin(), start_tile); i < count; ++i, ++it, tile += offset) {
354 uint8_t count = axis ==
AXIS_X ? height : width;
359 bool reuse = (station_to_join != NEW_STATION);
360 if (!reuse) station_to_join = StationID::Invalid();
361 bool distant_join = (station_to_join != StationID::Invalid());
365 TileArea roadstop_area(start_tile, width, height);
369 if (roadstopspec !=
nullptr) {
370 unit_cost = roadstopspec->
GetBuildCost(PR_BUILD_STATION_TRUCK);
372 unit_cost = _price[PR_BUILD_STATION_TRUCK];
376 if (cost.
Failed())
return cost;
380 if (ret.
Failed())
return ret;
391 ret = wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
392 if (ret.
Failed())
return ret;
400 if (!specindex.has_value())
return CommandCost(STR_ERROR_TOO_MANY_STATION_SPECS);
412 wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
415 if (roadstopspec !=
nullptr) {
431 for (
TileIndex cur_tile : roadstop_area) {
444 wp->
rect.BeforeAddTile(cur_tile, StationRect::ADD_TRY);
458 if (roadstopspec !=
nullptr) wp->SetRoadStopRandomBits(cur_tile, 0);
489 if (ret.
Failed())
return ret;
501 wp->
rect.BeforeAddTile(tile, StationRect::ADD_TRY);
542 if (ret.
Failed())
return ret;
555 wp->
rect.AfterRemoveTile(wp, tile);
572 if (!wp->name.empty() && wp->name == name)
return false;
592 if (ret.
Failed())
return ret;
595 bool reset = text.empty();
624 if (wp ==
nullptr)
return {
CMD_ERROR, StationID::Invalid() };
628 if (ret.
Failed())
return { ret, StationID::Invalid() };
633 return {
CommandCost(STR_ERROR_SITE_UNSUITABLE), StationID::Invalid() };
636 bool other_station =
false;
640 if (st != wp && st->
xy == tile) other_station =
true;
643 if (other_station)
return {
CommandCost(STR_ERROR_SITE_UNSUITABLE), StationID::Invalid() };
660 if (result.
Failed())
return;
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Map accessor functions for bridges.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Set()
Set all bits.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Money GetCost() const
The costs as made up to this moment.
bool Failed() const
Did this command fail?
void Insert(const T &element)
Insert a single element in the tree.
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Struct containing information relating to NewGRF classes for stations and airports.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
uint GetSpecCount() const
Get the number of allocated specs within the class.
static uint GetClassCount()
Get the number of allocated classes.
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
static Date date
Current date in days (day counter).
Functions related to commands.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
@ Auto
don't allow building on structures
@ Execute
execute the given command
@ Bankrupt
company bankrupts, skip money check, skip vehicle on tile check in some cases
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
GUI Functions related to companies.
static constexpr Owner OWNER_NONE
The tile has no ownership.
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Axis OtherAxis(Axis a)
Select the other axis as provided.
Axis
Allow incrementing of DiagDirDiff variables.
@ INVALID_AXIS
Flag for an invalid Axis.
DiagDirection
Enumeration for diagonal directions.
static const uint ROAD_STOP_TRACKBIT_FACTOR
Multiplier for how many regular track bits a bay stop counts.
@ EXPENSES_CONSTRUCTION
Construction costs.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Functions related to OTTD's landscape.
Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Command definitions related to landscape (slopes etc.).
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
TileIndexDiff TileOffsByAxis(Axis axis)
Convert an Axis to a TileIndexDiff.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
static uint TileX(TileIndex tile)
Get the X component of a tile.
int32_t TileIndexDiff
An offset value between two tiles.
uint8_t StationGfx
Copy from station_map.h.
Functions/types related to NewGRF debugging.
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
std::optional< uint8_t > AllocateSpecToRoadStop(const RoadStopSpec *spec, BaseStation *st)
Allocate a RoadStopSpec to a Station.
void AssignSpecToRoadStop(const RoadStopSpec *spec, BaseStation *st, uint8_t specindex)
Assign a previously allocated RoadStopSpec specindex to a Station.
NewGRF definitions and structures for road stops.
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
void AssignSpecToStation(const StationSpec *spec, BaseStation *st, uint8_t specindex)
Assign a previously allocated StationSpec specindex to a Station.
void DeallocateSpecFromStation(BaseStation *st, uint8_t specindex)
Deallocate a StationSpec from a Station.
std::optional< uint8_t > AllocateSpecToStation(const StationSpec *spec, BaseStation *st)
Allocate a StationSpec to a Station.
Header file for NewGRF stations.
static RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
@ Normal
Normal rail tile without signals.
TrackBits GetRailReservationTrackBits(Tile t)
Returns the reserved track bits of the tile.
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
bool MayHaveRoad(Tile t)
Test whether a tile can have road/tram types.
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
RoadBits GetAllRoadBits(Tile tile)
Get all set RoadBits on the given tile.
static bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Owner GetRoadOwner(Tile t, RoadTramType rtt)
Get the owner of a specific road type.
RoadBits
Enumeration for the road parts on a tile.
@ ROAD_Y
Full road along the y-axis (north-west + south-east)
@ ROAD_X
Full road along the x-axis (south-west + north-east)
@ RTT_ROAD
Road road type.
@ RTT_TRAM
Tram road type.
RoadType
The different roadtypes we support.
@ INVALID_ROADTYPE
flag for invalid roadtype
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Slope
Enumeration for the slope-type.
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company's vehicles have this station in orders.
void SetRailStationTileFlags(TileIndex tile, const StationSpec *statspec)
Set rail station tile flags for the given tile.
Declarations for accessing the k-d tree of stations.
void ForAllStationsRadius(TileIndex center, uint radius, Func func)
Call a function on all stations whose sign is within a radius of a center tile.
Functions related to station layouts.
void SetCustomStationSpecIndex(Tile t, uint8_t specindex)
Set the custom station spec for this tile.
bool IsRailWaypointTile(Tile t)
Is this tile a station tile and a rail waypoint?
void MakeDriveThroughRoadStop(Tile t, Owner station, Owner road, Owner tram, StationID sid, StationType rst, RoadType road_rt, RoadType tram_rt, Axis a)
Make the given tile a drivethrough roadstop tile.
StationID GetStationIndex(Tile t)
Get StationID from a tile.
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
uint GetCustomStationSpecIndex(Tile t)
Get the custom station spec for this tile.
bool IsRailWaypoint(Tile t)
Is this station tile a rail waypoint?
void SetRailStationReservation(Tile t, bool b)
Set the reservation state of the rail station.
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
void MakeRailWaypoint(Tile t, Owner o, StationID sid, Axis a, uint8_t section, RailType rt)
Make the given tile a rail waypoint tile.
bool IsRoadWaypointTile(Tile t)
Is this tile a station tile and a road waypoint?
Axis GetDriveThroughStopAxis(Tile t)
Gets the axis of the drive through stop.
void MakeBuoy(Tile t, StationID sid, WaterClass wc)
Make the given tile a buoy tile.
bool HasStationReservation(Tile t)
Get the reservation state of the rail station.
void SetCustomRoadStopSpecIndex(Tile t, uint8_t specindex)
Set the custom road stop spec for this tile.
@ Dock
Station with a dock.
@ TruckStop
Station with truck stops.
@ Train
Station with train station.
@ BusStop
Station with bus stops.
StationType
Station types.
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including '\0'.
Definition of base types and functions in a cross-platform compatible way.
size_t Utf8StringLength(std::string_view str)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
Functions related to low-level strings.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Base class for all station-ish types.
StringID string_id
Default name (town area) of station.
TileIndex xy
Base tile of the station.
StationFacilities facilities
The facilities that this station has.
TileArea train_station
Tile area the train 'station' part covers.
Owner owner
The owner of this station.
uint8_t delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
StationAnimationTriggers cached_roadstop_anim_triggers
NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing sh...
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
Town * town
The town this station is associated with.
static BaseStation * GetByTile(TileIndex tile)
Get the base station belonging to a specific tile.
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
TimerGameCalendar::Date build_date
Date of construction.
std::string name
Custom name.
uint32_t station
Count of company owned station tiles.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
bool build_on_slopes
allow building on slopes
ConstructionSettings construction
construction of things in-game
StationSettings station
settings related to station management
Represents the covered area of e.g.
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
TileIndex tile
The base tile of the area.
static Titem * Get(auto index)
Returns Titem with given index.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
const Tindex index
Index of this pool item.
Money GetBuildCost(Price category) const
Get the cost for building a road stop of this type.
static bool IsValidID(auto index)
Tests whether given index is a valid index for station of this type.
static Waypoint * Create(Targs &&... args)
Creates a new T-object in the station pool.
static Pool::IterateWrapper< Waypoint > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
static Waypoint * Get(auto index)
Gets station with given index.
static Waypoint * GetIfValid(auto index)
Returns station if the index is a valid index for this station type.
StationRect - used to track station spread out rectangle - cheaper than scanning whole map.
bool PtInExtendedRect(int x, int y, int distance=0) const
Determines whether a given point (x, y) is within a certain distance of the station rectangle.
uint8_t station_spread
amount a station may spread
bool distant_join_stations
allow to join non-adjacent stations
void UpdatePosition(int center, int top, std::string_view str, std::string_view str_small={})
Update the position of the viewport sign.
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
Representation of a waypoint.
TileArea road_waypoint_area
Tile area the road waypoint part covers.
uint16_t waypoint_flags
Waypoint flags, see WaypointFlags.
void MoveSign(TileIndex new_xy) override
Move the waypoint main coordinate somewhere else.
void UpdateVirtCoord() override
Update the virtual coords needed to draw the waypoint sign.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
static constexpr uint TILE_SIZE
Tile size in world coordinates.
@ MP_STATION
A tile of a station.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition of the game-calendar-timer.
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
@ TRACK_BIT_Y
Y-axis track.
@ TRACK_BIT_X
X-axis track.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Functions related to vehicles.
void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel)
Select or deselect waypoint for coverage area highlight.
Functions related to (drawing on) viewports.
Declarations for accessing the k-d tree of viewports.
Functions related to water management.
void ClearNeighbourNonFloodingStates(TileIndex tile)
Clear non-flooding state of the tiles around a tile.
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
bool HasTileWaterGround(Tile t)
Checks whether the tile has water at the ground.
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
Handles dividing the water in the map into regions to assist pathfinding.
@ WPF_ROAD
This is a road waypoint.
static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
Check whether the given tile is suitable for a waypoint.
CommandCost CmdBuildRoadWaypoint(DoCommandFlags flags, TileIndex start_tile, Axis axis, uint8_t width, uint8_t height, RoadStopClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent)
Build a road waypoint on an existing road.
CommandCost CmdBuildRailWaypoint(DoCommandFlags flags, TileIndex start_tile, Axis axis, uint8_t width, uint8_t height, StationClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent)
Convert existing rail to waypoint.
void CcMoveWaypointName(Commands, const CommandCost &result, StationID waypoint_id)
Callback function that is called after a name is moved.
CommandCost IsRailStationBridgeAboveOk(TileIndex tile, const StationSpec *spec, StationType type, StationGfx layout)
Test if a rail station can be built below a bridge.
std::tuple< CommandCost, StationID > CmdMoveWaypointName(DoCommandFlags flags, StationID waypoint_id, TileIndex tile)
Move a waypoint name.
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta)
Check whether we can expand the rail part of the given station.
Axis GetAxisForNewRailWaypoint(TileIndex tile)
Get the axis for a new rail waypoint.
Axis GetAxisForNewRoadWaypoint(TileIndex tile)
Get the axis for a new road waypoint.
CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp, bool is_road)
Find a nearby waypoint that joins this waypoint.
CommandCost IsBuoyBridgeAboveOk(TileIndex tile)
Test if a buoy can be built below a bridge.
CommandCost RemoveRoadWaypointStop(TileIndex tile, DoCommandFlags flags, int replacement_spec_index)
Remove a road waypoint.
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlags flags)
Remove a buoy.
CommandCost ClearTile_Station(TileIndex tile, DoCommandFlags flags)
Clear a single tile of a station.
CommandCost CmdRenameWaypoint(DoCommandFlags flags, StationID waypoint_id, const std::string &text)
Rename a waypoint.
CommandCost CmdBuildBuoy(DoCommandFlags flags, TileIndex tile)
Build a buoy.
static bool IsUniqueWaypointName(const std::string &name)
Check whether the name is unique amongst the waypoints.
static Waypoint * FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid, bool is_road)
Find a deleted waypoint close to a tile.
CommandCost CalculateRoadStopCost(TileArea tile_area, DoCommandFlags flags, bool is_drive_through, StationType station_type, const RoadStopSpec *roadstopspec, Axis axis, DiagDirection ddir, StationID *est, RoadType rt, Money unit_cost)
Calculates cost of new road stops within the area.
Command definitions related to waypoints.
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-...
Window functions not directly related to making/drawing windows.
@ WC_WAYPOINT_VIEW
Waypoint view; Window numbers:
Entry point for OpenTTD to YAPF's cache.
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.