aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/MapInstance.cpp10
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.cpp33
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.hpp2
-rw-r--r--src/openvic-simulation/map/State.cpp26
-rw-r--r--src/openvic-simulation/map/State.hpp9
5 files changed, 51 insertions, 29 deletions
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp
index 56b3642..ea174eb 100644
--- a/src/openvic-simulation/map/MapInstance.cpp
+++ b/src/openvic-simulation/map/MapInstance.cpp
@@ -94,11 +94,15 @@ bool MapInstance::apply_history_to_provinces(
if (history_map != nullptr) {
ProvinceHistoryEntry const* pop_history_entry = nullptr;
- for (ProvinceHistoryEntry const* entry : history_map->get_entries_up_to(date)) {
- province.apply_history_to_province(entry, country_manager);
+ for (auto const& [entry_date, entry] : history_map->get_entries()) {
+ if (entry_date > date) {
+ break;
+ }
+
+ province.apply_history_to_province(*entry, country_manager);
if (!entry->get_pops().empty()) {
- pop_history_entry = entry;
+ pop_history_entry = entry.get();
}
}
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp
index ee20590..f95ee21 100644
--- a/src/openvic-simulation/map/ProvinceInstance.cpp
+++ b/src/openvic-simulation/map/ProvinceInstance.cpp
@@ -236,12 +236,7 @@ bool ProvinceInstance::setup(BuildingTypeManager const& building_type_manager) {
return ret;
}
-bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const* entry, CountryInstanceManager& country_manager) {
- if (entry == nullptr) {
- Logger::error("Trying to apply null province history to ", get_identifier());
- return false;
- }
-
+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) {
@@ -250,25 +245,25 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const* ent
}
};
- if (entry->get_owner()) {
- ret &= set_owner(&country_manager.get_country_instance_from_definition(**entry->get_owner()));
+ if (entry.get_owner()) {
+ ret &= set_owner(&country_manager.get_country_instance_from_definition(**entry.get_owner()));
}
- if (entry->get_controller()) {
- ret &= set_controller(&country_manager.get_country_instance_from_definition(**entry->get_controller()));
+ if (entry.get_controller()) {
+ ret &= set_controller(&country_manager.get_country_instance_from_definition(**entry.get_controller()));
}
- set_optional(colony_status, entry->get_colonial());
- set_optional(slave, entry->get_slave());
- for (auto const& [country, add] : entry->get_cores()) {
+ set_optional(colony_status, entry.get_colonial());
+ set_optional(slave, entry.get_slave());
+ for (auto const& [country, add] : entry.get_cores()) {
if (add) {
ret &= add_core(country_manager.get_country_instance_from_definition(*country));
} else {
ret &= remove_core(country_manager.get_country_instance_from_definition(*country));
}
}
- set_optional(rgo, entry->get_rgo());
- 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()) {
+ set_optional(rgo, entry.get_rgo());
+ 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()) {
BuildingInstance* existing_entry = buildings.get_item_by_identifier(building->get_identifier());
if (existing_entry != nullptr) {
existing_entry->set_level(level);
@@ -280,8 +275,8 @@ bool ProvinceInstance::apply_history_to_province(ProvinceHistoryEntry const* ent
ret = false;
}
}
- // TODO: load state buildings - entry->get_state_buildings()
- // TODO: party loyalties for each POP when implemented on POP side - entry->get_party_loyalties()
+ // TODO: load state buildings - entry.get_state_buildings()
+ // TODO: party loyalties for each POP when implemented on POP side - entry.get_party_loyalties()
return ret;
}
diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp
index 048ac3b..7ba35cd 100644
--- a/src/openvic-simulation/map/ProvinceInstance.hpp
+++ b/src/openvic-simulation/map/ProvinceInstance.hpp
@@ -131,7 +131,7 @@ 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);
+ bool apply_history_to_province(ProvinceHistoryEntry const& entry, CountryInstanceManager& country_manager);
void setup_pop_test_values(IssueManager const& issue_manager);
};
diff --git a/src/openvic-simulation/map/State.cpp b/src/openvic-simulation/map/State.cpp
index 68f2f43..90cbace 100644
--- a/src/openvic-simulation/map/State.cpp
+++ b/src/openvic-simulation/map/State.cpp
@@ -10,11 +10,19 @@
using namespace OpenVic;
State::State(
- StateSet const& new_state_set, CountryInstance* owner, ProvinceInstance* capital,
- std::vector<ProvinceInstance*>&& provinces, ProvinceInstance::colony_status_t colony_status,
+ StateSet const& new_state_set,
+ CountryInstance* new_owner,
+ ProvinceInstance* new_capital,
+ std::vector<ProvinceInstance*>&& new_provinces,
+ ProvinceInstance::colony_status_t new_colony_status,
decltype(pop_type_distribution)::keys_t const& pop_type_keys
-) : state_set { new_state_set }, owner { owner }, capital { capital }, provinces { std::move(provinces) },
- colony_status { colony_status }, pop_type_distribution { &pop_type_keys } {}
+) : state_set { new_state_set },
+ owner { new_owner },
+ capital { new_capital },
+ provinces { std::move(new_provinces) },
+ colony_status { new_colony_status },
+ pop_type_distribution { &pop_type_keys },
+ industrial_power { 0 } {}
std::string State::get_identifier() const {
return StringUtils::append_string_views(
@@ -47,6 +55,16 @@ void State::update_gamestate() {
average_consciousness /= total_population;
average_militancy /= total_population;
}
+
+ // TODO - use actual values when State has factory data
+ const int32_t total_factory_levels_in_state = 0;
+ const int32_t potential_workforce_in_state = 0; // sum of worker pops, regardless of employment
+ const int32_t potential_employment_in_state = 0; // sum of (factory level * production method base_workforce_size)
+
+ industrial_power = total_factory_levels_in_state * std::clamp(
+ (fixed_point_t { potential_workforce_in_state } / 100).floor() * 400 / potential_employment_in_state,
+ fixed_point_t::_0_20(), fixed_point_t::_4()
+ );
}
/* Whether two provinces in the same region should be grouped into the same state or not.
diff --git a/src/openvic-simulation/map/State.hpp b/src/openvic-simulation/map/State.hpp
index 44b1947..6035e10 100644
--- a/src/openvic-simulation/map/State.hpp
+++ b/src/openvic-simulation/map/State.hpp
@@ -31,9 +31,14 @@ namespace OpenVic {
fixed_point_t PROPERTY(average_militancy);
IndexedMap<PopType, fixed_point_t> PROPERTY(pop_type_distribution);
+ fixed_point_t PROPERTY(industrial_power);
+
State(
- StateSet const& new_state_set, CountryInstance* owner, ProvinceInstance* capital,
- std::vector<ProvinceInstance*>&& provinces, ProvinceInstance::colony_status_t colony_status,
+ StateSet const& new_state_set,
+ CountryInstance* new_owner,
+ ProvinceInstance* new_capital,
+ std::vector<ProvinceInstance*>&& new_provinces,
+ ProvinceInstance::colony_status_t new_colony_status,
decltype(pop_type_distribution)::keys_t const& pop_type_keys
);