Update to 14.0-beta1

This commit is contained in:
dP
2024-02-04 02:18:17 +05:30
parent 79037e2c65
commit 33ef333b57
1325 changed files with 138461 additions and 70983 deletions
+45 -41
View File
@@ -24,8 +24,8 @@
#include "safeguards.h"
static BuildingCounts<uint32> _building_counts;
static HouseClassMapping _class_mapping[HOUSE_CLASS_MAX];
static BuildingCounts<uint32_t> _building_counts;
static std::array<HouseClassMapping, HOUSE_CLASS_MAX> _class_mapping;
HouseOverrideManager _house_mngr(NEW_HOUSE_OFFSET, NUM_HOUSES, INVALID_HOUSE_ID);
@@ -53,8 +53,8 @@ static const GRFFile *GetHouseSpecGrf(HouseID house_id)
* @param watched_cargo_triggers Cargo types that triggered the watched cargo callback.
*/
HouseResolverObject::HouseResolverObject(HouseID house_id, TileIndex tile, Town *town,
CallbackID callback, uint32 param1, uint32 param2,
bool not_yet_constructed, uint8 initial_random_bits, CargoTypes watched_cargo_triggers)
CallbackID callback, uint32_t param1, uint32_t param2,
bool not_yet_constructed, uint8_t initial_random_bits, CargoTypes watched_cargo_triggers)
: ResolverObject(GetHouseSpecGrf(house_id), callback, param1, param2),
house_scope(*this, house_id, tile, town, not_yet_constructed, initial_random_bits, watched_cargo_triggers),
town_scope(*this, town, not_yet_constructed) // Don't access StorePSA if house is not yet constructed.
@@ -67,12 +67,17 @@ GrfSpecFeature HouseResolverObject::GetFeature() const
return GSF_HOUSES;
}
uint32 HouseResolverObject::GetDebugID() const
uint32_t HouseResolverObject::GetDebugID() const
{
return HouseSpec::Get(this->house_scope.house_id)->grf_prop.local_id;
}
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
void ResetHouseClassIDs()
{
_class_mapping = {};
}
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32_t grfid)
{
/* Start from 1 because 0 means that no class has been assigned. */
for (int i = 1; i != lengthof(_class_mapping); i++) {
@@ -136,29 +141,28 @@ void DecreaseBuildingCount(Town *t, HouseID house_id)
if (_building_counts.class_count[class_id] > 0) _building_counts.class_count[class_id]--;
}
/* virtual */ uint32 HouseScopeResolver::GetRandomBits() const
/* virtual */ uint32_t HouseScopeResolver::GetRandomBits() const
{
/* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */
assert(IsValidTile(this->tile) && (this->not_yet_constructed || IsTileType(this->tile, MP_HOUSE)));
return this->not_yet_constructed ? this->initial_random_bits : GetHouseRandomBits(this->tile);
}
/* virtual */ uint32 HouseScopeResolver::GetTriggers() const
/* virtual */ uint32_t HouseScopeResolver::GetTriggers() const
{
/* Note: Towns build houses over houses. So during construction checks 'tile' may be a valid but unrelated house. */
assert(IsValidTile(this->tile) && (this->not_yet_constructed || IsTileType(this->tile, MP_HOUSE)));
return this->not_yet_constructed ? 0 : GetHouseTriggers(this->tile);
}
static uint32 GetNumHouses(HouseID house_id, const Town *town)
static uint32_t GetNumHouses(HouseID house_id, const Town *town)
{
uint8 map_id_count, town_id_count, map_class_count, town_class_count;
HouseClassID class_id = HouseSpec::Get(house_id)->class_id;
map_id_count = ClampU(_building_counts.id_count[house_id], 0, 255);
map_class_count = ClampU(_building_counts.class_count[class_id], 0, 255);
town_id_count = ClampU(town->cache.building_counts.id_count[house_id], 0, 255);
town_class_count = ClampU(town->cache.building_counts.class_count[class_id], 0, 255);
uint8_t map_id_count = ClampTo<uint8_t>(_building_counts.id_count[house_id]);
uint8_t map_class_count = ClampTo<uint8_t>(_building_counts.class_count[class_id]);
uint8_t town_id_count = ClampTo<uint8_t>(town->cache.building_counts.id_count[house_id]);
uint8_t town_class_count = ClampTo<uint8_t>(town->cache.building_counts.class_count[class_id]);
return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count;
}
@@ -170,7 +174,7 @@ static uint32 GetNumHouses(HouseID house_id, const Town *town)
* @param grf_version8 True, if we are dealing with a new NewGRF which uses GRF version >= 8.
* @return a construction of bits obeying the newgrf format
*/
static uint32 GetNearbyTileInformation(byte parameter, TileIndex tile, bool grf_version8)
static uint32_t GetNearbyTileInformation(byte parameter, TileIndex tile, bool grf_version8)
{
tile = GetNearbyTile(parameter, tile);
return GetNearbyTileInformation(tile, grf_version8);
@@ -263,7 +267,7 @@ static bool SearchNearbyHouseGRFID(TileIndex tile, void *user_data)
* @param house the HouseID that is associated to the house, the callback is called for
* @return the Manhattan distance from the center tile, if any, and 0 if failure
*/
static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseID house)
static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex tile, HouseID house)
{
static TestTileOnSearchProc * const search_procs[3] = {
SearchNearbyHouseID,
@@ -271,8 +275,8 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
SearchNearbyHouseGRFID,
};
TileIndex found_tile = tile;
uint8 searchtype = GB(parameter, 6, 2);
uint8 searchradius = GB(parameter, 0, 6);
uint8_t searchtype = GB(parameter, 6, 2);
uint8_t searchradius = GB(parameter, 0, 6);
if (searchtype >= lengthof(search_procs)) return 0; // do not run on ill-defined code
if (searchradius < 1) return 0; // do not use a too low radius
@@ -290,14 +294,14 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
/**
* @note Used by the resolver to get values for feature 07 deterministic spritegroups.
*/
/* virtual */ uint32 HouseScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
/* virtual */ uint32_t HouseScopeResolver::GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const
{
switch (variable) {
/* Construction stage. */
case 0x40: return (IsTileType(this->tile, MP_HOUSE) ? GetHouseBuildingStage(this->tile) : 0) | TileHash2Bit(TileX(this->tile), TileY(this->tile)) << 2;
/* Building age. */
case 0x41: return IsTileType(this->tile, MP_HOUSE) ? GetHouseAge(this->tile) : 0;
case 0x41: return IsTileType(this->tile, MP_HOUSE) ? GetHouseAge(this->tile).base() : 0;
/* Town zone */
case 0x42: return GetTownRadiusGroup(this->town, this->tile);
@@ -341,18 +345,18 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
/* Cargo acceptance history of nearby stations */
case 0x64: {
CargoID cid = GetCargoTranslation(parameter, this->ro.grffile);
if (cid == CT_INVALID) return 0;
if (!IsValidCargoID(cid)) return 0;
/* Extract tile offset. */
int8 x_offs = GB(GetRegister(0x100), 0, 8);
int8 y_offs = GB(GetRegister(0x100), 8, 8);
TileIndex testtile = TILE_MASK(this->tile + TileDiffXY(x_offs, y_offs));
int8_t x_offs = GB(GetRegister(0x100), 0, 8);
int8_t y_offs = GB(GetRegister(0x100), 8, 8);
TileIndex testtile = Map::WrapToMap(this->tile + TileDiffXY(x_offs, y_offs));
StationFinder stations(TileArea(testtile, 1, 1));
const StationList *sl = stations.GetStations();
/* Collect acceptance stats. */
uint32 res = 0;
uint32_t res = 0;
for (Station *st : *sl) {
if (HasBit(st->goods[cid].status, GoodsEntry::GES_EVER_ACCEPTED)) SetBit(res, 0);
if (HasBit(st->goods[cid].status, GoodsEntry::GES_LAST_MONTH)) SetBit(res, 1);
@@ -410,8 +414,8 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
return UINT_MAX;
}
uint16 GetHouseCallback(CallbackID callback, uint32 param1, uint32 param2, HouseID house_id, Town *town, TileIndex tile,
bool not_yet_constructed, uint8 initial_random_bits, CargoTypes watched_cargo_triggers)
uint16_t GetHouseCallback(CallbackID callback, uint32_t param1, uint32_t param2, HouseID house_id, Town *town, TileIndex tile,
bool not_yet_constructed, uint8_t initial_random_bits, CargoTypes watched_cargo_triggers)
{
assert(IsValidTile(tile) && (not_yet_constructed || IsTileType(tile, MP_HOUSE)));
@@ -425,9 +429,9 @@ static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *grou
const DrawTileSprites *dts = group->ProcessRegisters(&stage);
const HouseSpec *hs = HouseSpec::Get(house_id);
PaletteID palette = hs->random_colour[TileHash2Bit(ti->x, ti->y)] + PALETTE_RECOLOUR_START;
PaletteID palette = GENERAL_SPRITE_COLOUR(hs->random_colour[TileHash2Bit(ti->x, ti->y)]);
if (HasBit(hs->callback_mask, CBM_HOUSE_COLOUR)) {
uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, Town::GetByTile(ti->tile), ti->tile);
uint16_t callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, Town::GetByTile(ti->tile), ti->tile);
if (callback != CALLBACK_FAILED) {
/* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
palette = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
@@ -455,7 +459,7 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
bool draw_old_one = true;
if (HasBit(hs->callback_mask, CBM_HOUSE_DRAW_FOUNDATIONS)) {
/* Called to determine the type (if any) of foundation to draw for the house tile */
uint32 callback_res = GetHouseCallback(CBID_HOUSE_DRAW_FOUNDATIONS, 0, 0, house_id, Town::GetByTile(ti->tile), ti->tile);
uint32_t callback_res = GetHouseCallback(CBID_HOUSE_DRAW_FOUNDATIONS, 0, 0, house_id, Town::GetByTile(ti->tile), ti->tile);
if (callback_res != CALLBACK_FAILED) draw_old_one = ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DRAW_FOUNDATIONS, callback_res);
}
@@ -474,13 +478,13 @@ void DrawNewHouseTile(TileInfo *ti, HouseID house_id)
}
/* Simple wrapper for GetHouseCallback to keep the animation unified. */
uint16 GetSimpleHouseCallback(CallbackID callback, uint32 param1, uint32 param2, const HouseSpec *spec, Town *town, TileIndex tile, CargoTypes extra_data)
uint16_t GetSimpleHouseCallback(CallbackID callback, uint32_t param1, uint32_t param2, const HouseSpec *spec, Town *town, TileIndex tile, CargoTypes extra_data)
{
return GetHouseCallback(callback, param1, param2, spec - HouseSpec::Get(0), town, tile, false, 0, extra_data);
}
/** Helper class for animation control. */
struct HouseAnimationBase : public AnimationBase<HouseAnimationBase, HouseSpec, Town, CargoTypes, GetSimpleHouseCallback> {
struct HouseAnimationBase : public AnimationBase<HouseAnimationBase, HouseSpec, Town, CargoTypes, GetSimpleHouseCallback, TileAnimationFrameAnimationHelper<Town> > {
static const CallbackID cb_animation_speed = CBID_HOUSE_ANIMATION_SPEED;
static const CallbackID cb_animation_next_frame = CBID_HOUSE_ANIMATION_NEXT_FRAME;
@@ -516,19 +520,19 @@ bool CanDeleteHouse(TileIndex tile)
}
if (HasBit(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) {
uint16 callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile);
uint16_t callback_res = GetHouseCallback(CBID_HOUSE_DENY_DESTRUCTION, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile);
return (callback_res == CALLBACK_FAILED || !ConvertBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DENY_DESTRUCTION, callback_res));
} else {
return !(hs->extra_flags & BUILDING_IS_PROTECTED);
}
}
static void AnimationControl(TileIndex tile, uint16 random_bits)
static void AnimationControl(TileIndex tile, uint16_t random_bits)
{
const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) {
uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
uint32_t param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_ANIMATION_START_STOP, hs, Town::GetByTile(tile), tile, param, 0);
}
}
@@ -551,7 +555,7 @@ bool NewHouseTileLoop(TileIndex tile)
* tile loop reaches them. This should only be enabled for the northern
* tile, or strange things will happen (here, and in TTDPatch). */
if (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) {
uint16 random = GB(Random(), 0, 16);
uint16_t random = GB(Random(), 0, 16);
if (hs->building_flags & BUILDING_HAS_1_TILE) AnimationControl(tile, random);
if (hs->building_flags & BUILDING_2_TILES_Y) AnimationControl(TILE_ADDXY(tile, 0, 1), random);
@@ -564,7 +568,7 @@ bool NewHouseTileLoop(TileIndex tile)
/* Check callback 21, which determines if a house should be destroyed. */
if (HasBit(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) {
uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile);
uint16_t callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile);
if (callback_res != CALLBACK_FAILED && Convert8bitBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DESTRUCTION, callback_res)) {
ClearTownHouse(Town::GetByTile(tile), tile);
return false;
@@ -599,7 +603,7 @@ static void DoTriggerHouse(TileIndex tile, HouseTrigger trigger, byte base_rando
/* Rerandomise bits. Scopes other than SELF are invalid for houses. For bug-to-bug-compatibility with TTDP we ignore the scope. */
byte new_random_bits = Random();
byte random_bits = GetHouseRandomBits(tile);
uint32 reseed = object.GetReseedSum();
uint32_t reseed = object.GetReseedSum();
random_bits &= ~reseed;
random_bits |= (first ? new_random_bits : base_random) & reseed;
SetHouseRandomBits(tile, random_bits);
@@ -635,10 +639,10 @@ void TriggerHouse(TileIndex t, HouseTrigger trigger)
* @param trigger_cargoes Cargo types that triggered the callback.
* @param random Random bits.
*/
void DoWatchedCargoCallback(TileIndex tile, TileIndex origin, CargoTypes trigger_cargoes, uint16 random)
void DoWatchedCargoCallback(TileIndex tile, TileIndex origin, CargoTypes trigger_cargoes, uint16_t random)
{
TileIndexDiffC diff = TileIndexToTileIndexDiffC(origin, tile);
uint32 cb_info = random << 16 | (uint8)diff.y << 8 | (uint8)diff.x;
uint32_t cb_info = random << 16 | (uint8_t)diff.y << 8 | (uint8_t)diff.x;
HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_WATCHED_CARGO_ACCEPTED, HouseSpec::Get(GetHouseType(tile)), Town::GetByTile(tile), tile, 0, cb_info, trigger_cargoes);
}
@@ -659,7 +663,7 @@ void WatchedCargoCallback(TileIndex tile, CargoTypes trigger_cargoes)
if (trigger_cargoes == 0) return;
/* Same random value for all tiles of a multi-tile house. */
uint16 r = Random();
uint16_t r = Random();
/* Do the callback, start at northern tile. */
TileIndex north = tile + GetHouseNorthPart(id);