aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc
diff options
context:
space:
mode:
author zaaarf <me@zaaarf.foo>2024-01-07 23:47:39 +0100
committer zaaarf <me@zaaarf.foo>2024-01-07 23:47:39 +0100
commit6f07de81a6ca430c522527958e05440d67b04937 (patch)
tree6aae2959564bf93d85b2dc985cf5d4ea6c03fb78 /src/openvic-simulation/misc
parentb06b25bd2910818029ebbf1cd3014ef20a64e25b (diff)
feat: condition loading and parsing
Co-authored-by: Hop311 <Hop3114@gmail.com>
Diffstat (limited to 'src/openvic-simulation/misc')
-rw-r--r--src/openvic-simulation/misc/Decision.cpp5
-rw-r--r--src/openvic-simulation/misc/Event.cpp51
-rw-r--r--src/openvic-simulation/misc/Event.hpp4
-rw-r--r--src/openvic-simulation/misc/Modifier.cpp2
4 files changed, 41 insertions, 21 deletions
diff --git a/src/openvic-simulation/misc/Decision.cpp b/src/openvic-simulation/misc/Decision.cpp
index 36eb871..df78c80 100644
--- a/src/openvic-simulation/misc/Decision.cpp
+++ b/src/openvic-simulation/misc/Decision.cpp
@@ -56,8 +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;
+ ConditionScript potential { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
+ ConditionScript allow { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
+ ConditionalWeight ai_will_do { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
EffectScript effect;
bool ret = expect_dictionary_keys(
"alert", ZERO_OR_ONE, expect_bool(assign_variable_callback(alert)),
diff --git a/src/openvic-simulation/misc/Event.cpp b/src/openvic-simulation/misc/Event.cpp
index fb97d63..eb5f7da 100644
--- a/src/openvic-simulation/misc/Event.cpp
+++ b/src/openvic-simulation/misc/Event.cpp
@@ -6,8 +6,8 @@
using namespace OpenVic;
using namespace OpenVic::NodeTools;
-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) } {}
+Event::EventOption::EventOption(std::string_view new_name, EffectScript&& new_effect, ConditionalWeight&& new_ai_chance)
+ : name { new_name }, effect { std::move(new_effect) }, ai_chance { std::move(new_ai_chance) } {}
bool Event::EventOption::parse_scripts(GameManager& game_manager) {
bool ret = true;
@@ -86,6 +86,17 @@ bool EventManager::register_event(
}
}
+ if (options.empty()) {
+ Logger::error("Event with ID ", identifier, " has no options!");
+ return false;
+ } else {
+ for (Event::EventOption const& option : options) {
+ if (option.name.empty()) {
+ Logger::warning("Event with ID ", identifier, " has an option with no name!");
+ }
+ }
+ }
+
// TODO - error if is_triggered_only with triggers or MTTH defined
return events.add_item({
@@ -108,25 +119,29 @@ bool EventManager::load_event_file(IssueManager const& issue_manager, ast::NodeC
return expect_dictionary(
[this, &issue_manager](std::string_view key, ast::NodeCPtr value) -> bool {
Event::event_type_t type;
- std::string_view identifier, title, description, image, news_title, news_desc_long, news_desc_medium,
- news_desc_short;
- 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;
+ scope_t initial_scope;
if (key == "country_event") {
type = Event::event_type_t::COUNTRY;
+ initial_scope = scope_t::COUNTRY;
} else if (key == "province_event") {
type = Event::event_type_t::PROVINCE;
+ initial_scope = scope_t::PROVINCE;
} else {
Logger::error("Invalid event type: ", key);
return false;
}
+ std::string_view identifier, title, description, image, news_title, news_desc_long, news_desc_medium,
+ news_desc_short;
+ 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 { initial_scope, initial_scope, scope_t::NO_SCOPE };
+ ConditionalWeight mean_time_to_happen { initial_scope, initial_scope, scope_t::NO_SCOPE };
+ EffectScript immediate;
+ std::vector<Event::EventOption> options;
+
bool ret = expect_dictionary_keys(
"id", ONE_EXACTLY, expect_identifier(assign_variable_callback(identifier)),
"title", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(title)),
@@ -144,20 +159,24 @@ bool EventManager::load_event_file(IssueManager const& issue_manager, ast::NodeC
"election", ZERO_OR_ONE, expect_bool(assign_variable_callback(election)),
"issue_group", ZERO_OR_ONE,
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;
+ "option", ONE_OR_MORE, [&options, initial_scope](ast::NodeCPtr node) -> bool {
+ std::string_view name;
EffectScript effect;
- ConditionalWeight ai_chance;
+ ConditionalWeight ai_chance {
+ initial_scope,
+ initial_scope,
+ scope_t::COUNTRY | scope_t::PROVINCE
+ };
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(name)),
"ai_chance", ZERO_OR_ONE, ai_chance.expect_conditional_weight(ConditionalWeight::FACTOR)
)(node);
ret &= effect.expect_script()(node);
- options.push_back({ title, std::move(effect), std::move(ai_chance) });
+ options.push_back({ name, std::move(effect), std::move(ai_chance) });
return ret;
},
"trigger", ZERO_OR_ONE, trigger.expect_script(),
diff --git a/src/openvic-simulation/misc/Event.hpp b/src/openvic-simulation/misc/Event.hpp
index 37f9270..72e96fd 100644
--- a/src/openvic-simulation/misc/Event.hpp
+++ b/src/openvic-simulation/misc/Event.hpp
@@ -20,11 +20,11 @@ namespace OpenVic {
friend struct Event;
private:
- std::string PROPERTY(title);
+ std::string PROPERTY(name);
EffectScript PROPERTY(effect);
ConditionalWeight PROPERTY(ai_chance);
- EventOption(std::string_view new_title, EffectScript&& new_effect, ConditionalWeight&& new_ai_chance);
+ EventOption(std::string_view new_name, EffectScript&& new_effect, ConditionalWeight&& new_ai_chance);
bool parse_scripts(GameManager& game_manager);
diff --git a/src/openvic-simulation/misc/Modifier.cpp b/src/openvic-simulation/misc/Modifier.cpp
index ca4c950..c83fcf0 100644
--- a/src/openvic-simulation/misc/Modifier.cpp
+++ b/src/openvic-simulation/misc/Modifier.cpp
@@ -344,7 +344,7 @@ 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;
+ ConditionScript trigger { scope_t::COUNTRY, scope_t::COUNTRY, scope_t::NO_SCOPE };
bool ret = expect_modifier_value_and_keys(
move_variable_callback(modifier_value),