From cfaa9457a6926fb85ae477e29c2df036e2691121 Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 12 Oct 2013 16:34:04 +0000 Subject: (svn r25839) -Codechange: Use NUM_HOUSES_PER_GRF instead of NUM_HOUSES to properly distinguish limits per NewGRF and limits of the pool. -Change: [NewGRF] Lower the limit of house types per NewGRF from 256 to 255 to prevent usage of ID 0xFF in Action3, and thus allowing it to become an extended byte somewhen. --- src/house.h | 6 ++++-- src/newgrf.cpp | 16 ++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/house.h b/src/house.h index b74e13c18..ddc2a448c 100644 --- a/src/house.h +++ b/src/house.h @@ -24,9 +24,11 @@ */ static const byte TOWN_HOUSE_COMPLETED = 3; +static const HouseID NUM_HOUSES_PER_GRF = 255; ///< Number of supported houses per NewGRF; limited to 255 to allow extending Action3 with an extended byte later on. + static const uint HOUSE_NO_CLASS = 0; -static const HouseID NEW_HOUSE_OFFSET = 110; -static const HouseID NUM_HOUSES = 512; +static const HouseID NEW_HOUSE_OFFSET = 110; ///< Offset for new houses. +static const HouseID NUM_HOUSES = 512; ///< Total number of houses. static const HouseID INVALID_HOUSE_ID = 0xFFFF; /** diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 78c662ad4..8274dd8b9 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2183,14 +2183,14 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt { ChangeInfoResult ret = CIR_SUCCESS; - if (hid + numinfo > NUM_HOUSES) { - grfmsg(1, "TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring.", hid + numinfo, NUM_HOUSES); + if (hid + numinfo > NUM_HOUSES_PER_GRF) { + grfmsg(1, "TownHouseChangeInfo: Too many houses loaded (%u), max (%u). Ignoring.", hid + numinfo, NUM_HOUSES_PER_GRF); return CIR_INVALID_ID; } /* Allocate house specs if they haven't been allocated already. */ if (_cur.grffile->housespec == NULL) { - _cur.grffile->housespec = CallocT(NUM_HOUSES); + _cur.grffile->housespec = CallocT(NUM_HOUSES_PER_GRF); } for (int i = 0; i < numinfo; i++) { @@ -7789,7 +7789,7 @@ static void ResetCustomHouses() for (GRFFile **file = _grf_files.Begin(); file != end; file++) { HouseSpec **&housespec = (*file)->housespec; if (housespec == NULL) continue; - for (uint i = 0; i < NUM_HOUSES; i++) { + for (uint i = 0; i < NUM_HOUSES_PER_GRF; i++) { free(housespec[i]); } @@ -8419,14 +8419,14 @@ static void FinaliseHouseArray() HouseSpec **&housespec = (*file)->housespec; if (housespec == NULL) continue; - for (int i = 0; i < NUM_HOUSES; i++) { + for (int i = 0; i < NUM_HOUSES_PER_GRF; i++) { HouseSpec *hs = housespec[i]; if (hs == NULL) continue; - const HouseSpec *next1 = (i + 1 < NUM_HOUSES ? housespec[i + 1] : NULL); - const HouseSpec *next2 = (i + 2 < NUM_HOUSES ? housespec[i + 2] : NULL); - const HouseSpec *next3 = (i + 3 < NUM_HOUSES ? housespec[i + 3] : NULL); + const HouseSpec *next1 = (i + 1 < NUM_HOUSES_PER_GRF ? housespec[i + 1] : NULL); + const HouseSpec *next2 = (i + 2 < NUM_HOUSES_PER_GRF ? housespec[i + 2] : NULL); + const HouseSpec *next3 = (i + 3 < NUM_HOUSES_PER_GRF ? housespec[i + 3] : NULL); if (!IsHouseSpecValid(hs, next1, next2, next3, (*file)->filename)) continue; -- cgit v1.2.3-54-g00ecf