Skip to content

Commit 4b41a21

Browse files
authored
Merge pull request #545 from OpenVicProject/track_balance_history
Track balance history for countries
2 parents d04b04a + 7762c63 commit 4b41a21

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/openvic-simulation/country/CountryInstance.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ CountryInstance::CountryInstance(
7070
building_type_unlock_levels { building_type_keys },
7171

7272
/* Budget */
73+
balance_history{30, 0},
7374
taxable_income_by_pop_type { pop_type_keys },
7475
effective_tax_rate_by_strata {
7576
strata_keys,
@@ -1835,7 +1836,7 @@ void CountryInstance::country_tick_before_map(InstanceManager& instance_manager)
18351836
// + industrial subsidies
18361837
// + loan interest
18371838

1838-
fixed_point_t available_funds = cash_stockpile;
1839+
fixed_point_t available_funds = cache_stockpile_start_of_tick = cash_stockpile;
18391840
fixed_point_t actual_import_subsidies;
18401841
const fixed_point_t projected_administration_spending_copy = projected_administration_spending.get_untracked();
18411842
const fixed_point_t projected_education_spending_copy = projected_education_spending.get_untracked();
@@ -1979,6 +1980,8 @@ void CountryInstance::country_tick_after_map(InstanceManager& instance_manager)
19791980
const fixed_point_t gold_income_value = country_defines.get_gold_to_cash_rate() * total_gold_production;;
19801981
gold_income.set(gold_income_value);
19811982
cash_stockpile += gold_income_value;
1983+
const fixed_point_t yesterdays_balance = cash_stockpile - cache_stockpile_start_of_tick;
1984+
balance_history.push_back(yesterdays_balance);
19821985
}
19831986

19841987
CountryInstance::good_data_t::good_data_t()

src/openvic-simulation/country/CountryInstance.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "openvic-simulation/types/TechnologyUnlockLevel.hpp"
2020
#include "openvic-simulation/types/UnitBranchType.hpp"
2121
#include "openvic-simulation/types/UnitVariant.hpp"
22+
#include "openvic-simulation/types/ValueHistory.hpp"
2223
#include "openvic-simulation/utility/Getters.hpp"
2324
#include "openvic-simulation/utility/Containers.hpp"
2425
#include "openvic-simulation/utility/reactive/DerivedState.hpp"
@@ -142,7 +143,8 @@ namespace OpenVic {
142143
// TODO - total amount of each good produced
143144

144145
/* Budget */
145-
// TODO - cash stockpile change over last 30 days
146+
fixed_point_t cache_stockpile_start_of_tick;
147+
ValueHistory<fixed_point_t> PROPERTY(balance_history);
146148
STATE_PROPERTY(fixed_point_t, gold_income);
147149
atomic_fixed_point_t PROPERTY(cash_stockpile);
148150
std::mutex taxable_income_mutex;

0 commit comments

Comments
 (0)