# waypoint.cpp File Reference

Handling of waypoints. More...

`#include "stdafx.h"`
`#include "command_func.h"`
`#include "landscape.h"`
`#include "rail.h"`
`#include "bridge_map.h"`
`#include "station_base.h"`
`#include "town.h"`
`#include "waypoint.h"`
`#include "yapf/yapf.h"`
`#include "strings_func.h"`
`#include "gfx_func.h"`
`#include "functions.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 "oldpool_func.h"`
`#include "viewport_func.h"`
`#include "train.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Functions
static void | UpdateWaypointSign (Waypoint *wp)
| Update the sign for the waypoint.
static void | RedrawWaypointSign (const Waypoint *wp)
| Redraw the sign of a waypoint.
void | UpdateAllWaypointSigns ()
| Update all signs.
static void | MakeDefaultWaypointName (Waypoint *wp)
| Set the default name for a waypoint.
static Waypoint * | FindDeletedWaypointCloseTo (TileIndex tile)
| Find a deleted waypoint close to a tile.
CommandCost | CmdBuildTrainWaypoint (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Convert existing rail to waypoint.
void | WaypointsDailyLoop ()
| Daily loop for waypoints.
CommandCost | RemoveTrainWaypoint (TileIndex tile, DoCommandFlag flags, bool justremove)
| Remove a waypoint.
CommandCost | CmdRemoveTrainWaypoint (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Delete a waypoint.
static bool | IsUniqueWaypointName (const char *name)
CommandCost | CmdRenameWaypoint (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Rename a waypoint.
Station * | ComposeWaypointStation (TileIndex tile)
| This hacks together some dummy one-shot Station structure for a waypoint.
void | DrawWaypointSprite (int x, int y, int stat_id, RailType railtype)
| Draw a waypoint.
void | InitializeWaypoints ()

## Detailed Description

Handling of waypoints.

Definition in file waypoint.cpp.

## Function Documentation

CommandCost CmdBuildTrainWaypoint | ( | TileIndex | 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:

  | tile | tile where waypoint will be built
  | flags | type of operation
  | p1 | graphics for waypoint type, 0 indicates standard graphics
  | p2 | unused

Todo:
  When checking for the tile slope, distingush between "Flat land required" and "land sloped in wrong direction"

Definition at line 159 of file waypoint.cpp.

References _date, _settings_game, AXIS_X, AXIS_Y, AxisToTrack(), ConstructionSettings::build_on_slopes, CMD_ERROR, GameSettings::construction, DC_EXEC, FindDeletedWaypointCloseTo(), GetCustomStationSpec(), GetNumCustomStations(), GetRailTileType(), GetRailType(), GetTileOwner(), GetTileSlope(), GetTrackBits(), GetTrackReservation(), HasBit(), InvalidateWindowData(), IsBridgeAbove(), IsSteepSlope(), IsTileType(), MakeDefaultWaypointName(), MarkTileDirtyByTile(), MayHaveBridgeAbove(), MP_RAILWAY, RAIL_TILE_NORMAL, RedrawWaypointSign(), return_cmd_error, SetDepotWaypointReservation(), SLOPE_FLAT, STAT_CLASS_WAYP, TRACK_BIT_X, TRACK_BIT_Y, UpdateWaypointSign(), and YapfNotifyTrackLayoutChange().

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

Delete a waypoint.

Parameters:

  | tile | tile where waypoint is to be deleted
  | flags | type of operation
  | p1 | unused
  | p2 | unused

Returns:
  cost of operation or error

Definition at line 321 of file waypoint.cpp.

References RemoveTrainWaypoint().

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

Returns:
  cost of operation or error

Definition at line 345 of file waypoint.cpp.

References CMD_ERROR, DC_EXEC, MakeDefaultWaypointName(), MarkWholeScreenDirty(), MAX_LENGTH_WAYPOINT_NAME_BYTES, return_cmd_error, StrEmpty(), and UpdateWaypointSign().

Station* ComposeWaypointStation | ( | TileIndex | tile | ) |

This hacks together some dummy one-shot Station structure for a waypoint.

Parameters:

  | tile | on which to work

Returns:
  pointer to a Station

Definition at line 379 of file waypoint.cpp.

References GetWaypointByTile().

void DrawWaypointSprite | ( | int | x,
|  | int | y,
|  | int | stat_id,
|  | RailType | railtype |
| ) |  |  |

Draw a waypoint.

Parameters:

  | x | coordinate
  | y | coordinate
  | stat_id | station id
  | railtype | RailType to use for

Definition at line 402 of file waypoint.cpp.

References AXIS_X, DrawStationTile(), and STAT_CLASS_WAYP.

static Waypoint* FindDeletedWaypointCloseTo | ( | TileIndex | tile | ) | `[static]`

Find a deleted waypoint close to a tile.

Parameters:

  | tile | to search from

Definition at line 130 of file waypoint.cpp.

References DistanceManhattan(), and OWNER_NONE.

Referenced by CmdBuildTrainWaypoint().

static void MakeDefaultWaypointName | ( | Waypoint * | wp | ) | `[static]`

Set the default name for a waypoint.

Parameters:

  | wp | Waypoint to work on

Definition at line 71 of file waypoint.cpp.

References HasBit(), and SetBit().

Referenced by CmdBuildTrainWaypoint(), and CmdRenameWaypoint().

static void RedrawWaypointSign | ( | const Waypoint * | wp | ) | `[static]`

Redraw the sign of a waypoint.

Parameters:

  | wp | Waypoint to redraw sign

Definition at line 46 of file waypoint.cpp.

References MarkAllViewportsDirty().

Referenced by CmdBuildTrainWaypoint(), and RemoveTrainWaypoint().

CommandCost RemoveTrainWaypoint | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | bool | justremove |
| ) |  |  |

Remove a waypoint.

Parameters:

  | tile | from which to remove waypoint
  | flags | type of operation
  | justremove | will indicate if it is removed from rail or if rails are removed too

Returns:
  cost of operation or error

Definition at line 273 of file waypoint.cpp.

References AddTrackToSignalBuffer(), CMD_ERROR, DC_EXEC, FreeTrainTrackReservation(), GetDepotWaypointReservation(), GetRailType(), GetRailWaypointBits(), GetRailWaypointTrack(), GetTrainForReservation(), GetWaypointByTile(), IsRailWaypointTile(), MarkTileDirtyByTile(), OWNER_WATER, RedrawWaypointSign(), SetTrackReservation(), TryPathReserve(), and YapfNotifyTrackLayoutChange().

Referenced by CmdRemoveTrainWaypoint().

static void UpdateWaypointSign | ( | Waypoint * | wp | ) | `[static]`

Update the sign for the waypoint.

Parameters:

  | wp | Waypoint to update sign

Definition at line 36 of file waypoint.cpp.

References TILE_SIZE, TileX(), TileY(), Point::x, and Point::y.

Referenced by CmdBuildTrainWaypoint(), CmdRenameWaypoint(), and UpdateAllWaypointSigns().

void WaypointsDailyLoop | ( |  | ) |

Daily loop for waypoints.

Functions used by the IncreaseDate function.

Definition at line 256 of file waypoint.cpp.