Anesthetic hediff?

Started by Tutankhamun, October 22, 2021, 08:17:01 PM

Previous topic - Next topic

Tutankhamun

I'm trying to make a sort of "Induced Coma" that is just a buffed up anesthetize surgery that uses more medicine but keeps pawns down for longer. Problem is that i can't seem to find where/when the hediff is applied to the pawn. Is that in C# code?

              <HediffDef ParentName="DiseaseBase">
                    <defName>InducedComaX3</defName>
                    <label>Induced Coma (3 days)</label>
                    <description>Creates a induced coma that renders the creature unconscious for several days.</description>
                    <isBad>false</isBad>
                    <initialSeverity>1</initialSeverity>
                    <maxSeverity>1</maxSeverity>
                    <comps>
                      <li Class="HediffCompProperties_Disappears">
                        <disappearsAfterTicks>180000~181000</disappearsAfterTicks>
                      </li>
                      <li Class="HediffCompProperties_SeverityPerDay">
                        <severityPerDay>-0.33</severityPerDay>
                      </li>
                    </comps>
                    <stages>
                      <li>
                        <label>wearing off</label>
                        <painFactor>0.95</painFactor>
                        <vomitMtbDays>4</vomitMtbDays>
                        <capMods>
                          <li>
                            <capacity>Consciousness</capacity>
                            <setMax>0.9</setMax>
                          </li>
                          <li>
                            <capacity>Manipulation</capacity>
                            <offset>-0.1</offset>
                          </li>
                          <li>
                            <capacity>Moving</capacity>
                            <offset>-0.05</offset>
                          </li>
                        </capMods>
                        <mentalStateGivers>
                          <li>
                            <mentalState>WanderConfused</mentalState>
                            <mtbDays>50</mtbDays>
                          </li>
                        </mentalStateGivers>
                      </li>
                      <li>
                        <minSeverity>0.1</minSeverity>
                        <label>woozy</label>
                        <painFactor>0.8</painFactor>
                        <vomitMtbDays>0.25</vomitMtbDays>
                        <capMods>
                          <li>
                            <capacity>Consciousness</capacity>
                            <setMax>0.7</setMax>
                          </li>
                          <li>
                            <capacity>Moving</capacity>
                            <offset>-0.2</offset>
                          </li>
                          <li>
                            <capacity>Manipulation</capacity>
                            <offset>-0.2</offset>
                          </li>
                          <li>
                            <capacity>Talking</capacity>
                            <offset>-0.2</offset>
                          </li>
                          <li>
                            <capacity>Metabolism</capacity>
                            <offset>-0.2</offset>
                          </li>
                          <li>
                            <capacity>Sight</capacity>
                            <offset>-0.15</offset>
                          </li>
                        </capMods>
                        <forgetMemoryThoughtMtbDays>5</forgetMemoryThoughtMtbDays>
                        <mentalStateGivers>
                          <li>
                            <mentalState>WanderConfused</mentalState>
                            <mtbDays>5</mtbDays>
                          </li>
                        </mentalStateGivers>
                      </li>
                      <li>
                        <minSeverity>0.11</minSeverity>
                        <label>coma</label>
                        <painFactor>0</painFactor>
                        <capMods>
                          <li>
                            <capacity>Consciousness</capacity>
                            <setMax>0.01</setMax>
                          </li>
                        </capMods>
                      </li>
                    </stages>
                  </HediffDef>



                  <RecipeDef ParentName="SurgeryFlesh">
                    <defName>RecipeInducedComaX3</defName>
                    <label>Induced Coma (3 days)</label>
                    <description>Creates a induced coma that renders the creature unconscious for several days.</description>
                    <workerClass>Recipe_Surgery</workerClass>
                    <jobString>Inducing Coma.</jobString>
                    <workAmount>0</workAmount>
                    <hideBodyPartNames>true</hideBodyPartNames>
                    <targetsBodyPart>false</targetsBodyPart>
                    <surgerySuccessChanceFactor>2</surgerySuccessChanceFactor>
                    <ingredients>
                      <li>
                        <filter>
                          <categories>
                            <li>Medicine</li>
                          </categories>
                        </filter>
                        <count>2</count>
                      </li>
                    </ingredients>
                    <fixedIngredientFilter>
                      <categories>
                        <li>Medicine</li>
                      </categories>
                    </fixedIngredientFilter>
                  </RecipeDef>

JT

#1
Yep, anaesthetic is applied via code; the only XML involvement is the definition of the hediff itself, and a hard-coded "<anesthetize>true</anesthetize>" flag on any given medical bill's RecipeDef.

Fortunately, what you actually want is already possible in the game -- do a search for "Recipe_AddHediff" in the game's Data folder to find the correct recipe example (Sterilize), then follow the example: switch your workerClass to "Recipe_AddsHediff" and configure the addsHediff appropriately, and be sure to set anesthetize=false so you don't double-dip the patient with both an induced coma and anesthetic that could in all probability kill them.  (Honestly, the "volunteering" necessary to test surgical mods makes me pretty damned uncomfortable at times. ;-))

Alternatively, if you're interested in going the extra fully-metricated 1.6 kilometres to make a script mod, you'd probably just bypass the anesthetize flag entirely.  Instead you'd write a new bill; this gives you the advantage that you can avoid "double dipping" the patient if they're already anaesthetised, as that would also kill them even if the bill itself doesn't apply any.  Since I have a few surgical bill doers in my own code, here's a chopped version that took me no time at all, and should give you the base template to follow (but this is only the reel and line, not the whole fish: you'll still have to learn enough to finish it on your own =)):

public class SurgicalBill_InduceComa : Recipe_Surgery
{
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List<Thing> ingredients, Bill bill)
{
Hediff anaesthetic = pawn.health.hediffSet.hediffs.Find(diff => diff.def == HediffDefOf.Anesthetic);
if(anaesthetic != null) {
pawn.health.RemoveHediff(anaesthetic); //if already under the effects of anesthetic, remove it so we don't kill the unlucky blighter
}

//Add Hediff here... hint: AddHediff(hediffDef) is available in any pawn's Pawn_HealthTracker, and looks quite similar to the removal above
//Report violation?  Record the Tale in the colony's history?  All certainly possible...
}

public override bool IsViolationOnPawn(Pawn pawn, BodyPartRecord part, Faction billDoerFaction)
{
if(pawn.guilt.IsGuilty) return false;
if(pawn.health.InPainShock) return false;
if(pawn.health.summaryHealth.SummaryHealthPercent < 0.25) return false;
if(HealthUtility.TicksUntilDeathDueToBloodLoss(pawn) < GenDate.TicksPerHour*8) return false;
foreach(Hediff hediff in pawn.health.hediffSet.hediffs) {
if(hediff.CurStage.lifeThreatening && !hediff.FullyImmune()) return false;
}
return true;
}
}

Tutankhamun

#2
Quote from: JT on October 24, 2021, 09:09:11 AM
Yep, anaesthetic is applied via code; the only XML involvement is the definition of the hediff itself, and a hard-coded "<anesthetize>true</anesthetize>" flag on any given medical bill's RecipeDef.

Fortunately, what you actually want is already possible in the game -- do a search for "Recipe_AddHediff" in the game's Data folder to find the correct recipe example (Sterilize), then follow the example: switch your workerClass to "Recipe_AddsHediff" and configure the addsHediff appropriately, and be sure to set anesthetize=false so you don't double-dip the patient with both an induced coma and anesthetic that could in all probability kill them.  (Honestly, the "volunteering" necessary to test surgical mods makes me pretty damned uncomfortable at times. ;-))

Alternatively, if you're interested in going the extra fully-metricated 1.6 kilometres to make a script mod, you'd probably just bypass the anesthetize flag entirely.  Instead you'd write a new bill; this gives you the advantage that you can avoid "double dipping" the patient if they're already anaesthetised, as that would also kill them even if the bill itself doesn't apply any.  Since I have a few surgical bill doers in my own code, here's a chopped version that took me no time at all, and should give you the base template to follow (but this is only the reel and line, not the whole fish: you'll still have to learn enough to finish it on your own =)):

public class SurgicalBill_InduceComa : Recipe_Surgery
{
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List<Thing> ingredients, Bill bill)
{
Hediff anaesthetic = pawn.health.hediffSet.hediffs.Find(diff => diff.def == HediffDefOf.Anesthetic);
if(anaesthetic != null) {
pawn.health.RemoveHediff(anaesthetic); //if already under the effects of anesthetic, remove it so we don't kill the unlucky blighter
}

//Add Hediff here... hint: AddHediff(hediffDef) is available in any pawn's Pawn_HealthTracker, and looks quite similar to the removal above
//Report violation?  Record the Tale in the colony's history?  All certainly possible...
}

public override bool IsViolationOnPawn(Pawn pawn, BodyPartRecord part, Faction billDoerFaction)
{
if(pawn.guilt.IsGuilty) return false;
if(pawn.health.InPainShock) return false;
if(pawn.health.summaryHealth.SummaryHealthPercent < 0.25) return false;
if(HealthUtility.TicksUntilDeathDueToBloodLoss(pawn) < GenDate.TicksPerHour*8) return false;
foreach(Hediff hediff in pawn.health.hediffSet.hediffs) {
if(hediff.CurStage.lifeThreatening && !hediff.FullyImmune()) return false;
}
return true;
}
}

Thanks! I decided to go with the xml method.