diff options
author | wvpm <24685035+wvpm@users.noreply.github.com> | 2024-09-22 10:48:18 +0200 |
---|---|---|
committer | wvpm <24685035+wvpm@users.noreply.github.com> | 2024-09-22 10:48:18 +0200 |
commit | ea9b695022d197d918f1bb4292a0f424018dad37 (patch) | |
tree | 15d46970d136b08da9adf53a86e54fa97675cab2 /src | |
parent | 61ccb748627a3faeec282f53f746045d1a695517 (diff) |
Map province history rgo to production type for province instance
Diffstat (limited to 'src')
8 files changed, 51 insertions, 17 deletions
diff --git a/src/openvic-simulation/InstanceManager.cpp b/src/openvic-simulation/InstanceManager.cpp index c9ce24a..d0a4a18 100644 --- a/src/openvic-simulation/InstanceManager.cpp +++ b/src/openvic-simulation/InstanceManager.cpp @@ -126,7 +126,8 @@ bool InstanceManager::load_bookmark(Bookmark const* new_bookmark) { definition_manager.get_history_manager().get_province_manager(), today, country_instance_manager, // TODO - the following argument is for generating test pop attributes - definition_manager.get_politics_manager().get_issue_manager() + definition_manager.get_politics_manager().get_issue_manager(), + definition_manager.get_economy_manager().get_production_type_manager() ); ret &= country_instance_manager.apply_history_to_countries( diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp index 9bf6f49..92bf921 100644 --- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp +++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp @@ -3,7 +3,7 @@ using namespace OpenVic; ResourceGatheringOperation::ResourceGatheringOperation( - ProductionType const& new_production_type, + ProductionType const* new_production_type, fixed_point_t new_size_multiplier, fixed_point_t new_revenue_yesterday, fixed_point_t new_output_quantity_yesterday, @@ -17,5 +17,5 @@ ResourceGatheringOperation::ResourceGatheringOperation( employees { std::move(new_employees) } {} ResourceGatheringOperation::ResourceGatheringOperation( - ProductionType const& new_production_type, fixed_point_t new_size_multiplier + 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 d71c569..7528d6d 100644 --- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp +++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp @@ -7,7 +7,7 @@ namespace OpenVic { class ResourceGatheringOperation final { private: - ProductionType const& PROPERTY(production_type); + ProductionType const* PROPERTY_RW_ACCESS(production_type, public); fixed_point_t PROPERTY(revenue_yesterday); fixed_point_t PROPERTY(output_quantity_yesterday); fixed_point_t PROPERTY(unsold_quantity_yesterday); @@ -16,10 +16,10 @@ namespace OpenVic { public: ResourceGatheringOperation( - ProductionType const& new_production_type, fixed_point_t new_size_multiplier, fixed_point_t new_revenue_yesterday, + 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); + ResourceGatheringOperation(ProductionType const* new_production_type, fixed_point_t new_size_multiplier); }; } diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp index 0ce8cea..7c529bc 100644 --- a/src/openvic-simulation/map/MapInstance.cpp +++ b/src/openvic-simulation/map/MapInstance.cpp @@ -3,6 +3,7 @@ #include "openvic-simulation/history/ProvinceHistory.hpp" #include "openvic-simulation/map/MapDefinition.hpp" #include "openvic-simulation/utility/Logger.hpp" +#include "economy/production/ProductionType.hpp" using namespace OpenVic; @@ -82,7 +83,7 @@ bool MapInstance::setup( bool MapInstance::apply_history_to_provinces( ProvinceHistoryManager const& history_manager, Date date, CountryInstanceManager& country_manager, - IssueManager const& issue_manager + IssueManager const& issue_manager, ProductionTypeManager const& production_type_manager ) { bool ret = true; @@ -99,7 +100,7 @@ bool MapInstance::apply_history_to_provinces( break; } - province.apply_history_to_province(*entry, country_manager); + province.apply_history_to_province(*entry, country_manager, production_type_manager); if (!entry->get_pops().empty()) { pop_history_entry = entry.get(); diff --git a/src/openvic-simulation/map/MapInstance.hpp b/src/openvic-simulation/map/MapInstance.hpp index 99c13d3..22a564f 100644 --- a/src/openvic-simulation/map/MapInstance.hpp +++ b/src/openvic-simulation/map/MapInstance.hpp @@ -5,6 +5,7 @@ #include "openvic-simulation/map/State.hpp" #include "openvic-simulation/types/Date.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" +#include "economy/production/ProductionType.hpp" namespace OpenVic { struct MapDefinition; @@ -49,7 +50,7 @@ namespace OpenVic { ); bool apply_history_to_provinces( ProvinceHistoryManager const& history_manager, Date date, CountryInstanceManager& country_manager, - IssueManager const& issue_manager + IssueManager const& issue_manager, ProductionTypeManager const& production_type_manager ); void update_gamestate(Date today, DefineManager const& define_manager); diff --git a/src/openvic-simulation/map/Mapmode.cpp b/src/openvic-simulation/map/Mapmode.cpp index f951a05..88eb2eb 100644 --- a/src/openvic-simulation/map/Mapmode.cpp +++ b/src/openvic-simulation/map/Mapmode.cpp @@ -179,7 +179,7 @@ bool MapmodeManager::setup_mapmodes() { "mapmode_terrain_type", get_colour_mapmode(&ProvinceInstance::get_terrain_type) }, { - "mapmode_rgo", get_colour_mapmode(&ProvinceInstance::get_rgo) + "mapmode_rgo", get_colour_mapmode(&ProvinceInstance::get_rgo_good) }, { "mapmode_infrastructure", diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index 06b3f1e..1d69fec 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/GoodDefinition.hpp" +#include "openvic-simulation/economy/production/ProductionType.hpp" #include "openvic-simulation/history/ProvinceHistory.hpp" #include "openvic-simulation/map/ProvinceDefinition.hpp" #include "openvic-simulation/military/UnitInstanceGroup.hpp" @@ -23,7 +25,7 @@ ProvinceInstance::ProvinceInstance( cores {}, slave { false }, crime { nullptr }, - rgo { nullptr }, + rgo_production_type { nullptr }, buildings { "buildings", false }, armies {}, navies {}, @@ -255,7 +257,7 @@ bool ProvinceInstance::setup(BuildingTypeManager const& building_type_manager) { return ret; } -bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager) { +bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager, ProductionTypeManager const& production_type_manager) { bool ret = true; constexpr auto set_optional = []<typename T>(T& target, std::optional<T> const& source) { @@ -279,7 +281,25 @@ 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()); + + auto const& rgo_good_optional = entry.get_rgo(); + if(rgo_good_optional.has_value()) { + GoodDefinition const* const rgo_good = rgo_good_optional.value(); + if(rgo_good != nullptr) { + IndexedMap<GoodDefinition, ProductionType const*> const& good_to_rgo_production_type = production_type_manager.get_good_to_rgo_production_type(); + ProductionType const* rgo_production_type = good_to_rgo_production_type[*rgo_good]; + if(rgo_production_type!= nullptr) { + set_rgo_production_type(rgo_production_type); + } + else { + //error we expect the good to have an rgo production type but there is none + //Victoria 2 treats this as null, but clearly the modder wanted there to be a good + } + } + //else explicitly set null, no-op + } + //else default null, no-op + 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()) { diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp index fa0be98..9899a16 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -1,14 +1,18 @@ #pragma once +#include <cstddef> + #include <plf_colony.h> #include "openvic-simulation/economy/BuildingInstance.hpp" +#include "openvic-simulation/economy/production/ProductionType.hpp" #include "openvic-simulation/military/UnitInstance.hpp" #include "openvic-simulation/military/UnitType.hpp" #include "openvic-simulation/pop/Pop.hpp" -#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp" #include "openvic-simulation/types/HasIdentifier.hpp" #include "openvic-simulation/types/OrderedContainers.hpp" +#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp" + namespace OpenVic { struct MapInstance; @@ -70,8 +74,7 @@ namespace OpenVic { bool PROPERTY(slave); Crime const* PROPERTY_RW(crime); - // TODO - change this into a factory-like structure - GoodDefinition const* PROPERTY(rgo); + ProductionType const* PROPERTY_RW_ACCESS(rgo_production_type, public); IdentifierRegistry<BuildingInstance> IDENTIFIER_REGISTRY(building); ordered_set<ArmyInstance*> PROPERTY(armies); ordered_set<NavyInstance*> PROPERTY(navies); @@ -112,6 +115,14 @@ namespace OpenVic { return controller; } + GoodDefinition const* get_rgo_good() const { + GoodDefinition const* rgo_good { nullptr }; + if(rgo_production_type != nullptr) { + rgo_good = rgo_production_type->get_output_good(); + } + return rgo_good; + } + bool set_owner(CountryInstance* new_owner); bool set_controller(CountryInstance* new_controller); bool add_core(CountryInstance& new_core); @@ -133,7 +144,7 @@ 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); + bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager, ProductionTypeManager const& production_type_manager); void setup_pop_test_values(IssueManager const& issue_manager); }; |