Add reconstructed and demolished house counters
This commit is contained in:
@@ -26,6 +26,24 @@ struct TownGrowthTick {
|
||||
uint16 prev_houses;
|
||||
};
|
||||
|
||||
struct HouseRebuilt {
|
||||
Town *town;
|
||||
TileIndex tile;
|
||||
bool was_successful;
|
||||
};
|
||||
|
||||
struct HouseBuilt {
|
||||
Town *town;
|
||||
TileIndex tile;
|
||||
const HouseSpec *house_spec;
|
||||
};
|
||||
|
||||
struct HouseCompleted {
|
||||
Town *town;
|
||||
TileIndex tile;
|
||||
const HouseSpec *house_spec;
|
||||
};
|
||||
|
||||
struct CompanyEvent {
|
||||
Company *company;
|
||||
};
|
||||
|
||||
@@ -15,6 +15,11 @@ Game::Game() {
|
||||
t->cm.cs_total_prev = t->cm.cs_total;
|
||||
t->cm.hr_last_month = t->cm.hr_total - t->cm.hr_total_prev;
|
||||
t->cm.hr_total_prev = t->cm.hr_total;
|
||||
|
||||
t->cm.houses_reconstructed_last_month = t->cm.houses_reconstructed_this_month;
|
||||
t->cm.houses_reconstructed_this_month = 0;
|
||||
t->cm.houses_demolished_last_month = t->cm.houses_demolished_this_month;
|
||||
t->cm.houses_demolished_this_month = 0;
|
||||
}
|
||||
});
|
||||
this->events.listen<event::TownGrowthTick>([this] (const event::TownGrowthTick &event) {
|
||||
@@ -26,6 +31,19 @@ Game::Game() {
|
||||
event.town->cm.cs_total++;
|
||||
}
|
||||
});
|
||||
this->events.listen<event::HouseRebuilt>([this] (const event::HouseRebuilt &event) {
|
||||
if (event.was_successful) {
|
||||
event.town->cm.houses_reconstructed_this_month++;
|
||||
} else {
|
||||
event.town->cm.houses_demolished_this_month++;
|
||||
}
|
||||
});
|
||||
this->events.listen<event::HouseBuilt>([this] (const event::HouseBuilt &event) {
|
||||
event.town->cm.houses_constructing++;
|
||||
});
|
||||
this->events.listen<event::HouseCompleted>([this] (const event::HouseCompleted &event) {
|
||||
event.town->cm.houses_constructing--;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace citymania
|
||||
@@ -7,15 +7,21 @@ namespace ext {
|
||||
|
||||
class Town {
|
||||
public:
|
||||
uint32 hs_total = 0; ///< number of skipped house buildings (HS) in total
|
||||
uint32 hs_total_prev = 0; ///< number of skipped house buildings (HS) in total at the end of last month
|
||||
uint32 hs_last_month = 0; ///< number of skipped house buildings (HS) during last month
|
||||
uint32 cs_total = 0; ///< number of skipped growth cycles (CS) in total
|
||||
uint32 cs_total_prev = 0; ///< number of skipped growth cycles (CS) in total at the end of last month
|
||||
uint32 cs_last_month = 0; ///< number of skipped growth cycles (CS) during last month
|
||||
uint32 hr_total = 0; ///< number of houses removed by the server (HR) in total
|
||||
uint32 hr_total_prev = 0; ///< number of houses removed by the server (HR) in total at the end of last month
|
||||
uint32 hr_last_month = 0; ///< number of houses removed by the server (HR) during last month
|
||||
bool growing_by_chance = false; ///< whether town is growing due to 1/12 chance
|
||||
uint32 hs_total = 0; ///< number of skipped house buildings (HS) in total
|
||||
uint32 hs_total_prev = 0; ///< number of skipped house buildings (HS) in total at the end of last month
|
||||
uint32 hs_last_month = 0; ///< number of skipped house buildings (HS) during last month
|
||||
uint32 cs_total = 0; ///< number of skipped growth cycles (CS) in total
|
||||
uint32 cs_total_prev = 0; ///< number of skipped growth cycles (CS) in total at the end of last month
|
||||
uint32 cs_last_month = 0; ///< number of skipped growth cycles (CS) during last month
|
||||
uint32 hr_total = 0; ///< number of houses removed by the server (HR) in total
|
||||
uint32 hr_total_prev = 0; ///< number of houses removed by the server (HR) in total at the end of last month
|
||||
uint32 hr_last_month = 0; ///< number of houses removed by the server (HR) during last month
|
||||
uint32 houses_constructing = 0; ///< number of houses currently being built
|
||||
uint32 houses_reconstructed_this_month = 0; ///< number of houses rebuilt this month
|
||||
uint32 houses_reconstructed_last_month = 0; ///< number of houses rebuild last month
|
||||
uint32 houses_demolished_this_month = 0; ///< number of houses demolished this month
|
||||
uint32 houses_demolished_last_month = 0; ///< number of houses demolished last month
|
||||
};
|
||||
|
||||
} // namespace citymania
|
||||
|
||||
@@ -496,8 +496,14 @@ static void MakeSingleHouseBigger(TileIndex tile)
|
||||
if (IsHouseCompleted(tile)) {
|
||||
/* Now that construction is complete, we can add the population of the
|
||||
* building to the town. */
|
||||
ChangePopulation(Town::GetByTile(tile), HouseSpec::Get(GetHouseType(tile))->population);
|
||||
HouseID house_id = GetHouseType(tile);
|
||||
auto hs = HouseSpec::Get(house_id);
|
||||
Town *town = Town::GetByTile(tile);
|
||||
ChangePopulation(Town::GetByTile(tile), hs->population);
|
||||
ResetHouseAge(tile);
|
||||
|
||||
if (hs->building_flags & BUILDING_HAS_1_TILE)
|
||||
citymania::Emit(citymania::event::HouseCompleted{town, tile, hs});
|
||||
}
|
||||
MarkTileDirtyByTile(tile);
|
||||
}
|
||||
@@ -632,7 +638,9 @@ static void TileLoop_Town(TileIndex tile)
|
||||
ClearTownHouse(t, tile);
|
||||
|
||||
/* Rebuild with another house? */
|
||||
if (GB(r, 24, 8) >= 12) BuildTownHouse(t, tile);
|
||||
bool rebuild_res = false;
|
||||
if (GB(r, 24, 8) >= 12) rebuild_res = BuildTownHouse(t, tile);
|
||||
citymania::Emit(citymania::event::HouseRebuilt{t, tile, rebuild_res});
|
||||
}
|
||||
|
||||
cur_company.Restore();
|
||||
@@ -2582,6 +2590,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
||||
byte construction_counter = 0;
|
||||
byte construction_stage = 0;
|
||||
|
||||
bool completed = false;
|
||||
if (_generating_world || _game_mode == GM_EDITOR) {
|
||||
uint32 r = Random();
|
||||
|
||||
@@ -2590,6 +2599,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
||||
|
||||
if (construction_stage == TOWN_HOUSE_COMPLETED) {
|
||||
ChangePopulation(t, hs->population);
|
||||
completed = true;
|
||||
} else {
|
||||
construction_counter = GB(r, 2, 2);
|
||||
}
|
||||
@@ -2600,6 +2610,9 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
||||
UpdateTownGrowthRate(t);
|
||||
UpdateTownCargoes(t, tile);
|
||||
|
||||
citymania::Emit(citymania::event::HouseBuilt{t, tile, hs});
|
||||
if (completed) citymania::Emit(citymania::event::HouseCompleted{t, tile, hs});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3453,6 +3466,7 @@ static void UpdateTownGrowth(Town *t)
|
||||
|
||||
ClrBit(t->flags, TOWN_IS_GROWING);
|
||||
SetWindowDirty(WC_TOWN_VIEW, t->index);
|
||||
t->cm.growing_by_chance = false;
|
||||
|
||||
if (_settings_game.economy.town_growth_rate == 0 && t->fund_buildings_months == 0) return;
|
||||
|
||||
@@ -3479,7 +3493,10 @@ static void UpdateTownGrowth(Town *t)
|
||||
return;
|
||||
}
|
||||
|
||||
if (t->fund_buildings_months == 0 && CountActiveStations(t) == 0 && !Chance16(1, 12)) return;
|
||||
if (t->fund_buildings_months == 0 && CountActiveStations(t) == 0) {
|
||||
if(!Chance16(1, 12)) return;
|
||||
t->cm.growing_by_chance = true;
|
||||
}
|
||||
|
||||
SetBit(t->flags, TOWN_IS_GROWING);
|
||||
SetWindowDirty(WC_TOWN_VIEW, t->index);
|
||||
|
||||
Reference in New Issue
Block a user