aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/modifier/StaticModifierCache.cpp
diff options
context:
space:
mode:
author wvpm <24685035+wvpm@users.noreply.github.com>2024-10-21 14:09:40 +0200
committer wvpm <24685035+wvpm@users.noreply.github.com>2024-10-26 16:49:08 +0200
commit3daebe5db14949f55be2c50220323138260dbaea (patch)
tree46039d0eb5d630cf000e94aed584aebaaa8f3f9b /src/openvic-simulation/modifier/StaticModifierCache.cpp
parentc88cf59997529cbca008f9a2b629822de9deaa2a (diff)
contextual modifier parsingcontextual_modifier_parsing
Diffstat (limited to 'src/openvic-simulation/modifier/StaticModifierCache.cpp')
-rw-r--r--src/openvic-simulation/modifier/StaticModifierCache.cpp238
1 files changed, 147 insertions, 91 deletions
diff --git a/src/openvic-simulation/modifier/StaticModifierCache.cpp b/src/openvic-simulation/modifier/StaticModifierCache.cpp
index b03d827..953b49b 100644
--- a/src/openvic-simulation/modifier/StaticModifierCache.cpp
+++ b/src/openvic-simulation/modifier/StaticModifierCache.cpp
@@ -1,115 +1,171 @@
#include "StaticModifierCache.hpp"
+#include <string_view>
+
+#include "openvic-simulation/dataloader/NodeTools.hpp"
+#include "openvic-simulation/modifier/Modifier.hpp"
#include "openvic-simulation/modifier/ModifierManager.hpp"
using namespace OpenVic;
+using namespace OpenVic::NodeTools;
+using enum Modifier::modifier_type_t;
StaticModifierCache::StaticModifierCache()
: // Country modifiers
- very_easy_player { nullptr },
- easy_player { nullptr },
- hard_player { nullptr },
- very_hard_player { nullptr },
- very_easy_ai { nullptr },
- easy_ai { nullptr },
- hard_ai { nullptr },
- very_hard_ai { nullptr },
- base_modifier { nullptr },
- war { nullptr },
- peace { nullptr },
- disarming { nullptr },
- war_exhaustion { nullptr },
- infamy { nullptr },
- debt_default_to { nullptr },
- bad_debter { nullptr },
- great_power { nullptr },
- secondary_power { nullptr },
- civilised { nullptr },
- uncivilised { nullptr },
- literacy { nullptr },
- plurality { nullptr },
- generalised_debt_default { nullptr },
- total_occupation { nullptr },
- total_blockaded { nullptr },
+ very_easy_player { "very_easy_player", {}, STATIC },
+ easy_player { "easy_player", {}, STATIC },
+ hard_player { "hard_player", {}, STATIC },
+ very_hard_player { "very_hard_player", {}, STATIC },
+ very_easy_ai { "very_easy_ai", {}, STATIC },
+ easy_ai { "easy_ai", {}, STATIC },
+ hard_ai { "hard_ai", {}, STATIC },
+ very_hard_ai { "very_hard_ai", {}, STATIC },
+ base_modifier { "base_values", {}, STATIC },
+ war { "war", {}, STATIC },
+ peace { "peace", {}, STATIC },
+ disarming { "disarming", {}, STATIC },
+ war_exhaustion { "war_exhaustion", {}, STATIC },
+ infamy { "badboy", {}, STATIC },
+ debt_default_to { "debt_default_to", {}, STATIC },
+ great_power { "great_power", {}, STATIC },
+ secondary_power { "second_power", {}, STATIC },
+ civilised { "civ_nation", {}, STATIC },
+ uncivilised { "unciv_nation", {}, STATIC },
+ literacy { "average_literacy", {}, STATIC },
+ plurality { "plurality", {}, STATIC },
+ total_occupation { "total_occupation", {}, STATIC },
+ total_blockaded { "total_blockaded", {}, STATIC },
in_bankruptcy { nullptr },
+ bad_debtor { nullptr },
+ generalised_debt_default { nullptr },
// Province modifiers
- overseas { nullptr },
- coastal { nullptr },
- non_coastal { nullptr },
- coastal_sea { nullptr },
- sea_zone { nullptr },
- land_province { nullptr },
- blockaded { nullptr },
- no_adjacent_controlled { nullptr },
- core { nullptr },
- has_siege { nullptr },
- occupied { nullptr },
- nationalism { nullptr },
- infrastructure { nullptr } {}
-
-bool StaticModifierCache::load_static_modifiers(ModifierManager& modifier_manager) {
+ overseas { "overseas", {}, STATIC },
+ coastal { "coastal", {}, STATIC },
+ non_coastal { "non_coastal", {}, STATIC },
+ coastal_sea { "coastal_sea", {}, STATIC },
+ sea_zone { "sea_zone", {}, STATIC },
+ land_province { "land_province", {}, STATIC },
+ blockaded { "blockaded", {}, STATIC },
+ no_adjacent_controlled { "no_adjacent_controlled", {}, STATIC },
+ core { "core", {}, STATIC },
+ has_siege { "has_siege", {}, STATIC },
+ occupied { "occupied", {}, STATIC },
+ nationalism { "nationalism", {}, STATIC },
+ infrastructure { "infrastructure", {}, STATIC } {}
+
+bool StaticModifierCache::load_static_modifiers(ModifierManager& modifier_manager, const ast::NodeCPtr root) {
bool ret = true;
+ key_map_t key_map {};
- const auto set_static_modifier = [&modifier_manager, &ret](
- Modifier const*& modifier, std::string_view name, fixed_point_t multiplier = 1
+ const auto set_static_country_modifier = [&key_map, &modifier_manager, &ret](
+ Modifier& modifier
) -> void {
- Modifier* mutable_modifier = modifier_manager.static_modifiers.get_item_by_identifier(name);
+ ret &= add_key_map_entry(
+ key_map, modifier.get_identifier(), ONE_EXACTLY,
+ expect_dictionary(modifier_manager.expect_base_country_modifier(modifier))
+ );
+ };
+
+ const auto set_country_event_modifier = [&key_map, &modifier_manager, &ret](
+ const std::string_view identifier, const IconModifier::icon_t icon
+ ) -> void {
+ ret &= add_key_map_entry(
+ key_map, identifier, ONE_EXACTLY,
+ [&modifier_manager, identifier, icon](const ast::NodeCPtr value) -> bool {
+ if (modifier_manager.get_event_modifier_by_identifier(identifier) != nullptr) {
+ return true; //an event modifier overrides a static modifier with the same identifier.
+ }
- if (mutable_modifier != nullptr) {
- if (multiplier != fixed_point_t::_1()) {
- *mutable_modifier *= multiplier;
+ ModifierValue modifier_value {};
+ bool has_parsed_modifier = expect_dictionary(modifier_manager.expect_base_country_modifier(modifier_value))(value);
+ has_parsed_modifier &= modifier_manager.add_event_modifier(identifier, std::move(modifier_value), icon, STATIC);
+ return has_parsed_modifier;
}
+ );
+
+ };
- modifier = mutable_modifier;
- } else {
- Logger::error("Failed to set static modifier: ", name);
- ret = false;
- }
+ const auto set_static_province_modifier = [&key_map, &modifier_manager, &ret](
+ Modifier& modifier
+ ) -> void {
+ ret &= add_key_map_entry(
+ key_map, modifier.get_identifier(), ONE_EXACTLY,
+ expect_dictionary(modifier_manager.expect_base_province_modifier(modifier))
+ );
};
// Country modifiers
- set_static_modifier(very_easy_player, "very_easy_player");
- set_static_modifier(easy_player, "easy_player");
- set_static_modifier(hard_player, "hard_player");
- set_static_modifier(very_hard_player, "very_hard_player");
- set_static_modifier(very_easy_ai, "very_easy_ai");
- set_static_modifier(easy_ai, "easy_ai");
- set_static_modifier(hard_ai, "hard_ai");
- set_static_modifier(very_hard_ai, "very_hard_ai");
-
- set_static_modifier(base_modifier, "base_values");
- set_static_modifier(war, "war");
- set_static_modifier(peace, "peace");
- set_static_modifier(disarming, "disarming");
- set_static_modifier(war_exhaustion, "war_exhaustion");
- set_static_modifier(infamy, "badboy");
- set_static_modifier(debt_default_to, "debt_default_to");
- set_static_modifier(bad_debter, "bad_debter");
- set_static_modifier(great_power, "great_power");
- set_static_modifier(secondary_power, "second_power");
- set_static_modifier(civilised, "civ_nation");
- set_static_modifier(uncivilised, "unciv_nation");
- set_static_modifier(literacy, "average_literacy");
- set_static_modifier(plurality, "plurality");
- set_static_modifier(generalised_debt_default, "generalised_debt_default");
- set_static_modifier(total_occupation, "total_occupation", 100);
- set_static_modifier(total_blockaded, "total_blockaded");
- set_static_modifier(in_bankruptcy, "in_bankrupcy");
+ set_static_country_modifier(very_easy_player);
+ set_static_country_modifier(easy_player);
+ set_static_country_modifier(hard_player);
+ set_static_country_modifier(very_hard_player);
+ set_static_country_modifier(very_easy_ai);
+ set_static_country_modifier(easy_ai);
+ set_static_country_modifier(hard_ai);
+ set_static_country_modifier(very_hard_ai);
+
+ ret &= add_key_map_entry(
+ key_map, base_modifier.get_identifier(), ONE_EXACTLY,
+ expect_dictionary_keys_and_default(
+ modifier_manager.expect_base_country_modifier(base_modifier),
+ "supply_limit", ZERO_OR_ONE, [this, &modifier_manager](const ast::NodeCPtr value) -> bool {
+ return modifier_manager._add_modifier_cb(
+ base_modifier,
+ modifier_manager.get_modifier_effect_cache().get_supply_limit_global_base(),
+ value
+ );
+ }
+ )
+ );
+
+ set_static_country_modifier(war);
+ set_static_country_modifier(peace);
+ set_static_country_modifier(disarming);
+ set_static_country_modifier(war_exhaustion);
+ set_static_country_modifier(infamy);
+ set_static_country_modifier(debt_default_to);
+ set_static_country_modifier(great_power);
+ set_static_country_modifier(secondary_power);
+ set_static_country_modifier(civilised);
+ set_static_country_modifier(uncivilised);
+ set_static_country_modifier(literacy);
+ set_static_country_modifier(plurality);
+ set_static_country_modifier(total_occupation);
+ set_static_country_modifier(total_blockaded);
+
+ // Country Event modifiers
+ static constexpr IconModifier::icon_t default_icon = 0;
+ static constexpr std::string_view bad_debtor_id = "bad_debter"; //paradox typo
+ static constexpr std::string_view in_bankruptcy_id = "in_bankrupcy"; //paradox typo
+ static constexpr std::string_view generalised_debt_default_id = "generalised_debt_default";
+ set_country_event_modifier(bad_debtor_id, default_icon);
+ set_country_event_modifier(in_bankruptcy_id, default_icon);
+ set_country_event_modifier(generalised_debt_default_id, default_icon);
// Province modifiers
- set_static_modifier(overseas, "overseas");
- set_static_modifier(coastal, "coastal");
- set_static_modifier(non_coastal, "non_coastal");
- set_static_modifier(coastal_sea, "coastal_sea");
- set_static_modifier(sea_zone, "sea_zone");
- set_static_modifier(land_province, "land_province");
- set_static_modifier(blockaded, "blockaded");
- set_static_modifier(no_adjacent_controlled, "no_adjacent_controlled");
- set_static_modifier(core, "core");
- set_static_modifier(has_siege, "has_siege");
- set_static_modifier(occupied, "occupied");
- set_static_modifier(nationalism, "nationalism");
- set_static_modifier(infrastructure, "infrastructure");
+ set_static_province_modifier(overseas);
+ set_static_province_modifier(coastal);
+ set_static_province_modifier(non_coastal);
+ set_static_province_modifier(coastal_sea);
+ set_static_province_modifier(sea_zone);
+ set_static_province_modifier(land_province);
+ set_static_province_modifier(blockaded);
+ set_static_province_modifier(no_adjacent_controlled);
+ set_static_province_modifier(core);
+ set_static_province_modifier(has_siege);
+ set_static_province_modifier(occupied);
+ set_static_province_modifier(nationalism);
+ set_static_province_modifier(infrastructure);
+
+
+ ret &= expect_dictionary_key_map_and_default(key_map, key_value_invalid_callback)(root);
+
+ if (ret) {
+ bad_debtor = modifier_manager.get_event_modifier_by_identifier(bad_debtor_id);
+ in_bankruptcy = modifier_manager.get_event_modifier_by_identifier(in_bankruptcy_id);
+ generalised_debt_default = modifier_manager.get_event_modifier_by_identifier(generalised_debt_default_id);
+ total_occupation *= 100;
+ }
return ret;
}