aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/scripts/ConditionalWeight.cpp
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/scripts/ConditionalWeight.cpp
parentb06b25bd2910818029ebbf1cd3014ef20a64e25b (diff)
feat: condition loading and parsing
Co-authored-by: Hop311 <Hop3114@gmail.com>
Diffstat (limited to 'src/openvic-simulation/scripts/ConditionalWeight.cpp')
-rw-r--r--src/openvic-simulation/scripts/ConditionalWeight.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/openvic-simulation/scripts/ConditionalWeight.cpp b/src/openvic-simulation/scripts/ConditionalWeight.cpp
index 17bbbd6..e5bb7d0 100644
--- a/src/openvic-simulation/scripts/ConditionalWeight.cpp
+++ b/src/openvic-simulation/scripts/ConditionalWeight.cpp
@@ -3,9 +3,12 @@
using namespace OpenVic;
using namespace OpenVic::NodeTools;
+ConditionalWeight::ConditionalWeight(scope_t new_initial_scope, scope_t new_this_scope, scope_t new_from_scope)
+ : initial_scope { new_initial_scope }, this_scope { new_this_scope }, from_scope { new_from_scope } {}
+
template<typename T>
-static NodeCallback auto expect_modifier(std::vector<T>& items) {
- return [&items](ast::NodeCPtr node) -> bool {
+static NodeCallback auto expect_modifier(std::vector<T>& items, scope_t initial_scope, scope_t this_scope, scope_t from_scope) {
+ return [&items, initial_scope, this_scope, from_scope](ast::NodeCPtr node) -> bool {
fixed_point_t weight = 0;
bool successful = false;
bool ret = expect_key("factor", expect_fixed_point(assign_variable_callback(weight)), &successful)(node);
@@ -13,7 +16,7 @@ static NodeCallback auto expect_modifier(std::vector<T>& items) {
Logger::info("ConditionalWeight modifier missing factor key!");
return false;
}
- ConditionScript condition;
+ ConditionScript condition { initial_scope, this_scope, from_scope };
ret &= condition.expect_script()(node);
items.emplace_back(std::make_pair(weight, std::move(condition)));
return ret;
@@ -26,11 +29,11 @@ node_callback_t ConditionalWeight::expect_conditional_weight(base_key_t base_key
base_key_to_string(base_key), ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(base)),
"days", ZERO_OR_ONE, success_callback,
"years", ZERO_OR_ONE, success_callback,
- "modifier", ZERO_OR_MORE, expect_modifier(condition_weight_items),
+ "modifier", ZERO_OR_MORE, expect_modifier(condition_weight_items, initial_scope, this_scope, from_scope),
"group", ZERO_OR_MORE, [this](ast::NodeCPtr node) -> bool {
condition_weight_group_t items;
const bool ret = expect_dictionary_keys(
- "modifier", ONE_OR_MORE, expect_modifier(items)
+ "modifier", ONE_OR_MORE, expect_modifier(items, initial_scope, this_scope, from_scope)
)(node);
if (!items.empty()) {
condition_weight_items.emplace_back(std::move(items));