aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map/State.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/map/State.cpp')
-rw-r--r--src/openvic-simulation/map/State.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp
index 31ea05f..2951c22 100644
--- a/src/openvic-simulation/map/State.cpp
+++ b/src/openvic-simulation/map/State.cpp
@@ -23,8 +23,10 @@ State::State(
provinces { std::move(new_provinces) },
colony_status { new_colony_status },
pop_type_distribution { &pop_type_keys },
+ pops_cache_by_type { &pop_type_keys },
industrial_power { 0 },
- max_supported_regiments { 0 } {}
+ max_supported_regiments { 0 }
+ {}
std::string State::get_identifier() const {
return StringUtils::append_string_views(
@@ -41,7 +43,11 @@ void State::update_gamestate() {
pop_type_distribution.clear();
max_supported_regiments = 0;
- for (ProvinceInstance const* province : provinces) {
+ for (PopType const& pop_type : *pops_cache_by_type.get_keys()) {
+ pops_cache_by_type[pop_type].clear();
+ }
+
+ for (ProvinceInstance const* const province : provinces) {
total_population += province->get_total_population();
// TODO - change casting if Pop::pop_size_t changes type
@@ -51,7 +57,16 @@ void State::update_gamestate() {
average_militancy += province->get_average_militancy() * province_population;
pop_type_distribution += province->get_pop_type_distribution();
-
+ IndexedMap<PopType, std::vector<Pop*>> const& province_pops_cache_by_type = province->get_pops_cache_by_type();
+ for (PopType const& pop_type : *province_pops_cache_by_type.get_keys()) {
+ std::vector<Pop*> const& province_pops_of_type = province_pops_cache_by_type[pop_type];
+ std::vector<Pop*>& state_pops_of_type = pops_cache_by_type[pop_type];
+ state_pops_of_type.insert(
+ state_pops_of_type.end(),
+ province_pops_of_type.begin(),
+ province_pops_of_type.end()
+ );
+ }
max_supported_regiments += province->get_max_supported_regiments();
}
@@ -81,6 +96,10 @@ void State::update_gamestate() {
industrial_power = total_factory_levels_in_state * workforce_scalar;
}
+IndexedMap<PopType, std::vector<Pop*>>& State::get_mutable_pops_cache_by_type() {
+ return pops_cache_by_type;
+}
+
/* Whether two provinces in the same region should be grouped into the same state or not.
* (Assumes both provinces non-null.) */
static bool provinces_belong_in_same_state(ProvinceInstance const* lhs, ProvinceInstance const* rhs) {
@@ -198,4 +217,4 @@ void StateManager::update_gamestate() {
for (StateSet& state_set : state_sets) {
state_set.update_gamestate();
}
-}
+} \ No newline at end of file