diff --git a/docs/newgrf-additions.html b/docs/newgrf-additions.html index 3dbbc2e598..320b5c2119 100644 --- a/docs/newgrf-additions.html +++ b/docs/newgrf-additions.html @@ -782,6 +782,60 @@

Variational Action 2 - Stations

Track type in purchase list (42)

This is indicated by the feature name: varaction2_station_var42, version 1

+

Station info of nearby tiles (68)

+

If feature name varaction2_station_var68_extended_localidx is present and the feature is successfully tested for,
+ then the local setID field which would normally be in bits 0..7 (clamped to 0..255), is instead split such that the lower byte is in bits 0..7, and the upper byte is in bits 24..31, such that the variable overall has the format: + + + + + + + + +
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 station setIDs greater than 255, bits 24 - 31 need to be used as well. +
8 - 9 + 0 - The tile uses original TTD graphics
+ 1 - The tile is defined in the current GRF
+ 2 - The tile is defined in another GRF +
10Set if the selected tile belongs to the current station, clear otherwise
11Clear if the selected tile is parallel with the current one, set if perpendicular to it
12 - 13 + 0 - plain platform
+ 1 - platform with building
+ 2 - platform with roof, left side
+ 3 - platform with roof, right side +
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 station setIDs greater than 255 (does not define more than 256 station types). +
+
+ The remaining bits are reserved for future use and should be masked.
+ This format requires varaction2_station_var68_extended_localidx, version 1. +

+

Station info of nearby tiles v2 (mappable variable: station_station_info_nearby_tiles_v2)

+

This has a similar value to 68/Station info of nearby tiles, above.
+ + + + + + + +
BitsMeaning
0 - 15If the tile is defined in the current GRF, this is the setID used in the definition. Otherwise, the content is undefined.
16 - 17 + 0 - The tile uses original TTD graphics
+ 1 - The tile is defined in the current GRF
+ 2 - The tile is defined in another GRF +
18Set if the selected tile belongs to the current station, clear otherwise
19Clear if the selected tile is parallel with the current one, set if perpendicular to it
20 - 21 + 0 - plain platform
+ 1 - platform with building
+ 2 - platform with roof, left side
+ 3 - platform with roof, right side +
+
+ The remaining bits are reserved for future use and should be masked.
+ This requires varaction2_station_station_nearby_info_v2, version 1. +


Variational Action 2 - Railtypes

Signal routing restriction information (mappable variable: railtype_signal_restriction_info)

diff --git a/src/newgrf.cpp b/src/newgrf.cpp index ae7c433496..063638ced2 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5977,6 +5977,10 @@ static void NewSpriteGroup(ByteReader *buf) 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 (info.scope_feature == GSF_STATIONS && HasBit(_cur.grffile->observed_feature_tests, GFTOF_STATION_VAR68_EXT_LOCALIDX)) { + if (adjust.variable == 0x68) adjust.variable = A2VRI_STATION_INFO_NEARBY_TILES_EXT; + if (adjust.variable == 0x7B && adjust.parameter == 0x68) adjust.parameter = A2VRI_STATION_INFO_NEARBY_TILES_EXT; + } if (adjust.type != DSGA_TYPE_NONE) { adjust.add_val = buf->ReadVarSize(varsize); diff --git a/src/newgrf_extension.cpp b/src/newgrf_extension.cpp index 191026b9b5..9311bade77 100644 --- a/src/newgrf_extension.cpp +++ b/src/newgrf_extension.cpp @@ -24,6 +24,8 @@ extern const GRFFeatureInfo _grf_feature_list[] = { GRFFeatureInfo("action0_station_prop1B", 1), GRFFeatureInfo("action0_station_disallowed_bridge_pillars", 1), GRFFeatureInfo("varaction2_station_var42", 1), + GRFFeatureInfo("varaction2_station_var68_extended_localidx", 1, GFTOF_STATION_VAR68_EXT_LOCALIDX), + GRFFeatureInfo("varaction2_station_station_nearby_info_v2", 1), GRFFeatureInfo("more_bridge_types", 1), GRFFeatureInfo("action0_bridge_prop14", 1), GRFFeatureInfo("action0_bridge_pillar_flags", 1), @@ -149,6 +151,7 @@ extern const GRFPropertyMapDefinition _grf_action0_remappable_properties[] = { /** Action14 Action2 remappable variable list */ extern const GRFVariableMapDefinition _grf_action2_remappable_variables[] = { + GRFVariableMapDefinition(GSF_STATIONS, A2VRI_STATION_INFO_NEARBY_TILES_V2, "station_station_info_nearby_tiles_v2"), GRFVariableMapDefinition(GSF_OBJECTS, A2VRI_OBJECT_FOUNDATION_SLOPE, "object_foundation_tile_slope"), GRFVariableMapDefinition(GSF_OBJECTS, A2VRI_OBJECT_FOUNDATION_SLOPE_CHANGE, "object_foundation_change_tile_slope"), GRFVariableMapDefinition(GSF_ROADSTOPS, 0x40, "roadstop_view"), diff --git a/src/newgrf_extension.h b/src/newgrf_extension.h index 863f2d4a4e..6764de01f7 100644 --- a/src/newgrf_extension.h +++ b/src/newgrf_extension.h @@ -76,7 +76,9 @@ enum Action0RemapPropertyIds { enum Action2VariableRemapIds { - A2VRI_OBJECT_FOUNDATION_SLOPE = 0x100, + A2VRI_STATION_INFO_NEARBY_TILES_EXT = 0x100, + A2VRI_STATION_INFO_NEARBY_TILES_V2, + A2VRI_OBJECT_FOUNDATION_SLOPE, A2VRI_OBJECT_FOUNDATION_SLOPE_CHANGE, A2VRI_VEHICLE_CURRENT_SPEED_SCALED, A2VRI_ROADSTOP_INFO_NEARBY_TILES_EXT, @@ -107,6 +109,7 @@ enum GRFFeatureTestObservationFlag : uint8 { GFTOF_MORE_VARACTION2_TYPES, GFTOF_MULTI_PART_SHIPS, GFTOF_ROAD_STOPS, + GFTOF_STATION_VAR68_EXT_LOCALIDX, GFTOF_INVALID = 0xFF, }; diff --git a/src/newgrf_optimiser.cpp b/src/newgrf_optimiser.cpp index 4ef1d2ec9f..ca8b35430a 100644 --- a/src/newgrf_optimiser.cpp +++ b/src/newgrf_optimiser.cpp @@ -45,6 +45,8 @@ static bool IsExpensiveStationVariable(uint16 variable) case 0x67: case 0x68: case 0x6A: + case A2VRI_STATION_INFO_NEARBY_TILES_EXT: + case A2VRI_STATION_INFO_NEARBY_TILES_V2: return true; default: diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index d9493a3b69..facc30cbdd 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -23,6 +23,7 @@ #include "tunnelbridge_map.h" #include "newgrf_animation_base.h" #include "newgrf_class_func.h" +#include "newgrf_extension.h" #include "safeguards.h" @@ -268,6 +269,37 @@ TownScopeResolver *StationResolverObject::GetTown() return this->town_scope; } +uint32 StationScopeResolver::GetNearbyStationInfo(uint32 parameter, StationScopeResolver::NearbyStationInfoMode mode) const +{ + TileIndex nearby_tile = GetNearbyTile(parameter, this->tile); + + if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF; + + uint32 grfid = this->st->speclist[GetCustomStationSpecIndex(this->tile)].grfid; + bool perpendicular = GetRailStationAxis(this->tile) != GetRailStationAxis(nearby_tile); + bool same_station = this->st->TileBelongsToRailStation(nearby_tile); + uint32 res = GB(GetStationGfx(nearby_tile), 1, 2) << 12 | !!perpendicular << 11 | !!same_station << 10; + + uint16 localidx = 0; + if (IsCustomStationSpecIndex(nearby_tile)) { + const StationSpecList ssl = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)]; + localidx = ssl.localidx; + res |= 1 << (ssl.grfid != grfid ? 9 : 8); + } + + switch (mode) { + case NearbyStationInfoMode::Standard: + default: + return res | std::min(localidx, 0xFF); + + case NearbyStationInfoMode::Extended: + return res | (localidx & 0xFF) | ((localidx & 0xFF00) << 16); + + case NearbyStationInfoMode::V2: + return (res << 8) | localidx; + } +} + /* virtual */ uint32 StationScopeResolver::GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const { if (this->st == nullptr) { @@ -355,21 +387,19 @@ TownScopeResolver *StationResolverObject::GetTown() return result; } - case 0x68: { // Station info of nearby tiles - TileIndex nearby_tile = GetNearbyTile(parameter, this->tile); - - if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF; + /* Station info of nearby tiles */ + case 0x68: { + return this->GetNearbyStationInfo(parameter, NearbyStationInfoMode::Standard); + } - uint32 grfid = this->st->speclist[GetCustomStationSpecIndex(this->tile)].grfid; - bool perpendicular = GetRailStationAxis(this->tile) != GetRailStationAxis(nearby_tile); - bool same_station = this->st->TileBelongsToRailStation(nearby_tile); - uint32 res = GB(GetStationGfx(nearby_tile), 1, 2) << 12 | !!perpendicular << 11 | !!same_station << 10; + /* Station info of nearby tiles: extended */ + case A2VRI_STATION_INFO_NEARBY_TILES_EXT: { + return this->GetNearbyStationInfo(parameter, NearbyStationInfoMode::Extended); + } - if (IsCustomStationSpecIndex(nearby_tile)) { - const StationSpecList ssl = BaseStation::GetByTile(nearby_tile)->speclist[GetCustomStationSpecIndex(nearby_tile)]; - res |= 1 << (ssl.grfid != grfid ? 9 : 8) | ssl.localidx; - } - return res; + /* Station info of nearby tiles: v2 */ + case A2VRI_STATION_INFO_NEARBY_TILES_V2: { + return this->GetNearbyStationInfo(parameter, NearbyStationInfoMode::V2); } case 0x6A: { // GRFID of nearby station tiles diff --git a/src/newgrf_station.h b/src/newgrf_station.h index cff5d68db4..36991ad58f 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -46,6 +46,14 @@ struct StationScopeResolver : public ScopeResolver { uint32 GetTriggers() const override; uint32 GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const override; + +private: + enum class NearbyStationInfoMode { + Standard, + Extended, + V2, + }; + uint32 GetNearbyStationInfo(uint32 parameter, NearbyStationInfoMode mode) const; }; /** Station resolver. */ diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index f9f815940c..7400071a1e 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -584,6 +584,8 @@ static const NIVariable _niv_stations[] = { NIV(0x68, "station info of nearby tiles"), NIV(0x69, "information about cargo accepted in the past"), NIV(0x6A, "GRFID of nearby station tiles"), + NIV(A2VRI_STATION_INFO_NEARBY_TILES_EXT, "station info of nearby tiles ext"), + NIV(A2VRI_STATION_INFO_NEARBY_TILES_V2, "station info of nearby tiles v2"), NIV_END() };