# ai_road.cpp File Reference

Implementation of AIRoad. More...

`#include "ai_road.hpp"`
`#include "ai_map.hpp"`
`#include "ai_station.hpp"`
`#include "ai_cargo.hpp"`
`#include "../../station_map.h"`
`#include "../../command_type.h"`
`#include "../../settings_type.h"`
`#include "../../company_func.h"`
`#include "../../script/squirrel_helper_type.hpp"`

Go to the source code of this file.

## Functions

static bool | CheckAutoExpandedRoadBits (const Array *existing, int32 start, int32 end)
| Check whether the given existing bits the start and end part can be build.
static int32 | LookupWithoutBuildOnSlopes (::Slope slope, const Array *existing, int32 start, int32 end)
| Lookup function for building road parts when building on slopes is disabled.
static int32 | RotateNeighbour (int32 neighbour)
| Rotate a neighbour bit a single time clockwise.
static RoadBits | NeighbourToRoadBits (int32 neighbour)
| Convert a neighbour to a road bit representation for easy internal use.
static int32 | LookupWithBuildOnSlopes (::Slope slope, Array *existing, int32 start, int32 end)
| Lookup function for building road parts when building on slopes is enabled.
static bool | NormaliseTileOffset (int32 *tile)
| Normalise all input data so we can easily handle it without needing to call the API lots of times or create large if-elseif-elseif-else constructs.
static bool | NeighbourHasReachableRoad (::RoadTypes rts, TileIndex start_tile, DiagDirection neighbour)
| Check whether one can reach (possibly by building) a road piece the center of the neighbouring tile.

## Detailed Description

Implementation of AIRoad.

Definition in file ai_road.cpp.

## Function Documentation

static bool CheckAutoExpandedRoadBits | ( | const Array * | existing,
|  | int32 | start,
|  | int32 | end |
| ) |  |  | `[static]`

Check whether the given existing bits the start and end part can be build.

As the function assumes the bits being build on a slope that does not allow level foundations all of the existing parts will always be in a straight line. This also needs to hold for the start and end parts, otherwise it is for sure not valid. Finally a check will be done to determine whether the existing road parts match the to-be-build parts. As they can only be placed in one direction, just checking the start part with the first existing part is enough.

Parameters:

  | existing | The existing road parts.
  | start | The part that should be build first.
  | end | The part that will be build second.

Returns:
  True if and only if the road bits can be build.

Definition at line 110 of file ai_road.cpp.

Referenced by LookupWithBuildOnSlopes(), and LookupWithoutBuildOnSlopes().

static int32 LookupWithBuildOnSlopes | ( | ::Slope | slope,
|  | Array * | existing,
|  | int32 | start,
|  | int32 | end |
| ) |  |  | `[static]`

Lookup function for building road parts when building on slopes is enabled.

Parameters:

  | slope | The slope of the tile to examine.
  | existing | The existing neighbours.
  | start | The part that should be build first.
  | end | The part that will be build second.

Returns:
  0 when the build parts do not connect, 1 when they do connect once they are build or 2 when building the first part automatically builds the second part.

Definition at line 189 of file ai_road.cpp.

References CheckAutoExpandedRoadBits(), IsSteepSlope(), lengthof, NeighbourToRoadBits(), ROAD_NE, ROAD_NONE, ROAD_NW, ROAD_SE, ROAD_SW, RotateNeighbour(), SLOPE_EW, SLOPE_FLAT, SLOPE_STEEP_E, SLOPE_STEEP_N, SLOPE_STEEP_S, SLOPE_STEEP_W, SLOPE_SW, SLOPE_W, and SLOPE_WSE.

Referenced by AIRoad::CanBuildConnectedRoadParts().

static int32 LookupWithoutBuildOnSlopes | ( | ::Slope | slope,
|  | const Array * | existing,
|  | int32 | start,
|  | int32 | end |
| ) |  |  | `[static]`

Lookup function for building road parts when building on slopes is disabled.

Parameters:

  | slope | The slope of the tile to examine.
  | existing | The existing road parts.
  | start | The part that should be build first.
  | end | The part that will be build second.

Returns:
  0 when the build parts do not connect, 1 when they do connect once they are build or 2 when building the first part automatically builds the second part.

Definition at line 125 of file ai_road.cpp.

References CheckAutoExpandedRoadBits(), SLOPE_FLAT, SLOPE_NE, SLOPE_NW, SLOPE_SE, and SLOPE_SW.

Referenced by AIRoad::CanBuildConnectedRoadParts().

static bool NeighbourHasReachableRoad | ( | ::RoadTypes | rts,
|  | TileIndex | start_tile,
|  | DiagDirection | neighbour |
| ) |  |  | `[static]`

Check whether one can reach (possibly by building) a road piece the center of the neighbouring tile.

This includes roads and (drive through) stations.

Parameters:

  | start_tile | The tile to "enter" the neighbouring tile.
  | neighbour | The direction to the neighbouring tile to "enter".

Returns:
  true if and only if the tile is reachable.

Definition at line 402 of file ai_road.cpp.

References DiagDirToAxis(), GetRoadStopDir(), GetTileType(), MP_ROAD, MP_STATION, and TileAddByDiagDir().

Referenced by AIRoad::GetNeighbourRoadCount().

static RoadBits NeighbourToRoadBits | ( | int32 | neighbour | ) | `[static]`

Convert a neighbour to a road bit representation for easy internal use.

Parameters:

  | neighbour | The neighbour.

Returns:
  The bits representing the direction.

Definition at line 168 of file ai_road.cpp.

References ROAD_NE, ROAD_NW, ROAD_SE, and ROAD_SW.

Referenced by LookupWithBuildOnSlopes().

static bool NormaliseTileOffset | ( | int32 * | tile | ) | `[static]`

Normalise all input data so we can easily handle it without needing to call the API lots of times or create large if-elseif-elseif-else constructs.

In this case it means that a TileXY(0, -1) becomes -2 and TileXY(0, 1) becomes 2. TileXY(-1, 0) and TileXY(1, 0) stay respectively -1 and 1. Any other value means that it is an invalid tile offset.

Parameters:

  | tile | The tile to normalise.

Returns:
  True if and only if the tile offset is valid.

Definition at line 337 of file ai_road.cpp.

References TileDiffXY().

Referenced by AIRoad::CanBuildConnectedRoadParts().

static int32 RotateNeighbour | ( | int32 | neighbour | ) | `[static]`

Rotate a neighbour bit a single time clockwise.

Parameters:

  | neighbour | The neighbour.

Returns:
  The rotate neighbour data.

Definition at line 152 of file ai_road.cpp.

Referenced by LookupWithBuildOnSlopes().