|
50 | 50 | #include "openvic-simulation/utility/Containers.hpp" |
51 | 51 | #include "openvic-simulation/utility/Logger.hpp" |
52 | 52 | #include "openvic-simulation/core/Typedefs.hpp" |
| 53 | +#include "openvic-simulation/scripts/Condition.hpp" |
53 | 54 |
|
54 | 55 | using namespace OpenVic; |
55 | 56 |
|
@@ -1178,6 +1179,125 @@ void CountryInstance::start_research(Technology const& technology, const Date to |
1178 | 1179 | _update_current_tech(today); |
1179 | 1180 | } |
1180 | 1181 |
|
| 1182 | +bool CountryInstance::evaluate_leaf(ConditionNode const& node) const { |
| 1183 | + std::string_view const& id = node.get_condition()->get_identifier(); |
| 1184 | + |
| 1185 | + // TODO: https://vic2.paradoxwikis.com/List_of_conditions#Country_Scope Implement all of these |
| 1186 | + |
| 1187 | + if (id == "ai") { |
| 1188 | + bool expected = std::get<bool>(node.get_value()); |
| 1189 | + return is_ai() == expected; |
| 1190 | + } |
| 1191 | + |
| 1192 | + if (id == "average_consciousness") { |
| 1193 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1194 | + return get_average_consciousness() >= expected; |
| 1195 | + } |
| 1196 | + |
| 1197 | + if (id == "average_militancy") { |
| 1198 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1199 | + return get_average_militancy() >= expected; |
| 1200 | + } |
| 1201 | + |
| 1202 | + if (id == "badboy") { |
| 1203 | + fixed_point_t expected_ratio = std::get<fixed_point_t>(node.get_value()); |
| 1204 | + return get_infamy_untracked() >= (expected_ratio * fixed_point_t(25)); |
| 1205 | + } |
| 1206 | + |
| 1207 | + if (id == "civilized") { |
| 1208 | + bool expected = std::get<bool>(node.get_value()); |
| 1209 | + return is_civilised() == expected; |
| 1210 | + } |
| 1211 | + |
| 1212 | + if (id == "colonial_nation") { |
| 1213 | + bool expected = std::get<bool>(node.get_value()); |
| 1214 | + return is_colonial(colony_status_t::COLONY) == expected; |
| 1215 | + } |
| 1216 | + |
| 1217 | + if (id == "exists") { |
| 1218 | + bool expected = std::get<bool>(node.get_value()); |
| 1219 | + return exists() == expected; |
| 1220 | + } |
| 1221 | + |
| 1222 | + if (id == "industrial_score") { |
| 1223 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1224 | + return get_industrial_power_untracked() >= expected; |
| 1225 | + } |
| 1226 | + |
| 1227 | + if (id == "is_disarmed") { |
| 1228 | + bool expected = std::get<bool>(node.get_value()); |
| 1229 | + return is_disarmed() == expected; |
| 1230 | + } |
| 1231 | + |
| 1232 | + if (id == "is_greater_power") { |
| 1233 | + bool expected = std::get<bool>(node.get_value()); |
| 1234 | + return is_great_power() == expected; |
| 1235 | + } |
| 1236 | + |
| 1237 | + if (id == "is_mobilised") { |
| 1238 | + bool expected = std::get<bool>(node.get_value()); |
| 1239 | + return is_mobilised() == expected; |
| 1240 | + } |
| 1241 | + |
| 1242 | + if (id == "is_secondary_power") { |
| 1243 | + bool expected = std::get<bool>(node.get_value()); |
| 1244 | + return is_secondary_power() == expected; |
| 1245 | + } |
| 1246 | + |
| 1247 | + if (id == "num_of_cities") { |
| 1248 | + uint64_t expected = std::get<uint64_t>(node.get_value()); |
| 1249 | + return get_owned_provinces().size() >= expected; |
| 1250 | + } |
| 1251 | + |
| 1252 | + if (id == "num_of_ports") { |
| 1253 | + uint64_t expected = std::get<uint64_t>(node.get_value()); |
| 1254 | + return get_port_count() >= expected; |
| 1255 | + } |
| 1256 | + |
| 1257 | + if (id == "number_of_states") { |
| 1258 | + uint64_t expected = std::get<uint64_t>(node.get_value()); |
| 1259 | + return get_states().size() >= expected; |
| 1260 | + } |
| 1261 | + |
| 1262 | + if (id == "prestige") { |
| 1263 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1264 | + return get_prestige_untracked() >= expected; |
| 1265 | + } |
| 1266 | + |
| 1267 | + if (id == "plurality") { |
| 1268 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1269 | + return get_plurality_untracked() >= expected; |
| 1270 | + } |
| 1271 | + |
| 1272 | + if (id == "total_amount_of_ships") { |
| 1273 | + uint64_t expected = std::get<uint64_t>(node.get_value()); |
| 1274 | + return get_ship_count() >= expected; |
| 1275 | + } |
| 1276 | + |
| 1277 | + if (id == "rank") { |
| 1278 | + uint64_t expected = std::get<uint64_t>(node.get_value()); |
| 1279 | + return get_total_rank() >= expected; |
| 1280 | + } |
| 1281 | + |
| 1282 | + if (id == "tag") { |
| 1283 | + memory::string const& expected = std::get<memory::string>(node.get_value()); |
| 1284 | + return country_definition.get_identifier() == expected; |
| 1285 | + } |
| 1286 | + |
| 1287 | + if (id == "war") { |
| 1288 | + bool expected = std::get<bool>(node.get_value()); |
| 1289 | + return is_at_war() == expected; |
| 1290 | + } |
| 1291 | + |
| 1292 | + if (id == "war_exhaustion") { |
| 1293 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1294 | + return get_war_exhaustion() >= expected; |
| 1295 | + } |
| 1296 | + |
| 1297 | + spdlog::warn_s("Condition {} not implemented in CountryInstance::evaluate_leaf", node.get_condition() ? node.get_condition()->get_identifier() : "NULL"); |
| 1298 | + return false; |
| 1299 | +} |
| 1300 | + |
1181 | 1301 | void CountryInstance::apply_foreign_investments( |
1182 | 1302 | fixed_point_map_t<CountryDefinition const*> const& investments, CountryInstanceManager const& country_instance_manager |
1183 | 1303 | ) { |
|
0 commit comments