aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/misc')
-rw-r--r--src/openvic-simulation/misc/Decision.cpp43
-rw-r--r--src/openvic-simulation/misc/Decision.hpp26
-rw-r--r--src/openvic-simulation/misc/Event.cpp65
-rw-r--r--src/openvic-simulation/misc/Event.hpp27
-rw-r--r--src/openvic-simulation/misc/Modifier.cpp29
-rw-r--r--src/openvic-simulation/misc/Modifier.hpp15
6 files changed, 159 insertions, 46 deletions
diff --git a/src/openvic-simulation/misc/Decision.cpp b/src/openvic-simulation/misc/Decision.cpp
index d50a16a..36eb871 100644
--- a/src/openvic-simulation/misc/Decision.cpp
+++ b/src/openvic-simulation/misc/Decision.cpp
@@ -6,14 +6,26 @@ using namespace OpenVic::NodeTools;
Decision::Decision(
std::string_view new_identifier, bool new_alert, bool new_news, std::string_view new_news_title,
std::string_view new_news_desc_long, std::string_view new_news_desc_medium, std::string_view new_news_desc_short,
- std::string_view new_picture
+ std::string_view new_picture, ConditionScript&& new_potential, ConditionScript&& new_allow,
+ ConditionalWeight&& new_ai_will_do, EffectScript&& new_effect
) : HasIdentifier { new_identifier }, alert { new_alert }, news { new_news }, news_title { new_news_title },
news_desc_long { new_news_desc_long }, news_desc_medium { new_news_desc_medium },
- news_desc_short { new_news_desc_short }, picture { new_picture } {}
+ news_desc_short { new_news_desc_short }, picture { new_picture }, potential { std::move(new_potential) },
+ allow { std::move(new_allow) }, ai_will_do { std::move(new_ai_will_do) }, effect { std::move(new_effect) } {}
+
+bool Decision::parse_scripts(GameManager& game_manager) {
+ bool ret = true;
+ ret &= potential.parse_script(false, game_manager);
+ ret &= allow.parse_script(false, game_manager);
+ ret &= ai_will_do.parse_scripts(game_manager);
+ ret &= effect.parse_script(false, game_manager);
+ return ret;
+}
bool DecisionManager::add_decision(
std::string_view identifier, bool alert, bool news, std::string_view news_title, std::string_view news_desc_long,
- std::string_view news_desc_medium, std::string_view news_desc_short, std::string_view picture
+ std::string_view news_desc_medium, std::string_view news_desc_short, std::string_view picture, ConditionScript&& potential,
+ ConditionScript&& allow, ConditionalWeight&& ai_will_do, EffectScript&& effect
) {
if (identifier.empty()) {
Logger::error("Invalid decision identifier - empty!");
@@ -33,7 +45,8 @@ bool DecisionManager::add_decision(
}
return decisions.add_item({
- identifier, alert, news, news_title, news_desc_long, news_desc_medium, news_desc_short, picture
+ identifier, alert, news, news_title, news_desc_long, news_desc_medium, news_desc_short, picture, std::move(potential),
+ std::move(allow), std::move(ai_will_do), std::move(effect)
}, duplicate_warning_callback);
}
@@ -43,6 +56,9 @@ bool DecisionManager::load_decision_file(ast::NodeCPtr root) {
[this](std::string_view identifier, ast::NodeCPtr node) -> bool {
bool alert = true, news = false;
std::string_view news_title, news_desc_long, news_desc_medium, news_desc_short, picture;
+ ConditionScript potential, allow;
+ ConditionalWeight ai_will_do;
+ EffectScript effect;
bool ret = expect_dictionary_keys(
"alert", ZERO_OR_ONE, expect_bool(assign_variable_callback(alert)),
"news", ZERO_OR_ONE, expect_bool(assign_variable_callback(news)),
@@ -51,16 +67,25 @@ bool DecisionManager::load_decision_file(ast::NodeCPtr root) {
"news_desc_medium", ZERO_OR_ONE, expect_string(assign_variable_callback(news_desc_medium)),
"news_desc_short", ZERO_OR_ONE, expect_string(assign_variable_callback(news_desc_short)),
"picture", ZERO_OR_ONE, expect_identifier_or_string(assign_variable_callback(picture)),
- "potential", ONE_EXACTLY, success_callback, //TODO
- "allow", ONE_EXACTLY, success_callback, //TODO
- "effect", ONE_EXACTLY, success_callback, //TODO
- "ai_will_do", ZERO_OR_ONE, success_callback //TODO
+ "potential", ONE_EXACTLY, potential.expect_script(),
+ "allow", ONE_EXACTLY, allow.expect_script(),
+ "effect", ONE_EXACTLY, effect.expect_script(),
+ "ai_will_do", ZERO_OR_ONE, ai_will_do.expect_conditional_weight(ConditionalWeight::FACTOR)
)(node);
ret &= add_decision(
- identifier, alert, news, news_title, news_desc_long, news_desc_medium, news_desc_short, picture
+ identifier, alert, news, news_title, news_desc_long, news_desc_medium, news_desc_short, picture,
+ std::move(potential), std::move(allow), std::move(ai_will_do), std::move(effect)
);
return ret;
}
)
)(root);
}
+
+bool DecisionManager::parse_scripts(GameManager& game_manager) {
+ bool ret = true;
+ for (Decision& decision : decisions.get_items()) {
+ ret &= decision.parse_scripts(game_manager);
+ }
+ return ret;
+}
diff --git a/src/openvic-simulation/misc/Decision.hpp b/src/openvic-simulation/misc/Decision.hpp
index 32141fe..593b6e4 100644
--- a/src/openvic-simulation/misc/Decision.hpp
+++ b/src/openvic-simulation/misc/Decision.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "openvic-simulation/scripts/ConditionalWeight.hpp"
+#include "openvic-simulation/scripts/EffectScript.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
namespace OpenVic {
@@ -11,18 +13,25 @@ namespace OpenVic {
private:
const bool PROPERTY_CUSTOM_PREFIX(alert, has);
const bool PROPERTY_CUSTOM_PREFIX(news, is);
- const std::string PROPERTY(news_title);
- const std::string PROPERTY(news_desc_long);
- const std::string PROPERTY(news_desc_medium);
- const std::string PROPERTY(news_desc_short);
- const std::string PROPERTY(picture);
+ std::string PROPERTY(news_title);
+ std::string PROPERTY(news_desc_long);
+ std::string PROPERTY(news_desc_medium);
+ std::string PROPERTY(news_desc_short);
+ std::string PROPERTY(picture);
+ ConditionScript PROPERTY(potential);
+ ConditionScript PROPERTY(allow);
+ ConditionalWeight PROPERTY(ai_will_do);
+ EffectScript PROPERTY(effect);
Decision(
std::string_view new_identifier, bool new_alert, bool new_news, std::string_view new_news_title,
std::string_view new_news_desc_long, std::string_view new_news_desc_medium, std::string_view new_news_desc_short,
- std::string_view new_picture
+ std::string_view new_picture, ConditionScript&& new_potential, ConditionScript&& new_allow,
+ ConditionalWeight&& new_ai_will_do, EffectScript&& new_effect
);
+ bool parse_scripts(GameManager& game_manager);
+
public:
Decision(Decision&&) = default;
};
@@ -34,9 +43,12 @@ namespace OpenVic {
public:
bool add_decision(
std::string_view identifier, bool alert, bool news, std::string_view news_title, std::string_view news_desc_long,
- std::string_view news_desc_medium, std::string_view news_desc_short, std::string_view picture
+ std::string_view news_desc_medium, std::string_view news_desc_short, std::string_view picture,
+ ConditionScript&& potential, ConditionScript&& allow, ConditionalWeight&& ai_will_do, EffectScript&& effect
);
bool load_decision_file(ast::NodeCPtr root);
+
+ bool parse_scripts(GameManager& game_manager);
};
}
diff --git a/src/openvic-simulation/misc/Event.cpp b/src/openvic-simulation/misc/Event.cpp
index 4507de4..fb97d63 100644
--- a/src/openvic-simulation/misc/Event.cpp
+++ b/src/openvic-simulation/misc/Event.cpp
@@ -6,19 +6,41 @@
using namespace OpenVic;
using namespace OpenVic::NodeTools;
-Event::EventOption::EventOption(std::string_view new_title) : title { new_title } {}
+Event::EventOption::EventOption(std::string_view new_title, EffectScript&& new_effect, ConditionalWeight&& new_ai_chance)
+ : title { new_title }, effect { std::move(new_effect) }, ai_chance { std::move(new_ai_chance) } {}
+
+bool Event::EventOption::parse_scripts(GameManager& game_manager) {
+ bool ret = true;
+ ret &= effect.parse_script(false, game_manager);
+ ret &= ai_chance.parse_scripts(game_manager);
+ return ret;
+}
Event::Event(
std::string_view new_identifier, std::string_view new_title, std::string_view new_description,
std::string_view new_image, event_type_t new_type, bool new_triggered_only, bool new_major, bool new_fire_only_once,
bool new_allows_multiple_instances, bool new_news, std::string_view new_news_title, std::string_view new_news_desc_long,
std::string_view new_news_desc_medium, std::string_view new_news_desc_short, bool new_election,
- IssueGroup const* new_election_issue_group, std::vector<EventOption>&& new_options
+ IssueGroup const* new_election_issue_group, ConditionScript&& new_trigger, ConditionalWeight&& new_mean_time_to_happen,
+ EffectScript&& new_immediate, std::vector<EventOption>&& new_options
) : HasIdentifier { new_identifier }, title { new_title }, description { new_description }, image { new_image },
type { new_type }, triggered_only { new_triggered_only }, major { new_major }, fire_only_once { new_fire_only_once },
allows_multiple_instances { new_allows_multiple_instances }, news { new_news }, news_title { new_news_title },
news_desc_long { new_news_desc_long }, news_desc_medium { new_news_desc_medium }, news_desc_short { new_news_desc_short },
- election { new_election }, election_issue_group { new_election_issue_group }, options { std::move(new_options) } {}
+ election { new_election }, election_issue_group { new_election_issue_group }, trigger { std::move(new_trigger) },
+ mean_time_to_happen { std::move(new_mean_time_to_happen) }, immediate { std::move(new_immediate) },
+ options { std::move(new_options) } {}
+
+bool Event::parse_scripts(GameManager& game_manager) {
+ bool ret = true;
+ ret &= trigger.parse_script(true, game_manager);
+ ret &= mean_time_to_happen.parse_scripts(game_manager);
+ ret &= immediate.parse_script(true, game_manager);
+ for (EventOption& option : options) {
+ ret &= option.parse_scripts(game_manager);
+ }
+ return ret;
+}
OnAction::OnAction(std::string_view new_identifier, weight_map_t&& new_weighted_events)
: HasIdentifier { new_identifier }, weighted_events { std::move(new_weighted_events) } {}
@@ -27,8 +49,8 @@ bool EventManager::register_event(
std::string_view identifier, std::string_view title, std::string_view description, std::string_view image,
Event::event_type_t type, bool triggered_only, bool major, bool fire_only_once, bool allows_multiple_instances, bool news,
std::string_view news_title, std::string_view news_desc_long, std::string_view news_desc_medium,
- std::string_view news_desc_short, bool election, IssueGroup const* election_issue_group,
- std::vector<Event::EventOption>&& options
+ std::string_view news_desc_short, bool election, IssueGroup const* election_issue_group, ConditionScript&& trigger,
+ ConditionalWeight&& mean_time_to_happen, EffectScript&& immediate, std::vector<Event::EventOption>&& options
) {
if (identifier.empty()) {
Logger::error("Invalid event ID - empty!");
@@ -68,7 +90,8 @@ bool EventManager::register_event(
return events.add_item({
identifier, title, description, image, type, triggered_only, major, fire_only_once, allows_multiple_instances, news,
- news_title, news_desc_long, news_desc_medium, news_desc_short, election, election_issue_group, std::move(options)
+ news_title, news_desc_long, news_desc_medium, news_desc_short, election, election_issue_group, std::move(trigger),
+ std::move(mean_time_to_happen), std::move(immediate), std::move(options)
}, duplicate_warning_callback);
}
@@ -90,6 +113,9 @@ bool EventManager::load_event_file(IssueManager const& issue_manager, ast::NodeC
bool triggered_only = false, major = false, fire_only_once = false, allows_multiple_instances = false,
news = false, election = false;
IssueGroup const* election_issue_group = nullptr;
+ ConditionScript trigger;
+ ConditionalWeight mean_time_to_happen;
+ EffectScript immediate;
std::vector<Event::EventOption> options;
if (key == "country_event") {
@@ -120,25 +146,28 @@ bool EventManager::load_event_file(IssueManager const& issue_manager, ast::NodeC
issue_manager.expect_issue_group_identifier(assign_variable_callback_pointer(election_issue_group)),
"option", ONE_OR_MORE, [&options](ast::NodeCPtr node) -> bool {
std::string_view title;
+ EffectScript effect;
+ ConditionalWeight ai_chance;
bool ret = expect_dictionary_keys_and_default(
key_value_success_callback,
- "name", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(title))
+ "name", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(title)),
+ "ai_chance", ZERO_OR_ONE, ai_chance.expect_conditional_weight(ConditionalWeight::FACTOR)
)(node);
- // TODO: option effects
+ ret &= effect.expect_script()(node);
- options.push_back({ title });
+ options.push_back({ title, std::move(effect), std::move(ai_chance) });
return ret;
},
- "trigger", ZERO_OR_ONE, success_callback, // TODO - trigger condition
- "mean_time_to_happen", ZERO_OR_ONE, success_callback, // TODO - MTTH weighted conditions
- "immediate", ZERO_OR_MORE, success_callback // TODO - immediate effects
+ "trigger", ZERO_OR_ONE, trigger.expect_script(),
+ "mean_time_to_happen", ZERO_OR_ONE, mean_time_to_happen.expect_conditional_weight(ConditionalWeight::MONTHS),
+ "immediate", ZERO_OR_MORE, immediate.expect_script()
)(value);
ret &= register_event(
identifier, title, description, image, type, triggered_only, major, fire_only_once, allows_multiple_instances,
news, news_title, news_desc_long, news_desc_medium, news_desc_short, election, election_issue_group,
- std::move(options)
+ std::move(trigger), std::move(mean_time_to_happen), std::move(immediate), std::move(options)
);
return ret;
}
@@ -176,4 +205,12 @@ bool EventManager::load_on_action_file(ast::NodeCPtr root) {
})(root);
on_actions.lock();
return ret;
-} \ No newline at end of file
+}
+
+bool EventManager::parse_scripts(GameManager& game_manager) {
+ bool ret = true;
+ for (Event& event : events.get_items()) {
+ ret &= event.parse_scripts(game_manager);
+ }
+ return ret;
+}
diff --git a/src/openvic-simulation/misc/Event.hpp b/src/openvic-simulation/misc/Event.hpp
index c41ef3f..37f9270 100644
--- a/src/openvic-simulation/misc/Event.hpp
+++ b/src/openvic-simulation/misc/Event.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "openvic-simulation/scripts/ConditionalWeight.hpp"
+#include "openvic-simulation/scripts/EffectScript.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
@@ -15,12 +17,16 @@ namespace OpenVic {
struct EventOption {
friend struct EventManager;
+ friend struct Event;
private:
std::string PROPERTY(title);
- // TODO: option effects
+ EffectScript PROPERTY(effect);
+ ConditionalWeight PROPERTY(ai_chance);
- EventOption(std::string_view new_title);
+ EventOption(std::string_view new_title, EffectScript&& new_effect, ConditionalWeight&& new_ai_chance);
+
+ bool parse_scripts(GameManager& game_manager);
public:
EventOption(EventOption const&) = delete;
@@ -48,18 +54,23 @@ namespace OpenVic {
bool PROPERTY_CUSTOM_PREFIX(election, is);
IssueGroup const* PROPERTY(election_issue_group);
- std::vector<EventOption> PROPERTY(options);
+ ConditionScript PROPERTY(trigger);
+ ConditionalWeight PROPERTY(mean_time_to_happen);
+ EffectScript PROPERTY(immediate);
- // TODO: triggers, MTTH, immediate effects
+ std::vector<EventOption> PROPERTY(options);
Event(
std::string_view new_identifier, std::string_view new_title, std::string_view new_description,
std::string_view new_image, event_type_t new_type, bool new_triggered_only, bool new_major,
bool new_fire_only_once, bool new_allows_multiple_instances, bool new_news, std::string_view new_news_title,
std::string_view new_news_desc_long, std::string_view new_news_desc_medium, std::string_view new_news_desc_short,
- bool new_election, IssueGroup const* new_election_issue_group, std::vector<EventOption>&& new_options
+ bool new_election, IssueGroup const* new_election_issue_group, ConditionScript&& new_trigger,
+ ConditionalWeight&& new_mean_time_to_happen, EffectScript&& new_immediate, std::vector<EventOption>&& new_options
);
+ bool parse_scripts(GameManager& game_manager);
+
public:
Event(Event&&) = default;
};
@@ -88,13 +99,15 @@ namespace OpenVic {
std::string_view identifier, std::string_view title, std::string_view description, std::string_view image,
Event::event_type_t type, bool triggered_only, bool major, bool fire_only_once, bool allows_multiple_instances,
bool news, std::string_view news_title, std::string_view news_desc_long, std::string_view news_desc_medium,
- std::string_view news_desc_short, bool election, IssueGroup const* election_issue_group,
- std::vector<Event::EventOption>&& options
+ std::string_view news_desc_short, bool election, IssueGroup const* election_issue_group, ConditionScript&& trigger,
+ ConditionalWeight&& mean_time_to_happen, EffectScript&& immediate, std::vector<Event::EventOption>&& options
);
bool add_on_action(std::string_view identifier, OnAction::weight_map_t&& new_weighted_events);
bool load_event_file(IssueManager const& issue_manager, ast::NodeCPtr root);
bool load_on_action_file(ast::NodeCPtr root);
+
+ bool parse_scripts(GameManager& game_manager);
};
} // namespace OpenVic
diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp
index 94d38e0..bbc8f59 100644
--- a/src/openvic-simulation/misc/Modifier.cpp
+++ b/src/openvic-simulation/misc/Modifier.cpp
@@ -82,8 +82,13 @@ ModifierValue ModifierValue::operator-(ModifierValue const& right) const {
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 } {}
-TriggeredModifier::TriggeredModifier(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon)
- : Modifier { new_identifier, std::move(new_values), 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) } {}
+
+bool TriggeredModifier::parse_scripts(GameManager const& game_manager) {
+ return trigger.parse_script(false, game_manager);
+}
ModifierInstance::ModifierInstance(Modifier const& modifier, Date expiry_date)
: modifier { modifier }, expiry_date { expiry_date } {}
@@ -319,12 +324,14 @@ bool ModifierManager::load_static_modifiers(ast::NodeCPtr root) {
return ret;
}
-bool ModifierManager::add_triggered_modifier(std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon) {
+bool ModifierManager::add_triggered_modifier(
+ std::string_view identifier, ModifierValue&& values, Modifier::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 }, duplicate_warning_callback);
+ return triggered_modifiers.add_item({ identifier, std::move(values), icon, std::move(trigger) }, duplicate_warning_callback);
}
bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) {
@@ -333,12 +340,14 @@ bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) {
[this](std::string_view key, ast::NodeCPtr value) -> bool {
ModifierValue modifier_value;
Modifier::icon_t icon = 0;
+ ConditionScript trigger;
+
bool ret = expect_modifier_value_and_keys(
move_variable_callback(modifier_value),
"icon", ZERO_OR_ONE, expect_uint(assign_variable_callback(icon)),
- "trigger", ONE_EXACTLY, success_callback // TODO - load condition
+ "trigger", ONE_EXACTLY, trigger.expect_script()
)(value);
- ret &= add_triggered_modifier(key, std::move(modifier_value), icon);
+ ret &= add_triggered_modifier(key, std::move(modifier_value), icon, std::move(trigger));
return ret;
}
)(root);
@@ -346,6 +355,14 @@ bool ModifierManager::load_triggered_modifiers(ast::NodeCPtr root) {
return ret;
}
+bool ModifierManager::parse_scripts(GameManager const& game_manager) {
+ bool ret = true;
+ for (TriggeredModifier& modifier : triggered_modifiers.get_items()) {
+ ret &= modifier.parse_scripts(game_manager);
+ }
+ return ret;
+}
+
key_value_callback_t ModifierManager::_modifier_effect_callback(
ModifierValue& modifier, key_value_callback_t default_callback, ModifierEffectValidator auto effect_validator
) const {
diff --git a/src/openvic-simulation/misc/Modifier.hpp b/src/openvic-simulation/misc/Modifier.hpp
index f3a2499..033cc47 100644
--- a/src/openvic-simulation/misc/Modifier.hpp
+++ b/src/openvic-simulation/misc/Modifier.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "openvic-simulation/scripts/ConditionScript.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
namespace OpenVic {
@@ -83,10 +84,14 @@ namespace OpenVic {
friend struct ModifierManager;
private:
- // TODO - trigger condition
+ ConditionScript trigger;
protected:
- TriggeredModifier(std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon);
+ TriggeredModifier(
+ std::string_view new_identifier, ModifierValue&& new_values, icon_t new_icon, ConditionScript&& new_trigger
+ );
+
+ bool parse_scripts(GameManager const& game_manager);
public:
TriggeredModifier(TriggeredModifier&&) = default;
@@ -139,9 +144,13 @@ namespace OpenVic {
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);
+ bool add_triggered_modifier(
+ std::string_view identifier, ModifierValue&& values, Modifier::icon_t icon, ConditionScript&& trigger
+ );
bool load_triggered_modifiers(ast::NodeCPtr root);
+ bool parse_scripts(GameManager const& game_manager);
+
NodeTools::node_callback_t expect_validated_modifier_value_and_default(
NodeTools::callback_t<ModifierValue&&> modifier_callback, NodeTools::key_value_callback_t default_callback,
ModifierEffectValidator auto effect_validator