Functions

waypoint_cmd.cpp File Reference

Command Handling for waypoints. More...

#include "stdafx.h"
#include "cmd_helper.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 "strings_func.h"
#include "viewport_func.h"
#include "window_func.h"
#include "date_func.h"
#include "vehicle_func.h"
#include "string_func.h"
#include "company_func.h"
#include "newgrf_station.h"
#include "company_base.h"
#include "water.h"
#include "company_gui.h"
#include "table/strings.h"

Go to the source code of this file.

Functions

static WaypointFindDeletedWaypointCloseTo (TileIndex tile, StringID str, CompanyID cid)
 Find a deleted waypoint close to a tile.
Axis GetAxisForNewWaypoint (TileIndex tile)
 Get the axis for a new waypoint.
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.
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.
CommandCost FindJoiningWaypoint (StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp)
 Find a nearby waypoint that joins this waypoint.
CommandCost CanExpandRailStation (const BaseStation *st, TileArea &new_ta, Axis axis)
 Check whether we can expand the rail part of the given station.
CommandCost CmdBuildRailWaypoint (TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Convert existing rail to waypoint.
CommandCost CmdBuildBuoy (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build a buoy.
CommandCost RemoveBuoy (TileIndex tile, DoCommandFlag flags)
 Remove a buoy.
static bool IsUniqueWaypointName (const char *name)
 Check whether the name is unique amongst the waypoints.
CommandCost CmdRenameWaypoint (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Rename a waypoint.

Detailed Description

Command Handling for waypoints.

Definition in file waypoint_cmd.cpp.


Function Documentation

CommandCost CanExpandRailStation ( const BaseStation st,
TileArea new_ta,
Axis  axis 
)

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

Parameters:
st the station to expand
new_ta the current (and if all is fine new) tile area of the rail part of the station
axis the axis of the newly build rail
Returns:
Succeeded or failed command.

Definition at line 979 of file station_cmd.cpp.

References _settings_game, OrthogonalTileArea::h, max(), min(), return_cmd_error, GameSettings::station, StationSettings::station_spread, OrthogonalTileArea::tile, TileX(), TileXY(), TileY(), BaseStation::train_station, and OrthogonalTileArea::w.

Referenced by CmdBuildRailStation(), and CmdBuildRailWaypoint().

CommandCost ClearTile_Station ( TileIndex  tile,
DoCommandFlag  flags 
)

Clear a single tile of a station.

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

Definition at line 4015 of file station_cmd.cpp.

References CanRemoveRoadWithStop(), CMD_ERROR, DC_AUTO, GetStationType(), HasTileRoadType(), IsDriveThroughStopTile(), RemoveAirport(), RemoveBuoy(), RemoveDock(), RemoveRailStation(), RemoveRailWaypoint(), RemoveRoadStop(), return_cmd_error, ROADTYPE_TRAM, and SetDParam().

Referenced by CheckFlatLandRailStation(), CheckFlatLandRoadStop(), and IsValidTileForWaypoint().

CommandCost CmdBuildBuoy ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)
CommandCost CmdBuildRailWaypoint ( TileIndex  start_tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Convert existing rail to waypoint.

Eg build a waypoint station over piece of rail

Parameters:
start_tile northern most tile where waypoint will be built
flags type of operation
p1 various bitstuffed elements

  • p1 = (bit 4) - orientation (Axis)
  • p1 = (bit 8-15) - width of waypoint
  • p1 = (bit 16-23) - height of waypoint
  • p1 = (bit 24) - allow waypoints directly adjacent to other waypoints.
p2 various bitstuffed elements

  • p2 = (bit 0- 7) - custom station class
  • p2 = (bit 8-15) - custom station id
text unused
Returns:
the cost of this operation or an error

Definition at line 159 of file waypoint_cmd.cpp.

References _current_company, _date, _settings_game, AllocaM, AllocateSpecToStation(), AXIS_X, AxisToDiagDir(), AxisToTrack(), BaseStation::build_date, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_station_pool >::CanAllocateItem(), CanExpandRailStation(), CMD_ERROR, DC_EXEC, DeallocateSpecFromStation(), BaseStation::delete_ctr, DirtyCompanyInfrastructureWindows(), StationSettings::distant_join_stations, EXPENSES_CONSTRUCTION, BaseStation::facilities, CommandCost::Failed(), FindDeletedWaypointCloseTo(), FindJoiningWaypoint(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), NewGRFClass< Tspec, Tid, Tmax >::Get(), GetCustomStationSpecIndex(), GetRailReservationTrackBits(), GetRailType(), GetStationLayout(), GetTileOwner(), HasBit(), HasStationReservation(), HasStationTileRail(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Company::infrastructure, INVALID_TILE, BaseStation::IsInUse(), IsTileType(), SpecializedStation< Waypoint, true >::IsValidID(), IsValidTileForWaypoint(), MakeDefaultName(), MakeRailWaypoint(), MarkTileDirtyByTile(), MP_RAILWAY, OtherAxis(), BaseStation::owner, BaseStation::rect, return_cmd_error, SetCustomStationSpecIndex(), SetRailStationReservation(), STAT_CLASS_WAYP, CompanyInfrastructure::station, GameSettings::station, StationSettings::station_spread, BaseStation::string_id, OrthogonalTileArea::tile, TileOffsByDiagDir(), BaseStation::town, BaseStation::train_station, Waypoint::UpdateVirtCoord(), BaseStation::xy, and YapfNotifyTrackLayoutChange().

CommandCost CmdRenameWaypoint ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Rename a waypoint.

Parameters:
tile unused
flags type of operation
p1 id of waypoint
p2 unused
text the new name or an empty string when resetting to the default
Returns:
the cost of this operation or an error

Definition at line 398 of file waypoint_cmd.cpp.

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

static Waypoint* FindDeletedWaypointCloseTo ( TileIndex  tile,
StringID  str,
CompanyID  cid 
) [static]

Find a deleted waypoint close to a tile.

Parameters:
tile to search from
str the string to get the 'type' of
cid previous owner of the waypoint
Returns:
the deleted nearby waypoint

Definition at line 54 of file waypoint_cmd.cpp.

References DistanceManhattan(), FOR_ALL_WAYPOINTS, BaseStation::IsInUse(), BaseStation::owner, BaseStation::string_id, and BaseStation::xy.

Referenced by CmdBuildBuoy(), and CmdBuildRailWaypoint().

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

Find a nearby waypoint that joins this waypoint.

Parameters:
existing_waypoint an existing waypoint we build over
waypoint_to_join the waypoint to join to
adjacent whether adjacent waypoints are allowed
ta the area of the newly build waypoint
wp 'return' pointer for the found waypoint
Returns:
command cost with the error or 'okay'

Definition at line 1119 of file station_cmd.cpp.

Referenced by CmdBuildRailWaypoint().

Axis GetAxisForNewWaypoint ( TileIndex  tile  ) 

Get the axis for a new 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:
tile the tile to look at.
Returns:
the axis for the to-be-build waypoint.

Definition at line 80 of file waypoint_cmd.cpp.

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

Referenced by IsValidTileForWaypoint(), and PlaceRail_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.

Parameters:
layout The layout to write to.
numtracks The number of tracks to write.
plat_len The length of the platforms.
statspec The specification of the station to (possibly) get the layout from.

Definition at line 1024 of file station_cmd.cpp.

Referenced by CmdBuildRailStation(), and CmdBuildRailWaypoint().

static bool IsUniqueWaypointName ( const char *  name  )  [static]

Check whether the name is unique amongst the waypoints.

Parameters:
name The name to check.
Returns:
True iff the name is unique.

Definition at line 378 of file waypoint_cmd.cpp.

References FOR_ALL_WAYPOINTS, and BaseStation::name.

Referenced by CmdRenameWaypoint().

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

Check whether the given tile is suitable for a waypoint.

Parameters:
tile the tile to check for suitability
axis the axis of the waypoint
waypoint Waypoint 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 103 of file waypoint_cmd.cpp.

References _settings_game, ConstructionSettings::build_on_slopes, CheckOwnership(), ClearTile_Station(), GameSettings::construction, DC_AUTO, EnsureNoVehicleOnGround(), CommandCost::Failed(), GetAxisForNewWaypoint(), GetStationIndex(), GetTileOwner(), GetTileSlope(), IsBridgeAbove(), IsRailWaypoint(), IsSteepSlope(), IsTileType(), MayHaveBridgeAbove(), MP_STATION, return_cmd_error, SLOPE_FLAT, and CommandCost::Succeeded().

Referenced by CmdBuildRailWaypoint().

CommandCost RemoveBuoy ( TileIndex  tile,
DoCommandFlag  flags 
)