diff --git a/docs/landscape.html b/docs/landscape.html index 94b7795a68..ab918a77ff 100644 --- a/docs/landscape.html +++ b/docs/landscape.html @@ -721,10 +721,9 @@ -
  • m3 bit 6 : bit 8 of house type (m4), allowing 512 different types.
  • -
  • m3 bit 5 : free
  • +
  • m3 bits 6..5 : free
  • m3 bits 4..0 : triggers activated (newhouses)
  • -
  • m4 : town building type (with m3[6] bit)
  • +
  • m4 : free
  • m5 : see m3 bit 7
  • m6 :
  • +
  • m8 bits 15..12 : free
  • +
  • m8 bits 11..0 : town building type
  • Newhouses is the name englobing a newGRF feature developed by TTDPatch devs (mainly Csaboka).
    It allows the replacement of the properties as well as the graphics of houses in the game.
    - To distinguish between the standard behaviour and the newGRF one, HouseID (m4 + m3[6]) is tested for anything above 110.
    + To distinguish between the standard behaviour and the newGRF one, HouseID is tested for anything above 110.
    110 is the count of standard houses. So above 110 means there is a new definition of at least one house
    diff --git a/docs/landscape_grid.html b/docs/landscape_grid.html index 23bd4980b8..e7d2d99f68 100644 --- a/docs/landscape_grid.html +++ b/docs/landscape_grid.html @@ -156,17 +156,17 @@ the array so you can quickly see what is used and what is not. finished house XXXX XXXX XXXX XXXX XXXX XXXX - 1 XOXXXXX - XXXX XXXX + 1OOX XXXX + OOOO OOOO XXXX XXXX XXXX XXXX XXXX XXXX - OOOO OOOO OOOO OOOO + OOOO XXXX XXXX XXXX house under construction - O XOXXXXX - OOOXX XXX + OXOX XXXX + OOOX XXXX 4 diff --git a/src/house.h b/src/house.h index 4f19c6d40b..76fe41739d 100644 --- a/src/house.h +++ b/src/house.h @@ -22,12 +22,12 @@ */ static const uint8_t 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; ///< Offset for new houses. -static const HouseID NUM_HOUSES = 512; ///< Total number of houses. -static const HouseID INVALID_HOUSE_ID = 0xFFFF; +static const HouseID NEW_HOUSE_OFFSET = 110; ///< Offset for new houses. +static const HouseID NUM_HOUSES = 4096; ///< Total number of houses. +static const HouseID INVALID_HOUSE_ID = UINT16_MAX; + +static const HouseID NUM_HOUSES_PER_GRF = NUM_HOUSES; ///< Number of supported houses per NewGRF. static const uint HOUSE_NUM_ACCEPTS = 16; ///< Max number of cargoes accepted by a tile static const uint HOUSE_ORIGINAL_NUM_ACCEPTS = 3; ///< Original number of accepted cargo types. diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index b87aaa63a5..e71d271df0 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -492,7 +492,7 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex tile, Ho local_houseid = nearby_house_id; } else { local_houseid = (hs->grf_prop.grffile == this->ro.grffile ? 1 : 2) << 8; - local_houseid |= hs->grf_prop.local_id; + local_houseid |= ClampTo(hs->grf_prop.local_id); // Spec only allows 8 bits, so all local-ids above 254 are clamped. } return houseclass << 16 | local_houseid; } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 60765ba924..1782d052b2 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1539,6 +1539,17 @@ bool AfterLoadGame() } } + if (IsSavegameVersionBefore(SLV_INCREASE_HOUSE_LIMIT)) { + for (auto t : Map::Iterate()) { + if (IsTileType(t, MP_HOUSE)) { + /* House type is moved from m4 + m3[6] to m8. */ + SetHouseType(t, t.m4() | (GB(t.m3(), 6, 1) << 8)); + t.m4() = 0; + ClrBit(t.m3(), 6); + } + } + } + /* Check and update house and town values */ UpdateHousesAndTowns(); diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index be0c3d9683..8caa133ef8 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -394,6 +394,7 @@ enum SaveLoadVersion : uint16_t { SLV_NONFLOODING_WATER_TILES, ///< 345 PR#13013 Store water tile non-flooding state. SLV_PATH_CACHE_FORMAT, ///< 346 PR#12345 Vehicle path cache format changed. SLV_ANIMATED_TILE_STATE_IN_MAP, ///< 347 PR#13082 Animated tile state saved for improved performance. + SLV_INCREASE_HOUSE_LIMIT, ///< 348 PR#12288 Increase house limit to 4096. SL_MAX_VERSION, ///< Highest possible saveload version }; diff --git a/src/town_map.h b/src/town_map.h index 39131c5ec1..aae94676ac 100644 --- a/src/town_map.h +++ b/src/town_map.h @@ -48,7 +48,7 @@ inline void SetTownIndex(Tile t, TownID index) inline HouseID GetCleanHouseType(Tile t) { assert(IsTileType(t, MP_HOUSE)); - return t.m4() | (GB(t.m3(), 6, 1) << 8); + return GB(t.m8(), 0, 12); } /** @@ -71,8 +71,7 @@ inline HouseID GetHouseType(Tile t) inline void SetHouseType(Tile t, HouseID house_id) { assert(IsTileType(t, MP_HOUSE)); - t.m4() = GB(house_id, 0, 8); - SB(t.m3(), 6, 1, GB(house_id, 8, 1)); + SB(t.m8(), 0, 12, house_id); } /**