diff --git a/src/pathfinder/water_regions.cpp b/src/pathfinder/water_regions.cpp index 7c327cd6a4..72a409d857 100644 --- a/src/pathfinder/water_regions.cpp +++ b/src/pathfinder/water_regions.cpp @@ -19,10 +19,11 @@ #include "../ship.h" #include "../debug.h" #include "../3rdparty/fmt/ranges.h" +#include "../core/convertible_through_base.hpp" #include "../safeguards.h" using TWaterRegionTraversabilityBits = uint16_t; -constexpr TWaterRegionPatchLabel FIRST_REGION_LABEL = 1; +constexpr TWaterRegionPatchLabel FIRST_REGION_LABEL{1}; static_assert(sizeof(TWaterRegionTraversabilityBits) * 8 == WATER_REGION_EDGE_LENGTH); static_assert(sizeof(TWaterRegionPatchLabel) == sizeof(uint8_t)); // Important for the hash calculation. @@ -36,7 +37,7 @@ static inline int GetWaterRegionY(TileIndex tile) { return TileY(tile) / WATER_R static inline int GetWaterRegionMapSizeX() { return Map::SizeX() / WATER_REGION_EDGE_LENGTH; } static inline int GetWaterRegionMapSizeY() { return Map::SizeY() / WATER_REGION_EDGE_LENGTH; } -static inline TWaterRegionIndex GetWaterRegionIndex(int region_x, int region_y) { return GetWaterRegionMapSizeX() * region_y + region_x; } +static inline TWaterRegionIndex GetWaterRegionIndex(int region_x, int region_y) { return TWaterRegionIndex(GetWaterRegionMapSizeX() * region_y + region_x); } static inline TWaterRegionIndex GetWaterRegionIndex(TileIndex tile) { return GetWaterRegionIndex(GetWaterRegionX(tile), GetWaterRegionY(tile)); } using TWaterRegionPatchLabelArray = std::array; @@ -50,7 +51,7 @@ class WaterRegionData { std::array edge_traversability_bits{}; std::unique_ptr tile_patch_labels; // Tile patch labels, this may be nullptr in the following trivial cases: region is invalid, region is only land (0 patches), region is only water (1 patch) bool has_cross_region_aqueducts = false; - TWaterRegionPatchLabel number_of_patches = 0; // 0 = no water, 1 = one single patch of water, etc... + TWaterRegionPatchLabel::BaseType number_of_patches{0}; // 0 = no water, 1 = one single patch of water, etc... }; /** @@ -183,7 +184,7 @@ public: if (increase_label) current_label++; } - this->data.number_of_patches = highest_assigned_label; + this->data.number_of_patches = highest_assigned_label.base(); if (this->NumberOfPatches() == 0 || (this->NumberOfPatches() == 1 && std::all_of(this->data.tile_patch_labels->begin(), this->data.tile_patch_labels->end(), [](TWaterRegionPatchLabel label) { return label == FIRST_REGION_LABEL; }))) { @@ -221,8 +222,8 @@ public: } }; -std::vector _water_region_data; -std::vector _is_water_region_valid; +ReferenceThroughBaseContainer> _water_region_data; +ReferenceThroughBaseContainer> _is_water_region_valid; static TileIndex GetTileIndexFromLocalCoordinate(int region_x, int region_y, int local_x, int local_y) { @@ -274,7 +275,7 @@ static TWaterRegionIndex GetWaterRegionIndex(const WaterRegionDesc &water_region */ int CalculateWaterRegionPatchHash(const WaterRegionPatchDesc &water_region_patch) { - return water_region_patch.label | GetWaterRegionIndex(water_region_patch) << 8; + return water_region_patch.label.base() | GetWaterRegionIndex(water_region_patch).base() << 8; } /** diff --git a/src/pathfinder/water_regions.h b/src/pathfinder/water_regions.h index 3cccc6dc37..b5749991ae 100644 --- a/src/pathfinder/water_regions.h +++ b/src/pathfinder/water_regions.h @@ -10,15 +10,16 @@ #ifndef WATER_REGIONS_H #define WATER_REGIONS_H +#include "../core/strong_typedef_type.hpp" #include "../tile_type.h" #include "../map_func.h" -using TWaterRegionPatchLabel = uint8_t; -using TWaterRegionIndex = uint; +using TWaterRegionIndex = StrongType::Typedef; +using TWaterRegionPatchLabel = StrongType::Typedef; constexpr int WATER_REGION_EDGE_LENGTH = 16; constexpr int WATER_REGION_NUMBER_OF_TILES = WATER_REGION_EDGE_LENGTH * WATER_REGION_EDGE_LENGTH; -constexpr TWaterRegionPatchLabel INVALID_WATER_REGION_PATCH = 0; +constexpr TWaterRegionPatchLabel INVALID_WATER_REGION_PATCH{0}; /** * Describes a single interconnected patch of water within a particular water region.