diff options
author | Hop311 <Hop3114@gmail.com> | 2024-04-15 20:59:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-15 20:59:47 +0200 |
commit | a57e81703102bc52297fbdc074da755fa8edbedd (patch) | |
tree | 54a0ad26ef3cec9a56644479611e8abaad62b1f7 /src/openvic-simulation/map/Province.cpp | |
parent | 109d31f147512c8d51f35f9773cd3c6bb1b8b994 (diff) | |
parent | 5799836bee29024ce8a2d0fc45e06664c0110751 (diff) |
Merge pull request #154 from OpenVicProject/units
Generate starting unit instances
Diffstat (limited to 'src/openvic-simulation/map/Province.cpp')
-rw-r--r-- | src/openvic-simulation/map/Province.cpp | 37 |
1 files changed, 37 insertions, 0 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; |