diff options
author | Hop311 <Hop3114@gmail.com> | 2023-04-29 00:48:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-29 00:48:13 +0200 |
commit | 5195a460330af234391dfdc892847d74d0d29393 (patch) | |
tree | 588f505bd94991b3a6c7a95b18b02e712df36cc7 /extension/src/openvic2/map/Map.cpp | |
parent | 1b35c3a4434873b98f8e3aa7770f0edd37ec053c (diff) | |
parent | 05937359e8c53ee76dc3ce537dd70083a016f766 (diff) |
Merge branch 'main' into goods
Diffstat (limited to 'extension/src/openvic2/map/Map.cpp')
-rw-r--r-- | extension/src/openvic2/map/Map.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/extension/src/openvic2/map/Map.cpp b/extension/src/openvic2/map/Map.cpp index 90f2420..4e7c0bb 100644 --- a/extension/src/openvic2/map/Map.cpp +++ b/extension/src/openvic2/map/Map.cpp @@ -159,7 +159,7 @@ Province const* Map::get_province_by_colour(colour_t colour) const { } index_t Map::get_province_index_at(size_t x, size_t y) const { - if (x < width && y < height) return province_index_image[x + y * width]; + if (x < width && y < height) return province_shape_image[x + y * width].index; return NULL_INDEX; } @@ -175,8 +175,8 @@ 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]; } -return_t Map::generate_province_index_image(size_t new_width, size_t new_height, uint8_t const* colour_data) { - if (!province_index_image.empty()) { +return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data) { + if (!province_shape_image.empty()) { Logger::error("Province index image has already been generated!"); return FAILURE; } @@ -194,7 +194,7 @@ return_t Map::generate_province_index_image(size_t new_width, size_t new_height, } width = new_width; height = new_height; - province_index_image.resize(width * height); + province_shape_image.resize(width * height); std::vector<bool> province_checklist(provinces.get_item_count()); return_t ret = SUCCESS; @@ -207,22 +207,23 @@ return_t Map::generate_province_index_image(size_t new_width, size_t new_height, if (x > 0) { const int32_t jdx = idx - 1; if (colour_at(colour_data, jdx) == colour) { - province_index_image[idx] = province_index_image[jdx]; + province_shape_image[idx] = province_shape_image[jdx]; continue; } } if (y > 0) { const int32_t jdx = idx - width; if (colour_at(colour_data, jdx) == colour) { - province_index_image[idx] = province_index_image[jdx]; + province_shape_image[idx] = province_shape_image[jdx]; continue; } } Province const* province = get_province_by_colour(colour); if (province != nullptr) { const index_t index = province->get_index(); - province_index_image[idx] = index; province_checklist[index - 1] = true; + province_shape_image[idx].index = index; + province_shape_image[idx].terrain = !province->is_water(); continue; } if (unrecognised_colours.find(colour) == unrecognised_colours.end()) { @@ -230,7 +231,8 @@ return_t Map::generate_province_index_image(size_t new_width, size_t new_height, Logger::error("Unrecognised province colour ", Province::colour_to_hex_string(colour), " at (", x, ", ", y, ")"); ret = FAILURE; } - province_index_image[idx] = NULL_INDEX; + province_shape_image[idx].index = NULL_INDEX; + province_shape_image[idx].terrain = 0; } } @@ -251,8 +253,8 @@ size_t Map::get_height() const { return height; } -std::vector<index_t> const& Map::get_province_index_image() const { - return province_index_image; +std::vector<Map::shape_pixel_t> const& Map::get_province_shape_image() const { + return province_shape_image; } return_t Map::add_mapmode(std::string const& identifier, Mapmode::colour_func_t colour_func) { @@ -293,13 +295,14 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) Logger::error("Invalid mapmode index: ", index); return FAILURE; } - target += 4; // Skip past Province::NULL_INDEX + // Skip past Province::NULL_INDEX + for (size_t i = 0; i < MAPMODE_COLOUR_SIZE; ++i) + *target++ = 0; for (Province const& province : provinces.get_items()) { const colour_t colour = mapmode->get_colour(*this, province); *target++ = (colour >> 16) & 0xFF; *target++ = (colour >> 8) & 0xFF; *target++ = colour & 0xFF; - *target++ = province.is_water() ? 0 : 255; } return SUCCESS; } |