diff options
Diffstat (limited to 'src/openvic-simulation')
-rw-r--r-- | src/openvic-simulation/economy/FactoryProducer.cpp | 59 | ||||
-rw-r--r-- | src/openvic-simulation/economy/FactoryProducer.hpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.cpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.hpp | 2 |
4 files changed, 66 insertions, 4 deletions
diff --git a/src/openvic-simulation/economy/FactoryProducer.cpp b/src/openvic-simulation/economy/FactoryProducer.cpp index 81ebd4a..98c04b2 100644 --- a/src/openvic-simulation/economy/FactoryProducer.cpp +++ b/src/openvic-simulation/economy/FactoryProducer.cpp @@ -1,5 +1,10 @@ #include "FactoryProducer.hpp" +#include "openvic-simulation/economy/Good.hpp" +#include "openvic-simulation/pop/Pop.hpp" +#include "openvic-simulation/types/fixed_point/FixedPoint.hpp" + + using namespace OpenVic; FactoryProducer::FactoryProducer( @@ -20,7 +25,8 @@ FactoryProducer::FactoryProducer( market_spendings_yesterday { new_market_spendings_yesterday }, paychecks_yesterday { new_paychecks_yesterday }, unprofitable_days { new_unprofitable_days }, subsidised_days { new_subsidised_days }, days_without_input { new_days_without_input }, hiring_priority { new_hiring_priority }, - profit_history_current { new_profit_history_current }, daily_profit_history { std::move(new_daily_profit_history) } {} + profit_history_current { new_profit_history_current }, daily_profit_history { std::move(new_daily_profit_history) }, + employees_per_job_cache {} {} FactoryProducer::FactoryProducer(ProductionType const& new_production_type, const fixed_point_t new_size_multiplier) : FactoryProducer { new_production_type, new_size_multiplier, 0, 0, 0, {}, {}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {} } {} @@ -37,3 +43,54 @@ fixed_point_t FactoryProducer::get_average_profitability_last_seven_days() const return sum / (1 + profit_history_current); } + +void FactoryProducer::produce( + const fixed_point_t input_modifier, const fixed_point_t throughput_modifier, const fixed_point_t output_modifier +) { + fixed_point_t my_input_multiplier = input_modifier, my_throughput_multiplier = throughput_modifier, + my_output_multiplier = output_modifier; + for (Job const& job : production_type.get_jobs()) { + const fixed_point_t number_of_employees_in_job = employees_per_job_cache[&job]; + switch (job.get_effect_type()) { + case Job::effect_t::INPUT: + my_input_multiplier += job.get_effect_multiplier() * number_of_employees_in_job / + (size_multiplier * production_type.get_base_workforce_size()); + break; + case Job::effect_t::OUTPUT: + my_output_multiplier += job.get_effect_multiplier() * number_of_employees_in_job / + (size_multiplier * production_type.get_base_workforce_size()); + break; + case Job::effect_t::THROUGHPUT: + my_throughput_multiplier *= + job.get_effect_multiplier() * number_of_employees_in_job / production_type.get_base_workforce_size(); + break; + } + } + + my_input_multiplier *= my_throughput_multiplier; + my_output_multiplier *= my_throughput_multiplier; + + fixed_point_t lack_of_inputs_multiplier = 1; + for (const auto& [good, base_input_amount] : production_type.get_input_goods()) { + const fixed_point_t desired_input = base_input_amount * my_input_multiplier; + const fixed_point_t in_stock = stockpile[good]; + if (desired_input > in_stock) { + fixed_point_t relative_inputs = in_stock / desired_input; + if (relative_inputs < lack_of_inputs_multiplier) { + lack_of_inputs_multiplier = relative_inputs; + } + } + } + + if (lack_of_inputs_multiplier < 1) { + my_input_multiplier *= lack_of_inputs_multiplier; + my_output_multiplier *= lack_of_inputs_multiplier; + days_without_input++; + } + + for (const auto& [good, base_input_amount] : production_type.get_input_goods()) { + stockpile[good] -= base_input_amount * my_input_multiplier; + } + + output_quantity_yesterday = production_type.get_base_output_quantity() * my_output_multiplier; +} diff --git a/src/openvic-simulation/economy/FactoryProducer.hpp b/src/openvic-simulation/economy/FactoryProducer.hpp index 623ec48..5570b7a 100644 --- a/src/openvic-simulation/economy/FactoryProducer.hpp +++ b/src/openvic-simulation/economy/FactoryProducer.hpp @@ -13,6 +13,8 @@ namespace OpenVic { static constexpr uint8_t DAYS_OF_HISTORY = 7; using daily_profit_history_t = std::array<fixed_point_t, DAYS_OF_HISTORY>; + ordered_map<Job const*, Pop::pop_size_t> employees_per_job_cache; + uint8_t PROPERTY(profit_history_current); daily_profit_history_t PROPERTY(daily_profit_history); ProductionType const& PROPERTY(production_type); @@ -47,5 +49,8 @@ namespace OpenVic { fixed_point_t get_profitability_yesterday() const; fixed_point_t get_average_profitability_last_seven_days() const; + void produce( + const fixed_point_t input_modifier, const fixed_point_t throughput_modifier, const fixed_point_t output_modifier + ); }; } diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index 1701321..536459d 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -533,8 +533,8 @@ bool PopManager::load_pop_into_vector( *non_integer_size = true; } - if (culture != nullptr && religion != nullptr && size >= 1) { - vec.emplace_back(Pop { type, *culture, *religion, size.to_int64_t(), militancy, consciousness, rebel_type }); + if (culture != nullptr && religion != nullptr && size >= 1 && size <= std::numeric_limits<Pop::pop_size_t>::max()) { + vec.emplace_back(Pop { type, *culture, *religion, size.to_int32_t(), militancy, consciousness, rebel_type }); } else { Logger::warning( "Some pop arguments are invalid: culture = ", culture, ", religion = ", religion, ", size = ", size diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp index cdecf44..647d06d 100644 --- a/src/openvic-simulation/pop/Pop.hpp +++ b/src/openvic-simulation/pop/Pop.hpp @@ -30,7 +30,7 @@ namespace OpenVic { struct Pop { friend struct PopManager; - using pop_size_t = int64_t; + using pop_size_t = int32_t; static constexpr pop_size_t MAX_SIZE = std::numeric_limits<pop_size_t>::max(); |