Save this month values for town layout counters instead of prev totals
This commit is contained in:
@@ -22,7 +22,7 @@ namespace event {
|
|||||||
|
|
||||||
struct NewMonth {};
|
struct NewMonth {};
|
||||||
|
|
||||||
struct TownBiilt {
|
struct TownBuilt {
|
||||||
Town *town;
|
Town *town;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,9 @@ namespace citymania {
|
|||||||
Game::Game() {
|
Game::Game() {
|
||||||
this->events.listen<event::NewMonth>(event::Slot::GAME, [this] (const event::NewMonth &) {
|
this->events.listen<event::NewMonth>(event::Slot::GAME, [this] (const event::NewMonth &) {
|
||||||
for (Town *t : Town::Iterate()) {
|
for (Town *t : Town::Iterate()) {
|
||||||
t->cm.hs_last_month = t->cm.hs_total - t->cm.hs_total_prev;
|
t->cm.hs_last_month = t->cm.hs_this_month;
|
||||||
t->cm.hs_total_prev = t->cm.hs_total;
|
t->cm.cs_last_month = t->cm.cs_this_month;
|
||||||
t->cm.cs_last_month = t->cm.cs_total - t->cm.cs_total_prev;
|
t->cm.hr_last_month = t->cm.hr_this_month;
|
||||||
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_last_month = t->cm.houses_reconstructed_this_month;
|
||||||
t->cm.houses_reconstructed_this_month = 0;
|
t->cm.houses_reconstructed_this_month = 0;
|
||||||
@@ -28,20 +25,23 @@ Game::Game() {
|
|||||||
this->towns_growth_tiles.clear();
|
this->towns_growth_tiles.clear();
|
||||||
});
|
});
|
||||||
this->events.listen<event::TownBuilt>(event::Slot::GAME, [this] (const event::TownBuilt &event) {
|
this->events.listen<event::TownBuilt>(event::Slot::GAME, [this] (const event::TownBuilt &event) {
|
||||||
t->cm.hs_total = t->cm.hs_last_month = t->cm.hs_total_prev = 0;
|
auto t = event.town;
|
||||||
t->cm.cs_total = t->cm.cs_last_month = t->cm.cs_total_prev = 0;
|
t->cm.hs_total = t->cm.hs_last_month = t->cm.hs_this_month = 0;
|
||||||
t->cm.hr_total = t->cm.hr_last_month = t->cm.hr_total_prev = 0;
|
t->cm.cs_total = t->cm.cs_last_month = t->cm.cs_this_month = 0;
|
||||||
|
t->cm.hr_total = t->cm.hr_last_month = t->cm.hr_this_month = 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
this->events.listen<event::TownGrowthSucceeded>(event::Slot::GAME, [this] (const event::TownGrowthSucceeded &event) {
|
this->events.listen<event::TownGrowthSucceeded>(event::Slot::GAME, [this] (const event::TownGrowthSucceeded &event) {
|
||||||
if (event.town->cache.num_houses <= event.prev_houses) {
|
if (event.town->cache.num_houses <= event.prev_houses) {
|
||||||
event.town->cm.hs_total++;
|
event.town->cm.hs_total++;
|
||||||
|
event.town->cm.hs_this_month++;
|
||||||
this->set_town_growth_tile(event.tile, TownGrowthTileState::HS);
|
this->set_town_growth_tile(event.tile, TownGrowthTileState::HS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this->events.listen<event::TownGrowthFailed>(event::Slot::GAME, [this] (const event::TownGrowthFailed &event) {
|
this->events.listen<event::TownGrowthFailed>(event::Slot::GAME, [this] (const event::TownGrowthFailed &event) {
|
||||||
event.town->cm.cs_total++;
|
event.town->cm.cs_total++;
|
||||||
|
event.town->cm.cs_this_month++;
|
||||||
this->set_town_growth_tile(event.tile, TownGrowthTileState::CS);
|
this->set_town_growth_tile(event.tile, TownGrowthTileState::CS);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ static void EncodeTowns(BitOStream &bs)
|
|||||||
bs.WriteBytes(t->cm.houses_demolished_this_month, 2);
|
bs.WriteBytes(t->cm.houses_demolished_this_month, 2);
|
||||||
bs.WriteBytes(t->cm.houses_demolished_last_month, 2);
|
bs.WriteBytes(t->cm.houses_demolished_last_month, 2);
|
||||||
bs.WriteBytes(t->cm.hs_total, 4);
|
bs.WriteBytes(t->cm.hs_total, 4);
|
||||||
bs.WriteBytes(t->cm.hs_total_prev, 2);
|
bs.WriteBytes(t->cm.hs_this_month, 2);
|
||||||
bs.WriteBytes(t->cm.hs_last_month, 2);
|
bs.WriteBytes(t->cm.hs_last_month, 2);
|
||||||
bs.WriteBytes(t->cm.cs_total, 4);
|
bs.WriteBytes(t->cm.cs_total, 4);
|
||||||
bs.WriteBytes(t->cm.cs_total_prev, 2);
|
bs.WriteBytes(t->cm.cs_this_month, 2);
|
||||||
bs.WriteBytes(t->cm.cs_last_month, 2);
|
bs.WriteBytes(t->cm.cs_last_month, 2);
|
||||||
bs.WriteBytes(t->cm.hr_total, 4);
|
bs.WriteBytes(t->cm.hr_total, 4);
|
||||||
bs.WriteBytes(t->cm.hr_total_prev, 2);
|
bs.WriteBytes(t->cm.hr_this_month, 2);
|
||||||
bs.WriteBytes(t->cm.hr_last_month, 2);
|
bs.WriteBytes(t->cm.hr_last_month, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,13 +56,13 @@ static void DecodeTowns(BitIStream &bs)
|
|||||||
t->cm.houses_demolished_this_month = bs.ReadBytes(2);
|
t->cm.houses_demolished_this_month = bs.ReadBytes(2);
|
||||||
t->cm.houses_demolished_last_month = bs.ReadBytes(2);
|
t->cm.houses_demolished_last_month = bs.ReadBytes(2);
|
||||||
t->cm.hs_total = bs.ReadBytes(2);
|
t->cm.hs_total = bs.ReadBytes(2);
|
||||||
t->cm.hs_total_prev = bs.ReadBytes(2);
|
t->cm.hs_this_month = bs.ReadBytes(2);
|
||||||
t->cm.hs_last_month = bs.ReadBytes(2);
|
t->cm.hs_last_month = bs.ReadBytes(2);
|
||||||
t->cm.cs_total = bs.ReadBytes(2);
|
t->cm.cs_total = bs.ReadBytes(2);
|
||||||
t->cm.cs_total_prev = bs.ReadBytes(2);
|
t->cm.cs_this_month = bs.ReadBytes(2);
|
||||||
t->cm.cs_last_month = bs.ReadBytes(2);
|
t->cm.cs_last_month = bs.ReadBytes(2);
|
||||||
t->cm.hr_total = bs.ReadBytes(2);
|
t->cm.hr_total = bs.ReadBytes(2);
|
||||||
t->cm.hr_total_prev = bs.ReadBytes(2);
|
t->cm.hr_this_month = bs.ReadBytes(2);
|
||||||
t->cm.hr_last_month = bs.ReadBytes(2);
|
t->cm.hr_last_month = bs.ReadBytes(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -352,13 +352,13 @@ static void DecodeDataV1(BitIStream &bs) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
t->cm.hs_total = bs.ReadBytes(4);
|
t->cm.hs_total = bs.ReadBytes(4);
|
||||||
t->cm.hs_total_prev = bs.ReadBytes(2);
|
t->cm.hs_this_month = t->cm.hs_total - bs.ReadBytes(2);
|
||||||
t->cm.hs_last_month = bs.ReadBytes(2);
|
t->cm.hs_last_month = bs.ReadBytes(2);
|
||||||
t->cm.cs_total = bs.ReadBytes(4);
|
t->cm.cs_total = bs.ReadBytes(4);
|
||||||
t->cm.cs_total_prev = bs.ReadBytes(2);
|
t->cm.cs_this_month = t->cm.cs_total - bs.ReadBytes(2);
|
||||||
t->cm.cs_last_month = bs.ReadBytes(2);
|
t->cm.cs_last_month = bs.ReadBytes(2);
|
||||||
t->cm.hr_total = bs.ReadBytes(4);
|
t->cm.hr_total = bs.ReadBytes(4);
|
||||||
t->cm.hr_total_prev = bs.ReadBytes(2);
|
t->cm.hr_this_month = t->cm.hr_total -bs.ReadBytes(2);
|
||||||
t->cm.hr_last_month = bs.ReadBytes(2);
|
t->cm.hr_last_month = bs.ReadBytes(2);
|
||||||
}
|
}
|
||||||
DecodeTownsGrowthTiles(bs, _game->towns_growth_tiles);
|
DecodeTownsGrowthTiles(bs, _game->towns_growth_tiles);
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ public:
|
|||||||
bool growing_by_chance = false; ///< whether town is growing due to 1/12 chance
|
bool growing_by_chance = false; ///< whether town is growing due to 1/12 chance
|
||||||
uint32 real_population = 0; ///< population including unfinished houses
|
uint32 real_population = 0; ///< population including unfinished houses
|
||||||
uint32 hs_total = 0; ///< number of skipped house buildings (HS) in total
|
uint32 hs_total = 0; ///< number of skipped house buildings (HS) in total
|
||||||
uint16 hs_total_prev = 0; ///< number of skipped house buildings (HS) in total at the end of last month
|
uint16 hs_this_month = 0; ///< number of skipped house buildings (HS) during the current month
|
||||||
uint16 hs_last_month = 0; ///< number of skipped house buildings (HS) during last month
|
uint16 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 = 0; ///< number of skipped growth cycles (CS) in total
|
||||||
uint16 cs_total_prev = 0; ///< number of skipped growth cycles (CS) in total at the end of last month
|
uint16 cs_this_month = 0; ///< number of skipped growth cycles (CS) during the current month
|
||||||
uint16 cs_last_month = 0; ///< number of skipped growth cycles (CS) during last month
|
uint16 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 = 0; ///< number of houses removed by the server (HR) in total
|
||||||
uint16 hr_total_prev = 0; ///< number of houses removed by the server (HR) in total at the end of last month
|
uint16 hr_this_month = 0; ///< number of houses removed by the server (HR) during the current month
|
||||||
uint16 hr_last_month = 0; ///< number of houses removed by the server (HR) during last month
|
uint16 hr_last_month = 0; ///< number of houses removed by the server (HR) during last month
|
||||||
uint16 houses_constructing = 0; ///< number of houses currently being built
|
uint16 houses_constructing = 0; ///< number of houses currently being built
|
||||||
uint16 houses_reconstructed_this_month = 0; ///< number of houses rebuilt this month
|
uint16 houses_reconstructed_this_month = 0; ///< number of houses rebuilt this month
|
||||||
|
|||||||
Reference in New Issue
Block a user