Space Engineers

Space Engineers

Resource Exchanger 2
 This topic has been pinned, so it's probably important
Sinus32  [developer] 1 Nov, 2015 @ 10:47am
Balancing algorithm's details
Here are details of how the balancing algorithm works.

- Resource Exchanger processes each group of blocks of one kind independently
- Currently following kinds of blocks are supported: Reactors, Refineries, Oxygen generators, Drills, Turrets
1. For each group of blocks of one kind the script does:
1.1. Divide blocks of one kind into "conveyor networks"
1.2. For each conveyor network the script does:
1.2.1. Divide blocks in conveyor network into "groups that can share items"
1.2.2. For each group the script does:
1.2.2.1. For each block in the group calculate a percentage value of how much space is used
1.2.2.2. Sort blocks in the group according to the percentage value
1.2.2.3. For each pair of blocks: first and last, second and second last, and so on do:
1.2.2.3.1. Calculate how much/many items have to be moved to balance block's inventories
1.2.2.3.1. Move calculated amount of items from one inventory to second one

- It is assumed that two blocks are in the same "conveyor network" if the first block's inventory is connected to second block's inventory and second block's inventory is connected to the first block's inventory. This means if two block are connected only by one conveyor sorter they are in two separated networks, but if that blocks are connected by two conveyor sorters, one in each direction, the blocks will be in the same conveyor network.
Attention! The script cannot read filters applied on conveyor sorters, so if any conveyor sorters with filters applied exist in connection between blocks the script may try to move resources in a way they cannot be moved. The script will fail then.

- If refineries and arc furnaces exist in the same conveyor network they will not exchange ore because they creates two separated groups "that can share items". This division is hard-coded in the script and prevents exchanging items between blocks that cannot or should not exchange items. Currently defined "groups that can share items" are:
a. Small/Large reactors on small/large ships/stations
b. Arc reactors (any size)
c. Drills (any kinds)
d. Refineries
e. Arc furnaces
f. Gatling Turret and Gatling Gun
g. Missile Turret and Rocket Launcher
All blocks of types which this script doesn't know, can exchange items only with blocks of the same type.

- For calculating how much volume takes some amount of anything the script needs a few hard-coded values.
Because of this currently the script can move only all items from vanilla Space Engineers, and items from mods which are explicitly supported.
If you need support for any mod, please make a request in discussion Modded blocks compatibility requests