1
0
Fork 0

Codechange: Pass HouseSpec by reference to IsHouseSpecValid().

pull/14013/head
Peter Nelson 2025-04-15 19:39:55 +01:00 committed by Peter Nelson
parent b57f3262ec
commit f9ab492e64
1 changed files with 17 additions and 17 deletions

View File

@ -945,40 +945,40 @@ void FinaliseCargoArray()
* @param filename The filename of the newgrf this house was defined in.
* @return Whether the given housespec is valid.
*/
static bool IsHouseSpecValid(HouseSpec *hs, const HouseSpec *next1, const HouseSpec *next2, const HouseSpec *next3, const std::string &filename)
static bool IsHouseSpecValid(HouseSpec &hs, const HouseSpec *next1, const HouseSpec *next2, const HouseSpec *next3, const std::string &filename)
{
if ((hs->building_flags.Any(BUILDING_HAS_2_TILES) &&
if ((hs.building_flags.Any(BUILDING_HAS_2_TILES) &&
(next1 == nullptr || !next1->enabled || next1->building_flags.Any(BUILDING_HAS_1_TILE))) ||
(hs->building_flags.Any(BUILDING_HAS_4_TILES) &&
(hs.building_flags.Any(BUILDING_HAS_4_TILES) &&
(next2 == nullptr || !next2->enabled || next2->building_flags.Any(BUILDING_HAS_1_TILE) ||
next3 == nullptr || !next3->enabled || next3->building_flags.Any(BUILDING_HAS_1_TILE)))) {
hs->enabled = false;
if (!filename.empty()) Debug(grf, 1, "FinaliseHouseArray: {} defines house {} as multitile, but no suitable tiles follow. Disabling house.", filename, hs->grf_prop.local_id);
hs.enabled = false;
if (!filename.empty()) Debug(grf, 1, "FinaliseHouseArray: {} defines house {} as multitile, but no suitable tiles follow. Disabling house.", filename, hs.grf_prop.local_id);
return false;
}
/* Some places sum population by only counting north tiles. Other places use all tiles causing desyncs.
* As the newgrf specs define population to be zero for non-north tiles, we just disable the offending house.
* If you want to allow non-zero populations somewhen, make sure to sum the population of all tiles in all places. */
if ((hs->building_flags.Any(BUILDING_HAS_2_TILES) && next1->population != 0) ||
(hs->building_flags.Any(BUILDING_HAS_4_TILES) && (next2->population != 0 || next3->population != 0))) {
hs->enabled = false;
if (!filename.empty()) Debug(grf, 1, "FinaliseHouseArray: {} defines multitile house {} with non-zero population on additional tiles. Disabling house.", filename, hs->grf_prop.local_id);
if ((hs.building_flags.Any(BUILDING_HAS_2_TILES) && next1->population != 0) ||
(hs.building_flags.Any(BUILDING_HAS_4_TILES) && (next2->population != 0 || next3->population != 0))) {
hs.enabled = false;
if (!filename.empty()) Debug(grf, 1, "FinaliseHouseArray: {} defines multitile house {} with non-zero population on additional tiles. Disabling house.", filename, hs.grf_prop.local_id);
return false;
}
/* Substitute type is also used for override, and having an override with a different size causes crashes.
* This check should only be done for NewGRF houses because grf_prop.subst_id is not set for original houses.*/
if (!filename.empty() && (hs->building_flags & BUILDING_HAS_1_TILE) != (HouseSpec::Get(hs->grf_prop.subst_id)->building_flags & BUILDING_HAS_1_TILE)) {
hs->enabled = false;
Debug(grf, 1, "FinaliseHouseArray: {} defines house {} with different house size then it's substitute type. Disabling house.", filename, hs->grf_prop.local_id);
if (!filename.empty() && (hs.building_flags & BUILDING_HAS_1_TILE) != (HouseSpec::Get(hs.grf_prop.subst_id)->building_flags & BUILDING_HAS_1_TILE)) {
hs.enabled = false;
Debug(grf, 1, "FinaliseHouseArray: {} defines house {} with different house size then it's substitute type. Disabling house.", filename, hs.grf_prop.local_id);
return false;
}
/* Make sure that additional parts of multitile houses are not available. */
if (!hs->building_flags.Any(BUILDING_HAS_1_TILE) && (hs->building_availability & HZ_ZONALL) != 0 && (hs->building_availability & HZ_CLIMALL) != 0) {
hs->enabled = false;
if (!filename.empty()) Debug(grf, 1, "FinaliseHouseArray: {} defines house {} without a size but marked it as available. Disabling house.", filename, hs->grf_prop.local_id);
if (!hs.building_flags.Any(BUILDING_HAS_1_TILE) && (hs.building_availability & HZ_ZONALL) != 0 && (hs.building_availability & HZ_CLIMALL) != 0) {
hs.enabled = false;
if (!filename.empty()) Debug(grf, 1, "FinaliseHouseArray: {} defines house {} without a size but marked it as available. Disabling house.", filename, hs.grf_prop.local_id);
return false;
}
@ -1040,7 +1040,7 @@ static void FinaliseHouseArray()
const HouseSpec *next2 = (i + 2 < num_houses ? file.housespec[i + 2].get() : nullptr);
const HouseSpec *next3 = (i + 3 < num_houses ? file.housespec[i + 3].get() : nullptr);
if (!IsHouseSpecValid(hs, next1, next2, next3, file.filename)) continue;
if (!IsHouseSpecValid(*hs, next1, next2, next3, file.filename)) continue;
_house_mngr.SetEntitySpec(hs);
}
@ -1054,7 +1054,7 @@ static void FinaliseHouseArray()
/* We need to check all houses again to we are sure that multitile houses
* did get consecutive IDs and none of the parts are missing. */
if (!IsHouseSpecValid(hs, next1, next2, next3, std::string{})) {
if (!IsHouseSpecValid(*hs, next1, next2, next3, std::string{})) {
/* GetHouseNorthPart checks 3 houses that are directly before
* it in the house pool. If any of those houses have multi-tile
* flags set it assumes it's part of a multitile house. Since