Skip to content

Commit

Permalink
steps to account for multiple commodities being defined as money
Browse files Browse the repository at this point in the history
  • Loading branch information
schombert committed Jan 7, 2024
1 parent 839a0b7 commit 96e45da
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/economy/economy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ void update_province_rgo_production(sys::state& state, dcon::province_id p, dcon
assert(amount * state.world.commodity_get_current_price(c) >= 0);
state.world.province_set_rgo_full_profit(p, amount * state.world.commodity_get_current_price(c));

if(c == money) {
if(c.get_money_rgo()) {
assert(std::isfinite(amount * state.defines.gold_to_cash_rate) && amount * state.defines.gold_to_cash_rate >= 0.0f);
state.world.nation_get_stockpiles(n, money) += amount * state.defines.gold_to_cash_rate;
}
Expand Down Expand Up @@ -2804,6 +2804,9 @@ void daily_update(sys::state& state) {

concurrency::parallel_for(uint32_t(1), total_commodities, [&](uint32_t k) {
dcon::commodity_id cid{dcon::commodity_id::value_base_t(k)};
if(state.world.commodity_get_rgo_amount(cid))
return;

float total_r_demand = 0.0f;
float total_consumption = 0.0f;
float total_production = 0.0f;
Expand Down Expand Up @@ -3220,7 +3223,7 @@ float estimate_gold_income(sys::state& state, dcon::nation_id n) {
auto amount = 0.f;
for(auto poid : state.world.nation_get_province_ownership_as_nation(n)) {
auto prov = poid.get_province();
if(prov.get_rgo().id == economy::money) {
if(prov.get_rgo().get_money_rgo()) {
amount += province::rgo_production_quantity(state, prov.id);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/gamestate/dcon_generated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ object {
type{ bitfield }
tag{ scenario }
}
property{
name{ money_rgo }
type{ bitfield }
tag{ scenario }
}
property{
name{ is_mine }
type{ bitfield }
Expand Down
40 changes: 23 additions & 17 deletions src/parsing/parsers_declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,31 @@ void culture_group::union_tag(association_type, uint32_t v, error_handler& err,

void good::money(association_type, bool v, error_handler& err, int32_t line, good_context& context) {
if(v) {
context.outer_context.state.world.commodity_set_color(economy::money,
context.outer_context.state.world.commodity_get_color(context.id));
context.outer_context.state.world.commodity_set_cost(economy::money,
context.outer_context.state.world.commodity_get_cost(context.id));
context.outer_context.state.world.commodity_set_commodity_group(economy::money,
context.outer_context.state.world.commodity_get_commodity_group(context.id));
context.outer_context.state.world.commodity_set_name(economy::money,
context.outer_context.state.world.commodity_get_name(context.id));
context.outer_context.state.world.commodity_set_is_available_from_start(economy::money,
context.outer_context.state.world.commodity_get_is_available_from_start(context.id));

for(auto& pr : context.outer_context.map_of_commodity_names) {
if(pr.second == context.id) {
pr.second = economy::money;
break;
if(context.outer_context.money_set) {
context.outer_context.state.world.commodity_set_money_rgo(context.id, true);
} else {
context.outer_context.state.world.commodity_set_color(economy::money,
context.outer_context.state.world.commodity_get_color(context.id));
context.outer_context.state.world.commodity_set_cost(economy::money,
context.outer_context.state.world.commodity_get_cost(context.id));
context.outer_context.state.world.commodity_set_commodity_group(economy::money,
context.outer_context.state.world.commodity_get_commodity_group(context.id));
context.outer_context.state.world.commodity_set_name(economy::money,
context.outer_context.state.world.commodity_get_name(context.id));
context.outer_context.state.world.commodity_set_is_available_from_start(economy::money,
context.outer_context.state.world.commodity_get_is_available_from_start(context.id));
context.outer_context.state.world.commodity_set_money_rgo(economy::money, true);

for(auto& pr : context.outer_context.map_of_commodity_names) {
if(pr.second == context.id) {
pr.second = economy::money;
break;
}
}
context.id = economy::money;
context.outer_context.state.world.pop_back_commodity();
context.outer_context.money_set = true;
}
context.id = economy::money;
context.outer_context.state.world.pop_back_commodity();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/parsing/parsers_declarations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ struct scenario_building_context {
int32_t number_of_commodities_seen = 0;
int32_t number_of_national_values_seen = 0;
bool new_maps = false;
bool money_set = false;
};

struct national_identity_file {
Expand Down

0 comments on commit 96e45da

Please sign in to comment.