[Mod 1.1] FactorioChem Proof-of-Concept

Topics and discussion about specific mods
Post Reply
Neutrality
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Jan 31, 2020 5:10 am
Contact:

[Mod 1.1] FactorioChem Proof-of-Concept

Post by Neutrality »

FactorioChem
Mod link: https://mods.factorio.com/mod/FactorioChem
Demo video: https://www.youtube.com/watch?v=N_FWJbBB50g

FactorioChem Proof-of-Concept puzzle mod - SpaceChem in Factorio. SpaceChem by Zachtronics Industries.

Design and shape molecules in 2D space within the confines of a single item slot.
Description
What if Factorio items had physical shape and occupied physical space?

This mod explores the idea of manipulating molecules like SpaceChem by Zachtronics Industries. In this mod, you'll rotate, bond, fission, and splice molecules and more to obtain the right ingredients to produce science.

Image

The thing is, there are a lot of possible molecules. Molecules have shape, and depending on how you configure your assembly buildings to position them, the resulting reactions will cause totally different results. Solve open-ended puzzles around manufacturing molecules to obtain the progressively more complicated sets of molecules you need for science.

Aside from space science, science recipes exclusively require molecule ingredients, and only require molecule reaction buildings and previous science packs as technology prerequisites.

Please note: this mod generates over 59,000 different items - it takes a long time to load

There are too many possible molecule conversions to make a recipe for each one, so instead, most buildings added by this mod use a pseudo-assembling-machine system that dynamically converts molecules based on presets that you specify in each machine. Settings are copy-pastable and blueprintable. (Undo/redo also works but only with robots; hand-mined buildings will lose their settings)
How do the machines work?
Molecule reaction buildings look something like this:

Image

To handle the dynamic nature of transforming molecules, molecule reaction buildings use a separate set of inventories to hold each part of its reaction. Every building consumes up to 3 inputs and produces up to 3 outputs. Each input and output has its own inventory in a specific position per building, and is moved into or out of the building via loaders (technically you can also use inserters).

Every molecule reaction building contains a GUI that looks similar to this:

Image

Inputs on the left, outputs on the right, and up to 3 settings in the middle.

When a building is idle, it continually checks its inputs and settings to see if they produce a valid reaction. If so, the inputs are consumed and the assembly building begins a "craft" of its fixed recipe; once the recipe is complete, the building places the results in the output inventories. Should a building be mined in the middle of a reaction, the ingredients of the unfinished reaction are returned to the miner just like regular assembling machines.

The lower half of each building's GUI is a demo area where you can test out reactions with different settings. Some example reactions are provided for each building type.

For convenience you can refer to the periodic table accessible through a bottom bar shortcut or in the GUI.
How do molecules work?
Every molecule is a grid of atoms, up to 3x3. This is the largest that either dimension can be - neither dimension can be 4 or greater.

Each atom gets its own item, as well as many of the possible molecules (see the next section for further explanation).

Within each molecule, all atoms are connected to each other through vertically or horizontally adjacent bonds. Any two atoms can be connected by up to 3 bonds, and any single atom can be connected by bonds up to its bond count (but not more). Bond count per atom is indicated by its color and provided in its description.

Atoms and molecules all have a stack limit of 1 and cannot be handcrafted. Molecule items are hidden and there are no recipes to convert one molecule into another.

There are four basic interactions involved in modifying molecules, split into two categories:
  • Fusion/Fission: combines two atoms into one or splits one atom into two (but no nuclear explosions, sorry). Fusion and fission perform simple additions and subtractions on the atomic numbers of the atoms used, so the total proton count never changes. Depending on the building, fission and fusion either apply to lone atoms or to atoms within molecules.
  • Bonding/Debonding: add or remove a bond between two atoms. This can be used to join two molecules or split one molecule into two, or to add or remove a bond between existing atoms within a molecule. The atoms themselves do not change (unless specified due to settings).
Additionally, Splicing joins two molecules into one by overlapping them and performing fusion on the overlapping atoms, and Severing splits one molecule into two by performing fission on one atom. Bonds are moved between the resulting molecules but are not added or removed otherwise.
How many molecules are there?
To work around item limitations, molecules are divided into two categories: simple molecules and complex molecules.

Simple molecules are the single- and multi-atom molecules that fit all of these properties:
  • Aside from single atoms, all atoms in all simple molecules have bonds exactly equal to their bond count. Multi-atom radical molecules are never simple molecules.
  • Molecules consisting of only H, C, N, and O can contain up to 8 atoms
  • Molecules with 4 atoms can contain elements up to Ne
  • Molecules with 3 atoms can contain elements up to Ar
  • Molecules with 2 atoms can contain any elements
  • Molecules with 5-8 atoms can contain single and double bonds, but not triple bonds or higher
  • Molecules with 2-4 atoms can contain single, double, and triple bonds
There are 59,584 simple molecules and each simple molecule receives its own unique item. (Fun fact: multi-atom simple molecules always have an even sum of atomic numbers)

Complex molecules do not have the same restrictions as simple molecules, and
  • can contain up to 9 atoms,
  • can always form up to triple bonds, and
  • can be radicals.
However, they are mostly visually indistinguishable from each other. To see what's in a complex molecule, you'll have to inspect it in your inventory. There are 68,574,768,928,886,778 possible complex molecules, minus the 59,584 simple molecules. There are 150 different shapes for complex molecules, and each shape gets its own item.

Image

All sciences only use simple molecule ingredients and can be obtained without ever creating complex molecules, but you can always create complex molecules anyways and most molecules are easier to create using complex molecules as intermediates.

Bond, Debond, Splice, and Sever buildings allow optional fission or fusion on atoms within molecules - this is necessary to ensure that there is always a way to create simple molecules without ever creating complex molecules.

--------------------------------------------------------------------------------------------------------------------------------

Likely not compatible with mods that modify sciences or heavily modify the technology tree (by default; you can enable a setting to prevent changes to technologies or science recipes), but likely compatible with most other mods.

I don't currently have anything I'm planning on adding but definitely leave a suggestion if there's something you'd like to see.


Gallery
Last edited by Neutrality on Sat Nov 11, 2023 1:13 am, edited 4 times in total.

User avatar
Brathahn
Fast Inserter
Fast Inserter
Posts: 108
Joined: Sat Aug 02, 2014 1:50 pm
Contact:

Re: [Mod 1.1] FactorioChem Proof-of-Concept

Post by Brathahn »

As a former Spacechem player, i am simply amazed that you managed to recreate this concept in factorio. Just wow! Kudos to you!
Also i think this might get some attention of other mod makers, as this is the rare occurence of a really new mod concept.

i would really like to see how you managed to create the ~60k different items. i guess you created a program that wrote all the definitions and created all the icons? i would love to read a nice writeup on the Alt-F4 blog

vjbone
Fast Inserter
Fast Inserter
Posts: 143
Joined: Sun Feb 14, 2016 10:02 am
Contact:

Re: [Mod 1.1] FactorioChem Proof-of-Concept

Post by vjbone »

I like how it looks, especially assembler ui and icons (grid looks weird but clear :lol:)

Neutrality
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Jan 31, 2020 5:10 am
Contact:

Re: [Mod 1.1] FactorioChem Proof-of-Concept

Post by Neutrality »

Brathahn wrote:
Wed May 03, 2023 5:14 am
As a former Spacechem player, i am simply amazed that you managed to recreate this concept in factorio. Just wow! Kudos to you!
Also i think this might get some attention of other mod makers, as this is the rare occurence of a really new mod concept.

i would really like to see how you managed to create the ~60k different items. i guess you created a program that wrote all the definitions and created all the icons? i would love to read a nice writeup on the Alt-F4 blog
A writeup could be fun! Once I've finished assembling some footage and recovered from the development push, I'll look into it.

Regarding the two parts about items:
  • Icons: Each atom and bond(s) is rendered individually, resulting in up to 36 atom images to cover every size and position, and about 100 different bond images. Based on the size and composition of a molecule, the molecule generator adds an icon layer for each atom and bond(s), plus an extra hidden background layer with the overall shape because only the first layer receives a shadow.
  • Items: This is one of the meatier parts of the mod. After setting some parameter limits to ensure it doesn't go over the hard 65536 item limit, it:
    • Computes each shape (3x3 grid, 2^9 = 512 theoretical patterns, only 150 fully-connectable shapes), and then for each shape:
    • BFS every possible bond configuration. All molecules in the shape have to be connected in some way. Loops are allowed, but to prevent duplicates, a loop can only be formed if each atom is currently at the same BFS depth from the "first" atom in the shape. For each bond configuration:
    • Iterate all N^M possible molecules for that configuration (M = atom count in shape, N = atoms that can form the number of bonds at a given atom in the molecule) and generate an item for it. The parameters limit which N atoms can appear in a molecule based on its size and the number of bonds at a given atom, as well as how many bonds can form between two atoms.
    • Fortunately, the equipment grid of armor items allows every other possible molecule within the basic constraints

Post Reply

Return to “Mods”