aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic2/Map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'extension/src/openvic2/Map.cpp')
-rw-r--r--extension/src/openvic2/Map.cpp43
1 files changed, 33 insertions, 10 deletions
diff --git a/extension/src/openvic2/Map.cpp b/extension/src/openvic2/Map.cpp
index 40c421a..4815dff 100644
--- a/extension/src/openvic2/Map.cpp
+++ b/extension/src/openvic2/Map.cpp
@@ -5,14 +5,33 @@
using namespace OpenVic2;
-std::string Province::to_string() const {
+Province::Province(std::string const& new_identifier, colour_t new_colour) :
+ identifier(new_identifier), colour(new_colour) {}
+
+std::string Province::colour_to_hex_string(colour_t colour) {
std::ostringstream stream;
- stream << "(" << identifier << ", " << std::hex << std::setfill('0') << std::setw(6) << colour << ")";
+ stream << std::hex << std::setfill('0') << std::setw(6) << colour;
return stream.str();
}
+std::string const& Province::get_identifier() const {
+ return identifier;
+}
+
+Province::colour_t Province::get_colour() const {
+ return colour;
+}
+
+std::string Province::to_string() const {
+ return "(" + std::to_string(index) + ", " + identifier + ", " + colour_to_hex_string(colour) + ")";
+}
+
bool Map::add_province(std::string const& identifier, Province::colour_t colour, std::string& error_message) {
- Province new_province = { identifier, colour };
+ if (colour == Province::NULL_COLOUR || colour > Province::MAX_COLOUR) {
+ error_message = "Invalid province colour: " + Province::colour_to_hex_string(colour);
+ return false;
+ }
+ Province new_province{ identifier, colour };
for (Province const& province : provinces) {
if (province.identifier == identifier) {
error_message = "Duplicate province identifiers: " + province.to_string() + " and " + new_province.to_string();
@@ -28,10 +47,14 @@ bool Map::add_province(std::string const& identifier, Province::colour_t colour,
return true;
}
-Province Map::get_province(Province::colour_t colour) {
- for(Province const& province : provinces) {
- if (province.colour == colour) {
- return province;
- }
- }
-} \ No newline at end of file
+Province* Map::get_province_by_identifier(std::string const& identifier) {
+ for (Province& province : provinces)
+ if (province.identifier == identifier) return &province;
+ return nullptr;
+}
+
+Province* Map::get_province_by_colour(Province::colour_t colour) {
+ for (Province& province : provinces)
+ if (province.colour == colour) return &province;
+ return nullptr;
+}