ShotgunNinja / Kerbalism

Hundreds of Kerbals were killed in the making of this mod.
The Unlicense
43 stars 19 forks source link

QOL modifiers can't be used in a Process #79

Closed gotmachine closed 7 years ago

gotmachine commented 7 years ago

I'm trying to achieve a custom habitat/QOL system where a breakdown only happens when the living space/confort is below a threeshold :

Rule
    {
        name = habitat
        input = QOL
        rate = 1000.0
        interval = 21600.0 // 100 QOL resource consumed per day per kerbal
        degeneration = 0.03333 // 30 days without comfort will trigger breakdown
        breakdown = true // trigger breakdown event instead of death
    }
Process
    {
        name = comfortproducer
        modifier = living_space,comfort
        output = QOL@0.04629
    }

But with this ruleset, I'm facing an issue : the planner doesn't show in the VAB/SPH and the console is spammed by those exceptions :

[EXC 19:33:22.758] NullReferenceException: Object reference not set to an instance of an object
    KERBALISM.Modifiers.evaluate (KERBALISM.environment_analyzer env, KERBALISM.vessel_analyzer va, KERBALISM.resource_simulator sim, System.Collections.Generic.List`1 modifiers)
    KERBALISM.resource_simulator.process_process (KERBALISM.Process p, KERBALISM.environment_analyzer env, KERBALISM.vessel_analyzer va)
    KERBALISM.resource_simulator.analyze (System.Collections.Generic.List`1 parts, KERBALISM.environment_analyzer env, KERBALISM.vessel_analyzer va)
    KERBALISM.Planner.update ()
    KERBALISM.Launcher.update ()
    KERBALISM.UI.update (Boolean show_window)
    KERBALISM.Kerbalism.Update ()

This seems to be linked with the fact that I'm using _modifier = livingspace,comfort in a process and not in a rule (no exception if I remove the line)

ShotgunNinja commented 7 years ago

This is fixed, it was rather intricate.

The planner resource analysis require the vessel analysis, and viceversa. This 'recursive' problem is not an issue: for the first simulation in planner, resource analysis will have empty vessel analysis. For subsequent simulation steps, it will use values from the previous step (that's acceptable).

However, if a process use the comforts modifier it will throw an exception (because it is still null). This in turn will make it so that the vessel analysis is never done. This is what I fixed.

There is then another issue: the 'stress' and 'radiation' panels in planner were designed to require a rule. They have some flexibility on the set of modifiers used in those rules, but if a rule doesn't exist containing the modifier 'living_space' or 'radiation', these panels will not be shown. This is some kind of limitation on the current way all this information in planner is organized (the panels were designed when the system was much less flexible).

So, even after this fix, in your setup you will not see the 'stress' panel. You can somehow compensate by adding a supply definition for the resource 'QOL'

Supply
{
  resource = QOL
}

This will add a resource panel to the planner, that will show you at least some info about it. Contrary to the 'special' panels, the resource ones are fully generic.

gotmachine commented 7 years ago

Thanks for the detailed explanation !

I already figured that adding a "supply" section control visibility of the resource in the panel. Indeed it would be nice to be able to select in the config file the visibility of the various "hardcoded" panels, independently of the modifiers used in the profile. Also, maybe there is a technical limitation at play but it would be nice to have the features switchs and parameters in a section of the profile file instead of in the Settings.cfg