aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author wvpm <24685035+wvpm@users.noreply.github.com>2024-01-12 21:53:46 +0100
committer GitHub <noreply@github.com>2024-01-12 21:53:46 +0100
commit7b5a960ee9fce4241f83e5217bcf8f43af99f330 (patch)
tree60101bdfe575a25c9ef10cdcc52691140795405d
parente79d3e0416e62883c697225b090d03abafc7bb30 (diff)
parent177a0051eceb657ad838048d9532e306e18ce4e5 (diff)
Merge pull request #126 from OpenVicProject/improve_modifiers
Case insensitive modifiers & added more
-rw-r--r--src/openvic-simulation/economy/Good.cpp4
-rw-r--r--src/openvic-simulation/military/Unit.cpp44
-rw-r--r--src/openvic-simulation/misc/Modifier.cpp81
-rw-r--r--src/openvic-simulation/misc/Modifier.hpp9
-rw-r--r--src/openvic-simulation/politics/Rebel.cpp14
-rw-r--r--src/openvic-simulation/pop/Pop.cpp8
6 files changed, 92 insertions, 68 deletions
diff --git a/src/openvic-simulation/economy/Good.cpp b/src/openvic-simulation/economy/Good.cpp
index 435d860..d674a68 100644
--- a/src/openvic-simulation/economy/Good.cpp
+++ b/src/openvic-simulation/economy/Good.cpp
@@ -93,11 +93,11 @@ bool GoodManager::load_goods_file(ast::NodeCPtr root) {
bool GoodManager::generate_modifiers(ModifierManager& modifier_manager) const {
bool ret = true;
- const auto good_modifier = [this, &modifier_manager, &ret](std::string_view name, bool positive_good) -> void {
+ const auto good_modifier = [this, &modifier_manager, &ret](std::string_view name, bool is_positive_good) -> void {
ret &= modifier_manager.register_complex_modifier(name);
for (Good const& good : get_goods()) {
ret &= modifier_manager.add_modifier_effect(
- StringUtils::append_string_views(name, "_", good.get_identifier()), positive_good
+ ModifierManager::get_flat_identifier(name, good.get_identifier()), is_positive_good
);
}
};
diff --git a/src/openvic-simulation/military/Unit.cpp b/src/openvic-simulation/military/Unit.cpp
index db04335..9981c86 100644
--- a/src/openvic-simulation/military/Unit.cpp
+++ b/src/openvic-simulation/military/Unit.cpp
@@ -203,11 +203,11 @@ bool UnitManager::generate_modifiers(ModifierManager& modifier_manager) const {
bool ret = true;
const auto generate_stat_modifiers = [&modifier_manager, &ret](std::string_view identifier, Unit::type_t type) -> void {
-
- const auto stat_modifier = [&modifier_manager, &ret, &identifier](std::string_view suffix, bool positive_good,
- ModifierEffect::format_t format) -> void {
+ const auto stat_modifier = [&modifier_manager, &ret, &identifier](
+ std::string_view suffix, bool is_positive_good, ModifierEffect::format_t format
+ ) -> void {
ret &= modifier_manager.add_modifier_effect(
- StringUtils::append_string_views(identifier, suffix), positive_good, format
+ ModifierManager::get_flat_identifier(identifier, suffix), is_positive_good, format
);
};
@@ -215,29 +215,29 @@ bool UnitManager::generate_modifiers(ModifierManager& modifier_manager) const {
ret &= modifier_manager.register_complex_modifier(identifier);
- stat_modifier("_attack", true, RAW_DECIMAL);
- stat_modifier("_defence", true, RAW_DECIMAL);
- stat_modifier("_default_organisation", true, RAW_DECIMAL);
- stat_modifier("_maximum_speed", true, RAW_DECIMAL);
- stat_modifier("_build_time", false, INT);
- stat_modifier("_supply_consumption", false, PROPORTION_DECIMAL);
+ stat_modifier("attack", true, RAW_DECIMAL);
+ stat_modifier("defence", true, RAW_DECIMAL);
+ stat_modifier("default_organisation", true, RAW_DECIMAL);
+ stat_modifier("maximum_speed", true, RAW_DECIMAL);
+ stat_modifier("build_time", false, INT);
+ stat_modifier("supply_consumption", false, PROPORTION_DECIMAL);
switch (type) {
case Unit::type_t::LAND:
- stat_modifier("_reconnaissance", true, RAW_DECIMAL);
- stat_modifier("_discipline", true, PROPORTION_DECIMAL);
- stat_modifier("_support", true, PROPORTION_DECIMAL);
- stat_modifier("_maneuver", true, INT);
- stat_modifier("_siege", true, RAW_DECIMAL);
+ stat_modifier("reconnaissance", true, RAW_DECIMAL);
+ stat_modifier("discipline", true, PROPORTION_DECIMAL);
+ stat_modifier("support", true, PROPORTION_DECIMAL);
+ stat_modifier("maneuver", true, INT);
+ stat_modifier("siege", true, RAW_DECIMAL);
break;
case Unit::type_t::NAVAL:
- stat_modifier("_colonial_points", true, INT);
- stat_modifier("_supply_consumption_score", false, INT);
- stat_modifier("_hull", true, RAW_DECIMAL);
- stat_modifier("_gun_power", true, RAW_DECIMAL);
- stat_modifier("_fire_range", true, RAW_DECIMAL);
- stat_modifier("_evasion", true, PROPORTION_DECIMAL);
- stat_modifier("_torpedo_attack", true, RAW_DECIMAL);
+ stat_modifier("colonial_points", true, INT);
+ stat_modifier("supply_consumption_score", false, INT);
+ stat_modifier("hull", true, RAW_DECIMAL);
+ stat_modifier("gun_power", true, RAW_DECIMAL);
+ stat_modifier("fire_range", true, RAW_DECIMAL);
+ stat_modifier("evasion", true, PROPORTION_DECIMAL);
+ stat_modifier("torpedo_attack", true, RAW_DECIMAL);
break;
}
};
diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp
index 2d95f0d..0844681 100644
--- a/src/openvic-simulation/misc/Modifier.cpp
+++ b/src/openvic-simulation/misc/Modifier.cpp
@@ -107,16 +107,27 @@ bool ModifierManager::setup_modifier_effects() {
bool ret = true;
using enum ModifierEffect::format_t;
+ /* Tech/inventions only*/
+ ret &= add_modifier_effect("cb_creation_speed", true);
+ ret &= add_modifier_effect("combat_width", false);
+ ret &= add_modifier_effect("plurality", true, PERCENTAGE_DECIMAL);
+ ret &= add_modifier_effect("pop_growth", true);
+ ret &= add_modifier_effect("regular_experience_level", true, RAW_DECIMAL);
+ ret &= add_modifier_effect("reinforce_rate", true);
+ ret &= add_modifier_effect("seperatism", false); // paradox typo
+ ret &= add_modifier_effect("shared_prestige", true, RAW_DECIMAL);
+ ret &= add_modifier_effect("tax_eff", true);
/* Country Modifier Effects */
ret &= add_modifier_effect("administrative_efficiency", true);
ret &= add_modifier_effect("administrative_efficiency_modifier", true);
+ ret &= add_modifier_effect("administrative_multiplier", true);
ret &= add_modifier_effect("artisan_input", false);
ret &= add_modifier_effect("artisan_output", true);
ret &= add_modifier_effect("artisan_throughput", true);
ret &= add_modifier_effect("badboy", false, RAW_DECIMAL);
- ret &= add_modifier_effect("cb_creation_speed", true); //seemingly works the same way as cb_generation_speed_modifier
ret &= add_modifier_effect("cb_generation_speed_modifier", true);
+ ret &= add_modifier_effect("civilization_progress_modifier", true);
ret &= add_modifier_effect("colonial_life_rating", false, INT);
ret &= add_modifier_effect("colonial_migration", true);
ret &= add_modifier_effect("colonial_points", true, INT);
@@ -137,7 +148,6 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("global_assimilation_rate", true);
ret &= add_modifier_effect("global_immigrant_attract", true);
ret &= add_modifier_effect("global_pop_consciousness_modifier", false, RAW_DECIMAL);
- ret &= add_modifier_effect("global_pop_growth", true);
ret &= add_modifier_effect("global_pop_militancy_modifier", false, RAW_DECIMAL);
ret &= add_modifier_effect("global_population_growth", true);
ret &= add_modifier_effect("goods_demand", false);
@@ -167,12 +177,10 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("min_social_spending", true);
ret &= add_modifier_effect("min_tariff", true);
ret &= add_modifier_effect("min_tax", true);
+ ret &= add_modifier_effect("minimum_wage", true);
ret &= add_modifier_effect("mobilisation_economy_impact", false);
- ret &= add_modifier_effect("mobilisation_impact", false);
ret &= add_modifier_effect("mobilisation_size", true);
- ret &= add_modifier_effect("mobilization_economy_impact", false);
ret &= add_modifier_effect("mobilization_impact", false);
- ret &= add_modifier_effect("mobilization_size", true);
ret &= add_modifier_effect("naval_attack_modifier", true);
ret &= add_modifier_effect("naval_attrition", false);
ret &= add_modifier_effect("naval_defense_modifier", true);
@@ -183,50 +191,36 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("org_regain", true);
ret &= add_modifier_effect("pension_level", true);
ret &= add_modifier_effect("permanent_prestige", true, RAW_DECIMAL);
- ret &= add_modifier_effect("plurality", true, PERCENTAGE_DECIMAL);
ret &= add_modifier_effect("political_reform_desire", false);
- ret &= add_modifier_effect("pop_growth", true);
+ ret &= add_modifier_effect("poor_savings_modifier", true);
ret &= add_modifier_effect("prestige", true, RAW_DECIMAL);
- ret &= add_modifier_effect("regular_experience_level", true, RAW_DECIMAL);
- ret &= add_modifier_effect("reinforce_rate", true);
+ ret &= add_modifier_effect("reinforce_speed", true);
ret &= add_modifier_effect("research_points", true, RAW_DECIMAL);
ret &= add_modifier_effect("research_points_modifier", true);
ret &= add_modifier_effect("research_points_on_conquer", true);
ret &= add_modifier_effect("rgo_output", true);
- ret &= add_modifier_effect("RGO_output", true);
- ret &= add_modifier_effect("rgo_size", true);
- ret &= add_modifier_effect("RGO_size", true);
ret &= add_modifier_effect("rgo_throughput", true);
- ret &= add_modifier_effect("RGO_throughput", true);
ret &= add_modifier_effect("ruling_party_support", true);
- ret &= add_modifier_effect("shared_prestige", true, RAW_DECIMAL);
ret &= add_modifier_effect("social_reform_desire", false);
ret &= add_modifier_effect("soldier_to_pop_loss", true);
- ret &= add_modifier_effect("seperatism", false); // paradox typo
ret &= add_modifier_effect("supply_consumption", false);
ret &= add_modifier_effect("supply_range", true);
ret &= add_modifier_effect("suppression_points_modifier", true);
ret &= add_modifier_effect("tariff_efficiency_modifier", true);
- ret &= add_modifier_effect("tax_eff", true);
ret &= add_modifier_effect("tax_efficiency", true);
+ ret &= add_modifier_effect("unemployment_benefit", true);
ret &= add_modifier_effect("unit_recruitment_time", false);
- ret &= add_modifier_effect("unit_start_experience", true, RAW_DECIMAL);
ret &= add_modifier_effect("war_exhaustion", false);
- ret &= add_modifier_effect("civilization_progress_modifier", true);
- ret &= add_modifier_effect("administrative_multiplier", true);
- ret &= add_modifier_effect("unemployment_benefit", true);
- ret &= add_modifier_effect("minimum_wage", true);
- ret &= add_modifier_effect("war_exhaustion_effect", false);
- ret &= add_modifier_effect("reinforce_speed", true);
+
+ /* State only*/
+ ret &= add_modifier_effect("flashpoint_tension", true);
+ ret &= add_modifier_effect("railroads", true); // capitalist likelihood for railroads vs factories
/* Province Modifier Effects */
ret &= add_modifier_effect("assimilation_rate", true);
ret &= add_modifier_effect("boost_strongest_party", 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);
- ret &= add_modifier_effect("farm_RGO_size", true);
- ret &= add_modifier_effect("flashpoint_tension", false);
ret &= add_modifier_effect("immigrant_attract", true);
ret &= add_modifier_effect("immigrant_push", false);
ret &= add_modifier_effect("life_rating", true);
@@ -238,28 +232,22 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("local_factory_throughput", true);
ret &= add_modifier_effect("local_repair", true);
ret &= add_modifier_effect("local_rgo_output", true);
- ret &= add_modifier_effect("local_RGO_output", true);
ret &= add_modifier_effect("local_rgo_throughput", true);
- ret &= add_modifier_effect("local_RGO_throughput", true);
ret &= add_modifier_effect("local_ruling_party_support", true);
ret &= add_modifier_effect("local_ship_build", false);
ret &= add_modifier_effect("max_attrition", false, RAW_DECIMAL);
ret &= add_modifier_effect("mine_rgo_eff", true);
- ret &= add_modifier_effect("mine_RGO_eff", true);
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("number_of_voters", false);
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("railroads", true); // capitalist likelihood for railroads vs factories
ret &= add_modifier_effect("supply_limit", true, RAW_DECIMAL);
/* Military Modifier Effects */
ret &= add_modifier_effect("attack", true, INT);
ret &= add_modifier_effect("attrition", false, RAW_DECIMAL);
- ret &= add_modifier_effect("combat_width", false);
ret &= add_modifier_effect("defence", true, INT);
ret &= add_modifier_effect("experience", true);
ret &= add_modifier_effect("morale", true);
@@ -280,6 +268,12 @@ bool ModifierManager::register_complex_modifier(std::string_view identifier) {
}
}
+std::string ModifierManager::get_flat_identifier(
+ const std::string_view complex_modifier_identifier, const std::string_view variant_identifier
+) {
+ return StringUtils::append_string_views(complex_modifier_identifier, " ", variant_identifier);
+}
+
bool ModifierManager::add_event_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon) {
if (identifier.empty()) {
Logger::error("Invalid event modifier effect identifier - empty!");
@@ -370,8 +364,21 @@ bool ModifierManager::parse_scripts(GameManager const& game_manager) {
key_value_callback_t ModifierManager::_modifier_effect_callback(
ModifierValue& modifier, key_value_callback_t default_callback, ModifierEffectValidator auto effect_validator
) const {
- const auto add_modifier_cb = [this, &modifier, effect_validator](ModifierEffect const* effect, ast::NodeCPtr value) -> bool {
+ const auto add_modifier_cb = [this, &modifier,
+ effect_validator](ModifierEffect const* effect, ast::NodeCPtr value) -> bool {
if (effect_validator(*effect)) {
+
+ static const case_insensitive_string_set_t no_effect_modifiers {
+ "boost_strongest_party", "poor_savings_modifier", "poor_life_needs",
+ "poor_everyday_needs", "poor_luxury_needs", "middle_life_needs",
+ "middle_everyday_needs", "middle_luxury_needs", "rich_life_needs",
+ "rich_everyday_needs", "rich_luxury_needs", "local_artisan_input",
+ "local_artisan_throughput", "local_artisan_output", "artisan_input",
+ "artisan_throughput", "artisan_output", "import_cost"
+ };
+ if (no_effect_modifiers.contains(effect->get_identifier())) {
+ Logger::warning("This modifier does nothing: ", effect->get_identifier());
+ }
return expect_fixed_point(map_callback(modifier.values, effect))(value);
} else {
Logger::error("Failed to validate modifier effect: ", effect->get_identifier());
@@ -379,8 +386,9 @@ key_value_callback_t ModifierManager::_modifier_effect_callback(
}
};
- const auto add_flattened_modifier_cb = [this, add_modifier_cb](std::string_view prefix, std::string_view key, ast::NodeCPtr value) -> bool {
- const std::string flat_identifier = StringUtils::append_string_views(prefix, "_", key);
+ const auto add_flattened_modifier_cb =
+ [this, add_modifier_cb](std::string_view prefix, std::string_view key, ast::NodeCPtr value) -> bool {
+ const std::string flat_identifier = get_flat_identifier(prefix, key);
ModifierEffect const* effect = get_modifier_effect_by_identifier(flat_identifier);
if (effect != nullptr) {
return add_modifier_cb(effect, value);
@@ -407,6 +415,9 @@ key_value_callback_t ModifierManager::_modifier_effect_callback(
} else {
return expect_dictionary(std::bind_front(add_flattened_modifier_cb, key))(value);
}
+ } else if (key == "war_exhaustion_effect") {
+ Logger::warning("war_exhaustion_effect does nothing (vanilla issues have it).");
+ return true;
} else {
return default_callback(key, value);
}
diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp
index 033cc47..83efe9b 100644
--- a/src/openvic-simulation/misc/Modifier.hpp
+++ b/src/openvic-simulation/misc/Modifier.hpp
@@ -3,6 +3,9 @@
#include "openvic-simulation/scripts/ConditionScript.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
+#include "dataloader/NodeTools.hpp"
+
+
namespace OpenVic {
struct ModifierManager;
@@ -115,8 +118,8 @@ namespace OpenVic {
* so instead we use an IdentifierInstanceRegistry (using std::unique_ptr's under the hood).
*/
private:
- IdentifierInstanceRegistry<ModifierEffect> IDENTIFIER_REGISTRY(modifier_effect);
- string_set_t complex_modifiers;
+ CaseInsensitiveIdentifierInstanceRegistry<ModifierEffect> IDENTIFIER_REGISTRY(modifier_effect);
+ case_insensitive_string_set_t complex_modifiers;
IdentifierRegistry<Modifier> IDENTIFIER_REGISTRY(event_modifier);
IdentifierRegistry<Modifier> IDENTIFIER_REGISTRY(static_modifier);
@@ -135,6 +138,8 @@ namespace OpenVic {
);
bool register_complex_modifier(std::string_view identifier);
+ static std::string
+ get_flat_identifier(const std::string_view complex_modifier_identifier, const std::string_view variant_identifier);
bool setup_modifier_effects();
diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp
index f86bb51..4bf5ecb 100644
--- a/src/openvic-simulation/politics/Rebel.cpp
+++ b/src/openvic-simulation/politics/Rebel.cpp
@@ -1,5 +1,10 @@
#include "Rebel.hpp"
+#include <string_view>
+
+#include "openvic-simulation/misc/Modifier.hpp"
+
+
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -172,14 +177,15 @@ bool RebelManager::load_rebels_file(
bool RebelManager::generate_modifiers(ModifierManager& modifier_manager) const {
bool ret = true;
+ static constexpr std::string_view identifier = "rebel_org_gain";
+ static constexpr bool is_positive_good = false;
+ ret &= modifier_manager.register_complex_modifier(identifier);
- ret &= modifier_manager.register_complex_modifier("rebel_org_gain");
-
- ret &= modifier_manager.add_modifier_effect("rebel_org_gain_all", false);
+ ret &= modifier_manager.add_modifier_effect(ModifierManager::get_flat_identifier(identifier, "all"), is_positive_good);
for (RebelType const& rebel_type : get_rebel_types()) {
ret &= modifier_manager.add_modifier_effect(
- StringUtils::append_string_views("rebel_org_gain_", rebel_type.get_identifier()), false
+ ModifierManager::get_flat_identifier(identifier, rebel_type.get_identifier()), is_positive_good
);
}
return ret;
diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp
index d15bd2e..5afcb18 100644
--- a/src/openvic-simulation/pop/Pop.cpp
+++ b/src/openvic-simulation/pop/Pop.cpp
@@ -319,15 +319,17 @@ bool PopManager::load_pop_into_vector(
bool PopManager::generate_modifiers(ModifierManager& modifier_manager) const {
bool ret = true;
+
for (Strata const& strata : get_stratas()) {
- const auto strata_modifier = [&modifier_manager, &ret, &strata](std::string_view suffix, bool positive_good) -> void {
+ const auto strata_modifier = [&modifier_manager, &ret, &strata](
+ std::string_view suffix, bool is_positive_good
+ ) -> void {
ret &= modifier_manager.add_modifier_effect(
- StringUtils::append_string_views(strata.get_identifier(), suffix), positive_good
+ StringUtils::append_string_views(strata.get_identifier(), suffix), is_positive_good
);
};
strata_modifier("_income_modifier", true);
- strata_modifier("_savings_modifier", true);
strata_modifier("_vote", true);
strata_modifier("_life_needs", false);