diff options
author | wvpm <24685035+wvpm@users.noreply.github.com> | 2024-09-22 20:44:08 +0200 |
---|---|---|
committer | wvpm <24685035+wvpm@users.noreply.github.com> | 2024-09-22 20:44:08 +0200 |
commit | 873229df9f38ff19eb23018fd522bb313e511085 (patch) | |
tree | 3fc318ff2c945e29c352864d0244c301344572de /src/openvic-simulation | |
parent | 26cbbc7612ce2f42cfd44f099aa72898656691a7 (diff) |
Refactored RGO into part of ProvinceInstance
Diffstat (limited to 'src/openvic-simulation')
4 files changed, 12 insertions, 37 deletions
diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp deleted file mode 100644 index 92bf921..0000000 --- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "ResourceGatheringOperation.hpp" - -using namespace OpenVic; - -ResourceGatheringOperation::ResourceGatheringOperation( - ProductionType const* new_production_type, - fixed_point_t new_size_multiplier, - fixed_point_t new_revenue_yesterday, - fixed_point_t new_output_quantity_yesterday, - fixed_point_t new_unsold_quantity_yesterday, - ordered_map<Pop*, Pop::pop_size_t>&& new_employees -) : production_type { new_production_type }, - revenue_yesterday { new_revenue_yesterday }, - output_quantity_yesterday { new_output_quantity_yesterday }, - unsold_quantity_yesterday { new_unsold_quantity_yesterday }, - size_multiplier { new_size_multiplier }, - employees { std::move(new_employees) } {} - -ResourceGatheringOperation::ResourceGatheringOperation( - ProductionType const* new_production_type, fixed_point_t new_size_multiplier -) : ResourceGatheringOperation { new_production_type, new_size_multiplier, 0, 0, 0, {} } {} diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp index 2fb782e..f5706e1 100644 --- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp +++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp @@ -11,15 +11,12 @@ namespace OpenVic { fixed_point_t PROPERTY(revenue_yesterday); fixed_point_t PROPERTY(output_quantity_yesterday); fixed_point_t PROPERTY(unsold_quantity_yesterday); - fixed_point_t PROPERTY(size_multiplier); + fixed_point_t PROPERTY_RW(size_multiplier); ordered_map<Pop*, Pop::pop_size_t> PROPERTY(employees); public: - ResourceGatheringOperation( - ProductionType const* new_production_type, fixed_point_t new_size_multiplier, fixed_point_t new_revenue_yesterday, - fixed_point_t new_output_quantity_yesterday, fixed_point_t new_unsold_quantity_yesterday, - ordered_map<Pop*, Pop::pop_size_t>&& new_employees - ); - ResourceGatheringOperation(ProductionType const* new_production_type, fixed_point_t new_size_multiplier); + constexpr bool is_valid() const { + return production_type != nullptr; + } }; } diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index 98e8fcb..e8361da 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -1,4 +1,5 @@ #include "ProvinceInstance.hpp" +#include <cstddef> #include "openvic-simulation/country/CountryInstance.hpp" #include "openvic-simulation/economy/production/ProductionType.hpp" @@ -27,7 +28,7 @@ ProvinceInstance::ProvinceInstance( cores {}, slave { false }, crime { nullptr }, - rgo { nullptr }, + rgo { ResourceGatheringOperation {} }, buildings { "buildings", false }, armies {}, navies {}, @@ -40,15 +41,15 @@ ProvinceInstance::ProvinceInstance( max_supported_regiments { 0 } {} GoodDefinition const* ProvinceInstance::get_rgo_good() const { - if(rgo == nullptr) { return nullptr; } - return rgo->get_production_type()->get_output_good(); + if(!rgo.is_valid()) { return nullptr; } + return rgo.get_production_type()->get_output_good(); } void ProvinceInstance::set_rgo_production_type(ProductionType const& rgo_production_type) { if(rgo_production_type.get_template_type() != ProductionType::template_type_t::RGO) { //error } convert_rgo_worker_pops_to_equivalent(rgo_production_type); - rgo->set_production_type(&rgo_production_type); + rgo.set_production_type(&rgo_production_type); } bool ProvinceInstance::set_owner(CountryInstance* new_owner) { @@ -362,10 +363,8 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent 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) - }; + rgo.set_size_multiplier(calculate_rgo_size(rgo_production_type)); + rgo.set_production_type(&rgo_production_type); } void ProvinceInstance::setup_pop_test_values(IssueManager const& issue_manager) { diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp index d551f37..6ca7c6b 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -76,7 +76,7 @@ namespace OpenVic { bool PROPERTY(slave); Crime const* PROPERTY_RW(crime); - ResourceGatheringOperation* PROPERTY(rgo); + ResourceGatheringOperation PROPERTY(rgo); IdentifierRegistry<BuildingInstance> IDENTIFIER_REGISTRY(building); ordered_set<ArmyInstance*> PROPERTY(armies); ordered_set<NavyInstance*> PROPERTY(navies); |