Addon mods - KerbalColonies/KerbalColoniesCore GitHub Wiki

This section is about creating plugin for custom facility types.

Baseclass

All facilities need to be derived from the KCFacilityBase class, if your new facility type can hold kerbals then it must be derived from the KCKerbalFacilityBase class.

Registering

In order to be usable all facility types need to be registered at the KCFacilityTypeRegistry (via RegisterType) and if it can be built with a facility config it additionally needs to be registered via RegisterFacilityInfo. You might use the default KCFacilityInfoClass or create a custom one for additional requirements in the config files. The registration needs to happen at the main menu during the MonoBehaviour Awake phase.

You can also remove types (e.g. if you want to replace the crewquarters with another one that has support for a lifesupport mod) but then you must make sure that the removed type is not used, otherwise there might be exceptions.

Loading and Saving

Constructors

All facility types need two constructors:

  1. A constructor with a colonyclass, a facilityinfo and a bool enabled. This one is used to create new facilities.
  2. A constructor with a colonyclass, a facilityinfo and a confignode. This one is used to restore existing facilities, the saved data is stored in the confignode.

getConfigNode

Used to save existing facilities to be loaded again the next time, you need to use the confignode provided by the KCFacilityBase, e.g.

public override ConfigNode getConfigNode()
{
    ConfigNode node = base.getConfigNode();
    node.AddNode(createKerbalNode());
    return node;
}

If you have any questions feel free to ask on the ksp forum thread, this is only a very short overview with the most important things.