CRPL FloodFillTerrain Function

Started by Hubs, November 11, 2015, 08:25:01 AM

Previous topic - Next topic

Hubs

I'm looking for some more information on the FloodFillTerrain function. From what I've read on the wiki, it appears to get all cells on the same level of terrain within a range, effectively like the collector green area. Is this true? I haven't seen any other reference to it in the forums or seen anything like this used in a map.

knucracker

Yeah, it starts at the specified cell and then does search across connected terrain cells that are within the specified height range.  The results are returned as a list.  Here's an example the eduran did that I happened to find by searching my stockpile of crpl scripts.

--

# Lake.crpl
# Created by: eduran
# inspired by the endless ocean used in 3P Hawai'i
# ------------------------------------------

# This script finds all cells connected to the starting cell by terrain of the specified height.
# These cells are filled with creeper. Any Walls found are removed and creeper will continuously
# spawn at their former locations.

$refillInterval:15
$lakeMinHeight:4
$lakeMaxHeight:4
$startingCellX:44
$startingCellY:38
$fillHeight:1.0
$refillPerTick:0.07

once
FloodFillTerrain(<-startingCellX <-startingCellY <-lakeMinHeight <-lakeMaxHeight 0 0 -1) ->LakeCells
CreateList ->RefillCellsX
CreateList ->RefillCellsY
do(GetListCount(<-LakeCells) 0)
@Convert2XYCoords(GetListElement(<-LakeCells i)) ->y ->x
if(GetWall(<-x <-y) neq0)
SetWall(<-x <-y 0)
AppendToList(<-RefillCellsX <-x)
AppendToList(<-RefillCellsY <-y)
endif
SetCreeper(<-x <-y <-fillHeight sub(0.05))
loop
GetListCount(<-RefillCellsX) ->nOfCells
endonce

do(<-nOfCells 0)
GetListElement(<-RefillCellsX i) ->x
GetListElement(<-RefillCellsY i) ->y
GetCreeper(<-x <-y) ->cAmt
if(<-cAmt lt(<-fillHeight sub(<-refillPerTick)))
AddCreeper(<-x <-y <-refillPerTick)
else if(<-cAmt lt(<-fillHeight))
AddCreeper(<-x <-y <-fillHeight sub(<-cAmt))
endif endif
loop

:Convert2XYCoords
# converts uni-coordinate into x and y coordinate
# i1 - x1 y1
->tmp
<-tmp mod(MapWidth)
<-tmp div(MapWidth)

Hubs