aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-06-13 18:59:47 +0200
committer GitHub <noreply@github.com>2024-06-13 18:59:47 +0200
commitbfd539513af435564daf70f94f6cce146dd5c948 (patch)
tree7ba5a06714c267185dd3a59aabc6556a105c122f /src/openvic-simulation/map
parent01a8f60aaca9784d814f4cb35a3fc4be86e1dd20 (diff)
parent4b39e77304094708d5c503b6a221386408cc4409 (diff)
Merge pull request #165 from OpenVicProject/instance-definition-managers
Separated GameManager into Definition and Instance Managers
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Crime.cpp4
-rw-r--r--src/openvic-simulation/map/Crime.hpp2
-rw-r--r--src/openvic-simulation/map/MapInstance.cpp16
-rw-r--r--src/openvic-simulation/map/MapInstance.hpp2
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.cpp28
-rw-r--r--src/openvic-simulation/map/ProvinceInstance.hpp2
6 files changed, 23 insertions, 31 deletions
diff --git a/src/openvic-simulation/map/Crime.cpp b/src/openvic-simulation/map/Crime.cpp
index 3f5a718..03da0fc 100644
--- a/src/openvic-simulation/map/Crime.cpp
+++ b/src/openvic-simulation/map/Crime.cpp
@@ -43,10 +43,10 @@ bool CrimeManager::load_crime_modifiers(ModifierManager const& modifier_manager,
return ret;
}
-bool CrimeManager::parse_scripts(GameManager const& game_manager) {
+bool CrimeManager::parse_scripts(DefinitionManager const& definition_manager) {
bool ret = true;
for (Crime& crime : crime_modifiers.get_items()) {
- ret &= crime.parse_scripts(game_manager);
+ ret &= crime.parse_scripts(definition_manager);
}
return ret;
}
diff --git a/src/openvic-simulation/map/Crime.hpp b/src/openvic-simulation/map/Crime.hpp
index 01044f9..cb539f3 100644
--- a/src/openvic-simulation/map/Crime.hpp
+++ b/src/openvic-simulation/map/Crime.hpp
@@ -30,6 +30,6 @@ namespace OpenVic {
bool load_crime_modifiers(ModifierManager const& modifier_manager, ast::NodeCPtr root);
- bool parse_scripts(GameManager const& game_manager);
+ bool parse_scripts(DefinitionManager const& definition_manager);
};
}
diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp
index 23fe6a3..093d341 100644
--- a/src/openvic-simulation/map/MapInstance.cpp
+++ b/src/openvic-simulation/map/MapInstance.cpp
@@ -49,20 +49,18 @@ ProvinceDefinition::index_t MapInstance::get_selected_province_index() const {
: ProvinceDefinition::NULL_INDEX;
}
-bool MapInstance::reset(BuildingTypeManager const& building_type_manager) {
+bool MapInstance::setup(BuildingTypeManager const& building_type_manager) {
+ if (province_instances_are_locked()) {
+ Logger::error("Cannot setup map - province instances are locked!");
+ return false;
+ }
if (!map_definition.province_definitions_are_locked()) {
- Logger::error("Cannot reset map - province consts are not locked!");
+ Logger::error("Cannot setup map - province consts are not locked!");
return false;
}
bool ret = true;
- // TODO - ensure all references to old ProvinceInstances are safely cleared
- state_manager.reset();
- selected_province = nullptr;
-
- province_instances.reset();
-
province_instances.reserve(map_definition.get_province_definition_count());
for (ProvinceDefinition const& province : map_definition.get_province_definitions()) {
@@ -72,7 +70,7 @@ bool MapInstance::reset(BuildingTypeManager const& building_type_manager) {
province_instances.lock();
for (ProvinceInstance& province : province_instances.get_items()) {
- ret &= province.reset(building_type_manager);
+ ret &= province.setup(building_type_manager);
}
if (get_province_instance_count() != map_definition.get_province_definition_count()) {
diff --git a/src/openvic-simulation/map/MapInstance.hpp b/src/openvic-simulation/map/MapInstance.hpp
index 1f87326..353a3a4 100644
--- a/src/openvic-simulation/map/MapInstance.hpp
+++ b/src/openvic-simulation/map/MapInstance.hpp
@@ -44,7 +44,7 @@ namespace OpenVic {
ProvinceInstance* get_selected_province();
ProvinceDefinition::index_t get_selected_province_index() const;
- bool reset(BuildingTypeManager const& building_type_manager);
+ bool setup(BuildingTypeManager const& building_type_manager);
bool apply_history_to_provinces(
ProvinceHistoryManager const& history_manager, Date date, IdeologyManager const& ideology_manager,
IssueManager const& issue_manager, Country const& country
diff --git a/src/openvic-simulation/map/ProvinceInstance.cpp b/src/openvic-simulation/map/ProvinceInstance.cpp
index be77d6e..2a0863d 100644
--- a/src/openvic-simulation/map/ProvinceInstance.cpp
+++ b/src/openvic-simulation/map/ProvinceInstance.cpp
@@ -10,7 +10,7 @@ using namespace OpenVic;
ProvinceInstance::ProvinceInstance(ProvinceDefinition const& new_province_definition)
: HasIdentifierAndColour { new_province_definition },
province_definition { new_province_definition },
- terrain_type { nullptr },
+ terrain_type { new_province_definition.get_default_terrain_type() },
life_rating { 0 },
colony_status { colony_status_t::STATE },
state { nullptr },
@@ -138,22 +138,18 @@ bool ProvinceInstance::remove_navy(NavyInstance& navy) {
}
}
-bool ProvinceInstance::reset(BuildingTypeManager const& building_type_manager) {
- terrain_type = province_definition.get_default_terrain_type();
- life_rating = 0;
- colony_status = colony_status_t::STATE;
- state = nullptr;
- owner = nullptr;
- controller = nullptr;
- cores.clear();
- slave = false;
- crime = nullptr;
- rgo = nullptr;
-
- buildings.reset();
+bool ProvinceInstance::setup(BuildingTypeManager const& building_type_manager) {
+ if (buildings_are_locked()) {
+ Logger::error("Cannot setup province ", get_identifier(), " - buildings already locked!");
+ return false;
+ }
+
bool ret = true;
+
if (!province_definition.is_water()) {
if (building_type_manager.building_types_are_locked()) {
+ buildings.reserve(building_type_manager.get_province_building_types().size());
+
for (BuildingType const* building_type : building_type_manager.get_province_building_types()) {
ret &= buildings.add_item({ *building_type });
}
@@ -162,10 +158,8 @@ bool ProvinceInstance::reset(BuildingTypeManager const& building_type_manager) {
ret = false;
}
}
- lock_buildings();
- pops.clear();
- _update_pops();
+ lock_buildings();
return ret;
}
diff --git a/src/openvic-simulation/map/ProvinceInstance.hpp b/src/openvic-simulation/map/ProvinceInstance.hpp
index beae0eb..67ce423 100644
--- a/src/openvic-simulation/map/ProvinceInstance.hpp
+++ b/src/openvic-simulation/map/ProvinceInstance.hpp
@@ -82,7 +82,7 @@ namespace OpenVic {
bool add_navy(NavyInstance& navy);
bool remove_navy(NavyInstance& navy);
- bool reset(BuildingTypeManager const& building_type_manager);
+ bool setup(BuildingTypeManager const& building_type_manager);
bool apply_history_to_province(ProvinceHistoryEntry const* entry);
void setup_pop_test_values(