|
51 | 51 | #include "openvic-simulation/utility/Containers.hpp" |
52 | 52 | #include "openvic-simulation/utility/Logger.hpp" |
53 | 53 | #include "openvic-simulation/core/Typedefs.hpp" |
| 54 | +#include "openvic-simulation/scripts/Condition.hpp" |
54 | 55 |
|
55 | 56 | using namespace OpenVic; |
56 | 57 |
|
@@ -1223,6 +1224,125 @@ void CountryInstance::start_research(Technology const& technology, const Date to |
1223 | 1224 | _update_current_tech(today); |
1224 | 1225 | } |
1225 | 1226 |
|
| 1227 | +bool CountryInstance::evaluate_leaf(ConditionNode const& node) const { |
| 1228 | + std::string_view const& id = node.get_condition()->get_identifier(); |
| 1229 | + |
| 1230 | + // TODO: https://vic2.paradoxwikis.com/List_of_conditions#Country_Scope Implement all of these |
| 1231 | + |
| 1232 | + if (id == "ai") { |
| 1233 | + bool expected = std::get<bool>(node.get_value()); |
| 1234 | + return is_ai() == expected; |
| 1235 | + } |
| 1236 | + |
| 1237 | + if (id == "average_consciousness") { |
| 1238 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1239 | + return get_average_consciousness() >= expected; |
| 1240 | + } |
| 1241 | + |
| 1242 | + if (id == "average_militancy") { |
| 1243 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1244 | + return get_average_militancy() >= expected; |
| 1245 | + } |
| 1246 | + |
| 1247 | + if (id == "badboy") { |
| 1248 | + fixed_point_t expected_ratio = std::get<fixed_point_t>(node.get_value()); |
| 1249 | + return get_infamy_untracked() >= (expected_ratio * fixed_point_t(25)); |
| 1250 | + } |
| 1251 | + |
| 1252 | + if (id == "civilized") { |
| 1253 | + bool expected = std::get<bool>(node.get_value()); |
| 1254 | + return is_civilised() == expected; |
| 1255 | + } |
| 1256 | + |
| 1257 | + if (id == "colonial_nation") { |
| 1258 | + bool expected = std::get<bool>(node.get_value()); |
| 1259 | + return is_colonial(colony_status_t::COLONY) == expected; |
| 1260 | + } |
| 1261 | + |
| 1262 | + if (id == "exists") { |
| 1263 | + bool expected = std::get<bool>(node.get_value()); |
| 1264 | + return exists() == expected; |
| 1265 | + } |
| 1266 | + |
| 1267 | + if (id == "industrial_score") { |
| 1268 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1269 | + return get_industrial_power_untracked() >= expected; |
| 1270 | + } |
| 1271 | + |
| 1272 | + if (id == "is_disarmed") { |
| 1273 | + bool expected = std::get<bool>(node.get_value()); |
| 1274 | + return is_disarmed() == expected; |
| 1275 | + } |
| 1276 | + |
| 1277 | + if (id == "is_greater_power") { |
| 1278 | + bool expected = std::get<bool>(node.get_value()); |
| 1279 | + return is_great_power() == expected; |
| 1280 | + } |
| 1281 | + |
| 1282 | + if (id == "is_mobilised") { |
| 1283 | + bool expected = std::get<bool>(node.get_value()); |
| 1284 | + return is_mobilised() == expected; |
| 1285 | + } |
| 1286 | + |
| 1287 | + if (id == "is_secondary_power") { |
| 1288 | + bool expected = std::get<bool>(node.get_value()); |
| 1289 | + return is_secondary_power() == expected; |
| 1290 | + } |
| 1291 | + |
| 1292 | + if (id == "num_of_cities") { |
| 1293 | + uint64_t expected = std::get<uint64_t>(node.get_value()); |
| 1294 | + return get_owned_provinces().size() >= expected; |
| 1295 | + } |
| 1296 | + |
| 1297 | + if (id == "num_of_ports") { |
| 1298 | + uint64_t expected = std::get<uint64_t>(node.get_value()); |
| 1299 | + return get_port_count() >= expected; |
| 1300 | + } |
| 1301 | + |
| 1302 | + if (id == "number_of_states") { |
| 1303 | + uint64_t expected = std::get<uint64_t>(node.get_value()); |
| 1304 | + return get_states().size() >= expected; |
| 1305 | + } |
| 1306 | + |
| 1307 | + if (id == "prestige") { |
| 1308 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1309 | + return get_prestige_untracked() >= expected; |
| 1310 | + } |
| 1311 | + |
| 1312 | + if (id == "plurality") { |
| 1313 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1314 | + return get_plurality_untracked() >= expected; |
| 1315 | + } |
| 1316 | + |
| 1317 | + if (id == "total_amount_of_ships") { |
| 1318 | + uint64_t expected = std::get<uint64_t>(node.get_value()); |
| 1319 | + return get_ship_count() >= expected; |
| 1320 | + } |
| 1321 | + |
| 1322 | + if (id == "rank") { |
| 1323 | + uint64_t expected = std::get<uint64_t>(node.get_value()); |
| 1324 | + return get_total_rank() >= expected; |
| 1325 | + } |
| 1326 | + |
| 1327 | + if (id == "tag") { |
| 1328 | + memory::string const& expected = std::get<memory::string>(node.get_value()); |
| 1329 | + return country_definition.get_identifier() == expected; |
| 1330 | + } |
| 1331 | + |
| 1332 | + if (id == "war") { |
| 1333 | + bool expected = std::get<bool>(node.get_value()); |
| 1334 | + return is_at_war() == expected; |
| 1335 | + } |
| 1336 | + |
| 1337 | + if (id == "war_exhaustion") { |
| 1338 | + fixed_point_t expected = std::get<fixed_point_t>(node.get_value()); |
| 1339 | + return get_war_exhaustion() >= expected; |
| 1340 | + } |
| 1341 | + |
| 1342 | + spdlog::warn_s("Condition {} not implemented in CountryInstance::evaluate_leaf", node.get_condition() ? node.get_condition()->get_identifier() : "NULL"); |
| 1343 | + return false; |
| 1344 | +} |
| 1345 | + |
1226 | 1346 | void CountryInstance::apply_foreign_investments( |
1227 | 1347 | fixed_point_map_t<CountryDefinition const*> const& investments, CountryInstanceManager const& country_instance_manager |
1228 | 1348 | ) { |
|
0 commit comments