Ludeon Forums

RimWorld => Mods => Help => Topic started by: Spacebeans on August 07, 2016, 10:39:45 AM

Title: Need help with a trait that checks for race.
Post by: Spacebeans on August 07, 2016, 10:39:45 AM
Hello everyone,

I'm an incredibly green modder trying to make a small mod that adds a generic alien race, and with it two mutually exclusive traits: xenophile and xenophobe.

My goal is to have xenophiles receive a mood buff if there's someone in the colony that has a different race than the xenophile, and have xenophobes get a mood debuff if not everyone has the same race. This is meant as a two-way system, so colonists with the "alien" race and the "xenophobe" trait will also get pissed if there's even a single "human" in the colony.

I managed to add the traits by basing the XML file on the Prosthophile/phobe trait. I also wanted to base the "race check" on the dislikes men/women trait, but digging through the decompiled files it looks like there's no easy way to copy that for race, unless I try to code in C#, which seems a tad overwhelming.

Is there an easy way through XML manipulation that I'm missing, or a different mod that has written a dll for a "race check"? Or do I have to learn C#?

These are the traits:

<?xml version="1.0" encoding="utf-8"?>

<TraitDefs>
<TraitDef>
<defName>Xenophile</defName>
<commonality>0.2</commonality>
<degreeDatas>
<li>
<label>xenophile</label>
<description>NAME has a fascination with alien races.</description>
</li>
</degreeDatas>
<conflictingTraits>
<li>Xenophobe</li>
</conflictingTraits>
</TraitDef>

<TraitDef>
<defName>Xenophobe</defName>
<commonality>0.2</commonality>
<degreeDatas>
<li>
<label>xenophobe</label>
<description>NAME has an irrational fear of alien races.</description>
</li>
</degreeDatas>
<conflictingTraits>
<li>Xenophile</li>
</conflictingTraits>
</TraitDef>
</TraitDefs>


This is the Thoughts_Situation_Traits.xml, which is theoretical atm:

<?xml version="1.0" encoding="utf-8" ?>

<Defs>
<ThoughtDef>
    <defName>XenophileNoXenos</defName>
    <workerClass>ThoughtWorker_ColonyHasNoAlien</workerClass>
    <invert>true</invert>
    <requiredTraits>
      <li>Xenophile</li>
    </requiredTraits>
    <stages>
      <li>
        <label>there are no aliens present</label>
        <description>I wish I could interact with other sentient species from our galaxy</description>
        <baseMoodEffect>-2</baseMoodEffect>
      </li>
    </stages>
  </ThoughtDef>

  <ThoughtDef>
    <defName>XenophileHappy</defName>
    <workerClass>ThoughtWorker_ColonyHasAlien</workerClass>
    <requiredTraits>
      <li>Xenophile</li>
    </requiredTraits>
    <stages>
      <li>
        <label>there are aliens present</label>
        <description>I still can't believe I spoke to an alien! My wildest dreams came true!</description>
        <baseMoodEffect>15</baseMoodEffect>
      </li>
    </stages>
  </ThoughtDef>

  <ThoughtDef>
<defName>XenophobeHappy</defName>
<workerClass>ThoughtWorker_ColonyHasNoAlien</workerClass>
    <requiredTraits>
      <li>Xenophobe</li>
    </requiredTraits>
    <stages>
      <li>
        <label>there are no aliens present</label>
        <description>A strong colony thrives on racial purity! </description>
        <baseMoodEffect>5</baseMoodEffect>
      </li>
    </stages>
  </ThoughtDef>
  <ThoughtDef>
    <defName>XenophobeUnhappy</defName>
    <workerClass>ThoughtWorker_ColonyHasAlien</workerClass>
    <requiredTraits>
      <li>Xenophobe</li>
    </requiredTraits>
    <stages>
      <li>
        <label>there are aliens present</label>
        <description>I can't believe we let these alien scum join us! No one will threaten the purity of our race! </description>
        <baseMoodEffect>-15</baseMoodEffect>
      </li>
    </stages>
  </ThoughtDef>
</Defs>


Let me know if there's any other info you need me to deliver.
Title: Re: Need help with a trait that checks for race.
Post by: 1000101 on August 07, 2016, 02:27:39 PM
We'd need to see the code for your thought worker to help you with detecting the presence/absence of a particular pawn class (thingDef).
Title: Re: Need help with a trait that checks for race.
Post by: Spacebeans on August 08, 2016, 04:30:09 AM
Quote from: 1000101 on August 07, 2016, 02:27:39 PM
We'd need to see the code for your thought worker to help you with detecting the presence/absence of a particular pawn class (thingDef).

"Thoughtworker_ColonyHasNoAlien" isn't referring to anything at the moment, I just use it as a placeholder for when I find an actual line of code to refer to.

Did you need this?

<?xml version="1.0" encoding="utf-8" ?>
<ThingDefs>



  <!-- ============================ Alien ========================== -->

  <ThingDef ParentName="BasePawn">
    <defName>Alien</defName>
    <label>alien</label>
    <description>A new sentient lifeform that has unceremoniously made contact with humans across the galaxy. Very little is known about their physiology.</description>
    <uiIconPath>Things/Pawn/Humanlike/UI/IconHuman</uiIconPath>
    <statBases>
      <MarketValue>4750</MarketValue>
      <MoveSpeed>4.61</MoveSpeed>
      <Flammability>1.0</Flammability>
      <ComfyTemperatureMin>8</ComfyTemperatureMin>
      <ComfyTemperatureMax>28</ComfyTemperatureMax>
      <LeatherAmount>20</LeatherAmount>
    </statBases>
    <verbs>
      <li>
        <verbClass>Verb_MeleeAttack</verbClass>
        <defaultCooldownTicks>100</defaultCooldownTicks>
        <meleeDamageBaseAmount>7</meleeDamageBaseAmount>
        <meleeDamageDef>Blunt</meleeDamageDef>
        <linkedBodyPartsGroup>LeftHand</linkedBodyPartsGroup>
      </li>
      <li>
        <verbClass>Verb_MeleeAttack</verbClass>
        <defaultCooldownTicks>100</defaultCooldownTicks>
        <meleeDamageBaseAmount>7</meleeDamageBaseAmount>
        <meleeDamageDef>Blunt</meleeDamageDef>
        <linkedBodyPartsGroup>RightHand</linkedBodyPartsGroup>
      </li>
    </verbs>
    <race>
      <thinkTreeMain>Humanlike</thinkTreeMain>
      <thinkTreeConstant>HumanlikeConstant</thinkTreeConstant>
      <intelligence>Humanlike</intelligence>
      <makesFootprints>true</makesFootprints>
      <lifeExpectancy>80</lifeExpectancy>
      <leatherColor>(180,230,190)</leatherColor>
      <leatherCommonalityFactor>0.01</leatherCommonalityFactor>
      <leatherInsulation>0.70</leatherInsulation>
      <leatherMarketValue>30</leatherMarketValue>
      <nameCategory>HumanStandard</nameCategory>
      <body>Human</body>
      <baseBodySize>1</baseBodySize>
      <baseHealthScale>1</baseHealthScale>
      <foodType>OmnivoreHuman</foodType>
      <gestationPeriodDays>45</gestationPeriodDays>
      <litterSizeCurve>
        <points>
          <li>(0.5, 0)</li>
          <li>(1, 1)</li>
          <li>(1.01, 0.02)</li>
          <li>(3.5, 0)</li>
        </points>
      </litterSizeCurve>
      <lifeStageAges>
        <li>
          <def>HumanlikeBaby</def>
          <minAge>0</minAge>
        </li>
        <li>
          <def>HumanlikeToddler</def>
          <minAge>1.2</minAge>
        </li>
        <li>
          <def>HumanlikeChild</def>
          <minAge>4</minAge>
        </li>
        <li>
          <def>HumanlikeTeenager</def>
          <minAge>13</minAge>
        </li>
        <li>
          <def>HumanlikeAdult</def>
          <minAge>18</minAge>
        </li>
      </lifeStageAges>
      <soundMeleeHitPawn>Pawn_Melee_Punch_HitPawn</soundMeleeHitPawn>
      <soundMeleeHitBuilding>Pawn_Melee_Punch_HitBuilding</soundMeleeHitBuilding>
      <soundMeleeMiss>Pawn_Melee_Punch_Miss</soundMeleeMiss>
      <specialshadowData>
        <volume>(0.3, 0.8, 0.4)</volume>
        <offset>(0,0,-0.3)</offset>
      </specialshadowData>
      <ageGenerationCurve>
        <points>
          <li>(14,0)</li>
          <li>(16,100)</li>
          <li>(50,100)</li>
          <li>(60,30)</li>
          <li>(70,18)</li>
          <li>(80,10)</li>
          <li>(90,3)</li>
          <li>(100,0)</li>
        </points>
      </ageGenerationCurve>
      <hediffGiverSets>
        <li>OrganicStandard</li>
      </hediffGiverSets>
    </race>
    <recipes>
      <li>InstallPowerClaw</li>
      <li>InstallScytherBlade</li>
      <li>InstallBionicEye</li>
      <li>InstallBionicArm</li>
      <li>InstallBionicLeg</li>
      <li>InstallSimpleProstheticArm</li>
      <li>InstallSimpleProstheticLeg</li>
      <li>InstallPegLeg</li>
      <li>InstallDenture</li>
      <li>InstallJoywire</li>
      <li>InstallPainstopper</li>
      <li>InstallNaturalHeart</li>
      <li>InstallNaturalLung</li>
      <li>InstallNaturalKidney</li>
      <li>InstallNaturalLiver</li>
      <li>ExciseCarcinoma</li>
      <li>RemoveBodyPart</li>
      <li>Euthanize</li>
    </recipes>
  </ThingDef>



</ThingDefs>