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

Method enableFloodFill

source/gamemap/GameMap.cpp:2277–2442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2275}
2276
2277void GameMap::enableFloodFill()
2278{
2279 // Carry out a flood fill of the whole level to make sure everything is good.
2280 // Start by setting the flood fill color for every tile on the map to -1.
2281 for (int jj = 0; jj < getMapSizeY(); ++jj)
2282 {
2283 for (int ii = 0; ii < getMapSizeX(); ++ii)
2284 {
2285 getTile(ii,jj)->resetFloodFill();
2286 }
2287 }
2288
2289 // The algorithm used to find a path is efficient when the path exists but not if it doesn't.
2290 // To improve path finding, we tag the contiguous tiles to know if a path exists between 2 tiles or not.
2291 // Because creatures can go through ground, water or lava, we process all of theses.
2292 // Note : when a tile is digged, floodfill will have to be refreshed.
2293 mFloodFillEnabled = true;
2294
2295 // To optimize floodfilling, we start by tagging the dirt tiles with fullness = 0
2296 // because they are walkable for most creatures. When we will have tagged all
2297 // thoses, we will deal with water/lava remaining (there can be some left if
2298 // surrounded by not passable tiles).
2299 FloodFillType currentType = FloodFillType::ground;
2300 // We do the floodfill for the rogue seat. Then, once it is done, we copy for the other seats.
2301 // If there are locked doors, floodfill will be refreshed when they are added
2302 Seat* rogueSeat = getSeatRogue();
2303 while(true)
2304 {
2305 int yy = 0;
2306
2307 bool isTileFound;
2308 isTileFound = false;
2309 while(!isTileFound && (yy < getMapSizeY()))
2310 {
2311 for(int xx = 0; xx < getMapSizeX(); ++xx)
2312 {
2313 Tile* tile = getTile(xx, yy);
2314 if(tile->getFullness() > 0.0)
2315 continue;
2316
2317 if(currentType == FloodFillType::ground)
2318 {
2319 if(((tile->getType() == TileType::dirt) ||
2320 (tile->getType() == TileType::gold) ||
2321 (tile->getType() == TileType::rock)) &&
2322 (tile->getFloodFillValue(rogueSeat, FloodFillType::ground) == Tile::NO_FLOODFILL))
2323 {
2324 isTileFound = true;
2325 if(tile->getFloodFillValue(rogueSeat, FloodFillType::ground) == Tile::NO_FLOODFILL)
2326 tile->replaceFloodFill(rogueSeat, FloodFillType::ground, nextUniqueFloodFillValue());
2327 if(tile->getFloodFillValue(rogueSeat, FloodFillType::groundWater) == Tile::NO_FLOODFILL)
2328 tile->replaceFloodFill(rogueSeat, FloodFillType::groundWater, nextUniqueFloodFillValue());
2329 if(tile->getFloodFillValue(rogueSeat, FloodFillType::groundLava) == Tile::NO_FLOODFILL)
2330 tile->replaceFloodFill(rogueSeat, FloodFillType::groundLava, nextUniqueFloodFillValue());
2331 if(tile->getFloodFillValue(rogueSeat, FloodFillType::groundWaterLava) == Tile::NO_FLOODFILL)
2332 tile->replaceFloodFill(rogueSeat, FloodFillType::groundWaterLava, nextUniqueFloodFillValue());
2333 break;
2334 }

Callers

nothing calls this directly

Calls 7

resetFloodFillMethod · 0.80
getFullnessMethod · 0.80
getFloodFillValueMethod · 0.80
toStringFunction · 0.50
getTypeMethod · 0.45
replaceFloodFillMethod · 0.45

Tested by

no test coverage detected