mirror of https://github.com/OpenTTD/OpenTTD
Codechange: add and use TileOffsByAxis(...) over TileOffsByDir(DiagDirToAxis(...))
parent
7a71df2952
commit
38c9eb76a0
|
@ -108,6 +108,12 @@ TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
|
|||
return TileXY(x, y);
|
||||
}
|
||||
|
||||
/** 'Lookup table' for tile offsets given an Axis */
|
||||
extern const TileIndexDiffC _tileoffs_by_axis[] = {
|
||||
{ 1, 0}, ///< AXIS_X
|
||||
{ 0, 1}, ///< AXIS_Y
|
||||
};
|
||||
|
||||
/** 'Lookup table' for tile offsets given a DiagDirection */
|
||||
extern const TileIndexDiffC _tileoffs_by_diagdir[] = {
|
||||
{-1, 0}, ///< DIAGDIR_NE
|
||||
|
|
|
@ -543,6 +543,20 @@ uint DistanceMaxPlusManhattan(TileIndex, TileIndex); ///< Max + Manhattan
|
|||
uint DistanceFromEdge(TileIndex); ///< shortest distance from any edge of the map
|
||||
uint DistanceFromEdgeDir(TileIndex, DiagDirection); ///< distance from the map edge in given direction
|
||||
|
||||
/**
|
||||
* Convert an Axis to a TileIndexDiff
|
||||
*
|
||||
* @param axis The Axis
|
||||
* @return The resulting TileIndexDiff in southern direction (either SW or SE).
|
||||
*/
|
||||
inline TileIndexDiff TileOffsByAxis(Axis axis)
|
||||
{
|
||||
extern const TileIndexDiffC _tileoffs_by_axis[];
|
||||
|
||||
assert(IsValidAxis(axis));
|
||||
return ToTileIndexDiff(_tileoffs_by_axis[axis]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a DiagDirection to a TileIndexDiff
|
||||
*
|
||||
|
|
|
@ -70,7 +70,7 @@ struct ETileArea : TileArea {
|
|||
case TA_PLATFORM: {
|
||||
TileIndex start, end;
|
||||
Axis axis = GetRailStationAxis(tile);
|
||||
TileIndexDiff delta = TileOffsByDiagDir(AxisToDiagDir(axis));
|
||||
TileIndexDiff delta = TileOffsByAxis(axis);
|
||||
|
||||
for (end = tile; IsRailStationTile(end + delta) && IsCompatibleTrainStationTile(end + delta, tile); end += delta) { /* Nothing */ }
|
||||
for (start = tile; IsRailStationTile(start - delta) && IsCompatibleTrainStationTile(start - delta, tile); start -= delta) { /* Nothing */ }
|
||||
|
|
|
@ -233,7 +233,7 @@ CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis
|
|||
StationID est = INVALID_STATION;
|
||||
|
||||
/* Check whether the tiles we're building on are valid rail or not. */
|
||||
TileIndexDiff offset = TileOffsByDiagDir(AxisToDiagDir(OtherAxis(axis)));
|
||||
TileIndexDiff offset = TileOffsByAxis(OtherAxis(axis));
|
||||
for (int i = 0; i < count; i++) {
|
||||
TileIndex tile = start_tile + i * offset;
|
||||
CommandCost ret = IsValidTileForWaypoint(tile, axis, &est);
|
||||
|
@ -373,7 +373,7 @@ CommandCost CmdBuildRoadWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis
|
|||
if (ret.Failed()) return ret;
|
||||
|
||||
/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
|
||||
TileIndex center_tile = start_tile + (count / 2) * TileOffsByDiagDir(AxisToDiagDir(OtherAxis(axis)));;
|
||||
TileIndex center_tile = start_tile + (count / 2) * TileOffsByAxis(OtherAxis(axis));
|
||||
if (wp == nullptr && reuse) wp = FindDeletedWaypointCloseTo(center_tile, STR_SV_STNAME_WAYPOINT, _current_company, true);
|
||||
|
||||
if (wp != nullptr) {
|
||||
|
|
Loading…
Reference in New Issue