diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index 3bccc60d76..c709da6197 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -68,6 +68,20 @@ uint32 RoadStopScopeResolver::GetTriggers() const uint32 RoadStopScopeResolver::GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const { + auto get_road_type_variable = [&](RoadTramType rtt) -> uint32 { + RoadType rt; + if (this->tile == INVALID_TILE) { + rt = (GetRoadTramType(this->roadtype) == rtt) ? this->roadtype : INVALID_ROADTYPE; + } else { + rt = GetRoadType(this->tile, rtt); + } + if (rt == INVALID_ROADTYPE) { + return 0xFFFFFFFF; + } else { + return GetReverseRoadTypeTranslation(rt, this->roadstopspec->grf_prop.grffile); + } + }; + switch (variable) { /* View/rotation */ case 0x40: return this->view; @@ -82,10 +96,10 @@ uint32 RoadStopScopeResolver::GetVariable(uint16 variable, uint32 parameter, Get case 0x42: return this->tile == INVALID_TILE ? 0 : GetTerrainType(this->tile, TCX_NORMAL); // terrain_type /* Road type */ - case 0x43: return this->tile == INVALID_TILE ? 0 : GetReverseRoadTypeTranslation(GetRoadTypeRoad(this->tile), this->roadstopspec->grf_prop.grffile); + case 0x43: return get_road_type_variable(RTT_ROAD); /* Tram type */ - case 0x44: return this->tile == INVALID_TILE ? 0 : GetReverseRoadTypeTranslation(GetRoadTypeTram(this->tile), this->roadstopspec->grf_prop.grffile); + case 0x44: return get_road_type_variable(RTT_TRAM); /* Town zone and Manhattan distance of closest town */ case 0x45: { @@ -175,9 +189,9 @@ const SpriteGroup *RoadStopResolverObject::ResolveReal(const RealSpriteGroup *gr return group->loading[0]; } -RoadStopResolverObject::RoadStopResolverObject(const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, const RoadTypeInfo *rti, StationType type, uint8 view, +RoadStopResolverObject::RoadStopResolverObject(const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, RoadType roadtype, StationType type, uint8 view, CallbackID callback, uint32 param1, uint32 param2) - : ResolverObject(roadstopspec->grf_prop.grffile, callback, param1, param2), roadstop_scope(*this, st, roadstopspec, tile, rti, type, view) + : ResolverObject(roadstopspec->grf_prop.grffile, callback, param1, param2), roadstop_scope(*this, st, roadstopspec, tile, roadtype, type, view) { this->town_scope = nullptr; @@ -228,9 +242,9 @@ TownScopeResolver* RoadStopResolverObject::GetTown() return this->town_scope; } -uint16 GetRoadStopCallback(CallbackID callback, uint32 param1, uint32 param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, const RoadTypeInfo *rti, StationType type, uint8 view) +uint16 GetRoadStopCallback(CallbackID callback, uint32 param1, uint32 param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, RoadType roadtype, StationType type, uint8 view) { - RoadStopResolverObject object(roadstopspec, st, tile, rti, type, view, callback, param1, param2); + RoadStopResolverObject object(roadstopspec, st, tile, roadtype, type, view, callback, param1, param2); return object.ResolveCallback(); } @@ -249,7 +263,7 @@ void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, assert(spec != nullptr); const RoadTypeInfo *rti = GetRoadTypeInfo(roadtype); - RoadStopResolverObject object(spec, nullptr, INVALID_TILE, rti, type, view); + RoadStopResolverObject object(spec, nullptr, INVALID_TILE, roadtype, type, view); const SpriteGroup *group = object.Resolve(); if (group == nullptr || group->type != SGT_TILELAYOUT) return; const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(nullptr); @@ -297,7 +311,7 @@ void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, /** Wrapper for animation control, see GetRoadStopCallback. */ uint16 GetAnimRoadStopCallback(CallbackID callback, uint32 param1, uint32 param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, int extra_data) { - return GetRoadStopCallback(callback, param1, param2, roadstopspec, st, tile, nullptr, GetStationType(tile), GetStationGfx(tile)); + return GetRoadStopCallback(callback, param1, param2, roadstopspec, st, tile, INVALID_ROADTYPE, GetStationType(tile), GetStationGfx(tile)); } struct RoadStopAnimationFrameAnimationHelper { @@ -405,7 +419,7 @@ void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTri } if (cargo_type == CT_INVALID || HasBit(ss->cargo_triggers, cargo_type)) { - RoadStopResolverObject object(ss, st, cur_tile, nullptr, GetStationType(cur_tile), GetStationGfx(cur_tile)); + RoadStopResolverObject object(ss, st, cur_tile, INVALID_ROADTYPE, GetStationType(cur_tile), GetStationGfx(cur_tile)); object.waiting_triggers = st->waiting_triggers; const SpriteGroup *group = object.Resolve(); diff --git a/src/newgrf_roadstop.h b/src/newgrf_roadstop.h index 092b3a1948..4b8d62ceac 100644 --- a/src/newgrf_roadstop.h +++ b/src/newgrf_roadstop.h @@ -80,10 +80,10 @@ struct RoadStopScopeResolver : public ScopeResolver { CargoID cargo_type; ///< Type of cargo of the station. StationType type; ///< Station type. uint8 view; ///< Station axis. - const RoadTypeInfo *rti; ///< Road type info + RoadType roadtype; ///< Road type (used when no tile) - RoadStopScopeResolver(ResolverObject& ro, BaseStation* st, const RoadStopSpec *roadstopspec, TileIndex tile, const RoadTypeInfo *rti, StationType type, uint8 view = 0) - : ScopeResolver(ro), tile(tile), st(st), roadstopspec(roadstopspec), type(type), view(view), rti(rti) + RoadStopScopeResolver(ResolverObject& ro, BaseStation* st, const RoadStopSpec *roadstopspec, TileIndex tile, RoadType roadtype, StationType type, uint8 view = 0) + : ScopeResolver(ro), tile(tile), st(st), roadstopspec(roadstopspec), type(type), view(view), roadtype(roadtype) { } @@ -99,7 +99,7 @@ struct RoadStopResolverObject : public ResolverObject { RoadStopScopeResolver roadstop_scope; ///< The stop scope resolver. TownScopeResolver *town_scope; ///< The town scope resolver (created on the first call). - RoadStopResolverObject(const RoadStopSpec* roadstopspec, BaseStation* st, TileIndex tile, const RoadTypeInfo *rti, StationType type, uint8 view, CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0); + RoadStopResolverObject(const RoadStopSpec* roadstopspec, BaseStation* st, TileIndex tile, RoadType roadtype, StationType type, uint8 view, CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0); ~RoadStopResolverObject(); ScopeResolver* GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override { @@ -155,7 +155,7 @@ typedef NewGRFClass RoadStopC void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view); -uint16 GetRoadStopCallback(CallbackID callback, uint32 param1, uint32 param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, const RoadTypeInfo *rti, StationType type, uint8 view); +uint16 GetRoadStopCallback(CallbackID callback, uint32 param1, uint32 param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, RoadType roadtype, StationType type, uint8 view); void AnimateRoadStopTile(TileIndex tile); uint8 GetRoadStopTileAnimationSpeed(TileIndex tile); diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 7a6c6c1abe..f9e7022616 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -97,7 +97,7 @@ static bool IsRoadStopAvailable(const RoadStopSpec *roadstopspec, StationType ty { if (roadstopspec == nullptr || !HasBit(roadstopspec->callback_mask, CBM_ROAD_STOP_AVAIL)) return true; - uint16 cb_res = GetRoadStopCallback(CBID_STATION_AVAILABILITY, 0, 0, roadstopspec, nullptr, INVALID_TILE, GetRoadTypeInfo(_cur_roadtype), type, 0); + uint16 cb_res = GetRoadStopCallback(CBID_STATION_AVAILABILITY, 0, 0, roadstopspec, nullptr, INVALID_TILE, _cur_roadtype, type, 0); if (cb_res == CALLBACK_FAILED) return true; return Convert8bitBooleanCallback(roadstopspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 2b5e478361..fd28e90f62 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2149,7 +2149,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin /* Check if the road stop is buildable */ if (HasBit(roadstopspec->callback_mask, CBM_ROAD_STOP_AVAIL)) { - uint16 cb_res = GetRoadStopCallback(CBID_STATION_AVAILABILITY, 0, 0, roadstopspec, nullptr, INVALID_TILE, GetRoadTypeInfo(rt), type ? STATION_TRUCK : STATION_BUS, 0); + uint16 cb_res = GetRoadStopCallback(CBID_STATION_AVAILABILITY, 0, 0, roadstopspec, nullptr, INVALID_TILE, rt, type ? STATION_TRUCK : STATION_BUS, 0); if (cb_res != CALLBACK_FAILED && !Convert8bitBooleanCallback(roadstopspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res)) return CMD_ERROR; } } @@ -3500,7 +3500,7 @@ draw_default_foundation: int view = dir; if (IsDriveThroughStopTile(ti->tile)) view += 4; st = BaseStation::GetByTile(ti->tile); - RoadStopResolverObject object(stopspec, st, ti->tile, nullptr, GetStationType(ti->tile), view); + RoadStopResolverObject object(stopspec, st, ti->tile, INVALID_ROADTYPE, GetStationType(ti->tile), view); const SpriteGroup *group = object.Resolve(); const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(nullptr); t = dts; diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index e1dbbe50e8..b98688f554 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -1418,7 +1418,7 @@ class NIHRoadStop : public NIHelper { { int view = GetRoadStopDir(index); if (IsDriveThroughStopTile(index)) view += 4; - RoadStopResolverObject ro(GetRoadStopSpec(index), BaseStation::GetByTile(index), index, nullptr, GetStationType(index), view); + RoadStopResolverObject ro(GetRoadStopSpec(index), BaseStation::GetByTile(index), index, INVALID_ROADTYPE, GetStationType(index), view); return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, extra); }