-
Notifications
You must be signed in to change notification settings - Fork 13
Formulas
Formulas are used in modding FrEee to perform calculations and create multiple data file records out of one, easing the tedium of modding items that have many levels and allowing for the creation of "tech grids" using only one record.
Formulas are actually short Python scripts, so any functions you can call in a script, you can also call in a formula. The only limitation is that you can only perform operations that can be done in one line of Python code.
There are two types of formulas: static and dynamic. Static formulas are evaluated once when the game is loaded (though this really should be when a new game is started), and then the value is cached, while dynamic formulas are evaluated as needed, and are not cached.
To create a static formula, simply prefix it in the data files with a single equals sign:
#!python
Cost Minerals := =1000 + 500 * level
To create a dynamic formula, simply prefix it in the data files with a double equals sign:
#!python
Unlock Requirement := ==empire.ResearchedTechnologies['Lasers'] >= 5 or empire.ResearchedTechnologies['Particle Physics'] >= 5
Note that dynamic formulas can slow down the game due to the cost of passing game state over to Python repeatedly, so use them sparingly. Eventually we will introduce caching of formulas for a single turn (perhaps more), which should mitigate this problem.
You can now also embed formulas in your data fields using string interpolation syntax:
Name := Mineral Miner Facility {level.ToRomanNumeral()}
If you want to embed a dynamic formula, use {{double curly braces}}. If a field has both static and dynamic embedded formulas, they will all be treated as dynamic.