aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic/map')
-rw-r--r--src/openvic/map/Building.cpp2
-rw-r--r--src/openvic/map/Map.cpp22
-rw-r--r--src/openvic/map/Map.hpp2
3 files changed, 19 insertions, 7 deletions
diff --git a/src/openvic/map/Building.cpp b/src/openvic/map/Building.cpp
index 1513e06..317ccdf 100644
--- a/src/openvic/map/Building.cpp
+++ b/src/openvic/map/Building.cpp
@@ -2,7 +2,7 @@
#include <cassert>
-#include "../Logger.hpp"
+#include "../utility/Logger.hpp"
#include "Province.hpp"
using namespace OpenVic;
diff --git a/src/openvic/map/Map.cpp b/src/openvic/map/Map.cpp
index 8d5b9e7..2efee32 100644
--- a/src/openvic/map/Map.cpp
+++ b/src/openvic/map/Map.cpp
@@ -3,8 +3,8 @@
#include <cassert>
#include <unordered_set>
-#include "../Logger.hpp"
#include "../economy/Good.hpp"
+#include "../utility/Logger.hpp"
using namespace OpenVic;
@@ -15,6 +15,8 @@ Mapmode::Mapmode(index_t new_index, std::string const& new_identifier, colour_fu
assert(colour_func != nullptr);
}
+const Mapmode Mapmode::ERROR_MAPMODE { 0, "mapmode_error", [](Map const& map, Province const& province) -> colour_t { return 0xFFFF0000; } };
+
Mapmode::index_t Mapmode::get_index() const {
return index;
}
@@ -180,7 +182,8 @@ Region const* Map::get_region_by_identifier(std::string const& identifier) const
}
static colour_t colour_at(uint8_t const* colour_data, int32_t idx) {
- return (colour_data[idx * 3] << 16) | (colour_data[idx * 3 + 1] << 8) | colour_data[idx * 3 + 2];
+ idx *= 3;
+ return (colour_data[idx] << 16) | (colour_data[idx + 1] << 8) | colour_data[idx + 2];
}
return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data,
@@ -313,10 +316,17 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target)
Logger::error("Mapmode colour target pointer is null!");
return FAILURE;
}
+ return_t ret = SUCCESS;
Mapmode const* mapmode = mapmodes.get_item_by_index(index);
if (mapmode == nullptr) {
- Logger::error("Invalid mapmode index: ", index);
- return FAILURE;
+ // Not an error if mapmodes haven't yet been loaded,
+ // e.g. if we want to allocate the province colour
+ // texture before mapmodes are loaded.
+ if (!(mapmodes.get_item_count() == 0 && index == 0)) {
+ Logger::error("Invalid mapmode index: ", index);
+ ret = FAILURE;
+ }
+ mapmode = &Mapmode::ERROR_MAPMODE;
}
// Skip past Province::NULL_INDEX
for (size_t i = 0; i < MAPMODE_COLOUR_SIZE; ++i)
@@ -328,14 +338,14 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target)
*target++ = colour & FULL_COLOUR;
*target++ = (colour >> 24) & FULL_COLOUR;
}
- return SUCCESS;
+ return ret;
}
return_t Map::setup(GoodManager const& good_manager, BuildingManager const& building_manager) {
return_t ret = SUCCESS;
for (Province& province : provinces.get_items()) {
// Set all land provinces to have an RGO based on their index to test them
- if (!province.is_water())
+ if (!province.is_water() && good_manager.get_good_count() > 0)
province.rgo = good_manager.get_good_by_index(province.get_index() % good_manager.get_good_count());
if (building_manager.generate_province_buildings(province) != SUCCESS) ret = FAILURE;
}
diff --git a/src/openvic/map/Map.hpp b/src/openvic/map/Map.hpp
index a7c29bb..3533a14 100644
--- a/src/openvic/map/Map.hpp
+++ b/src/openvic/map/Map.hpp
@@ -19,6 +19,8 @@ namespace OpenVic {
Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func);
public:
+ static const Mapmode ERROR_MAPMODE;
+
index_t get_index() const;
colour_t get_colour(Map const& map, Province const& province) const;
};