|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
21 #include "viewport_kdtree.h"
34 #include "table/strings.h"
49 _viewport_sign_kdtree.
Insert(ViewportSignKdtreeItem::MakeWaypoint(this->
index));
61 if (this->
xy == new_xy)
return;
63 this->BaseStation::MoveSign(new_xy);
79 if (!wp->IsInUse() && wp->string_id == str && wp->owner == cid) {
82 if (cur_dist < thres) {
132 if (*waypoint == INVALID_STATION) {
134 }
else if (*waypoint != wp) {
145 if (ret.
Failed())
return ret;
184 byte count = axis ==
AXIS_X ? height : width;
189 bool reuse = (station_to_join != NEW_STATION);
190 if (!reuse) station_to_join = INVALID_STATION;
191 bool distant_join = (station_to_join != INVALID_STATION);
195 TileArea new_location(start_tile, width, height);
199 for (
TileIndex cur_tile : new_location) {
204 StationID est = INVALID_STATION;
208 for (
int i = 0; i < count; i++) {
209 TileIndex tile = start_tile + i * offset;
211 if (ret.
Failed())
return ret;
216 if (ret.
Failed())
return ret;
219 TileIndex center_tile = start_tile + (count / 2) * offset;
229 if (ret.
Failed())
return ret;
232 ret = wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
233 if (ret.
Failed())
return ret;
248 wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
261 byte *layout_ptr =
new byte[count];
262 if (spec ==
nullptr) {
264 memset(layout_ptr, 0, count);
272 for (
int i = 0; i < count; i++) {
273 TileIndex tile = start_tile + i * offset;
284 bool blocked = spec !=
nullptr &&
HasBit(spec->
blocked, gfx);
286 bool pylons = spec !=
nullptr ?
HasBit(spec->
pylons, gfx) : gfx < 4;
287 bool wires = spec ==
nullptr || !
HasBit(spec->
wires, gfx);
326 if (ret.
Failed())
return ret;
338 wp->
rect.BeforeAddTile(tile, StationRect::ADD_TRY);
378 if (ret.
Failed())
return ret;
391 wp->
rect.AfterRemoveTile(wp, tile);
408 if (!wp->name.empty() && wp->name == name)
return false;
428 if (ret.
Failed())
return ret;
431 bool reset = text.empty();
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)
Clear a single tile of a station.
static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
Check whether the given tile is suitable for a waypoint.
StationFacility facilities
The facilities that this station has.
CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis axis, byte width, byte height, StationClassID spec_class, uint16_t spec_index, StationID station_to_join, bool adjacent)
Convert existing rail to waypoint.
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 MoveSign(TileIndex new_xy) override
Move the waypoint main coordinate somewhere else.
void MakeRailWaypoint(Tile t, Owner o, StationID sid, Axis a, byte section, RailType rt)
Make the given tile a rail waypoint tile.
byte StationGfx
Copy from station_map.h.
static Titem * Get(size_t index)
Returns Titem with given index.
void MakeBuoy(Tile t, StationID sid, WaterClass wc)
Make the given tile a buoy tile.
StationSettings station
settings related to station management
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Town * town
The town this station is associated with.
Axis GetAxisForNewWaypoint(TileIndex tile)
Get the axis for a new waypoint.
Axis
Allow incrementing of DiagDirDiff variables.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Tindex index
Index of this pool item.
static Waypoint * FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid)
Find a deleted waypoint close to a tile.
CommandCost CmdBuildBuoy(DoCommandFlag flags, TileIndex tile)
Build a buoy.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp)
Find a nearby waypoint that joins this waypoint.
void SetStationTileHaveWires(Tile t, bool b)
Set the catenary wires state of the rail station.
Representation of a waypoint.
void SetStationTileHavePylons(Tile t, bool b)
Set the catenary pylon state of the rail station.
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
static const uint TILE_SIZE
Tile size in world coordinates.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
void GetStationLayout(byte *layout, uint numtracks, uint plat_len, const StationSpec *statspec)
Create the station layout for the given number of tracks and platform length.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Owner
Enum for all companies/owners.
@ DC_EXEC
execute the given command
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
Owner owner
The owner of this station.
bool IsRailWaypointTile(Tile t)
Is this tile a station tile and a rail waypoint?
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
DoCommandFlag
List of flags for a command.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
uint32_t station
Count of company owned station tiles.
bool Succeeded() const
Did this command succeed?
void Remove(const T &element)
Remove a single element from the tree, if it exists.
StringID string_id
Default name (town area) of station.
static Pool::IterateWrapper< Waypoint > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
void UpdateVirtCoord() override
Update the virtual coords needed to draw the waypoint sign.
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...
Slope
Enumeration for the slope-type.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
void CheckForDockingTile(TileIndex t)
Mark the supplied tile as a docking tile if it is suitable for docking.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
StationGfx GetStationGfx(Tile t)
Get the station graphics of this tile.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
void SetCustomStationSpecIndex(Tile t, byte specindex)
Set the custom station spec for this tile.
@ EXPENSES_CONSTRUCTION
Construction costs.
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
@ STAT_CLASS_WAYP
Waypoint class.
Common return value for all commands.
TileArea train_station
Tile area the train 'station' part covers.
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
byte pylons
Bitmask of base tiles (0 - 7) which should contain elrail pylons.
void Insert(const T &element)
Insert a single element in the tree.
TrackBits GetRailReservationTrackBits(Tile t)
Returns the reserved track bits of the tile.
bool Failed() const
Did this command fail?
Represents the covered area of e.g.
DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta)
Check whether we can expand the rail part of the given station.
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ TRACK_BIT_X
X-axis track.
@ WC_WAYPOINT_VIEW
Waypoint view; Window numbers:
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
std::string name
Custom name.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
Remove a buoy.
int32_t TileIndexDiff
An offset value between two tiles.
Coordinates of a point in 2D.
static debug_inline RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
@ FACIL_DOCK
Station with a dock.
byte station_spread
amount a station may spread
void SetRailStationReservation(Tile t, bool b)
Set the reservation state of the rail station.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
void SetStationTileBlocked(Tile t, bool b)
Set the blocked state of the rail station.
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including '\0'.
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
CompanyID _current_company
Company currently doing an action.
@ INVALID_AXIS
Flag for an invalid Axis.
@ FACIL_TRAIN
Station with train station.
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
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.
TileIndex tile
The base tile of the area.
bool HasStationReservation(Tile t)
Get the reservation state of the rail station.
bool build_on_slopes
allow building on slopes
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
@ OWNER_NONE
The tile has no ownership.
static bool IsUniqueWaypointName(const std::string &name)
Check whether the name is unique amongst the waypoints.
@ MP_STATION
A tile of a station.
static Waypoint * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
bool kdtree_valid
Are the sign data valid for use with the _viewport_sign_kdtree?
@ RAIL_TILE_NORMAL
Normal rail tile without signals.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
@ DC_AUTO
don't allow building on structures
TileIndex xy
Base tile of the station.
Base class for all station-ish types.
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company's vehicles have this station in orders.
Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
byte delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
bool distant_join_stations
allow to join non-adjacent stations
CommandCost CmdRenameWaypoint(DoCommandFlag flags, StationID waypoint_id, const std::string &text)
Rename a waypoint.
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
static Waypoint * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
@ TRACK_BIT_Y
Y-axis track.
static Date date
Current date in days (day counter).
ConstructionSettings construction
construction of things in-game
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
bool IsRailWaypoint(Tile t)
Is this station tile a rail waypoint?
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Axis OtherAxis(Axis a)
Select the other axis as provided.
bool HasTileWaterGround(Tile t)
Checks whether the tile has water at the ground.
byte wires
Bitmask of base tiles (0 - 7) which should contain elrail wires.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
byte blocked
Bitmask of base tiles (0 - 7) which are blocked to trains.
TimerGameCalendar::Date build_date
Date of construction.
uint GetCustomStationSpecIndex(Tile t)
Get the custom station spec for this tile.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.