I have a function that runs when one kills an enemy that checks the terrain and if in list, converts it to another terrain.
The problem I'm having is that it's turning water into land, even though I do a check against a tile set before doing the conversion.
Was wondering if I had an error in my logic or if it's just the way the game converts land/tiles that is causing this. I think because it always tries to create a boarder, it will fill in the water as a result. Not sure if I can prevent that.
Here is my code: I supply the function below with a Size = 2 if unit and a Size = 4 if spawner.
Code: Select all
---- Only convert the below tiles:
local replaceableTiles =
{
["grass"] = "grass-medium",
["grass-medium"] = "grass-dry",
["grass-dry"] = "sand",
["sand"] = "sand-dark",
["sand-dark"] = "dirt",
["dirt"] = "dirt-dark"
}
---------------------------------------------
function Scorched_Earth(surface, pos, size)
--- Turn the terrain into desert
local currentTilename = surface.get_tile(pos.x, pos.y).name
local New_tiles = {}
for xxx=-size,size do
for yyy=-size,size do
new_position = {x = pos.x + xxx,y = pos.y + yyy}
currentTilename = surface.get_tile(new_position.x, new_position.y).name
if replaceableTiles[currentTilename] then -- <check to make sure it's not water, right?
table.insert(New_tiles, {name=replaceableTiles[currentTilename], position=new_position})
end
end
end
surface.set_tiles(New_tiles)
end
---------------------------------------------