@@ -1153,9 +1153,19 @@ static constexpr auto _execute_condition_node_list_multi_scope_callback(
11531153 ) -> bool {
11541154 return _execute_iterative<EXPECTED_VALUE, REQUIRE_ALL>(
11551155 change_scopes (condition, instance_manager, current_scope, this_scope, from_scope),
1156- [&instance_manager, &this_scope, &from_scope, &argument](scope_t new_scope) -> bool {
1156+ [&instance_manager, &this_scope, &from_scope, &argument](auto new_scope) -> bool {
1157+ scope_t new_scope_final;
1158+ if constexpr (std::same_as<decltype (new_scope), CountryDefinition const *>) {
1159+ new_scope_final = &instance_manager.get_country_instance_manager ()
1160+ .get_country_instance_from_definition (*new_scope);
1161+ } else if constexpr (std::same_as<decltype (new_scope), ProvinceDefinition const *>) {
1162+ new_scope_final =
1163+ &instance_manager.get_map_instance ().get_province_instance_from_definition (*new_scope);
1164+ } else {
1165+ new_scope_final = new_scope;
1166+ }
11571167 return _execute_condition_node_list<true , true >(
1158- instance_manager, new_scope , this_scope, from_scope, argument
1168+ instance_manager, new_scope_final , this_scope, from_scope, argument
11591169 );
11601170 }
11611171 );
@@ -1732,58 +1742,83 @@ bool ConditionManager::setup_conditions(DefinitionManager const& definition_mana
17321742 ret &= add_condition (
17331743 " average_consciousness" ,
17341744 _parse_condition_node_value_callback<fixed_point_t , COUNTRY | PROVINCE>,
1735-
1736- // TODO - can be used on province too!!!
17371745 _execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
1738- _execute_condition_node_convert_scope<CountryInstance, scope_t , scope_t , fixed_point_t >(
1739- [](
1740- Condition const & condition, InstanceManager const & instance_manager, CountryInstance const * current_scope,
1741- scope_t this_scope, scope_t from_scope, fixed_point_t argument
1742- ) -> bool {
1743- return current_scope->get_national_consciousness () >= argument;
1744- }
1745- )
1746- )
1746+ [](
1747+ Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope, scope_t this_scope,
1748+ scope_t from_scope, fixed_point_t argument
1749+ ) -> bool {
1750+ struct visitor_t {
1751+
1752+ Condition const & condition;
1753+ InstanceManager const & instance_manager;
1754+ scope_t const & this_scope;
1755+ scope_t const & from_scope;
1756+ fixed_point_t const & argument;
1757+
1758+ bool operator ()(no_scope_t no_scope) const {
1759+ Logger::error (" Error executing condition \" " , condition.get_identifier (), " \" : no current scope!" );
1760+ return false ;
1761+ }
17471762
1748- // _execute_condition_node_cast_argument_callback<fixed_point_t, scope_t, scope_t, scope_t>(
1749- // _execute_condition_node_try_cast_scope_types<
1750- // bool, CountryInstance const*, ProvinceInstance const*
1751- // >(
1752- // [](
1753- // InstanceManager const& instance_manager, CountryInstance const* current_scope, scope_t this_scope,
1754- // scope_t from_scope, fixed_point_t argument
1755- // ) -> bool {
1756- // return current_scope->get_national_consciousness() >= argument;
1757- // },
1758- // [](
1759- // InstanceManager const& instance_manager, ProvinceInstance const* current_scope, scope_t this_scope,
1760- // scope_t from_scope, fixed_point_t argument
1761- // ) -> bool {
1762- // return current_scope->get_average_consciousness() >= argument;
1763- // },
1764- // [](
1765- // InstanceManager const& instance_manager, ProvinceInstance const* current_scope, scope_t this_scope,
1766- // scope_t from_scope, fixed_point_t argument
1767- // ) -> bool {
1768- // return false;
1769- // }
1770- // )
1771- // )
1763+ constexpr bool operator ()(CountryInstance const * country) {
1764+ return country->get_national_consciousness () >= argument;
1765+ }
1766+ constexpr bool operator ()(State const * state) const {
1767+ return state->get_average_consciousness () >= argument;
1768+ }
1769+ constexpr bool operator ()(ProvinceInstance const * province) const {
1770+ return province->get_average_consciousness () >= argument;
1771+ }
1772+ constexpr bool operator ()(Pop const * pop) const {
1773+ return pop->get_consciousness () >= argument;
1774+ }
1775+ };
1776+
1777+ return std::visit (visitor_t {
1778+ condition, instance_manager, this_scope, from_scope, argument
1779+ }, current_scope);
1780+ }
1781+ )
17721782 );
17731783 ret &= add_condition (
17741784 " average_militancy" ,
17751785 _parse_condition_node_value_callback<fixed_point_t , COUNTRY | PROVINCE>,
1776-
1777- // TODO - can be used on province too!!!
17781786 _execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
1779- _execute_condition_node_convert_scope<CountryInstance, scope_t , scope_t , fixed_point_t >(
1780- [](
1781- Condition const & condition, InstanceManager const & instance_manager, CountryInstance const * current_scope,
1782- scope_t this_scope, scope_t from_scope, fixed_point_t argument
1783- ) -> bool {
1784- return current_scope->get_national_militancy () >= argument;
1785- }
1786- )
1787+ [](
1788+ Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope, scope_t this_scope,
1789+ scope_t from_scope, fixed_point_t argument
1790+ ) -> bool {
1791+ struct visitor_t {
1792+
1793+ Condition const & condition;
1794+ InstanceManager const & instance_manager;
1795+ scope_t const & this_scope;
1796+ scope_t const & from_scope;
1797+ fixed_point_t const & argument;
1798+
1799+ bool operator ()(no_scope_t no_scope) const {
1800+ Logger::error (" Error executing condition \" " , condition.get_identifier (), " \" : no current scope!" );
1801+ return false ;
1802+ }
1803+
1804+ constexpr bool operator ()(CountryInstance const * country) {
1805+ return country->get_national_militancy () >= argument;
1806+ }
1807+ constexpr bool operator ()(State const * state) const {
1808+ return state->get_average_militancy () >= argument;
1809+ }
1810+ constexpr bool operator ()(ProvinceInstance const * province) const {
1811+ return province->get_average_militancy () >= argument;
1812+ }
1813+ constexpr bool operator ()(Pop const * pop) const {
1814+ return pop->get_militancy () >= argument;
1815+ }
1816+ };
1817+
1818+ return std::visit (visitor_t {
1819+ condition, instance_manager, this_scope, from_scope, argument
1820+ }, current_scope);
1821+ }
17871822 )
17881823 );
17891824 ret &= add_condition (
@@ -2984,26 +3019,16 @@ bool ConditionManager::setup_conditions(DefinitionManager const& definition_mana
29843019 ret &= add_condition (
29853020 region.get_identifier (),
29863021 _parse_condition_node_list_callback<PROVINCE>,
2987- nullptr
2988- /* _execute_condition_node_list_multi_scope_callback<expect_true, require_all>(
3022+ _execute_condition_node_list_multi_scope_callback<
3023+ expect_true, require_all, std::vector<ProvinceDefinition const *> const &
3024+ >(
29893025 [®ion](
29903026 Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope,
29913027 scope_t this_scope, scope_t from_scope
2992- ) -> std::vector<scope_t> {
2993- std::vector<ProvinceDefinition const*> const& region_provinces = region.get_provinces();
2994-
2995- std::vector<scope_t> region_province_scopes;
2996- region_province_scopes.reserve(region_provinces.size());
2997-
2998- for (ProvinceDefinition const* province : region_provinces) {
2999- region_province_scopes.push_back(
3000- &instance_manager.get_map_instance().get_province_instance_from_definition(*province)
3001- );
3002- }
3003-
3004- return region_province_scopes;
3028+ ) -> std::vector<ProvinceDefinition const *> const & {
3029+ return region.get_provinces ();
30053030 }
3006- )*/
3031+ )
30073032 );
30083033 }
30093034
0 commit comments