NewGRF: Add/extend station variables for station info of nearby tiles
In preparation for support of more than 255 stations per GRF
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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<uint16>(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);
|
||||
/* Station info of nearby tiles */
|
||||
case 0x68: {
|
||||
return this->GetNearbyStationInfo(parameter, NearbyStationInfoMode::Standard);
|
||||
}
|
||||
|
||||
if (!HasStationTileRail(nearby_tile)) return 0xFFFFFFFF;
|
||||
/* Station info of nearby tiles: extended */
|
||||
case A2VRI_STATION_INFO_NEARBY_TILES_EXT: {
|
||||
return this->GetNearbyStationInfo(parameter, NearbyStationInfoMode::Extended);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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()
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user