aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map/Map.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-12-25 13:21:38 +0100
committer GitHub <noreply@github.com>2023-12-25 13:21:38 +0100
commitbff91f78f9c5339079c10adfbf8232e5159c1a2d (patch)
treea40b49f6dc155fc5c3c47b623926764642242677 /src/openvic-simulation/map/Map.cpp
parentdcef842d5e070854913f9e61e4a1f485870ae703 (diff)
parent48204950cd8d48e6df26ed6892f57b3d9da823de (diff)
Merge pull request #103 from OpenVicProject/province-buildings
Province building scaffolding
Diffstat (limited to 'src/openvic-simulation/map/Map.cpp')
-rw-r--r--src/openvic-simulation/map/Map.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp
index aa8ed5e..fde3b3a 100644
--- a/src/openvic-simulation/map/Map.cpp
+++ b/src/openvic-simulation/map/Map.cpp
@@ -30,7 +30,7 @@ Mapmode::base_stripe_t Mapmode::get_base_stripe_colours(Map const& map, Province
}
Map::Map()
- : width { 0 }, height { 0 }, max_provinces { Province::MAX_INDEX }, selected_province_index { Province::NULL_INDEX },
+ : width { 0 }, height { 0 }, max_provinces { Province::MAX_INDEX }, selected_province { nullptr },
highest_province_population { 0 }, total_map_population { 0 } {}
bool Map::add_province(std::string_view identifier, colour_t colour) {
@@ -181,18 +181,24 @@ bool Map::set_max_provinces(Province::index_t new_max_provinces) {
}
void Map::set_selected_province(Province::index_t index) {
- if (index > get_province_count()) {
- Logger::error(
- "Trying to set selected province to an invalid index ", index, " (max index is ", get_province_count(), ")"
- );
- selected_province_index = Province::NULL_INDEX;
+ if (index == Province::NULL_INDEX) {
+ selected_province = nullptr;
} else {
- selected_province_index = index;
+ selected_province = get_province_by_index(index);
+ if (selected_province == nullptr) {
+ Logger::error(
+ "Trying to set selected province to an invalid index ", index, " (max index is ", get_province_count(), ")"
+ );
+ }
}
}
-Province const* Map::get_selected_province() const {
- return get_province_by_index(get_selected_province_index());
+Province* Map::get_selected_province() {
+ return selected_province;
+}
+
+Province::index_t Map::get_selected_province_index() const {
+ return selected_province != nullptr ? selected_province->get_index() : Province::NULL_INDEX;
}
bool Map::add_mapmode(std::string_view identifier, Mapmode::colour_func_t colour_func) {