I wrote a function that changes the terrain when you kill a biter or spawner. I don't think the code is very optimized and can probably be written better.
When terrain is replaced there is a boarder around the replaced terrain also, so this causes landfill when done near water. So when you kill a biter or spwaner, I look at the terrain around the area also and if water, I add the "false" to "surface.set_tiles(New_tiles, false)". This causes no boarder to form, though the replaced terrain is blocky.
So here is my current code and was just wondering if anyone had a better/more efficient way of doing this:
Code: Select all
local replaceableTiles =
{
["grass"] = "grass-medium",
["grass-medium"] = "grass-dry",
["grass-dry"] = "sand",
["sand"] = "sand-dark",
["sand-dark"] = "dirt",
["dirt"] = "dirt-dark"
}
local waterTiles =
{
["deepwater"] = true,
["deepwater-green"] = true,
["water"] = true,
["water-green"] = true
}
---------------------------------------------
function Scorched_Earth(surface, pos, size)
--- Turn the terrain into desert
local New_tiles = {}
local Water_Nearby = false
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
writeDebug("The current tile is: " .. currentTilename)
if waterTiles[currentTilename] then
Water_Nearby = true
end
if replaceableTiles[currentTilename] then
table.insert(New_tiles, {name=replaceableTiles[currentTilename], position=new_position})
end
end
end
if Water_Nearby then
surface.set_tiles(New_tiles, false)
else
for xxx=-(size+6),(size+6) do
for yyy=-(size+6),(size+6) do
new_position = {x = pos.x + xxx,y = pos.y + yyy}
currentTilename = surface.get_tile(new_position.x, new_position.y).name
if waterTiles[currentTilename] then
Water_Nearby = true
end
end
end
if Water_Nearby then
surface.set_tiles(New_tiles, false)
else
surface.set_tiles(New_tiles)
end
end
end