aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp66
-rw-r--r--src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp12
-rw-r--r--src/openvic-simulation/map/MapInstance.cpp2
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.cpp5
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.hpp2
5 files changed, 75 insertions, 12 deletions
diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
index 904ed38..d949582 100644
--- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
+++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
@@ -1,4 +1,5 @@
#include "ResourceGatheringOperation.hpp"
+#include <utility>
#include "openvic-simulation/pop/Pop.hpp"
#include "openvic-simulation/map/ProvinceInstance.hpp"
#include "openvic-simulation/map/TerrainType.hpp"
@@ -14,7 +15,7 @@ ResourceGatheringOperation::ResourceGatheringOperation(
fixed_point_t new_revenue_yesterday,
fixed_point_t new_output_quantity_yesterday,
fixed_point_t new_unsold_quantity_yesterday,
- ordered_map<Pop*, Pop::pop_size_t>&& new_employees
+ ordered_map<Pop const*, Pop::pop_size_t>&& new_employees
) : production_type { new_production_type },
revenue_yesterday { new_revenue_yesterday },
output_quantity_yesterday { new_output_quantity_yesterday },
@@ -29,14 +30,22 @@ ResourceGatheringOperation::ResourceGatheringOperation() : ResourceGatheringOper
, fixed_point_t::_0(), {}
} {}
-void ResourceGatheringOperation::update_size(ProvinceInstance const& location) {
+void ResourceGatheringOperation::initialise_for_new_game(ProvinceInstance const& location, ProductionType const& production_type) {
+ set_production_type(&production_type);
+ const Pop::pop_size_t total_worker_count_in_province = update_size_and_return_total_worker_count(location);
+ hire(location, total_worker_count_in_province);
+ output_quantity_yesterday = produce(location);
+ revenue_yesterday = output_quantity_yesterday * production_type.get_output_good().get_base_price(); //TODO sell on market
+}
+
+Pop::pop_size_t ResourceGatheringOperation::update_size_and_return_total_worker_count(ProvinceInstance const& location) {
+ Pop::pop_size_t total_worker_count_in_province = 0; //not counting equivalents
if(production_type == nullptr) {
size_multiplier = fixed_point_t::_0();
}
else {
ProductionType const& production_type = *(this->production_type);
std::vector<Job> const& jobs = production_type.get_jobs();
- fixed_point_t total_worker_count_in_province = 0; //not counting equivalents
for(Pop const& pop : location.get_pops()) {
bool is_worker_pop_type = false;
for(Job const& job : jobs) {
@@ -64,4 +73,55 @@ void ResourceGatheringOperation::update_size(ProvinceInstance const& location) {
}
size_multiplier = ((total_worker_count_in_province / base_workforce_size).ceil() * fixed_point_t::_1_50()).floor();
}
+ return total_worker_count_in_province;
+}
+
+void ResourceGatheringOperation::hire(ProvinceInstance const& location, Pop::pop_size_t available_worker_count) {
+ if(this->production_type == nullptr) {
+ employees.empty();
+ return;
+ }
+
+ const Pop::pop_size_t max_worker_count = production_type->get_base_workforce_size() * size_multiplier; // * size modifiers (terrain, province, tech, country, etc)
+ fixed_point_t proportion_to_hire;
+ if(max_worker_count >= available_worker_count) {
+ //hire everyone
+ proportion_to_hire = fixed_point_t::_1();
+ }
+ else {
+ //hire all pops proportionally
+ const fixed_point_t max_worker_count_real = max_worker_count, available_worker_count_real = available_worker_count;
+ proportion_to_hire = max_worker_count_real / available_worker_count_real;
+ }
+
+ ProductionType const& production_type = *(this->production_type);
+ std::vector<Job> const& jobs = production_type.get_jobs();
+ for(Pop const& pop : location.get_pops()) {
+ bool is_worker_pop_type = false;
+ for(Job const& job : jobs) {
+ if(job.get_pop_type() == pop.get_type()) {
+ is_worker_pop_type = true;
+ break;
+ }
+ }
+
+ ProductionType const& production_type = *(this->production_type);
+ std::vector<Job> const& jobs = production_type.get_jobs();
+ if(is_worker_pop_type) {
+ const Pop::pop_size_t pop_size_to_hire = (proportion_to_hire * pop.get_size()).floor().to_int32_t();
+ employees.insert(std::pair<Pop const*, Pop::pop_size_t> { &pop, pop_size_to_hire });
+ total_employees_count_cache += pop_size_to_hire;
+ }
+ }
+}
+
+fixed_point_t ResourceGatheringOperation::produce(ProvinceInstance const& location) {
+ if(this->production_type == nullptr) {
+ return fixed_point_t::_0();
+ }
+
+ ProductionType const& production_type = *(this->production_type);
+ const fixed_point_t base_workforce_size = production_type.get_base_workforce_size();
+ //TODO include modifiers, job effects, etc
+ return production_type.get_base_output_quantity() * total_employees_count_cache / base_workforce_size;
} \ No newline at end of file
diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp
index dff9f5f..125d5f2 100644
--- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp
+++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp
@@ -3,7 +3,7 @@
#include "openvic-simulation/economy/production/ProductionType.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/utility/Getters.hpp"
-#include "pop/Pop.hpp"
+#include "openvic-simulation/pop/Pop.hpp"
namespace OpenVic {
struct ResourceGatheringOperation {
@@ -13,7 +13,11 @@ namespace OpenVic {
fixed_point_t PROPERTY(output_quantity_yesterday);
fixed_point_t PROPERTY(unsold_quantity_yesterday);
fixed_point_t PROPERTY_RW(size_multiplier);
- ordered_map<Pop*, Pop::pop_size_t> PROPERTY(employees);
+ ordered_map<Pop const*, Pop::pop_size_t> PROPERTY(employees);
+ Pop::pop_size_t PROPERTY(total_employees_count_cache);
+ Pop::pop_size_t update_size_and_return_total_worker_count(ProvinceInstance const& location);
+ void hire(ProvinceInstance const& location, const Pop::pop_size_t available_worker_count);
+ fixed_point_t produce(ProvinceInstance const& location);
public:
ResourceGatheringOperation(
@@ -22,12 +26,12 @@ namespace OpenVic {
fixed_point_t new_revenue_yesterday,
fixed_point_t new_output_quantity_yesterday,
fixed_point_t new_unsold_quantity_yesterday,
- ordered_map<Pop*, Pop::pop_size_t>&& new_employees
+ ordered_map<Pop const*, Pop::pop_size_t>&& new_employees
);
ResourceGatheringOperation();
constexpr bool is_valid() const {
return production_type != nullptr;
}
- void update_size(ProvinceInstance const& location);
+ void initialise_for_new_game(ProvinceInstance const& location, ProductionType const& production_type);
};
}
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp
index f428263..3617f4a 100644
--- a/src/openvic-simulation/map/MapInstance.cpp
+++ b/src/openvic-simulation/map/MapInstance.cpp
@@ -116,7 +116,7 @@ bool MapInstance::apply_history_to_provinces(
}
if(rgo_production_type != nullptr) {
- province.setup_rgo(*rgo_production_type);
+ province.initialise_for_new_game(*rgo_production_type);
}
}
}
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp
index e2128ed..5d497c5 100644
--- a/src/openvic-simulation/map/ProvinceInstance.cpp
+++ b/src/openvic-simulation/map/ProvinceInstance.cpp
@@ -330,10 +330,9 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent
return ret;
}
-void ProvinceInstance::setup_rgo(ProductionType const& rgo_production_type) {
+void ProvinceInstance::initialise_for_new_game(ProductionType const& rgo_production_type) {
convert_rgo_worker_pops_to_equivalent(rgo_production_type);
- rgo.set_production_type(&rgo_production_type);
- rgo.update_size(*this);
+ rgo.initialise_for_new_game(*this,rgo_production_type);
}
void ProvinceInstance::setup_pop_test_values(IssueManager const& issue_manager) {
diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp
index 7e2754f..cea1c0a 100644
--- a/src/openvic-simulation/map/ProvinceInstance.hpp
+++ b/src/openvic-simulation/map/ProvinceInstance.hpp
@@ -140,7 +140,7 @@ namespace OpenVic {
bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager);
//after history and pops!
- void setup_rgo(ProductionType const& rgo_production_type);
+ void initialise_for_new_game(ProductionType const& rgo_production_type);
void setup_pop_test_values(IssueManager const& issue_manager);
};