SGM Library
This is not a mod, but a resource for modders. Its purpose is to centralize scripts that are used by multiple addons.
Most of the library functions allow you to determine (or estimate) the numerical value of an ingame property (which is not possible via normal scripting). The other "innovation" is that it shows a way to apply dynamic modifiers (by implementing a range of static modifiers and using binary search to determine which one is actually applied).
The naming scheme is more or less SGM_<scope>_<action>_<property>
- SGM_country_add_energy/food/influence/minerals/unity
- SGM_country_sub_energy/food/influence/minerals/unity
- SGM_country_get_energy_balance
- SGM_country_get_max_naval_capacity
- SGM_country_get_mineral_balance
- SGM_fleet_acc_fleet_size
- SGM_fleet_get_fleet_power
- SGM_fleet_get_fleet_size
- SGM_planet_get_planet_size
- SGM_ship_modifier_upkeep_add
- SGM_ship_modifier_weapon_damage_add
Some of these scripts consist of several thousands lines of code. When Stellaris is launched the code is interpreted, which causes the loading time to increase. Most mods use exclusively their own scripts, but I found that several of the SGM mods need the same functionality and thus I created this library to avoid loading the same script multiple times.
Modders are welcome to take a peak and copy as they like. Please leave a comment or thumbs up if you find something useful. You can also use the provided functions in your own mods by including this library as a "Required Item". If you do so, please make sure that you read and understand the disclaimer at the very end.
Some of the provided scripts are created "automatically" using a simple code creator written in Matlab. The source of the coder is included in the upload as well. You might find it useful for creating static, loop unrolled binary searches to determine the exact numerical value of Stellaris ingame variables, using only the minimally required number of "if" statements.
To specify the scope for the return value of a function use
- "save_event_target_as=SGM_result_scope" in your desired result scope
- the script will make the return value available in the marked scope using "event_target:SGM_result_scope"
- the result variable is named "SGM_<name_of_ingame_property>"
At last a fair word of warning: Stellaris scripting is primitive. There is no abstraction, there are no interfaces. You are directly depending on the implementation itself. If you use this library, every change that I make will directly affect your mod. I’ll try to keep the library stable and up-to-date, but understand that I am doing this in my free time, as a hobby. In no way am I to be held responsible for any inconvenience or error that results from using this library.
Revisions:
Old revisions of this mod are available below. Click the link to download.