diff options
author | zaaarf <80046572+zaaarf@users.noreply.github.com> | 2024-01-07 23:51:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-07 23:51:06 +0100 |
commit | 79b8b73304753fedab822e6aa859fa15673f52cc (patch) | |
tree | cb25cfb89f8b06fc34f5c906e658a1b322120089 /src/openvic-simulation/misc | |
parent | 400469f08f10ffd044d9948c3f0db340c8a60db0 (diff) | |
parent | 6f07de81a6ca430c522527958e05440d67b04937 (diff) |
Merge pull request #111 from OpenVicProject/conditions-checking
Condition definition checking/loading
Diffstat (limited to 'src/openvic-simulation/misc')
-rw-r--r-- | src/openvic-simulation/misc/Decision.cpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Event.cpp | 51 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Event.hpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/misc/Modifier.cpp | 2 |
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), |