Stack Combinator

by modo_lv

An arithmetic combinator that performs stack size multiplication/division/rounding on item signals. Features signal inversion and output display, compatible with Picker Dollies and Nullius.

Content
2 months ago
1.1
14.8K
Circuit network
Owner:
modo_lv
Source:
https://github.com/modo-lv/factorio-m...
Homepage:
N/A
License:
CreativeCommonds BY-NC 4.0
Created:
3 years ago
Latest Version:
1.6.1 (2 months ago)
Factorio version:
1.1
Downloaded by:
14.8K users

Stack Combinator

A mod for Factorio that adds a new type of circuit network combinator to research and craft: a stack combinator. This combinator modifies each item signal it receives according to that item's stack size and selected operation. For example, if the stack size for Coal is 50, and you send a Coal signal with value 2 and * (multiplication) selected, a stack combinator will output Coal×100 signal.

Features

  • Item signal stacking. Each item signal sent to the stack combinator input is output with its amount modified according to that item's stack size, depending on the selected operation:
    • Multiplication.
    • Division with result rounding up (away from zero) or down (towards zero).
    • Rounding to full stack: up (away from zero), down (towards zero) or both (whichever is closer).
  • Signal inversion. Each combinator can also be configured to invert input signals (green, red or both), which treats positive input signal amounts as negative and vice-versa.
  • Signal merge precedence: You can choose per combinator whether to merge input signals (before applying stack calculations), or apply stacking to each wire separately (so that only the resulting output signals are merged).
  • Wagon stack mode: Each combinator can be toggled to use train wagon capacity instead of stack size, allowing for more convenient train station signal management in mods with multiple wagon tiers and/or stops of different sizes.
  • Input and output signal display. Opening the stack combinator shows all input and output signals, even if the combinator's output isn't connected to anything. The display includes "raw" input and output signals — what stack combinator is receiving and sending (displayed in silver), and additional "network" output signals — what the final signals are on the output wire, taking into account any other signal sources connected to those wires.
  • Non-item signals: Fluid and virtual signals do not have stacks, so they are passed through as-is. This can be configured in map settings to apply inversion (if any) instead, or to drop non-item signals completely.

Compatibility & balancing

  • Works with blueprints.
  • Shouldn't break anything. Stack combinator is based on the arithmetic and constant combinators, and does not involve any other entities or game objects.
  • Other mods:
  • Research costs are calculated dynamically based on circuit network technology costs, so it should fit in naturally with balance changes introduced by other mods.
  • Crafting costs are an arithmetic combinator and a repair pack (copper cable in Nullius).

Limitations & performance

  • Due to the way game works, the maximum amount of output signals is initially limited to 40 — twice the capacity of a vanilla constant combinator, meaning one StaCo can process signals from two full constant combinators. You can increase the limit in startup settings, but it may affect performance, depending on how many StaCos you have.
    • If a static combinator receives more signals than it can output, it won't output anything and raise an alert (so you can see on the map which combinator is having the problem and where).
  • Unfortunately due to how Factorio is built, the only way to achieve this functionality is to manually modify circuit signals in a mod script, which can impact game performance. There are two map settings to let you mitigate this, at the cost of update speeds:

  • Update delay determines how frequently updates happen. The game runs 60 ticks per second, and you can use this setting to slow down stack combinator updates so that they don't happen on every tick, but, say, every 6 (10 times per second; this is the default value).

  • Update limit controls how many stack combinators are processed in each update.

As an example, with the default values of 6 (delay) and 100 (limit), 1000 combinators would be updated over the course of 1 second: first 100 of the combinators would get updated, then nothing for 0.1 seconds, then the next 100 and so on. As a vague benchmark, with an Intel i5-8400 CPU, on a completely empty map with nothing but a thousand stack combinators on it, processing each update takes about half of a millisecond.

Discussion & bug reports

Acknowledgements

  • This is my first serious mod (Declutter was a trivial couple of lines), and the mod that helped me figure out most of what I needed to get started was Filter Combinator by gcascaes.
  • Big thanks to Picker Dollies for making it not only possible, but trivially easy to add support for it in other mods.
  • Thanks to therax for the idea on how to semi-automatically restore the combinator's internal circuit wiring if it gets removed.
  • I also had a look at:

Screenshots