diff options
Diffstat (limited to 'src/openvic-simulation/map/Region.cpp')
-rw-r--r-- | src/openvic-simulation/map/Region.cpp | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/src/openvic-simulation/map/Region.cpp b/src/openvic-simulation/map/Region.cpp index 18a47a9..6f40338 100644 --- a/src/openvic-simulation/map/Region.cpp +++ b/src/openvic-simulation/map/Region.cpp @@ -4,9 +4,7 @@ using namespace OpenVic; -ProvinceSet::ProvinceSet(provinces_t&& new_provinces) : provinces { std::move(new_provinces) } {} - -bool ProvinceSet::add_province(Province* province) { +bool ProvinceSet::add_province(Province const* province) { if (locked) { Logger::error("Cannot add province to province set - locked!"); return false; @@ -16,13 +14,39 @@ bool ProvinceSet::add_province(Province* province) { return false; } if (contains_province(province)) { - Logger::error("Cannot add province ", province->get_identifier(), " to province set - already in the set!"); + Logger::warning("Cannot add province ", province->get_identifier(), " to province set - already in the set!"); return false; } provinces.push_back(province); return true; } +bool ProvinceSet::add_provinces(provinces_t const& new_provinces) { + bool ret = true; + for (Province const* province : new_provinces) { + ret &= add_province(province); + } + return ret; +} + +bool ProvinceSet::remove_province(Province const* province) { + if (locked) { + Logger::error("Cannot remove province from province set - locked!"); + return false; + } + if (province == nullptr) { + Logger::error("Cannot remove province from province set - null province!"); + return false; + } + const provinces_t::const_iterator it = std::find(provinces.begin(), provinces.end(), province); + if (it == provinces.end()) { + Logger::warning("Cannot remove province ", province->get_identifier(), " from province set - already not in the set!"); + return false; + } + provinces.erase(it); + return true; +} + void ProvinceSet::lock(bool log) { if (locked) { Logger::error("Failed to lock province set - already locked!"); @@ -67,14 +91,11 @@ ProvinceSet::provinces_t const& ProvinceSet::get_provinces() const { return provinces; } -static constexpr colour_t ERROR_REGION_COLOUR { colour_t::max_value, 0, 0 }; +Region::Region(std::string_view new_identifier, colour_t new_colour, bool new_meta) + : HasIdentifierAndColour { new_identifier, new_colour, false }, meta { new_meta } {} -Region::Region(std::string_view new_identifier, provinces_t&& new_provinces, bool new_meta) - : HasIdentifierAndColour { - new_identifier, new_provinces.size() > 0 ? new_provinces.front()->get_colour() : ERROR_REGION_COLOUR, false - }, ProvinceSet { std::move(new_provinces) }, meta { new_meta } { - lock(); -} +ProvinceSetModifier::ProvinceSetModifier(std::string_view new_identifier, ModifierValue&& new_values) + : Modifier { new_identifier, std::move(new_values), 0 } {} bool Region::get_meta() const { return meta; |