Turn off water tile correction?

Place to get help with not working mods / modding interface.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Turn off water tile correction?

Post by aubergine18 »

So, I've been working on bridges:

Image

Between the two ends of the bridge, I detect water tiles and replace them with fake water tiles that don't collide with player layer. Result is that player can walk on them. Then I place the wooden bridge entities over the top.

So far, so good. However, despite my best efforts, the land tiles are still getting changed by the presence of the fake water tiles which you can even see on the image above, but here is a clearer example:

Before placing bridge:

Image

After:

Image

See how the land tiles near bottom left have changed due to presence of the fake water?

I've tried to stop that happening as follows:

1. I've set `needs_correction = false` on the fake water tile prototypes.
2. I've set second param of set_tiles() to false (to make it not correct tiles)

But despite both of those things, any land tiles adjacent to fake water tiles get "corrected".

Any ideas? (or are there better ways to allow walking on water?)
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
Reinard-kun
Inserter
Inserter
Posts: 21
Joined: Wed Jan 14, 2015 7:35 pm
Contact:

Re: Turn off water tile correction?

Post by Reinard-kun »

OK so I have a rather dumb idea.
What you want is a bridge, like landfill, but with autoplace. So why don't you just create a custom tile that looks like a bridge above water and place it in the land tiles layer? I can try to make a test mod, however I never worked with autoplace-controls and it may take some time.
Rational thinking is awesome, except if you're dealing with women.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5286
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Turn off water tile correction?

Post by Klonan »

How are you settings the tiles?

I've never had the correction when done like this:

Code: Select all

 local tiles = {} for X = -10,10 do table.insert(tiles, {name = "water", position = {X,0}}) end game.surfaces[1].set_tiles(tiles, false) 
Which ends up looking like this:

Image
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Turn off water tile correction?

Post by aubergine18 »

Klonan wrote:How are you settings the tiles?

I've never had the correction when done like this:

Code: Select all

 local tiles = {} for X = -10,10 do table.insert(tiles, {name = "water", position = {X,0}}) end game.surfaces[1].set_tiles(tiles, false) 

I'm using set_tiles(tiles, false) like you. Maybe it only happens when fake water is placed on existing water?

I'll do some more testing to see if I can find the cause.
Reinard-kun wrote:OK so I have a rather dumb idea.
What you want is a bridge, like landfill, but with autoplace. So why don't you just create a custom tile that looks like a bridge above water and place it in the land tiles layer? I can try to make a test mod, however I never worked with autoplace-controls and it may take some time.
No, I don't want autoplace. The bridges are manually placed, with a little bit of scripting magic to make that a enjoyable task.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5286
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Turn off water tile correction?

Post by Klonan »

aubergine18 wrote:
Klonan wrote:How are you settings the tiles?

I've never had the correction when done like this:

Code: Select all

 local tiles = {} for X = -10,10 do table.insert(tiles, {name = "water", position = {X,0}}) end game.surfaces[1].set_tiles(tiles, false) 

I'm using set_tiles(tiles, false) like you. Maybe it only happens when fake water is placed on existing water?

I'll do some more testing to see if I can find the cause.

setting water-green over water seems to work just fine:

Image
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Turn off water tile correction?

Post by aubergine18 »

@Klonan: Just done some more testing and I can confirm that the issue is still happening.

My code for reference:

Code: Select all

-- control.lua
local toFake, fromFake = {}, {}
local waterTiles = { 'water', 'water-green', 'deepwater', 'deepwater-green' }
for _,name in ipairs( waterTiles ) do
  local fake = 'fake-'..name
  toFake[name] = fake
  fromFake[fake] = name
end

local function getArea( from, to )
  local floor = math.floor
  return Area.adjust (
    Area.construct (
      floor(from.x),
      floor(from.y),
      floor(  to.x),
      floor(  to.y)
    )
  )
end

-- construct the bridge between two end points
local function build( from, to )
  local surface = from.surface
  local path = getArea( from.position, to.position )
  local tiles = {}

  for x,y in Area.iterate( path ) do

    local tile = surface.get_tile( x, y ).name
    local fakeTile = toFake[tile]


    if fakeTile then -- replace with fake water
      from.surface.create_entity {
        name = 'map-overlay', --> just some flying text
        position = {x,y},
        force = from.force,
        text = 'FW',
        color = { r=0, g=1, b=0, a=1 }
      }.active = false;

      table.insert( tiles, { name = fakeTile, position = {x,y} } )
    end

  end--for

  if #tiles > 0 then surface.set_tiles( tiles, false) end

end
The `from`, `to` passed in to `build()` are the entities representing the two ends of teh bridge (as illustrated in first image of OP), with `build()` being triggered once the second entity is placed.

The fake water I'm using is generated as follows:

Code: Select all

--data.lua
local waterTypes = { 'water', 'water-green', 'deepwater', 'deepwater-green' }

for _,current in ipairs( waterTypes ) do
  local original = data.raw.tile[current]
  if original then

    local fake = table.deepcopy( original )

    fake.ageing                   = original.ageing - 0.0001
    fake.allowed_neighbors        = nil
    fake.autoplace                = nil
    fake.can_be_part_of_blueprint = false;
    fake.collision_mask           = { 'ground-tile', 'item-layer', 'doodad-layer', 'resource-layer' }
    fake.decorative_removal_probability = 1
    fake.name                     = 'fake-'..original.name
    fake.needs_correction         = false;

    data:extend { fake }

  end
end
Note: I'm not creating water on land as per your example, I'm replacing existing water with fake water. It's as if the existing land tiles around those replacements are auto-"correcting" themselves, regardless of the settings provided either to the fake water tile prototypes or the `set_tiles()` method.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5286
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Turn off water tile correction?

Post by Klonan »

Are you taking into consideration that the edge of the water is grass tiles, so you should set them along with setting the water
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Turn off water tile correction?

Post by aubergine18 »

No, I wasn't. So I should set the surrounding grass tiles also? That seems to defeat the purpose of having the second parameter to `set_tiles()`? I thought the whole point of that parameter was to prevent adjacent tiles from being "corrected". Will I also need to set the adjacent water next to those grass tiles to water, and then the adjacent grass tiles to that water to grass, and so on, recursively, until entire lake has been recreated?
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5286
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Turn off water tile correction?

Post by Klonan »

aubergine18 wrote:No, I wasn't. So I should set the surrounding grass tiles also? That seems to defeat the purpose of having the second parameter to `set_tiles()`? I thought the whole point of that parameter was to prevent adjacent tiles from being "corrected". Will I also need to set the adjacent water next to those grass tiles to water, and then the adjacent grass tiles to that water to grass, and so on, recursively, until entire lake has been recreated?
It should work, the way you have it, and in my usage it has always worked properly. I don't know specifically what you are doing differently
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Turn off water tile correction?

Post by aubergine18 »

Tried setting some of the grass, it made things much worse:

Image

The reason I wanted to leave the grass completely unchanged is that it was correct sprites prior to my fake water being added. However, as soon as I start adding grass, with the `correct_tiles` param set to `false`, I also start getting solid regions of grass next to water (which looks bad), and the weird artefacts with surrounding grass still persist.

To me, the second param of set_tiles() is bugged, in that it doesn't apply to adjacent tiles outside the region being changed. If I have to also redraw those tiles, then I need to draw their adjacent tiles, and so on, until entire lake is recreated, and then hope that nothing weird happens with the land outside the lake, otherwise I have to redraw all of that too. :/

Time for a bug report me thinks.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Turn off water tile correction?

Post by aubergine18 »

Updated `build()` function for that last screenshot (moved the flying text out in to an `addText()` function, not included below for sake of brevity):

Code: Select all

-- construct the bridge between two end points
local function build( from, to )
  local surface = from.surface
  local path = getArea( from.position, to.position )
  local tiles = {}

  for x,y in Area.iterate( path ) do

    local tile = surface.get_tile( x, y ).name
    local fakeTile = toFake[tile]

    if fakeTile then -- replace with fake water
      table.insert( tiles, { name = fakeTile, position = {x,y} } )
      addText( surface, x, y, 'fake' )
    else
      table.insert( tiles, { name = tile    , position = {x,y} } )
      addText( surface, x, y, 'grass' )
    end

  end--for

  if #tiles > 0 then surface.set_tiles( tiles, false ) end

end
This illustrates the issue I'm facing, the only way to not correct adjacent tiles is to redraw them, which still causes their adjacent tiles to be corrected (wrongly) and also results in unwanted full patches of grass at water edge.

But report added: viewtopic.php?f=7&t=34465
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Turn off water tile correction?

Post by aubergine18 »

I'm still trying out various things and found that turning tile correction ON actually made things slightly better. Fewer tiles are disrupted on average.

EDIT: Just noticed via the hint text on GUI that it's a table { player_index = ... }

Would it be possible to add to that table: creative_mode = true -- this would make it much easier to confirm that creative mode did the remote call, ie. distinguish it from some other mod making the call (`if param1 and param1.creative_mode then ...`).
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding help”