aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-10-29 22:24:42 +0100
committer hop311 <hop3114@gmail.com>2023-10-30 19:51:35 +0100
commit61e5c971cd371950a3bd659799208d8143dddd4f (patch)
tree3d6e4cf31866df81f80143b9d6801d2dec3190e6
parent1603fbafb1c03830f38fefd87d8bd0d7d3f135a2 (diff)
ModifierEffects stored as instances
-rw-r--r--src/openvic-simulation/Modifier.cpp37
-rw-r--r--src/openvic-simulation/Modifier.hpp16
-rw-r--r--src/openvic-simulation/economy/Building.cpp15
-rw-r--r--src/openvic-simulation/economy/Building.hpp2
-rw-r--r--src/openvic-simulation/economy/EconomyManager.hpp2
5 files changed, 41 insertions, 31 deletions
diff --git a/src/openvic-simulation/Modifier.cpp b/src/openvic-simulation/Modifier.cpp
index a42cc66..605ffe4 100644
--- a/src/openvic-simulation/Modifier.cpp
+++ b/src/openvic-simulation/Modifier.cpp
@@ -107,7 +107,9 @@ bool ModifierManager::add_modifier_effect(std::string_view identifier, bool posi
Logger::error("Invalid modifier effect identifier - empty!");
return false;
}
- return modifier_effects.add_item({ identifier, positive_good, format });
+ return modifier_effects.add_item(std::unique_ptr<ModifierEffect> {
+ new ModifierEffect { identifier, positive_good, format }
+ });
}
bool ModifierManager::add_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon) {
@@ -150,8 +152,7 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("influence_modifier", true);
ret &= add_modifier_effect("issue_change_speed", true);
ret &= add_modifier_effect("land_organisation", true);
- // weird, land_unit_start_experience = 15 would give a 15% boost
- ret &= add_modifier_effect("land_unit_start_experience", true);
+ ret &= add_modifier_effect("land_unit_start_experience", true, PERCENTAGE_DECIMAL);
ret &= add_modifier_effect("leadership_modifier", true);
ret &= add_modifier_effect("loan_interest", false);
ret &= add_modifier_effect("max_loan_modifier", true);
@@ -172,8 +173,7 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("mobilisation_impact", false);
ret &= add_modifier_effect("mobilisation_size", true);
ret &= add_modifier_effect("naval_organisation", true);
- // weird, naval_unit_start_experience = 15 would give a 15% boost
- ret &= add_modifier_effect("naval_unit_start_experience", true);
+ ret &= add_modifier_effect("naval_unit_start_experience", true, PERCENTAGE_DECIMAL);
ret &= add_modifier_effect("non_accepted_pop_consciousness_modifier", false, RAW_DECIMAL);
ret &= add_modifier_effect("non_accepted_pop_militancy_modifier", false, RAW_DECIMAL);
ret &= add_modifier_effect("org_regain", true);
@@ -188,7 +188,9 @@ bool ModifierManager::setup_modifier_effects() {
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_throughput", true);
+ ret &= add_modifier_effect("RGO_throughput", true);
ret &= add_modifier_effect("rich_income_modifier", true);
ret &= add_modifier_effect("rich_life_needs", true);
ret &= add_modifier_effect("rich_everyday_needs", true);
@@ -197,9 +199,10 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("ruling_party_support", true);
ret &= add_modifier_effect("social_reform_desire", false);
ret &= add_modifier_effect("supply_consumption", false);
- // weird, naval_unit_start_experience = 15 would give a 15% boost
- ret &= add_modifier_effect("unit_start_experience", true);
+ ret &= add_modifier_effect("tax_efficiency", true);
+ ret &= add_modifier_effect("unit_start_experience", true, PERCENTAGE_DECIMAL);
ret &= add_modifier_effect("war_exhaustion", false);
+
// TODO: make technology group modifiers dynamic
ret &= add_modifier_effect("army_tech_research_bonus", true);
ret &= add_modifier_effect("commerce_tech_research_bonus", true);
@@ -224,9 +227,13 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("pop_militancy_modifier", false, RAW_DECIMAL);
ret &= add_modifier_effect("population_growth", true);
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("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("supply_limit", true, RAW_DECIMAL);
@@ -242,22 +249,6 @@ bool ModifierManager::setup_modifier_effects() {
ret &= add_modifier_effect("reliability", true, RAW_DECIMAL);
ret &= add_modifier_effect("speed", true);
- /* These should be added automatically for each Building loaded (or at least
- * non-factories), however currently we need modifier effects locked before we
- * can load buildings, so some architectural changes will be needed.
- */
- ret &= add_modifier_effect("max_fort", true, ModifierEffect::format_t::INT);
- ret &= add_modifier_effect("min_build_fort", true, ModifierEffect::format_t::INT);
- ret &= add_modifier_effect("max_naval_base", true, ModifierEffect::format_t::INT);
- ret &= add_modifier_effect("min_build_naval_base", true, ModifierEffect::format_t::INT);
- ret &= add_modifier_effect("max_railroad", true, ModifierEffect::format_t::INT);
- ret &= add_modifier_effect("min_build_railroad", true, ModifierEffect::format_t::INT);
- ret &= add_modifier_effect("max_university", true, ModifierEffect::format_t::INT);
- ret &= add_modifier_effect("min_build_university", true, ModifierEffect::format_t::INT);
- ret &= add_modifier_effect("max_bank", true, ModifierEffect::format_t::INT);
- ret &= add_modifier_effect("min_build_bank", true, ModifierEffect::format_t::INT);
-
- modifier_effects.lock();
return ret;
}
diff --git a/src/openvic-simulation/Modifier.hpp b/src/openvic-simulation/Modifier.hpp
index 2a98782..4af470e 100644
--- a/src/openvic-simulation/Modifier.hpp
+++ b/src/openvic-simulation/Modifier.hpp
@@ -8,7 +8,12 @@ namespace OpenVic {
struct ModifierEffect : HasIdentifier {
friend struct ModifierManager;
- enum class format_t { RAW_DECIMAL, PERCENTAGE_DECIMAL, INT };
+ enum class format_t {
+ PROPORTION_DECIMAL, /* An unscaled fraction/ratio, with 1 being "full"/"whole" */
+ PERCENTAGE_DECIMAL, /* A fraction/ratio scaled so that 100 is "full"/"whole" */
+ RAW_DECIMAL, /* A continuous quantity, e.g. attack strength */
+ INT /* A discrete quantity, e.g. building count limit */
+ };
private:
/* If true, positive values will be green and negative values will be red.
@@ -95,9 +100,12 @@ namespace OpenVic {
concept ModifierEffectValidator = std::predicate<Fn, ModifierEffect const&>;
struct ModifierManager {
-
+ /* Some ModifierEffects are generated mid-load, such as max/min count modifiers for each building, so
+ * we can't lock it until loading is over. This means we can't rely on locking for pointer stability,
+ * so instead we use an IdentifierInstanceRegistry (using std::unique_ptr's under the hood).
+ */
private:
- IdentifierRegistry<ModifierEffect> modifier_effects;
+ IdentifierInstanceRegistry<ModifierEffect> modifier_effects;
IdentifierRegistry<Modifier> modifiers;
/* effect_validator takes in ModifierEffect const& */
@@ -111,7 +119,7 @@ namespace OpenVic {
bool add_modifier_effect(
std::string_view identifier, bool province_good,
- ModifierEffect::format_t format = ModifierEffect::format_t::PERCENTAGE_DECIMAL
+ ModifierEffect::format_t format = ModifierEffect::format_t::PROPORTION_DECIMAL
);
IDENTIFIER_REGISTRY_ACCESSORS(modifier_effect)
diff --git a/src/openvic-simulation/economy/Building.cpp b/src/openvic-simulation/economy/Building.cpp
index a79741b..39b49ee 100644
--- a/src/openvic-simulation/economy/Building.cpp
+++ b/src/openvic-simulation/economy/Building.cpp
@@ -207,8 +207,8 @@ bool BuildingManager::add_building(std::string_view identifier, BuildingType con
}
bool BuildingManager::load_buildings_file(
- GoodManager const& good_manager, ProductionTypeManager const& production_type_manager,
- ModifierManager const& modifier_manager, ast::NodeCPtr root
+ GoodManager const& good_manager, ProductionTypeManager const& production_type_manager, ModifierManager& modifier_manager,
+ ast::NodeCPtr root
) {
bool ret = expect_dictionary_reserve_length(buildings, [this](std::string_view, ast::NodeCPtr value) -> bool {
return expect_key("type", expect_identifier(
@@ -281,6 +281,17 @@ bool BuildingManager::load_buildings_file(
)(root);
lock_buildings();
+ for (Building const& building : buildings.get_items()) {
+ std::string max_modifier_prefix = "max_";
+ std::string min_modifier_prefix = "min_build_";
+ modifier_manager.add_modifier_effect(
+ max_modifier_prefix.append(building.get_identifier()), true, ModifierEffect::format_t::INT
+ );
+ modifier_manager.add_modifier_effect(
+ min_modifier_prefix.append(building.get_identifier()), false, ModifierEffect::format_t::INT
+ );
+ }
+
return ret;
}
diff --git a/src/openvic-simulation/economy/Building.hpp b/src/openvic-simulation/economy/Building.hpp
index 89b6db8..0b94298 100644
--- a/src/openvic-simulation/economy/Building.hpp
+++ b/src/openvic-simulation/economy/Building.hpp
@@ -162,7 +162,7 @@ namespace OpenVic {
bool load_buildings_file(
GoodManager const& good_manager, ProductionTypeManager const& production_type_manager,
- ModifierManager const& modifier_manager, ast::NodeCPtr root
+ ModifierManager& modifier_manager, ast::NodeCPtr root
);
bool generate_province_buildings(Province& province) const;
diff --git a/src/openvic-simulation/economy/EconomyManager.hpp b/src/openvic-simulation/economy/EconomyManager.hpp
index b7d45c9..7445614 100644
--- a/src/openvic-simulation/economy/EconomyManager.hpp
+++ b/src/openvic-simulation/economy/EconomyManager.hpp
@@ -20,7 +20,7 @@ namespace OpenVic {
return production_type_manager.load_production_types_file(good_manager, pop_manager, root);
}
- inline bool load_buildings_file(ModifierManager const& modifier_manager, ast::NodeCPtr root) {
+ inline bool load_buildings_file(ModifierManager& modifier_manager, ast::NodeCPtr root) {
return building_manager.load_buildings_file(good_manager, production_type_manager, modifier_manager, root);
}
};