Fix road stop road/tram type variables when not present and in GUI

This commit is contained in:
Jonathan G Rennison
2022-02-16 19:03:41 +00:00
parent a0e6380d7a
commit 650a359a16
5 changed files with 32 additions and 18 deletions

View File

@@ -68,6 +68,20 @@ uint32 RoadStopScopeResolver::GetTriggers() const
uint32 RoadStopScopeResolver::GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) 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) { switch (variable) {
/* View/rotation */ /* View/rotation */
case 0x40: return this->view; 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 case 0x42: return this->tile == INVALID_TILE ? 0 : GetTerrainType(this->tile, TCX_NORMAL); // terrain_type
/* Road 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 */ /* 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 */ /* Town zone and Manhattan distance of closest town */
case 0x45: { case 0x45: {
@@ -175,9 +189,9 @@ const SpriteGroup *RoadStopResolverObject::ResolveReal(const RealSpriteGroup *gr
return group->loading[0]; 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) 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; this->town_scope = nullptr;
@@ -228,9 +242,9 @@ TownScopeResolver* RoadStopResolverObject::GetTown()
return this->town_scope; 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(); return object.ResolveCallback();
} }
@@ -249,7 +263,7 @@ void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec,
assert(spec != nullptr); assert(spec != nullptr);
const RoadTypeInfo *rti = GetRoadTypeInfo(roadtype); 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(); const SpriteGroup *group = object.Resolve();
if (group == nullptr || group->type != SGT_TILELAYOUT) return; if (group == nullptr || group->type != SGT_TILELAYOUT) return;
const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(nullptr); 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. */ /** Wrapper for animation control, see GetRoadStopCallback. */
uint16 GetAnimRoadStopCallback(CallbackID callback, uint32 param1, uint32 param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, int extra_data) 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 { struct RoadStopAnimationFrameAnimationHelper {
@@ -405,7 +419,7 @@ void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTri
} }
if (cargo_type == CT_INVALID || HasBit(ss->cargo_triggers, cargo_type)) { 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; object.waiting_triggers = st->waiting_triggers;
const SpriteGroup *group = object.Resolve(); const SpriteGroup *group = object.Resolve();

View File

@@ -80,10 +80,10 @@ struct RoadStopScopeResolver : public ScopeResolver {
CargoID cargo_type; ///< Type of cargo of the station. CargoID cargo_type; ///< Type of cargo of the station.
StationType type; ///< Station type. StationType type; ///< Station type.
uint8 view; ///< Station axis. 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) 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), rti(rti) : 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. RoadStopScopeResolver roadstop_scope; ///< The stop scope resolver.
TownScopeResolver *town_scope; ///< The town scope resolver (created on the first call). 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(); ~RoadStopResolverObject();
ScopeResolver* GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override { ScopeResolver* GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override {
@@ -155,7 +155,7 @@ typedef NewGRFClass<RoadStopSpec, RoadStopClassID, ROADSTOP_CLASS_MAX> RoadStopC
void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view); 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); void AnimateRoadStopTile(TileIndex tile);
uint8 GetRoadStopTileAnimationSpeed(TileIndex tile); uint8 GetRoadStopTileAnimationSpeed(TileIndex tile);

View File

@@ -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; 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; if (cb_res == CALLBACK_FAILED) return true;
return Convert8bitBooleanCallback(roadstopspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res); return Convert8bitBooleanCallback(roadstopspec->grf_prop.grffile, CBID_STATION_AVAILABILITY, cb_res);

View File

@@ -2149,7 +2149,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* Check if the road stop is buildable */ /* Check if the road stop is buildable */
if (HasBit(roadstopspec->callback_mask, CBM_ROAD_STOP_AVAIL)) { 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; 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; int view = dir;
if (IsDriveThroughStopTile(ti->tile)) view += 4; if (IsDriveThroughStopTile(ti->tile)) view += 4;
st = BaseStation::GetByTile(ti->tile); 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 SpriteGroup *group = object.Resolve();
const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(nullptr); const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(nullptr);
t = dts; t = dts;

View File

@@ -1418,7 +1418,7 @@ class NIHRoadStop : public NIHelper {
{ {
int view = GetRoadStopDir(index); int view = GetRoadStopDir(index);
if (IsDriveThroughStopTile(index)) view += 4; 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); return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, extra);
} }