diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/headless/main.cpp | 65 | ||||
-rw-r--r-- | src/openvic-simulation/economy/production/ProductionType.cpp | 6 | ||||
-rw-r--r-- | src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/history/ProvinceHistory.cpp | 17 | ||||
-rw-r--r-- | src/openvic-simulation/history/ProvinceHistory.hpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.cpp | 43 | ||||
-rw-r--r-- | src/openvic-simulation/map/ProvinceInstance.hpp | 12 |
7 files changed, 114 insertions, 35 deletions
diff --git a/src/headless/main.cpp b/src/headless/main.cpp index 21e9f7c..85c0ce2 100644 --- a/src/headless/main.cpp +++ b/src/headless/main.cpp @@ -1,5 +1,12 @@ #include <cstring> - +#include <string> +#include <vector> + +#include "economy/GoodDefinition.hpp" +#include <openvic-simulation/country/CountryInstance.hpp> +#include <openvic-simulation/economy/production/ProductionType.hpp> +#include <openvic-simulation/economy/production/ResourceGatheringOperation.hpp> +#include <openvic-simulation/pop/Pop.hpp> #include <openvic-simulation/dataloader/Dataloader.hpp> #include <openvic-simulation/GameManager.hpp> #include <openvic-simulation/testing/Testing.hpp> @@ -18,6 +25,42 @@ static void print_help(std::ostream& stream, char const* program_name) { << "(Paths with spaces need to be enclosed in \"quotes\").\n"; } +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"); + } + else { + ProductionType const* const production_type = rgo->get_production_type(); + if (production_type == nullptr) { + Logger::error( + "\n ", province.get_identifier(), + " - production_type: nullptr" + ); + } + 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) + ); + } + } + } +} + static bool run_headless(Dataloader::path_vector_t const& roots, bool run_tests) { bool ret = true; @@ -72,9 +115,27 @@ static bool run_headless(Dataloader::path_vector_t const& roots, bool run_tests) CountryInstanceManager const& country_instance_manager = game_manager.get_instance_manager()->get_country_instance_manager(); - print_ranking_list("Great Powers", country_instance_manager.get_great_powers()); + std::vector<CountryInstance*> const& great_powers = country_instance_manager.get_great_powers(); + print_ranking_list("Great Powers", great_powers); print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers()); print_ranking_list("All countries", country_instance_manager.get_total_ranking()); + + Logger::info("===== RGO test... ====="); + for (int i = 0; i < 3; ++i) { + CountryInstance const* const great_power = great_powers[i]; + if(great_power == nullptr) { + Logger::warning("Great power ",std::to_string(i), " is null."); + } + else { + ProvinceInstance const* const capital_province = great_power->get_capital(); + if(capital_province == nullptr) { + Logger::warning(great_power->get_identifier(), " has no capital ProvinceInstance set."); + } + else { + print_rgo(*capital_province); + } + } + } } else { Logger::error("Instance manager not available!"); ret = false; diff --git a/src/openvic-simulation/economy/production/ProductionType.cpp b/src/openvic-simulation/economy/production/ProductionType.cpp index bc5bc0b..fd9bce7 100644 --- a/src/openvic-simulation/economy/production/ProductionType.cpp +++ b/src/openvic-simulation/economy/production/ProductionType.cpp @@ -174,15 +174,15 @@ bool ProductionTypeManager::add_production_type( base_output_quantity, std::move(bonuses), std::move(maintenance_requirements), is_coastal, is_farm, is_mine }); - if(ret && (is_farm | is_mine)) { + if(ret && (template_type == RGO)) { ProductionType const& production_type = production_types.get_items().back(); auto current_rgo_pt = good_to_rgo_production_type[*output_good]; if(current_rgo_pt == nullptr) { // first rgo pt good_to_rgo_production_type[*output_good] = &production_type; } - else if (is_farm && current_rgo_pt->is_mine()) { - // farms are preferred over mines in V2 + else if (is_farm && !current_rgo_pt->is_farm()) { + // farms are preferred (over mines) in V2 good_to_rgo_production_type[*output_good] = &production_type; } //else ignore, we already have an rgo pt diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp index 7528d6d..2fb782e 100644 --- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp +++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp @@ -5,9 +5,9 @@ #include "openvic-simulation/utility/Getters.hpp" namespace OpenVic { - class ResourceGatheringOperation final { + struct ResourceGatheringOperation { private: - ProductionType const* PROPERTY_RW_ACCESS(production_type, public); + ProductionType const* PROPERTY_RW(production_type); fixed_point_t PROPERTY(revenue_yesterday); fixed_point_t PROPERTY(output_quantity_yesterday); fixed_point_t PROPERTY(unsold_quantity_yesterday); diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp index ef8793b..7d3d6eb 100644 --- a/src/openvic-simulation/history/ProvinceHistory.cpp +++ b/src/openvic-simulation/history/ProvinceHistory.cpp @@ -1,7 +1,10 @@ #include "ProvinceHistory.hpp" #include "openvic-simulation/DefinitionManager.hpp" +#include "openvic-simulation/economy/GoodDefinition.hpp" #include "openvic-simulation/map/ProvinceDefinition.hpp" +#include "dataloader/NodeTools.hpp" +#include "types/IdentifierRegistry.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -57,6 +60,9 @@ bool ProvinceHistoryMap::_load_history_entry( }; }; + constexpr bool allow_empty_true = true; + constexpr bool do_warn = true; + return expect_dictionary_keys_and_default( [this, &definition_manager, &building_type_manager, &entry]( std::string_view key, ast::NodeCPtr value) -> bool { @@ -98,7 +104,16 @@ bool ProvinceHistoryMap::_load_history_entry( expect_identifier(expect_mapped_string(colony_status_map, assign_variable_callback(entry.colonial))), "is_slave", ZERO_OR_ONE, expect_bool(assign_variable_callback(entry.slave)), "trade_goods", ZERO_OR_ONE, - good_definition_manager.expect_good_definition_identifier(assign_variable_callback_pointer_opt(entry.rgo)), + good_definition_manager.expect_good_definition_identifier_or_string( + [&definition_manager, &entry](GoodDefinition const& rgo_good) ->bool { + entry.rgo_production_type = definition_manager.get_economy_manager().get_production_type_manager().get_good_to_rgo_production_type()[rgo_good]; + return entry.rgo_production_type != nullptr; + //we expect the good to have an rgo production type + //Victoria 2 treats this as null, but clearly the modder wanted there to be a good + }, + allow_empty_true, //could be explicitly setting trade_goods to null + do_warn //could be typo in good identifier + ), "life_rating", ZERO_OR_ONE, expect_uint<ProvinceInstance::life_rating_t>(assign_variable_callback(entry.life_rating)), "terrain", ZERO_OR_ONE, terrain_type_manager.expect_terrain_type_identifier( assign_variable_callback_pointer_opt(entry.terrain_type) diff --git a/src/openvic-simulation/history/ProvinceHistory.hpp b/src/openvic-simulation/history/ProvinceHistory.hpp index 99ea2af..db6b57f 100644 --- a/src/openvic-simulation/history/ProvinceHistory.hpp +++ b/src/openvic-simulation/history/ProvinceHistory.hpp @@ -32,7 +32,7 @@ namespace OpenVic { std::optional<ProvinceInstance::colony_status_t> PROPERTY(colonial); std::optional<bool> PROPERTY(slave); ordered_map<CountryDefinition const*, bool> PROPERTY(cores); - std::optional<GoodDefinition const*> PROPERTY(rgo); + ProductionType const* PROPERTY(rgo_production_type); std::optional<ProvinceInstance::life_rating_t> PROPERTY(life_rating); std::optional<TerrainType const*> PROPERTY(terrain_type); ordered_map<BuildingType const*, BuildingType::level_t> PROPERTY(province_buildings); diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp index 1d69fec..d35c44e 100644 --- a/src/openvic-simulation/map/ProvinceInstance.cpp +++ b/src/openvic-simulation/map/ProvinceInstance.cpp @@ -1,13 +1,14 @@ #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" #include "openvic-simulation/misc/Define.hpp" #include "openvic-simulation/politics/Ideology.hpp" +#include "economy/production/ResourceGatheringOperation.hpp" +#include "types/fixed_point/FixedPoint.hpp" using namespace OpenVic; @@ -25,7 +26,7 @@ ProvinceInstance::ProvinceInstance( cores {}, slave { false }, crime { nullptr }, - rgo_production_type { nullptr }, + rgo { nullptr }, buildings { "buildings", false }, armies {}, navies {}, @@ -37,6 +38,21 @@ ProvinceInstance::ProvinceInstance( religion_distribution {}, max_supported_regiments { 0 } {} + GoodDefinition const* ProvinceInstance::get_rgo_good() const { + if(rgo == nullptr) { return nullptr; } + return rgo->get_production_type()->get_output_good(); + } + void ProvinceInstance::set_rgo_production_type(ProductionType const& production_type) { + if(production_type.get_template_type() != ProductionType::template_type_t::RGO) { + //error + } + + //recalculate rgo size? + //convert pops farmers <> labourers + + rgo->set_production_type(&production_type); + } + bool ProvinceInstance::set_owner(CountryInstance* new_owner) { bool ret = true; @@ -282,23 +298,14 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent } } - 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 + 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 + }; } - //else default null, no-op set_optional(life_rating, entry.get_life_rating()); set_optional(terrain_type, entry.get_terrain_type()); diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp index 9899a16..5863a97 100644 --- a/src/openvic-simulation/map/ProvinceInstance.hpp +++ b/src/openvic-simulation/map/ProvinceInstance.hpp @@ -12,6 +12,7 @@ #include "openvic-simulation/types/HasIdentifier.hpp" #include "openvic-simulation/types/OrderedContainers.hpp" #include "openvic-simulation/types/fixed_point/FixedPointMap.hpp" +#include "economy/production/ResourceGatheringOperation.hpp" namespace OpenVic { @@ -74,7 +75,7 @@ namespace OpenVic { bool PROPERTY(slave); Crime const* PROPERTY_RW(crime); - ProductionType const* PROPERTY_RW_ACCESS(rgo_production_type, public); + ResourceGatheringOperation* PROPERTY(rgo); IdentifierRegistry<BuildingInstance> IDENTIFIER_REGISTRY(building); ordered_set<ArmyInstance*> PROPERTY(armies); ordered_set<NavyInstance*> PROPERTY(navies); @@ -115,13 +116,8 @@ 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; - } + GoodDefinition const* get_rgo_good() const; + void set_rgo_production_type(ProductionType const& production_type); bool set_owner(CountryInstance* new_owner); bool set_controller(CountryInstance* new_controller); |