|
1 | 1 | #include "FactoryProducer.hpp" |
2 | 2 |
|
| 3 | +#include <map> |
| 4 | + |
| 5 | +#include "economy/Good.hpp" |
| 6 | +#include "pop/Pop.hpp" |
| 7 | +#include "types/fixed_point/FixedPoint.hpp" |
| 8 | + |
| 9 | + |
3 | 10 | using namespace OpenVic; |
4 | 11 |
|
5 | 12 | FactoryProducer::FactoryProducer( |
@@ -37,3 +44,71 @@ fixed_point_t FactoryProducer::get_average_profitability_last_seven_days() const |
37 | 44 |
|
38 | 45 | return sum / (1 + profit_history_current); |
39 | 46 | } |
| 47 | + |
| 48 | +void FactoryProducer::produce( |
| 49 | + const fixed_point_t input_modifier, const fixed_point_t throughput_modifier, const fixed_point_t output_modifier |
| 50 | +) { |
| 51 | + std::map<PopType const* const, fixed_point_t> employees_per_job {}; |
| 52 | + for (const Job job : production_type.get_jobs()) { |
| 53 | + PopType const* const pop_type = job.get_pop_type(); |
| 54 | + employees_per_job[pop_type] = 0; |
| 55 | + } |
| 56 | + |
| 57 | + for (std::pair<Pop const* const, const fixed_point_t> pop_and_number_employed : employees) { |
| 58 | + Pop const* const pop = pop_and_number_employed.first; |
| 59 | + const fixed_point_t number_employed = pop_and_number_employed.second; |
| 60 | + PopType const* const pop_type = &(pop->get_type()); |
| 61 | + employees_per_job[pop_type] += number_employed; |
| 62 | + } |
| 63 | + |
| 64 | + fixed_point_t my_input_multiplier = input_modifier, my_throughput_multiplier = throughput_modifier, |
| 65 | + my_output_multiplier = output_modifier; |
| 66 | + for (const Job job : production_type.get_jobs()) { |
| 67 | + PopType const* const pop_type = job.get_pop_type(); |
| 68 | + const fixed_point_t number_of_employees_in_job = employees_per_job[pop_type]; |
| 69 | + switch (job.get_effect_type()) { |
| 70 | + case Job::effect_t::INPUT: |
| 71 | + my_input_multiplier += job.get_effect_multiplier() * number_of_employees_in_job / |
| 72 | + (size_multiplier * production_type.get_base_workforce_size()); |
| 73 | + break; |
| 74 | + case Job::effect_t::OUTPUT: |
| 75 | + my_output_multiplier += job.get_effect_multiplier() * number_of_employees_in_job / |
| 76 | + (size_multiplier * production_type.get_base_workforce_size()); |
| 77 | + break; |
| 78 | + case Job::effect_t::THROUGHPUT: |
| 79 | + my_throughput_multiplier *= |
| 80 | + job.get_effect_multiplier() * number_of_employees_in_job / production_type.get_base_workforce_size(); |
| 81 | + break; |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + my_input_multiplier *= my_throughput_multiplier; |
| 86 | + my_output_multiplier *= my_throughput_multiplier; |
| 87 | + |
| 88 | + fixed_point_t lack_of_inputs_multiplier = 1; |
| 89 | + for (std::pair<Good const* const, const fixed_point_t> good_and_input : production_type.get_input_goods()) { |
| 90 | + Good const* const good = good_and_input.first; |
| 91 | + const fixed_point_t desired_input = good_and_input.second * my_input_multiplier; |
| 92 | + const fixed_point_t in_stock = stockpile[good]; |
| 93 | + if (desired_input > in_stock) { |
| 94 | + fixed_point_t relative_inputs = in_stock / desired_input; |
| 95 | + if (relative_inputs < lack_of_inputs_multiplier) { |
| 96 | + lack_of_inputs_multiplier = relative_inputs; |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + if (lack_of_inputs_multiplier < 1) { |
| 102 | + my_input_multiplier *= lack_of_inputs_multiplier; |
| 103 | + my_output_multiplier *= lack_of_inputs_multiplier; |
| 104 | + days_without_input++; |
| 105 | + } |
| 106 | + |
| 107 | + for (std::pair<Good const* const, const fixed_point_t> good_and_input : production_type.get_input_goods()) { |
| 108 | + Good const* const good = good_and_input.first; |
| 109 | + const fixed_point_t desired_input = good_and_input.second * my_input_multiplier; |
| 110 | + stockpile[good] -= desired_input; |
| 111 | + } |
| 112 | + |
| 113 | + output_quantity_yesterday = production_type.get_base_output_quantity() * my_output_multiplier; |
| 114 | +} |
0 commit comments