Backgrounds - Histidine91/Nexerelin GitHub Wiki

Guide by Lukas04

Backgrounds are an additional option (starting in Nexerelin 0.11.1) that can be picked after the player chooses their faction. They do not appear for custom starts. A background can be made to start the player with more cargo, with a unique skill, or to remember the choice for later and have it come up in dialogs, or pretty much anything else. The player can only pick one Background. A background gets its own intel entry after game creation.

Implementing Backgrounds

To create a new background, you will have to first create a character_backgrounds.csv in your mods data/config/exerelin folder. To do this, go to the same folder location within the Nexerelin and copy its character_backgrounds.csv in to your own folder. When opening the CSV, it should look somewhat like this:

Clear out all the rows and fill them in with your own details.

id: Should be unique, recommended to use an acronym of your mods name as a prefix.
name: The title that is shown for your background.
shortDescription: The description shown right under the title, without being hovered over. Should be very short.
longDescription: Shows on hover and in the intel.
order: How the Backgrounds are ordered in the selection list, a lower number puts it higher in the list.
iconPath: The path to the icon file that is supposed to be displayed.
plugin: The classpath for the BaseCharacterBackground class that is supposed to be run, more details in the next section.

The BaseCharacterBackground Plugin.

Each background requires a plugin, this plugin can be used to modify various details of the background or to execute specific code on game start if the background was picked. For this you have to create a new java class that extends the BaseCharacterBackground class found under the exerelin.campaign.backgrounds path.

package exerelin.campaign.backgrounds;

import com.fs.starfarer.api.campaign.FactionSpecAPI;
import exerelin.utilities.NexFactionConfig;

public class ExampleCharacterBackground extends BaseCharacterBackground {

}

For this example, the path we put in the plugin column in our csv would be exerelin.campaign.backgrounds.ExampleCharacterBackground. With this you could technicly start the game and see your background appear in the selection. However the plugin can be used to give more functionality to your background. For example, you could overwrite the getTitle() method and make the name of the faction you have choosen appear in the name.

    @Override
    public String getTitle(FactionSpecAPI factionSpec, NexFactionConfig factionConfig) {
        return factionSpec.getDisplayName() + " Officer";
    }

You could make your Background only appear if the faction you have choosen are considered Pirates. Note how most methods pass both the vanilla FactionSpecAPI and the NexFactionConfig, which provides you with a lot of information about what faction has been picked.

    @Override
    public boolean shouldShowInSelection(FactionSpecAPI factionSpec, NexFactionConfig factionConfig) {
        return factionConfig.pirateFaction;
    }

You could add more information or ui elements to the selection-hover tooltip. The Heavy-Debt background as an example uses this to show the debt calculation if F1 is pressed.

    @Override
    public void addTooltipForSelection(TooltipMakerAPI tooltip, FactionSpecAPI factionSpec, NexFactionConfig factionConfig, Boolean expanded) {
        super.addTooltipForSelection(tooltip, factionSpec, factionConfig, expanded);

        int base = HeavyDebtObligation.DEBT_BASE;
        int perLevel = HeavyDebtObligation.DEBT_PER_LEVEL;
        float mult = Global.getSettings().getFloat("nex_spacerDebtMult");

        if (expanded) {
            tooltip.addSpacer(10f);
            tooltip.addPara("The formula for debt calculation is: (" + base + " + (" + perLevel + " * level)) * " + mult, 0f, Misc.getTextColor(), Misc.getHighlightColor(),
                    "" + base, "" + perLevel, "level","" + mult);
        }
    }

And to end it off, the plugin has four methods that equal that of the BaseModPlugin new game creation methods, meaning they let you execute code during specific parts of new game creation. The example below uses it to give the player the navigation skill from the start.

    @Override
    public void onNewGameAfterTimePass(FactionSpecAPI factionSpec, NexFactionConfig factionConfig) {
        Global.getSector().getPlayerPerson().getStats().setSkillLevel(Skills.NAVIGATION, 1f);
    }

Theres more methods that can be overwriten, so make sure to check the rest out to see if they may help you accomplish what you were meaning to do.

Detecting a choosen background

CharacterBackgroundUtils.isBackgroundActive("backgroundID") will return true if the specific background id equals that of the choosen background. There is also the Nex_HasBackground backgroundIDHere command for rules.csv