diff options
Diffstat (limited to 'src/openvic-simulation/map/ProvinceInstance.cpp')
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.cpp | 67 |
1 files changed, 56 insertions, 11 deletions
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); |