-
Notifications
You must be signed in to change notification settings - Fork 9
Condition Evaluation #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Condition Evaluation #698
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,6 +50,7 @@ | |||||||||||||||||||||||||||||||
| #include "openvic-simulation/utility/Containers.hpp" | ||||||||||||||||||||||||||||||||
| #include "openvic-simulation/utility/Logger.hpp" | ||||||||||||||||||||||||||||||||
| #include "openvic-simulation/core/Typedefs.hpp" | ||||||||||||||||||||||||||||||||
| #include "openvic-simulation/scripts/Condition.hpp" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| using namespace OpenVic; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -1178,6 +1179,125 @@ void CountryInstance::start_research(Technology const& technology, const Date to | |||||||||||||||||||||||||||||||
| _update_current_tech(today); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| bool CountryInstance::evaluate_leaf(ConditionNode const& node) const { | ||||||||||||||||||||||||||||||||
| std::string_view const& id = node.get_condition()->get_identifier(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // TODO: https://vic2.paradoxwikis.com/List_of_conditions#Country_Scope Implement all of these | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (id == "ai") { | ||||||||||||||||||||||||||||||||
| bool expected = std::get<bool>(node.get_value()); | ||||||||||||||||||||||||||||||||
| return is_ai() == expected; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (id == "average_consciousness") { | ||||||||||||||||||||||||||||||||
| fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); | ||||||||||||||||||||||||||||||||
| return get_average_consciousness() >= expected; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (id == "average_militancy") { | ||||||||||||||||||||||||||||||||
| fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); | ||||||||||||||||||||||||||||||||
| return get_average_militancy() >= expected; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (id == "badboy") { | ||||||||||||||||||||||||||||||||
| fixed_point_t expected_ratio = std::get<fixed_point_t>(node.get_value()); | ||||||||||||||||||||||||||||||||
| return get_infamy_untracked() >= (expected_ratio * fixed_point_t(25)); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (id == "civilized") { | ||||||||||||||||||||||||||||||||
| bool expected = std::get<bool>(node.get_value()); | ||||||||||||||||||||||||||||||||
| return is_civilised() == expected; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (id == "colonial_nation") { | ||||||||||||||||||||||||||||||||
| bool expected = std::get<bool>(node.get_value()); | ||||||||||||||||||||||||||||||||
| return is_colonial(colony_status_t::COLONY) == expected; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (id == "exists") { | ||||||||||||||||||||||||||||||||
| bool expected = std::get<bool>(node.get_value()); | ||||||||||||||||||||||||||||||||
| return exists() == expected; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+1217
to
+1220
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (id == "industrial_score") { | ||||||||||||||||||||||||||||||||
| fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); | ||||||||||||||||||||||||||||||||
| return get_industrial_power_untracked() >= expected; | ||||||||||||||||||||||||||||||||
|
Comment on lines
+1223
to
+1224
|
||||||||||||||||||||||||||||||||
| fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); | |
| return get_industrial_power_untracked() >= expected; | |
| return std::visit( | |
| [this](auto const& value) -> bool { | |
| using T = std::decay_t<decltype(value)>; | |
| if constexpr (std::is_same_v<T, fixed_point_t>) { | |
| return get_industrial_power_untracked() >= value; | |
| } else { | |
| Logger::error( | |
| "industrial_score condition received unsupported value type"); | |
| return false; | |
| } | |
| }, | |
| node.get_value() | |
| ); |
Copilot
AI
Feb 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message duplicates the condition null-check logic unnecessarily. Since id is already obtained from node.get_condition()->get_identifier() at line 1183, and would have crashed earlier if condition were null, the ternary operator here is redundant. The message should simply use id for consistency.
| spdlog::warn_s("Condition {} not implemented in CountryInstance::evaluate_leaf", node.get_condition() ? node.get_condition()->get_identifier() : "NULL"); | |
| spdlog::warn_s("Condition {} not implemented in CountryInstance::evaluate_leaf", id); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |||||
| #include "openvic-simulation/misc/GameRulesManager.hpp" | ||||||
| #include "openvic-simulation/modifier/StaticModifierCache.hpp" | ||||||
| #include "openvic-simulation/types/TypedIndices.hpp" | ||||||
| #include "openvic-simulation/scripts/Condition.hpp" | ||||||
|
|
||||||
| using namespace OpenVic; | ||||||
|
|
||||||
|
|
@@ -399,6 +400,11 @@ void ProvinceInstance::province_tick( | |||||
| rgo.rgo_tick(reusable_vectors[0]); | ||||||
| } | ||||||
|
|
||||||
| bool ProvinceInstance::evaluate_leaf(ConditionNode const& node) const { | ||||||
| // TODO: implement | ||||||
|
||||||
| // TODO: implement | |
| spdlog::warn_s("ProvinceInstance::evaluate_leaf is not yet implemented; returning false for condition."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a hardcoded value.
The bad boy limit comes from the country defines.