Conversation
There was a problem hiding this comment.
Pull request overview
Introduces an initial runtime evaluation path for scripted conditions by adding an evaluation Context and wiring ConditionNode evaluation through scope redirection/iteration, while also extending condition registration metadata (localisation keys + tooltip subject) via a builder API.
Changes:
- Add
Context(variant of scope pointers + THIS/FROM tracking) to support scope changes and iterators during condition evaluation. - Add
ConditionNode::evaluate()/evaluate_group()and delegate leaf evaluation to scope objects (CountryInstance/ProvinceInstance/State/Pop). - Extend
Conditionregistration with localisation/tooltip metadata and replace direct registration calls with aConditionBuilderfluent API.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/openvic-simulation/scripts/Context.hpp | Defines evaluation context, including scope pointer variant and THIS/FROM linkage. |
| src/openvic-simulation/scripts/Context.cpp | Implements scope identification, identifier access, leaf dispatch, iterator sub-contexts, and redirect contexts. |
| src/openvic-simulation/scripts/Condition.hpp | Adds tooltip metadata fields and declares ConditionNode evaluation entrypoints + builder-based condition registration. |
| src/openvic-simulation/scripts/Condition.cpp | Implements condition evaluation logic and migrates condition registration to builder API. |
| src/openvic-simulation/population/Pop.hpp / Pop.cpp | Adds pop-scope leaf evaluation (partial) for conditions. |
| src/openvic-simulation/map/State.hpp / State.cpp | Adds state-scope leaf evaluation stub and wires includes. |
| src/openvic-simulation/map/ProvinceInstance.hpp / ProvinceInstance.cpp | Adds province-scope leaf evaluation stub and wires includes. |
| src/openvic-simulation/country/CountryInstance.hpp / CountryInstance.cpp | Adds country-scope leaf evaluation (partial) and wires includes. |
Comments suppressed due to low confidence (1)
src/openvic-simulation/scripts/Condition.cpp:211
- AND/OR/NOT are registered with scope COUNTRY, but ConditionNode::evaluate() enforces
share_scope_type(condition->scope, context.get_scope_type()). Since AND is also the root condition, this makes any condition script evaluated in a non-country context (province/state/pop) immediately fail at the root. Register these logical operators with a scope mask that includes all valid scopes (e.g., POP|PROVINCE|STATE|COUNTRY) or exempt them from scope checks.
/* Special Conditions */
ret &= add_condition("AND", GROUP, COUNTRY);
ret &= add_condition("OR", GROUP, COUNTRY);
ret &= add_condition("NOT", GROUP, COUNTRY);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <limits> | ||
| #include <compare> |
There was a problem hiding this comment.
#include <compare> was added but doesn't appear to be used anywhere in this file. Removing unused includes helps keep compile times and dependencies down.
| #include <compare> |
| return p->get_identifier(); | ||
| } | ||
| else if constexpr (std::is_same_v<T, State const*>) { | ||
| return p->get_identifier(); |
There was a problem hiding this comment.
Context::get_identifier() returns std::string_view for State by forwarding State::get_identifier(), but State::get_identifier() returns a memory::string by value. This will produce a dangling string_view (view into a temporary) and can lead to use-after-free. Consider returning a stable view (e.g., change State::get_identifier() to return std::string_view to stored data) or change Context::get_identifier() to return an owning string type when the scope is State.
| return p->get_identifier(); | |
| // State::get_identifier() returns a string by value; storing it in a | |
| // thread_local buffer ensures the returned string_view does not dangle. | |
| thread_local std::string state_identifier_buffer; | |
| state_identifier_buffer = p->get_identifier(); | |
| return std::string_view{ state_identifier_buffer }; |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.