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.
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?".
With fluid locks, issue is deeper than it looks like. In current implementation fluid locks are because of existing fluid filters(i assume they are just fluid boxes of assembler that are assigned to specific fluids). Every time network is split in half and "automatism" is triggered, it will recompute that one of pipe branches is now empty-and-unfiltered and so underground disconnected section may become connected. Because of this, remove-create model may not be enough to solve this issue. Better one would be to just change force attribute (as there is no other alternative in this particular case of game.merge_forces) and after all entities are updated, perform global fixing - but i feel there may be some recursions when fixing one entity would require other already fixed to be updated again.
Doing temporary fluid locks directly on entities to which currently updated fluid entity is connected would introduce new issue - this fluid locks when removed, should also trigger "automatism" because of cases where changing force would split some fluid networks:
- temporary-fluid-lock-issue.png (102.43 KiB) Viewed 5626 times
In this case two inner underground pipes when doing fluid-lock to acid, when merging would first disconnect from one acid source and not connect to crude-oil but would still be assigned to acid, then when merging second underground pipe in middle by setting temporary fluid filter on other underground pipe in middle second underground pipe should not connect to other crude-oil. Then when removing this temporary fluid-lock, inner two underground pipes would isolate, become empty and not assigned and so they would need to be assigned to crude-oil when removing temporary fluid-lock.
Expanding fluid-lock idea to other issues, there are again problems that would come to solve: for example it would prevent some actions that are allowed using other sequence of actions:
- it would prevent rotation that should be allowed but which changes fluid content of some pipes:
- temporary-fluid-lock-issue-2.png (55.1 KiB) Viewed 5626 times
That would be because 3-pipe "L" part would be locked to acid and so fluid mixing detection would kick in and prevent rotation. (ref:
73884)
- it would prevent entity teleportation that should be allowed:
- temporary-fluid-lock-issue-3.png (56.99 KiB) Viewed 5626 times
Here 2-pipe "I" would become locked and so moving underground pipe 1 tile up again kick-in fluid mixing detecion and would prevent teleportation (ref:
73840)
These cases are extra annoying: they cannot be solved by doing create-remove ("lets test if dest is viable before removing src entity") because they would enter fluid-mixing when they are legit.
For now best solution i can think of would be to create temporary copy of all fluid entities, check if doing update in question would create fluid-mixing then drop this copy. Based on result changes would be performed (they would not create fluid-mixing) or would be rejected without changing anything in game state. This would solve rotation, teleport and upgrade issues but not issue from this bug report...
They are even more annoying because checking if 3-pipe "L" part for rotation or 2-pipe "I" part for teleport would become not filtered when removing entity in question would need whole fluid-system traversal to find if there are other paths to fluid filter that are not going through entity in question. This would need at least O(n) extra memory to perform DFS or BFS as a way to find if any path to fluid-filter exists that is not going through entity in question. This may be part of solution for rotation and teleportation as it would tell if fluid entities that should connect after rotation/teleportation will become compatible after removal of current entity without actual removal of entity.
Then we go to super extra annoying cases: by doing DFS or BFS to check if fluid boxes in new configuration are compatible, we decide "it will not kick-in fluid mixing so we can remove entity in question", this triggers "automatism", system that was decided to be empty-and-not-assigned may connect by disconnected underground pipe pair and so action action should be aborted:
- temporary-fluid-lock-issue-4.png (89.19 KiB) Viewed 5626 times
Here as right underground pipes are disconnected, DFS or BFS would detect that 3-pipe "L" section would become unassigned, on removal of underground pipe if would however assign "L" section to water. (this case however for now is working fine)
edit:
- temporary-fluid-lock-issue-5.png (87.99 KiB) Viewed 5624 times
This case is broken: underground to water is disconnected, so inner "I" section is assigned to acid only by underground pipe going to acid assembler. However when trying to teleport underground pipe from middle-bottomleft to middle-upleft (to change connection to crude-oil), it should work but for now fluid mixing prevention kicks in (after removal of UP inner part is assigned to water) and entity is not moved, it is then restored and creates fluid mixing of acid and water
edit:
- pipe-teleport-issue.png (92.99 KiB) Viewed 5609 times
This case is also interesting: by teleporting underground pipe to connect to crude-oil, when using DFS/BFS to find other connections to acid there would be none so this teleport should be allowed but then by removing underground pipe from source position there would be new path for acid and so teleport would fail if acid underground pipes (on longer path) would connect