diff options
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r-- | src/openvic-simulation/map/MapInstance.cpp | 33 | ||||
-rw-r--r-- | src/openvic-simulation/map/MapInstance.hpp | 10 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.cpp | 32 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.hpp | 9 | ||||
-rw-r--r-- | src/openvic-simulation/map/State.cpp | 45 | ||||
-rw-r--r-- | src/openvic-simulation/map/State.hpp | 5 |
6 files changed, 103 insertions, 31 deletions
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp index 4a4a1e5..80aad5e 100644 --- a/src/openvic-simulation/map/MapInstance.cpp +++ b/src/openvic-simulation/map/MapInstance.cpp @@ -81,7 +81,7 @@ bool MapInstance::setup( } bool MapInstance::apply_history_to_provinces( - ProvinceHistoryManager const& history_manager, Date date, CountryInstanceManager& country_manager, + ProvinceHistoryManager const& history_manager, const Date date, CountryInstanceManager& country_manager, IssueManager const& issue_manager ) { bool ret = true; @@ -128,41 +128,44 @@ bool MapInstance::apply_history_to_provinces( return ret; } -void MapInstance::update_modifier_sums(Date today, StaticModifierCache const& static_modifier_cache) { +void MapInstance::update_modifier_sums(const Date today, StaticModifierCache const& static_modifier_cache) { for (ProvinceInstance& province : province_instances.get_items()) { province.update_modifier_sum(today, static_modifier_cache); } } -void MapInstance::update_gamestate(Date today, DefineManager const& define_manager) { - for (ProvinceInstance& province : province_instances.get_items()) { - province.update_gamestate(today, define_manager); - } - state_manager.update_gamestate(); - - // Update population stats +void MapInstance::update_gamestate(const Date today, DefineManager const& define_manager) { highest_province_population = 0; total_map_population = 0; + + for (ProvinceInstance& province : province_instances.get_items()) { + province.update_gamestate(today, define_manager); - for (ProvinceInstance const& province : province_instances.get_items()) { + // Update population stats const Pop::pop_size_t province_population = province.get_total_population(); - if (highest_province_population < province_population) { highest_province_population = province_population; } total_map_population += province_population; } + state_manager.update_gamestate(); } -void MapInstance::tick(Date today) { +void MapInstance::map_tick(const Date today, ModifierEffectCache const& modifier_effect_cache) { for (ProvinceInstance& province : province_instances.get_items()) { - province.tick(today); + province.province_tick(today, modifier_effect_cache); } } -void MapInstance::initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache){ +void MapInstance::initialise_for_new_game( + const Date today, + DefineManager const& define_manager, + ModifierEffectCache const& modifier_effect_cache +) { + update_gamestate(today, define_manager); for (ProvinceInstance& province : province_instances.get_items()) { - province.initialise_for_new_game(modifier_effect_cache); + province.initialise_rgo(modifier_effect_cache); } + state_manager.tick(today, modifier_effect_cache); }
\ No newline at end of file diff --git a/src/openvic-simulation/map/MapInstance.hpp b/src/openvic-simulation/map/MapInstance.hpp index a580c55..1ca28d2 100644 --- a/src/openvic-simulation/map/MapInstance.hpp +++ b/src/openvic-simulation/map/MapInstance.hpp @@ -48,13 +48,13 @@ namespace OpenVic { decltype(ProvinceInstance::ideology_distribution)::keys_t const& ideology_keys ); bool apply_history_to_provinces( - ProvinceHistoryManager const& history_manager, Date date, CountryInstanceManager& country_manager, + ProvinceHistoryManager const& history_manager, const Date date, CountryInstanceManager& country_manager, IssueManager const& issue_manager ); - void update_modifier_sums(Date today, StaticModifierCache const& static_modifier_cache); - void update_gamestate(Date today, DefineManager const& define_manager); - void tick(Date today); - void initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache); + void update_modifier_sums(const Date today, StaticModifierCache const& static_modifier_cache); + void update_gamestate(const Date today, DefineManager const& define_manager); + void map_tick(const Date today, ModifierEffectCache const& modifier_effect_cache); + void initialise_for_new_game(const Date today, DefineManager const& define_manager, ModifierEffectCache const& modifier_effect_cache); }; } diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index b3d2df3..5a3dda2 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -40,10 +40,15 @@ ProvinceInstance::ProvinceInstance( pops {}, total_population { 0 }, pop_type_distribution { &pop_type_keys }, + pops_cache_by_type { &pop_type_keys }, ideology_distribution { &ideology_keys }, culture_distribution {}, religion_distribution {}, - max_supported_regiments { 0 } {} + max_supported_regiments { 0 } { + for (PopType const& pop_type : pop_type_keys) { + pops_cache_by_type[pop_type] = {}; + } + } GoodDefinition const* ProvinceInstance::get_rgo_good() const { if (!rgo.is_valid()) { return nullptr; } @@ -182,6 +187,10 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) { culture_distribution.clear(); religion_distribution.clear(); + for (PopType const& pop_type : *pops_cache_by_type.get_keys()) { + pops_cache_by_type[pop_type].clear(); + } + max_supported_regiments = 0; MilitaryDefines const& military_defines = define_manager.get_military_defines(); @@ -202,6 +211,7 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) { average_militancy += pop.get_militancy(); pop_type_distribution[*pop.get_type()] += pop.get_size(); + pops_cache_by_type[*pop.get_type()].push_back(&pop); ideology_distribution += pop.get_ideologies(); culture_distribution[&pop.get_culture()] += pop.get_size(); religion_distribution[&pop.get_religion()] += pop.get_size(); @@ -354,17 +364,21 @@ bool ProvinceInstance::convert_rgo_worker_pops_to_equivalent(ProductionType cons return is_valid_operation; } -void ProvinceInstance::update_gamestate(Date today, DefineManager const& define_manager) { +void ProvinceInstance::update_gamestate(const Date today, DefineManager const& define_manager) { for (BuildingInstance& building : buildings.get_items()) { building.update_gamestate(today); } _update_pops(define_manager); } -void ProvinceInstance::tick(Date today) { +void ProvinceInstance::province_tick(const Date today, ModifierEffectCache const& modifier_effect_cache) { for (BuildingInstance& building : buildings.get_items()) { building.tick(today); } + rgo.rgo_tick( + *this, + modifier_effect_cache + ); } template<UnitType::branch_t Branch> @@ -468,8 +482,8 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent return ret; } -void ProvinceInstance::initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache) { - rgo.initialise_for_new_game(*this, modifier_effect_cache); +void ProvinceInstance::initialise_rgo(ModifierEffectCache const& modifier_effect_cache) { + rgo.initialise_rgo_size_multiplier(*this, modifier_effect_cache); } void ProvinceInstance::setup_pop_test_values(IssueManager const& issue_manager) { @@ -478,6 +492,14 @@ void ProvinceInstance::setup_pop_test_values(IssueManager const& issue_manager) } } +State* ProvinceInstance::get_mutable_state() { + return state; +} + plf::colony<Pop>& ProvinceInstance::get_mutable_pops() { return pops; +} + +IndexedMap<PopType, std::vector<Pop*>>& ProvinceInstance::get_mutable_pops_cache_by_type() { + return pops_cache_by_type; }
\ No newline at end of file diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp index ba800a9..ec83af4 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -96,6 +96,7 @@ namespace OpenVic { fixed_point_t PROPERTY(average_consciousness); fixed_point_t PROPERTY(average_militancy); IndexedMap<PopType, Pop::pop_size_t> PROPERTY(pop_type_distribution); + IndexedMap<PopType, std::vector<Pop*>> PROPERTY(pops_cache_by_type); IndexedMap<Ideology, fixed_point_t> PROPERTY(ideology_distribution); fixed_point_map_t<Culture const*> PROPERTY(culture_distribution); fixed_point_map_t<Religion const*> PROPERTY(religion_distribution); @@ -148,8 +149,8 @@ namespace OpenVic { ) const; std::vector<ModifierSum::modifier_entry_t> get_contributing_modifiers(ModifierEffect const& effect) const; - void update_gamestate(Date today, DefineManager const& define_manager); - void tick(Date today); + void update_gamestate(const Date today, DefineManager const& define_manager); + void province_tick(const Date today, ModifierEffectCache const& modifier_effect_cache); template<UnitType::branch_t Branch> bool add_unit_instance_group(UnitInstanceGroup<Branch>& group); @@ -159,9 +160,11 @@ namespace OpenVic { bool setup(BuildingTypeManager const& building_type_manager); bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager); - void initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache); + void initialise_rgo(ModifierEffectCache const& modifier_effect_cache); void setup_pop_test_values(IssueManager const& issue_manager); + State* get_mutable_state(); plf::colony<Pop>& get_mutable_pops(); + IndexedMap<PopType, std::vector<Pop*>>& get_mutable_pops_cache_by_type(); }; } 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 diff --git a/src/openvic-simulation/map/State.hpp b/src/openvic-simulation/map/State.hpp index a39eea6..e1f5953 100644 --- a/src/openvic-simulation/map/State.hpp +++ b/src/openvic-simulation/map/State.hpp @@ -30,6 +30,7 @@ namespace OpenVic { fixed_point_t PROPERTY(average_consciousness); fixed_point_t PROPERTY(average_militancy); IndexedMap<PopType, Pop::pop_size_t> PROPERTY(pop_type_distribution); + IndexedMap<PopType, std::vector<Pop*>> PROPERTY(pops_cache_by_type); fixed_point_t PROPERTY(industrial_power); @@ -48,6 +49,8 @@ namespace OpenVic { std::string get_identifier() const; void update_gamestate(); + void state_tick(const Date today, ModifierEffectCache const& modifier_effect_cache); + IndexedMap<PopType, std::vector<Pop*>>& get_mutable_pops_cache_by_type(); }; struct Region; @@ -67,6 +70,7 @@ namespace OpenVic { size_t get_state_count() const; void update_gamestate(); + void tick(const Date today, ModifierEffectCache const& modifier_effect_cache); }; struct MapInstance; @@ -90,5 +94,6 @@ namespace OpenVic { void reset(); void update_gamestate(); + void tick(const Date today, ModifierEffectCache const& modifier_effect_cache); }; } |