From 7874702f30d5855319faf197b10aed31f07f5e27 Mon Sep 17 00:00:00 2001 From: Hop311 Date: Mon, 22 May 2023 10:36:23 +0100 Subject: BMP palette parser + Logger macro --- src/openvic/map/Map.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/openvic/map/Map.cpp') 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 #include -#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; } -- cgit v1.2.3-56-ga3b1