21 #include "viewport_kdtree.h"
35 #include "table/strings.h"
50 _viewport_sign_kdtree.
Insert(ViewportSignKdtreeItem::MakeWaypoint(this->
index));
62 if (this->
xy == new_xy)
return;
64 this->BaseStation::MoveSign(new_xy);
81 if (!wp->IsInUse() && wp->string_id == str && wp->owner == cid &&
HasBit(wp->waypoint_flags,
WPF_ROAD) == is_road) {
84 if (cur_dist < thres) {
157 if (*waypoint == INVALID_STATION) {
159 }
else if (*waypoint != wp) {
170 if (ret.
Failed())
return ret;
213 uint8_t count = axis ==
AXIS_X ? height : width;
218 bool reuse = (station_to_join != NEW_STATION);
219 if (!reuse) station_to_join = INVALID_STATION;
220 bool distant_join = (station_to_join != INVALID_STATION);
224 TileArea new_location(start_tile, width, height);
228 for (
TileIndex cur_tile : new_location) {
233 StationID est = INVALID_STATION;
237 for (
int i = 0; i < count; i++) {
238 TileIndex tile = start_tile + i * offset;
240 if (ret.
Failed())
return ret;
245 if (ret.
Failed())
return ret;
248 TileIndex center_tile = start_tile + (count / 2) * offset;
258 if (ret.
Failed())
return ret;
261 ret = wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
262 if (ret.
Failed())
return ret;
277 wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
290 std::vector<uint8_t> layout(count);
291 if (spec !=
nullptr) {
298 for (
int i = 0; i < count; i++) {
299 TileIndex tile = start_tile + i * offset;
347 uint8_t count = axis ==
AXIS_X ? height : width;
352 bool reuse = (station_to_join != NEW_STATION);
353 if (!reuse) station_to_join = INVALID_STATION;
354 bool distant_join = (station_to_join != INVALID_STATION);
358 TileArea roadstop_area(start_tile, width, height);
362 if (roadstopspec !=
nullptr) {
363 unit_cost = roadstopspec->
GetBuildCost(PR_BUILD_STATION_TRUCK);
365 unit_cost = _price[PR_BUILD_STATION_TRUCK];
367 StationID est = INVALID_STATION;
369 if (cost.
Failed())
return cost;
373 if (ret.
Failed())
return ret;
384 ret = wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
385 if (ret.
Failed())
return ret;
392 if (AllocateSpecToRoadStop(roadstopspec, wp,
false) == -1)
return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS);
404 wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
406 if (roadstopspec !=
nullptr) {
421 uint8_t map_spec_index = AllocateSpecToRoadStop(roadstopspec, wp,
true);
424 for (
TileIndex cur_tile : roadstop_area) {
437 wp->
rect.BeforeAddTile(cur_tile, StationRect::ADD_TRY);
451 if (roadstopspec !=
nullptr) wp->SetRoadStopRandomBits(cur_tile, 0);
482 if (ret.
Failed())
return ret;
494 wp->
rect.BeforeAddTile(tile, StationRect::ADD_TRY);
535 if (ret.
Failed())
return ret;
548 wp->
rect.AfterRemoveTile(wp, tile);
565 if (!wp->name.empty() && wp->name == name)
return false;
585 if (ret.
Failed())
return ret;
588 bool reset = text.empty();
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.
constexpr uint CountBits(T value)
Counts the number of set bits in a variable.
Map accessor functions for bridges.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
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.
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.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
DoCommandFlag
List of flags for a command.
@ DC_AUTO
don't allow building on structures
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
@ DC_EXEC
execute the given command
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.
Owner
Enum for all companies/owners.
@ 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 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.
int32_t TileIndexDiff
An offset value between two tiles.
NewGRF definitions and structures for road stops.
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
void DeallocateSpecFromStation(BaseStation *st, uint8_t specindex)
Deallocate a StationSpec from a Station.
Header file for NewGRF stations.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
static debug_inline RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
TrackBits GetRailReservationTrackBits(Tile t)
Returns the reserved track bits of the tile.
@ RAIL_TILE_NORMAL
Normal rail tile without signals.
void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count)
Update road infrastructure counts for a company.
static debug_inline bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
bool MayHaveRoad(Tile t)
Test whether a tile can have road/tram types.
RoadBits GetAllRoadBits(Tile tile)
Get all set RoadBits on the given 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)
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.
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.
@ FACIL_DOCK
Station with a dock.
@ FACIL_BUS_STOP
Station with bus stops.
@ FACIL_TRUCK_STOP
Station with truck stops.
@ FACIL_TRAIN
Station with train station.
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(const char *s)
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.
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.
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)
uint16_t triggers
The triggers that trigger animation.
Base class for all station-ish types.
StationFacility facilities
The facilities that this station has.
StringID string_id
Default name (town area) of station.
TileIndex xy
Base tile of the station.
TileArea train_station
Tile area the train 'station' part covers.
uint8_t cached_roadstop_anim_triggers
NOSAVE: Combined animation trigger bitmask for road stops, used to determine if trigger processing sh...
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 ...
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.
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.
Coordinates of a point in 2D.
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Money GetBuildCost(Price category) const
Get the cost for building a road stop of this type.
static Waypoint * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
static Pool::IterateWrapper< Waypoint > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
static Waypoint * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
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, StringID str, StringID str_small=STR_NULL)
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.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
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_SIZE
Tile size in world coordinates.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ MP_STATION
A tile of a station.
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.
Functions related to (drawing on) 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 ClearTile_Station(TileIndex tile, DoCommandFlag flags)
Clear a single tile of a station.
CommandCost CmdBuildRoadWaypoint(DoCommandFlag 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 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.
static Waypoint * FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid, bool is_road)
Find a deleted waypoint close to a tile.
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 CmdBuildRailWaypoint(DoCommandFlag 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 GetStationLayout(uint8_t *layout, uint numtracks, uint plat_len, const StationSpec *statspec)
Create the station layout for the given number of tracks and platform length.
CommandCost CmdBuildBuoy(DoCommandFlag flags, TileIndex tile)
Build a buoy.
static bool IsUniqueWaypointName(const std::string &name)
Check whether the name is unique amongst the waypoints.
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
Remove a buoy.
CommandCost CalculateRoadStopCost(TileArea tile_area, DoCommandFlag flags, bool is_drive_through, StationType station_type, Axis axis, DiagDirection ddir, StationID *est, RoadType rt, Money unit_cost)
Calculates cost of new road stops within the area.
CommandCost RemoveRoadWaypointStop(TileIndex tile, DoCommandFlag flags, int replacement_spec_index)
Remove a road waypoint.
CommandCost CmdRenameWaypoint(DoCommandFlag flags, StationID waypoint_id, const std::string &text)
Rename a waypoint.
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.