diff options
Diffstat (limited to 'src/openvic-simulation/map/State.cpp')
-rw-r--r-- | src/openvic-simulation/map/State.cpp | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp index 31ea05f..a13c271 100644 --- a/src/openvic-simulation/map/State.cpp +++ b/src/openvic-simulation/map/State.cpp @@ -23,8 +23,13 @@ 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 } { + for (PopType const& pop_type : pop_type_keys) { + pops_cache_by_type[pop_type] = {}; + } + } std::string State::get_identifier() const { return StringUtils::append_string_views( @@ -41,7 +46,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 province : provinces) { total_population += province->get_total_population(); // TODO - change casting if Pop::pop_size_t changes type @@ -51,7 +60,15 @@ 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*>>& province_pops_cache_by_type = province->get_mutable_pops_cache_by_type(); + for (PopType const& pop_type : *province_pops_cache_by_type.get_keys()) { + std::vector<Pop*>& pops_of_type = province_pops_cache_by_type[pop_type]; + pops_cache_by_type[pop_type].insert( + pops_cache_by_type[pop_type].end(), + pops_of_type.begin(), + pops_of_type.end() + ); + } max_supported_regiments += province->get_max_supported_regiments(); } @@ -81,6 +98,16 @@ void State::update_gamestate() { industrial_power = total_factory_levels_in_state * workforce_scalar; } +void State::state_tick(const Date today, ModifierEffectCache const& modifier_effect_cache) { + for (ProvinceInstance* province : provinces) { + province->province_tick(today, modifier_effect_cache); + } +} + +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) { @@ -99,6 +126,12 @@ void StateSet::update_gamestate() { } } +void StateSet::tick(const Date today, ModifierEffectCache const& modifier_effect_cache) { + for (State& state : states) { + state.state_tick(today, modifier_effect_cache); + } +} + bool StateManager::add_state_set( MapInstance& map_instance, Region const& region, decltype(State::pop_type_distribution)::keys_t const& pop_type_keys ) { @@ -199,3 +232,9 @@ void StateManager::update_gamestate() { state_set.update_gamestate(); } } + +void StateManager::tick(const Date today, ModifierEffectCache const& modifier_effect_cache) { + for (StateSet& state_set : state_sets) { + state_set.tick(today, modifier_effect_cache); + } +}
\ No newline at end of file |