Skip to content

Commit

Permalink
Merge pull request #297 from OpenVicProject/pop_spending
Browse files Browse the repository at this point in the history
Pop needs & spending
  • Loading branch information
wvpm authored Feb 12, 2025
2 parents 28555e3 + b25fde2 commit 5f0d9af
Show file tree
Hide file tree
Showing 19 changed files with 563 additions and 203 deletions.
3 changes: 2 additions & 1 deletion src/openvic-simulation/InstanceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ InstanceManager::InstanceManager(
good_instance_manager { new_definition_manager.get_economy_manager().get_good_definition_manager() },
market_instance { new_definition_manager.get_define_manager().get_country_defines(), good_instance_manager },
artisanal_producer_factory_pattern {
market_instance,
new_definition_manager.get_modifier_manager().get_modifier_effect_cache(),
new_definition_manager.get_economy_manager().get_production_type_manager()
},
Expand Down Expand Up @@ -94,6 +93,7 @@ bool InstanceManager::setup() {
definition_manager.get_economy_manager().get_building_type_manager(),
market_instance,
definition_manager.get_modifier_manager().get_modifier_effect_cache(),
definition_manager.get_define_manager().get_pops_defines(),
definition_manager.get_pop_manager().get_stratas(),
definition_manager.get_pop_manager().get_pop_types(),
definition_manager.get_politics_manager().get_ideology_manager().get_ideologies()
Expand Down Expand Up @@ -151,6 +151,7 @@ bool InstanceManager::load_bookmark(Bookmark const* new_bookmark) {
country_instance_manager,
// TODO - the following argument is for generating test pop attributes
definition_manager.get_politics_manager().get_issue_manager(),
market_instance,
artisanal_producer_factory_pattern
);

Expand Down
24 changes: 21 additions & 3 deletions src/openvic-simulation/country/CountryInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,15 @@ bool CountryInstance::modify_invention_unlock(
return false;
}

const bool invention_was_unlocked = unlock_level > 0;
unlock_level += unlock_level_change;
if (invention_was_unlocked != (unlock_level > 0)) {
if (invention_was_unlocked) {
inventions_count--;
} else {
inventions_count++;
}
}

bool ret = true;

Expand Down Expand Up @@ -1389,14 +1397,24 @@ void CountryInstance::tick(InstanceManager& instance_manager) {
//income_from_gold = country_defines.gold_to_cash_rate * sum (total_good_production * good.get_base_price()) for each good with is_money=true
}


void CountryInstance::report_pop_need_consumption(PopType const& pop_type, GoodDefinition const& good, const fixed_point_t quantity) {
//TODO
}
void CountryInstance::report_artisan_input_consumption(ProductionType const& production_type, GoodDefinition const& good, const fixed_point_t quantity) {
//TODO
}
void CountryInstance::report_artisan_output(ProductionType const& production_type, const fixed_point_t quantity) {
//TODO record artisan output
//TODO
}
void CountryInstance::report_factory_input_consumption(ProductionType const& production_type, GoodDefinition const& good, const fixed_point_t quantity) {
//TODO
}
void CountryInstance::report_factory_output(ProductionType const& production_type, const fixed_point_t quantity) {
//TODO record factory output
//TODO
}
void CountryInstance::report_rgo_output(GoodDefinition const& good, const fixed_point_t quantity) {
//TODO record rgo output
//TODO
}

CountryInstance::good_data_t& CountryInstance::get_good_data(GoodInstance const& good_instance) {
Expand Down
4 changes: 4 additions & 0 deletions src/openvic-simulation/country/CountryInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ namespace OpenVic {
/* Technology */
IndexedMap<Technology, unlock_level_t> PROPERTY(technology_unlock_levels);
IndexedMap<Invention, unlock_level_t> PROPERTY(invention_unlock_levels);
int32_t PROPERTY(inventions_count);
Technology const* PROPERTY(current_research, nullptr);
fixed_point_t PROPERTY(invested_research_points);
fixed_point_t PROPERTY(current_research_cost);
Expand Down Expand Up @@ -518,7 +519,10 @@ namespace OpenVic {
void update_gamestate(InstanceManager& instance_manager);
void tick(InstanceManager& instance_manager);

void report_pop_need_consumption(PopType const& pop_type, GoodDefinition const& good, const fixed_point_t quantity);
void report_artisan_input_consumption(ProductionType const& production_type, GoodDefinition const& good, const fixed_point_t quantity);
void report_artisan_output(ProductionType const& production_type, const fixed_point_t quantity);
void report_factory_input_consumption(ProductionType const& production_type, GoodDefinition const& good, const fixed_point_t quantity);
void report_factory_output(ProductionType const& production_type, const fixed_point_t quantity);
void report_rgo_output(GoodDefinition const& good, const fixed_point_t quantity);

Expand Down
6 changes: 3 additions & 3 deletions src/openvic-simulation/economy/GoodInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ void GoodInstance::update_next_price_limits() {
absolute_minimum_price,
price - max_price_change
);

price_inverse = fixed_point_t::_1() / price;
}

void GoodInstance::add_buy_up_to_order(GoodBuyUpToOrder&& buy_up_to_order) {
Expand Down Expand Up @@ -195,7 +197,7 @@ void GoodInstance::execute_orders() {
//sell below max_next_price
if (game_rules_manager.get_use_optimal_pricing()) {
//drop price while remaining_supply > 0 && new_price > min_next_price
while (remaining_supply > 0) {
while (remaining_supply > fixed_point_t::_0()) {
const fixed_point_t possible_price = money_left_to_spend_sum / remaining_supply;

if (possible_price >= new_price) {
Expand Down Expand Up @@ -272,8 +274,6 @@ void GoodInstance::execute_orders() {
price = new_price;
update_next_price_limits();
}

price = new_price;
}

void GoodInstance::record_price_history() {
Expand Down
2 changes: 2 additions & 0 deletions src/openvic-simulation/economy/GoodInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace OpenVic {
fixed_point_t absolute_maximum_price;
fixed_point_t absolute_minimum_price;

//TODO get from pool instead of storing as field
//only used inside execute_orders()
std::vector<fixed_point_t> quantity_bought_per_order;
std::vector<fixed_point_t> purchasing_power_per_order;
Expand All @@ -38,6 +39,7 @@ namespace OpenVic {
std::vector<GoodMarketSellOrder> market_sell_orders;

fixed_point_t PROPERTY(price);
fixed_point_t PROPERTY(price_inverse);
fixed_point_t PROPERTY(price_change_yesterday);
fixed_point_t PROPERTY(max_next_price);
fixed_point_t PROPERTY(min_next_price);
Expand Down
Loading

0 comments on commit 5f0d9af

Please sign in to comment.