Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a custom input/output template option #15

Merged
merged 1 commit into from
Sep 11, 2023

Conversation

ignaloidas
Copy link
Contributor

Allows for some very funky balancer layouts, like for example, this 4-4 balancer
Screenshot_20230812_020520

@R-O-C-K-E-T
Copy link
Owner

Feature looks neat and I look forward to seeing what other balancers can be made with this.

From the looks of it the value of item['colour'] should be derivable from the network, since if the belt is pointing outside the grid (e.g. grid.get_tile_instance_offset(x, y, *tile.output_direction.vec, EdgeMode.NO_WRAP) is None) then it must be the network output colour and vice versa for belts pointing into the grid (grid.get_tile_instance_offset(x, y, *tile.input_direction.reverse.vec, EdgeMode.NO_WRAP) is None).

I believe that a better way of allowing inputs/outputs to be anywhere instead of in lines would be to add a variant of setup_balancer_ends that only applies a cardinality constraint on the number of inputs/outputs and doesn't prescribe where those belts are. Then if the user wants some specific input/output locations then they can add as many or as few as they want through --partial.

An outline of the steps to implement this: For each tile on the perimeter of the grid create two literals is_input and is_output. is_input should imply that the tile is a belt pointing into the grid and is coloured the network input colour. is_output should imply that the tile is a belt pointing out of the grid and is coloured the network output colour. Both being false should imply that the tile is empty. In addition to these per tile clauses, up you'll need to add a cardinality constraint across all of the distinct is_input literals so that the total true count is equal to the number of network inputs (grid.clauses += library_equals(is_inputs, input_count, grid.pool) and also do the same for the is_output literals with the number of network outputs.

--partial could be extended to support forcing particular tiles to be empty (the same as tile["force_empty"]). In addition it may still be useful to add colour support to --partial. Improvements to --partial are great, since they benefit all tools that support --partial. Though if the previous suggestion was implemented. Then if all inputs/outputs were provided by the user, all other perimeter tiles would be forced empty anyway.

The way I recommend extending --partial to support forcing empty is by adding a new tile type (something like FillerTile) that would represent a tile that has been specifically marked empty. Then in blueprint.py update import_blueprint to interpret some factorio entity (perhaps wooden chest?) as that FillerTile. This would allow specifying tiles as required empty without having to manually edit any JSON.

@ignaloidas
Copy link
Contributor Author

Hmm, doing it that way does have some pretty nice benefits, but I'm still not entirely sure on how the whole grid construction works (to get to this point I've mostly cobbled together what was already there), so I'd need to learn a bit more about that. I'll try to do that (not editing the jsons by hand would be pretty nice) but that's gonna take a bit.

@ignaloidas
Copy link
Contributor Author

Alright, I updated it mostly in the way you proposed. Seems to work pretty nicely, for example here's a 4x5 balancer meant to split off a single lane off a bus, I only forced the top row to be empty and bus inputs and outputs, the split-off location chosen by SAT.

4x5_splitoff.mp4

@R-O-C-K-E-T
Copy link
Owner

LGTM, if you can get it passing lint then I'll yeet it in.

It looks really good, thanks for fixing up some issues that have been annoyed me as well.

Also adds a FillerTile (read as wooden chest) to force certain tiles
empty and a couple extra little fixes I added while using this tool.
@ignaloidas
Copy link
Contributor Author

Gah, thought I've ran lint, it appears not recently enough. Fixed it, should be good now.

@R-O-C-K-E-T R-O-C-K-E-T merged commit a3318bc into R-O-C-K-E-T:main Sep 11, 2023
3 checks passed
@ignaloidas ignaloidas deleted the custom_ends branch September 11, 2023 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants