Codechange: split GetRoadDir as bays have DiagDir and drive throughs have Axis

This commit is contained in:
Rubidium
2024-10-22 23:25:07 +02:00
committed by rubidium42
parent d6aa09f96a
commit c9819f8957
11 changed files with 100 additions and 56 deletions

View File

@@ -64,9 +64,8 @@ void RoadStop::MakeDriveThrough()
assert(this->east == nullptr && this->west == nullptr);
RoadStopType rst = GetRoadStopType(this->xy);
DiagDirection dir = GetRoadStopDir(this->xy);
/* Use absolute so we always go towards the northern tile */
TileIndexDiff offset = abs(TileOffsByDiagDir(dir));
Axis axis = GetDriveThroughStopAxis(this->xy);
TileIndexDiff offset = TileOffsByAxis(axis);
/* Information about the tile north of us */
TileIndex north_tile = this->xy - offset;
@@ -132,9 +131,8 @@ void RoadStop::ClearDriveThrough()
assert(this->east != nullptr && this->west != nullptr);
RoadStopType rst = GetRoadStopType(this->xy);
DiagDirection dir = GetRoadStopDir(this->xy);
/* Use absolute so we always go towards the northern tile */
TileIndexDiff offset = abs(TileOffsByDiagDir(dir));
Axis axis = GetDriveThroughStopAxis(this->xy);
TileIndexDiff offset = TileOffsByAxis(axis);
/* Information about the tile north of us */
TileIndex north_tile = this->xy - offset;
@@ -307,8 +305,8 @@ void RoadStop::Entry::Enter(const RoadVehicle *rv)
return IsTileType(next, MP_STATION) &&
GetStationIndex(next) == GetStationIndex(rs) &&
GetStationType(next) == GetStationType(rs) &&
GetRoadStopDir(next) == GetRoadStopDir(rs) &&
IsDriveThroughStopTile(next);
IsDriveThroughStopTile(next) &&
GetDriveThroughStopAxis(next) == GetDriveThroughStopAxis(rs);
}
typedef std::list<const RoadVehicle *> RVList; ///< A list of road vehicles
@@ -344,6 +342,21 @@ Vehicle *FindVehiclesInRoadStop(Vehicle *v, void *data)
return nullptr;
}
/**
* Get the DiagDirection for entering the drive through stop from the given 'side' (east or west) on the given axis.
* @param east Enter from the east when true or from the west when false.
* @param axis The axis of the drive through stop.
* @return The DiagDirection the vehicles far when entering 'our' side of the drive through stop.
*/
static DiagDirection GetEntryDirection(bool east, Axis axis)
{
switch (axis) {
case AXIS_X: return east ? DIAGDIR_NE : DIAGDIR_SW;
case AXIS_Y: return east ? DIAGDIR_SE : DIAGDIR_NW;
default: NOT_REACHED();
}
}
/**
* Rebuild, from scratch, the vehicles and other metadata on this stop.
* @param rs the roadstop this entry is part of
@@ -353,14 +366,14 @@ void RoadStop::Entry::Rebuild(const RoadStop *rs, int side)
{
assert(HasBit(rs->status, RSSFB_BASE_ENTRY));
DiagDirection dir = GetRoadStopDir(rs->xy);
Axis axis = GetDriveThroughStopAxis(rs->xy);
if (side == -1) side = (rs->east == this);
RoadStopEntryRebuilderHelper rserh;
rserh.dir = side ? dir : ReverseDiagDir(dir);
rserh.dir = GetEntryDirection(side, axis);
this->length = 0;
TileIndexDiff offset = abs(TileOffsByDiagDir(dir));
TileIndexDiff offset = TileOffsByAxis(axis);
for (TileIndex tile = rs->xy; IsDriveThroughRoadStopContinuation(rs->xy, tile); tile += offset) {
this->length += TILE_SIZE;
FindVehicleOnPos(tile, &rserh, FindVehiclesInRoadStop);
@@ -382,7 +395,8 @@ void RoadStop::Entry::CheckIntegrity(const RoadStop *rs) const
if (!HasBit(rs->status, RSSFB_BASE_ENTRY)) return;
/* The tile 'before' the road stop must not be part of this 'line' */
assert(!IsDriveThroughRoadStopContinuation(rs->xy, rs->xy - abs(TileOffsByDiagDir(GetRoadStopDir(rs->xy)))));
assert(IsDriveThroughStopTile(rs->xy));
assert(!IsDriveThroughRoadStopContinuation(rs->xy, rs->xy - TileOffsByAxis(GetDriveThroughStopAxis(rs->xy))));
Entry temp;
temp.Rebuild(rs, rs->east == this);