NewGRF: Add extended house variables to get uncapped building counts, other IDs

This commit is contained in:
Jonathan G Rennison 2024-08-05 18:41:47 +01:00
parent 49972e56a1
commit e554cb9d62
7 changed files with 84 additions and 11 deletions

View File

@ -102,6 +102,14 @@
<tr><th>Name</th><th>Value range</th><th>Comment</th></tr> <tr><th>Name</th><th>Value range</th><th>Comment</th></tr>
<tr><td>same_house_count_town_uncapped</td><td>0..4294967295</td><td>Number of the houses with the same ID in the same town as this house (not clamped to 0xFF)</td></tr> <tr><td>same_house_count_town_uncapped</td><td>0..4294967295</td><td>Number of the houses with the same ID in the same town as this house (not clamped to 0xFF)</td></tr>
<tr><td>same_house_count_map_uncapped</td><td>0..4294967295</td><td>Number of the houses with the same ID on the entire map (not clamped to 0xFF)</td></tr> <tr><td>same_house_count_map_uncapped</td><td>0..4294967295</td><td>Number of the houses with the same ID on the entire map (not clamped to 0xFF)</td></tr>
<tr><td>same_class_count_town</td><td>0..4294967295</td><td>Number of the houses with the same class in the same town as this house (not clamped to 0xFF). The class of the north tile of the use is used for this purpose, as other tiles don't normally have a class.</td></tr>
<tr><td>same_class_count_map</td><td>0..4294967295</td><td>Number of the houses with the same class on the entire map (not clamped to 0xFF). The class of the north tile of the use is used for this purpose, as other tiles don't normally have a class.</td></tr>
<tr><td>old_house_count_town_uncapped</td><td>0..4294967295</td><td>Number of the houses with the given old ID in the same town as this house (not clamped to 0xFF)</td></tr>
<tr><td>old_house_count_map_uncapped</td><td>0..4294967295</td><td>Number of the houses with the given old ID on the entire map (not clamped to 0xFF)</td></tr>
<tr><td>other_house_count_town_uncapped</td><td>0..4294967295</td><td>Number of the houses with the given new ID in the same town as this house (not clamped to 0xFF)</td></tr>
<tr><td>other_house_count_map_uncapped</td><td>0..4294967295</td><td>Number of the houses with the given new ID on the entire map (not clamped to 0xFF)</td></tr>
<tr><td>other_class_count_town_uncapped</td><td>0..4294967295</td><td>Number of the houses with the same class as the house with the given new ID in the same town as this house (not clamped to 0xFF)</td></tr>
<tr><td>other_class_count_map_uncapped</td><td>0..4294967295</td><td>Number of the houses with the same class as the house with the given new ID on the entire map (not clamped to 0xFF)</td></tr>
</table> </table>
<h3 id="railtype-properties"><a href="https://newgrf-specs.tt-wiki.net/wiki/NML:Railtypes#Railtype_properties">Railtype properties</a></h3> <h3 id="railtype-properties"><a href="https://newgrf-specs.tt-wiki.net/wiki/NML:Railtypes#Railtype_properties">Railtype properties</a></h3>

View File

@ -832,18 +832,42 @@
<p>This is the same as bits 0 - 7 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Building_counts_.2844.29">44/Building counts</a>, except not clamped to a maximum of 0xFF.<br /> <p>This is the same as bits 0 - 7 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Building_counts_.2844.29">44/Building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1. This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p> </p>
<h4 id="house_same_class_town_count">Building count: same class, current town (mappable variable: house_same_class_town_count)</h4>
<p>This is the same as bits 16 - 23 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Building_counts_.2844.29">44/Building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p>
<h4 id="house_same_id_map_count">Building count: same ID, whole map (mappable variable: house_same_id_map_count)</h4> <h4 id="house_same_id_map_count">Building count: same ID, whole map (mappable variable: house_same_id_map_count)</h4>
<p>This is the same as bits 8 - 15 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Building_counts_.2844.29">44/Building counts</a>, except not clamped to a maximum of 0xFF.<br /> <p>This is the same as bits 8 - 15 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Building_counts_.2844.29">44/Building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1. This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p> </p>
<h4 id="house_same_class_town_count">Building count: same class, current town (mappable variable: house_same_class_town_count)</h4>
<p>This is the same as bits 16 - 23 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Building_counts_.2844.29">44/Building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p>
<h4 id="house_same_class_map_count">Building count: same class, total (mappable variable: house_same_class_map_count)</h4> <h4 id="house_same_class_map_count">Building count: same class, total (mappable variable: house_same_class_map_count)</h4>
<p>This is the same as bits 24 - 31 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Building_counts_.2844.29">44/Building counts</a>, except not clamped to a maximum of 0xFF.<br /> <p>This is the same as bits 24 - 31 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Building_counts_.2844.29">44/Building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1. This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p> </p>
<h4 id="house_other_old_id_town_count">Building count: other old ID, total (mappable variable: house_other_old_id_town_count)</h4>
<p>This is the same as bits 0 - 7 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Other_building_counts_.2860.2C_61.29">60/Other building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p>
<h4 id="house_other_old_id_map_count">Building count: other old ID, total (mappable variable: house_other_old_id_map_count)</h4>
<p>This is the same as bits 8 - 15 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Other_building_counts_.2860.2C_61.29">60/Other building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p>
<h4 id="house_other_id_town_count">Building count: other new ID, current town (mappable variable: house_other_id_town_count)</h4>
<p>This is the same as bits 0 - 7 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Other_building_counts_.2860.2C_61.29">61/Other building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p>
<h4 id="house_other_id_map_count">Building count: other new ID, whole map (mappable variable: house_other_id_map_count)</h4>
<p>This is the same as bits 8 - 15 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Other_building_counts_.2860.2C_61.29">61/Other building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p>
<h4 id="house_other_class_town_count">Building count: other new class, current town (mappable variable: house_other_class_town_count)</h4>
<p>This is the same as bits 16 - 23 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Other_building_counts_.2860.2C_61.29">61/Other building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p>
<h4 id="house_other_class_map_count">Building count: other new class, total (mappable variable: house_other_class_map_count)</h4>
<p>This is the same as bits 24 - 31 of <a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Houses#Other_building_counts_.2860.2C_61.29">61/Other building counts</a>, except not clamped to a maximum of 0xFF.<br />
This requires <font face="monospace">varaction2_house_uncapped_building_counts</font>, version 1.
</p>
<br /> <br />
<h3 id="varaction2_railtypes"><a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Railtypes">Variational Action 2 - Railtypes</a></h3> <h3 id="varaction2_railtypes"><a href="https://newgrf-specs.tt-wiki.net/wiki/VariationalAction2/Railtypes">Variational Action 2 - Railtypes</a></h3>
<h4 id="railtype_signal_restriction_info">Signal routing restriction information (mappable variable: railtype_signal_restriction_info)</h4> <h4 id="railtype_signal_restriction_info">Signal routing restriction information (mappable variable: railtype_signal_restriction_info)</h4>

View File

@ -162,6 +162,12 @@ extern const GRFVariableMapDefinition _grf_action2_remappable_variables[] = {
GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_SAME_CLASS_MAP_COUNT, "house_same_class_map_count"), GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_SAME_CLASS_MAP_COUNT, "house_same_class_map_count"),
GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_SAME_ID_TOWN_COUNT, "house_same_id_town_count"), GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_SAME_ID_TOWN_COUNT, "house_same_id_town_count"),
GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_SAME_CLASS_TOWN_COUNT, "house_same_class_town_count"), GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_SAME_CLASS_TOWN_COUNT, "house_same_class_town_count"),
GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_OTHER_OLD_ID_MAP_COUNT, "house_other_old_id_map_count"),
GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_OTHER_OLD_ID_TOWN_COUNT, "house_other_old_id_town_count"),
GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_OTHER_ID_MAP_COUNT, "house_other_id_map_count"),
GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_OTHER_CLASS_MAP_COUNT, "house_other_class_map_count"),
GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_OTHER_ID_TOWN_COUNT, "house_other_id_town_count"),
GRFVariableMapDefinition(GSF_HOUSES, A2VRI_HOUSE_OTHER_CLASS_TOWN_COUNT, "house_other_class_town_count"),
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x40, "roadstop_view"), GRFVariableMapDefinition(GSF_ROADSTOPS, 0x40, "roadstop_view"),
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x41, "roadstop_type"), GRFVariableMapDefinition(GSF_ROADSTOPS, 0x41, "roadstop_type"),
GRFVariableMapDefinition(GSF_ROADSTOPS, 0x42, "roadstop_terrain_type"), GRFVariableMapDefinition(GSF_ROADSTOPS, 0x42, "roadstop_terrain_type"),

View File

@ -85,6 +85,12 @@ enum Action2VariableRemapIds {
A2VRI_HOUSE_SAME_CLASS_MAP_COUNT, A2VRI_HOUSE_SAME_CLASS_MAP_COUNT,
A2VRI_HOUSE_SAME_ID_TOWN_COUNT, A2VRI_HOUSE_SAME_ID_TOWN_COUNT,
A2VRI_HOUSE_SAME_CLASS_TOWN_COUNT, A2VRI_HOUSE_SAME_CLASS_TOWN_COUNT,
A2VRI_HOUSE_OTHER_OLD_ID_MAP_COUNT,
A2VRI_HOUSE_OTHER_OLD_ID_TOWN_COUNT,
A2VRI_HOUSE_OTHER_ID_MAP_COUNT,
A2VRI_HOUSE_OTHER_CLASS_MAP_COUNT,
A2VRI_HOUSE_OTHER_ID_TOWN_COUNT,
A2VRI_HOUSE_OTHER_CLASS_TOWN_COUNT,
A2VRI_ROADSTOP_INFO_NEARBY_TILES_EXT, A2VRI_ROADSTOP_INFO_NEARBY_TILES_EXT,
A2VRI_ROADSTOP_INFO_NEARBY_TILES_V2, A2VRI_ROADSTOP_INFO_NEARBY_TILES_V2,
A2VRI_ROADSTOP_ROAD_INFO_NEARBY_TILES, A2VRI_ROADSTOP_ROAD_INFO_NEARBY_TILES,

View File

@ -391,6 +391,21 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex tile, Ho
return 0; return 0;
} }
HouseID HouseScopeResolver::GetOtherHouseID(uint32_t parameter) const
{
const HouseSpec *hs = HouseSpec::Get(this->house_id);
if (hs->grf_prop.grffile == nullptr) return INVALID_HOUSE_ID;
return _house_mngr.GetID(parameter, hs->grf_prop.grffile->grfid);
}
template <typename F>
uint32_t HouseScopeResolver::OtherHouseIDVariable(uint32_t parameter, F func) const
{
HouseID new_house = this->GetOtherHouseID(parameter);
return new_house == INVALID_HOUSE_ID ? 0 : func(new_house);
}
/** /**
* @note Used by the resolver to get values for feature 07 deterministic spritegroups. * @note Used by the resolver to get values for feature 07 deterministic spritegroups.
*/ */
@ -429,14 +444,16 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex tile, Ho
/* Building counts for old houses with id = parameter. */ /* Building counts for old houses with id = parameter. */
case 0x60: return parameter < NEW_HOUSE_OFFSET ? GetNumHouses(parameter, this->town) : 0; case 0x60: return parameter < NEW_HOUSE_OFFSET ? GetNumHouses(parameter, this->town) : 0;
/* Building counts for new houses with id = parameter. */ case A2VRI_HOUSE_OTHER_OLD_ID_MAP_COUNT: return parameter < NEW_HOUSE_OFFSET ? _building_counts.id_count[parameter] : 0;
case 0x61: { case A2VRI_HOUSE_OTHER_OLD_ID_TOWN_COUNT: return parameter < NEW_HOUSE_OFFSET ? this->town->cache.building_counts.id_count[parameter] : 0;
const HouseSpec *hs = HouseSpec::Get(this->house_id);
if (hs->grf_prop.grffile == nullptr) return 0;
HouseID new_house = _house_mngr.GetID(parameter, hs->grf_prop.grffile->grfid); /* Building counts for new houses with id = parameter. */
return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->town); case 0x61: return this->OtherHouseIDVariable(parameter, [&](HouseID new_house) { return GetNumHouses(new_house, this->town); });
}
case A2VRI_HOUSE_OTHER_ID_MAP_COUNT: return this->OtherHouseIDVariable(parameter, [&](HouseID new_house) { return _building_counts.id_count[new_house]; });
case A2VRI_HOUSE_OTHER_CLASS_MAP_COUNT: return this->OtherHouseIDVariable(parameter, [&](HouseID new_house) { return _building_counts.class_count[HouseSpec::Get(new_house)->class_id]; });
case A2VRI_HOUSE_OTHER_ID_TOWN_COUNT: return this->OtherHouseIDVariable(parameter, [&](HouseID new_house) { return this->town->cache.building_counts.id_count[new_house]; });
case A2VRI_HOUSE_OTHER_CLASS_TOWN_COUNT: return this->OtherHouseIDVariable(parameter, [&](HouseID new_house) { return this->town->cache.building_counts.class_count[HouseSpec::Get(new_house)->class_id]; });
/* Land info for nearby tiles. */ /* Land info for nearby tiles. */
case 0x62: return GetNearbyTileInformation(parameter, this->tile, this->ro.grffile->grf_version >= 8, extra->mask); case 0x62: return GetNearbyTileInformation(parameter, this->tile, this->ro.grffile->grf_version >= 8, extra->mask);

View File

@ -52,6 +52,12 @@ struct HouseScopeResolver : public CommonHouseScopeResolver {
uint32_t GetRandomBits() const override; uint32_t GetRandomBits() const override;
uint32_t GetVariable(uint16_t variable, uint32_t parameter, GetVariableExtra *extra) const override; uint32_t GetVariable(uint16_t variable, uint32_t parameter, GetVariableExtra *extra) const override;
uint32_t GetTriggers() const override; uint32_t GetTriggers() const override;
private:
HouseID GetOtherHouseID(uint32_t parameter) const;
template <typename F>
uint32_t OtherHouseIDVariable(uint32_t parameter, F func) const;
}; };
/** /**

View File

@ -941,6 +941,12 @@ static const NIVariable _niv_house[] = {
NIV(A2VRI_HOUSE_SAME_CLASS_MAP_COUNT, "building count: same class, map"), NIV(A2VRI_HOUSE_SAME_CLASS_MAP_COUNT, "building count: same class, map"),
NIV(A2VRI_HOUSE_SAME_ID_TOWN_COUNT, "building count: same ID, town"), NIV(A2VRI_HOUSE_SAME_ID_TOWN_COUNT, "building count: same ID, town"),
NIV(A2VRI_HOUSE_SAME_CLASS_TOWN_COUNT, "building count: same class, town"), NIV(A2VRI_HOUSE_SAME_CLASS_TOWN_COUNT, "building count: same class, town"),
NIVF(A2VRI_HOUSE_OTHER_OLD_ID_MAP_COUNT, "building count: other old ID, map", NIVF_SHOW_PARAMS),
NIVF(A2VRI_HOUSE_OTHER_OLD_ID_TOWN_COUNT, "building count: other old ID, town", NIVF_SHOW_PARAMS),
NIVF(A2VRI_HOUSE_OTHER_ID_MAP_COUNT, "building count: other ID, map", NIVF_SHOW_PARAMS),
NIVF(A2VRI_HOUSE_OTHER_CLASS_MAP_COUNT, "building count: other class, map", NIVF_SHOW_PARAMS),
NIVF(A2VRI_HOUSE_OTHER_ID_TOWN_COUNT, "building count: other ID, town", NIVF_SHOW_PARAMS),
NIVF(A2VRI_HOUSE_OTHER_CLASS_TOWN_COUNT, "building count: other class, town", NIVF_SHOW_PARAMS),
NIV_END() NIV_END()
}; };