OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
21 #include "viewport_kdtree.h"
32 #include "table/strings.h"
47 _viewport_sign_kdtree.
Insert(ViewportSignKdtreeItem::MakeWaypoint(this->
index));
59 if (this->
xy == new_xy)
return;
61 this->BaseStation::MoveSign(new_xy);
77 if (!wp->IsInUse() && wp->string_id == str && wp->owner == cid) {
80 if (cur_dist < thres) {
130 if (*waypoint == INVALID_STATION) {
132 }
else if (*waypoint != wp) {
143 if (ret.
Failed())
return ret;
180 Axis axis = Extract<Axis, 6, 1>(p1);
181 byte width =
GB(p1, 8, 8);
182 byte height =
GB(p1, 16, 8);
183 bool adjacent =
HasBit(p1, 24);
186 byte spec_index =
GB(p2, 8, 8);
187 StationID station_to_join =
GB(p2, 16, 16);
194 byte count = axis ==
AXIS_X ? height : width;
199 bool reuse = (station_to_join != NEW_STATION);
200 if (!reuse) station_to_join = INVALID_STATION;
201 bool distant_join = (station_to_join != INVALID_STATION);
206 StationID est = INVALID_STATION;
210 for (
int i = 0; i < count; i++) {
211 TileIndex tile = start_tile + i * offset;
213 if (ret.
Failed())
return ret;
217 TileArea new_location(start_tile, width, height);
219 if (ret.
Failed())
return ret;
222 TileIndex center_tile = start_tile + (count / 2) * offset;
232 if (ret.
Failed())
return ret;
235 CommandCost ret = wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
236 if (ret.
Failed())
return ret;
251 wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
264 byte *layout_ptr =
AllocaM(
byte, count);
265 if (spec ==
nullptr) {
267 memset(layout_ptr, 0, count);
275 for (
int i = 0; i < count; i++) {
276 TileIndex tile = start_tile + i * offset;
319 if (ret.
Failed())
return ret;
331 wp->
rect.BeforeAddTile(tile, StationRect::ADD_TRY);
371 if (ret.
Failed())
return ret;
384 wp->
rect.AfterRemoveTile(wp, tile);
401 if (!wp->name.empty() && wp->name == name)
return false;
423 if (ret.
Failed())
return ret;
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a waypoint.
void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec)
Create the station layout for the given number of tracks and platform length.
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.
uint32 TileIndex
The index/ID of a Tile.
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.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
static Titem * Get(size_t index)
Returns Titem with given index.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
StationSettings station
settings related to station management
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
static bool IsRailWaypointTile(TileIndex t)
Is this tile a station tile and a rail waypoint?
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis)
Check whether we can expand the rail part of the given station.
Town * town
The town this station is associated with.
static void SetCustomStationSpecIndex(TileIndex t, byte specindex)
Set the custom station spec for this tile.
Axis GetAxisForNewWaypoint(TileIndex tile)
Get the axis for a new waypoint.
static Axis OtherAxis(Axis a)
Select the other axis as provided.
static void SetRailStationReservation(TileIndex t, bool b)
Set the reservation state of the rail station.
Tindex index
Index of this pool item.
static Waypoint * FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid)
Find a deleted waypoint close to a tile.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp)
Find a nearby waypoint that joins this waypoint.
uint32 station
Count of company owned station tiles.
Representation of a waypoint.
static const uint TILE_SIZE
Tile size in world coordinates.
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
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.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
DoCommandFlag
List of flags for a command.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
bool Succeeded() const
Did this command succeed?
static uint TileX(TileIndex tile)
Get the X component of a tile.
static TrackBits GetRailReservationTrackBits(TileIndex t)
Returns the reserved track bits of the tile.
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.
static void MakeRailWaypoint(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
Make the given tile a rail waypoint tile.
static void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
Make the given tile a buoy tile.
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...
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.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
@ EXPENSES_CONSTRUCTION
Construction costs.
TrackedViewportSign sign
NOSAVE: Dimensions of sign.
@ STAT_CLASS_WAYP
Waypoint class.
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Common return value for all commands.
static uint GetCustomStationSpecIndex(TileIndex t)
Get the custom station spec for this tile.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
Date _date
Current date in days (day counter)
static Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
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.
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
int32 TileIndexDiff
An offset value between to tiles.
void Insert(const T &element)
Insert a single element in the tree.
bool Failed() const
Did this command fail?
Represents the covered area of e.g.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
@ TRACK_BIT_X
X-axis track.
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
@ WC_WAYPOINT_VIEW
Waypoint view; Window numbers:
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
std::string name
Custom name.
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
Remove a buoy.
Coordinates of a point in 2D.
Slope
Enumeration for the slope-type.
static bool IsUniqueWaypointName(const char *name)
Check whether the name is unique amongst the waypoints.
@ FACIL_DOCK
Station with a dock.
byte station_spread
amount a station may spread
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
@ DC_BANKRUPT
company bankrupts, skip money check, skip vehicle on tile check in some cases
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a buoy.
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
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.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
CompanyID _current_company
Company currently doing an action.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
static bool IsRailWaypoint(TileIndex t)
Is this station tile a rail waypoint?
@ 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.
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
TileIndex tile
The base tile of the area.
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 RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
@ MP_STATION
A tile of a station.
static Waypoint * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
static StationID GetStationIndex(TileIndex t)
Get StationID from a 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()
@ 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.
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
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.
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Convert existing rail to waypoint.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Axis
Allow incrementing of DiagDirDiff variables.
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.
ConstructionSettings construction
construction of things in-game
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
@ INVALID_AXIS
Flag for an invalid Axis.
static Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Date build_date
Date of construction.
@ CMD_LANDSCAPE_CLEAR
demolish a tile
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro