diff options
author | wvpm <24685035+wvpm@users.noreply.github.com> | 2024-09-22 01:07:51 +0200 |
---|---|---|
committer | wvpm <24685035+wvpm@users.noreply.github.com> | 2024-10-30 22:04:41 +0100 |
commit | 0d861669d9e1f5d487c810ae01be50f142790f1e (patch) | |
tree | 187df50130475006b404c5ab57f0fa679173ad04 /src/openvic-simulation/map/ProvinceInstance.cpp | |
parent | 48e4e92682db99239e928a67e6677cdd2c53a375 (diff) |
Implement rgo for new gameprepare_for_rgo
Map province history rgo to production type for province instance
output_goods back to ZERO_OR_ONE
Link trade_goods in history to RGO instance for province.
Other producer types as structs instead of classes
Convert pops to equivalents & calculate rgo size
Also convert pops when changing rgo
Clean up
Refactored RGO into part of ProvinceInstance
ProductionType const& output_good
Remove unused imports
Clean up unused imports
Restore constructor for ResourceGatheringOperation to initialise from savegame
Move rgo size calculation to rgo
Use terrain modifiers to calculate rgo size (placeholder code)
Clean up
Basic production & sales for rgo when initialising new game
Use mutable pops
Paychecks for owners, workers and slaves
Clean up
Simplify rgo instantiation
Co-authored-by: Hop311 <Hop3114@gmail.com>
Simplify good_to_rgo_production_type assignment
Co-authored-by: Hop311 <Hop3114@gmail.com>
Fix import
Co-authored-by: Hop311 <Hop3114@gmail.com>
min(3, great_powers.size())
Co-authored-by: Hop311 <Hop3114@gmail.com>
Fix import
Co-authored-by: Hop311 <Hop3114@gmail.com>
Apply comments
Log errors and return result when applying history
Cleanup
Diffstat (limited to 'src/openvic-simulation/map/ProvinceInstance.cpp')
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.cpp | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index cbb23bd..64a104b 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -1,6 +1,8 @@ #include "ProvinceInstance.hpp" #include "openvic-simulation/country/CountryInstance.hpp" +#include "openvic-simulation/economy/production/ProductionType.hpp" +#include "openvic-simulation/economy/production/ResourceGatheringOperation.hpp" #include "openvic-simulation/history/ProvinceHistory.hpp" #include "openvic-simulation/map/Crime.hpp" #include "openvic-simulation/map/ProvinceDefinition.hpp" @@ -10,6 +12,8 @@ #include "openvic-simulation/misc/Define.hpp" #include "openvic-simulation/modifier/StaticModifierCache.hpp" #include "openvic-simulation/politics/Ideology.hpp" +#include "openvic-simulation/pop/Pop.hpp" +#include "openvic-simulation/utility/Logger.hpp" using namespace OpenVic; @@ -29,7 +33,7 @@ ProvinceInstance::ProvinceInstance( event_modifiers {}, slave { false }, crime { nullptr }, - rgo { nullptr }, + rgo { pop_type_keys }, buildings { "buildings", false }, armies {}, navies {}, @@ -41,6 +45,25 @@ ProvinceInstance::ProvinceInstance( religion_distribution {}, max_supported_regiments { 0 } {} +GoodDefinition const* ProvinceInstance::get_rgo_good() const { + if (!rgo.is_valid()) { return nullptr; } + return &(rgo.get_production_type_nullable()->get_output_good()); +} +bool ProvinceInstance::set_rgo_production_type_nullable(ProductionType const* rgo_production_type_nullable) { + bool is_valid_operation = true; + if (rgo_production_type_nullable != nullptr) { + ProductionType const& rgo_production_type = *rgo_production_type_nullable; + if (rgo_production_type.get_template_type() != ProductionType::template_type_t::RGO) { + Logger::error("Tried setting province ", get_identifier(), " rgo to ", rgo_production_type.get_identifier(), " which is not of template_type RGO."); + is_valid_operation = false; + } + is_valid_operation&=convert_rgo_worker_pops_to_equivalent(rgo_production_type); + } + + rgo.set_production_type_nullable(rgo_production_type_nullable); + return is_valid_operation; +} + bool ProvinceInstance::set_owner(CountryInstance* new_owner) { bool ret = true; @@ -176,7 +199,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(); @@ -311,6 +334,24 @@ std::vector<ModifierSum::modifier_entry_t> ProvinceInstance::get_contributing_mo } } +bool ProvinceInstance::convert_rgo_worker_pops_to_equivalent(ProductionType const& production_type) { + bool is_valid_operation = true; + std::vector<Job> const& jobs = production_type.get_jobs(); + for(Pop& pop : pops) { + 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) { + is_valid_operation&=pop.convert_to_equivalent(); + } + } + } + } + return is_valid_operation; +} + void ProvinceInstance::update_gamestate(Date today, DefineManager const& define_manager) { for (BuildingInstance& building : buildings.get_items()) { building.update_gamestate(today); @@ -405,7 +446,7 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent ret &= remove_core(country_manager.get_country_instance_from_definition(*country)); } } - set_optional(rgo, entry.get_rgo()); + 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()) { @@ -425,8 +466,16 @@ 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::setup_pop_test_values(IssueManager const& issue_manager) { for (Pop& pop : pops) { pop.setup_pop_test_values(issue_manager); } } + +plf::colony<Pop>& ProvinceInstance::get_mutable_pops() { + return pops; +}
\ No newline at end of file |