diff options
Diffstat (limited to 'src/openvic-simulation/economy/production')
-rw-r--r-- | src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp | 34 | ||||
-rw-r--r-- | src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp | 4 |
2 files changed, 28 insertions, 10 deletions
diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp index ddf9d77..2413768 100644 --- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp +++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp @@ -4,6 +4,7 @@ #include "openvic-simulation/economy/production/Employee.hpp" #include "openvic-simulation/economy/production/ProductionType.hpp" +#include "openvic-simulation/economy/trading/SellResult.hpp" #include "openvic-simulation/map/ProvinceInstance.hpp" #include "openvic-simulation/map/State.hpp" #include "openvic-simulation/modifier/ModifierEffectCache.hpp" @@ -14,6 +15,7 @@ using namespace OpenVic; ResourceGatheringOperation::ResourceGatheringOperation( + MarketInstance& new_market_instance, ModifierEffectCache const& new_modifier_effect_cache, ProductionType const* new_production_type_nullable, fixed_point_t new_size_multiplier, @@ -22,7 +24,8 @@ ResourceGatheringOperation::ResourceGatheringOperation( fixed_point_t new_unsold_quantity_yesterday, std::vector<Employee>&& new_employees, decltype(employee_count_per_type_cache)::keys_t const& pop_type_keys -) : modifier_effect_cache { new_modifier_effect_cache }, +) : market_instance { new_market_instance }, + modifier_effect_cache { new_modifier_effect_cache }, location_ptr { nullptr }, production_type_nullable { new_production_type_nullable }, revenue_yesterday { new_revenue_yesterday }, @@ -39,9 +42,11 @@ ResourceGatheringOperation::ResourceGatheringOperation( { } ResourceGatheringOperation::ResourceGatheringOperation( + MarketInstance& new_market_instance, ModifierEffectCache const& new_modifier_effect_cache, decltype(employee_count_per_type_cache)::keys_t const& pop_type_keys ) : ResourceGatheringOperation { + new_market_instance, new_modifier_effect_cache, nullptr, fixed_point_t::_0(), fixed_point_t::_0(), fixed_point_t::_0(), @@ -146,15 +151,24 @@ void ResourceGatheringOperation::rgo_tick() { owner_pops_cache, total_owner_count_in_state_cache ); - - revenue_yesterday = output_quantity_yesterday * production_type.get_output_good().get_base_price(); //TODO sell on market - - pay_employees( - revenue_yesterday, - total_worker_count_in_province, - owner_pops_cache, - total_owner_count_in_state_cache - ); + market_instance.place_market_sell_order({ + production_type.get_output_good(), + output_quantity_yesterday, + [ + this, + total_worker_count_in_province, + owner_pops_cache = std::move(owner_pops_cache), + total_owner_count_in_state_cache + ](const SellResult sell_result) mutable -> void { + revenue_yesterday = sell_result.get_money_gained(); + pay_employees( + revenue_yesterday, + total_worker_count_in_province, + owner_pops_cache, + total_owner_count_in_state_cache + ); + } + }); } void ResourceGatheringOperation::hire(const Pop::pop_size_t available_worker_count) { diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp index 4b87cb4..fae454b 100644 --- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp +++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp @@ -2,6 +2,7 @@ #include "openvic-simulation/economy/production/Employee.hpp" #include "openvic-simulation/economy/production/ProductionType.hpp" +#include "openvic-simulation/economy/trading/MarketInstance.hpp" #include "openvic-simulation/modifier/ModifierEffectCache.hpp" #include "openvic-simulation/pop/Pop.hpp" #include "openvic-simulation/types/fixed_point/FixedPoint.hpp" @@ -12,6 +13,7 @@ namespace OpenVic { struct ResourceGatheringOperation { private: + MarketInstance& market_instance; ModifierEffectCache const& modifier_effect_cache; ProvinceInstance* location_ptr; ProductionType const* PROPERTY_RW(production_type_nullable); @@ -42,6 +44,7 @@ namespace OpenVic { public: ResourceGatheringOperation( + MarketInstance& new_market_instance, ModifierEffectCache const& new_modifier_effect_cache, ProductionType const* new_production_type_nullable, fixed_point_t new_size_multiplier, @@ -53,6 +56,7 @@ namespace OpenVic { ); ResourceGatheringOperation( + MarketInstance& new_market_instance, ModifierEffectCache const& new_modifier_effect_cache, decltype(employee_count_per_type_cache)::keys_t const& pop_type_keys ); |