Skip to content

Commit

Permalink
Further invention chance condition stuff (even for those with limits …
Browse files Browse the repository at this point in the history
…failing in 1836)
  • Loading branch information
Hop311 committed Dec 29, 2024
1 parent 8b4e523 commit 65a251d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 51 deletions.
76 changes: 38 additions & 38 deletions src/headless/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,44 +90,44 @@ static bool run_headless(Dataloader::path_vector_t const& roots, bool run_tests)
ret &= game_manager.update_clock();

// TODO - REMOVE TEST CODE
Logger::info("===== Ranking system test... =====");
if (game_manager.get_instance_manager()) {
const auto print_ranking_list = [](std::string_view title, std::vector<CountryInstance*> const& countries) -> void {
std::string text;
for (CountryInstance const* country : countries) {
text += StringUtils::append_string_views(
"\n ", country->get_identifier(),
" - Total #", std::to_string(country->get_total_rank()), " (", country->get_total_score().to_string(1),
"), Prestige #", std::to_string(country->get_prestige_rank()), " (", country->get_prestige().to_string(1),
"), Industry #", std::to_string(country->get_industrial_rank()), " (", country->get_industrial_power().to_string(1),
"), Military #", std::to_string(country->get_military_rank()), " (", country->get_military_power().to_string(1), ")"
);
}
Logger::info(title, ":", text);
};

CountryInstanceManager const& country_instance_manager =
game_manager.get_instance_manager()->get_country_instance_manager();

std::vector<CountryInstance*> const& great_powers = country_instance_manager.get_great_powers();
print_ranking_list("Great Powers", great_powers);
print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers());
print_ranking_list("All countries", country_instance_manager.get_total_ranking());

Logger::info("===== RGO test... =====");
for (size_t i = 0; i < std::min<size_t>(3, great_powers.size()); ++i) {
CountryInstance const& great_power = *great_powers[i];
ProvinceInstance const* const capital_province = great_power.get_capital();
if (capital_province == nullptr) {
Logger::warning(great_power.get_identifier(), " has no capital ProvinceInstance set.");
} else {
print_rgo(*capital_province);
}
}
} else {
Logger::error("Instance manager not available!");
ret = false;
}
// Logger::info("===== Ranking system test... =====");
// if (game_manager.get_instance_manager()) {
// const auto print_ranking_list = [](std::string_view title, std::vector<CountryInstance*> const& countries) -> void {
// std::string text;
// for (CountryInstance const* country : countries) {
// text += StringUtils::append_string_views(
// "\n ", country->get_identifier(),
// " - Total #", std::to_string(country->get_total_rank()), " (", country->get_total_score().to_string(1),
// "), Prestige #", std::to_string(country->get_prestige_rank()), " (", country->get_prestige().to_string(1),
// "), Industry #", std::to_string(country->get_industrial_rank()), " (", country->get_industrial_power().to_string(1),
// "), Military #", std::to_string(country->get_military_rank()), " (", country->get_military_power().to_string(1), ")"
// );
// }
// Logger::info(title, ":", text);
// };

// CountryInstanceManager const& country_instance_manager =
// game_manager.get_instance_manager()->get_country_instance_manager();

// std::vector<CountryInstance*> const& great_powers = country_instance_manager.get_great_powers();
// print_ranking_list("Great Powers", great_powers);
// print_ranking_list("Secondary Powers", country_instance_manager.get_secondary_powers());
// print_ranking_list("All countries", country_instance_manager.get_total_ranking());

// Logger::info("===== RGO test... =====");
// for (size_t i = 0; i < std::min<size_t>(3, great_powers.size()); ++i) {
// CountryInstance const& great_power = *great_powers[i];
// ProvinceInstance const* const capital_province = great_power.get_capital();
// if (capital_province == nullptr) {
// Logger::warning(great_power.get_identifier(), " has no capital ProvinceInstance set.");
// } else {
// print_rgo(*capital_province);
// }
// }
// } else {
// Logger::error("Instance manager not available!");
// ret = false;
// }

return ret;
}
Expand Down
1 change: 0 additions & 1 deletion src/openvic-simulation/country/CountryInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,6 @@ bool CountryInstance::apply_history_to_country(CountryHistoryEntry const& entry,
invention.get_chance().execute(instance_manager, this, this) > 0
) {
ret &= unlock_invention(invention);
// Logger::info("Unlocked invention ", invention.get_identifier(), " for country ", get_identifier());
}
}

Expand Down
37 changes: 25 additions & 12 deletions src/openvic-simulation/scripts/Condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,23 +1286,18 @@ bool ConditionManager::setup_conditions(DefinitionManager const& definition_mana
ret &= add_condition(
"any_neighbor_country",
_parse_condition_node_list_callback<COUNTRY, COUNTRY>,
_execute_condition_node_unimplemented
/*_execute_condition_node_convert_scope<CountryInstance, scope_t, scope_t, argument_t const&>(
_execute_condition_node_convert_scope<CountryInstance, scope_t, scope_t, argument_t const&>(
_execute_condition_node_list_multi_scope_callback<
expect_true, require_any, std::vector<scope_t>, CountryInstance const*
expect_true, require_any, ordered_set<CountryInstance*> const&, CountryInstance const*
>(
[](
Condition const& condition, InstanceManager const& instance_manager, CountryInstance const* current_scope,
scope_t this_scope, scope_t from_scope
) -> std::vector<scope_t> {
std::vector<scope_t> neighbouring_country_scopes;
// TODO - fill neighbouring_country_scopes with pointers to countries neighbouring *current_scope
return neighbouring_country_scopes;
) -> ordered_set<CountryInstance*> const& {
return current_scope->get_neighbouring_countries();
}
)
)*/
)
);
ret &= add_condition(
"any_owned_province",
Expand Down Expand Up @@ -2185,6 +2180,7 @@ bool ConditionManager::setup_conditions(DefinitionManager const& definition_mana
"industrial_score",
// This doesn't seem to work with regular country identifiers, they're treated as 0
_parse_condition_node_value_callback<fixed_point_t, COUNTRY | THIS | FROM>,
// TODO - THIS | FROM cases (could use _execute_condition_node_value_or_this_or_from_callback ???)
_execute_condition_node_cast_argument_callback<fixed_point_t, scope_t, scope_t, scope_t>(
_execute_condition_node_convert_scope<CountryInstance, scope_t, scope_t, fixed_point_t>(
[](
Expand Down Expand Up @@ -2316,7 +2312,14 @@ bool ConditionManager::setup_conditions(DefinitionManager const& definition_mana
"is_ideology_enabled",
// The wiki says this can only be used at COUNTRY and PROVINCE scopes but I see no reason why it can't be global
_parse_condition_node_value_callback<Ideology const*>,
_execute_condition_node_unimplemented
_execute_condition_node_cast_argument_callback<Ideology const*, scope_t, scope_t, scope_t>(
[](
Condition const& condition, InstanceManager const& instance_manager, scope_t current_scope, scope_t this_scope,
scope_t from_scope, Ideology const* argument
) -> bool {
return instance_manager.get_politics_instance_manager().is_ideology_unlocked(*argument);
}
)
);
ret &= add_condition(
"is_independant", // paradox typo
Expand Down Expand Up @@ -2486,9 +2489,19 @@ bool ConditionManager::setup_conditions(DefinitionManager const& definition_mana
_execute_condition_node_unimplemented
);
ret &= add_condition(
// This uses the British spelling, unlike the "any_neighbor_[country|province]" conditions which use the US spelling
"neighbour",
_parse_condition_node_value_callback<CountryDefinition const*, COUNTRY | THIS | FROM>,
_execute_condition_node_unimplemented
_execute_condition_node_value_or_cast_this_or_from_callback<CountryInstance const*>(
_execute_condition_node_convert_scope<CountryInstance, CountryInstance const*>(
[](
Condition const& condition, InstanceManager const& instance_manager, CountryInstance const* current_scope,
CountryInstance const* value
) -> bool {
return current_scope->is_neighbour(*value);
}
)
)
);
ret &= add_condition(
"num_of_allies",
Expand Down

0 comments on commit 65a251d

Please sign in to comment.