Technology Tree: logical OR operator

by Pithlit

Provides logical OR operation in the technology tree for other mods. An OR-node automatically unlocks as soon as one of the predecessor technologies is researched. An OR-node can be used as prerequisite for other technologies, so they become available for research, as soon as one of the prerequisite technologies is researched.

Internal
25 days ago
2.0
94
Owner:
Pithlit
Source:
N/A
Homepage:
N/A
License:
MIT
Created:
26 days ago
Latest Version:
1.1.0 (25 days ago)
Factorio version:
2.0
Downloaded by:
94 users

This mod provides a function for other mods to add logical OR-nodes to the technology tree.
Stand-alone this mod does nothing.

Example:

How to use from your mod:

local technology_or = require("__technology_or__.technology_or")
local tech = technology_or.OR({"automation", "logistics"})
data.raw.technology["automobilism"].prerequisites = {tech.name}

This block of code adds an OR-node in the technology tree. As soon as automation or logistics is researched, the OR-node is also automatically unlocked. After that, automobilism can be researched.

Documentation:

To access the functions, provided by this mod, require the lib file and store it in a local variable:

local technology_or = require("__technology_or__.technology_or")

Now you can call the two functions, that are provided by this mod:

  • technology_or.OR(technologies, dont_extend)
  • technology_or.DEPEND_ON(technology_name, prerequisite_name, dont_modify_prerequisites, dont_extend)

The function technology_or.OR*takes two arguments:

  • technologies: array[TechnologyID]
  • dont_extend: optional - bool, defaults to false

It will return a TechnologyPrototype, that automatically unlocks when any of the technologies in the technologies argument is researched.
If dont_extend is true, data:extend has not yet been called with the new prototype. You may further modify the returned prototype and call data:extend by yourself.

The function technology_or.DEPEND_ON takes four arguments:
* technology_name: TechnologyID
* prerequisite_name: TechnologyID
* dont_modify_prerequisites: optional - bool, defaults to false
* dont_extend: optional - bool, defaults to false

It will return a TechnologyPrototype, that automatically unlocks when the technology prerequisite_name is researched.
Additionally the returned prototype will be added to the prerequisites of the technology given by technology_name, if dont_modify_prerequisites is false.
If dont_extend is true, data:extend has not yet been called with the new prototype. You may further modify the returned prototype and call data:extend by yourself.

Known issues:

  • In cases, where the names of the predecessor technologies end with a number, the localisation might fail. Any hint how to prevent this is welcome.
  • The localisation of OR-nodes that depend on other OR-nodes or technologies with a localised_name might fail.
  • You can not alter the name of a prototype after it is added to the game with data:extend. If you need to modify it, call the functions with dont_extend
  • The game cleans up the technology tree after the data stage, so that common dependencies of technologies and ther predecessors olny apply to the predecessor, and no longer to the dependent technology. This can cause issues with OR-nodes. If you need to set up an explicit dependency between two technologies, use the DEPEND_ON function.