OpenTTD Source  20241120-master-g6d3adc6169
waypoint_cmd.cpp File Reference

Command Handling for waypoints. More...

#include "stdafx.h"
#include "command_func.h"
#include "landscape.h"
#include "bridge_map.h"
#include "town.h"
#include "waypoint_base.h"
#include "pathfinder/yapf/yapf_cache.h"
#include "pathfinder/water_regions.h"
#include "strings_func.h"
#include "viewport_func.h"
#include "viewport_kdtree.h"
#include "window_func.h"
#include "timer/timer_game_calendar.h"
#include "vehicle_func.h"
#include "string_func.h"
#include "company_func.h"
#include "newgrf_station.h"
#include "newgrf_roadstop.h"
#include "company_base.h"
#include "water.h"
#include "company_gui.h"
#include "waypoint_cmd.h"
#include "landscape_cmd.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

static WaypointFindDeletedWaypointCloseTo (TileIndex tile, StringID str, CompanyID cid, bool is_road)
 Find a deleted waypoint close to a tile. More...
 
Axis GetAxisForNewRailWaypoint (TileIndex tile)
 Get the axis for a new rail waypoint. More...
 
Axis GetAxisForNewRoadWaypoint (TileIndex tile)
 Get the axis for a new road waypoint. More...
 
CommandCost ClearTile_Station (TileIndex tile, DoCommandFlag flags)
 Clear a single tile of a station. More...
 
static CommandCost IsValidTileForWaypoint (TileIndex tile, Axis axis, StationID *waypoint)
 Check whether the given tile is suitable for a waypoint. More...
 
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. More...
 
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. More...
 
CommandCost CanExpandRailStation (const BaseStation *st, TileArea &new_ta)
 Check whether we can expand the rail part of the given station. More...
 
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. More...
 
CommandCost RemoveRoadWaypointStop (TileIndex tile, DoCommandFlag flags, int replacement_spec_index)
 Remove a road waypoint. More...
 
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. More...
 
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. More...
 
CommandCost CmdBuildBuoy (DoCommandFlag flags, TileIndex tile)
 Build a buoy. More...
 
CommandCost RemoveBuoy (TileIndex tile, DoCommandFlag flags)
 Remove a buoy. More...
 
static bool IsUniqueWaypointName (const std::string &name)
 Check whether the name is unique amongst the waypoints. More...
 
CommandCost CmdRenameWaypoint (DoCommandFlag flags, StationID waypoint_id, const std::string &text)
 Rename a waypoint. More...
 

Detailed Description

Command Handling for waypoints.

Definition in file waypoint_cmd.cpp.

Function Documentation

◆ CalculateRoadStopCost()

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.

Parameters
tile_areaArea to check.
flagsOperation to perform.
is_drive_throughTrue if trying to build a drive-through station.
station_typeStation type (bus, truck or road waypoint).
axisAxis of a drive-through road stop.
ddirEntrance direction (DiagDirection) for normal stops. Converted to the axis for drive-through stops.
stationStationID to be queried and returned if available.
rtRoad type to build, may be INVALID_ROADTYPE if an existing road is required.
unit_costThe cost to build one road stop of the current type.
Returns
The cost in case of success, or an error code if it failed.

Definition at line 1919 of file station_cmd.cpp.

References CommandCost::AddCost(), AxisToDiagDir(), CheckFlatLandRoadStop(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), IsAnyRoadStop(), IsTileType(), MP_STATION, ReverseDiagDir(), and SetBit().

◆ CanExpandRailStation()

CommandCost CanExpandRailStation ( const BaseStation st,
TileArea new_ta 
)

Check whether we can expand the rail part of the given station.

Parameters
stthe station to expand
new_tathe current (and if all is fine new) tile area of the rail part of the station
Returns
Succeeded or failed command.

Definition at line 1081 of file station_cmd.cpp.

References BaseStation::train_station.

◆ ClearTile_Station()

CommandCost ClearTile_Station ( TileIndex  tile,
DoCommandFlag  flags 
)

Clear a single tile of a station.

Parameters
tileThe tile to clear.
flagsThe DoCommand flags related to the "command".
Returns
The cost, or error of clearing.

Definition at line 4700 of file station_cmd.cpp.

References DC_AUTO, and GetStationType().

Referenced by CheckFlatLandRoadStop(), and IsValidTileForWaypoint().

◆ CmdBuildBuoy()

CommandCost CmdBuildBuoy ( DoCommandFlag  flags,
TileIndex  tile 
)

Build a buoy.

Parameters
flagsoperation to perform
tiletile where to place the buoy
Returns
the cost of this operation or an error

Definition at line 468 of file waypoint_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_station_pool >::CanAllocateItem(), EXPENSES_CONSTRUCTION, FindDeletedWaypointCloseTo(), HasTileWaterGround(), IsBridgeAbove(), IsTileFlat(), OWNER_NONE, and return_cmd_error.

◆ CmdBuildRailWaypoint()

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.

Eg build a waypoint station over piece of rail

Parameters
flagstype of operation
start_tilenorthern most tile where waypoint will be built
axisorientation (Axis)
widthwidth of waypoint
heightheight of waypoint
spec_classcustom station class
spec_indexcustom station id
station_to_joinstation ID to join (NEW_STATION if build new one)
adjacentallow waypoints directly adjacent to other waypoints.
Returns
the cost of this operation or an error

Definition at line 203 of file waypoint_cmd.cpp.

◆ CmdBuildRoadWaypoint()

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.

Parameters
flagstype of operation.
start_tilenorthern most tile where waypoint will be built.
axisorientation (Axis).
widthwidth of waypoint.
heightheight of waypoint.
spec_classcustom road stop class.
spec_indexcustom road stop id.
station_to_joinstation ID to join (NEW_STATION if build new one).
adjacentallow waypoints directly adjacent to other waypoints.
Returns
the cost of this operation or an error.

Definition at line 335 of file waypoint_cmd.cpp.

◆ CmdRenameWaypoint()

CommandCost CmdRenameWaypoint ( DoCommandFlag  flags,
StationID  waypoint_id,
const std::string &  text 
)

Rename a waypoint.

Parameters
flagstype of operation
waypoint_idid of waypoint
textthe new name or an empty string when resetting to the default
Returns
the cost of this operation or an error

Definition at line 578 of file waypoint_cmd.cpp.

References CheckOwnership(), CMD_ERROR, DC_EXEC, CommandCost::Failed(), SpecializedStation< Waypoint, true >::GetIfValid(), IsUniqueWaypointName(), MAX_LENGTH_STATION_NAME_CHARS, BaseStation::name, BaseStation::owner, OWNER_NONE, return_cmd_error, Waypoint::UpdateVirtCoord(), and Utf8StringLength().

◆ FindDeletedWaypointCloseTo()

static Waypoint* FindDeletedWaypointCloseTo ( TileIndex  tile,
StringID  str,
CompanyID  cid,
bool  is_road 
)
static

Find a deleted waypoint close to a tile.

Parameters
tileto search from
strthe string to get the 'type' of
cidprevious owner of the waypoint
is_roadwhether to find a road waypoint
Returns
the deleted nearby waypoint

Definition at line 75 of file waypoint_cmd.cpp.

References DistanceManhattan(), HasBit(), SpecializedStation< Waypoint, true >::Iterate(), and WPF_ROAD.

Referenced by CmdBuildBuoy().

◆ FindJoiningWaypoint()

CommandCost FindJoiningWaypoint ( StationID  existing_waypoint,
StationID  waypoint_to_join,
bool  adjacent,
TileArea  ta,
Waypoint **  wp,
bool  is_road 
)

Find a nearby waypoint that joins this waypoint.

Parameters
existing_waypointan existing waypoint we build over
waypoint_to_jointhe waypoint to join to
adjacentwhether adjacent waypoints are allowed
tathe area of the newly build waypoint
wp'return' pointer for the found waypoint
is_roadwhether to find a road waypoint
Returns
command cost with the error or 'okay'

Definition at line 1222 of file station_cmd.cpp.

References HasBit(), Waypoint::waypoint_flags, and WPF_ROAD.

◆ GetAxisForNewRailWaypoint()

Axis GetAxisForNewRailWaypoint ( TileIndex  tile)

Get the axis for a new rail waypoint.

This means that if it is a valid tile to build a waypoint on it returns a valid Axis, otherwise an invalid one.

Parameters
tilethe tile to look at.
Returns
the axis for the to-be-build waypoint.

Definition at line 101 of file waypoint_cmd.cpp.

References AXIS_X, AXIS_Y, GetRailStationAxis(), GetRailTileType(), GetTrackBits(), INVALID_AXIS, IsRailWaypointTile(), IsTileType(), MP_RAILWAY, RAIL_TILE_NORMAL, TRACK_BIT_X, and TRACK_BIT_Y.

Referenced by PlaceRail_Waypoint().

◆ GetAxisForNewRoadWaypoint()

Axis GetAxisForNewRoadWaypoint ( TileIndex  tile)

Get the axis for a new road waypoint.

This means that if it is a valid tile to build a waypoint on it returns a valid Axis, otherwise an invalid one.

Parameters
tilethe tile to look at.
Returns
the axis for the to-be-build waypoint.

Definition at line 123 of file waypoint_cmd.cpp.

References AXIS_X, AXIS_Y, GetAllRoadBits(), GetDriveThroughStopAxis(), INVALID_AXIS, IsNormalRoadTile(), IsRoadWaypointTile(), ROAD_X, and ROAD_Y.

Referenced by PlaceRoad_Waypoint().

◆ GetStationLayout()

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.

Parameters
layoutThe layout to write to.
numtracksThe number of tracks to write.
plat_lenThe length of the platforms.
statspecThe specification of the station to (possibly) get the layout from.

Definition at line 1126 of file station_cmd.cpp.

References GetStationLayoutKey(), and StationSpec::layouts.

◆ IsUniqueWaypointName()

static bool IsUniqueWaypointName ( const std::string &  name)
static

Check whether the name is unique amongst the waypoints.

Parameters
nameThe name to check.
Returns
True iff the name is unique.

Definition at line 562 of file waypoint_cmd.cpp.

References SpecializedStation< Waypoint, true >::Iterate().

Referenced by CmdRenameWaypoint().

◆ IsValidTileForWaypoint()

static CommandCost IsValidTileForWaypoint ( TileIndex  tile,
Axis  axis,
StationID *  waypoint 
)
static

Check whether the given tile is suitable for a waypoint.

Parameters
tilethe tile to check for suitability
axisthe axis of the waypoint
waypointWaypoint the waypoint to check for is already joined to. If we find another waypoint it can join to it will throw an error.

Definition at line 147 of file waypoint_cmd.cpp.

References ClearTile_Station(), DC_AUTO, GetStationIndex(), IsRailWaypoint(), IsTileType(), and MP_STATION.

◆ RemoveBuoy()

◆ RemoveRoadWaypointStop()

CommandCost RemoveRoadWaypointStop ( TileIndex  tile,
DoCommandFlag  flags,
int  replacement_spec_index 
)

Remove a road waypoint.

Parameters
tileTileIndex been queried
flagsoperation to perform
replacement_spec_indexreplacement spec index to avoid deallocating, if < 0, tile is not being replaced
Returns
cost or failure of operation

Definition at line 2255 of file station_cmd.cpp.

References _current_company, CheckOwnership(), DC_BANKRUPT, EnsureNoVehicleOnGround(), CommandCost::Failed(), SpecializedStation< Waypoint, true >::GetByTile(), BaseStation::owner, and OWNER_WATER.