11#include " FactoryProducer.hpp"
22
3+ #include < map>
4+
5+ #include " economy/Good.hpp"
6+ #include " pop/Pop.hpp"
7+ #include " types/fixed_point/FixedPoint.hpp"
8+
9+
310using namespace OpenVic ;
411
512FactoryProducer::FactoryProducer (
@@ -20,7 +27,8 @@ FactoryProducer::FactoryProducer(
2027 market_spendings_yesterday { new_market_spendings_yesterday }, paychecks_yesterday { new_paychecks_yesterday },
2128 unprofitable_days { new_unprofitable_days }, injected_days { new_injected_days },
2229 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) } {}
30+ profit_history_current { new_profit_history_current }, daily_profit_history { std::move (new_daily_profit_history) },
31+ employees_per_job_cache {} {}
2432FactoryProducer::FactoryProducer (ProductionType const & new_production_type, const fixed_point_t new_size_multiplier)
2533 : FactoryProducer { new_production_type, new_size_multiplier, 0 , 0 , 0 , {}, {}, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , {} } {}
2634
@@ -37,3 +45,54 @@ fixed_point_t FactoryProducer::get_average_profitability_last_seven_days() const
3745
3846 return sum / (1 + profit_history_current);
3947}
48+
49+ void FactoryProducer::produce (
50+ const fixed_point_t input_modifier, const fixed_point_t throughput_modifier, const fixed_point_t output_modifier
51+ ) {
52+ fixed_point_t my_input_multiplier = input_modifier, my_throughput_multiplier = throughput_modifier,
53+ my_output_multiplier = output_modifier;
54+ for (Job const & job : production_type.get_jobs ()) {
55+ const fixed_point_t number_of_employees_in_job = employees_per_job_cache[&job];
56+ switch (job.get_effect_type ()) {
57+ case Job::effect_t ::INPUT:
58+ my_input_multiplier += job.get_effect_multiplier () * number_of_employees_in_job /
59+ (size_multiplier * production_type.get_base_workforce_size ());
60+ break ;
61+ case Job::effect_t ::OUTPUT:
62+ my_output_multiplier += job.get_effect_multiplier () * number_of_employees_in_job /
63+ (size_multiplier * production_type.get_base_workforce_size ());
64+ break ;
65+ case Job::effect_t ::THROUGHPUT:
66+ my_throughput_multiplier *=
67+ job.get_effect_multiplier () * number_of_employees_in_job / production_type.get_base_workforce_size ();
68+ break ;
69+ }
70+ }
71+
72+ my_input_multiplier *= my_throughput_multiplier;
73+ my_output_multiplier *= my_throughput_multiplier;
74+
75+ fixed_point_t lack_of_inputs_multiplier = 1 ;
76+ for (const auto & [good, base_input_amount] : production_type.get_input_goods ()) {
77+ const fixed_point_t desired_input = base_input_amount * my_input_multiplier;
78+ const fixed_point_t in_stock = stockpile[good];
79+ if (desired_input > in_stock) {
80+ fixed_point_t relative_inputs = in_stock / desired_input;
81+ if (relative_inputs < lack_of_inputs_multiplier) {
82+ lack_of_inputs_multiplier = relative_inputs;
83+ }
84+ }
85+ }
86+
87+ if (lack_of_inputs_multiplier < 1 ) {
88+ my_input_multiplier *= lack_of_inputs_multiplier;
89+ my_output_multiplier *= lack_of_inputs_multiplier;
90+ days_without_input++;
91+ }
92+
93+ for (const auto & [good, base_input_amount] : production_type.get_input_goods ()) {
94+ stockpile[good] -= base_input_amount * my_input_multiplier;
95+ }
96+
97+ output_quantity_yesterday = production_type.get_base_output_quantity () * my_output_multiplier;
98+ }
0 commit comments