Space Engineers

Space Engineers

Asteroid Filter API
Echthros  [developer] 11 Apr, 2024 @ 9:20pm
Asteroid Filter Mod API
Setup Steps:
1. Copy AsteroidFilterApiClient.cs file to your code project.
2. Instantiate the AsteroidFilterApi class in the main MySessionComponentBase and store it in a property. (i.e. public AsteroidFilterApi AsteroidFilterApi = new AsteroidFilterApi();)
3. Add the AsteroidFilterApi.Load() call to the LoadData() method and the AsteroidFilterApi.Unload() call to the UnloadData() override methods in the main MySessionComponentBase.
4. Use the API methods as you please.

Methods:
bool? SetAsteroidFilter(string name, int priority, Func<IMyVoxelBase, bool> isZoneActive, Func<IMyVoxelBase, bool> isSpawnValid)
Adds a new asteroid spawn filter rule.
  • name: Filter name must be unique. Defining the same filter name again will override the parameters of the one with the same name.
  • priority: Determines the order that the filter rules are executed. Higher value rules are processed first. Rules with the same priority do not have guaranteed order.
  • isZoneActive: Function reference which takes the asteroid being spawned as input and returns a value indicating if the rule will be used. If the return is true, then the "isSpawnValid()" method will be checked and the result will determine if the asteroid spawns. If the return is false, then it will move to checking the next-lowest priority rule. If all rules fail to apply, then the asteroid will spawn by default.
  • isSpawnValid: Function reference which takes the asteroid being spawned as input and returns a value indicating if the asteroid should spawn.

Pointers:
Generally, you will want to limit your "isZoneActive()" so that it only returns true when you want the rule to apply, so this is where you will generally put your more complex checks (i.e. checking grids speeds, proximity to planets, etc.). The "isSpawnValid()" function should usually only have "return true;" or "return false;" as a body depending on whether the rule is additive or subtractive.

Remember that higher priority rules take precedence, so if you set a rule to have very high priority and set "isZoneActive()" to always return true, then no other rule will ever be considered.

Also, the "isZoneActive()" will be run for every rule (until one of them returns true) every single time the server attempts to spawn any asteroid, so try to keep them as efficient as possible for performance reasons (cache everything if you can!).
Last edited by Echthros; 11 Apr, 2024 @ 9:34pm