aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author wvpm <24685035+wvpm@users.noreply.github.com>2024-11-03 22:23:39 +0100
committer wvpm <24685035+wvpm@users.noreply.github.com>2024-11-03 22:39:01 +0100
commit4eba08af501560e9139a562c53fbbc8b694fb4cf (patch)
treee9553d2f4ed09abb920921006b976c7ef4baa46c /src
parent19026ff6aee8748df4777ec044065d13460e806a (diff)
ModifierEffectCache & location to fieldsto_fields
Diffstat (limited to 'src')
-rw-r--r--src/openvic-simulation/InstanceManager.cpp6
-rw-r--r--src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp53
-rw-r--r--src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp26
-rw-r--r--src/openvic-simulation/map/MapInstance.cpp19
-rw-r--r--src/openvic-simulation/map/MapInstance.hpp5
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.cpp19
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.hpp9
-rw-r--r--src/openvic-simulation/map/State.cpp12
-rw-r--r--src/openvic-simulation/map/State.hpp6
9 files changed, 93 insertions, 62 deletions
diff --git a/src/openvic-simulation/InstanceManager.cpp b/src/openvic-simulation/InstanceManager.cpp
index 4f388b0..277b439 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.map_tick(today, definition_manager.get_modifier_manager().get_modifier_effect_cache());
+ map_instance.map_tick(today);
set_gamestate_needs_update();
}
@@ -75,6 +75,7 @@ bool InstanceManager::setup() {
bool ret = good_instance_manager.setup(definition_manager.get_economy_manager().get_good_definition_manager());
ret &= map_instance.setup(
definition_manager.get_economy_manager().get_building_type_manager(),
+ definition_manager.get_modifier_manager().get_modifier_effect_cache(),
definition_manager.get_pop_manager().get_pop_types(),
definition_manager.get_politics_manager().get_ideology_manager().get_ideologies()
);
@@ -142,8 +143,7 @@ bool InstanceManager::load_bookmark(Bookmark const* new_bookmark) {
update_modifier_sums();
map_instance.initialise_for_new_game(
today,
- definition_manager.get_define_manager(),
- definition_manager.get_modifier_manager().get_modifier_effect_cache()
+ definition_manager.get_define_manager()
);
}
diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
index 74bcabf..ddf9d77 100644
--- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
+++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.cpp
@@ -14,6 +14,7 @@
using namespace OpenVic;
ResourceGatheringOperation::ResourceGatheringOperation(
+ ModifierEffectCache const& new_modifier_effect_cache,
ProductionType const* new_production_type_nullable,
fixed_point_t new_size_multiplier,
fixed_point_t new_revenue_yesterday,
@@ -21,7 +22,9 @@ 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
-) : production_type_nullable { new_production_type_nullable },
+) : modifier_effect_cache { new_modifier_effect_cache },
+ location_ptr { nullptr },
+ production_type_nullable { new_production_type_nullable },
revenue_yesterday { new_revenue_yesterday },
output_quantity_yesterday { new_output_quantity_yesterday },
unsold_quantity_yesterday { new_unsold_quantity_yesterday },
@@ -35,22 +38,32 @@ ResourceGatheringOperation::ResourceGatheringOperation(
employee_count_per_type_cache { &pop_type_keys }
{ }
-ResourceGatheringOperation::ResourceGatheringOperation(decltype(employee_count_per_type_cache)::keys_t const& pop_type_keys) : ResourceGatheringOperation {
+ResourceGatheringOperation::ResourceGatheringOperation(
+ ModifierEffectCache const& new_modifier_effect_cache,
+ decltype(employee_count_per_type_cache)::keys_t const& pop_type_keys
+) : ResourceGatheringOperation {
+ new_modifier_effect_cache,
nullptr, fixed_point_t::_0(),
fixed_point_t::_0(), fixed_point_t::_0(),
fixed_point_t::_0(), {}, pop_type_keys
} {}
-void ResourceGatheringOperation::initialise_rgo_size_multiplier(
- ProvinceInstance& location,
- ModifierEffectCache const& modifier_effect_cache
-) {
+void ResourceGatheringOperation::setup_location_ptr(ProvinceInstance& location) {
+ if (location_ptr != nullptr) {
+ Logger::error("RGO already has a location_ptr pointing to province ", location_ptr->get_identifier());
+ }
+
+ location_ptr = &location;
+}
+
+void ResourceGatheringOperation::initialise_rgo_size_multiplier() {
if (production_type_nullable == nullptr) {
size_multiplier = fixed_point_t::_0();
max_employee_count_cache = fixed_point_t::_0();
return;
}
+ ProvinceInstance& location = *location_ptr;
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();
@@ -75,14 +88,15 @@ void ResourceGatheringOperation::initialise_rgo_size_multiplier(
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);
+ const fixed_point_t size_modifier = calculate_size_modifier();
max_employee_count_cache = (size_modifier * size_multiplier * base_workforce_size).floor();
}
-fixed_point_t ResourceGatheringOperation::calculate_size_modifier(ProvinceInstance const& location, ModifierEffectCache const& modifier_effect_cache) const {
+fixed_point_t ResourceGatheringOperation::calculate_size_modifier() const {
if (production_type_nullable == nullptr) {
return fixed_point_t::_1();
}
+ ProvinceInstance& location = *location_ptr;
ProductionType const& production_type = *production_type_nullable;
@@ -100,12 +114,13 @@ 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) {
+void ResourceGatheringOperation::rgo_tick() {
if (production_type_nullable == nullptr) {
output_quantity_yesterday = 0;
revenue_yesterday = 0;
return;
}
+ ProvinceInstance& location = *location_ptr;
ProductionType const& production_type = *production_type_nullable;
std::vector<Job> const& jobs = production_type.get_jobs();
@@ -116,7 +131,7 @@ void ResourceGatheringOperation::rgo_tick(ProvinceInstance& location, ModifierEf
total_worker_count_in_province += province_pop_type_distribution[*job.get_pop_type()];
}
- hire(location, total_worker_count_in_province);
+ hire(total_worker_count_in_province);
Pop::pop_size_t total_owner_count_in_state_cache = 0;
std::vector<Pop*>* owner_pops_cache = nullptr;
@@ -128,16 +143,13 @@ void ResourceGatheringOperation::rgo_tick(ProvinceInstance& location, ModifierEf
}
output_quantity_yesterday = produce(
- location,
owner_pops_cache,
- total_owner_count_in_state_cache,
- modifier_effect_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(
- location,
revenue_yesterday,
total_worker_count_in_province,
owner_pops_cache,
@@ -145,7 +157,7 @@ void ResourceGatheringOperation::rgo_tick(ProvinceInstance& location, ModifierEf
);
}
-void ResourceGatheringOperation::hire(ProvinceInstance& location, Pop::pop_size_t available_worker_count) {
+void ResourceGatheringOperation::hire(const Pop::pop_size_t available_worker_count) {
total_employees_count_cache = 0;
total_paid_employees_count_cache=0;
if (production_type_nullable == nullptr) {
@@ -153,6 +165,7 @@ void ResourceGatheringOperation::hire(ProvinceInstance& location, Pop::pop_size_
employee_count_per_type_cache.fill(fixed_point_t::_0());
return;
}
+ ProvinceInstance& location = *location_ptr;
ProductionType const& production_type = *production_type_nullable;
if (max_employee_count_cache <= 0) { return; }
@@ -187,12 +200,10 @@ void ResourceGatheringOperation::hire(ProvinceInstance& location, Pop::pop_size_
}
fixed_point_t ResourceGatheringOperation::produce(
- ProvinceInstance& location,
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 Pop::pop_size_t total_owner_count_in_state_cache
) {
- const fixed_point_t size_modifier = calculate_size_modifier(location, modifier_effect_cache);
+ const fixed_point_t size_modifier = calculate_size_modifier();
if (size_modifier == fixed_point_t::_0()){
return fixed_point_t::_0();
}
@@ -200,6 +211,7 @@ fixed_point_t ResourceGatheringOperation::produce(
if (production_type_nullable == nullptr || max_employee_count_cache <= 0) {
return fixed_point_t::_0();
}
+ ProvinceInstance& location = *location_ptr;
ProductionType const& production_type = *production_type_nullable;
fixed_point_t throughput_multiplier = fixed_point_t::_1();
@@ -290,12 +302,13 @@ fixed_point_t ResourceGatheringOperation::produce(
}
void ResourceGatheringOperation::pay_employees(
- ProvinceInstance& location,
const fixed_point_t revenue,
const Pop::pop_size_t total_worker_count_in_province,
std::vector<Pop*>* const owner_pops_cache,
const Pop::pop_size_t total_owner_count_in_state_cache
) {
+ ProvinceInstance& location = *location_ptr;
+
total_owner_income_cache = 0;
total_employee_income_cache = 0;
if (revenue <= 0 || total_worker_count_in_province <= 0) {
diff --git a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp
index d94a22a..4b87cb4 100644
--- a/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp
+++ b/src/openvic-simulation/economy/production/ResourceGatheringOperation.hpp
@@ -8,8 +8,12 @@
#include "openvic-simulation/utility/Getters.hpp"
namespace OpenVic {
+ struct ProvinceInstance;
+
struct ResourceGatheringOperation {
private:
+ ModifierEffectCache const& modifier_effect_cache;
+ ProvinceInstance* location_ptr;
ProductionType const* PROPERTY_RW(production_type_nullable);
fixed_point_t PROPERTY(revenue_yesterday);
fixed_point_t PROPERTY(output_quantity_yesterday);
@@ -23,16 +27,13 @@ namespace OpenVic {
fixed_point_t PROPERTY(total_employee_income_cache);
IndexedMap<PopType, Pop::pop_size_t> PROPERTY(employee_count_per_type_cache);
- 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 calculate_size_modifier() const;
+ void hire(const Pop::pop_size_t available_worker_count);
fixed_point_t produce(
- ProvinceInstance& location,
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 Pop::pop_size_t total_owner_count_in_state_cache
);
void pay_employees(
- ProvinceInstance& location,
const fixed_point_t revenue,
const Pop::pop_size_t total_worker_count_in_province,
std::vector<Pop*>* const owner_pops_cache,
@@ -41,6 +42,7 @@ namespace OpenVic {
public:
ResourceGatheringOperation(
+ ModifierEffectCache const& new_modifier_effect_cache,
ProductionType const* new_production_type_nullable,
fixed_point_t new_size_multiplier,
fixed_point_t new_revenue_yesterday,
@@ -49,11 +51,17 @@ namespace OpenVic {
std::vector<Employee>&& new_employees,
decltype(employee_count_per_type_cache)::keys_t const& pop_type_keys
);
- ResourceGatheringOperation(decltype(employee_count_per_type_cache)::keys_t const& pop_type_keys);
+
+ ResourceGatheringOperation(
+ ModifierEffectCache const& new_modifier_effect_cache,
+ decltype(employee_count_per_type_cache)::keys_t const& pop_type_keys
+ );
+
constexpr bool is_valid() const {
return production_type_nullable != nullptr;
}
- void initialise_rgo_size_multiplier(ProvinceInstance& location, ModifierEffectCache const& modifier_effect_cache);
- void rgo_tick(ProvinceInstance& location, ModifierEffectCache const& modifier_effect_cache);
+ void setup_location_ptr(ProvinceInstance& location);
+ void initialise_rgo_size_multiplier();
+ void rgo_tick();
};
}
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp
index 80aad5e..85ff042 100644
--- a/src/openvic-simulation/map/MapInstance.cpp
+++ b/src/openvic-simulation/map/MapInstance.cpp
@@ -43,6 +43,7 @@ ProvinceDefinition::index_t MapInstance::get_selected_province_index() const {
bool MapInstance::setup(
BuildingTypeManager const& building_type_manager,
+ ModifierEffectCache const& modifier_effect_cache,
decltype(ProvinceInstance::pop_type_distribution)::keys_t const& pop_type_keys,
decltype(ProvinceInstance::ideology_distribution)::keys_t const& ideology_keys
) {
@@ -60,7 +61,12 @@ bool MapInstance::setup(
province_instances.reserve(map_definition.get_province_definition_count());
for (ProvinceDefinition const& province : map_definition.get_province_definitions()) {
- ret &= province_instances.add_item({ province, pop_type_keys, ideology_keys });
+ ret &= province_instances.add_item({
+ modifier_effect_cache,
+ province,
+ pop_type_keys,
+ ideology_keys
+ });
}
province_instances.lock();
@@ -152,20 +158,19 @@ void MapInstance::update_gamestate(const Date today, DefineManager const& define
state_manager.update_gamestate();
}
-void MapInstance::map_tick(const Date today, ModifierEffectCache const& modifier_effect_cache) {
+void MapInstance::map_tick(const Date today) {
for (ProvinceInstance& province : province_instances.get_items()) {
- province.province_tick(today, modifier_effect_cache);
+ province.province_tick(today);
}
}
void MapInstance::initialise_for_new_game(
const Date today,
- DefineManager const& define_manager,
- ModifierEffectCache const& modifier_effect_cache
+ DefineManager const& define_manager
) {
update_gamestate(today, define_manager);
for (ProvinceInstance& province : province_instances.get_items()) {
- province.initialise_rgo(modifier_effect_cache);
+ province.initialise_rgo();
}
- state_manager.tick(today, modifier_effect_cache);
+ state_manager.tick(today);
} \ No newline at end of file
diff --git a/src/openvic-simulation/map/MapInstance.hpp b/src/openvic-simulation/map/MapInstance.hpp
index 1ca28d2..a498061 100644
--- a/src/openvic-simulation/map/MapInstance.hpp
+++ b/src/openvic-simulation/map/MapInstance.hpp
@@ -44,6 +44,7 @@ namespace OpenVic {
bool setup(
BuildingTypeManager const& building_type_manager,
+ ModifierEffectCache const& modifier_effect_cache,
decltype(ProvinceInstance::pop_type_distribution)::keys_t const& pop_type_keys,
decltype(ProvinceInstance::ideology_distribution)::keys_t const& ideology_keys
);
@@ -54,7 +55,7 @@ namespace OpenVic {
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);
+ void map_tick(const Date today);
+ void initialise_for_new_game(const Date today, DefineManager const& define_manager);
};
}
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp
index 5a3dda2..775dcad 100644
--- a/src/openvic-simulation/map/ProvinceInstance.cpp
+++ b/src/openvic-simulation/map/ProvinceInstance.cpp
@@ -18,7 +18,9 @@
using namespace OpenVic;
ProvinceInstance::ProvinceInstance(
- ProvinceDefinition const& new_province_definition, decltype(pop_type_distribution)::keys_t const& pop_type_keys,
+ ModifierEffectCache const& new_modifier_effect_cache,
+ ProvinceDefinition const& new_province_definition,
+ decltype(pop_type_distribution)::keys_t const& pop_type_keys,
decltype(ideology_distribution)::keys_t const& ideology_keys
) : HasIdentifierAndColour { new_province_definition },
province_definition { new_province_definition },
@@ -33,7 +35,7 @@ ProvinceInstance::ProvinceInstance(
event_modifiers {},
slave { false },
crime { nullptr },
- rgo { pop_type_keys },
+ rgo { new_modifier_effect_cache, pop_type_keys },
buildings { "buildings", false },
armies {},
navies {},
@@ -371,14 +373,11 @@ void ProvinceInstance::update_gamestate(const Date today, DefineManager const& d
_update_pops(define_manager);
}
-void ProvinceInstance::province_tick(const Date today, ModifierEffectCache const& modifier_effect_cache) {
+void ProvinceInstance::province_tick(const Date today) {
for (BuildingInstance& building : buildings.get_items()) {
building.tick(today);
}
- rgo.rgo_tick(
- *this,
- modifier_effect_cache
- );
+ rgo.rgo_tick();
}
template<UnitType::branch_t Branch>
@@ -418,6 +417,8 @@ bool ProvinceInstance::setup(BuildingTypeManager const& building_type_manager) {
return false;
}
+ rgo.setup_location_ptr(*this);
+
bool ret = true;
if (!province_definition.is_water()) {
@@ -482,8 +483,8 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const& ent
return ret;
}
-void ProvinceInstance::initialise_rgo(ModifierEffectCache const& modifier_effect_cache) {
- rgo.initialise_rgo_size_multiplier(*this, modifier_effect_cache);
+void ProvinceInstance::initialise_rgo() {
+ rgo.initialise_rgo_size_multiplier();
}
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 ec83af4..997d025 100644
--- a/src/openvic-simulation/map/ProvinceInstance.hpp
+++ b/src/openvic-simulation/map/ProvinceInstance.hpp
@@ -7,6 +7,7 @@
#include "openvic-simulation/economy/production/ResourceGatheringOperation.hpp"
#include "openvic-simulation/military/UnitInstance.hpp"
#include "openvic-simulation/military/UnitType.hpp"
+#include "openvic-simulation/modifier/ModifierEffectCache.hpp"
#include "openvic-simulation/modifier/ModifierSum.hpp"
#include "openvic-simulation/pop/Pop.hpp"
#include "openvic-simulation/types/HasIdentifier.hpp"
@@ -103,7 +104,9 @@ namespace OpenVic {
size_t PROPERTY(max_supported_regiments);
ProvinceInstance(
- ProvinceDefinition const& new_province_definition, decltype(pop_type_distribution)::keys_t const& pop_type_keys,
+ ModifierEffectCache const& new_modifier_effect_cache,
+ ProvinceDefinition const& new_province_definition,
+ decltype(pop_type_distribution)::keys_t const& pop_type_keys,
decltype(ideology_distribution)::keys_t const& ideology_keys
);
@@ -150,7 +153,7 @@ namespace OpenVic {
std::vector<ModifierSum::modifier_entry_t> get_contributing_modifiers(ModifierEffect const& effect) const;
void update_gamestate(const Date today, DefineManager const& define_manager);
- void province_tick(const Date today, ModifierEffectCache const& modifier_effect_cache);
+ void province_tick(const Date today);
template<UnitType::branch_t Branch>
bool add_unit_instance_group(UnitInstanceGroup<Branch>& group);
@@ -160,7 +163,7 @@ namespace OpenVic {
bool setup(BuildingTypeManager const& building_type_manager);
bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager);
- void initialise_rgo(ModifierEffectCache const& modifier_effect_cache);
+ void initialise_rgo();
void setup_pop_test_values(IssueManager const& issue_manager);
State* get_mutable_state();
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp
index a13c271..0987c50 100644
--- a/src/openvic-simulation/map/State.cpp
+++ b/src/openvic-simulation/map/State.cpp
@@ -98,9 +98,9 @@ void State::update_gamestate() {
industrial_power = total_factory_levels_in_state * workforce_scalar;
}
-void State::state_tick(const Date today, ModifierEffectCache const& modifier_effect_cache) {
+void State::state_tick(const Date today) {
for (ProvinceInstance* province : provinces) {
- province->province_tick(today, modifier_effect_cache);
+ province->province_tick(today);
}
}
@@ -126,9 +126,9 @@ void StateSet::update_gamestate() {
}
}
-void StateSet::tick(const Date today, ModifierEffectCache const& modifier_effect_cache) {
+void StateSet::tick(const Date today) {
for (State& state : states) {
- state.state_tick(today, modifier_effect_cache);
+ state.state_tick(today);
}
}
@@ -233,8 +233,8 @@ void StateManager::update_gamestate() {
}
}
-void StateManager::tick(const Date today, ModifierEffectCache const& modifier_effect_cache) {
+void StateManager::tick(const Date today) {
for (StateSet& state_set : state_sets) {
- state_set.tick(today, modifier_effect_cache);
+ state_set.tick(today);
}
} \ No newline at end of file
diff --git a/src/openvic-simulation/map/State.hpp b/src/openvic-simulation/map/State.hpp
index e1f5953..55cd9e7 100644
--- a/src/openvic-simulation/map/State.hpp
+++ b/src/openvic-simulation/map/State.hpp
@@ -49,7 +49,7 @@ namespace OpenVic {
std::string get_identifier() const;
void update_gamestate();
- void state_tick(const Date today, ModifierEffectCache const& modifier_effect_cache);
+ void state_tick(const Date today);
IndexedMap<PopType, std::vector<Pop*>>& get_mutable_pops_cache_by_type();
};
@@ -70,7 +70,7 @@ namespace OpenVic {
size_t get_state_count() const;
void update_gamestate();
- void tick(const Date today, ModifierEffectCache const& modifier_effect_cache);
+ void tick(const Date today);
};
struct MapInstance;
@@ -94,6 +94,6 @@ namespace OpenVic {
void reset();
void update_gamestate();
- void tick(const Date today, ModifierEffectCache const& modifier_effect_cache);
+ void tick(const Date today);
};
}