From 4794eeedd9abc1393526a97253bf9d59b5ecd179 Mon Sep 17 00:00:00 2001 From: BrickPi <49528459+BrickPi@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:12:00 -0600 Subject: Implement National Foci --- .vscode/launch.json | 20 ++++ src/openvic-simulation/Modifier.cpp | 6 +- src/openvic-simulation/dataloader/Dataloader.cpp | 7 ++ src/openvic-simulation/politics/NationalFocus.cpp | 118 +++++++++++++++++++++ src/openvic-simulation/politics/NationalFocus.hpp | 76 +++++++++++++ .../politics/PoliticsManager.hpp | 6 ++ 6 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 src/openvic-simulation/politics/NationalFocus.cpp create mode 100644 src/openvic-simulation/politics/NationalFocus.hpp diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..da3dff4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,20 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppvsdbg", + "request": "launch", + "program": "${workspaceFolder}/bin/openvic-simulation.headless.windows.template_debug.dev.x86_64.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "console": "integratedTerminal" + } + + ] +} \ No newline at end of file diff --git a/src/openvic-simulation/Modifier.cpp b/src/openvic-simulation/Modifier.cpp index c3b7f6a..f6e34e1 100644 --- a/src/openvic-simulation/Modifier.cpp +++ b/src/openvic-simulation/Modifier.cpp @@ -226,6 +226,7 @@ bool ModifierManager::setup_modifier_effects() { ret &= add_modifier_effect("pop_consciousness_modifier", false, RAW_DECIMAL); ret &= add_modifier_effect("pop_militancy_modifier", false, RAW_DECIMAL); ret &= add_modifier_effect("population_growth", true); + ret &= add_modifier_effect("flashpoint_tension", false); ret &= add_modifier_effect("farm_rgo_eff", true); ret &= add_modifier_effect("farm_RGO_eff", true); ret &= add_modifier_effect("farm_rgo_size", true); @@ -235,6 +236,7 @@ bool ModifierManager::setup_modifier_effects() { ret &= add_modifier_effect("mine_rgo_size", true); ret &= add_modifier_effect("mine_RGO_size", true); ret &= add_modifier_effect("movement_cost", false); + ret &= add_modifier_effect("railroads", true); // capitalist likelihood for railroads vs factories ret &= add_modifier_effect("supply_limit", true, RAW_DECIMAL); /* Military Modifier Effects */ @@ -324,10 +326,10 @@ node_callback_t ModifierManager::expect_whitelisted_modifier_value( node_callback_t ModifierManager::expect_modifier_value_and_key_map_and_default( callback_t modifier_callback, key_value_callback_t default_callback, key_map_t&& key_map ) const { - return [this, modifier_callback, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> bool { + return [this, modifier_callback, default_callback, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> bool { bool ret = expect_modifier_value_and_default( modifier_callback, - dictionary_keys_callback(key_map, key_value_invalid_callback) + dictionary_keys_callback(key_map, default_callback) )(node); ret &= check_key_map_counts(key_map); return ret; diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp index 011b524..d36799f 100644 --- a/src/openvic-simulation/dataloader/Dataloader.cpp +++ b/src/openvic-simulation/dataloader/Dataloader.cpp @@ -843,6 +843,7 @@ bool Dataloader::load_defines(GameManager& game_manager) const { static const std::string graphical_culture_type_file = "common/graphicalculturetype.txt"; static const std::string ideology_file = "common/ideologies.txt"; static const std::string issues_file = "common/issues.txt"; + static const std::string national_foci_file = "common/national_focus.txt"; static const std::string national_values_file = "common/nationalvalues.txt"; static const std::string production_types_file = "common/production_types.txt"; static const std::string religion_file = "common/religion.txt"; @@ -918,6 +919,12 @@ bool Dataloader::load_defines(GameManager& game_manager) const { Logger::error("Failed to load issues!"); ret = false; } + if (!game_manager.get_politics_manager().load_national_foci_file( + game_manager.get_pop_manager(), game_manager.get_economy_manager().get_good_manager(), game_manager.get_modifier_manager(), parse_defines(lookup_file(national_foci_file)).get_file_node() + )) { + Logger::error("Failed to load national foci!"); + ret = false; + } if (!game_manager.get_politics_manager().get_national_value_manager().load_national_values_file( game_manager.get_modifier_manager(), parse_defines(lookup_file(national_values_file)).get_file_node() )) { diff --git a/src/openvic-simulation/politics/NationalFocus.cpp b/src/openvic-simulation/politics/NationalFocus.cpp new file mode 100644 index 0000000..6f25c3e --- /dev/null +++ b/src/openvic-simulation/politics/NationalFocus.cpp @@ -0,0 +1,118 @@ +#include "NationalFocus.hpp" + +#include "openvic-simulation/dataloader/NodeTools.hpp" + +using namespace OpenVic; +using namespace OpenVic::NodeTools; + +NationalFocusGroup::NationalFocusGroup(std::string_view new_identifier) : HasIdentifier { new_identifier } {} + +NationalFocus::NationalFocus( + std::string_view new_identifier, + uint8_t new_icon, + NationalFocusGroup const& new_group, + ModifierValue&& new_modifiers, + pop_promotion_map_t&& new_encouraged_promotion, + party_loyalty_map_t&& new_encouraged_loyalty, + production_map_t&& new_encouraged_production +) : HasIdentifier { new_identifier }, + icon { new_icon }, + group { new_group }, + modifiers { std::move(new_modifiers) }, + encouraged_promotion { std::move(new_encouraged_promotion) }, + encouraged_loyalty { std::move(new_encouraged_loyalty) }, + encouraged_production { std::move(new_encouraged_production) } {} + +NationalFocusManager::NationalFocusManager() : national_focus_groups { "national focus groups" }, national_foci { "national foci" } {} + +inline bool NationalFocusManager::add_national_focus_group(std::string_view identifier) { + if (identifier.empty()) { + Logger::error("No identifier for national focus group!"); + return false; + } + return national_focus_groups.add_item({ identifier }); +} + +inline bool NationalFocusManager::add_national_focus( + std::string_view identifier, + uint8_t icon, + NationalFocusGroup const& group, + ModifierValue&& modifiers, + NationalFocus::pop_promotion_map_t&& encouraged_promotion, + NationalFocus::party_loyalty_map_t&& encouraged_loyalty, + NationalFocus::production_map_t&& encouraged_production +) { + if (identifier.empty()) { + Logger::error("No identifier for national focus!"); + return false; + } + if (icon < 1) { + Logger::error("Invalid icon ", icon, " for national focus ", identifier); + return false; + } + return national_foci.add_item({ identifier, icon, group, std::move(modifiers), std::move(encouraged_promotion), std::move(encouraged_loyalty), std::move(encouraged_production) }); +} + +bool NationalFocusManager::load_national_foci_file(PopManager const& pop_manager, IdeologyManager const& ideology_manager, GoodManager const& good_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root) { + bool ret = expect_dictionary_reserve_length(national_focus_groups, [this](std::string_view identifier, ast::NodeCPtr node) -> bool { + return add_national_focus_group(identifier); + })(root); + lock_national_focus_groups(); + + ret &= expect_national_focus_group_dictionary([this, &pop_manager, &ideology_manager, &good_manager, &modifier_manager](NationalFocusGroup const& group, ast::NodeCPtr node) -> bool { + bool ret = expect_dictionary([this, &group, &pop_manager, &ideology_manager, &good_manager, &modifier_manager](std::string_view identifier, ast::NodeCPtr node) -> bool { + uint8_t icon; + ModifierValue modifiers; + NationalFocus::pop_promotion_map_t promotions; + NationalFocus::party_loyalty_map_t loyalties; + NationalFocus::production_map_t production; + + Ideology const* last_specified_ideology = nullptr; // weird, I know + + bool ret = modifier_manager.expect_modifier_value_and_keys_and_default( + move_variable_callback(modifiers), + [&promotions, &pop_manager, &production, &good_manager, &modifiers, &modifier_manager](std::string_view key, ast::NodeCPtr value) -> bool { + PopType const* pop_type = pop_manager.get_pop_type_by_identifier(key); + if (pop_type != nullptr) { + fixed_point_t boost; + bool ret = expect_fixed_point(assign_variable_callback(boost))(value); + promotions[pop_type] = boost; + return ret; + } + Good const* good = good_manager.get_good_by_identifier(key); + if (good != nullptr) { + fixed_point_t boost; + bool ret = expect_fixed_point(assign_variable_callback(boost))(value); + production[good] = boost; + return ret; + } + return key_value_invalid_callback(key, value); + }, + "icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)), + "ideology", ZERO_OR_MORE, ideology_manager.expect_ideology_identifier(assign_variable_callback_pointer(last_specified_ideology)), + "loyalty_value", ZERO_OR_MORE, [&identifier, &last_specified_ideology, &loyalties](ast::NodeCPtr value) -> bool { + if (last_specified_ideology == nullptr) { + Logger::error("In national focus ", identifier, ": No ideology selected for loyalty_value!"); + return false; + } + fixed_point_t boost; + bool ret = expect_fixed_point(assign_variable_callback(boost))(value); + loyalties[last_specified_ideology] += boost; + return ret; + }, + "limit", ZERO_OR_ONE, success_callback, // TODO: implement conditions + "has_flashpoint", ZERO_OR_ONE, success_callback, // special case, include in limit + "own_provinces", ZERO_OR_ONE, success_callback, // special case, include in limit + "outliner_show_as_percent", ZERO_OR_ONE, success_callback // special case + )(node); + + add_national_focus(identifier, icon, group, std::move(modifiers), std::move(promotions), std::move(loyalties), std::move(production)); + + return ret; + })(node); + return ret; + })(root); + lock_national_foci(); + + return ret; +} diff --git a/src/openvic-simulation/politics/NationalFocus.hpp b/src/openvic-simulation/politics/NationalFocus.hpp new file mode 100644 index 0000000..7c5e40a --- /dev/null +++ b/src/openvic-simulation/politics/NationalFocus.hpp @@ -0,0 +1,76 @@ +#pragma once + +#include "openvic-simulation/types/IdentifierRegistry.hpp" +#include "openvic-simulation/utility/Getters.hpp" +#include "openvic-simulation/Modifier.hpp" +#include "openvic-simulation/pop/Pop.hpp" +#include "openvic-simulation/politics/Ideology.hpp" +#include "openvic-simulation/economy/Good.hpp" + +#include + +namespace OpenVic { + struct NationalFocusManager; + + struct NationalFocusGroup : HasIdentifier { + friend struct NationalFocusManager; + + private: + NationalFocusGroup(std::string_view new_identifier); + }; + + struct NationalFocus : HasIdentifier { + friend struct NationalFocusManager; + + public: + using pop_promotion_map_t = std::map; + using party_loyalty_map_t = std::map; + using production_map_t = std::map; + + private: + uint8_t PROPERTY(icon); + NationalFocusGroup const& PROPERTY(group); + ModifierValue PROPERTY(modifiers); + pop_promotion_map_t PROPERTY(encouraged_promotion); + party_loyalty_map_t PROPERTY(encouraged_loyalty); + production_map_t PROPERTY(encouraged_production); + + NationalFocus( + std::string_view new_identifier, + uint8_t new_icon, + NationalFocusGroup const& new_group, + ModifierValue&& new_modifiers, + pop_promotion_map_t&& new_encouraged_promotion, + party_loyalty_map_t&& new_encouraged_loyalty, + production_map_t&& new_encouraged_production + ); + + public: + NationalFocus(NationalFocus&&) = default; + }; + + struct NationalFocusManager { + private: + IdentifierRegistry national_focus_groups; + IdentifierRegistry national_foci; + + public: + NationalFocusManager(); + + inline bool add_national_focus_group(std::string_view identifier); + IDENTIFIER_REGISTRY_ACCESSORS(national_focus_group) + + inline bool add_national_focus( + std::string_view identifier, + uint8_t icon, + NationalFocusGroup const& group, + ModifierValue&& modifiers, + NationalFocus::pop_promotion_map_t&& encouraged_promotion, + NationalFocus::party_loyalty_map_t&& encouraged_loyalty, + NationalFocus::production_map_t&& encouraged_production + ); + IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(national_focus, national_foci); + + bool load_national_foci_file(PopManager const& pop_manager, IdeologyManager const& ideology_manager, GoodManager const& good_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root); + }; +} // namespace OpenVic diff --git a/src/openvic-simulation/politics/PoliticsManager.hpp b/src/openvic-simulation/politics/PoliticsManager.hpp index 1423cf7..b30d1c0 100644 --- a/src/openvic-simulation/politics/PoliticsManager.hpp +++ b/src/openvic-simulation/politics/PoliticsManager.hpp @@ -4,6 +4,7 @@ #include "openvic-simulation/politics/Ideology.hpp" #include "openvic-simulation/politics/Issue.hpp" #include "openvic-simulation/politics/NationalValue.hpp" +#include "openvic-simulation/politics/NationalFocus.hpp" namespace OpenVic { struct PoliticsManager { @@ -12,15 +13,20 @@ namespace OpenVic { IdeologyManager ideology_manager; IssueManager issue_manager; NationalValueManager national_value_manager; + NationalFocusManager national_focus_manager; public: REF_GETTERS(government_type_manager) REF_GETTERS(ideology_manager) REF_GETTERS(issue_manager) REF_GETTERS(national_value_manager) + REF_GETTERS(national_focus_manager) inline bool load_government_types_file(ast::NodeCPtr root) { return government_type_manager.load_government_types_file(ideology_manager, root); } + inline bool load_national_foci_file(PopManager const& pop_manager, GoodManager const& good_manager, ModifierManager const& modifier_manager, ast::NodeCPtr root) { + return national_focus_manager.load_national_foci_file(pop_manager, ideology_manager, good_manager, modifier_manager, root); + } }; } -- cgit v1.2.3-56-ga3b1