Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Increase house type limit to 4096. #12288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 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
2 changes: 1 addition & 1 deletion src/newgrf_house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,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<uint8_t>(hs->grf_prop.local_id);
}
return houseclass << 16 | local_houseid;
}
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