Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/lexy-vdf
2 changes: 1 addition & 1 deletion deps/openvic-dataloader
2 changes: 1 addition & 1 deletion scripts
Submodule scripts updated 1 files
+3 −15 tools/windows.py
59 changes: 58 additions & 1 deletion src/openvic-simulation/economy/FactoryProducer.cpp
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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, {} } {}

Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine the country calls some method on each state, which calls this method for each factory.
The country & state create the modifier values here.

) {
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;
}
5 changes: 5 additions & 0 deletions src/openvic-simulation/economy/FactoryProducer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
);
};
}
4 changes: 2 additions & 2 deletions src/openvic-simulation/pop/Pop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/pop/Pop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down