Just as planned, work on the material tree editor continued this week.

Before implementing the most important part of the tool - validating that the tree is valid - I first had to implement a basic save-and-load function so I wouldn’t have to rebuild my test data from scratch every time I changed something. This will also be extremely important later on when we have to work with (the single) existing data files used by the production game world and we have to add new materials and dependencies without changing any of the existing values.

Once I had this working, I went on to implement the first and most important part of the tree validation code. What I mean by this is the following: The material tree is essentially made up of production chains. Resources are extracted, these are than used in some production facility to produce intermediate products and those in turn might be used to manufacture more complex products. The production processes are the nodes of the tree and the dependencies on input materials form the edges.

We now have to make sure that the tree follows a basic set of rules. For example, there must not be cyclic dependencies. If a production process depends on an input material that is only available much further down in the tree, this material has to be provided by NPCs to avoid a chicken-and-egg situation. The editor will figure this out and tell us which materials and/or reactors (that’s what we call production facility types internally) must be NPC-provided.

There are of course more rules beyond this: Certain reactors require higher population levels to operate. These population levels in turn require more advanced supplies to be available, so the editor once again ensures that those supplies can either be manufactured on lower population levels or - in case of the lowest level - be purchased from NPCs.

Next up on the to-do list for the material editor are even more constraints (dependencies on certain planet types, for example), the computation of material complexities as foundation for basic NPC behavior like pricing and the integration with the game itself so we can import the material tree and all the data that comes with it into the game without everything blowing up.