Skip to content

Commit c25b340

Browse files
committed
draft for factory production
1 parent e98cd1f commit c25b340

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

src/openvic-simulation/economy/FactoryProducer.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
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+
310
using namespace OpenVic;
411

512
FactoryProducer::FactoryProducer(
@@ -37,3 +44,71 @@ fixed_point_t FactoryProducer::get_average_profitability_last_seven_days() const
3744

3845
return sum / (1 + profit_history_current);
3946
}
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+
}

src/openvic-simulation/economy/FactoryProducer.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,8 @@ namespace OpenVic {
4545

4646
fixed_point_t get_profitability_yesterday() const;
4747
fixed_point_t get_average_profitability_last_seven_days() const;
48+
void produce(
49+
const fixed_point_t input_modifier, const fixed_point_t throughput_modifier, const fixed_point_t output_modifier
50+
);
4851
};
4952
}

src/openvic-simulation/pop/Pop.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace OpenVic {
3030
struct Pop {
3131
friend struct PopManager;
3232

33-
using pop_size_t = int64_t;
33+
using pop_size_t = int32_t;
3434

3535
static constexpr pop_size_t MAX_SIZE = std::numeric_limits<pop_size_t>::max();
3636

0 commit comments

Comments
 (0)