MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / refreshFloodFill

Method refreshFloodFill

source/gamemap/GameMap.cpp:2219–2275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2217}
2218
2219void GameMap::refreshFloodFill(Seat* seat, Tile* tile)
2220{
2221 std::vector<uint32_t> colors(static_cast<uint32_t>(FloodFillType::nbValues), Tile::NO_FLOODFILL);
2222
2223 // If the tile has opened a new place, we use the same floodfillcolor for all the areas
2224 for(uint32_t i = 0; i < colors.size(); ++i)
2225 {
2226 FloodFillType type = static_cast<FloodFillType>(i);
2227 if(!tile->isFloodFillPossible(seat, type))
2228 continue;
2229
2230 for(Tile* neigh : tile->getAllNeighbors())
2231 {
2232 uint32_t neighColor = neigh->getFloodFillValue(seat, type);
2233 if(neighColor == Tile::NO_FLOODFILL)
2234 continue;
2235
2236 colors[i] = neighColor;
2237 break;
2238 }
2239 }
2240
2241 // Now, we fill floodfill if no color was found on any neighboor tile
2242 // That might happen if a tile surrounded by water is dug
2243 for(uint32_t i = 0; i < colors.size(); ++i)
2244 {
2245 FloodFillType type = static_cast<FloodFillType>(i);
2246 if(colors[i] != Tile::NO_FLOODFILL)
2247 continue;
2248
2249 if(!tile->isFloodFillPossible(seat, type))
2250 continue;
2251
2252 colors[i] = nextUniqueFloodFillValue();
2253 }
2254
2255 // Now, we update the tile and its neighboors
2256 for(uint32_t i = 0; i < colors.size(); ++i)
2257 {
2258 const uint32_t& color = colors[i];
2259 FloodFillType type = static_cast<FloodFillType>(i);
2260 if(color == Tile::NO_FLOODFILL)
2261 continue;
2262
2263 tile->replaceFloodFill(seat, type, color);
2264 for(Tile* neigh : tile->getAllNeighbors())
2265 {
2266 uint32_t neighColor = neigh->getFloodFillValue(seat, type);
2267 if(neighColor == Tile::NO_FLOODFILL)
2268 continue;
2269 if(neighColor == color)
2270 continue;
2271
2272 replaceFloodFill(seat, type, neighColor, color);
2273 }
2274 }
2275}
2276

Callers 1

setFullnessMethod · 0.80

Calls 3

isFloodFillPossibleMethod · 0.80
getFloodFillValueMethod · 0.80
replaceFloodFillMethod · 0.45

Tested by

no test coverage detected