diff --git a/cm_changelog.txt b/cm_changelog.txt index 1983cd54cc..d22652a322 100644 --- a/cm_changelog.txt +++ b/cm_changelog.txt @@ -92,6 +92,7 @@ This is usable for any OpenTTD servers - Shaded trees. - Add APM counter to the status bar. - Added cmtreemap console command to plant trees according to a heightmap image (scenario editor only). +- Fix town HR couter. *** 1.10.2 (5 Jun 2020) *** - Add new minimap mode showing industries, height and farms at the same time. diff --git a/src/citymania/cm_event.hpp b/src/citymania/cm_event.hpp index 54d66b9c4b..17536c3e30 100644 --- a/src/citymania/cm_event.hpp +++ b/src/citymania/cm_event.hpp @@ -57,6 +57,12 @@ struct HouseCleared { bool was_completed; ///< whether house was completed before destruction }; +struct HouseDestroyed { // by dynamite, called after HouseCleared + CompanyID company_id; + Town *town; + TileIndex tile; +}; + struct HouseCompleted { Town *town; TileIndex tile; diff --git a/src/citymania/cm_game.cpp b/src/citymania/cm_game.cpp index c4e035daef..9120047191 100644 --- a/src/citymania/cm_game.cpp +++ b/src/citymania/cm_game.cpp @@ -62,6 +62,14 @@ Game::Game() { event.town->cm.real_population -= event.house_spec->population; }); + this->events.listen(event::Slot::GAME, [this] (const event::HouseDestroyed &event) { + const Company *company = Company::GetIfValid(event.company_id); + if (company && company->cm.is_server) { + this->set_town_growth_tile(event.tile, TownGrowthTileState::HR); + event.town->cm.hr_total++; + } + }); + this->events.listen(event::Slot::GAME, [this] (const event::HouseCompleted &event) { event.town->cm.houses_constructing--; }); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index f480c349c2..ec59510df9 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -65,8 +65,6 @@ uint CBDECAY[NUM_CARGO] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, uint days_in_month[] = {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};//CB void CB_UpdateTownStorage(Town *t); //CB -const Money NOVAPOLIS_COMPANY_MONEY_THRESHOLD = INT64_MAX >> 4; - TownID _new_town_id; CargoTypes _town_cargoes_accepted; ///< Bitmap of all cargoes accepted by houses. @@ -702,12 +700,8 @@ static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags) ChangeTownRating(t, -rating, RATING_HOUSE_MINIMUM, flags); if (flags & DC_EXEC) { - // if (_current_company == COMPANY_FIRST && - // Company::Get(_current_company)->money > NOVAPOLIS_COMPANY_MONEY_THRESHOLD) { - // if (t->cb.growth_state == TownGrowthState::GROWING) t->cm.hr_total++; - // UpdateTownGrowthTile(tile, t->cb.growth_state == TownGrowthState::GROWING ? TGTS_CB_HOUSE_REMOVED: TGTS_CB_HOUSE_REMOVED_NOGROW); - // } ClearTownHouse(t, tile); + citymania::Emit(citymania::event::HouseDestroyed{_current_company, t, tile}); } return cost;