Skip to content

Commit

Permalink
Change: Increase house type limit to 4096.
Browse files Browse the repository at this point in the history
This moves HouseType from m4+m3[6] to m8.
  • Loading branch information
PeterN committed Mar 13, 2024
1 parent 4865ab7 commit 4799802
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
9 changes: 5 additions & 4 deletions docs/landscape.html
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,9 @@ <h3><a name="Landscape">Landscape</a></h3>
</ul>
</li>
</ul>
<li>m3 bit 6 : bit 8 of house type (m4), allowing 512 different types.</li>
<li>m3 bit 5 : free</li>
<li>m3 bits 6..5 : free</li>
<li>m3 bits 4..0 : triggers activated <a href="#newhouses">(newhouses)</a></li>
<li>m4 : <a href="landscape_externals.html">town building type</a> (with m3[6] bit)</li>
<li>m4 : free</li>
<li>m5 : see m3 bit 7</li>
<li>m6 :
<ul>
Expand Down Expand Up @@ -759,10 +758,12 @@ <h3><a name="Landscape">Landscape</a></h3>
</li>
</ul>
</li>
<li>m8 bits 15..12 : free</li>
<li>m8 bits 11..0 : <a href="landscape_externals.html">town building type</a></li>
</ul>
<small><a name="newhouses"></a>Newhouses is the name englobing a newGRF feature developed by TTDPatch devs (mainly Csaboka).<br>
It allows the replacement of the properties as well as the graphics of houses in the game.<br>
To distinguish between the standard behaviour and the newGRF one, HouseID (m4 + m3[6]) is tested for anything above 110.<br>
To distinguish between the standard behaviour and the newGRF one, HouseID is tested for anything above 110.<br>
110 is the count of standard houses. So above 110 means there is a new definition of at least one house</small>
</td>
</tr>
Expand Down
10 changes: 5 additions & 5 deletions docs/landscape_grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ <h3 style="font-weight: bold;">Landscape</h3>
<td class="caption">finished house</td>
<td class="bits" rowspan=2><span class="used" title="House random bits">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="pool" title="Town index on pool">XXXX XXXX XXXX XXXX</span></td>
<td class="bits"><span class="used" title="House is complete/in construction (see m5)">1</span> <span class="used" title="House type (m4 + m3[6])">X</span><span class="free">O</span><span class="usable" title="Activated triggers (bits 2..4 don't have a meaning)">XXX</span><span class="used" title="Activated triggers (bits 2..4 don't have a meaning)">XX</span></td>
<td class="bits" rowspan=2><span class="used" title="House type (m4 + m3[6])">XXXX XXXX</span></td>
<td class="bits"><span class="used" title="House is complete/in construction (see m5)">1</span><span class="free">OO</span><span class="usable" title="Activated triggers (bits 2..4 don't have a meaning)">X XX</span><span class="used" title="Activated triggers (bits 2..4 don't have a meaning)">XX</span></td>
<td class="bits" rowspan=2><span class="free">OOOO OOOO</span></td>
<td class="bits"><span class="used" title="Age in years, clamped at 255">XXXX XXXX</span></td>
<td class="bits" rowspan=2><span class="abuse" title="Newhouses activated: periodic processing time remaining; if not, lift position for houses 04 and 05">XXXX XX</span><span class="free">OO</span></td>
<td class="bits" rowspan=2><span class="abuse" title="If newhouses active, m7 is the current animation frame">XXXX</span> <span class="abuse" title="If newhouses active, m7 is the current animantion frame; if not, lift behaviour for houses 04 and 05">XXXX</span></td>
<td class="bits" rowspan=2><span class="free">OOOO OOOO OOOO OOOO</span></td>
<td class="bits" rowspan=2><span class="free">OOOO</span> <span class="used" title="House type">XXXX XXXX XXXX</span></td>
</tr>
<tr>
<td class="caption">house under construction</td>
<td class="bits"><span class="used" title="House is complete/in construction (see m5)">O</span> <span class="used" title="House type (m4 + m3[6])">X</span><span class="free">O</span><span class="usable" title="Activated triggers (bits 2..4 don't have a meaning)">XXX</span><span class="used" title="Activated triggers (bits 2..4 don't have a meaning)">XX</span></td>
<td class="bits"><span class="free">OOO</span><span class="used" title="Construction stage">XX</span> <span class="used" title="Construction counter">XXX</span></td>
<td class="bits"><span class="used" title="House is complete/in construction (see m5)">O</span><span class="used" title="House type (m4 + m3[6])">X</span><span class="free">O</span><span class="usable" title="Activated triggers (bits 2..4 don't have a meaning)">X XX</span><span class="used" title="Activated triggers (bits 2..4 don't have a meaning)">XX</span></td>
<td class="bits"><span class="free">OOO</span><span class="used" title="Construction stage">X X</span><span class="used" title="Construction counter">XXX</span></td>
</tr>
<tr>
<td>4</td>
Expand Down
8 changes: 4 additions & 4 deletions src/house.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
*/
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; ///< Offset for new houses.
static const HouseID NUM_HOUSES = 512; ///< Total number of houses.
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 = 0xFFFF;

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

enum BuildingFlags {
Expand Down
11 changes: 11 additions & 0 deletions src/saveload/afterload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,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();

Expand Down
2 changes: 2 additions & 0 deletions src/saveload/saveload.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ enum SaveLoadVersion : uint16_t {
SLV_SCRIPT_RANDOMIZER, ///< 333 PR#12063 v14.0-RC1 Save script randomizers.
SLV_VEHICLE_ECONOMY_AGE, ///< 334 PR#12141 v14.0 Add vehicle age in economy year, for profit stats minimum age

SLV_INCREASE_HOUSE_LIMIT, ///< 335 PR#12288 Increase house limit to 4096.

SL_MAX_VERSION, ///< Highest possible saveload version
};

Expand Down
5 changes: 2 additions & 3 deletions src/town_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 4799802

Please sign in to comment.