diff options
author | wvpm <24685035+wvpm@users.noreply.github.com> | 2024-09-22 15:16:35 +0200 |
---|---|---|
committer | wvpm <24685035+wvpm@users.noreply.github.com> | 2024-09-22 15:16:35 +0200 |
commit | cf3bbdfddaf05f0439e9aeb6cce9d2bef5b47f53 (patch) | |
tree | be61fd166f76a4ec92fd0fb3e324fb188171509b | |
parent | d7f839a887ef6a19c935a59cad2697712d3b948a (diff) |
Convert pops to equivalents & calculate rgo size
-rw-r--r-- | src/openvic-simulation/map/MapInstance.cpp | 8 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.cpp | 67 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.hpp | 8 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.cpp | 14 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.hpp | 3 |
5 files changed, 84 insertions, 16 deletions
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp index 7c529bc..0b5286f 100644 --- a/src/openvic-simulation/map/MapInstance.cpp +++ b/src/openvic-simulation/map/MapInstance.cpp @@ -94,13 +94,15 @@ bool MapInstance::apply_history_to_provinces( if (history_map != nullptr) { ProvinceHistoryEntry const* pop_history_entry = nullptr; + ProductionType const* rgo_production_type = nullptr; for (auto const& [entry_date, entry] : history_map->get_entries()) { if (entry_date > date) { break; } - province.apply_history_to_province(*entry, country_manager, production_type_manager); + rgo_production_type = entry->get_rgo_production_type(); + province.apply_history_to_province(*entry, country_manager); if (!entry->get_pops().empty()) { pop_history_entry = entry.get(); @@ -112,6 +114,10 @@ bool MapInstance::apply_history_to_provinces( province.setup_pop_test_values(issue_manager); } + + if(rgo_production_type != nullptr) { + province.setup_rgo(*rgo_production_type); + } } } } diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index d35c44e..9e7fd6e 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -8,6 +8,7 @@ #include "openvic-simulation/misc/Define.hpp" #include "openvic-simulation/politics/Ideology.hpp" #include "economy/production/ResourceGatheringOperation.hpp" +#include "pop/Pop.hpp" #include "types/fixed_point/FixedPoint.hpp" using namespace OpenVic; @@ -188,7 +189,7 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) { average_consciousness += pop.get_consciousness(); average_militancy += pop.get_militancy(); - pop_type_distribution[pop.get_type()] += pop.get_size(); + pop_type_distribution[*pop.get_type()] += pop.get_size(); ideology_distribution += pop.get_ideologies(); culture_distribution[&pop.get_culture()] += pop.get_size(); religion_distribution[&pop.get_religion()] += pop.get_size(); @@ -203,6 +204,51 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) { } } +fixed_point_t ProvinceInstance::calculate_rgo_size(ProductionType const& production_type) const { + std::vector<Job> const& jobs = production_type.get_jobs(); + fixed_point_t total_worker_count_in_province = 0; //not counting equivalents + for(Pop const& pop : pops) { + bool is_worker_pop_type = false; + for(Job const& job : jobs) { + if(job.get_pop_type() == pop.get_type()) { + is_worker_pop_type = true; + break; + } + } + + if(is_worker_pop_type) { + total_worker_count_in_province += pop.get_size(); + } + } + + const fixed_point_t base_workforce_size = production_type.get_base_workforce_size(); + //TODO: if is_farm add farm size bonus + //TODO: if is_mine add mine size bonus + return ((total_worker_count_in_province / base_workforce_size).ceil() * fixed_point_t::_1_50()).floor(); +} + +void ProvinceInstance::convert_rgo_worker_pops_to_equivalent(ProductionType const& production_type) { + std::vector<Job> const& jobs = production_type.get_jobs(); + fixed_point_t total_worker_count_in_province = 0; //not counting equivalents + for(Pop& pop : pops) { + bool is_worker_pop_type = false; + for(Job const& job : jobs) { + PopType const* const job_pop_type = job.get_pop_type(); + PopType const* old_pop_type = pop.get_type(); + if(job_pop_type != old_pop_type) { + PopType const* const equivalent = old_pop_type->get_equivalent(); + if(job_pop_type == equivalent) { + pop.convert_to_equivalent(); + } + } + } + + if(is_worker_pop_type) { + total_worker_count_in_province += pop.get_size(); + } + } +} + void ProvinceInstance::update_gamestate(Date today, DefineManager const& define_manager) { for (BuildingInstance& building : buildings.get_items()) { building.update_gamestate(today); @@ -273,7 +319,7 @@ bool ProvinceInstance::setup(BuildingTypeManager const& building_type_manager) { return ret; } -bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager, ProductionTypeManager const& production_type_manager) { +bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager) { bool ret = true; constexpr auto set_optional = []<typename T>(T& target, std::optional<T> const& source) { @@ -298,15 +344,6 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent } } - ProductionType const* const rgo_production_type = entry.get_rgo_production_type(); - if(rgo_production_type != nullptr) { - constexpr fixed_point_t size_multiplier = fixed_point_t::_1(); - rgo = new ResourceGatheringOperation { - rgo_production_type, - size_multiplier - }; - } - set_optional(life_rating, entry.get_life_rating()); set_optional(terrain_type, entry.get_terrain_type()); for (auto const& [building, level] : entry.get_province_buildings()) { @@ -326,6 +363,14 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent return ret; } +void ProvinceInstance::setup_rgo(ProductionType const& rgo_production_type) { + convert_rgo_worker_pops_to_equivalent(rgo_production_type); + rgo = new ResourceGatheringOperation { + &rgo_production_type, + calculate_rgo_size(rgo_production_type) + }; +} + void ProvinceInstance::setup_pop_test_values(IssueManager const& issue_manager) { for (Pop& pop : pops) { pop.setup_pop_test_values(issue_manager); diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp index 5863a97..c8168a9 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -13,6 +13,7 @@ #include "openvic-simulation/types/OrderedContainers.hpp" #include "openvic-simulation/types/fixed_point/FixedPointMap.hpp" #include "economy/production/ResourceGatheringOperation.hpp" +#include "types/fixed_point/FixedPoint.hpp" namespace OpenVic { @@ -101,6 +102,8 @@ namespace OpenVic { void _add_pop(Pop&& pop); void _update_pops(DefineManager const& define_manager); + fixed_point_t calculate_rgo_size(ProductionType const& production_type) const; + void convert_rgo_worker_pops_to_equivalent(ProductionType const& production_type); public: ProvinceInstance(ProvinceInstance&&) = default; @@ -140,7 +143,10 @@ namespace OpenVic { bool remove_unit_instance_group(UnitInstanceGroup<Branch>& group); bool setup(BuildingTypeManager const& building_type_manager); - bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager, ProductionTypeManager const& production_type_manager); + bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager); + + //after history and pops! + void setup_rgo(ProductionType const& rgo_production_type); void setup_pop_test_values(IssueManager const& issue_manager); }; diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index dd829d9..85730e3 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -18,7 +18,7 @@ using enum PopType::income_type_t; PopBase::PopBase( PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size, fixed_point_t new_militancy, fixed_point_t new_consciousness, RebelType const* new_rebel_type -) : type { new_type }, culture { new_culture }, religion { new_religion }, size { new_size }, militancy { new_militancy }, +) : type { &new_type }, culture { new_culture }, religion { new_religion }, size { new_size }, militancy { new_militancy }, consciousness { new_consciousness }, rebel_type { new_rebel_type } {} Pop::Pop(PopBase const& pop_base, decltype(ideologies)::keys_t const& ideology_keys) @@ -114,6 +114,16 @@ void Pop::setup_pop_test_values(IssueManager const& issue_manager) { luxury_needs_fulfilled = test_range(); } +void Pop::convert_to_equivalent() { + PopType const* const equivalent = get_type()->get_equivalent(); + if(equivalent == nullptr) { + //error? + } + else { + type = equivalent; + } +} + void Pop::set_location(ProvinceInstance const& new_location) { if (location != &new_location) { location = &new_location; @@ -130,7 +140,7 @@ void Pop::set_location(ProvinceInstance const& new_location) { void Pop::update_gamestate( DefineManager const& define_manager, CountryInstance const* owner, fixed_point_t const& pop_size_per_regiment_multiplier ) { - if (type.get_can_be_recruited()) { + if (type->get_can_be_recruited()) { if ( size < define_manager.get_min_pop_size_for_regiment() || owner == nullptr || !RegimentType::allowed_cultures_check_culture_in_country(owner->get_allowed_regiment_cultures(), culture, *owner) diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp index 59a7794..ec8b955 100644 --- a/src/openvic-simulation/pop/Pop.hpp +++ b/src/openvic-simulation/pop/Pop.hpp @@ -35,7 +35,7 @@ namespace OpenVic { using pop_size_t = int32_t; protected: - PopType const& PROPERTY_ACCESS(type, protected); + PopType const* PROPERTY_ACCESS(type, protected); Culture const& PROPERTY_ACCESS(culture, protected); Religion const& PROPERTY_ACCESS(religion, protected); pop_size_t PROPERTY_ACCESS(size, protected); @@ -95,6 +95,7 @@ namespace OpenVic { Pop& operator=(Pop&&) = delete; void setup_pop_test_values(IssueManager const& issue_manager); + void convert_to_equivalent(); void set_location(ProvinceInstance const& new_location); |