Ingestible Dependency Genes - KonradHeinser/EBSGFramework GitHub Wiki

If you've tried using the vanilla dependency code, you know it's very rigid. It only accepts drugs, only ever uses the chemical dependency hediff, and doesn't work very well if you're not using the template. My solution for this was to create a system that accepts any list of things and/or categories, and let you decide what hediff you attach to the gene. Let's start with the easy part, the hediff itself.


The Hediff

To make a dependency hediff, you only need one thing, two if you want to use the automatic description generator.

The class:

        <hediffClass>EBSGFramework.Hediff_Dependency</hediffClass>

You need a positive severity per day for the automatic description to generate times:

        <comps>
<!--This is equivalent to the normal dependency genes. 
The thresholds are 5, 30, and 60 days with the normal severities-->

            <li Class="HediffCompProperties_SeverityPerDay">
                <severityPerDay>0.2</severityPerDay> 
                <minAge>13</minAge>
            </li>
        </comps>

And that's all you really need to make a dependency hediff. The framework does have some defaults/templates you can use if you so desire. These can be found in DependencyHediffs.xml. In the gene, you can reference one of the defNames if you just want to use the hediff directly, or create your own using the base as a parent if you want the same stages.

It's important to note that the label of the hediff won't matter in this case as the hediff will overwrite whatever it has with the gene's label. Also, in the event that you do not use one of the defaults, you'll need to make your own to create a mood debuff curve for when a pawn goes too long without ingesting the stuff.


The Gene

Regardless of whether you're making a chemical or a unique ingestible dependency, you're going to be assigning the same class to it, and using the same extension to specify the hediff to be applied:

        <geneClass>EBSGFramework.Gene_Dependency</geneClass>
        <modExtensions>
            <li Class="EBSGFramework.IDGExtension">
                <dependencyHediff>InsertHediffDefNameHere</dependencyHediff>
            </li>
	</modExtensions>

From here there's going to be a bit of a difference between chemical and ingestible genes. Chemical genes only have one more step, and that's adding the chemical directly into the GeneDef like so:

    <GeneDef>
        <defName>InsertDefNameHere</defName>
        <geneClass>EBSGFramework.Gene_Dependency</geneClass>
        <chemical>InsertChemicalDefDefNameHere</chemical>
        <modExtensions>
            <li Class="EBSGFramework.IDGExtension">
                <dependencyHediff>InsertHediffDefNameHere</dependencyHediff>
            </li>
	</modExtensions>
    </GeneDef>

While you will still need to add all the normal gene stuff to that def, the code behind doesn't need any other input to handle the dependency. For other dependencies, you need to add more tags to the extension to allow it to know what to call the dependency and what to consume.

The label is required if you don't have a chemical because there's no reliable way to figure out what to call the dependency otherwise:

        <modExtensions>
            <li Class="EBSGFramework.IDGExtension">
                <dependencyLabel>insert label here</dependencyLabel>
            </li>
	</modExtensions>

To specify what to consume, you get two lists, validThings and validCategories. You also have a checkIngredients (default False) tag that will have the code check the ingredients of an item to satisfy the need:

<!--checkIngredients will increase performance usage with more map items, especially with categories-->
        <modExtensions>
            <li Class="EBSGFramework.IDGExtension">
                <validThings>
                    <li>InsertDefNameHere</li>
                </validThings>
                <validCategories>
                    <li>InsertDefNameHere</li>
                </validCategories>
                <checkIngredients>True</checkIngredients> 
            </li>
	</modExtensions>

In some cases, your hediff may not follow the format the code expects. If your hediff doesn't start causing negative effects until after the second stage or you only want the later ones to be viewed as notable, adding minSatisfySeverity will make it so the hediff only looks at stages with a minSeverity greater than that for generating descriptions and for when the job giver send the pawn off to find an ingestible:

                <minSatisfySeverity>0.9</minSatisfySeverity>

The final thing of note is the descriptionOverride, which overrides the hediff's automatic description addon. You should only use this if you really don't like the hediff description generated, or are using a severity comp other than HediffCompProperties_SeverityPerDay. Your override won't be able to access pawn names or pronouns, and will not be able to have colored text automatically, so this is only recommended if you are really sure you want to override the description:

        <modExtensions>
            <li Class="EBSGFramework.IDGExtension">
                <descriptionOverride>Insert description here</descriptionOverride>
            </li>
	</modExtensions>

Complete Examples

Examples from Expanded Dependency Genes. The first adds a reliance on the wake-up chemical, and the second creates a dependency on chocolate

    <GeneDef>
        <defName>EBSG_WakeUpReliance</defName>
        <label>wake-up reliance</label>
        <description>There was a description here.</description> 
        <geneClass>EBSGFramework.Gene_Dependency</geneClass>
        <displayCategory>EBSG_Dependency</displayCategory>
        <minAgeActive>13</minAgeActive>
        <addictionChanceFactor>0</addictionChanceFactor>
        <biostatCpx>2</biostatCpx>
        <biostatMet>8</biostatMet>
        <labelShortAdj>wake-up-reliant</labelShortAdj>
        <displayOrderInCategory>6</displayOrderInCategory>
        <chemical>WakeUp</chemical>
        <iconPath>UI/Icons/Genes/Chemicals/WakeUp/ChemicalDependency</iconPath>
        <exclusionTags>
            <li>Addiction_WakeUp</li>
        </exclusionTags>
        <modExtensions>
            <li Class="EBSGFramework.IDGExtension">
                <dependencyHediff>EBSG_GeneticDrugReliance</dependencyHediff>
            </li>
        </modExtensions>
    </GeneDef>

    <GeneDef>
        <defName>EBSG_ChocolateDependency</defName>
        <label>chocolate dependency</label>
        <description>There was a description here.</description> 
        <geneClass>EBSGFramework.Gene_Dependency</geneClass>
        <displayCategory>EBSG_Dependency</displayCategory>
        <minAgeActive>13</minAgeActive>
        <labelShortAdj>chocolate-dependent</labelShortAdj>
        <displayOrderInCategory>101</displayOrderInCategory>
        <iconPath>EBSG/Gene_ChocolateDependency</iconPath>
        <biostatMet>3</biostatMet>
        <exclusionTags>
            <li>EBSG_ChocolateDependency</li>
        </exclusionTags>
        <modExtensions>
            <li Class="EBSGFramework.IDGExtension">
                <dependencyHediff>EBSG_GeneticFoodDependency</dependencyHediff>
                <dependencyLabel>chocolate</dependencyLabel>
                <validThings>
                    <li>Chocolate</li>
                </validThings>
                <checkIngredients>True</checkIngredients>
            </li>
	</modExtensions>
    </GeneDef>
⚠️ **GitHub.com Fallback** ⚠️