aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/misc/Decision.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-01-02 15:40:00 +0100
committer GitHub <noreply@github.com>2024-01-02 15:40:00 +0100
commit4c8da86c3bede8834f381fa63edaa3e140131f69 (patch)
treeff3433a63e91b9239eb7226e75054314182d6c1f /src/openvic-simulation/misc/Decision.cpp
parent66b80459c9d49895de902432bce11176b1270878 (diff)
parent5f64f983d0cead266a28791be42162c443fd2a75 (diff)
Merge pull request #112 from OpenVicProject/script-framework
Added framework for loading all Conditions and Effects
Diffstat (limited to 'src/openvic-simulation/misc/Decision.cpp')
-rw-r--r--src/openvic-simulation/misc/Decision.cpp43
1 files changed, 34 insertions, 9 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;
+}