From 48204950cd8d48e6df26ed6892f57b3d9da823de Mon Sep 17 00:00:00 2001 From: hop311 Date: Mon, 25 Dec 2023 00:22:01 +0000 Subject: Province building scaffolding --- src/openvic-simulation/map/Map.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/openvic-simulation/map/Map.cpp') 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) { -- cgit v1.2.3-56-ga3b1