# waypoint.cpp File Reference

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "command_func.h"`
`#include "landscape.h"`
`#include "order.h"`
`#include "rail_map.h"`
`#include "rail.h"`
`#include "bridge_map.h"`
`#include "saveload.h"`
`#include "station.h"`
`#include "town.h"`
`#include "waypoint.h"`
`#include "variables.h"`
`#include "yapf/yapf.h"`
`#include "newgrf.h"`
`#include "strings_func.h"`
`#include "gfx_func.h"`
`#include "functions.h"`
`#include "window_func.h"`
`#include "economy_func.h"`
`#include "date_func.h"`
`#include "vehicle_func.h"`
`#include "vehicle_base.h"`
`#include "string_func.h"`
`#include "signal_func.h"`
`#include "player_func.h"`
`#include "settings_type.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.
void | AfterLoadWaypoints ()
| Update waypoint graphics id against saved GRFID/localidx.
CommandCost | CmdBuildTrainWaypoint (TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
| Convert existing rail to waypoint.
void | WaypointsDailyLoop ()
| Daily loop for waypoints.
CommandCost | RemoveTrainWaypoint (TileIndex tile, uint32 flags, bool justremove)
| Remove a waypoint.
CommandCost | CmdRemoveTrainWaypoint (TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
| Delete a waypoint.
static bool | IsUniqueWaypointName (const char *name)
CommandCost | CmdRenameWaypoint (TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
| 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 | FixOldWaypoints ()
| Fix savegames which stored waypoints in their old format.
void | InitializeWaypoints ()
static void | Save_WAYP ()
static void | Load_WAYP ()
## Variables
static const SaveLoad | _waypoint_desc []
const ChunkHandler | _waypoint_chunk_handlers []

## Detailed Description

Definition in file waypoint.cpp.

## Function Documentation

void AfterLoadWaypoints | ( |  | ) |

Update waypoint graphics id against saved GRFID/localidx.

This is to ensure the chosen graphics are correct if GRF files are changed.

Definition at line 159 of file waypoint.cpp.

References GetCustomStationSpec(), GetNumCustomStations(), and STAT_CLASS_WAYP.

Referenced by ReloadNewGRFData().

CommandCost CmdBuildTrainWaypoint | ( | TileIndex | tile,
|  | uint32 | flags,
|  | uint32 | p1,
|  | uint32 | p2 |
| ) |  |  |

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 188 of file waypoint.cpp.

References AXIS_X, AXIS_Y, AxisToTrack(), CMD_ERROR, DC_EXEC, FindDeletedWaypointCloseTo(), GetCustomStationSpec(), GetNumCustomStations(), GetRailTileType(), GetRailType(), GetTileOwner(), GetTrackBits(), IsBridgeAbove(), IsSteepSlope(), IsTileType(), MakeDefaultWaypointName(), MarkTileDirtyByTile(), MayHaveBridgeAbove(), MP_RAILWAY, RAIL_TILE_NORMAL, RedrawWaypointSign(), return_cmd_error, SLOPE_FLAT, STAT_CLASS_WAYP, TRACK_BIT_X, TRACK_BIT_Y, UpdateWaypointSign(), and YapfNotifyTrackLayoutChange().

CommandCost CmdRemoveTrainWaypoint | ( | TileIndex | tile,
|  | uint32 | flags,
|  | uint32 | p1,
|  | uint32 | p2 |
| ) |  |  |

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 338 of file waypoint.cpp.

References RemoveTrainWaypoint().

CommandCost CmdRenameWaypoint | ( | TileIndex | tile,
|  | uint32 | flags,
|  | uint32 | p1,
|  | uint32 | p2 |
| ) |  |  |

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 365 of file waypoint.cpp.

References _cmd_text, CMD_ERROR, DC_EXEC, IsTileType(), MakeDefaultWaypointName(), MarkWholeScreenDirty(), MP_RAILWAY, return_cmd_error, 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 402 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 425 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 136 of file waypoint.cpp.

References DistanceManhattan().

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 77 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 52 of file waypoint.cpp.

References MarkAllViewportsDirty().

Referenced by CmdBuildTrainWaypoint(), and RemoveTrainWaypoint().

CommandCost RemoveTrainWaypoint | ( | TileIndex | tile,
|  | uint32 | 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 297 of file waypoint.cpp.

References AddTrackToSignalBuffer(), CMD_ERROR, DC_EXEC, GetRailType(), GetRailWaypointBits(), GetRailWaypointTrack(), GetTileOwner(), GetWaypointByTile(), IsRailWaypoint(), IsTileType(), MarkTileDirtyByTile(), MP_RAILWAY, OWNER_WATER, RedrawWaypointSign(), 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 42 of file waypoint.cpp.

References TILE_SIZE, TileX(), and TileY().

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

void WaypointsDailyLoop | ( |  | ) |

Daily loop for waypoints.

Functions used by the IncreaseDate function.

Definition at line 280 of file waypoint.cpp.

## Variable Documentation

const ChunkHandler _waypoint_chunk_handlers[]

Initial value:

     {
      { 'CHKP', Save_WAYP, Load_WAYP, CH_ARRAY | CH_LAST},
    }

const SaveLoad _waypoint_desc[]`[static]`

Initial value:

     {
      SLE_CONDVAR(Waypoint, xy,         SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
      SLE_CONDVAR(Waypoint, xy,         SLE_UINT32,                  6, SL_MAX_VERSION),
      SLE_CONDVAR(Waypoint, town_index, SLE_UINT16,                 12, SL_MAX_VERSION),
      SLE_CONDVAR(Waypoint, town_cn,    SLE_FILE_U8 | SLE_VAR_U16,  12, 88),
      SLE_CONDVAR(Waypoint, town_cn,    SLE_UINT16,                 89, SL_MAX_VERSION),
      SLE_CONDVAR(Waypoint, string,     SLE_STRINGID,                0, 83),
      SLE_CONDSTR(Waypoint, name,       SLE_STR, 0,                 84, SL_MAX_VERSION),
          SLE_VAR(Waypoint, deleted,    SLE_UINT8),

      SLE_CONDVAR(Waypoint, build_date, SLE_FILE_U16 | SLE_VAR_I32,  3, 30),
      SLE_CONDVAR(Waypoint, build_date, SLE_INT32,                  31, SL_MAX_VERSION),
      SLE_CONDVAR(Waypoint, localidx,   SLE_UINT8,                   3, SL_MAX_VERSION),
      SLE_CONDVAR(Waypoint, grfid,      SLE_UINT32,                 17, SL_MAX_VERSION),

    }

Definition at line 476 of file waypoint.cpp.