diff options
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r-- | src/openvic-simulation/map/Province.cpp | 37 | ||||
-rw-r--r-- | src/openvic-simulation/map/Province.hpp | 10 |
2 files changed, 45 insertions, 2 deletions
diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp index d1183f5..eb23759 100644 --- a/src/openvic-simulation/map/Province.cpp +++ b/src/openvic-simulation/map/Province.cpp @@ -1,6 +1,7 @@ #include "Province.hpp" #include "openvic-simulation/history/ProvinceHistory.hpp" +#include "openvic-simulation/military/UnitInstance.hpp" using namespace OpenVic; using namespace OpenVic::NodeTools; @@ -181,6 +182,42 @@ fvec2_t Province::get_unit_position() const { return positions.unit.value_or(positions.centre); } +bool Province::add_army(ArmyInstance& army) { + if (armies.emplace(&army).second) { + return true; + } else { + Logger::error("Trying to add already-existing army ", army.get_name(), " to province ", get_identifier()); + return false; + } +} + +bool Province::remove_army(ArmyInstance& army) { + if (armies.erase(&army) > 0) { + return true; + } else { + Logger::error("Trying to remove non-existent army ", army.get_name(), " from province ", get_identifier()); + return false; + } +} + +bool Province::add_navy(NavyInstance& navy) { + if (navies.emplace(&navy).second) { + return true; + } else { + Logger::error("Trying to add already-existing navy ", navy.get_name(), " to province ", get_identifier()); + return false; + } +} + +bool Province::remove_navy(NavyInstance& navy) { + if (navies.erase(&navy) > 0) { + return true; + } else { + Logger::error("Trying to remove non-existent navy ", navy.get_name(), " from province ", get_identifier()); + return false; + } +} + bool Province::reset(BuildingTypeManager const& building_type_manager) { terrain_type = default_terrain_type; life_rating = 0; diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp index 476ecc9..c4785dd 100644 --- a/src/openvic-simulation/map/Province.hpp +++ b/src/openvic-simulation/map/Province.hpp @@ -1,7 +1,5 @@ #pragma once -#include <cassert> - #include "openvic-simulation/country/Country.hpp" #include "openvic-simulation/economy/BuildingInstance.hpp" #include "openvic-simulation/politics/Ideology.hpp" @@ -20,6 +18,8 @@ namespace OpenVic { struct ProvinceSetModifier; using Climate = ProvinceSetModifier; using Continent = ProvinceSetModifier; + struct ArmyInstance; + struct NavyInstance; /* REQUIREMENTS: * MAP-5, MAP-7, MAP-8, MAP-43, MAP-47 @@ -118,6 +118,8 @@ namespace OpenVic { // TODO - change this into a factory-like structure Good const* PROPERTY(rgo); IdentifierRegistry<BuildingInstance> IDENTIFIER_REGISTRY(building); + ordered_set<ArmyInstance*> PROPERTY(armies); + ordered_set<NavyInstance*> PROPERTY(navies); std::vector<Pop> PROPERTY(pops); Pop::pop_size_t PROPERTY(total_population); @@ -154,6 +156,10 @@ namespace OpenVic { bool has_adjacency_going_through(Province const* province) const; fvec2_t get_unit_position() const; + bool add_army(ArmyInstance& army); + bool remove_army(ArmyInstance& army); + bool add_navy(NavyInstance& navy); + bool remove_navy(NavyInstance& navy); bool reset(BuildingTypeManager const& building_type_manager); bool apply_history_to_province(ProvinceHistoryEntry const* entry); |