SGM Library for Stellaris


SGM Library for Stellaris

Overview
This is not a mod, but a resource for modders. Its purpose is to centralize scripts that are used by multiple addons.

Features
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).

List of Functions
The naming scheme is more or less SGM___

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_planet_get_sp_level (sp=spaceport)
SGM_planet_num_sp_modules
SGM_planet_num_sp_slots_free
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.

Using SGM Library In Your Own Mods
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.

Automatic Code Generation
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.

Return Value Concept
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_”
Disclaimer
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.

Credits:
Soulbinder
1 Star2 Stars3 Stars4 Stars5 Stars


What is Stellaris mods?

A mod (short for "modification") is an alteration where someone, usually a player, changes some aspect (e.g. the way it looks or behaves) of a video game. Mods may range from small changes and simple tweaks to completely new games made within a video game. Games running on a personal computer are often designed with change in mind, allowing modern PC games to be modified by gamers without much difficulty. Don't wait and try Stellaris mods right now.




You may also like...

Leave a Reply

Your email address will not be published.