@@ -167,15 +167,18 @@ std::ostream& OpenVic::operator<<(std::ostream& stream, ConditionNode const& nod
167
167
Condition::Condition (
168
168
std::string_view new_identifier,
169
169
parse_callback_t && new_parse_callback,
170
- execute_callback_t && new_execute_callback
170
+ execute_callback_t && new_execute_callback,
171
+ void const * new_condition_data
171
172
) : HasIdentifier { new_identifier },
172
173
parse_callback { std::move (new_parse_callback) },
173
- execute_callback { std::move (new_execute_callback) } {}
174
+ execute_callback { std::move (new_execute_callback) },
175
+ condition_data { new_condition_data } {}
174
176
175
177
bool ConditionManager::add_condition (
176
178
std::string_view identifier,
177
179
Condition::parse_callback_t && parse_callback,
178
- Condition::execute_callback_t && execute_callback
180
+ Condition::execute_callback_t && execute_callback,
181
+ void const * condition_data
179
182
) {
180
183
if (identifier.empty ()) {
181
184
Logger::error (" Invalid condition identifier - empty!" );
@@ -195,7 +198,8 @@ bool ConditionManager::add_condition(
195
198
return conditions.add_item ({
196
199
identifier,
197
200
std::move (parse_callback),
198
- std::move (execute_callback)
201
+ std::move (execute_callback),
202
+ condition_data
199
203
});
200
204
}
201
205
@@ -3833,23 +3837,28 @@ bool ConditionManager::setup_conditions() {
3833
3837
_parse_condition_node_value_callback<fixed_point_t , COUNTRY>,
3834
3838
_execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
3835
3839
_execute_condition_node_convert_scope<CountryInstance, scope_t , scope_t , fixed_point_t >(
3836
- [&strata ](
3840
+ [](
3837
3841
Condition const & condition, InstanceManager const & instance_manager,
3838
3842
CountryInstance const * current_scope, scope_t this_scope, scope_t from_scope, fixed_point_t argument
3839
3843
) -> bool {
3844
+ Strata const & strata = *static_cast <Strata const *>(condition.get_condition_data ());
3845
+
3840
3846
return current_scope->get_tax_rate_slider_value_by_strata ()[strata].get_value () >= argument;
3841
3847
}
3842
3848
)
3843
- )
3849
+ ),
3850
+ &strata
3844
3851
);
3845
3852
ret &= add_condition (
3846
3853
StringUtils::append_string_views (identifier, " _strata_life_needs" ),
3847
3854
_parse_condition_node_value_callback<fixed_point_t , COUNTRY | PROVINCE>,
3848
3855
_execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
3849
- [&strata ](
3856
+ [](
3850
3857
Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope,
3851
3858
scope_t this_scope, scope_t from_scope, fixed_point_t argument
3852
3859
) -> bool {
3860
+ Strata const & strata = *static_cast <Strata const *>(condition.get_condition_data ());
3861
+
3853
3862
struct visitor_t {
3854
3863
3855
3864
Condition const & condition;
@@ -3880,16 +3889,19 @@ bool ConditionManager::setup_conditions() {
3880
3889
3881
3890
return std::visit (visitor_t { condition, argument, strata }, current_scope);
3882
3891
}
3883
- )
3892
+ ),
3893
+ &strata
3884
3894
);
3885
3895
ret &= add_condition (
3886
3896
StringUtils::append_string_views (identifier, " _strata_everyday_needs" ),
3887
3897
_parse_condition_node_value_callback<fixed_point_t , COUNTRY | PROVINCE>,
3888
3898
_execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
3889
- [&strata ](
3899
+ [](
3890
3900
Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope,
3891
3901
scope_t this_scope, scope_t from_scope, fixed_point_t argument
3892
3902
) -> bool {
3903
+ Strata const & strata = *static_cast <Strata const *>(condition.get_condition_data ());
3904
+
3893
3905
struct visitor_t {
3894
3906
3895
3907
Condition const & condition;
@@ -3920,16 +3932,19 @@ bool ConditionManager::setup_conditions() {
3920
3932
3921
3933
return std::visit (visitor_t { condition, argument, strata }, current_scope);
3922
3934
}
3923
- )
3935
+ ),
3936
+ &strata
3924
3937
);
3925
3938
ret &= add_condition (
3926
3939
StringUtils::append_string_views (identifier, " _strata_luxury_needs" ),
3927
3940
_parse_condition_node_value_callback<fixed_point_t , COUNTRY | PROVINCE>,
3928
3941
_execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
3929
- [&strata ](
3942
+ [](
3930
3943
Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope,
3931
3944
scope_t this_scope, scope_t from_scope, fixed_point_t argument
3932
3945
) -> bool {
3946
+ Strata const & strata = *static_cast <Strata const *>(condition.get_condition_data ());
3947
+
3933
3948
struct visitor_t {
3934
3949
3935
3950
Condition const & condition;
@@ -3960,16 +3975,19 @@ bool ConditionManager::setup_conditions() {
3960
3975
3961
3976
return std::visit (visitor_t { condition, argument, strata }, current_scope);
3962
3977
}
3963
- )
3978
+ ),
3979
+ &strata
3964
3980
);
3965
3981
ret &= add_condition (
3966
3982
StringUtils::append_string_views (identifier, " _strata_militancy" ),
3967
3983
_parse_condition_node_value_callback<fixed_point_t , COUNTRY>,
3968
3984
_execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
3969
- [&strata ](
3985
+ [](
3970
3986
Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope,
3971
3987
scope_t this_scope, scope_t from_scope, fixed_point_t argument
3972
3988
) -> bool {
3989
+ Strata const & strata = *static_cast <Strata const *>(condition.get_condition_data ());
3990
+
3973
3991
struct visitor_t {
3974
3992
3975
3993
Condition const & condition;
@@ -3999,7 +4017,8 @@ bool ConditionManager::setup_conditions() {
3999
4017
4000
4018
return std::visit (visitor_t { condition, argument, strata }, current_scope);
4001
4019
}
4002
- )
4020
+ ),
4021
+ &strata
4003
4022
);
4004
4023
}
4005
4024
@@ -4009,13 +4028,16 @@ bool ConditionManager::setup_conditions() {
4009
4028
country.get_identifier (),
4010
4029
_parse_condition_node_list_callback<COUNTRY>,
4011
4030
_execute_condition_node_list_single_scope_callback<expect_true, require_all>(
4012
- [&country ](
4031
+ [](
4013
4032
Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope,
4014
4033
scope_t this_scope, scope_t from_scope
4015
4034
) -> scope_t {
4035
+ CountryDefinition const & country = *static_cast <CountryDefinition const *>(condition.get_condition_data ());
4036
+
4016
4037
return &instance_manager.get_country_instance_manager ().get_country_instance_from_definition (country);
4017
4038
}
4018
- )
4039
+ ),
4040
+ &country
4019
4041
);
4020
4042
}
4021
4043
@@ -4026,13 +4048,16 @@ bool ConditionManager::setup_conditions() {
4026
4048
_execute_condition_node_list_multi_scope_callback<
4027
4049
expect_true, require_all, std::vector<ProvinceDefinition const *> const &
4028
4050
>(
4029
- [®ion ](
4051
+ [](
4030
4052
Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope,
4031
4053
scope_t this_scope, scope_t from_scope
4032
4054
) -> std::vector<ProvinceDefinition const *> const & {
4055
+ Region const & region = *static_cast <Region const *>(condition.get_condition_data ());
4056
+
4033
4057
return region.get_provinces ();
4034
4058
}
4035
- )
4059
+ ),
4060
+ ®ion
4036
4061
);
4037
4062
}
4038
4063
@@ -4041,13 +4066,17 @@ bool ConditionManager::setup_conditions() {
4041
4066
province.get_identifier (),
4042
4067
_parse_condition_node_list_callback<PROVINCE>,
4043
4068
_execute_condition_node_list_single_scope_callback<expect_true, require_all>(
4044
- [&province ](
4069
+ [](
4045
4070
Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope,
4046
4071
scope_t this_scope, scope_t from_scope
4047
4072
) -> scope_t {
4073
+ ProvinceDefinition const & province =
4074
+ *static_cast <ProvinceDefinition const *>(condition.get_condition_data ());
4075
+
4048
4076
return &instance_manager.get_map_instance ().get_province_instance_from_definition (province);
4049
4077
}
4050
- )
4078
+ ),
4079
+ &province
4051
4080
);
4052
4081
}
4053
4082
@@ -4057,10 +4086,12 @@ bool ConditionManager::setup_conditions() {
4057
4086
ideology.get_identifier (),
4058
4087
_parse_condition_node_value_callback<fixed_point_t , COUNTRY | PROVINCE>,
4059
4088
_execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
4060
- [&ideology ](
4089
+ [](
4061
4090
Condition const & condition, InstanceManager const & instance_manager, scope_t current_scope,
4062
4091
scope_t this_scope, scope_t from_scope, fixed_point_t argument
4063
4092
) -> bool {
4093
+ Ideology const & ideology = *static_cast <Ideology const *>(condition.get_condition_data ());
4094
+
4064
4095
struct visitor_t {
4065
4096
4066
4097
Condition const & condition;
@@ -4088,7 +4119,8 @@ bool ConditionManager::setup_conditions() {
4088
4119
4089
4120
return std::visit (visitor_t { condition, argument, ideology }, current_scope);
4090
4121
}
4091
- )
4122
+ ),
4123
+ &ideology
4092
4124
);
4093
4125
}
4094
4126
@@ -4098,14 +4130,17 @@ bool ConditionManager::setup_conditions() {
4098
4130
_parse_condition_node_value_callback<Reform const *, COUNTRY>,
4099
4131
_execute_condition_node_cast_argument_callback<Reform const *, scope_t , scope_t , scope_t >(
4100
4132
_execute_condition_node_convert_scope<CountryInstance, scope_t , scope_t , Reform const *>(
4101
- [&reform_group ](
4133
+ [](
4102
4134
Condition const & condition, InstanceManager const & instance_manager,
4103
4135
CountryInstance const * current_scope, scope_t this_scope, scope_t from_scope, Reform const * argument
4104
4136
) -> bool {
4137
+ ReformGroup const & reform_group = *static_cast <ReformGroup const *>(condition.get_condition_data ());
4138
+
4105
4139
return current_scope->get_reforms ()[reform_group] == argument;
4106
4140
}
4107
4141
)
4108
- )
4142
+ ),
4143
+ &reform_group
4109
4144
);
4110
4145
}
4111
4146
@@ -4115,15 +4150,18 @@ bool ConditionManager::setup_conditions() {
4115
4150
_parse_condition_node_value_callback<fixed_point_t , COUNTRY | PROVINCE>,
4116
4151
_execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
4117
4152
_execute_condition_node_convert_scope<CountryInstance, scope_t , scope_t , fixed_point_t >(
4118
- [&reform ](
4153
+ [](
4119
4154
Condition const & condition, InstanceManager const & instance_manager,
4120
4155
CountryInstance const * current_scope, scope_t this_scope, scope_t from_scope, fixed_point_t argument
4121
4156
) -> bool {
4157
+ Reform const & reform = *static_cast <Reform const *>(condition.get_condition_data ());
4158
+
4122
4159
return current_scope->get_issue_support (reform) * 100 >=
4123
4160
argument * current_scope->get_total_population ();
4124
4161
}
4125
4162
)
4126
- )
4163
+ ),
4164
+ &reform
4127
4165
);
4128
4166
}
4129
4167
@@ -4134,16 +4172,19 @@ bool ConditionManager::setup_conditions() {
4134
4172
_parse_condition_node_value_callback<Issue const *, COUNTRY>,
4135
4173
_execute_condition_node_cast_argument_callback<Issue const *, scope_t , scope_t , scope_t >(
4136
4174
_execute_condition_node_convert_scope<CountryInstance, scope_t , scope_t , Issue const *>(
4137
- [&issue_group ](
4175
+ [](
4138
4176
Condition const & condition, InstanceManager const & instance_manager,
4139
4177
CountryInstance const * current_scope, scope_t this_scope, scope_t from_scope, Issue const * argument
4140
4178
) -> bool {
4179
+ IssueGroup const & issue_group = *static_cast <IssueGroup const *>(condition.get_condition_data ());
4180
+
4141
4181
CountryParty const * ruling_party = current_scope->get_ruling_party ();
4142
4182
4143
4183
return ruling_party != nullptr ? ruling_party->get_policies ()[issue_group] == argument : false ;
4144
4184
}
4145
4185
)
4146
- )
4186
+ ),
4187
+ &issue_group
4147
4188
);
4148
4189
}
4149
4190
@@ -4153,15 +4194,18 @@ bool ConditionManager::setup_conditions() {
4153
4194
_parse_condition_node_value_callback<fixed_point_t , COUNTRY | PROVINCE>,
4154
4195
_execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
4155
4196
_execute_condition_node_convert_scope<CountryInstance, scope_t , scope_t , fixed_point_t >(
4156
- [&issue ](
4197
+ [](
4157
4198
Condition const & condition, InstanceManager const & instance_manager,
4158
4199
CountryInstance const * current_scope, scope_t this_scope, scope_t from_scope, fixed_point_t argument
4159
4200
) -> bool {
4201
+ Issue const & issue = *static_cast <Issue const *>(condition.get_condition_data ());
4202
+
4160
4203
return current_scope->get_issue_support (issue) * 100 >=
4161
4204
argument * current_scope->get_total_population ();
4162
4205
}
4163
4206
)
4164
- )
4207
+ ),
4208
+ &issue
4165
4209
);
4166
4210
}
4167
4211
@@ -4171,15 +4215,18 @@ bool ConditionManager::setup_conditions() {
4171
4215
_parse_condition_node_value_callback<fixed_point_t , COUNTRY>,
4172
4216
_execute_condition_node_cast_argument_callback<fixed_point_t , scope_t , scope_t , scope_t >(
4173
4217
_execute_condition_node_convert_scope<CountryInstance, scope_t , scope_t , fixed_point_t >(
4174
- [&pop_type ](
4218
+ [](
4175
4219
Condition const & condition, InstanceManager const & instance_manager,
4176
4220
CountryInstance const * current_scope, scope_t this_scope, scope_t from_scope, fixed_point_t argument
4177
4221
) -> bool {
4222
+ PopType const & pop_type = *static_cast <PopType const *>(condition.get_condition_data ());
4223
+
4178
4224
return current_scope->get_pop_type_proportion (pop_type) >=
4179
4225
argument * current_scope->get_total_population ();
4180
4226
}
4181
4227
)
4182
- )
4228
+ ),
4229
+ &pop_type
4183
4230
);
4184
4231
}
4185
4232
@@ -4192,14 +4239,17 @@ bool ConditionManager::setup_conditions() {
4192
4239
_parse_condition_node_value_callback<integer_t , COUNTRY>,
4193
4240
_execute_condition_node_cast_argument_callback<integer_t , scope_t , scope_t , scope_t >(
4194
4241
_execute_condition_node_convert_scope<CountryInstance, scope_t , scope_t , integer_t >(
4195
- [&technology ](
4242
+ [](
4196
4243
Condition const & condition, InstanceManager const & instance_manager,
4197
4244
CountryInstance const * current_scope, scope_t this_scope, scope_t from_scope, integer_t argument
4198
4245
) -> bool {
4246
+ Technology const & technology = *static_cast <Technology const *>(condition.get_condition_data ());
4247
+
4199
4248
return current_scope->is_technology_unlocked (technology) == (argument != 0 );
4200
4249
}
4201
4250
)
4202
- )
4251
+ ),
4252
+ &technology
4203
4253
);
4204
4254
}
4205
4255
0 commit comments