11#include " FactoryProducer.hpp"
22
3+ #include " openvic-simulation/economy/Good.hpp"
4+ #include " openvic-simulation/pop/Pop.hpp"
5+ #include " openvic-simulation/types/fixed_point/FixedPoint.hpp"
6+
7+
38using namespace OpenVic ;
49
510FactoryProducer::FactoryProducer (
@@ -20,7 +25,8 @@ FactoryProducer::FactoryProducer(
2025 market_spendings_yesterday { new_market_spendings_yesterday }, paychecks_yesterday { new_paychecks_yesterday },
2126 unprofitable_days { new_unprofitable_days }, injected_days { new_injected_days },
2227 days_without_input { new_days_without_input }, hiring_priority { new_hiring_priority },
23- profit_history_current { new_profit_history_current }, daily_profit_history { std::move (new_daily_profit_history) } {}
28+ profit_history_current { new_profit_history_current }, daily_profit_history { std::move (new_daily_profit_history) },
29+ employees_per_job_cache {} {}
2430FactoryProducer::FactoryProducer (ProductionType const & new_production_type, const fixed_point_t new_size_multiplier)
2531 : FactoryProducer { new_production_type, new_size_multiplier, 0 , 0 , 0 , {}, {}, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , {} } {}
2632
@@ -37,3 +43,54 @@ fixed_point_t FactoryProducer::get_average_profitability_last_seven_days() const
3743
3844 return sum / (1 + profit_history_current);
3945}
46+
47+ void FactoryProducer::produce (
48+ const fixed_point_t input_modifier, const fixed_point_t throughput_modifier, const fixed_point_t output_modifier
49+ ) {
50+ fixed_point_t my_input_multiplier = input_modifier, my_throughput_multiplier = throughput_modifier,
51+ my_output_multiplier = output_modifier;
52+ for (Job const & job : production_type.get_jobs ()) {
53+ const fixed_point_t number_of_employees_in_job = employees_per_job_cache[&job];
54+ switch (job.get_effect_type ()) {
55+ case Job::effect_t ::INPUT:
56+ my_input_multiplier += job.get_effect_multiplier () * number_of_employees_in_job /
57+ (size_multiplier * production_type.get_base_workforce_size ());
58+ break ;
59+ case Job::effect_t ::OUTPUT:
60+ my_output_multiplier += job.get_effect_multiplier () * number_of_employees_in_job /
61+ (size_multiplier * production_type.get_base_workforce_size ());
62+ break ;
63+ case Job::effect_t ::THROUGHPUT:
64+ my_throughput_multiplier *=
65+ job.get_effect_multiplier () * number_of_employees_in_job / production_type.get_base_workforce_size ();
66+ break ;
67+ }
68+ }
69+
70+ my_input_multiplier *= my_throughput_multiplier;
71+ my_output_multiplier *= my_throughput_multiplier;
72+
73+ fixed_point_t lack_of_inputs_multiplier = 1 ;
74+ for (const auto & [good, base_input_amount] : production_type.get_input_goods ()) {
75+ const fixed_point_t desired_input = base_input_amount * my_input_multiplier;
76+ const fixed_point_t in_stock = stockpile[good];
77+ if (desired_input > in_stock) {
78+ fixed_point_t relative_inputs = in_stock / desired_input;
79+ if (relative_inputs < lack_of_inputs_multiplier) {
80+ lack_of_inputs_multiplier = relative_inputs;
81+ }
82+ }
83+ }
84+
85+ if (lack_of_inputs_multiplier < 1 ) {
86+ my_input_multiplier *= lack_of_inputs_multiplier;
87+ my_output_multiplier *= lack_of_inputs_multiplier;
88+ days_without_input++;
89+ }
90+
91+ for (const auto & [good, base_input_amount] : production_type.get_input_goods ()) {
92+ stockpile[good] -= base_input_amount * my_input_multiplier;
93+ }
94+
95+ output_quantity_yesterday = production_type.get_base_output_quantity () * my_output_multiplier;
96+ }
0 commit comments