The Genes - KonradHeinser/EBSGFramework GitHub Wiki

Main Resource Gene

The most important portion of the DRG system is the Resource Gene itself. This is the gene referenced by all other parts of the system, and handles the bars, the hediffs, and even the primary resource packs pawns look for. A lot of this system is handled by the normal GeneDef stuff, meaning all main DRGs should have this stuff within the GeneDef itself:

        <geneClass>EBSGFramework.ResourceGene</geneClass>
        <resourceLossPerDay>1</resourceLossPerDay> <!--Negative means regeneration. A -1 would mean regenerating 100 per day-->
        <resourceGizmoThresholds>
            <li>0.25</li>
            <li>0.5</li>
            <li>0.75</li>
        </resourceGizmoThresholds>
        <resourceGizmoType>EBSGFramework.GeneGizmo_ResourceGene</resourceGizmoType> <!--If you have a GeneGizmo_Resource error, it's because you forgot this-->
        <showGizmoOnWorldView>false</showGizmoOnWorldView>
        <showGizmoWhenDrafted>true</showGizmoWhenDrafted>
        <resourceDescription>Insert resource description here.</resourceDescription>
        <resourceLabel>insert resource label here</resourceLabel>
	<modExtensions>
            <li Class="EBSGFramework.DRGExtension">
            </li>
	</modExtensions>

Bar customizing

All of that stuff will tell the game that the resource gene is, well a resource. All of the options from here on belong in the extension as they will specify the information specifically handled by the DRG system instead of just vanilla accessible stuff.

These options handle the resource information:

  • isMainGene : Default (False) : This is what tells the code if this is the gene handling all the resource storage. If the hemogenic genes were made with this system, Hemogenic would have this set to True while HemogenDrain would leave it as false
  • maximum : Default (1) : The maximum amount of the resource that can be stored at any given time. Just like Hemogen, this is coded to display at 100 times the value in-game
  • maxStat : A StatDef that overrides the maximum completely
  • maxFactorStat : A StatDef that multiplies the maximum. This can work with both maximum and maxStat
  • cravingHediff : Optional HediffDef to apply if the resource reaches 0
  • overchargeHediff : Optional HediffDef to apply if the resource reaches the maximum
  • passiveFactorStat : Optional StatDef that multiplies the effects of resource genes and resource drain genes
  • resourcePacks : A list of ThingDefs that the code should check for when trying to refill the resource
  • gainStat : Optional StatDef that multiplies any resource gains from non-gene, non-ability sources, like resourcePacks

These options tweak the gizmo's display:

  • barColor : Default ( (138, 3, 3) ) : The color to make the resource bar when the player isn't hovering over it
  • barHighlightColor : Default ( (145, 42, 42) ) : The color to make the resource bar when the player is hovering over it
  • iconPath : A texture path to use to find an icon in the upper right corner. If this and iconThing are left blank and the gene doesn't have any resourcePacks, then the area will be left blank
  • iconThing : A ThingDef to use for the icon in the upper right corner. If this and iconPath are left blank and the gene doesn't have any resourcePacks, then the area will be left blank
  • addTargetBar : Default (False) : When resourcePacks is left empty, the target levels bar is removed normally. This can be used to override that. If you are using Need Chargers or EBSGFramework.ThinkNode_ConditionalHighResourceLevels this may be of use to you
    • If you are using a need charger and don't set this to True, pawns will generally just use the building by themselves when the resource level drops below 50%
    • The think node will not be relevant for your case if you are using minLevel instead of useTargetValue

These alter what ingesting certain raw foods may do to resource levels. These effects scale with the total nutrition consumed:

  • eggIngestionEffect : Default (0) : Amount to offset the resource by when a raw egg is consumed
  • humanlikeCorpseIngestionEffect : Default (0) : Amount to offset the resource by when a humanlike corpse is consumed
  • corpseIngestionEffect : Default (0) : Amount to offset the resource by when a non-humanlike corpse is consumed
  • humanlikeIngestionEffect : Default (0) : Amount to offset the resource by when meat from a humanlike corpse is consumed
  • genericMeatIngestionEffect : Default (0) : Amount to offset the resource by when meat from a non-humanlike corpse is consumed

Draining genes

The final thing to cover is drain/regen genes, similar to HemogenDrain. These require almost nothing. Slap this code into a GeneDef, and you have yourself a draining gene. Make the loss negative, and you have a regeneration gene:

        <resourceLabel>insert resource label here</resourceLabel>
        <geneClass>EBSGFramework.ResourceDrainGene</geneClass>
        <prerequisite>InsertMainGeneDefNameHere</prerequisite> <!--All that really matters is that the main resource gene is always there-->
        <resourceLossPerDay>0.1</resourceLossPerDay> <!--Losing 10 per day-->
        <modExtensions>
	    <li Class="EBSGFramework.DRGExtension">
                <mainResourceGene>InsertMainGeneDefNameHere</mainResourceGene> <!--This must be whatever the main resource gene is-->
	    </li>
	</modExtensions>

Conditional Draining / Regeneration

Up until this point, all of the drain and regen genes we've been making are constantly active, but what if we only want them to be active in certain situations, like when in light/darkness, or only when the pawn has certain hediffs active? The DRG extension has some nodes that allow you to only take effect when specific conditions are met:

  • requiredHediffs : List of hediffs that the pawn needs to have all of to make the gene offset the resource

  • requireOneOfHediffs : List of hediffs that the pawn needs to have any one of to make the gene offset the resource

  • forbiddenHediffs : List of hediffs that the pawn needs to have none of to make the gene offset the resource

  • lightLevel : Default (0~1) : The light level of the area the pawn is standing must be in this range

  • invertLight : Default (False) : Makes it so lightLevel looks to make sure the value is outside the range instead of inside

    • For example, if you set the light level to 0.3~0.7, then invert it, instead of looking for light levels between 30% and 70%, it looks for light levels below 30% or above 70%
  • progressThroughDay : Default (0~1) : % of progress through the day when this will be active. For example, if this is set to be 0~0.5, then the drain/regen is usable from midnight until noon, 0.5~1 would be noon until midnight, and 0.25~0.75 6:00 to 18:00

    • If you aren't sure what to put for the percentage, take the hour you want it to start/end at, and divide it by 24. For example, if you want the available times to be 5:00-15:00 (5-3 for those who stick to 12 hour clocks), you would do 5/24 and 15/24 to get 0.208~0.625
  • invertTime : Default (False) : Makes it so progressThroughDay looks to make sure the value is outside the range instead of inside. This can be used to set up times that pass through midnight as it will result in you specifying the range of times when the drain/regen does not work

    • For example, the 0.208~0.625 in the example (5:00-15:00, morning to afternoon) would instead check for 15:00-5:00 (afternoon to morning) to make the drain/regen active
  • daysOfYear : Default (0~60) : Range of dates in the year where this is active

  • invertDOY : Default (False) : Makes it so daysOfYear looks to make sure the value is outside the range instead of inside. This can be used to set up times that pass through one year to the next as it will result in you specifying the range of times that do not work (i.e. 16~45 normally only allows for Jugust through Septober, but with invert active it instead only allows for Decembary through Aprimay)

  • daysOfQuadrum : Default (0~15) : Range of dates in the quadrum where this is active

  • invertDOQ : Default (False) : Makes it so daysOfQuadrum looks to make sure the value is outside the range instead of inside. This can be used to set up times in the middle of the quadrum that become invalid (i.e. using 5~10 will instead check to make sure it is before day 5 or after day 10 in the quadrum)

  • seasons : A list of valid seasons for this to be active. The options are Spring, Summer, Fall, Winter, PermanentSummer, and PermanentWinter. Summer includes both normal Summer and PermanentSummer, and Winter checks for both Winter and PermanentWinter. However, PermanentSummer and PermanentWinter do not check for their temporary variants

  • needLevels : Special list of items that cause the resource to only be offset if all needs are in their specified ranges (min 0 to max 1)

		<needLevels>
		    <li>
		        <need>InsertNeedDefNameHere</need>
		        <minNeedLevel>0</minNeedLevel>
		        <maxNeedLevel>1</maxNeedLevel>
		    </li>
		</needLevels>

Hediff Adder

If you want to have the initial or drain genes apply a specific hediff when added similar to what Hediff Adder does, you can do that by adding the same extension as what Hediff Adder uses. You do not need a special gene class to do this as the functionality is built directly into the DRG Gene classes.


Known Bugs

  • If a drain gene is added at a different time from when the main gene is added, the gizmo does not report it on the list. After some experimentation, this appears to be a solely visual caused by limitations in when the drain gene list is made, which can only occur on add or post-reload. The drain/regen itself should still apply without issue though.

Adapted Superhero Genes resource for Radiomancers, a type of superhero that uses a specialized form of radiation.

    <GeneDef>
        <defName>SHG_Archetypes_Radiomancer</defName>
        <label>radiomancer</label>
        <description>There was a lengthy description here, but I killed it for this example.</description>
        <displayCategory>Miscellaneous</displayCategory>
        <iconPath>Archetypes/Gene_Radiomancer</iconPath>
        <geneClass>EBSGFramework.ResourceGene</geneClass>
        <resourceGizmoThresholds>
            <li>0.25</li>
            <li>0.5</li>
            <li>0.75</li>
        </resourceGizmoThresholds>
        <resourceGizmoType>EBSGFramework.GeneGizmo_ResourceGene</resourceGizmoType>
        <showGizmoOnWorldView>false</showGizmoOnWorldView>
        <showGizmoWhenDrafted>true</showGizmoWhenDrafted>
        <resourceDescription>I have murdered another description!</resourceDescription>
        <resourceLabel>radiation</resourceLabel>
        <biostatArc>1</biostatArc>
        <resourceLossPerDay>-0.1</resourceLossPerDay>
        <displayOrderInCategory>-0.8</displayOrderInCategory>
	<modExtensions>
            <li Class="EBSGFramework.DRGExtension">
		<isMainGene>True</isMainGene>
                <maximum>1</maximum> <!--Not really needed since this is the default-->
                <barColor>(255, 255, 0)</barColor>
                <barHighlightColor>(205, 205, 50)</barHighlightColor>
                <iconThing>Uranium</iconThing>
                <cravingHediff>SHG_RadiomancerDrained</cravingHediff>
                <overchargeHediff>SHG_RadiomancerOvercharge</overchargeHediff>
                <resourcePacks>
                    <li>SHG_RadiationPack</li>
                </resourcePacks>
            </li>
	</modExtensions>
    </GeneDef>

    <GeneDef>
        <defName>SHG_RadiomancerDrain</defName>
        <label>radiomancer drain</label>
        <labelShortAdj>draining</labelShortAdj>
        <description>Carriers lose 10 radiation per day from entropy.</description>
        <resourceLabel>radiation</resourceLabel>
        <geneClass>EBSGFramework.ResourceDrainGene</geneClass>
        <iconPath>UI/Icons/Genes/Gene_HemogenDrain</iconPath>
        <prerequisite>SHG_Archetypes_Radiomancer</prerequisite>
        <resourceLossPerDay>0.1</resourceLossPerDay>
        <displayCategory>SHG_Radiomancer_Entropy</displayCategory>
        <displayOrderInCategory>1</displayOrderInCategory>
        <minAgeActive>3</minAgeActive>
        <biostatCpx>1</biostatCpx>
        <biostatMet>6</biostatMet>
        <modExtensions>
	    <li Class="EBSGFramework.DRGExtension">
                <mainResourceGene>SHG_Archetypes_Radiomancer</mainResourceGene>
	    </li>
	</modExtensions>
    </GeneDef>


Other Pages

⚠️ **GitHub.com Fallback** ⚠️