1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-24 12:44:10 +01:00

Codechange: Replace bitstuffed VehicleEnterTileStatus. (#14027)

VehicleEnterTileStatus was an bitset-style enum, but bitstuffed with a StationID. However the StationID part was only used by trains, and only in two locations.

Instead, return just the enum bitset. The two places which require the StationID just call GetStationIndex() directly.
This commit is contained in:
Peter Nelson
2025-04-20 21:10:02 +01:00
committed by GitHub
parent cb113cfed0
commit fc45bb5a2b
10 changed files with 67 additions and 81 deletions

View File

@@ -3696,12 +3696,12 @@ static bool ClickTile_Station(TileIndex tile)
return true;
}
static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
static VehicleEnterTileStates VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
{
if (v->type == VEH_TRAIN) {
StationID station_id = GetStationIndex(tile);
if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE;
if (!IsRailStation(tile) || !v->IsFrontEngine()) return VETSB_CONTINUE;
if (!v->current_order.ShouldStopAtStation(v, station_id)) return {};
if (!IsRailStation(tile) || !v->IsFrontEngine()) return {};
int station_ahead;
int station_length;
@@ -3711,7 +3711,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
* begin of the platform to the stop location is longer than the length
* of the platform. Station ahead 'includes' the current tile where the
* vehicle is on, so we need to subtract that. */
if (stop + station_ahead - (int)TILE_SIZE >= station_length) return VETSB_CONTINUE;
if (stop + station_ahead - (int)TILE_SIZE >= station_length) return {};
DiagDirection dir = DirToDiagDir(v->direction);
@@ -3724,7 +3724,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
stop &= TILE_SIZE - 1;
if (x == stop) {
return VETSB_ENTERED_STATION | static_cast<VehicleEnterTileStatus>(station_id.base() << VETS_STATION_ID_OFFSET); // enter station
return VehicleEnterTileState::EnteredStation; // enter station
} else if (x < stop) {
v->vehstatus.Set(VehState::TrainSlowing);
uint16_t spd = std::max(0, (stop - x) * 20 - 15);
@@ -3736,12 +3736,13 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
if (rv->state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)rv->state) && rv->frame == 0) {
if (IsStationRoadStop(tile) && rv->IsFrontEngine()) {
/* Attempt to allocate a parking bay in a road stop */
return RoadStop::GetByTile(tile, GetRoadStopType(tile))->Enter(rv) ? VETSB_CONTINUE : VETSB_CANNOT_ENTER;
if (RoadStop::GetByTile(tile, GetRoadStopType(tile))->Enter(rv)) return {};
return VehicleEnterTileState::CannotEnter;
}
}
}
return VETSB_CONTINUE;
return {};
}
/**