Add/adjust NewGRF road stop variables

This commit is contained in:
Jonathan G Rennison
2022-02-14 18:24:45 +00:00
parent 64fb6251bf
commit 3b8c73acad
3 changed files with 73 additions and 12 deletions

View File

@@ -109,7 +109,11 @@ extern const GRFVariableMapDefinition _grf_action2_remappable_variables[] = {
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x43, "roadstop_road_type"), GRFVariableMapDefinition(GSF_ROADSTOPS, 0x43, "roadstop_road_type"),
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x44, "roadstop_tram_type"), GRFVariableMapDefinition(GSF_ROADSTOPS, 0x44, "roadstop_tram_type"),
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x45, "roadstop_town_zone"), GRFVariableMapDefinition(GSF_ROADSTOPS, 0x45, "roadstop_town_zone"),
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x46, "roadstop_company_info"), GRFVariableMapDefinition(GSF_ROADSTOPS, 0x46, "roadstop_town_distance_squared"),
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x47, "roadstop_company_info"),
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x67, "roadstop_land_info_nearby_tiles"),
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x68, "roadstop_road_stop_info_nearby_tiles"),
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x6A, "roadstop_road_stop_grfid _nearby_tiles"),
GRFVariableMapDefinition(), GRFVariableMapDefinition(),
}; };

View File

@@ -67,26 +67,79 @@ uint32 RoadStopScopeResolver::GetTriggers() const
uint32 RoadStopScopeResolver::GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const uint32 RoadStopScopeResolver::GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const
{ {
switch (variable) { switch (variable) {
case 0x40: return this->view; // view /* View/rotation */
case 0x40: return this->view;
case 0x41: // stop type /* Stop type: 0: bus, 1: truck, 2: waypoint */
case 0x41:
if (this->type == STATION_BUS) return 0; if (this->type == STATION_BUS) return 0;
if (this->type == STATION_TRUCK) return 1; if (this->type == STATION_TRUCK) return 1;
return 2; return 2;
/* Terrain type */
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
case 0x43: return this->tile == INVALID_TILE ? 0 : GetReverseRoadTypeTranslation(GetRoadTypeRoad(this->tile), this->roadstopspec->grf_prop.grffile); // road_type /* Road type */
case 0x43: return this->tile == INVALID_TILE ? 0 : GetReverseRoadTypeTranslation(GetRoadTypeRoad(this->tile), this->roadstopspec->grf_prop.grffile);
case 0x44: return this->tile == INVALID_TILE ? 0 : GetReverseRoadTypeTranslation(GetRoadTypeTram(this->tile), this->roadstopspec->grf_prop.grffile); // tram_type /* Tram type */
case 0x44: return this->tile == INVALID_TILE ? 0 : GetReverseRoadTypeTranslation(GetRoadTypeTram(this->tile), this->roadstopspec->grf_prop.grffile);
case 0x45: { // town_zone /* Town zone and Manhattan distance of closest town */
if (this->tile == INVALID_TILE) return HZB_TOWN_EDGE; case 0x45: {
const Town *t = ClosestTownFromTile(this->tile, UINT_MAX); if (this->tile == INVALID_TILE) return HZB_TOWN_EDGE << 16;
return t != nullptr ? GetTownRadiusGroup(t, this->tile) : HZB_TOWN_EDGE; const Town *t = (this->st == nullptr) ? ClosestTownFromTile(this->tile, UINT_MAX) : this->st->town;
return t != nullptr ? (GetTownRadiusGroup(t, this->tile) << 16 | std::min(DistanceManhattan(this->tile, t->xy), 0xFFFFu)) : HZB_TOWN_EDGE << 16;
} }
case 0x46: return GetCompanyInfo(this->st == nullptr ? _current_company : this->st->owner); // company_type /* Get square of Euclidian distance of closest town */
case 0x46: {
if (this->tile == INVALID_TILE) return 0;
const Town *t = (this->st == nullptr) ? ClosestTownFromTile(this->tile, UINT_MAX) : this->st->town;
return t != nullptr ? DistanceSquare(this->tile, t->xy) : 0;
}
/* Company information */
case 0x47: return GetCompanyInfo(this->st == nullptr ? _current_company : this->st->owner);
/* Variables which use the parameter */
/* Variables 0x60 to 0x65 and 0x69 are handled separately below */
/* Land info of nearby tile */
case 0x67: {
TileIndex tile = this->tile;
if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
return GetNearbyTileInformation(tile, this->ro.grffile->grf_version >= 8);
}
/* Road stop info of nearby tiles */
case 0x68: {
TileIndex nearby_tile = GetNearbyTile(parameter, this->tile);
if (!IsAnyRoadStopTile(nearby_tile)) return 0xFFFFFFFF;
uint32 grfid = this->st->roadstop_speclist[GetCustomRoadStopSpecIndex(this->tile)].grfid;
bool same_orientation = GetStationGfx(this->tile) == GetStationGfx(nearby_tile);
bool same_station = GetStationIndex(nearby_tile) == this->st->index;
uint32 res = GetStationGfx(nearby_tile) << 12 | !same_orientation << 11 | !!same_station << 10;
if (IsCustomRoadStopSpecIndex(nearby_tile)) {
const RoadStopSpecList ssl = BaseStation::GetByTile(nearby_tile)->roadstop_speclist[GetCustomRoadStopSpecIndex(nearby_tile)];
res |= 1 << (ssl.grfid != grfid ? 9 : 8) | ssl.localidx;
}
return res;
}
/* GRFID of nearby road stop tiles */
case 0x6A: {
TileIndex nearby_tile = GetNearbyTile(parameter, this->tile);
if (!IsAnyRoadStopTile(nearby_tile)) return 0xFFFFFFFF;
if (!IsCustomRoadStopSpecIndex(nearby_tile)) return 0;
const RoadStopSpecList ssl = BaseStation::GetByTile(nearby_tile)->roadstop_speclist[GetCustomRoadStopSpecIndex(nearby_tile)];
return ssl.grfid;
}
case 0xF0: return this->st == nullptr ? 0 : this->st->facilities; // facilities case 0xF0: return this->st == nullptr ? 0 : this->st->facilities; // facilities

View File

@@ -1377,8 +1377,9 @@ static const NIVariable _nif_roadstops[] = {
NIV(0x42, "terrain type"), NIV(0x42, "terrain type"),
NIV(0x43, "road type"), NIV(0x43, "road type"),
NIV(0x44, "tram type"), NIV(0x44, "tram type"),
NIV(0x45, "town zone"), NIV(0x45, "town zone and Manhattan distance of town"),
NIV(0x46, "player info"), NIV(0x46, "square of Euclidean distance of town"),
NIV(0x47, "player info"),
NIV(0x48, "bitmask of accepted cargoes"), NIV(0x48, "bitmask of accepted cargoes"),
NIV(0x60, "amount of cargo waiting"), NIV(0x60, "amount of cargo waiting"),
NIV(0x61, "time since last cargo pickup"), NIV(0x61, "time since last cargo pickup"),
@@ -1386,7 +1387,10 @@ static const NIVariable _nif_roadstops[] = {
NIV(0x63, "time spent on route"), NIV(0x63, "time spent on route"),
NIV(0x64, "information about last vehicle picking cargo up"), NIV(0x64, "information about last vehicle picking cargo up"),
NIV(0x65, "amount of cargo acceptance"), NIV(0x65, "amount of cargo acceptance"),
NIV(0x67, "land info of nearby tiles"),
NIV(0x68, "road stop info of nearby tiles"),
NIV(0x69, "information about cargo accepted in the past"), NIV(0x69, "information about cargo accepted in the past"),
NIV(0x6A, "GRFID of nearby road stop tiles"),
NIV_END(), NIV_END(),
}; };