Codechange: Use EnumBitSet for TownFlags. (#14651)
This commit is contained in:
+17
-17
@@ -666,7 +666,7 @@ static void TileLoop_Town(TileIndex tile)
|
||||
Backup<CompanyID> cur_company(_current_company, OWNER_TOWN);
|
||||
|
||||
if (hs->building_flags.Any(BUILDING_HAS_1_TILE) &&
|
||||
HasBit(t->flags, TOWN_IS_GROWING) &&
|
||||
t->flags.Test(TownFlag::IsGrowing) &&
|
||||
CanDeleteHouse(tile) &&
|
||||
GetHouseAge(tile) >= hs->minimum_life &&
|
||||
--t->time_until_rebuild == 0) {
|
||||
@@ -917,7 +917,7 @@ static bool GrowTown(Town *t, TownExpandModes modes);
|
||||
*/
|
||||
static void TownTickHandler(Town *t)
|
||||
{
|
||||
if (HasBit(t->flags, TOWN_IS_GROWING)) {
|
||||
if (t->flags.Test(TownFlag::IsGrowing)) {
|
||||
TownExpandModes modes{TownExpandMode::Buildings};
|
||||
if (_settings_game.economy.allow_town_roads) modes.Set(TownExpandMode::Roads);
|
||||
int i = (int)t->grow_counter - 1;
|
||||
@@ -2046,7 +2046,7 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi
|
||||
t->cache.num_houses = 0;
|
||||
t->time_until_rebuild = 10;
|
||||
UpdateTownRadius(t);
|
||||
t->flags = 0;
|
||||
t->flags.Reset();
|
||||
t->cache.population = 0;
|
||||
InitializeBuildingCounts(t);
|
||||
/* Spread growth across ticks so even if there are many
|
||||
@@ -2867,15 +2867,15 @@ static bool TryBuildTownHouse(Town *t, TileIndex tile, TownExpandModes modes)
|
||||
if (TimerGameCalendar::year < hs->min_year || TimerGameCalendar::year > hs->max_year) continue;
|
||||
|
||||
/* Special houses that there can be only one of. */
|
||||
uint oneof = 0;
|
||||
TownFlags oneof{};
|
||||
|
||||
if (hs->building_flags.Test(BuildingFlag::IsChurch)) {
|
||||
SetBit(oneof, TOWN_HAS_CHURCH);
|
||||
oneof.Set(TownFlag::HasChurch);
|
||||
} else if (hs->building_flags.Test(BuildingFlag::IsStadium)) {
|
||||
SetBit(oneof, TOWN_HAS_STADIUM);
|
||||
oneof.Set(TownFlag::HasStadium);
|
||||
}
|
||||
|
||||
if (t->flags & oneof) continue;
|
||||
if (t->flags.Any(oneof)) continue;
|
||||
|
||||
/* Make sure there is no slope? */
|
||||
bool noslope = hs->building_flags.Test(BuildingFlag::NotSloped);
|
||||
@@ -2899,7 +2899,7 @@ static bool TryBuildTownHouse(Town *t, TileIndex tile, TownExpandModes modes)
|
||||
}
|
||||
|
||||
/* Special houses that there can be only one of. */
|
||||
t->flags |= oneof;
|
||||
t->flags.Set(oneof);
|
||||
|
||||
BuildTownHouse(t, tile, hs, house, random_bits, false, hs->extra_flags.Test(HouseExtraFlag::BuildingIsProtected));
|
||||
|
||||
@@ -3034,9 +3034,9 @@ void ClearTownHouse(Town *t, TileIndex tile)
|
||||
|
||||
/* Clear flags for houses that only may exist once/town. */
|
||||
if (hs->building_flags.Test(BuildingFlag::IsChurch)) {
|
||||
ClrBit(t->flags, TOWN_HAS_CHURCH);
|
||||
t->flags.Reset(TownFlag::HasChurch);
|
||||
} else if (hs->building_flags.Test(BuildingFlag::IsStadium)) {
|
||||
ClrBit(t->flags, TOWN_HAS_STADIUM);
|
||||
t->flags.Reset(TownFlag::HasStadium);
|
||||
}
|
||||
|
||||
/* Do the actual clearing of tiles */
|
||||
@@ -3168,7 +3168,7 @@ CommandCost CmdTownGrowthRate(DoCommandFlags flags, TownID town_id, uint16_t gro
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
if (growth_rate == 0) {
|
||||
/* Just clear the flag, UpdateTownGrowth will determine a proper growth rate */
|
||||
ClrBit(t->flags, TOWN_CUSTOM_GROWTH);
|
||||
t->flags.Reset(TownFlag::CustomGrowth);
|
||||
} else {
|
||||
uint old_rate = t->growth_rate;
|
||||
if (t->grow_counter >= old_rate) {
|
||||
@@ -3179,7 +3179,7 @@ CommandCost CmdTownGrowthRate(DoCommandFlags flags, TownID town_id, uint16_t gro
|
||||
t->grow_counter = t->grow_counter * growth_rate / old_rate;
|
||||
}
|
||||
t->growth_rate = growth_rate;
|
||||
SetBit(t->flags, TOWN_CUSTOM_GROWTH);
|
||||
t->flags.Set(TownFlag::CustomGrowth);
|
||||
}
|
||||
UpdateTownGrowth(t);
|
||||
InvalidateWindowData(WC_TOWN_VIEW, town_id);
|
||||
@@ -3829,7 +3829,7 @@ static uint GetNormalGrowthRate(Town *t)
|
||||
*/
|
||||
static void UpdateTownGrowthRate(Town *t)
|
||||
{
|
||||
if (HasBit(t->flags, TOWN_CUSTOM_GROWTH)) return;
|
||||
if (t->flags.Test(TownFlag::CustomGrowth)) return;
|
||||
uint old_rate = t->growth_rate;
|
||||
t->growth_rate = GetNormalGrowthRate(t);
|
||||
UpdateTownGrowCounter(t, old_rate);
|
||||
@@ -3844,7 +3844,7 @@ static void UpdateTownGrowth(Town *t)
|
||||
{
|
||||
UpdateTownGrowthRate(t);
|
||||
|
||||
ClrBit(t->flags, TOWN_IS_GROWING);
|
||||
t->flags.Reset(TownFlag::IsGrowing);
|
||||
SetWindowDirty(WC_TOWN_VIEW, t->index);
|
||||
|
||||
if (_settings_game.economy.town_growth_rate == 0 && t->fund_buildings_months == 0) return;
|
||||
@@ -3866,15 +3866,15 @@ static void UpdateTownGrowth(Town *t)
|
||||
}
|
||||
}
|
||||
|
||||
if (HasBit(t->flags, TOWN_CUSTOM_GROWTH)) {
|
||||
if (t->growth_rate != TOWN_GROWTH_RATE_NONE) SetBit(t->flags, TOWN_IS_GROWING);
|
||||
if (t->flags.Test(TownFlag::CustomGrowth)) {
|
||||
if (t->growth_rate != TOWN_GROWTH_RATE_NONE) t->flags.Set(TownFlag::IsGrowing);
|
||||
SetWindowDirty(WC_TOWN_VIEW, t->index);
|
||||
return;
|
||||
}
|
||||
|
||||
if (t->fund_buildings_months == 0 && CountActiveStations(t) == 0 && !Chance16(1, 12)) return;
|
||||
|
||||
SetBit(t->flags, TOWN_IS_GROWING);
|
||||
t->flags.Set(TownFlag::IsGrowing);
|
||||
SetWindowDirty(WC_TOWN_VIEW, t->index);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user