From 873229df9f38ff19eb23018fd522bb313e511085 Mon Sep 17 00:00:00 2001 From: wvpm <24685035+wvpm@users.noreply.github.com> Date: Sun, 22 Sep 2024 20:44:08 +0200 Subject: Refactored RGO into part of ProvinceInstance --- src/headless/main.cpp | 43 ++++++++++------------ .../production/ResourceGatheringOperation.cpp | 21 ----------- .../production/ResourceGatheringOperation.hpp | 11 ++---- src/openvic-simulation/map/ProvinceInstance.cpp | 15 ++++---- src/openvic-simulation/map/ProvinceInstance.hpp | 2 +- 5 files changed, 31 insertions(+), 61 deletions(-) delete mode 100644 src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp (limited to 'src') diff --git a/src/headless/main.cpp b/src/headless/main.cpp index 85c0ce2..3c9fc8b 100644 --- a/src/headless/main.cpp +++ b/src/headless/main.cpp @@ -26,37 +26,32 @@ static void print_help(std::ostream& stream, char const* program_name) { } static void print_rgo(ProvinceInstance const& province) { - ResourceGatheringOperation const* const rgo = province.get_rgo(); - if(rgo == nullptr) { - Logger::info("\n ", province.get_identifier(), " - rgo: nullptr"); + ResourceGatheringOperation const& rgo = province.get_rgo(); + ProductionType const* const production_type = rgo.get_production_type(); + if (production_type == nullptr) { + Logger::error( + "\n ", province.get_identifier(), + " - production_type: nullptr" + ); } else { - ProductionType const* const production_type = rgo->get_production_type(); - if (production_type == nullptr) { + GoodDefinition const* const output_good = production_type->get_output_good(); + if(output_good == nullptr) { Logger::error( "\n ", province.get_identifier(), - " - production_type: nullptr" + " - good: nullptr", + ", production_type: ", production_type->get_identifier() ); } else { - GoodDefinition const* const output_good = production_type->get_output_good(); - if(output_good == nullptr) { - Logger::error( - "\n ", province.get_identifier(), - " - good: nullptr", - ", production_type: ", production_type->get_identifier() - ); - } - else { - Logger::info( - "\n ", province.get_identifier(), - " - good: ", output_good->get_identifier(), - ", production_type: ", production_type->get_identifier(), - ", size_multiplier: ", rgo->get_size_multiplier().to_string(3), - ", output_quantity_yesterday: ", rgo->get_output_quantity_yesterday().to_string(3), - ", revenue_yesterday: ", rgo->get_revenue_yesterday().to_string(3) - ); - } + Logger::info( + "\n ", province.get_identifier(), + " - good: ", output_good->get_identifier(), + ", production_type: ", production_type->get_identifier(), + ", size_multiplier: ", rgo.get_size_multiplier().to_string(3), + ", output_quantity_yesterday: ", rgo.get_output_quantity_yesterday().to_string(3), + ", revenue_yesterday: ", rgo.get_revenue_yesterday().to_string(3) + ); } } } 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&& 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 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&& 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 #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 IDENTIFIER_REGISTRY(building); ordered_set PROPERTY(armies); ordered_set PROPERTY(navies); -- cgit v1.2.3-56-ga3b1