aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
author wvpm <24685035+wvpm@users.noreply.github.com>2024-09-22 15:16:35 +0200
committer wvpm <24685035+wvpm@users.noreply.github.com>2024-09-22 15:16:35 +0200
commitcf3bbdfddaf05f0439e9aeb6cce9d2bef5b47f53 (patch)
treebe61fd166f76a4ec92fd0fb3e324fb188171509b /src/openvic-simulation/map
parentd7f839a887ef6a19c935a59cad2697712d3b948a (diff)
Convert pops to equivalents & calculate rgo size
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/MapInstance.cpp8
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.cpp67
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.hpp8
3 files changed, 70 insertions, 13 deletions
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp
index 7c529bc..0b5286f 100644
--- a/src/openvic-simulation/map/MapInstance.cpp
+++ b/src/openvic-simulation/map/MapInstance.cpp
@@ -94,13 +94,15 @@ bool MapInstance::apply_history_to_provinces(
if (history_map != nullptr) {
ProvinceHistoryEntry const* pop_history_entry = nullptr;
+ ProductionType const* rgo_production_type = nullptr;
for (auto const& [entry_date, entry] : history_map->get_entries()) {
if (entry_date > date) {
break;
}
- province.apply_history_to_province(*entry, country_manager, production_type_manager);
+ rgo_production_type = entry->get_rgo_production_type();
+ province.apply_history_to_province(*entry, country_manager);
if (!entry->get_pops().empty()) {
pop_history_entry = entry.get();
@@ -112,6 +114,10 @@ bool MapInstance::apply_history_to_provinces(
province.setup_pop_test_values(issue_manager);
}
+
+ if(rgo_production_type != nullptr) {
+ province.setup_rgo(*rgo_production_type);
+ }
}
}
}
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp
index d35c44e..9e7fd6e 100644
--- a/src/openvic-simulation/map/ProvinceInstance.cpp
+++ b/src/openvic-simulation/map/ProvinceInstance.cpp
@@ -8,6 +8,7 @@
#include "openvic-simulation/misc/Define.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
#include "economy/production/ResourceGatheringOperation.hpp"
+#include "pop/Pop.hpp"
#include "types/fixed_point/FixedPoint.hpp"
using namespace OpenVic;
@@ -188,7 +189,7 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) {
average_consciousness += pop.get_consciousness();
average_militancy += pop.get_militancy();
- pop_type_distribution[pop.get_type()] += pop.get_size();
+ pop_type_distribution[*pop.get_type()] += pop.get_size();
ideology_distribution += pop.get_ideologies();
culture_distribution[&pop.get_culture()] += pop.get_size();
religion_distribution[&pop.get_religion()] += pop.get_size();
@@ -203,6 +204,51 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) {
}
}
+fixed_point_t ProvinceInstance::calculate_rgo_size(ProductionType const& production_type) const {
+ 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 : 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;
+ }
+ }
+
+ if(is_worker_pop_type) {
+ total_worker_count_in_province += pop.get_size();
+ }
+ }
+
+ const fixed_point_t base_workforce_size = production_type.get_base_workforce_size();
+ //TODO: if is_farm add farm size bonus
+ //TODO: if is_mine add mine size bonus
+ return ((total_worker_count_in_province / base_workforce_size).ceil() * fixed_point_t::_1_50()).floor();
+}
+
+void ProvinceInstance::convert_rgo_worker_pops_to_equivalent(ProductionType const& 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& pop : pops) {
+ bool is_worker_pop_type = false;
+ for(Job const& job : jobs) {
+ PopType const* const job_pop_type = job.get_pop_type();
+ PopType const* old_pop_type = pop.get_type();
+ if(job_pop_type != old_pop_type) {
+ PopType const* const equivalent = old_pop_type->get_equivalent();
+ if(job_pop_type == equivalent) {
+ pop.convert_to_equivalent();
+ }
+ }
+ }
+
+ if(is_worker_pop_type) {
+ total_worker_count_in_province += pop.get_size();
+ }
+ }
+}
+
void ProvinceInstance::update_gamestate(Date today, DefineManager const& define_manager) {
for (BuildingInstance& building : buildings.get_items()) {
building.update_gamestate(today);
@@ -273,7 +319,7 @@ bool ProvinceInstance::setup(BuildingTypeManager const& building_type_manager) {
return ret;
}
-bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager, ProductionTypeManager const& production_type_manager) {
+bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager) {
bool ret = true;
constexpr auto set_optional = []<typename T>(T& target, std::optional<T> const& source) {
@@ -298,15 +344,6 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent
}
}
- ProductionType const* const rgo_production_type = entry.get_rgo_production_type();
- if(rgo_production_type != nullptr) {
- constexpr fixed_point_t size_multiplier = fixed_point_t::_1();
- rgo = new ResourceGatheringOperation {
- rgo_production_type,
- size_multiplier
- };
- }
-
set_optional(life_rating, entry.get_life_rating());
set_optional(terrain_type, entry.get_terrain_type());
for (auto const& [building, level] : entry.get_province_buildings()) {
@@ -326,6 +363,14 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent
return ret;
}
+void ProvinceInstance::setup_rgo(ProductionType const& rgo_production_type) {
+ convert_rgo_worker_pops_to_equivalent(rgo_production_type);
+ rgo = new ResourceGatheringOperation {
+ &rgo_production_type,
+ calculate_rgo_size(rgo_production_type)
+ };
+}
+
void ProvinceInstance::setup_pop_test_values(IssueManager const& issue_manager) {
for (Pop& pop : pops) {
pop.setup_pop_test_values(issue_manager);
diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp
index 5863a97..c8168a9 100644
--- a/src/openvic-simulation/map/ProvinceInstance.hpp
+++ b/src/openvic-simulation/map/ProvinceInstance.hpp
@@ -13,6 +13,7 @@
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp"
#include "economy/production/ResourceGatheringOperation.hpp"
+#include "types/fixed_point/FixedPoint.hpp"
namespace OpenVic {
@@ -101,6 +102,8 @@ namespace OpenVic {
void _add_pop(Pop&& pop);
void _update_pops(DefineManager const& define_manager);
+ fixed_point_t calculate_rgo_size(ProductionType const& production_type) const;
+ void convert_rgo_worker_pops_to_equivalent(ProductionType const& production_type);
public:
ProvinceInstance(ProvinceInstance&&) = default;
@@ -140,7 +143,10 @@ namespace OpenVic {
bool remove_unit_instance_group(UnitInstanceGroup<Branch>& group);
bool setup(BuildingTypeManager const& building_type_manager);
- bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager, ProductionTypeManager const& production_type_manager);
+ bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager);
+
+ //after history and pops!
+ void setup_rgo(ProductionType const& rgo_production_type);
void setup_pop_test_values(IssueManager const& issue_manager);
};