From 0d861669d9e1f5d487c810ae01be50f142790f1e Mon Sep 17 00:00:00 2001 From: wvpm <24685035+wvpm@users.noreply.github.com> Date: Sun, 22 Sep 2024 01:07:51 +0200 Subject: Implement rgo for new game 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 Simplify good_to_rgo_production_type assignment Co-authored-by: Hop311 Fix import Co-authored-by: Hop311 min(3, great_powers.size()) Co-authored-by: Hop311 Fix import Co-authored-by: Hop311 Apply comments Log errors and return result when applying history Cleanup --- src/headless/main.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'src/headless/main.cpp') diff --git a/src/headless/main.cpp b/src/headless/main.cpp index 21e9f7c..a50b4ba 100644 --- a/src/headless/main.cpp +++ b/src/headless/main.cpp @@ -1,7 +1,10 @@ -#include - +#include #include +#include +#include +#include #include +#include #include #include @@ -18,6 +21,40 @@ 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& rgo = province.get_rgo(); + ProductionType const* const production_type_nullable = rgo.get_production_type_nullable(); + if (production_type_nullable == nullptr) { + Logger::error( + "\n ", province.get_identifier(), + " - production_type: nullptr" + ); + } else { + ProductionType const& production_type = *production_type_nullable; + GoodDefinition const& output_good = production_type.get_output_good(); + std::string text = StringUtils::append_string_views( + "\n\t", 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), + ", total owner income: ", rgo.get_total_owner_income_cache().to_string(3), + ", total employee income: ", rgo.get_total_employee_income_cache().to_string(3), + "\n\temployees:" + ); + + auto const& employee_count_per_type_cache=rgo.get_employee_count_per_type_cache(); + for (PopType const& pop_type : *employee_count_per_type_cache.get_keys()) { + const Pop::pop_size_t employees_of_type = employee_count_per_type_cache[pop_type]; + if (employees_of_type > 0) { + text += StringUtils::append_string_views("\n\t\t", std::to_string(employees_of_type), " ", pop_type.get_identifier()); + } + } + Logger::info("", text); + } +} + static bool run_headless(Dataloader::path_vector_t const& roots, bool run_tests) { bool ret = true; @@ -72,9 +109,21 @@ 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 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 (size_t i = 0; i < std::min(3, great_powers.size()); ++i) { + CountryInstance const& great_power = *great_powers[i]; + 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; -- cgit v1.2.3-56-ga3b1