diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index efc4faa314..4250b0b9cd 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -379,8 +379,7 @@ void AnimateRoadStopTile(TileIndex tile) void TriggerRoadStopAnimation(BaseStation *st, TileIndex trigger_tile, StationAnimationTrigger trigger, CargoType cargo_type) { - /* Get Station if it wasn't supplied */ - if (st == nullptr) st = BaseStation::GetByTile(trigger_tile); + assert(st != nullptr); /* Check the cached animation trigger bitmask to see if we need * to bother with any further processing. */ @@ -417,12 +416,13 @@ void TriggerRoadStopAnimation(BaseStation *st, TileIndex trigger_tile, StationAn * @param trigger trigger type * @param cargo_type cargo type causing the trigger */ -void TriggerRoadStopRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type) +void TriggerRoadStopRandomisation(BaseStation *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type) { - if (st == nullptr) st = Station::GetByTile(tile); + assert(st != nullptr); /* Check the cached cargo trigger bitmask to see if we need - * to bother with any further processing. */ + * to bother with any further processing. + * Note: cached_roadstop_cargo_triggers must be non-zero even for cargo-independent triggers. */ if (st->cached_roadstop_cargo_triggers == 0) return; if (IsValidCargoType(cargo_type) && !HasBit(st->cached_roadstop_cargo_triggers, cargo_type)) return; @@ -431,7 +431,10 @@ void TriggerRoadStopRandomisation(Station *st, TileIndex tile, StationRandomTrig uint32_t whole_reseed = 0; /* Bitmask of completely empty cargo types to be matched. */ - CargoTypes empty_mask = (trigger == StationRandomTrigger::CargoTaken) ? GetEmptyMask(st) : 0; + CargoTypes empty_mask{}; + if (trigger == StationRandomTrigger::CargoTaken) { + empty_mask = GetEmptyMask(Station::From(st)); + } StationRandomTriggers used_random_triggers; auto process_tile = [&](TileIndex cur_tile) { diff --git a/src/newgrf_roadstop.h b/src/newgrf_roadstop.h index 9064f96735..13ac38fed1 100644 --- a/src/newgrf_roadstop.h +++ b/src/newgrf_roadstop.h @@ -176,7 +176,7 @@ uint16_t GetRoadStopCallback(CallbackID callback, uint32_t param1, uint32_t para void AnimateRoadStopTile(TileIndex tile); uint8_t GetRoadStopTileAnimationSpeed(TileIndex tile); void TriggerRoadStopAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoType cargo_type = INVALID_CARGO); -void TriggerRoadStopRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type = INVALID_CARGO); +void TriggerRoadStopRandomisation(BaseStation *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type = INVALID_CARGO); bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype); bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype); diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 76ddb07800..f59f18daf3 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -909,8 +909,7 @@ void TriggerStationAnimation(BaseStation *st, TileIndex trigger_tile, StationAni TA_TILE, TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_WHOLE }; - /* Get Station if it wasn't supplied */ - if (st == nullptr) st = BaseStation::GetByTile(trigger_tile); + assert(st != nullptr); /* Check the cached animation trigger bitmask to see if we need * to bother with any further processing. */ @@ -943,18 +942,18 @@ void TriggerStationAnimation(BaseStation *st, TileIndex trigger_tile, StationAni * @param trigger trigger type * @param cargo_type cargo type causing trigger */ -void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRandomTrigger trigger, CargoType cargo_type) +void TriggerStationRandomisation(BaseStation *st, TileIndex trigger_tile, StationRandomTrigger trigger, CargoType cargo_type) { /* List of coverage areas for each animation trigger */ static const TriggerArea tas[] = { TA_WHOLE, TA_WHOLE, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM, TA_PLATFORM }; - /* Get Station if it wasn't supplied */ - if (st == nullptr) st = Station::GetByTile(trigger_tile); + assert(st != nullptr); /* Check the cached cargo trigger bitmask to see if we need - * to bother with any further processing. */ + * to bother with any further processing. + * Note: cached_cargo_triggers must be non-zero even for cargo-independent triggers. */ if (st->cached_cargo_triggers == 0) return; if (IsValidCargoType(cargo_type) && !HasBit(st->cached_cargo_triggers, cargo_type)) return; @@ -962,7 +961,10 @@ void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRan ETileArea area = ETileArea(st, trigger_tile, tas[static_cast(trigger)]); /* Bitmask of completely empty cargo types to be matched. */ - CargoTypes empty_mask = (trigger == StationRandomTrigger::CargoTaken) ? GetEmptyMask(st) : 0; + CargoTypes empty_mask{}; + if (trigger == StationRandomTrigger::CargoTaken) { + empty_mask = GetEmptyMask(Station::From(st)); + } /* Store triggers now for var 5F */ st->waiting_random_triggers.Set(trigger); diff --git a/src/newgrf_station.h b/src/newgrf_station.h index d6a8aa9df8..ef3bcbee01 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -213,7 +213,7 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID void AnimateStationTile(TileIndex tile); void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoType cargo_type = INVALID_CARGO); -void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type = INVALID_CARGO); +void TriggerStationRandomisation(BaseStation *st, TileIndex tile, StationRandomTrigger trigger, CargoType cargo_type = INVALID_CARGO); void StationUpdateCachedTriggers(BaseStation *st); #endif /* NEWGRF_STATION_H */ diff --git a/src/pathfinder/yapf/yapf_rail.cpp b/src/pathfinder/yapf/yapf_rail.cpp index af0725f501..21563b2d9a 100644 --- a/src/pathfinder/yapf/yapf_rail.cpp +++ b/src/pathfinder/yapf/yapf_rail.cpp @@ -80,7 +80,8 @@ private: tile = TileAdd(tile, diff); } while (IsCompatibleTrainStationTile(tile, start) && tile != this->origin_tile); - TriggerStationRandomisation(nullptr, start, StationRandomTrigger::PathReservation); + auto *st = Station::GetByTile(start); + TriggerStationRandomisation(st, start, StationRandomTrigger::PathReservation); return true; } diff --git a/src/pbs.cpp b/src/pbs.cpp index e567574609..917ca48988 100644 --- a/src/pbs.cpp +++ b/src/pbs.cpp @@ -113,7 +113,10 @@ bool TryReserveRailTrack(TileIndex tile, Track t, bool trigger_stations) case MP_STATION: if (HasStationRail(tile) && !HasStationReservation(tile)) { SetRailStationReservation(tile, true); - if (trigger_stations && IsRailStation(tile)) TriggerStationRandomisation(nullptr, tile, StationRandomTrigger::PathReservation); + if (trigger_stations && IsRailStation(tile)) { + auto *st = Station::GetByTile(tile); + TriggerStationRandomisation(st, tile, StationRandomTrigger::PathReservation); + } MarkTileDirtyByTile(tile); // some GRFs need redraw after reserving track return true; }