diff options
author | hop311 <hop3114@gmail.com> | 2024-07-21 15:09:25 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-07-22 20:21:27 +0200 |
commit | 67cbd14630c4344902d3fa1ddca178809da4293b (patch) | |
tree | 9df96829dd0f9a0bd7c2e6b0e047547aa4bff3a7 /src/openvic-simulation/map/State.cpp | |
parent | d1f3a96b72dd06b5f97dd4643e5f016a02b42ea6 (diff) |
Fleshing out Country, State and Province instances + historycountry-instance
Diffstat (limited to 'src/openvic-simulation/map/State.cpp')
-rw-r--r-- | src/openvic-simulation/map/State.cpp | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp index 42d84cc..68f2f43 100644 --- a/src/openvic-simulation/map/State.cpp +++ b/src/openvic-simulation/map/State.cpp @@ -1,23 +1,51 @@ #include "State.hpp" +#include "openvic-simulation/country/CountryInstance.hpp" #include "openvic-simulation/map/MapDefinition.hpp" #include "openvic-simulation/map/MapInstance.hpp" #include "openvic-simulation/map/ProvinceInstance.hpp" #include "openvic-simulation/map/Region.hpp" +#include "openvic-simulation/utility/StringUtils.hpp" using namespace OpenVic; State::State( - StateSet const& new_state_set, CountryDefinition const* owner, ProvinceInstance* capital, - std::vector<ProvinceInstance*>&& provinces, ProvinceInstance::colony_status_t colony_status + StateSet const& new_state_set, CountryInstance* owner, ProvinceInstance* capital, + std::vector<ProvinceInstance*>&& provinces, ProvinceInstance::colony_status_t colony_status, + decltype(pop_type_distribution)::keys_t const& pop_type_keys ) : state_set { new_state_set }, owner { owner }, capital { capital }, provinces { std::move(provinces) }, - colony_status { colony_status } {} + colony_status { colony_status }, pop_type_distribution { &pop_type_keys } {} + +std::string State::get_identifier() const { + return StringUtils::append_string_views( + state_set.get_region().get_identifier(), "_", owner->get_identifier(), "_", + ProvinceInstance::get_colony_status_string(colony_status) + ); +} void State::update_gamestate() { total_population = 0; + average_literacy = 0; + average_consciousness = 0; + average_militancy = 0; + pop_type_distribution.clear(); for (ProvinceInstance const* province : provinces) { total_population += province->get_total_population(); + + // TODO - change casting if Pop::pop_size_t changes type + const fixed_point_t province_population = fixed_point_t::parse(province->get_total_population()); + average_literacy += province->get_average_literacy() * province_population; + average_consciousness += province->get_average_consciousness() * province_population; + average_militancy += province->get_average_militancy() * province_population; + + pop_type_distribution += province->get_pop_type_distribution(); + } + + if (total_population > 0) { + average_literacy /= total_population; + average_consciousness /= total_population; + average_militancy /= total_population; } } @@ -39,7 +67,9 @@ void StateSet::update_gamestate() { } } -bool StateManager::add_state_set(MapInstance& map_instance, Region const& region) { +bool StateManager::add_state_set( + MapInstance& map_instance, Region const& region, decltype(State::pop_type_distribution)::keys_t const& pop_type_keys +) { if (region.get_meta()) { Logger::error("Cannot use meta region \"", region.get_identifier(), "\" as state template!"); return false; @@ -54,7 +84,7 @@ bool StateManager::add_state_set(MapInstance& map_instance, Region const& region for (ProvinceDefinition const* province : region.get_provinces()) { - ProvinceInstance* province_instance = map_instance.get_province_instance_from_const(province); + ProvinceInstance* province_instance = &map_instance.get_province_instance_from_definition(*province); // add to existing state if shared owner & status... for (std::vector<ProvinceInstance*>& provinces : temp_provinces) { @@ -83,22 +113,28 @@ bool StateManager::add_state_set(MapInstance& map_instance, Region const& region for (std::vector<ProvinceInstance*>& provinces : temp_provinces) { ProvinceInstance* capital = provinces.front(); - state_set.states.push_back( + CountryInstance* owner = capital->get_owner(); + + State& state = *state_set.states.insert( /* TODO: capital province logic */ - { state_set, capital->get_owner(), capital, std::move(provinces), capital->get_colony_status() } + { state_set, owner, capital, std::move(provinces), capital->get_colony_status(), pop_type_keys } ); - State const& state = state_set.states.back(); - for (ProvinceInstance* province : state.get_provinces()) { province->set_state(&state); } + + if (owner != nullptr) { + owner->add_state(state); + } } return true; } -bool StateManager::generate_states(MapInstance& map_instance) { +bool StateManager::generate_states( + MapInstance& map_instance, decltype(State::pop_type_distribution)::keys_t const& pop_type_keys +) { MapDefinition const& map_definition = map_instance.get_map_definition(); state_sets.clear(); @@ -109,7 +145,7 @@ bool StateManager::generate_states(MapInstance& map_instance) { for (Region const& region : map_definition.get_regions()) { if (!region.get_meta()) { - if (add_state_set(map_instance, region)) { + if (add_state_set(map_instance, region, pop_type_keys)) { state_count += state_sets.back().get_state_count(); } else { ret = false; |