Tile Replacement Question

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Tile Replacement Question

Post by TheSAguy »

Hi,
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
---------------------------------------------
Thanks.

Rockstar04
Fast Inserter
Fast Inserter
Posts: 171
Joined: Sun Feb 17, 2013 4:31 pm
Contact:

Re: Tile Replacement Question

Post by Rockstar04 »

I've found (in 0.12, which I think is still the same in 0.13) that the game needs to have a 1 tile wide strip of grass around all water, so if you run you check, return grass and try to change it to something else, it will turn some of the water to grass. The only way I can think to stop this is to check in all directions for water, and cancel your tile update.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Tile Replacement Question

Post by TheSAguy »

Rockstar04 wrote:I've found (in 0.12, which I think is still the same in 0.13) that the game needs to have a 1 tile wide strip of grass around all water, so if you run you check, return grass and try to change it to something else, it will turn some of the water to grass. The only way I can think to stop this is to check in all directions for water, and cancel your tile update.
This is exactly what I was thinking was happening.
Not precisely sure how to updated my function to do the checkthough.

Veden
Filter Inserter
Filter Inserter
Posts: 294
Joined: Wed Jul 13, 2016 3:54 pm
Contact:

Re: Tile Replacement Question

Post by Veden »

If you use
surface.set_tiles(New_tiles, false)
then it wont try to correct the tiles surrounding the changed tiles, but it may lead to the tiles looking funny.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Tile Replacement Question

Post by TheSAguy »

Veden wrote:If you use
surface.set_tiles(New_tiles, false)
then it wont try to correct the tiles surrounding the changed tiles, but it may lead to the tiles looking funny.
It works :) As you said, a little to get use to, but I think it's better than landfill :)
Thanks!

Post Reply

Return to “Modding help”