Is there a way to interecept the landfill event?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Is there a way to interecept the landfill event?

Post by Impatient »

Bafore a tile of water is filled in, I would like to do some calculations and conditinally allow the landfill. Is this possible?

Thanks!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Is there a way to interecept the landfill event?

Post by eradicator »

In general no event in factorio can be "cancelled". The event system merely informs you that something *has already* happend. The only option is to reverse the changes, which can be a real pain to do.

on_x_built_tile contains tiles :: array of OldTileAndPosition: The position data., which you can check for "was this a water tile". And if your condition isn't fullfilled you can then try to given the player back the item they just used to remove the water. And as far as i know there's no way to "give" items to a robot, so you'd have to do with the item in that case.

If this is about your dynamic waterfilling, a better solution for blueprints might be to check on_built_entity for landfill ghosts, then replace them with a generated simple_entity that costs as many landfill as you want, that way robots will bring the right amount of stuff to the tile ghost and you don't have to worry about that. See curved-rail for how to make an entity that requires more than one item to revive.

Edit:
Hm..there is robot.get_inventory(defines.inventory.robot_cargo), so it's not impossible to give the item *back* to a robot. But that doesn't matter as a construction bot won't ever carry more items to a ghost than it thinks it needs.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Re: Is there a way to interecept the landfill event?

Post by Impatient »

Hey eradicator,

thanks for your help! That is exactly what I needed to further pursue my idea.

The general idea I have, consists of another extra, I did not yet mention: I don't just want the water to have to be filled in with an amount of landfill according to its depth. I also want to prohibit, that water tiles are filled, if there are "deeper" water tiles adjacent to it. In that case the water tile that was filled, will be set back to its former depth and the adjacent tile will be filled, triggering the same logic recursively. This will lead to a trickle-down effect. Like when you fill in water and the filler material rolls/slides downhill under water, until it comes to a rest. With this effect it will not be possible to fill in water of various depths vertically. Instead it will creat an underwater hill, which's top rises above the water line eventually, given enough filling.

I had a look at what you pointed me to: on_player_built_tile and on_robot_built_tile. Both these events have the property OldTileAndPosition, which include the old tile. This is great news as I can now further explore pleegwat's suggestion on how to implement water of differing depths: Creating new tilesets for water of differing depth. This way I can use the chunk creation algorithm to create nicely looking seabeds. I already had a look in the code of vanila's base mod on how the chunk creation algo knows when to use the tilesets for deepwater and water. It is set in a tilesets AutoplaceSpecification if I recall right. As far as I understood it, the mechnism can be extended to n tilesets for water. This btw would not need to put back landfill in the players or robots inventory (sorry, the question was misleading in that regard).

Cheers mate, thanks a lot! You provided me another piece to the puzzle. :)

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Is there a way to interecept the landfill event?

Post by eradicator »

Impatient wrote:
Sat May 11, 2019 1:56 pm
This will lead to a trickle-down effect.
That is much easier to implement, and should certainly lead to a better user experience. Though you will have to think about a way to "fix" blueprinting of landfill. I.e. when i want a 10x10 area of land filled in a lake, i don't want to babysit the thing and reorder the filling each time it fails to be "high enough". Best workflow would be on_tile_built -> trickel down -> is original tile filled now? -> if no -> spawn a new ghost to order more landfill.

From a gameplay perspective i'm still sceptical. The general effect would be that landfill effectively becomes x% more expensive, where x% is a quasi-fixed factor based on how much deeper the water is on average. I guess the trickle-down effect also strongly disfavours building of land-bridges accross lakes (compared to expanding the shore a bit) - as they need to trickle down on every side. Do you have a fixed "vision" of what effect you want to have on gameplay, or do you just want to make it "more realistic", or something else?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Re: Is there a way to interecept the landfill event?

Post by Impatient »

I did not think about the implications on blueprinted landfill until now. What you suggest, sounds like the way to go in this regard.

My general idea is to make landfill more realistic but not impossible. Claiming land from the sea will be much more expensive and realistic than in vanilla or with existing mods that make the landfill item more expensive. As you mention, building landbridges accross the deap sea will be inefficient for just getting somewhere on foot, because of its immense cost, as there has to be a slope on each side of the landbridge. A landbridge will maybe pay off for train tracks. The sea then is not just flat and landfill has volume. This idea came to me, when I played around with water related mods like ones for swimming, ships, platforms, bridges, etc ... . A modification like this can be a complement to them - but also be used on its own. Giving a map a depth to its water tiles, would be like adding a little new dimmension to it and the necessity to deal with it. That spawns more ideas, like ... sea pylons, made from concrete and steel, dredges for making landfill and so on. Or maybe this will spawn other, less trivial follow up ideas. But in any case, it seems like a worthy, simple addition to the game, that smoothes out one of its "sharp edges".

User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Separate project thread for the deep water mod created

Post by Impatient »

FYI

I created a separate idea and project theread here, to bundle everything connected with the deep water mod idea.

User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Re: Is there a way to interecept the landfill event?

Post by Impatient »

eradicator wrote:
Sat May 11, 2019 2:25 pm
Best workflow would be on_tile_built -> trickel down -> is original tile filled now? -> if no -> spawn a new ghost to order more landfill.
eradicator wrote:
Sat May 11, 2019 8:40 am
If this is about your dynamic waterfilling, a better solution for blueprints might be to check on_built_entity for landfill ghosts, then replace them with a generated simple_entity that costs as many landfill as you want, that way robots will bring the right amount of stuff to the tile ghost and you don't have to worry about that. See curved-rail for how to make an entity that requires more than one item to revive.
I am currently looking into this. I had a look on on_built_entity in the API doc, but there are several things I do not understand yet. Do you suggest that this event also triggers if a player places a ghost? So that it would be possible to find out if a landfill ghost was placed?
That would be handy, because the on_x_built_tile events do not state if there was a ghost before or not. But that way I could at least keep track of landfill ghosts and their positions and then compare this to the position of the _built_tile event.

A generated simple entity that costs several landfill is an interesting idea. I'll keep it in mind.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Is there a way to interecept the landfill event?

Post by eradicator »

Not much time so very short answer:
on_robot_*_built is raised when a robot *revives* a ghost.
on_player_*_built is raised when the player builds a building *or* a ghost.

Players can not revive ghosts (though a mod may implement such functionality and raise script_raised_revive).
Thus there is no need to "keep track" of all ghosts. Because the robot event implies one existed.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Re: Is there a way to interecept the landfill event?

Post by Impatient »

eradicator wrote:
Sun May 12, 2019 7:40 am
... no need to "keep track" of all ghosts. Because the robot event implies one existed.
Ah, man, now I feel stupid :-D Of course, when a robot builds a tile, then there must have been a ghost before.

What about the case when there was a ghost and a player filled the water manually? I mean, it is not an edge case. Players placing BPs and then filling them in manually happens very often.
I assume, in that case on_player_built_tile is raised. If that is true, I still need to find a way to find out if a ghost was there before.
Imagine a player placing a blueprint over water. The robots start bringing landfill, the landfill trickles down and the seabed slowly starts to rise. The player grows impatient and starts to throw in landfill from the inventory manually, only to experience, that the robots stopped filling in certain spots after the palyer did that and everything slowed down even more. That would be a situation where I personally would get mad at the mod. :-D

I am going to spawn a new help thread for that question as it is distinct from the one asked here.
Last edited by Impatient on Mon May 13, 2019 2:30 am, edited 1 time in total.

User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Re: Is there a way to interecept the landfill event?

Post by Impatient »

I spawned a new thread to disquss the question of
How to determine if a ghost was on a tile when something was built

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Is there a way to interecept the landfill event?

Post by eradicator »

Impatient wrote:
Mon May 13, 2019 2:28 am
What about the case when there was a ghost and a player filled the water manually?
Same thing that happens when you build an inserter on an assembler ghost. The ghost is removed, then the inserter is placed. I don't think there's an event for the removal of the ghost, but i only did minimal testing.

Edit: Hm...apparently in 0.17 the player *can* "fill in" a ghost of an assembler in that placing a ghost-equivalent machine on a ghost will actually retain the recipe. Don't think that was the case before. And no clue if it's possible to detect.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”