Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Space Engineers New! Modding Guide: New Features Nov 2017

Discussion in 'Modding' started by rexxar, Nov 17, 2017.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. rexxar Senior Engineer

    Messages:
    1,530
    Hello modders! Here is a guide to the new features introduced in Major 185! Please see this thread for the full details of everything in the ModAPI update: https://forum.keenswh.com/threads/modapi-and-pb-api-changes-nov-2017.7398158/

    Grid Groups:
    I'm very excited about this feature. Mods now have access to the grid group system. This an interesting feature of our engine which tracks grids that are connected in some way. There are four connection types currently supported:
    • Mechanical - Connections by rotor, piston, suspension.
    • Logical - Terminal connections. i.e. rotors, pistons, wheels. Includes Mechanical connections.
    • Physical - Connections which lock physics. i.e. connectors. Includes Logical and Mechanical connections.
    • NoContactDamage - Connections which lock physics, but do not connect terminals. Landing gear only.
    This system is represented in the IMyGridGroups interface, located at MyAPIGateway.GridGroups:
    Code:
    public interface IMyGridGroups
    {
      /// <summary>
      /// Returns all grids connected to the given grid by the specified link type.
      /// </summary>
      List<IMyCubeGrid> GetGroup(IMyCubeGrid node, GridLinkTypeEnum type);
    
      /// <summary>
      /// Checks if two grids are connected by the given link type.
      /// </summary>
      bool HasConnection(IMyCubeGrid grid1, IMyCubeGrid grid2, GridLinkTypeEnum type);
    }
    
    
    Oxygen Provider:
    Mods can now create arbitrary pressurized volumes! This is the same system that planets use to provide oxygen, but it can do much more than just spheres. It's unlike other features of our API, you're required to implement an interface and add the object to the system. The good thing is this gives you a lot of freedom to how your pressurized volume works. Here's an example that creates a sphere where all the air is near the edge, maybe suitable for a Dyson sphere:
    Code:
    public class DysonAtmosphere : IMyOxygenProvider
    {
      private BoundingSphereD _sphere;
    
      public DysonAtmosphere(Vector3D center, double radius)
      {
        _sphere = new BoundingSphereD(center, radius);
      }
    
      public float GetOxygenForPosition(Vector3D worldPoint)
      {
        var d = Vector3D.DistanceSquared(worldPoint, _sphere.Center);
        var r2 = _sphere.Radius * _sphere.Radius;
    
        if (d > r2)
           return 0f;
    
        return (float)(d / r2);
      }
    
      public bool IsPositionInRange(Vector3D worldPoint)
      {
        return _sphere.Contains(worldPoint) == ContainmentType.Contains;
      }
    }
    
    To register your provider, you simply call
    Code:
    MyAPIGateway.Session.OxygenProviderSystem.AddOxygenGenerator(new CubePressure(box));
    This example is pretty simplistic, but hopefully you see that since you implement all the logic yourself, you could have any kind of volume, like maybe a band of breathable air high up in a planet's atmosphere, with unbreathable air further down.

    Note that the valid return values for GetOxygenForPosition is 0 to 1, where 0 is no pressure, and 1 is fully pressurized. You can return negative values, to cancel out atmosphere provided by other planets or mods.

    Game Version
    At MyAPIGateway.Session.Version, you'll find a System.Version object which represents the current game version. Version is represented as Major.Minor.Build.

    There are also now conditional compilation symbols defined for game version!
    Code:
    #if VERSION_185
    //this code will compile on versions 1.185.xxx
    #if BUILD_9
    //this code will compile on version 1.185.9
    #endif
    #endif
    
    This is useful if you want to make your mod backward compatible with older game versions.

    That's all for now, I'll be back Soon™ with more modding improvements and goodies!
     
    • Like Like x 3
Thread Status:
This last post in this thread was made more than 31 days old.