From 1dbbbed9e5c9c68f8adf9ad6ac5f0914257aa6a5 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 1 Jun 2023 18:14:23 +0100 Subject: [PATCH] NewGRF: Only extend value of road stops variable 68 if feature tested for --- docs/newgrf-roadstops.html | 8 ++++++-- src/newgrf.cpp | 5 +++++ src/newgrf_extension.cpp | 2 +- src/newgrf_extension.h | 2 ++ src/newgrf_optimiser.cpp | 2 ++ src/newgrf_roadstop.cpp | 25 ++++++++++++++++++------- src/newgrf_roadstop.h | 7 ++++++- src/table/newgrf_debug_data.h | 1 + 8 files changed, 41 insertions(+), 11 deletions(-) diff --git a/docs/newgrf-roadstops.html b/docs/newgrf-roadstops.html index b0e0226ebf..02d8c4566d 100644 --- a/docs/newgrf-roadstops.html +++ b/docs/newgrf-roadstops.html @@ -341,7 +341,9 @@ BitsMeaning 0 - 7 If the tile is defined in the current GRF, this is the lower 8 bits of the setID used in the definition. Otherwise, the content is undefined.
- Note that if this GRF has any road stop setIDs greater than 255, bits 24 - 31 need to be used as well. + Note that if this GRF has any road stop setIDs greater than 255, bits 24 - 31 need to be used as well.
+
+ If the road_stops feature is not tested for, this is the entire setID, clamped to the range 0..255. 8 - 9 0 - The tile uses original TTD graphics
@@ -367,7 +369,9 @@ 24 - 31 If the tile is defined in the current GRF, this is the upper 8 bits of the setID used in the definition. Otherwise, the content is undefined.
This can be ignored if this GRF does not have any road stop setIDs greater than 255 (does not define more than 256 road stop types).
- This requires road_stops, version 7. + This requires road_stops, version 7.
+
+ If the road_stops feature is not tested for, this is set to 0.
diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 6ea8a1cc37..ae7c433496 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5973,6 +5973,11 @@ static void NewSpriteGroup(ByteReader *buf) } } + if (info.scope_feature == GSF_ROADSTOPS && HasBit(_cur.grffile->observed_feature_tests, GFTOF_ROAD_STOPS)) { + if (adjust.variable == 0x68) adjust.variable = A2VRI_ROADSTOP_INFO_NEARBY_TILES_EXT; + if (adjust.variable == 0x7B && adjust.parameter == 0x68) adjust.parameter = A2VRI_ROADSTOP_INFO_NEARBY_TILES_EXT; + } + if (adjust.type != DSGA_TYPE_NONE) { adjust.add_val = buf->ReadVarSize(varsize); adjust.divmod_val = buf->ReadVarSize(varsize); diff --git a/src/newgrf_extension.cpp b/src/newgrf_extension.cpp index da364503bc..191026b9b5 100644 --- a/src/newgrf_extension.cpp +++ b/src/newgrf_extension.cpp @@ -60,7 +60,7 @@ extern const GRFFeatureInfo _grf_feature_list[] = { GRFFeatureInfo("action0_object_edge_foundation_mode", 2), GRFFeatureInfo("action0_object_flood_resistant", 1), GRFFeatureInfo("action0_object_viewport_map_tile_type", 1), - GRFFeatureInfo("road_stops", 9), + GRFFeatureInfo("road_stops", 9, GFTOF_ROAD_STOPS), GRFFeatureInfo("new_landscape", 2), GRFFeatureInfo("more_objects_per_grf", 1, GFTOF_MORE_OBJECTS_PER_GRF), GRFFeatureInfo("more_action2_ids", 1, GFTOF_MORE_ACTION2_IDS), diff --git a/src/newgrf_extension.h b/src/newgrf_extension.h index 9547f381ed..863f2d4a4e 100644 --- a/src/newgrf_extension.h +++ b/src/newgrf_extension.h @@ -79,6 +79,7 @@ enum Action2VariableRemapIds { A2VRI_OBJECT_FOUNDATION_SLOPE = 0x100, A2VRI_OBJECT_FOUNDATION_SLOPE_CHANGE, A2VRI_VEHICLE_CURRENT_SPEED_SCALED, + A2VRI_ROADSTOP_INFO_NEARBY_TILES_EXT, A2VRI_ROADSTOP_INFO_NEARBY_TILES_V2, A2VRI_RAILTYPE_SIGNAL_RESTRICTION_INFO, A2VRI_RAILTYPE_SIGNAL_CONTEXT, @@ -105,6 +106,7 @@ enum GRFFeatureTestObservationFlag : uint8 { GFTOF_TOWN_ZONE_CALLBACK, GFTOF_MORE_VARACTION2_TYPES, GFTOF_MULTI_PART_SHIPS, + GFTOF_ROAD_STOPS, GFTOF_INVALID = 0xFF, }; diff --git a/src/newgrf_optimiser.cpp b/src/newgrf_optimiser.cpp index c4ec3ca8a8..4ef1d2ec9f 100644 --- a/src/newgrf_optimiser.cpp +++ b/src/newgrf_optimiser.cpp @@ -94,6 +94,8 @@ static bool IsExpensiveRoadStopsVariable(uint16 variable) case 0x68: case 0x6A: case 0x6B: + case A2VRI_ROADSTOP_INFO_NEARBY_TILES_EXT: + case A2VRI_ROADSTOP_INFO_NEARBY_TILES_V2: return true; default: diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index d80abe4c51..22f499cfd7 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -67,7 +67,7 @@ uint32 RoadStopScopeResolver::GetTriggers() const return this->st == nullptr ? 0 : this->st->waiting_triggers; } -uint32 RoadStopScopeResolver::GetNearbyRoadStopsInfo(uint32 parameter, bool v2) const +uint32 RoadStopScopeResolver::GetNearbyRoadStopsInfo(uint32 parameter, RoadStopScopeResolver::NearbyRoadStopInfoMode mode) const { if (this->tile == INVALID_TILE) return 0xFFFFFFFF; TileIndex nearby_tile = GetNearbyTile(parameter, this->tile); @@ -93,10 +93,16 @@ uint32 RoadStopScopeResolver::GetNearbyRoadStopsInfo(uint32 parameter, bool v2) res |= (GetDriveThroughStopDisallowedRoadDirections(nearby_tile) << 21); } - if (v2) { - return (res << 8) | localidx; - } else { - return res | (localidx & 0xFF) | ((localidx & 0xFF00) << 16); + switch (mode) { + case NearbyRoadStopInfoMode::Standard: + default: + return res | std::min(localidx, 0xFF); + + case NearbyRoadStopInfoMode::Extended: + return res | (localidx & 0xFF) | ((localidx & 0xFF00) << 16); + + case NearbyRoadStopInfoMode::V2: + return (res << 8) | localidx; } } @@ -191,12 +197,17 @@ uint32 RoadStopScopeResolver::GetVariable(uint16 variable, uint32 parameter, Get /* Road stop info of nearby tiles */ case 0x68: { - return this->GetNearbyRoadStopsInfo(parameter, false); + return this->GetNearbyRoadStopsInfo(parameter, NearbyRoadStopInfoMode::Standard); + } + + /* Road stop info of nearby tiles: extended */ + case A2VRI_ROADSTOP_INFO_NEARBY_TILES_EXT: { + return this->GetNearbyRoadStopsInfo(parameter, NearbyRoadStopInfoMode::Extended); } /* Road stop info of nearby tiles: v2 */ case A2VRI_ROADSTOP_INFO_NEARBY_TILES_V2: { - return this->GetNearbyRoadStopsInfo(parameter, true); + return this->GetNearbyRoadStopsInfo(parameter, NearbyRoadStopInfoMode::V2); } /* GRFID of nearby road stop tiles */ diff --git a/src/newgrf_roadstop.h b/src/newgrf_roadstop.h index 6e848be737..24776f56ec 100644 --- a/src/newgrf_roadstop.h +++ b/src/newgrf_roadstop.h @@ -102,7 +102,12 @@ struct RoadStopScopeResolver : public ScopeResolver { uint32 GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const override; private: - uint32 GetNearbyRoadStopsInfo(uint32 parameter, bool v2) const; + enum class NearbyRoadStopInfoMode { + Standard, + Extended, + V2, + }; + uint32 GetNearbyRoadStopsInfo(uint32 parameter, NearbyRoadStopInfoMode mode) const; }; /** Road stop resolver. */ diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index ef2495b505..f9f815940c 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -1945,6 +1945,7 @@ static const NIVariable _nif_roadstops[] = { NIV(0x69, "information about cargo accepted in the past"), NIV(0x6A, "GRFID of nearby road stop tiles"), NIV(0x6B, "Road info of nearby plain road tiles"), + NIV(A2VRI_ROADSTOP_INFO_NEARBY_TILES_EXT, "road stop info of nearby tiles ext"), NIV(A2VRI_ROADSTOP_INFO_NEARBY_TILES_V2, "road stop info of nearby tiles v2"), NIV_END(), };