mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use EnumBitSet for HouseExtraFlags.
parent
2c7b3bb55d
commit
113205c540
16
src/house.h
16
src/house.h
|
@ -81,15 +81,13 @@ enum HouseZones : uint16_t {
|
|||
};
|
||||
DECLARE_ENUM_AS_BIT_SET(HouseZones)
|
||||
|
||||
enum HouseExtraFlags : uint8_t {
|
||||
NO_EXTRA_FLAG = 0,
|
||||
BUILDING_IS_HISTORICAL = 1U << 0, ///< this house will only appear during town generation in random games, thus the historical
|
||||
BUILDING_IS_PROTECTED = 1U << 1, ///< towns and AI will not remove this house, while human players will be able to
|
||||
SYNCHRONISED_CALLBACK_1B = 1U << 2, ///< synchronized callback 1B will be performed, on multi tile houses
|
||||
CALLBACK_1A_RANDOM_BITS = 1U << 3, ///< callback 1A needs random bits
|
||||
enum class HouseExtraFlag : uint8_t {
|
||||
BuildingIsHistorical = 0, ///< this house will only appear during town generation in random games, thus the historical
|
||||
BuildingIsProtected = 1, ///< towns and AI will not remove this house, while human players will be able to
|
||||
SynchronisedCallback1B = 2, ///< synchronized callback 1B will be performed, on multi tile houses
|
||||
Callback1ARandomBits = 3, ///< callback 1A needs random bits
|
||||
};
|
||||
|
||||
DECLARE_ENUM_AS_BIT_SET(HouseExtraFlags)
|
||||
using HouseExtraFlags = EnumBitSet<HouseExtraFlag, uint8_t>;
|
||||
|
||||
struct HouseSpec {
|
||||
/* Standard properties */
|
||||
|
@ -111,7 +109,7 @@ struct HouseSpec {
|
|||
HouseCallbackMasks callback_mask; ///< Bitmask of house callbacks that have to be called
|
||||
Colours random_colour[4]; ///< 4 "random" colours
|
||||
uint8_t probability; ///< Relative probability of appearing (16 is the standard value)
|
||||
HouseExtraFlags extra_flags; ///< some more flags
|
||||
HouseExtraFlags extra_flags{}; ///< some more flags
|
||||
HouseClassID class_id; ///< defines the class this house has (not grf file based)
|
||||
AnimationInfo animation; ///< information about the animation.
|
||||
uint8_t processing_time; ///< Periodic refresh multiplier
|
||||
|
|
|
@ -2607,7 +2607,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint first, uint last, int prop, Byt
|
|||
break;
|
||||
|
||||
case 0x19: // Extra flags
|
||||
housespec->extra_flags = (HouseExtraFlags)buf.ReadByte();
|
||||
housespec->extra_flags = static_cast<HouseExtraFlags>(buf.ReadByte());
|
||||
break;
|
||||
|
||||
case 0x1A: // Animation frames
|
||||
|
|
|
@ -596,7 +596,7 @@ void AnimateNewHouseTile(TileIndex tile)
|
|||
const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
|
||||
if (hs == nullptr) return;
|
||||
|
||||
HouseAnimationBase::AnimateTile(hs, Town::GetByTile(tile), tile, HasFlag(hs->extra_flags, CALLBACK_1A_RANDOM_BITS));
|
||||
HouseAnimationBase::AnimateTile(hs, Town::GetByTile(tile), tile, hs->extra_flags.Test(HouseExtraFlag::Callback1ARandomBits));
|
||||
}
|
||||
|
||||
void AnimateNewHouseConstruction(TileIndex tile)
|
||||
|
@ -622,7 +622,7 @@ bool CanDeleteHouse(TileIndex 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);
|
||||
return !hs->extra_flags.Test(HouseExtraFlag::BuildingIsProtected);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -631,7 +631,7 @@ static void AnimationControl(TileIndex tile, uint16_t random_bits)
|
|||
const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile));
|
||||
|
||||
if (hs->callback_mask.Test(HouseCallbackMask::AnimationStartStop)) {
|
||||
uint32_t param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
|
||||
uint32_t param = hs->extra_flags.Test(HouseExtraFlag::SynchronisedCallback1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
|
||||
HouseAnimationBase::ChangeAnimationFrame(CBID_HOUSE_ANIMATION_START_STOP, hs, Town::GetByTile(tile), tile, param, 0);
|
||||
}
|
||||
}
|
||||
|
@ -653,7 +653,7 @@ bool NewHouseTileLoop(TileIndex tile)
|
|||
* tiles will have the callback called at once, rather than when the
|
||||
* 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) {
|
||||
if (hs->extra_flags.Test(HouseExtraFlag::SynchronisedCallback1B)) {
|
||||
uint16_t random = GB(Random(), 0, 16);
|
||||
|
||||
if (hs->building_flags & BUILDING_HAS_1_TILE) AnimationControl(tile, random);
|
||||
|
|
|
@ -1814,7 +1814,7 @@ static_assert(lengthof(_town_draw_tile_data) == (NEW_HOUSE_OFFSET) * 4 * 4);
|
|||
{ca1, ca2, ca3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \
|
||||
{INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO}, \
|
||||
bf, ba, true, GRFFileProps(INVALID_HOUSE_ID), HouseCallbackMasks{}, {COLOUR_BEGIN, COLOUR_BEGIN, COLOUR_BEGIN, COLOUR_BEGIN}, \
|
||||
16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, {0, 2, 0, 0}, 0, 0, 0, {cg1, cg2, cg3}, }
|
||||
16, HouseExtraFlags{}, HOUSE_NO_CLASS, {0, 2, 0, 0}, 0, 0, 0, {cg1, cg2, cg3}, }
|
||||
/** House specifications from original data */
|
||||
extern const HouseSpec _original_house_specs[] = {
|
||||
/**
|
||||
|
|
|
@ -2741,7 +2741,7 @@ static void BuildTownHouse(Town *t, TileIndex tile, const HouseSpec *hs, HouseID
|
|||
uint32_t construction_random = Random();
|
||||
|
||||
construction_stage = TOWN_HOUSE_COMPLETED;
|
||||
if (_generating_world && !HasFlag(hs->extra_flags, HouseExtraFlags::BUILDING_IS_HISTORICAL) && Chance16(1, 7)) construction_stage = GB(construction_random, 0, 2);
|
||||
if (_generating_world && !hs->extra_flags.Test(HouseExtraFlag::BuildingIsHistorical) && Chance16(1, 7)) construction_stage = GB(construction_random, 0, 2);
|
||||
|
||||
if (construction_stage == TOWN_HOUSE_COMPLETED) {
|
||||
ChangePopulation(t, hs->population);
|
||||
|
@ -2835,7 +2835,7 @@ static bool TryBuildTownHouse(Town *t, TileIndex tile)
|
|||
|
||||
const HouseSpec *hs = HouseSpec::Get(house);
|
||||
|
||||
if (!_generating_world && _game_mode != GM_EDITOR && (hs->extra_flags & BUILDING_IS_HISTORICAL) != 0) {
|
||||
if (!_generating_world && _game_mode != GM_EDITOR && hs->extra_flags.Test(HouseExtraFlag::BuildingIsHistorical)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue