21
21
#include " openvic-simulation/types/UnitVariant.hpp"
22
22
#include " openvic-simulation/utility/Getters.hpp"
23
23
#include " openvic-simulation/utility/Containers.hpp"
24
+ #include " openvic-simulation/utility/reactive/DerivedState.hpp"
25
+ #include " openvic-simulation/utility/reactive/MutableState.hpp"
24
26
25
27
#include " openvic-simulation/types/IndexedFlatMapMacro.hpp" // below other imports that undef the macros
26
28
@@ -100,7 +102,7 @@ namespace OpenVic {
100
102
GameRulesManager const & game_rules_manager;
101
103
CountryRelationManager& country_relations_manager;
102
104
CountryDefines const & country_defines;
103
- SharedCountryValues const & shared_country_values;
105
+ SharedCountryValues& shared_country_values;
104
106
105
107
colour_t PROPERTY (colour); // Cached to avoid searching government overrides for every province
106
108
ProvinceInstance* PROPERTY_PTR (capital, nullptr );
@@ -115,7 +117,6 @@ namespace OpenVic {
115
117
country_status_t PROPERTY (country_status, country_status_t ::COUNTRY_STATUS_UNCIVILISED);
116
118
fixed_point_t PROPERTY (civilisation_progress);
117
119
Date PROPERTY (lose_great_power_date);
118
- fixed_point_t PROPERTY (total_score);
119
120
size_t PROPERTY (total_rank, 0 );
120
121
121
122
ordered_set<ProvinceInstance*> PROPERTY (owned_provinces);
@@ -132,7 +133,7 @@ namespace OpenVic {
132
133
memory::vector<ModifierInstance> PROPERTY (event_modifiers);
133
134
134
135
/* Production */
135
- fixed_point_t PROPERTY ( industrial_power);
136
+ STATE_PROPERTY ( fixed_point_t , industrial_power);
136
137
memory::vector<std::pair<State const *, fixed_point_t >> PROPERTY (industrial_power_from_states);
137
138
memory::vector<std::pair<CountryInstance const *, fixed_point_t >> PROPERTY (industrial_power_from_investments);
138
139
size_t PROPERTY (industrial_rank, 0 );
@@ -142,20 +143,19 @@ namespace OpenVic {
142
143
143
144
/* Budget */
144
145
// TODO - cash stockpile change over last 30 days
145
- fixed_point_t PROPERTY ( gold_income);
146
+ STATE_PROPERTY ( fixed_point_t , gold_income);
146
147
atomic_fixed_point_t PROPERTY (cash_stockpile);
147
148
std::mutex taxable_income_mutex;
148
149
IndexedFlatMap_PROPERTY (PopType, fixed_point_t , taxable_income_by_pop_type);
149
- fixed_point_t PROPERTY (tax_efficiency);
150
- IndexedFlatMap_PROPERTY (Strata, fixed_point_t , effective_tax_rate_by_strata);
150
+ STATE_PROPERTY (fixed_point_t , tax_efficiency);
151
+ IndexedFlatMap<Strata, DerivedState<fixed_point_t >> PROPERTY (effective_tax_rate_by_strata);
152
+ public:
153
+ DerivedState<fixed_point_t >& get_effective_tax_rate_by_strata (Strata const & strata);
154
+ private:
151
155
IndexedFlatMap_PROPERTY (Strata, SliderValue, tax_rate_slider_value_by_strata);
152
156
153
- fixed_point_t PROPERTY (administrative_efficiency_from_administrators);
154
- constexpr fixed_point_t get_corruption_cost_multiplier () const {
155
- return 2 - administrative_efficiency_from_administrators;
156
- }
157
- fixed_point_t PROPERTY (administrator_percentage);
158
- fixed_point_t PROPERTY (desired_administrator_percentage);
157
+ STATE_PROPERTY (fixed_point_t , administrative_efficiency_from_administrators);
158
+ STATE_PROPERTY (fixed_point_t , administrator_percentage);
159
159
160
160
// store per slider per good: desired, bought & cost
161
161
// store purchase record from last tick and prediction next tick
@@ -164,64 +164,64 @@ namespace OpenVic {
164
164
SliderValue PROPERTY (construction_spending_slider_value);
165
165
166
166
SliderValue PROPERTY (administration_spending_slider_value);
167
- fixed_point_t PROPERTY (actual_administration_spending );
168
- fixed_point_t PROPERTY (projected_administration_spending_unscaled_by_slider );
167
+ STATE_PROPERTY ( fixed_point_t , projected_administration_spending_unscaled_by_slider );
168
+ STATE_PROPERTY ( fixed_point_t , actual_administration_spending );
169
169
170
170
SliderValue PROPERTY (education_spending_slider_value);
171
- fixed_point_t PROPERTY (actual_education_spending );
172
- fixed_point_t PROPERTY (projected_education_spending_unscaled_by_slider );
171
+ STATE_PROPERTY ( fixed_point_t , projected_education_spending_unscaled_by_slider );
172
+ STATE_PROPERTY ( fixed_point_t , actual_education_spending );
173
173
174
174
SliderValue PROPERTY (military_spending_slider_value);
175
- fixed_point_t PROPERTY (actual_military_spending );
176
- fixed_point_t PROPERTY (projected_military_spending_unscaled_by_slider );
175
+ STATE_PROPERTY ( fixed_point_t , projected_military_spending_unscaled_by_slider );
176
+ STATE_PROPERTY ( fixed_point_t , actual_military_spending );
177
177
178
178
SliderValue PROPERTY (social_spending_slider_value);
179
- fixed_point_t PROPERTY (actual_social_spending);
180
- fixed_point_t PROPERTY (projected_pensions_spending_unscaled_by_slider);
181
- fixed_point_t PROPERTY (projected_unemployment_subsidies_spending_unscaled_by_slider);
179
+ STATE_PROPERTY (fixed_point_t , projected_pensions_spending_unscaled_by_slider);
180
+ STATE_PROPERTY (fixed_point_t , projected_unemployment_subsidies_spending_unscaled_by_slider);
181
+ STATE_PROPERTY (fixed_point_t , actual_social_spending);
182
+
183
+ // base here means not scaled by slider or pop size
184
+ IndexedFlatMap<PopType, DerivedState<fixed_point_t >> administration_salary_base_by_pop_type;
185
+ IndexedFlatMap<PopType, DerivedState<fixed_point_t >> education_salary_base_by_pop_type;
186
+ IndexedFlatMap<PopType, DerivedState<fixed_point_t >> military_salary_base_by_pop_type;
187
+ IndexedFlatMap<PopType, DerivedState<fixed_point_t >> social_income_variant_base_by_pop_type;
182
188
183
189
SliderValue PROPERTY (tariff_rate_slider_value);
184
- fixed_point_t PROPERTY (effective_tariff_rate);
185
190
std::mutex actual_net_tariffs_mutex;
186
- fixed_point_t PROPERTY (projected_import_subsidies);
187
- fixed_point_t PROPERTY (actual_net_tariffs);
188
- constexpr bool has_import_subsidies () const {
189
- return effective_tariff_rate < fixed_point_t ::_0;
190
- }
191
+ MutableState<fixed_point_t > actual_net_tariffs;
191
192
192
193
// TODO actual factory subsidies
193
194
// projected cost is UI only and lists the different factories
194
195
195
196
/* Technology */
196
197
IndexedFlatMap_PROPERTY (Technology, technology_unlock_level_t , technology_unlock_levels);
197
198
IndexedFlatMap_PROPERTY (Invention, technology_unlock_level_t , invention_unlock_levels);
198
- int32_t PROPERTY (inventions_count, 0 );
199
- Technology const * PROPERTY (current_research, nullptr );
200
- fixed_point_t PROPERTY ( invested_research_points);
201
- fixed_point_t PROPERTY ( current_research_cost);
202
- Date PROPERTY ( expected_research_completion_date);
203
- fixed_point_t PROPERTY ( research_point_stockpile);
204
- fixed_point_t PROPERTY ( daily_research_points);
199
+ STATE_PROPERTY ( int32_t , inventions_count );
200
+ STATE_PROPERTY ( Technology const *, current_research );
201
+ STATE_PROPERTY ( fixed_point_t , invested_research_points);
202
+ STATE_PROPERTY ( fixed_point_t , current_research_cost);
203
+ STATE_PROPERTY ( Date, expected_research_completion_date);
204
+ STATE_PROPERTY ( fixed_point_t , research_point_stockpile);
205
+ STATE_PROPERTY ( fixed_point_t , daily_research_points);
205
206
fixed_point_map_t <PopType const *> PROPERTY (research_points_from_pop_types);
206
- TechnologySchool const * PROPERTY (tech_school, nullptr );
207
+ STATE_PROPERTY ( TechnologySchool const *, tech_school );
207
208
// TODO - cached possible inventions with %age chance
208
209
209
210
/* Politics */
210
- NationalValue const * PROPERTY (national_value, nullptr );
211
- GovernmentType const * PROPERTY (government_type, nullptr );
211
+ STATE_PROPERTY ( NationalValue const *, national_value );
212
+ STATE_PROPERTY ( GovernmentType const *, government_type );
212
213
Date PROPERTY (last_election);
213
- CountryParty const * PROPERTY (ruling_party, nullptr );
214
+ STATE_PROPERTY ( CountryParty const *, ruling_party );
214
215
IndexedFlatMap_PROPERTY (Ideology, fixed_point_t , upper_house_proportion_by_ideology);
215
216
IndexedFlatMap_PROPERTY (ReformGroup, Reform const *, reforms);
216
- fixed_point_t PROPERTY ( total_administrative_multiplier);
217
+ STATE_PROPERTY ( fixed_point_t , total_administrative_multiplier);
217
218
RuleSet PROPERTY (rule_set);
218
219
// TODO - national issue support distribution (for just voters and for everyone)
219
220
IndexedFlatMap_PROPERTY (GovernmentType, GovernmentType const *, flag_overrides_by_government_type);
220
- GovernmentType const * PROPERTY (flag_government_type, nullptr );
221
- fixed_point_t PROPERTY (suppression_points);
222
- fixed_point_t PROPERTY (infamy); // in 0-25+ range
223
- fixed_point_t PROPERTY (plurality); // in 0-100 range
224
- fixed_point_t PROPERTY (revanchism);
221
+ STATE_PROPERTY (fixed_point_t , suppression_points);
222
+ STATE_PROPERTY (fixed_point_t , infamy); // in 0-25+ range
223
+ STATE_PROPERTY (fixed_point_t , plurality); // in 0-100 range
224
+ STATE_PROPERTY (fixed_point_t , revanchism);
225
225
IndexedFlatMap_PROPERTY (Crime, technology_unlock_level_t , crime_unlock_levels);
226
226
// TODO - rebel movements
227
227
@@ -233,6 +233,23 @@ namespace OpenVic {
233
233
// TODO - population change over last 30 days
234
234
235
235
public:
236
+ DerivedState<GovernmentType const *> flag_government_type;
237
+ DerivedState<fixed_point_t > total_score;
238
+ DerivedState<fixed_point_t > military_power;
239
+ DerivedState<fixed_point_t > research_progress;
240
+ DerivedState<fixed_point_t > desired_administrator_percentage;
241
+ DerivedState<fixed_point_t > corruption_cost_multiplier;
242
+ DerivedState<fixed_point_t > tariff_efficiency;
243
+ DerivedState<fixed_point_t > effective_tariff_rate;
244
+ DerivedState<fixed_point_t > projected_administration_spending;
245
+ DerivedState<fixed_point_t > projected_education_spending;
246
+ DerivedState<fixed_point_t > projected_military_spending;
247
+ DerivedState<fixed_point_t > projected_social_spending;
248
+ DerivedState<fixed_point_t > projected_social_spending_unscaled_by_slider;
249
+ DerivedState<fixed_point_t > projected_import_subsidies;
250
+ DerivedState<fixed_point_t > projected_spending;
251
+ DerivedState<bool > has_import_subsidies;
252
+
236
253
fixed_point_t get_taxable_income_by_strata (Strata const & strata) const ;
237
254
// TODO - national foci
238
255
@@ -272,7 +289,7 @@ namespace OpenVic {
272
289
IndexedFlatMap_PROPERTY (GoodInstance, good_data_t , goods_data);
273
290
274
291
/* Diplomacy */
275
- fixed_point_t PROPERTY ( prestige);
292
+ STATE_PROPERTY ( fixed_point_t , prestige);
276
293
size_t PROPERTY (prestige_rank, 0 );
277
294
fixed_point_t PROPERTY (diplomatic_points);
278
295
// The last time this country lost a war, i.e. accepted a peace offer sent from their offer tab or the enemy's demand
@@ -282,10 +299,9 @@ namespace OpenVic {
282
299
// TODO - colonial power, current wars
283
300
284
301
/* Military */
285
- fixed_point_t PROPERTY (military_power);
286
- fixed_point_t PROPERTY (military_power_from_land);
287
- fixed_point_t PROPERTY (military_power_from_sea);
288
- fixed_point_t PROPERTY (military_power_from_leaders);
302
+ STATE_PROPERTY (fixed_point_t , military_power_from_land);
303
+ STATE_PROPERTY (fixed_point_t , military_power_from_sea);
304
+ STATE_PROPERTY (fixed_point_t , military_power_from_leaders);
289
305
size_t PROPERTY (military_rank, 0 );
290
306
memory::vector<LeaderInstance*> SPAN_PROPERTY (generals);
291
307
memory::vector<LeaderInstance*> SPAN_PROPERTY (admirals);
@@ -347,7 +363,7 @@ namespace OpenVic {
347
363
utility::forwardable_span<const Ideology> ideology_keys,
348
364
GameRulesManager const * new_game_rules_manager,
349
365
CountryRelationManager* new_country_relations_manager,
350
- SharedCountryValues const * new_shared_country_values,
366
+ SharedCountryValues* new_shared_country_values,
351
367
GoodInstanceManager* new_good_instance_manager,
352
368
CountryDefines const * new_country_defines,
353
369
EconomyDefines const * new_economy_defines
@@ -558,7 +574,6 @@ namespace OpenVic {
558
574
fixed_point_t calculate_research_cost (
559
575
Technology const & technology, ModifierEffectCache const & modifier_effect_cache
560
576
) const ;
561
- fixed_point_t get_research_progress () const ;
562
577
bool can_research_tech (Technology const & technology, Date today) const ;
563
578
void start_research (Technology const & technology, InstanceManager const & instance_manager);
564
579
@@ -572,45 +587,21 @@ namespace OpenVic {
572
587
573
588
private:
574
589
void _update_production (DefineManager const & define_manager);
575
- void _update_effective_tax_rate_by_strata (Strata const & strata);
576
590
void _update_budget ();
577
591
578
592
// base here means not scaled by slider or pop size
579
- constexpr fixed_point_t calculate_administration_salary_base (
580
- SharedPopTypeValues const & pop_type_values,
581
- const fixed_point_t corruption_cost_multiplier
582
- ) const {
583
- return pop_type_values.get_administration_salary_base () * corruption_cost_multiplier;
584
- }
585
- constexpr fixed_point_t calculate_education_salary_base (
586
- SharedPopTypeValues const & pop_type_values,
587
- const fixed_point_t corruption_cost_multiplier
588
- ) const {
589
- return pop_type_values.get_education_salary_base () * corruption_cost_multiplier;
590
- }
591
- constexpr fixed_point_t calculate_military_salary_base (
592
- SharedPopTypeValues const & pop_type_values,
593
- const fixed_point_t corruption_cost_multiplier
594
- ) const {
595
- return pop_type_values.get_military_salary_base () * corruption_cost_multiplier;
596
- }
597
593
fixed_point_t calculate_pensions_base (
598
594
ModifierEffectCache const & modifier_effect_cache,
599
- SharedPopTypeValues const & pop_type_values
600
- ) const ;
595
+ PopType const & pop_type
596
+ );
601
597
fixed_point_t calculate_unemployment_subsidies_base (
602
598
ModifierEffectCache const & modifier_effect_cache,
603
- SharedPopTypeValues const & pop_type_values
604
- ) const ;
599
+ PopType const & pop_type
600
+ );
605
601
fixed_point_t calculate_minimum_wage_base (
606
602
ModifierEffectCache const & modifier_effect_cache,
607
- SharedPopTypeValues const & pop_type_values
608
- ) const ;
609
- constexpr fixed_point_t calculate_social_income_variant_base (
610
- SharedPopTypeValues const & pop_type_values
611
- ) const {
612
- return administrative_efficiency_from_administrators * pop_type_values.get_social_income_variant_base ();
613
- }
603
+ PopType const & pop_type
604
+ );
614
605
615
606
// Expects current_research to be non-null
616
607
void _update_current_tech (InstanceManager const & instance_manager);
@@ -652,8 +643,8 @@ namespace OpenVic {
652
643
void report_input_consumption (ProductionType const & production_type, GoodDefinition const & good, const fixed_point_t quantity);
653
644
void report_input_demand (ProductionType const & production_type, GoodDefinition const & good, const fixed_point_t quantity);
654
645
void report_output (ProductionType const & production_type, const fixed_point_t quantity);
655
- void request_salaries_and_welfare_and_import_subsidies (Pop& pop) const ;
656
- fixed_point_t calculate_minimum_wage_base (PopType const & pop_type) const ;
646
+ void request_salaries_and_welfare_and_import_subsidies (Pop& pop);
647
+ fixed_point_t calculate_minimum_wage_base (PopType const & pop_type);
657
648
fixed_point_t apply_tariff (const fixed_point_t money_spent_on_imports);
658
649
};
659
650
0 commit comments