@@ -51,12 +51,139 @@ std::string_view Context::get_identifier() const {
5151}
5252
5353bool Context::evaluate_leaf (ConditionNode const & node) const {
54+ std::string_view const id = node.get_condition ()->get_identifier ();
55+
5456 return std::visit (
5557 [&](auto const * p) -> bool {
5658 if (!p) {
5759 return false ;
5860 }
59- return p->evaluate_leaf (node);
61+
62+ using T = std::decay_t <decltype (*p)>;
63+
64+ if constexpr (std::is_same_v<T, CountryInstance>) {
65+ // TODO: https://vic2.paradoxwikis.com/List_of_conditions#Country_Scope
66+
67+ if (id == " ai" ) {
68+ bool expected = std::get<bool >(node.get_value ());
69+ return p->is_ai () == expected;
70+ }
71+ if (id == " average_consciousness" ) {
72+ fixed_point_t expected = std::get<fixed_point_t >(node.get_value ());
73+ return p->get_average_consciousness () >= expected;
74+ }
75+ if (id == " average_militancy" ) {
76+ fixed_point_t expected = std::get<fixed_point_t >(node.get_value ());
77+ return p->get_average_militancy () >= expected;
78+ }
79+ if (id == " badboy" ) {
80+ fixed_point_t expected_ratio = std::get<fixed_point_t >(node.get_value ());
81+ return p->get_infamy_untracked () >= (expected_ratio * fixed_point_t (25 ));
82+ }
83+ if (id == " civilized" ) {
84+ bool expected = std::get<bool >(node.get_value ());
85+ return p->is_civilised () == expected;
86+ }
87+ if (id == " colonial_nation" ) {
88+ bool expected = std::get<bool >(node.get_value ());
89+ bool has_colonies = false ;
90+ for (State const * state : p->get_states ()) {
91+ if (state && state->is_colonial_state ()) {
92+ has_colonies = true ;
93+ break ;
94+ }
95+ }
96+ return has_colonies == expected;
97+ }
98+ if (id == " exists" ) {
99+ bool expected = std::get<bool >(node.get_value ());
100+ return p->exists () == expected;
101+ }
102+ if (id == " industrial_score" ) {
103+ fixed_point_t expected = std::get<fixed_point_t >(node.get_value ());
104+ return p->get_industrial_power_untracked () >= expected;
105+ }
106+ if (id == " is_disarmed" ) {
107+ bool expected = std::get<bool >(node.get_value ());
108+ return p->is_disarmed () == expected;
109+ }
110+ if (id == " is_greater_power" ) {
111+ bool expected = std::get<bool >(node.get_value ());
112+ return p->is_great_power () == expected;
113+ }
114+ if (id == " is_mobilised" ) {
115+ bool expected = std::get<bool >(node.get_value ());
116+ return p->is_mobilised () == expected;
117+ }
118+ if (id == " is_secondary_power" ) {
119+ bool expected = std::get<bool >(node.get_value ());
120+ return p->is_secondary_power () == expected;
121+ }
122+ if (id == " num_of_cities" ) {
123+ uint64_t expected = std::get<uint64_t >(node.get_value ());
124+ return p->get_owned_provinces ().size () >= expected;
125+ }
126+ if (id == " num_of_ports" ) {
127+ uint64_t expected = std::get<uint64_t >(node.get_value ());
128+ return p->get_port_count () >= expected;
129+ }
130+ if (id == " number_of_states" ) {
131+ uint64_t expected = std::get<uint64_t >(node.get_value ());
132+ return p->get_states ().size () >= expected;
133+ }
134+ if (id == " prestige" ) {
135+ fixed_point_t expected = std::get<fixed_point_t >(node.get_value ());
136+ return p->get_prestige_untracked () >= expected;
137+ }
138+ if (id == " plurality" ) {
139+ fixed_point_t expected = std::get<fixed_point_t >(node.get_value ());
140+ return p->get_plurality_untracked () >= expected;
141+ }
142+ if (id == " total_amount_of_ships" ) {
143+ uint64_t expected = std::get<uint64_t >(node.get_value ());
144+ return p->get_ship_count () >= expected;
145+ }
146+ if (id == " rank" ) {
147+ uint64_t expected = std::get<uint64_t >(node.get_value ());
148+ return p->get_total_rank () >= expected;
149+ }
150+ if (id == " tag" ) {
151+ memory::string const & expected = std::get<memory::string>(node.get_value ());
152+ return p->get_identifier () == expected;
153+ }
154+ if (id == " war" ) {
155+ bool expected = std::get<bool >(node.get_value ());
156+ return p->is_at_war () == expected;
157+ }
158+ if (id == " war_exhaustion" ) {
159+ fixed_point_t expected = std::get<fixed_point_t >(node.get_value ());
160+ return p->get_war_exhaustion () >= expected;
161+ }
162+
163+ spdlog::warn_s (" Condition {} not implemented for Country scope" , id);
164+ return false ;
165+ }
166+ else if constexpr (std::is_same_v<T, State>) {
167+ // No state conditions according to wiki?
168+ spdlog::warn_s (" Condition {} not implemented for State scope" , id);
169+ return false ;
170+ }
171+ else if constexpr (std::is_same_v<T, ProvinceInstance>) {
172+ // TODO: https://vic2.paradoxwikis.com/List_of_conditions#Province_Scope
173+ spdlog::warn_s (" Condition {} not implemented for Province scope" , id);
174+ return false ;
175+ }
176+ else if constexpr (std::is_same_v<T, Pop>) {
177+ // TODO: https://vic2.paradoxwikis.com/List_of_conditions#Pop_Scope
178+ if (id == " consciousness" ) {
179+ fixed_point_t expected = std::get<fixed_point_t >(node.get_value ());
180+ return p->get_consciousness () >= expected;
181+ }
182+ spdlog::warn_s (" Condition {} not implemented for Pop scope" , id);
183+ return false ;
184+ }
185+
186+ return false ;
60187 },
61188 ptr
62189 );
@@ -79,7 +206,7 @@ std::vector<Context> Context::get_sub_contexts(std::string_view condition_id, sc
79206 result.emplace_back (make_child (prov));
80207 }
81208 }
82- else if (condition_id == " any_core " || condition_id == " all_core" ) {
209+ else if (condition_id == " any_core_province " || condition_id == " all_core" ) {
83210 for (ProvinceInstance const * prov : country->get_core_provinces ()) {
84211 result.emplace_back (make_child (prov));
85212 }
0 commit comments