@@ -28,7 +28,7 @@
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
static BuildingCounts<uint32> _building_counts;
|
||||
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);
|
||||
@@ -57,8 +57,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.
|
||||
@@ -71,7 +71,7 @@ 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;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ uint32 HouseResolverObject::GetDebugID() const
|
||||
* @param watched_cargo_triggers Cargo types that triggered the watched cargo callback.
|
||||
*/
|
||||
FakeHouseResolverObject::FakeHouseResolverObject(HouseID house_id,
|
||||
CallbackID callback, uint32 param1, uint32 param2)
|
||||
CallbackID callback, uint32_t param1, uint32_t param2)
|
||||
: ResolverObject(GetHouseSpecGrf(house_id), callback, param1, param2),
|
||||
house_scope(*this, house_id),
|
||||
town_scope(*this) // Don't access StorePSA if house is not yet constructed.
|
||||
@@ -100,7 +100,7 @@ GrfSpecFeature FakeHouseResolverObject::GetFeature() const
|
||||
return GSF_HOUSES;
|
||||
}
|
||||
|
||||
uint32 FakeHouseResolverObject::GetDebugID() const
|
||||
uint32_t FakeHouseResolverObject::GetDebugID() const
|
||||
{
|
||||
return HouseSpec::Get(this->house_scope.house_id)->grf_prop.local_id;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ void ResetHouseClassIDs()
|
||||
_class_mapping = {};
|
||||
}
|
||||
|
||||
HouseClassID AllocateHouseClassID(byte grf_class_id, uint32 grfid)
|
||||
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++) {
|
||||
@@ -174,21 +174,21 @@ 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_tile(IsValidTile(this->tile) && (this->not_yet_constructed || IsTileType(this->tile, MP_HOUSE)), this->tile);
|
||||
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_tile(IsValidTile(this->tile) && (this->not_yet_constructed || IsTileType(this->tile, MP_HOUSE)), this->tile);
|
||||
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)
|
||||
{
|
||||
HouseClassID class_id = HouseSpec::Get(house_id)->class_id;
|
||||
|
||||
@@ -207,7 +207,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, uint32 mask)
|
||||
static uint32_t GetNearbyTileInformation(byte parameter, TileIndex tile, bool grf_version8, uint32_t mask)
|
||||
{
|
||||
tile = GetNearbyTile(parameter, tile);
|
||||
return GetNearbyTileInformation(tile, grf_version8, mask);
|
||||
@@ -300,7 +300,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,
|
||||
@@ -308,8 +308,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
|
||||
|
||||
@@ -327,7 +327,7 @@ 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(uint16 variable, uint32 parameter, GetVariableExtra *extra) const
|
||||
/* virtual */ uint32_t HouseScopeResolver::GetVariable(uint16_t variable, uint32_t parameter, GetVariableExtra *extra) const
|
||||
{
|
||||
switch (variable) {
|
||||
/* Construction stage. */
|
||||
@@ -381,15 +381,15 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
|
||||
if (cid == CT_INVALID) return 0;
|
||||
|
||||
/* Extract tile offset. */
|
||||
int8 x_offs = GB(GetRegister(0x100), 0, 8);
|
||||
int8 y_offs = GB(GetRegister(0x100), 8, 8);
|
||||
int8_t x_offs = GB(GetRegister(0x100), 0, 8);
|
||||
int8_t y_offs = GB(GetRegister(0x100), 8, 8);
|
||||
TileIndex testtile = TILE_MASK(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);
|
||||
@@ -451,7 +451,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
|
||||
/**
|
||||
* @note Used by the resolver to get values for feature 07 deterministic spritegroups.
|
||||
*/
|
||||
/* virtual */ uint32 FakeHouseScopeResolver::GetVariable(uint16 variable, uint32 parameter, GetVariableExtra *extra) const
|
||||
/* virtual */ uint32_t FakeHouseScopeResolver::GetVariable(uint16_t variable, uint32_t parameter, GetVariableExtra *extra) const
|
||||
{
|
||||
switch (variable) {
|
||||
/* Construction stage. */
|
||||
@@ -509,8 +509,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)
|
||||
{
|
||||
if (tile != INVALID_TILE) {
|
||||
HouseResolverObject object(house_id, tile, town, callback, param1, param2,
|
||||
@@ -534,7 +534,7 @@ StringID GetHouseName(HouseID house_id, TileIndex tile)
|
||||
bool house_completed = (tile == INVALID_TILE) || IsHouseCompleted(tile);
|
||||
Town *t = (tile == INVALID_TILE) ? nullptr : Town::GetByTile(tile);
|
||||
|
||||
uint16 callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house_id, t, tile);
|
||||
uint16_t callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, house_completed ? 1 : 0, 0, house_id, t, tile);
|
||||
if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
|
||||
if (callback_res > 0x400) {
|
||||
ErrorUnknownCallbackResult(hs->grf_prop.grffile->grfid, CBID_HOUSE_CUSTOM_NAME, callback_res);
|
||||
@@ -552,7 +552,7 @@ static inline PaletteID GetHouseColour(HouseID house_id, TileIndex tile = INVALI
|
||||
const HouseSpec *hs = HouseSpec::Get(house_id);
|
||||
if (HasBit(hs->callback_mask, CBM_HOUSE_COLOUR)) {
|
||||
Town *t = (tile != INVALID_TILE) ? Town::GetByTile(tile) : nullptr;
|
||||
uint16 callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, t, tile);
|
||||
uint16_t callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, t, tile);
|
||||
if (callback != CALLBACK_FAILED) {
|
||||
/* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
|
||||
return HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
|
||||
@@ -608,7 +608,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);
|
||||
}
|
||||
|
||||
@@ -636,7 +636,7 @@ void DrawNewHouseTileInGUI(int x, int y, HouseID house_id, bool ground)
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
@@ -667,7 +667,7 @@ void AnimateNewHouseConstruction(TileIndex tile)
|
||||
}
|
||||
}
|
||||
|
||||
uint8 GetNewHouseTileAnimationSpeed(TileIndex tile)
|
||||
uint8_t GetNewHouseTileAnimationSpeed(TileIndex tile)
|
||||
{
|
||||
const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
|
||||
if (hs == nullptr) return 0;
|
||||
@@ -687,7 +687,7 @@ bool HouseAllowsConstruction(HouseID house_id, TileIndex tile, Town *t, byte ran
|
||||
{
|
||||
const HouseSpec *hs = HouseSpec::Get(house_id);
|
||||
if (HasBit(hs->callback_mask, CBM_HOUSE_ALLOW_CONSTRUCTION)) {
|
||||
uint16 callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house_id, t, tile, true, random_bits);
|
||||
uint16_t callback_res = GetHouseCallback(CBID_HOUSE_ALLOW_CONSTRUCTION, 0, 0, house_id, t, tile, true, random_bits);
|
||||
if (callback_res != CALLBACK_FAILED && !Convert8bitBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_ALLOW_CONSTRUCTION, callback_res)) {
|
||||
return false;
|
||||
}
|
||||
@@ -706,19 +706,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);
|
||||
}
|
||||
}
|
||||
@@ -745,7 +745,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);
|
||||
@@ -759,7 +759,7 @@ bool NewHouseTileLoop(TileIndex tile)
|
||||
/* Check callback 21, which determines if a house should be destroyed. */
|
||||
if (HasBit(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) {
|
||||
Town *t = Town::GetByTile(tile);
|
||||
uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), t, tile);
|
||||
uint16_t callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), t, tile);
|
||||
if (callback_res != CALLBACK_FAILED && Convert8bitBooleanCallback(hs->grf_prop.grffile, CBID_HOUSE_DESTRUCTION, callback_res)) {
|
||||
ClearTownHouse(t, tile);
|
||||
return false;
|
||||
@@ -794,7 +794,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);
|
||||
@@ -830,10 +830,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);
|
||||
}
|
||||
|
||||
@@ -854,7 +854,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);
|
||||
|
Reference in New Issue
Block a user