aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/economy/production/ArtisanalProducer.cpp
diff options
context:
space:
mode:
author wvpm <24685035+wvpm@users.noreply.github.com>2024-11-04 13:17:55 +0100
committer wvpm <24685035+wvpm@users.noreply.github.com>2024-11-04 14:38:19 +0100
commitc12e742ca980d7213e2bc08b902b63117aea54f6 (patch)
treed128c5f6abe32904b9a5a2a03718ace64c85c2e2 /src/openvic-simulation/economy/production/ArtisanalProducer.cpp
parent89e9c05f4d6276efa82fe486156357f841f864c3 (diff)
Implement artisanal productionartisanal_production
Diffstat (limited to 'src/openvic-simulation/economy/production/ArtisanalProducer.cpp')
-rw-r--r--src/openvic-simulation/economy/production/ArtisanalProducer.cpp66
1 files changed, 59 insertions, 7 deletions
diff --git a/src/openvic-simulation/economy/production/ArtisanalProducer.cpp b/src/openvic-simulation/economy/production/ArtisanalProducer.cpp
index d5cc3d3..2613d12 100644
--- a/src/openvic-simulation/economy/production/ArtisanalProducer.cpp
+++ b/src/openvic-simulation/economy/production/ArtisanalProducer.cpp
@@ -1,13 +1,65 @@
#include "ArtisanalProducer.hpp"
+#include "openvic-simulation/economy/GoodDefinition.hpp"
+#include "openvic-simulation/economy/trading/BuyResult.hpp"
+#include "openvic-simulation/economy/trading/SellResult.hpp"
+
using namespace OpenVic;
ArtisanalProducer::ArtisanalProducer(
+ MarketInstance& new_market_instance,
+ ModifierEffectCache const& new_modifier_effect_cache,
+ Pop& new_pop,
+ Pop::pop_size_t new_previous_pop_size,
+ fixed_point_t new_inputs_bought_scalar,
ProductionType const& new_production_type,
- GoodDefinition::good_definition_map_t&& new_stockpile,
- fixed_point_t new_current_production,
- GoodDefinition::good_definition_map_t&& new_current_needs
-) : production_type { new_production_type },
- stockpile { std::move(new_stockpile) },
- current_production { new_current_production },
- current_needs { std::move(new_current_needs) } {}
+ fixed_point_t new_current_production
+) : market_instance { new_market_instance },
+ modifier_effect_cache { new_modifier_effect_cache },
+ pop { new_pop },
+ previous_pop_size { new_previous_pop_size },
+ inputs_bought_scalar { new_inputs_bought_scalar },
+ production_type { new_production_type },
+ current_production { new_current_production }
+ {}
+
+void ArtisanalProducer::artisan_tick() {
+ current_production = production_type.get_base_output_quantity()
+ * inputs_bought_scalar
+ * previous_pop_size / production_type.get_base_workforce_size();
+
+ GoodDefinition const& output_good = production_type.get_output_good();
+ if (current_production > 0) {
+ market_instance.place_market_sell_order({
+ output_good,
+ current_production,
+ [this](const SellResult sell_result) -> void {
+ //TODO add artisanal income to pop (part of https://github.com/OpenVicProject/OpenVic-Simulation/issues/225 )
+ }
+ });
+ }
+
+ const fixed_point_t total_cash_to_spend = pop.get_cash();
+ if (production_type.get_input_goods().empty()) {
+ inputs_bought_scalar = fixed_point_t::_1();
+ }
+ else if (total_cash_to_spend > 0) {
+ int input_goods_count = static_cast<int>(production_type.get_input_goods().size());
+ for (auto const& [input_good_ptr, base_desired_quantity] : production_type.get_input_goods()) {
+ const fixed_point_t money_to_spend = total_cash_to_spend / input_goods_count;
+ const fixed_point_t desired_quantity = base_desired_quantity * pop.get_size() / production_type.get_base_workforce_size();
+ //TODO pop cash -= money_to_spend
+ market_instance.place_buy_up_to_order({
+ *input_good_ptr,
+ desired_quantity,
+ money_to_spend,
+ [this, desired_quantity](const BuyResult buy_result) -> void {
+ //TODO pop cash += buy_result.get_money_left()
+ inputs_bought_scalar = std::min(inputs_bought_scalar, buy_result.get_quantity_bought() / desired_quantity);
+ }
+ });
+ }
+ }
+
+ previous_pop_size = pop.get_size();
+} \ No newline at end of file