aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map/Region.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-09-09 23:49:54 +0200
committer GitHub <noreply@github.com>2023-09-09 23:49:54 +0200
commit6278a35f4704574933464700026d8deb997da5c1 (patch)
treeeb36a9b030b263d825eb93638e64deb0dbd38a78 /src/openvic-simulation/map/Region.cpp
parentbec619fc8f554cb075fcef2428f3b6bdb5e88e82 (diff)
parent3d7fbd9b376811ca0ed226fa78bcc8b6279ba8dc (diff)
Merge pull request #14 from OpenVicProject/dataloading
Dataloading scaffolding + basic culture and pop history loading
Diffstat (limited to 'src/openvic-simulation/map/Region.cpp')
-rw-r--r--src/openvic-simulation/map/Region.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/openvic-simulation/map/Region.cpp b/src/openvic-simulation/map/Region.cpp
new file mode 100644
index 0000000..33092c5
--- /dev/null
+++ b/src/openvic-simulation/map/Region.cpp
@@ -0,0 +1,69 @@
+#include "Region.hpp"
+
+using namespace OpenVic;
+
+bool ProvinceSet::add_province(Province* province) {
+ if (locked) {
+ Logger::error("Cannot add province to province set - locked!");
+ return false;
+ }
+ if (province == nullptr) {
+ Logger::error("Cannot add province to province set - null province!");
+ return false;
+ }
+ if (contains_province(province)) {
+ Logger::error("Cannot add province ", province->get_identifier(), " to province set - already in the set!");
+ return false;
+ }
+ provinces.push_back(province);
+ return true;
+}
+
+void ProvinceSet::lock(bool log) {
+ if (locked) {
+ Logger::error("Failed to lock province set - already locked!");
+ } else {
+ locked = true;
+ if (log) Logger::info("Locked province set with ", size(), " provinces");
+ }
+}
+
+bool ProvinceSet::is_locked() const {
+ return locked;
+}
+
+void ProvinceSet::reset() {
+ provinces.clear();
+ locked = false;
+}
+
+bool ProvinceSet::empty() const {
+ return provinces.empty();
+}
+
+size_t ProvinceSet::size() const {
+ return provinces.size();
+}
+
+void ProvinceSet::reserve(size_t size) {
+ if (locked) {
+ Logger::error("Failed to reserve space for ", size, " items in province set - already locked!");
+ } else {
+ provinces.reserve(size);
+ }
+}
+
+bool ProvinceSet::contains_province(Province const* province) const {
+ return province && std::find(provinces.begin(), provinces.end(), province) != provinces.end();
+}
+
+std::vector<Province*> const& ProvinceSet::get_provinces() const {
+ return provinces;
+}
+
+Region::Region(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
+
+colour_t Region::get_colour() const {
+ if (provinces.empty()) return FULL_COLOUR << 16;
+ return provinces.front()->get_colour();
+}