Water is not infinite


Makes water a finite resource. Uses a depth map: each water tile has a depth based on its type. Pumps drain lakes; depleted tiles become land. Refill with outfall pipes and rain

Tweaks
26 days ago
2.0
1.18K
Environment Fluids Power

g Sometimes player character is killed when not near water, or is teleported to near water.

a month ago
(updated a month ago)

Background: In non-Space-Age 2.0.72, using water-is-not-infinite_0.11.0, I have built a network of offshore pumps across a large body of water, to supply a large factory. Many of those offshore pumps I have been placing in remote view, using ctrl-shift-click to automatically place landfill underneath first. I also place pipes, pipe-to-ground, roboports, and power lines with ctrl-shift-click to hook it up to the large water network in the lake, and to let the robots reach to build it.

Problem: sometimes the mod seems to be mistaken about the position of my character when checking for flooding.
- One time I got (as best I can remember) an alert about the offshore pump being destroyed, I went to look at the alterted location, and my character was physically teleported to near/at the location it happened. The character was on land a long way from the water before that.
- Another couple of times, I got the console message "wasted, flooded", and my character suddenly died despite being hundreds of meters away in a desert. (And the resulting corpse was at that position in the desert as I expected, not in the water.) I think I was looking at something in remote view at the time, and my remote view might have been centered on water.

I don't know how to reproduce these events other than I keep playing and very rarely they will happen.

I have a load of other mods installed but none look like they would be related to this problem.

My speculation on the cause, from looking at the code, is there may be a difference between the position of player and position of player.character, when in remote view. (But I don't know the API; maybe they are the same after all.) If they are different, then prevent_player_flooding might then mix up the remote view position and the character position, causing the "wasted, flooded", or the teleportation I once observed.

a month ago

You're right that player position and player.character position are two different things.

Recently, a performance-related issue was reported https://mods.factorio.com/mod/water-is-not-infinite/discussion/694a4fd266b7ce6776381506
It turned out that accessing player.character is very expensive.

Anyway, I'll see what I can do. Thanks for the report

a month ago

Thanks!
In the time since I reported it, I have had a couple more teleportations, and now that I know what to look for, it does seem like the mix-up I described. Good luck with the fix.

a month ago

I've just had several character deaths while using the remote view with the debug mode (shift+F10) enabled.

a month ago

It turned out that accessing player.character is very expensive.

I wonder if it would be quicker to first reverse the question: Using the function that counts the entities of a specific type in an area to search for any player characters being there. But you would still need to do it in bulk, (e.g. search whole chunks and remember so you search each chunk only once per tick) not a search every time you update one tile.

a month ago

Who knows... You need to test it to say for sure.

For now, I just cache the character entity, and it seems to work well

New response