From e554cb9d629ab736bfed35f8b94c1f47fc866a1e Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 5 Aug 2024 18:41:47 +0100 Subject: [PATCH] NewGRF: Add extended house variables to get uncapped building counts, other IDs --- docs/newgrf-additions-nml.html | 8 ++++++++ docs/newgrf-additions.html | 32 ++++++++++++++++++++++++++++---- src/newgrf_extension.cpp | 6 ++++++ src/newgrf_extension.h | 6 ++++++ src/newgrf_house.cpp | 31 ++++++++++++++++++++++++------- src/newgrf_house.h | 6 ++++++ src/table/newgrf_debug_data.h | 6 ++++++ 7 files changed, 84 insertions(+), 11 deletions(-) diff --git a/docs/newgrf-additions-nml.html b/docs/newgrf-additions-nml.html index a228e99c00..550feb8f06 100644 --- a/docs/newgrf-additions-nml.html +++ b/docs/newgrf-additions-nml.html @@ -102,6 +102,14 @@ NameValue rangeComment same_house_count_town_uncapped0..4294967295Number of the houses with the same ID in the same town as this house (not clamped to 0xFF) same_house_count_map_uncapped0..4294967295Number of the houses with the same ID on the entire map (not clamped to 0xFF) + same_class_count_town0..4294967295Number 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. + same_class_count_map0..4294967295Number 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. + old_house_count_town_uncapped0..4294967295Number of the houses with the given old ID in the same town as this house (not clamped to 0xFF) + old_house_count_map_uncapped0..4294967295Number of the houses with the given old ID on the entire map (not clamped to 0xFF) + other_house_count_town_uncapped0..4294967295Number of the houses with the given new ID in the same town as this house (not clamped to 0xFF) + other_house_count_map_uncapped0..4294967295Number of the houses with the given new ID on the entire map (not clamped to 0xFF) + other_class_count_town_uncapped0..4294967295Number 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) + other_class_count_map_uncapped0..4294967295Number of the houses with the same class as the house with the given new ID on the entire map (not clamped to 0xFF)

Railtype properties

diff --git a/docs/newgrf-additions.html b/docs/newgrf-additions.html index 3dc61a32d6..03fc540e29 100644 --- a/docs/newgrf-additions.html +++ b/docs/newgrf-additions.html @@ -832,18 +832,42 @@

This is the same as bits 0 - 7 of 44/Building counts, except not clamped to a maximum of 0xFF.
This requires varaction2_house_uncapped_building_counts, version 1.

-

Building count: same class, current town (mappable variable: house_same_class_town_count)

-

This is the same as bits 16 - 23 of 44/Building counts, except not clamped to a maximum of 0xFF.
- This requires varaction2_house_uncapped_building_counts, version 1. -

Building count: same ID, whole map (mappable variable: house_same_id_map_count)

This is the same as bits 8 - 15 of 44/Building counts, except not clamped to a maximum of 0xFF.
This requires varaction2_house_uncapped_building_counts, version 1.

+

Building count: same class, current town (mappable variable: house_same_class_town_count)

+

This is the same as bits 16 - 23 of 44/Building counts, except not clamped to a maximum of 0xFF.
+ This requires varaction2_house_uncapped_building_counts, version 1. +

Building count: same class, total (mappable variable: house_same_class_map_count)

This is the same as bits 24 - 31 of 44/Building counts, except not clamped to a maximum of 0xFF.
This requires varaction2_house_uncapped_building_counts, version 1.

+

Building count: other old ID, total (mappable variable: house_other_old_id_town_count)

+

This is the same as bits 0 - 7 of 60/Other building counts, except not clamped to a maximum of 0xFF.
+ This requires varaction2_house_uncapped_building_counts, version 1. +

+

Building count: other old ID, total (mappable variable: house_other_old_id_map_count)

+

This is the same as bits 8 - 15 of 60/Other building counts, except not clamped to a maximum of 0xFF.
+ This requires varaction2_house_uncapped_building_counts, version 1. +

+

Building count: other new ID, current town (mappable variable: house_other_id_town_count)

+

This is the same as bits 0 - 7 of 61/Other building counts, except not clamped to a maximum of 0xFF.
+ This requires varaction2_house_uncapped_building_counts, version 1. +

+

Building count: other new ID, whole map (mappable variable: house_other_id_map_count)

+

This is the same as bits 8 - 15 of 61/Other building counts, except not clamped to a maximum of 0xFF.
+ This requires varaction2_house_uncapped_building_counts, version 1. +

+

Building count: other new class, current town (mappable variable: house_other_class_town_count)

+

This is the same as bits 16 - 23 of 61/Other building counts, except not clamped to a maximum of 0xFF.
+ This requires varaction2_house_uncapped_building_counts, version 1. +

+

Building count: other new class, total (mappable variable: house_other_class_map_count)

+

This is the same as bits 24 - 31 of 61/Other building counts, except not clamped to a maximum of 0xFF.
+ This requires varaction2_house_uncapped_building_counts, version 1. +


Variational Action 2 - Railtypes

Signal routing restriction information (mappable variable: railtype_signal_restriction_info)

diff --git a/src/newgrf_extension.cpp b/src/newgrf_extension.cpp index ef453e2db5..d3970f1ddf 100644 --- a/src/newgrf_extension.cpp +++ b/src/newgrf_extension.cpp @@ -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_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_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, 0x41, "roadstop_type"), GRFVariableMapDefinition(GSF_ROADSTOPS, 0x42, "roadstop_terrain_type"), diff --git a/src/newgrf_extension.h b/src/newgrf_extension.h index 3d2fc2d916..235e48a196 100644 --- a/src/newgrf_extension.h +++ b/src/newgrf_extension.h @@ -85,6 +85,12 @@ enum Action2VariableRemapIds { A2VRI_HOUSE_SAME_CLASS_MAP_COUNT, A2VRI_HOUSE_SAME_ID_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_V2, A2VRI_ROADSTOP_ROAD_INFO_NEARBY_TILES, diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 5c7746237c..8dd625ee47 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -391,6 +391,21 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex tile, Ho 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 +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. */ @@ -429,14 +444,16 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex tile, Ho /* Building counts for old houses with id = parameter. */ case 0x60: return parameter < NEW_HOUSE_OFFSET ? GetNumHouses(parameter, this->town) : 0; - /* Building counts for new houses with id = parameter. */ - case 0x61: { - const HouseSpec *hs = HouseSpec::Get(this->house_id); - if (hs->grf_prop.grffile == nullptr) return 0; + case A2VRI_HOUSE_OTHER_OLD_ID_MAP_COUNT: return parameter < NEW_HOUSE_OFFSET ? _building_counts.id_count[parameter] : 0; + case A2VRI_HOUSE_OTHER_OLD_ID_TOWN_COUNT: return parameter < NEW_HOUSE_OFFSET ? this->town->cache.building_counts.id_count[parameter] : 0; - HouseID new_house = _house_mngr.GetID(parameter, hs->grf_prop.grffile->grfid); - return new_house == INVALID_HOUSE_ID ? 0 : GetNumHouses(new_house, this->town); - } + /* Building counts for new houses with id = parameter. */ + 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. */ case 0x62: return GetNearbyTileInformation(parameter, this->tile, this->ro.grffile->grf_version >= 8, extra->mask); diff --git a/src/newgrf_house.h b/src/newgrf_house.h index ed544f456b..071e1fc414 100644 --- a/src/newgrf_house.h +++ b/src/newgrf_house.h @@ -52,6 +52,12 @@ struct HouseScopeResolver : public CommonHouseScopeResolver { uint32_t GetRandomBits() const override; uint32_t GetVariable(uint16_t variable, uint32_t parameter, GetVariableExtra *extra) const override; uint32_t GetTriggers() const override; + +private: + HouseID GetOtherHouseID(uint32_t parameter) const; + + template + uint32_t OtherHouseIDVariable(uint32_t parameter, F func) const; }; /** diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index b3425ceab5..3cb036729a 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -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_ID_TOWN_COUNT, "building count: same ID, 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() };