aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/modifier
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-09-21 09:03:51 +0200
committer GitHub <noreply@github.com>2024-09-21 09:03:51 +0200
commite35ff8ed703b0b6a5496a21a29e0b274c6a36874 (patch)
tree68fca0f77f6b20f3e1fe98d32a5a79311cfd3edc /src/openvic-simulation/modifier
parent118570dc7cf9ae9daf324c2aaba5a5d86fb2c330 (diff)
parent3fcdd0c7fce2de4cbe14a0cc3d6fb4c2731b93d9 (diff)
Merge pull request #205 from OpenVicProject/modifier-typesfix-modifiers
Modifier types
Diffstat (limited to 'src/openvic-simulation/modifier')
-rw-r--r--src/openvic-simulation/modifier/Modifier.cpp45
-rw-r--r--src/openvic-simulation/modifier/Modifier.hpp33
2 files changed, 60 insertions, 18 deletions
diff --git a/src/openvic-simulation/modifier/Modifier.cpp b/src/openvic-simulation/modifier/Modifier.cpp
index 6d0f42a..b26b8dd 100644
--- a/src/openvic-simulation/modifier/Modifier.cpp
+++ b/src/openvic-simulation/modifier/Modifier.cpp
@@ -129,12 +129,17 @@ void ModifierValue::multiply_add(ModifierValue const& other, fixed_point_t multi
}
}
-Modifier::Modifier(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon)
- : HasIdentifier { new_identifier }, ModifierValue { std::move(new_values) }, icon { new_icon } {}
+Modifier::Modifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type)
+ : HasIdentifier { new_identifier }, ModifierValue { std::move(new_values) }, type { new_type } {}
+
+IconModifier::IconModifier(
+ std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type, icon_t new_icon
+) : Modifier { new_identifier, std::move(new_values), new_type }, icon { new_icon } {}
TriggeredModifier::TriggeredModifier(
- std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, ConditionScript&& new_trigger
-) : Modifier { new_identifier, std::move(new_values), new_icon }, trigger { std::move(new_trigger) } {}
+ std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type, icon_t new_icon,
+ ConditionScript&& new_trigger
+) : IconModifier { new_identifier, std::move(new_values), new_type, new_icon }, trigger { std::move(new_trigger) } {}
bool TriggeredModifier::parse_scripts(DefinitionManager const& definition_manager) {
return trigger.parse_script(false, definition_manager);
@@ -404,12 +409,15 @@ std::string ModifierManager::get_flat_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) {
+bool ModifierManager::add_event_modifier(std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon) {
if (identifier.empty()) {
Logger::error("Invalid event modifier effect identifier - empty!");
return false;
}
- return event_modifiers.add_item({ identifier, std::move(values), icon }, duplicate_warning_callback);
+
+ return event_modifiers.add_item(
+ { identifier, std::move(values), Modifier::modifier_type_t::EVENT, icon }, duplicate_warning_callback
+ );
}
bool ModifierManager::load_event_modifiers(ast::NodeCPtr root) {
@@ -417,7 +425,7 @@ bool ModifierManager::load_event_modifiers(ast::NodeCPtr root) {
event_modifiers,
[this](std::string_view key, ast::NodeCPtr value) -> bool {
ModifierValue modifier_value;
- Modifier::icon_t icon = 0;
+ IconModifier::icon_t icon = 0;
bool ret = expect_modifier_value_and_keys(
move_variable_callback(modifier_value),
"icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon))
@@ -426,7 +434,9 @@ bool ModifierManager::load_event_modifiers(ast::NodeCPtr root) {
return ret;
}
)(root);
+
lock_event_modifiers();
+
return ret;
}
@@ -435,7 +445,10 @@ bool ModifierManager::add_static_modifier(std::string_view identifier, ModifierV
Logger::error("Invalid static modifier effect identifier - empty!");
return false;
}
- return static_modifiers.add_item({ identifier, std::move(values), 0 }, duplicate_warning_callback);
+
+ return static_modifiers.add_item(
+ { identifier, std::move(values), Modifier::modifier_type_t::STATIC }, duplicate_warning_callback
+ );
}
bool ModifierManager::load_static_modifiers(ast::NodeCPtr root) {
@@ -448,18 +461,24 @@ bool ModifierManager::load_static_modifiers(ast::NodeCPtr root) {
return ret;
}
)(root);
+
lock_static_modifiers();
+
return ret;
}
bool ModifierManager::add_triggered_modifier(
- std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger
+ std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger
) {
if (identifier.empty()) {
Logger::error("Invalid triggered modifier effect identifier - empty!");
return false;
}
- return triggered_modifiers.add_item({ identifier, std::move(values), icon, std::move(trigger) }, duplicate_warning_callback);
+
+ return triggered_modifiers.add_item(
+ { identifier, std::move(values), Modifier::modifier_type_t::TRIGGERED, icon, std::move(trigger) },
+ duplicate_warning_callback
+ );
}
bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) {
@@ -467,7 +486,7 @@ bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) {
triggered_modifiers,
[this](std::string_view key, ast::NodeCPtr value) -> bool {
ModifierValue modifier_value;
- Modifier::icon_t icon = 0;
+ IconModifier::icon_t icon = 0;
ConditionScript trigger { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
bool ret = expect_modifier_value_and_keys(
@@ -479,15 +498,19 @@ bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) {
return ret;
}
)(root);
+
lock_triggered_modifiers();
+
return ret;
}
bool ModifierManager::parse_scripts(DefinitionManager const& definition_manager) {
bool ret = true;
+
for (TriggeredModifier& modifier : triggered_modifiers.get_items()) {
ret &= modifier.parse_scripts(definition_manager);
}
+
return ret;
}
diff --git a/src/openvic-simulation/modifier/Modifier.hpp b/src/openvic-simulation/modifier/Modifier.hpp
index f525d6a..80d2db6 100644
--- a/src/openvic-simulation/modifier/Modifier.hpp
+++ b/src/openvic-simulation/modifier/Modifier.hpp
@@ -79,6 +79,24 @@ namespace OpenVic {
struct Modifier : HasIdentifier, ModifierValue {
friend struct ModifierManager;
+ enum struct modifier_type_t : uint8_t {
+ EVENT, STATIC, TRIGGERED, CRIME, TERRAIN, CLIMATE, CONTINENT, BUILDING, LEADER, NATIONAL_VALUE, NATIONAL_FOCUS,
+ ISSUE, REFORM, TECHNOLOGY, INVENTION, TECH_SCHOOL
+ };
+
+ private:
+ const modifier_type_t PROPERTY(type);
+
+ protected:
+ Modifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type);
+
+ public:
+ Modifier(Modifier&&) = default;
+ };
+
+ struct IconModifier : Modifier {
+ friend struct ModifierManager;
+
using icon_t = uint8_t;
private:
@@ -86,13 +104,13 @@ namespace OpenVic {
const icon_t PROPERTY(icon);
protected:
- Modifier(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon = 0);
+ IconModifier(std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type, icon_t new_icon);
public:
- Modifier(Modifier&&) = default;
+ IconModifier(IconModifier&&) = default;
};
- struct TriggeredModifier : Modifier {
+ struct TriggeredModifier : IconModifier {
friend struct ModifierManager;
private:
@@ -100,7 +118,8 @@ namespace OpenVic {
protected:
TriggeredModifier(
- std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, ConditionScript&& new_trigger
+ std::string_view new_identifier, ModifierValue&& new_values, modifier_type_t new_type, icon_t new_icon,
+ ConditionScript&& new_trigger
);
bool parse_scripts(DefinitionManager const& definition_manager);
@@ -131,7 +150,7 @@ namespace OpenVic {
CaseInsensitiveIdentifierRegistry<ModifierEffect, RegistryStorageInfoDeque> IDENTIFIER_REGISTRY(modifier_effect);
case_insensitive_string_set_t complex_modifiers;
- IdentifierRegistry<Modifier> IDENTIFIER_REGISTRY(event_modifier);
+ IdentifierRegistry<IconModifier> IDENTIFIER_REGISTRY(event_modifier);
IdentifierRegistry<Modifier> IDENTIFIER_REGISTRY(static_modifier);
IdentifierRegistry<TriggeredModifier> IDENTIFIER_REGISTRY(triggered_modifier);
@@ -155,14 +174,14 @@ namespace OpenVic {
bool setup_modifier_effects();
- bool add_event_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon);
+ bool add_event_modifier(std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon);
bool load_event_modifiers(ast::NodeCPtr root);
bool add_static_modifier(std::string_view identifier, ModifierValue&& values);
bool load_static_modifiers(ast::NodeCPtr root);
bool add_triggered_modifier(
- std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger
+ std::string_view identifier, ModifierValue&& values, IconModifier::icon_t icon, ConditionScript&& trigger
);
bool load_triggered_modifiers(ast::NodeCPtr root);