Skip to content

Commit 351988a

Browse files
adjust gdp calculation
1 parent 90e19e3 commit 351988a

File tree

6 files changed

+45
-19
lines changed

6 files changed

+45
-19
lines changed

assets/localisation/en-US/alice.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,8 @@ alice_pnt_dominant_religion;?YDominant religion:?! $x$
13071307
alice_pnt_dominant_ideology;?YDominant Ideology:?! $x$
13081308
ledger_ppp_gdp;GDP(PPP)
13091309
ledger_ppp_gdp_per_capita;GDP(PPP) per 1m people
1310+
ledger_inflation_adjusted_gdp;GDP(inflation-adjusted)
1311+
ledger_inflation_adjusted_gdp_per_capita;GDP(inflation-adjusted) per 1m people
13101312
ledger_standard_of_living;Standard of Living
13111313
alice_ledger_header_gdp_history;GDP(PPP) over time
13121314
alice_countryalert_colonialgood_start;You can colonize $region$

src/economy/economy.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,22 @@ int32_t previous_gdp_record_index(sys::state& state) {
158158
return ((date.year * 4 + date.month / 3) + gdp_history_length - 1) % gdp_history_length;
159159
}
160160

161-
float ideal_pound_conversion_rate(sys::state& state, dcon::market_id n) {
162-
return state.world.market_get_life_needs_costs(n, state.culture_definitions.primary_factory_worker)
163-
+ 0.1f * state.world.market_get_everyday_needs_costs(n, state.culture_definitions.primary_factory_worker);
161+
float ideal_pound_to_real_pound(sys::state& state) {
162+
auto cost_of_needs = 0.f;
163+
uint32_t total_commodities = state.world.commodity_size();
164+
auto worker = state.culture_definitions.primary_factory_worker;
165+
for(uint32_t i = 1; i < total_commodities; ++i) {
166+
dcon::commodity_id c{ dcon::commodity_id::value_base_t(i) };
167+
auto price = state.world.commodity_get_median_price(c);
168+
auto life_base = state.world.pop_type_get_life_needs(worker, c);
169+
auto everyday_base = state.world.pop_type_get_everyday_needs(worker, c);
170+
cost_of_needs += price * (life_base + 0.1f * everyday_base);
171+
}
172+
return cost_of_needs;
164173
}
165174

166175
float gdp(sys::state& state, dcon::market_id n) {
167-
float raw = state.world.market_get_gdp(n);
168-
//float ideal_pound = ideal_pound_conversion_rate(state, n);
169-
return raw; /// ideal_pound;
176+
return state.world.market_get_gdp(n);
170177
}
171178

172179
float gdp(sys::state& state, dcon::nation_id n) {
@@ -179,6 +186,17 @@ float gdp(sys::state& state, dcon::nation_id n) {
179186
return total;
180187
}
181188

189+
float gdp_adjusted(sys::state& state, dcon::nation_id n) {
190+
auto conversion = ideal_pound_to_real_pound(state);
191+
auto total = 0.f;
192+
state.world.nation_for_each_state_ownership(n, [&](auto soid) {
193+
auto sid = state.world.state_ownership_get_state(soid);
194+
auto market = state.world.state_instance_get_market_from_local_market(sid);
195+
total = total + economy::gdp(state, market);
196+
});
197+
return total / conversion;
198+
}
199+
182200
struct spending_cost {
183201
float construction;
184202
float other;

src/economy/economy.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ int32_t previous_gdp_record_index(sys::state& state);
335335

336336
float gdp(sys::state& state, dcon::nation_id n);
337337
float gdp(sys::state& state, dcon::market_id n);
338+
float gdp_adjusted(sys::state& state, dcon::nation_id n);
338339

339340
void prune_factories(sys::state& state); // get rid of closed factories in full states
340341
void go_bankrupt(sys::state& state, dcon::nation_id n);

src/gamestate/system_state.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4540,7 +4540,7 @@ void state::single_game_tick() {
45404540
if(((ymd_date.month % 3) == 0) && (ymd_date.day == 1)) {
45414541
auto index = economy::most_recent_gdp_record_index(*this);
45424542
for(auto n : world.in_nation) {
4543-
n.set_gdp_record(index, economy::gdp(*this, n));
4543+
n.set_gdp_record(index, economy::gdp_adjusted(*this, n));
45444544
}
45454545
}
45464546

src/gui/gui_common_elements.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,15 @@ class nation_total_score_text : public standard_nation_text {
645645
class nation_ppp_gdp_text : public standard_nation_text {
646646
public:
647647
std::string get_text(sys::state& state, dcon::nation_id nation_id) noexcept override {
648-
return text::format_float(economy::gdp(state, nation_id));
648+
return text::format_float(economy::gdp_adjusted(state, nation_id));
649649
}
650650
};
651651

652652
class nation_ppp_gdp_per_capita_text : public standard_nation_text {
653653
public:
654654
std::string get_text(sys::state& state, dcon::nation_id nation_id) noexcept override {
655655
float population = state.world.nation_get_demographics(nation_id, demographics::total);
656-
return text::format_float(economy::gdp(state, nation_id) / population * 1000000.f);
656+
return text::format_float(economy::gdp_adjusted(state, nation_id) / population * 1000000.f);
657657
}
658658
};
659659

src/gui/gui_ledger_window.hpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ class ledger_nation_ranking_buttons : public window_element_base {
172172
}
173173
{
174174
auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::gdp);
175-
ptr->set_button_text(state, text::produce_simple_string(state, "ledger_ppp_gdp"));
175+
ptr->set_button_text(state, text::produce_simple_string(state, "ledger_inflation_adjusted_gdp"));
176176
apply_offset(ptr);
177177
add_child_to_front(std::move(ptr));
178178
}
179179
{
180180
auto ptr = make_element_by_type<ledger_generic_sort_button>(state, button_def, ledger_sort_type::gdp_capita);
181-
ptr->set_button_text(state, text::produce_simple_string(state, "ledger_ppp_gdp_per_capita"));
181+
ptr->set_button_text(state, text::produce_simple_string(state, "ledger_inflation_adjusted_gdp_per_capita"));
182182
apply_offset(ptr);
183183
add_child_to_front(std::move(ptr));
184184
}
@@ -253,14 +253,14 @@ class ledger_nation_ranking_entry : public listbox_row_element_base<dcon::nation
253253
apply_offset(ptr);
254254
add_child_to_front(std::move(ptr));
255255
}
256-
// GDP PPP
256+
// GDP (inflation adjusted)
257257
{
258258
auto ptr = make_element_by_type<nation_ppp_gdp_text>(state,
259259
state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
260260
apply_offset(ptr);
261261
add_child_to_front(std::move(ptr));
262262
}
263-
// GDP PPP per capita
263+
// GDP (inflation adjusted) per capita
264264
{
265265
auto ptr = make_element_by_type<nation_ppp_gdp_per_capita_text>(state,
266266
state.ui_state.defs_by_name.find(state.lookup_key("ledger_default_textbox"))->second.definition);
@@ -356,18 +356,18 @@ class ledger_nation_ranking_listbox : public listbox_element_base<ledger_nation_
356356
float b_population = state.world.nation_get_demographics(b, demographics::total);
357357

358358
if(lsort.reversed) {
359-
return economy::gdp(state, a) / a_population < economy::gdp(state, b) / b_population;
359+
return economy::gdp_adjusted(state, a) / a_population < economy::gdp_adjusted(state, b) / b_population;
360360
} else {
361-
return economy::gdp(state, a) / a_population > economy::gdp(state, b) / b_population;
361+
return economy::gdp_adjusted(state, a) / a_population > economy::gdp_adjusted(state, b) / b_population;
362362
}
363363
});
364364
break;
365365
case ledger_sort_type::gdp:
366366
std::sort(row_contents.begin(), row_contents.end(), [&](dcon::nation_id a, dcon::nation_id b) {
367367
if(lsort.reversed) {
368-
return economy::gdp(state, a) < economy::gdp(state, b);
368+
return economy::gdp_adjusted(state, a) < economy::gdp_adjusted(state, b);
369369
} else {
370-
return economy::gdp(state, a) > economy::gdp(state, b);
370+
return economy::gdp_adjusted(state, a) > economy::gdp_adjusted(state, b);
371371
}
372372
});
373373
break;
@@ -2165,8 +2165,12 @@ class all_prices_graph : public window_element_base {
21652165
if((*ptr).data[commodity.index()]) {
21662166
for(uint32_t i = 0; i < graph_length; ++i) {
21672167
auto price = state.world.commodity_get_price_record(commodity, (newest_index + economy::price_history_length - graph_length + i + 1) % economy::price_history_length);
2168-
if(price > max) {
2169-
max = price;
2168+
auto log_price = log(price + 0.0001f);
2169+
if(log_price > max) {
2170+
max = log_price;
2171+
}
2172+
if (log_price < min) {
2173+
min = log_price;
21702174
}
21712175
}
21722176
}
@@ -2182,6 +2186,7 @@ class all_prices_graph : public window_element_base {
21822186

21832187
for(uint32_t i = 0; i < graph_length; ++i) {
21842188
datapoints[i] = state.world.commodity_get_price_record(commodity, (newest_index + economy::price_history_length - graph_length + i + 1) % economy::price_history_length);
2189+
datapoints[i] = log(datapoints[i] + 0.0001f);
21852190
}
21862191
graph_per_price[commodity.index()]->set_data_points(state, datapoints, min, max);
21872192
}

0 commit comments

Comments
 (0)