It is possible to merge two fluid systems into one when two forces are merged into one
- Open "fluid-mixing-by-merge_forces
save
Code: Select all
/c game.merge_forces("A", "B")
Code: Select all
/c game.merge_forces("A", "B")
I think hardness depends on internal data structure and implementation that would implement this, not on "just don't connect pipes". What if save contains only data about entities, not about connection between them?
I think best solution is (assuming implementation of entity merging into fluid systems using find-union) when rebuilding fluid system, if there are two entities that may connect, find representative of its set (this represents fluid system) and if they are not compatible (this means: both have fluid assigned but they are different fluids) skip merging of this two entities into one fluid segment. This requires save-file to contain fluidSystemID on every fluid entity (pipe, underground pipe, fluid box). Core idea is to store fluidSystemID to mark that entities that could connect, should be left unconnected. Using find-union, fluid system id could be equal to representative entity unit id.
The save data structure has to contain all needed information to deterministically reproduce any possible game world state. So if pipe connections depend on build order (wich they would obviously do if my proposed solution gets implemented), connectuion data has to be in the save (at least for entities wich would normally connect but do not in the saved game world).
Yes, the problem is that there obviously is a check missing since fluid mixing prevention was added to the game. Joining forces seems to be an overlooked edge case.
Reconnecting undergrounds to other endpoints is fine as long as it does not violate the fluid mixing prevention rule. Undergrounds connect to the nearest appropriately aligned endpoint if allowed to or do not connect at all. That is the defined and expected behaviour.
Remove-create is fine if not blindly connecting stuff that may not be connected. And as long as the order of doing the recreates is deterministic, it should not desync because it is done exactly the same on every copy of the game world.
As fluid systems will not change assigned liquids when not creating forbidden connections and assemblers are assigning fluid to a connected network depending on recipe, assembler recipe loss because of suddenly changing fluids can't happen after fixing the blindly-connecting issue.
I think issue is worst than this. Lets label entities from first post from left assembler to right assembler: A(left assembler)-B(pipe)-C(underground pipe)-D(und.pipe)-E(pipe)-F(assembler), where before merge, A,B,C are in first force containing crude oil and D-E-F are in second force containing acid.Oktokolo wrote: βWed Jul 31, 2019 4:25 amAs fluid systems will not change assigned liquids when not creating forbidden connections and assemblers are assigning fluid to a connected network depending on recipe, assembler recipe loss because of suddenly changing fluids can't happen after fixing the blindly-connecting issue.
Code: Select all
game.merge_forces("A", "B")
Yup. Here is my test setup: When flushed before merge, there are 118 iron plates and 118 copper plates. After merge there are 118 iron plates and 46 copper plates, no item spill
I always assumed, that the devs would use low-level functionality for doing the remove-create without triggering the automatisms the player can't avoid.boskid wrote: βWed Jul 31, 2019 5:49 am Assuming remove-create model (for now it fells like it), after removing B, entity C (already updated) will change fluid system to acid as it can connect to D and is empty (nothing prevents this connection). Then when creating entity B with crude-oil in mind(or pipe), it should not connect to entity C because it changed fluid into acid.
It may look funny but it is just useful skill that helps to discuss about complex code (treat it as black box), not available code or code that is beign designed. That way you may be able to catch design issues before writing any code. Here for me it is not available code so i was inferring about how it is implemented based on artifacts it gives (most likely reason for merging when updating entities was remove-create model with intermediate "automatism"). Even if it would happend i was wrong i would have some insight into what kind of problems i would need to solve.
Why not. When i am wrong (as in this case) i get corrected and learn more about how it actually works. And when i am right, i am happy about that too.
Looks like faction change code needs to tell the setup function, wich fluid lock an FS has to have to be allowed to connect to the new entity. The setup function has to honor that and don't connect FBs if fluid locks do not match.Dominik wrote: βWed Jul 31, 2019 12:01 pm So how it works:
The change force indeed just updates entities one by one. The entities handle that individually, but generally by doing destroy - change force - setup. That is done exactly to trigger all the "automatisms" as they make sure that everything is done correctly (there is a lot going on when removing/adding an entity - connecting or registering to various neighbours and lists etc.).
Changing how setup function works should be avoided here: it would violate SOLID-s SRP - setup function would be polluted with fluid specific variables and would need to check each entity type it is updating as "is it fluid related and should i use this extended interface method that requires extra fluid-lock-or-something-else variable?".Oktokolo wrote: βWed Jul 31, 2019 10:48 pm Looks like faction change code needs to tell the setup function, wich fluid lock an FS has to have to be allowed to connect to the new entity. The setup function has to honor that and don't connect FBs if fluid locks do not match.
If there is a consistency check on load wich checks connections, that probably has to be updated too.
Beeing able to somehow "prime" newly build pipes to belong to a chosen fluid would actually be nice to have in regular gameplay too, as it would be one way to allow compact pipe buses made of regular pipes without the currently mandatory one-tile gap.
It looks like this bug is indeed not fully fixable without introducing new bugs wich are also hard to fix as long as the automatism itself is not able to deal with two differently fluid-locked FS touching eachother. So it looks like as if you literally have no other choice than to allow adjacent pipes to be part of different fluid-locked FSes.
The linked mod allows replacing of pipes with mod-provided pipes that only connect in some directions. That replacement is called clamping on the mod page. It allows players to route pipes adjacent to eachother without autoconnecting them. The mod does clamping in an instantly intuitive way and adds some other piping-related QoL stuff like network and orphan highlighting too. I recommend testing it so you can be impressed about how flexible and user-friendly piping could become and how easy the unfixable bug would be to fix for good if you would have this mod as part of the core mod.
I should have one more now.