33 #include "table/strings.h" 65 if (cur_dist < thres) {
115 if (*waypoint == INVALID_STATION) {
117 }
else if (*waypoint != wp) {
128 if (ret.
Failed())
return ret;
164 Axis axis = Extract<Axis, 4, 1>(p1);
165 byte width =
GB(p1, 8, 8);
166 byte height =
GB(p1, 16, 8);
167 bool adjacent =
HasBit(p1, 24);
170 byte spec_index =
GB(p2, 8, 8);
171 StationID station_to_join =
GB(p2, 16, 16);
178 byte count = axis ==
AXIS_X ? height : width;
183 bool reuse = (station_to_join != NEW_STATION);
184 if (!reuse) station_to_join = INVALID_STATION;
185 bool distant_join = (station_to_join != INVALID_STATION);
190 StationID est = INVALID_STATION;
194 for (
int i = 0; i < count; i++) {
195 TileIndex tile = start_tile + i * offset;
197 if (ret.
Failed())
return ret;
203 if (ret.
Failed())
return ret;
206 TileIndex center_tile = start_tile + (count / 2) * offset;
216 if (ret.
Failed())
return ret;
219 CommandCost ret = wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST);
220 if (ret.
Failed())
return ret;
235 wp->
rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TRY);
248 byte *layout_ptr =
AllocaM(byte, count);
251 memset(layout_ptr, 0, count);
259 for (
int i = 0; i < count; i++) {
260 TileIndex tile = start_tile + i * offset;
303 if (ret.
Failed())
return ret;
315 wp->
rect.BeforeAddTile(tile, StationRect::ADD_TRY);
352 if (!(flags & DC_BANKRUPT)) {
354 if (ret.
Failed())
return ret;
367 wp->
rect.AfterRemoveTile(wp, tile);
386 if (wp->
name != NULL && strcmp(wp->
name, name) == 0)
return false;
408 if (ret.
Failed())
return ret;
Functions related to OTTD's strings.
don't allow building on structures
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
static void SetCustomStationSpecIndex(TileIndex t, byte specindex)
Set the custom station spec for this tile.
void DeallocateSpecFromStation(BaseStation *st, byte specindex)
Deallocate a StationSpec from a Station.
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
int32 TileIndexDiff
An offset value between to tiles.
static Titem * Get(size_t index)
Returns Titem with given index.
Functions related to dates.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
bool distant_join_stations
allow to join non-adjacent stations
bool IsInUse() const
Check whether the base station currently is in use; in use means that it is not scheduled for deletio...
Functions related to vehicles.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
static uint TileX(TileIndex tile)
Get the X component of a tile.
TileArea train_station
Tile area the train 'station' part covers.
byte station_spread
amount a station may spread
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
static bool IsUniqueWaypointName(const char *name)
Check whether the name is unique amongst the waypoints.
Tindex index
Index of this pool item.
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Helper functions to extract data from command parameters.
static bool IsRailWaypointTile(TileIndex t)
Is this tile a station tile and a rail waypoint?
Representation of a waypoint.
static void SetRailStationReservation(TileIndex t, bool b)
Set the reservation state of the rail station.
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...
static void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
Make the given tile a buoy tile.
uint32 station
Count of company owned station tiles.
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro
Common return value for all commands.
void UpdatePosition(int center, int top, StringID str, StringID str_small=STR_NULL)
Update the position of the viewport sign.
Town * town
The town this station is associated with.
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
StationSettings station
settings related to station management
static const uint TILE_SIZE
Tile size in world coordinates.
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
static uint GetCustomStationSpecIndex(TileIndex t)
Get the custom station spec for this tile.
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
Use this function to notify YAPF that track layout (or signal configuration) has change.
byte delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
company bankrupts, skip money check, skip vehicle on tile check in some cases
Functions related to (drawing on) viewports.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
ViewportSign sign
NOSAVE: Dimensions of sign.
Functions related to low-level strings.
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Waypoint view; Window numbers:
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Axis GetAxisForNewWaypoint(TileIndex tile)
Get the axis for a new waypoint.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
void MakeDefaultName(T *obj)
Set the default name for a depot/waypoint.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
static void MakeRailWaypoint(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
Make the given tile a rail waypoint tile.
static bool HasStationReservation(TileIndex t)
Get the reservation state of the rail station.
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
static Waypoint * FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid)
Find a deleted waypoint close to a tile.
Entry point for OpenTTD to YAPF's cache.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp)
Find a nearby waypoint that joins this waypoint.
DoCommandFlag
List of flags for a command.
bool Succeeded() const
Did this command succeed?
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec)
Allocate a StationSpec to a Station.
Definition of base types and functions in a cross-platform compatible way.
static TrackBits GetRailReservationTrackBits(TileIndex t)
Returns the reserved track bits of the tile.
A number of safeguards to prevent using unsafe methods.
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
bool HasStationInUse(StationID station, bool include_company, CompanyID company)
Tests whether the company's vehicles have this station in orders.
Represents the covered area of e.g.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
GUI Functions related to companies.
Map accessor functions for bridges.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
The tile has no ownership.
StationFacilityByte facilities
The facilities that this station has.
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
uint32 StringID
Numeric value that represents a string, independent of the selected language.
bool build_on_slopes
allow building on slopes
bool Failed() const
Did this command fail?
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
TileIndex tile
The base tile of the area.
OwnerByte owner
The owner of this station.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset)
Mark a tile given by its index dirty for repaint.
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
execute the given command
Functions related to companies.
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Header file for NewGRF stations.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
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...
CompanyByte _current_company
Company currently doing an action.
uint32 TileIndex
The index/ID of a Tile.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build a buoy.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Convert existing rail to waypoint.
TileIndex xy
Base tile of the station.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
void UpdateVirtCoord()
Update the virtual coords needed to draw the waypoint sign.
Slope
Enumeration for the slope-type.
Normal rail tile without signals.
static Waypoint * GetByTile(TileIndex tile)
Get the station belonging to a specific tile.
CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)
Clear a single tile of a station.
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Station with train station.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Functions related to OTTD's landscape.
static bool IsRailWaypoint(TileIndex t)
Is this station tile a rail 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.
Functions related to commands.
static bool IsValidID(size_t index)
Tests whether given index is a valid index for station of this type.
Coordinates of a point in 2D.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
static Axis OtherAxis(Axis a)
Select the other axis as provided.
ConstructionSettings construction
construction of things in-game
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
Remove a buoy.
static const uint MAX_LENGTH_STATION_NAME_CHARS
The maximum length of a station name in characters including '\0'.
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis)
Check whether we can expand the rail part of the given station.
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Rename a waypoint.
Waypoint(TileIndex tile=INVALID_TILE)
Create a waypoint at the given tile.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Owner
Enum for all companies/owners.
Window functions not directly related to making/drawing windows.
Functions related to water (management)
static DiagDirection AxisToDiagDir(Axis a)
Converts an Axis to a DiagDirection.
Flag for an invalid Axis.
Date _date
Current date in days (day counter)
static Point RemapCoords2(int x, int y)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap...
StringID string_id
Default name (town area) of station.
static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
Check whether the given tile is suitable for a waypoint.
Base class for all station-ish types.
Axis
Allow incrementing of DiagDirDiff variables.
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
#define FOR_ALL_WAYPOINTS(var)
Iterate over all waypoints.
Date build_date
Date of construction.
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-...
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
static Waypoint * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.