Implementation of AIRoad. More...
#include "../../stdafx.h"
#include "ai_map.hpp"
#include "ai_station.hpp"
#include "ai_cargo.hpp"
#include "../../station_base.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. |
Implementation of AIRoad.
Definition in file ai_road.cpp.
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.
existing | The existing road parts. | |
start | The part that should be build first. | |
end | The part that will be build second. |
Definition at line 115 of file ai_road.cpp.
References Array::array, and Array::size.
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.
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. |
Definition at line 194 of file ai_road.cpp.
References Array::array, CheckAutoExpandedRoadBits(), IsSteepSlope(), lengthof, NeighbourToRoadBits(), ROAD_E, ROAD_N, ROAD_NE, ROAD_S, ROAD_SW, ROAD_W, ROAD_X, ROAD_Y, RotateNeighbour(), Array::size, 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.
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. |
Definition at line 130 of file ai_road.cpp.
References CheckAutoExpandedRoadBits(), Array::size, 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.
rts | The road type we want to know reachability for | |
start_tile | The tile to "enter" the neighbouring tile. | |
neighbour | The direction to the neighbouring tile to "enter". |
Definition at line 408 of file ai_road.cpp.
References DiagDirToAxis(), GetRoadStopDir(), GetRoadTileType(), GetRoadTypes(), GetTileType(), IsDriveThroughStopTile(), 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.
neighbour | The neighbour. |
Definition at line 173 of file ai_road.cpp.
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.
tile | The tile to normalise. |
Definition at line 342 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.
neighbour | The neighbour. |
Definition at line 157 of file ai_road.cpp.
Referenced by LookupWithBuildOnSlopes().