aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openvic-simulation/InstanceManager.cpp8
-rw-r--r--src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp154
-rw-r--r--src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp17
-rw-r--r--src/openvic-simulation/map/MapInstance.cpp33
-rw-r--r--src/openvic-simulation/map/MapInstance.hpp10
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.cpp29
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.hpp9
-rw-r--r--src/openvic-simulation/map/State.cpp27
-rw-r--r--src/openvic-simulation/map/State.hpp2
9 files changed, 165 insertions, 124 deletions
diff --git a/src/openvic-simulation/InstanceManager.cpp b/src/openvic-simulation/InstanceManager.cpp
index 670cbfc..4f388b0 100644
--- a/src/openvic-simulation/InstanceManager.cpp
+++ b/src/openvic-simulation/InstanceManager.cpp
@@ -61,7 +61,7 @@ void InstanceManager::tick() {
Logger::info("Tick: ", today);
// Tick...
- map_instance.tick(today);
+ map_instance.map_tick(today, definition_manager.get_modifier_manager().get_modifier_effect_cache());
set_gamestate_needs_update();
}
@@ -140,7 +140,11 @@ bool InstanceManager::load_bookmark(Bookmark const* new_bookmark) {
if (ret) {
update_modifier_sums();
- map_instance.initialise_for_new_game(definition_manager.get_modifier_manager().get_modifier_effect_cache());
+ map_instance.initialise_for_new_game(
+ today,
+ definition_manager.get_define_manager(),
+ definition_manager.get_modifier_manager().get_modifier_effect_cache()
+ );
}
return ret;
diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
index 70cb64d..7f030ab 100644
--- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
+++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
@@ -41,47 +41,23 @@ ResourceGatheringOperation::ResourceGatheringOperation(decltype(employee_count_p
fixed_point_t::_0(), {}, pop_type_keys
} {}
-void ResourceGatheringOperation::initialise_for_new_game(ProvinceInstance& location, ModifierEffectCache const& modifier_effect_cache) {
- if (production_type_nullable == nullptr) {
- output_quantity_yesterday = 0;
- revenue_yesterday = 0;
- return;
- }
-
- ProductionType const& production_type = *production_type_nullable;
- const fixed_point_t size_modifier = calculate_size_modifier(location, modifier_effect_cache);
- const Pop::pop_size_t total_worker_count_in_province = update_size_and_return_total_worker_count(location, modifier_effect_cache, size_modifier);
- hire(location, total_worker_count_in_province);
- Pop::pop_size_t total_owner_count_in_state_cache = 0;
- std::vector<Pop*> owner_pops_cache {};
- output_quantity_yesterday = produce(location, owner_pops_cache, total_owner_count_in_state_cache, modifier_effect_cache, size_modifier);
- revenue_yesterday = output_quantity_yesterday * production_type.get_output_good().get_base_price(); //TODO sell on market
- pay_employees(location, revenue_yesterday, total_worker_count_in_province, owner_pops_cache, total_owner_count_in_state_cache);
-}
-
-Pop::pop_size_t ResourceGatheringOperation::update_size_and_return_total_worker_count(
+void ResourceGatheringOperation::initialise_rgo_size_multiplier(
ProvinceInstance& location,
- ModifierEffectCache const& modifier_effect_cache,
- const fixed_point_t size_modifier
+ ModifierEffectCache const& modifier_effect_cache
) {
if (production_type_nullable == nullptr) {
size_multiplier = fixed_point_t::_0();
max_employee_count_cache = fixed_point_t::_0();
- return fixed_point_t::_0();
+ return;
}
- Pop::pop_size_t total_worker_count_in_province = 0; //not counting equivalents
ProductionType const& production_type = *production_type_nullable;
std::vector<Job> const& jobs = production_type.get_jobs();
- //can't use pop_type_distribution as it is not filled correctly yet (possibly due to equivalent pop type conversion)
- for (Pop const& pop : location.get_pops()){
- PopType const* pop_type = pop.get_type();
- for(Job const& job : jobs) {
- if (job.get_pop_type() == pop_type) {
- total_worker_count_in_province += pop.get_size();
- break;
- }
- }
+ IndexedMap<PopType, Pop::pop_size_t> const& province_pop_type_distribution = location.get_pop_type_distribution();
+
+ Pop::pop_size_t total_worker_count_in_province = 0; //not counting equivalents
+ for(Job const& job : jobs) {
+ total_worker_count_in_province += province_pop_type_distribution[*job.get_pop_type()];
}
fixed_point_t base_size_modifier = fixed_point_t::_1();
@@ -98,8 +74,9 @@ Pop::pop_size_t ResourceGatheringOperation::update_size_and_return_total_worker_
} else {
size_multiplier = ((total_worker_count_in_province / (base_size_modifier * base_workforce_size)).ceil() * fixed_point_t::_1_50()).floor();
}
+
+ const fixed_point_t size_modifier = calculate_size_modifier(location, modifier_effect_cache);
max_employee_count_cache = (size_modifier * size_multiplier * base_workforce_size).floor();
- return total_worker_count_in_province;
}
fixed_point_t ResourceGatheringOperation::calculate_size_modifier(ProvinceInstance const& location, ModifierEffectCache const& modifier_effect_cache) const {
@@ -123,6 +100,51 @@ fixed_point_t ResourceGatheringOperation::calculate_size_modifier(ProvinceInstan
return size_modifier > fixed_point_t::_0() ? size_modifier : fixed_point_t::_0();
}
+void ResourceGatheringOperation::rgo_tick(ProvinceInstance& location, ModifierEffectCache const& modifier_effect_cache) {
+ if (production_type_nullable == nullptr | location.get_owner() == nullptr) {
+ output_quantity_yesterday = 0;
+ revenue_yesterday = 0;
+ return;
+ }
+
+ ProductionType const& production_type = *production_type_nullable;
+ std::vector<Job> const& jobs = production_type.get_jobs();
+ IndexedMap<PopType, Pop::pop_size_t> const& province_pop_type_distribution = location.get_pop_type_distribution();
+
+ Pop::pop_size_t total_worker_count_in_province = 0; //not counting equivalents
+ for(Job const& job : jobs) {
+ total_worker_count_in_province += province_pop_type_distribution[*job.get_pop_type()];
+ }
+
+ hire(location, total_worker_count_in_province);
+
+ Pop::pop_size_t total_owner_count_in_state_cache = 0;
+ std::vector<Pop*> const* owner_pops_cache = nullptr;
+
+ if (production_type.get_owner().has_value()) {
+ PopType const& owner_pop_type = *production_type.get_owner()->get_pop_type();
+ total_owner_count_in_state_cache = location.get_state()->get_pop_type_distribution()[owner_pop_type];
+ owner_pops_cache = &location.get_mutable_state()->get_mutable_pops_cache_by_type()[owner_pop_type];
+ }
+
+ output_quantity_yesterday = produce(
+ location,
+ owner_pops_cache,
+ total_owner_count_in_state_cache,
+ modifier_effect_cache
+ );
+
+ revenue_yesterday = output_quantity_yesterday * production_type.get_output_good().get_base_price(); //TODO sell on market
+
+ pay_employees(
+ location,
+ revenue_yesterday,
+ total_worker_count_in_province,
+ owner_pops_cache,
+ total_owner_count_in_state_cache
+ );
+}
+
void ResourceGatheringOperation::hire(ProvinceInstance& location, Pop::pop_size_t available_worker_count) {
total_employees_count_cache = 0;
total_paid_employees_count_cache=0;
@@ -166,17 +188,15 @@ void ResourceGatheringOperation::hire(ProvinceInstance& location, Pop::pop_size_
fixed_point_t ResourceGatheringOperation::produce(
ProvinceInstance& location,
- std::vector<Pop*>& owner_pops_cache,
- Pop::pop_size_t& total_owner_count_in_state_cache,
- ModifierEffectCache const& modifier_effect_cache,
- const fixed_point_t size_modifier
+ std::vector<Pop*> const* const owner_pops_cache,
+ const Pop::pop_size_t total_owner_count_in_state_cache,
+ ModifierEffectCache const& modifier_effect_cache
) {
+ const fixed_point_t size_modifier = calculate_size_modifier(location, modifier_effect_cache);
if (size_modifier == fixed_point_t::_0()){
return fixed_point_t::_0();
}
- total_owner_count_in_state_cache = 0;
- owner_pops_cache = {};
if (production_type_nullable == nullptr || max_employee_count_cache <= 0) {
return fixed_point_t::_0();
}
@@ -187,35 +207,15 @@ fixed_point_t ResourceGatheringOperation::produce(
std::optional<Job> const& owner = production_type.get_owner();
if (owner.has_value()) {
- Job const& owner_job = owner.value();
- PopType const* owner_job_pop_type_nullable = owner_job.get_pop_type();
- if (owner_job_pop_type_nullable == nullptr) {
- Logger::error("Owner job for ", production_type.get_identifier(), " has nullptr as pop_type.");
- return fixed_point_t::_0();
- }
- PopType const& owner_pop_type = *owner_job_pop_type_nullable;
- State const* state_nullable = location.get_state();
- if (state_nullable == nullptr) {
+ State const* state_ptr = location.get_state();
+ if (state_ptr == nullptr) {
Logger::error("Province ", location.get_identifier(), " has no state.");
return fixed_point_t::_0();
}
- State const& state = *state_nullable;
- Pop::pop_size_t state_population = 0; //state.get_total_population() is not filled yet
- std::vector<ProvinceInstance*> const& provinces_in_state = state.get_provinces();
- for (ProvinceInstance* const province_nullable : provinces_in_state) {
- if (province_nullable == nullptr) {
- Logger::error("State ", state.get_identifier(), " has nullptr in provinces.");
- return fixed_point_t::_0();
- }
- ProvinceInstance& province = *province_nullable;
- for (Pop& pop : province.get_mutable_pops()){
- state_population += pop.get_size();
- if (&owner_pop_type == pop.get_type()) {
- owner_pops_cache.push_back(&pop);
- total_owner_count_in_state_cache += pop.get_size();
- }
- }
- }
+
+ State const& state = *state_ptr;
+ const Pop::pop_size_t state_population = state.get_total_population();
+ Job const& owner_job = owner.value();
if (total_owner_count_in_state_cache > 0) {
switch (owner_job.get_effect_type()) {
@@ -293,32 +293,27 @@ void ResourceGatheringOperation::pay_employees(
ProvinceInstance& location,
const fixed_point_t revenue,
const Pop::pop_size_t total_worker_count_in_province,
- std::vector<Pop*>& owner_pops_cache,
+ std::vector<Pop*> const* const owner_pops_cache,
const Pop::pop_size_t total_owner_count_in_state_cache
) {
total_owner_income_cache = 0;
total_employee_income_cache = 0;
- if (production_type_nullable == nullptr || revenue <= 0 || total_worker_count_in_province <= 0) {
+ if (revenue <= 0 || total_worker_count_in_province <= 0) {
if (revenue < 0) { Logger::error("Negative revenue for province ", location.get_identifier()); }
if (total_worker_count_in_province < 0) { Logger::error("Negative total worker count for province ", location.get_identifier()); }
return;
}
-
- ProductionType const& production_type = *production_type_nullable;
fixed_point_t revenue_left = revenue;
- if (total_owner_count_in_state_cache > 0) {
- Job const& owner_job = production_type.get_owner().value();
- PopType const* owner_job_pop_type_nullable = owner_job.get_pop_type();
-
+ if (total_owner_count_in_state_cache > 0) {
fixed_point_t owner_share = (fixed_point_t::_2() * total_owner_count_in_state_cache / total_worker_count_in_province);
constexpr fixed_point_t upper_limit = fixed_point_t::_0_50();
if (owner_share > upper_limit) {
owner_share = upper_limit;
}
- for(Pop* owner_pop_nullable : owner_pops_cache) {
- Pop& owner_pop = *owner_pop_nullable;
+ for(Pop* owner_pop_ptr : *owner_pops_cache) {
+ Pop& owner_pop = *owner_pop_ptr;
const fixed_point_t income_for_this_pop = revenue_left * owner_share * owner_pop.get_size() / total_owner_count_in_state_cache;
owner_pop.add_rgo_owner_income(income_for_this_pop);
total_owner_income_cache += income_for_this_pop;
@@ -329,13 +324,14 @@ void ResourceGatheringOperation::pay_employees(
if (total_paid_employees_count_cache > 0) {
for (Employee& employee : employees) {
Pop& employee_pop = employee.pop;
- PopType const* employee_pop_type_nullable = employee_pop.get_type();
- if (employee_pop_type_nullable == nullptr) {
+
+ PopType const* employee_pop_type = employee_pop.get_type();
+ if (employee_pop_type == nullptr) {
Logger::error("employee has nullptr pop_type.");
return;
}
- PopType const& employee_pop_type = *employee_pop_type_nullable;
- if (employee_pop_type.get_is_slave()) {
+
+ if (employee_pop_type->get_is_slave()) {
continue;
}
diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp
index a15e87d..5079603 100644
--- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp
+++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp
@@ -23,25 +23,19 @@ namespace OpenVic {
fixed_point_t PROPERTY(total_employee_income_cache);
IndexedMap<PopType, Pop::pop_size_t> PROPERTY(employee_count_per_type_cache);
- Pop::pop_size_t update_size_and_return_total_worker_count(
- ProvinceInstance& location,
- ModifierEffectCache const& modifier_effect_cache,
- const fixed_point_t size_modifier
- );
fixed_point_t calculate_size_modifier(ProvinceInstance const& location, ModifierEffectCache const& modifier_effect_cache) const;
void hire(ProvinceInstance& location, const Pop::pop_size_t available_worker_count);
fixed_point_t produce(
ProvinceInstance& location,
- std::vector<Pop*>& owner_pops_cache,
- Pop::pop_size_t& total_owner_count_in_state_cache,
- ModifierEffectCache const& modifier_effect_cache,
- const fixed_point_t size_modifier
+ std::vector<Pop*> const* const owner_pops_cache,
+ const Pop::pop_size_t total_owner_count_in_state_cache,
+ ModifierEffectCache const& modifier_effect_cache
);
void pay_employees(
ProvinceInstance& location,
const fixed_point_t revenue,
const Pop::pop_size_t total_worker_count_in_province,
- std::vector<Pop*>& owner_pops_cache,
+ std::vector<Pop*> const* const owner_pops_cache,
const Pop::pop_size_t total_owner_count_in_state_cache
);
@@ -59,6 +53,7 @@ namespace OpenVic {
constexpr bool is_valid() const {
return production_type_nullable != nullptr;
}
- void initialise_for_new_game(ProvinceInstance& location, ModifierEffectCache const& modifier_effect_cache);
+ void initialise_rgo_size_multiplier(ProvinceInstance& location, ModifierEffectCache const& modifier_effect_cache);
+ void rgo_tick(ProvinceInstance& location, ModifierEffectCache const& modifier_effect_cache);
};
}
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp
index 4a4a1e5..240bec5 100644
--- a/src/openvic-simulation/map/MapInstance.cpp
+++ b/src/openvic-simulation/map/MapInstance.cpp
@@ -81,7 +81,7 @@ bool MapInstance::setup(
}
bool MapInstance::apply_history_to_provinces(
- ProvinceHistoryManager const& history_manager, Date date, CountryInstanceManager& country_manager,
+ ProvinceHistoryManager const& history_manager, const Date date, CountryInstanceManager& country_manager,
IssueManager const& issue_manager
) {
bool ret = true;
@@ -128,41 +128,44 @@ bool MapInstance::apply_history_to_provinces(
return ret;
}
-void MapInstance::update_modifier_sums(Date today, StaticModifierCache const& static_modifier_cache) {
+void MapInstance::update_modifier_sums(const Date today, StaticModifierCache const& static_modifier_cache) {
for (ProvinceInstance& province : province_instances.get_items()) {
province.update_modifier_sum(today, static_modifier_cache);
}
}
-void MapInstance::update_gamestate(Date today, DefineManager const& define_manager) {
- for (ProvinceInstance& province : province_instances.get_items()) {
- province.update_gamestate(today, define_manager);
- }
- state_manager.update_gamestate();
-
- // Update population stats
+void MapInstance::update_gamestate(const Date today, DefineManager const& define_manager) {
highest_province_population = 0;
total_map_population = 0;
+
+ for (ProvinceInstance& province : province_instances.get_items()) {
+ province.update_gamestate(today, define_manager);
- for (ProvinceInstance const& province : province_instances.get_items()) {
+ // Update population stats
const Pop::pop_size_t province_population = province.get_total_population();
-
if (highest_province_population < province_population) {
highest_province_population = province_population;
}
total_map_population += province_population;
}
+ state_manager.update_gamestate();
}
-void MapInstance::tick(Date today) {
+void MapInstance::map_tick(const Date today, ModifierEffectCache const& modifier_effect_cache) {
for (ProvinceInstance& province : province_instances.get_items()) {
- province.tick(today);
+ province.province_tick(today, modifier_effect_cache);
}
}
-void MapInstance::initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache){
+void MapInstance::initialise_for_new_game(
+ const Date today,
+ DefineManager const& define_manager,
+ ModifierEffectCache const& modifier_effect_cache
+) {
+ update_gamestate(today, define_manager);
for (ProvinceInstance& province : province_instances.get_items()) {
- province.initialise_for_new_game(modifier_effect_cache);
+ province.initialise_rgo(modifier_effect_cache);
+ province.province_tick(today, modifier_effect_cache);
}
} \ No newline at end of file
diff --git a/src/openvic-simulation/map/MapInstance.hpp b/src/openvic-simulation/map/MapInstance.hpp
index a580c55..1ca28d2 100644
--- a/src/openvic-simulation/map/MapInstance.hpp
+++ b/src/openvic-simulation/map/MapInstance.hpp
@@ -48,13 +48,13 @@ namespace OpenVic {
decltype(ProvinceInstance::ideology_distribution)::keys_t const& ideology_keys
);
bool apply_history_to_provinces(
- ProvinceHistoryManager const& history_manager, Date date, CountryInstanceManager& country_manager,
+ ProvinceHistoryManager const& history_manager, const Date date, CountryInstanceManager& country_manager,
IssueManager const& issue_manager
);
- void update_modifier_sums(Date today, StaticModifierCache const& static_modifier_cache);
- void update_gamestate(Date today, DefineManager const& define_manager);
- void tick(Date today);
- void initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache);
+ void update_modifier_sums(const Date today, StaticModifierCache const& static_modifier_cache);
+ void update_gamestate(const Date today, DefineManager const& define_manager);
+ void map_tick(const Date today, ModifierEffectCache const& modifier_effect_cache);
+ void initialise_for_new_game(const Date today, DefineManager const& define_manager, ModifierEffectCache const& modifier_effect_cache);
};
}
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp
index b3d2df3..2c4479e 100644
--- a/src/openvic-simulation/map/ProvinceInstance.cpp
+++ b/src/openvic-simulation/map/ProvinceInstance.cpp
@@ -40,10 +40,12 @@ ProvinceInstance::ProvinceInstance(
pops {},
total_population { 0 },
pop_type_distribution { &pop_type_keys },
+ pops_cache_by_type { &pop_type_keys },
ideology_distribution { &ideology_keys },
culture_distribution {},
religion_distribution {},
- max_supported_regiments { 0 } {}
+ max_supported_regiments { 0 }
+ {}
GoodDefinition const* ProvinceInstance::get_rgo_good() const {
if (!rgo.is_valid()) { return nullptr; }
@@ -182,6 +184,10 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) {
culture_distribution.clear();
religion_distribution.clear();
+ for (PopType const& pop_type : *pops_cache_by_type.get_keys()) {
+ pops_cache_by_type[pop_type].clear();
+ }
+
max_supported_regiments = 0;
MilitaryDefines const& military_defines = define_manager.get_military_defines();
@@ -202,6 +208,7 @@ void ProvinceInstance::_update_pops(DefineManager const& define_manager) {
average_militancy += pop.get_militancy();
pop_type_distribution[*pop.get_type()] += pop.get_size();
+ pops_cache_by_type[*pop.get_type()].push_back(&pop);
ideology_distribution += pop.get_ideologies();
culture_distribution[&pop.get_culture()] += pop.get_size();
religion_distribution[&pop.get_religion()] += pop.get_size();
@@ -354,17 +361,21 @@ bool ProvinceInstance::convert_rgo_worker_pops_to_equivalent(ProductionType cons
return is_valid_operation;
}
-void ProvinceInstance::update_gamestate(Date today, DefineManager const& define_manager) {
+void ProvinceInstance::update_gamestate(const Date today, DefineManager const& define_manager) {
for (BuildingInstance& building : buildings.get_items()) {
building.update_gamestate(today);
}
_update_pops(define_manager);
}
-void ProvinceInstance::tick(Date today) {
+void ProvinceInstance::province_tick(const Date today, ModifierEffectCache const& modifier_effect_cache) {
for (BuildingInstance& building : buildings.get_items()) {
building.tick(today);
}
+ rgo.rgo_tick(
+ *this,
+ modifier_effect_cache
+ );
}
template<UnitType::branch_t Branch>
@@ -468,8 +479,8 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent
return ret;
}
-void ProvinceInstance::initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache) {
- rgo.initialise_for_new_game(*this, modifier_effect_cache);
+void ProvinceInstance::initialise_rgo(ModifierEffectCache const& modifier_effect_cache) {
+ rgo.initialise_rgo_size_multiplier(*this, modifier_effect_cache);
}
void ProvinceInstance::setup_pop_test_values(IssueManager const& issue_manager) {
@@ -478,6 +489,14 @@ void ProvinceInstance::setup_pop_test_values(IssueManager const& issue_manager)
}
}
+State* ProvinceInstance::get_mutable_state() {
+ return state;
+}
+
plf::colony<Pop>& ProvinceInstance::get_mutable_pops() {
return pops;
+}
+
+IndexedMap<PopType, std::vector<Pop*>>& ProvinceInstance::get_mutable_pops_cache_by_type() {
+ return pops_cache_by_type;
} \ No newline at end of file
diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp
index ba800a9..ec83af4 100644
--- a/src/openvic-simulation/map/ProvinceInstance.hpp
+++ b/src/openvic-simulation/map/ProvinceInstance.hpp
@@ -96,6 +96,7 @@ namespace OpenVic {
fixed_point_t PROPERTY(average_consciousness);
fixed_point_t PROPERTY(average_militancy);
IndexedMap<PopType, Pop::pop_size_t> PROPERTY(pop_type_distribution);
+ IndexedMap<PopType, std::vector<Pop*>> PROPERTY(pops_cache_by_type);
IndexedMap<Ideology, fixed_point_t> PROPERTY(ideology_distribution);
fixed_point_map_t<Culture const*> PROPERTY(culture_distribution);
fixed_point_map_t<Religion const*> PROPERTY(religion_distribution);
@@ -148,8 +149,8 @@ namespace OpenVic {
) const;
std::vector<ModifierSum::modifier_entry_t> get_contributing_modifiers(ModifierEffect const& effect) const;
- void update_gamestate(Date today, DefineManager const& define_manager);
- void tick(Date today);
+ void update_gamestate(const Date today, DefineManager const& define_manager);
+ void province_tick(const Date today, ModifierEffectCache const& modifier_effect_cache);
template<UnitType::branch_t Branch>
bool add_unit_instance_group(UnitInstanceGroup<Branch>& group);
@@ -159,9 +160,11 @@ namespace OpenVic {
bool setup(BuildingTypeManager const& building_type_manager);
bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager);
- void initialise_for_new_game(ModifierEffectCache const& modifier_effect_cache);
+ void initialise_rgo(ModifierEffectCache const& modifier_effect_cache);
void setup_pop_test_values(IssueManager const& issue_manager);
+ State* get_mutable_state();
plf::colony<Pop>& get_mutable_pops();
+ IndexedMap<PopType, std::vector<Pop*>>& get_mutable_pops_cache_by_type();
};
}
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp
index 31ea05f..2951c22 100644
--- a/src/openvic-simulation/map/State.cpp
+++ b/src/openvic-simulation/map/State.cpp
@@ -23,8 +23,10 @@ State::State(
provinces { std::move(new_provinces) },
colony_status { new_colony_status },
pop_type_distribution { &pop_type_keys },
+ pops_cache_by_type { &pop_type_keys },
industrial_power { 0 },
- max_supported_regiments { 0 } {}
+ max_supported_regiments { 0 }
+ {}
std::string State::get_identifier() const {
return StringUtils::append_string_views(
@@ -41,7 +43,11 @@ void State::update_gamestate() {
pop_type_distribution.clear();
max_supported_regiments = 0;
- for (ProvinceInstance const* province : provinces) {
+ for (PopType const& pop_type : *pops_cache_by_type.get_keys()) {
+ pops_cache_by_type[pop_type].clear();
+ }
+
+ for (ProvinceInstance const* const province : provinces) {
total_population += province->get_total_population();
// TODO - change casting if Pop::pop_size_t changes type
@@ -51,7 +57,16 @@ void State::update_gamestate() {
average_militancy += province->get_average_militancy() * province_population;
pop_type_distribution += province->get_pop_type_distribution();
-
+ IndexedMap<PopType, std::vector<Pop*>> const& province_pops_cache_by_type = province->get_pops_cache_by_type();
+ for (PopType const& pop_type : *province_pops_cache_by_type.get_keys()) {
+ std::vector<Pop*> const& province_pops_of_type = province_pops_cache_by_type[pop_type];
+ std::vector<Pop*>& state_pops_of_type = pops_cache_by_type[pop_type];
+ state_pops_of_type.insert(
+ state_pops_of_type.end(),
+ province_pops_of_type.begin(),
+ province_pops_of_type.end()
+ );
+ }
max_supported_regiments += province->get_max_supported_regiments();
}
@@ -81,6 +96,10 @@ void State::update_gamestate() {
industrial_power = total_factory_levels_in_state * workforce_scalar;
}
+IndexedMap<PopType, std::vector<Pop*>>& State::get_mutable_pops_cache_by_type() {
+ return pops_cache_by_type;
+}
+
/* Whether two provinces in the same region should be grouped into the same state or not.
* (Assumes both provinces non-null.) */
static bool provinces_belong_in_same_state(ProvinceInstance const* lhs, ProvinceInstance const* rhs) {
@@ -198,4 +217,4 @@ void StateManager::update_gamestate() {
for (StateSet& state_set : state_sets) {
state_set.update_gamestate();
}
-}
+} \ No newline at end of file
diff --git a/src/openvic-simulation/map/State.hpp b/src/openvic-simulation/map/State.hpp
index a39eea6..5ca31a1 100644
--- a/src/openvic-simulation/map/State.hpp
+++ b/src/openvic-simulation/map/State.hpp
@@ -30,6 +30,7 @@ namespace OpenVic {
fixed_point_t PROPERTY(average_consciousness);
fixed_point_t PROPERTY(average_militancy);
IndexedMap<PopType, Pop::pop_size_t> PROPERTY(pop_type_distribution);
+ IndexedMap<PopType, std::vector<Pop*>> PROPERTY(pops_cache_by_type);
fixed_point_t PROPERTY(industrial_power);
@@ -48,6 +49,7 @@ namespace OpenVic {
std::string get_identifier() const;
void update_gamestate();
+ IndexedMap<PopType, std::vector<Pop*>>& get_mutable_pops_cache_by_type();
};
struct Region;