Beginner issue: Can't get surgery to appear

Started by Boartato, July 19, 2018, 03:13:24 PM

Previous topic - Next topic

Boartato

I've googled, checked threads on this forum, and looked at other mods. I have no idea what I'm doing wrong, but this practice surgery of installing a "pog leg" doesn't appear. I've tried renaming my definitions, I've tried having it install different body parts, I've tried including base definitions in the file. I tried copying all the code from the Core defs and changed names to try and get a duplicate surgery.

Absolutely nothing works, even though Rimworld only claims that my version is a mismatch when loading.

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

  <RecipeDef Abstract="True" Name="Boart_SurgeryFlesh">
    <effectWorking>Surgery</effectWorking>
    <soundWorking>Recipe_Surgery</soundWorking>
    <workSpeedStat>MedicalOperationSpeed</workSpeedStat>
    <workSkill>Medicine</workSkill>
    <workSkillLearnFactor>16</workSkillLearnFactor>
  </RecipeDef>

<RecipeDef ParentName="SurgeryFlesh">
<defName>Boart_InstallPogLeg</defName>
<label>install pog leg</label>
<description>Install a pog leg.</description>
<workerClass>Recipe_InstallArtificialPart</workerClass>
<jobString>Installing pog leg.</jobString>
<workAmount>1300</workAmount>
<surgerySuccessChanceFactor>1.30</surgerySuccessChanceFactor>
<skillRequirements>
<Medicine>3</Medicine>
</skillRequirements>
<ingredients>
<li>
<filter>
          <categories>
<li>Medicine</li>
</categories>
</filter>
<count>1</count>
</li>
<li>
<filter>
<thingDefs>
<li>WoodLog</li>
</thingDefs>
</filter>
<count>1</count>
</li>
</ingredients>
<fixedIngredientFilter>
      <categories>
        <li>Medicine</li>
      </categories>
      <thingDefs>
<li>WoodLog</li>
</thingDefs>
</fixedIngredientFilter>
<appliedOnFixedBodyParts>
<li>Leg</li>
</appliedOnFixedBodyParts>
<addsHediff>Boart_SimpleProstheticLeg</addsHediff>
</RecipeDef>

</Defs>


<?xml version="1.0" encoding="utf-8" ?>
<Defs>
  <!-- Added body parts -->

  <HediffDef Name="Boart_AddedBodyPartBase" Abstract="True">
    <hediffClass>Hediff_AddedPart</hediffClass>
    <defaultLabelColor>(0.5, 0.5, 0.9)</defaultLabelColor>
    <isBad>false</isBad>
  </HediffDef>

  <HediffDef ParentName="Boart_AddedBodyPartBase">
    <defName>Boart_SimpleProstheticLeg</defName>
    <label>Boart's prosthetic leg</label>
    <labelNoun>a prosthetic leg</labelNoun>
    <spawnThingOnRemoved>SimpleProstheticLeg</spawnThingOnRemoved>
    <addedPartProps>
      <solid>true</solid>
      <partEfficiency>0.85</partEfficiency>
    </addedPartProps>
  </HediffDef>

 
</Defs>

There are many mods like it, but this mod is mine.

Mehni

Quote from: Boartato on July 19, 2018, 03:13:24 PM
I've tried including base definitions in the file.

Don't you dare release it with that intact. That'll cause a slew of issues. Here's why.

As for your issue, you're missing the part that adds the surgery to the pawn. recipes tag in Races_Humanlike.xml, or wherever you need it. Target it with xpath.

Boartato

#2
Thanks for the tip, really worked on streamlining my code to get the desperate junk I threw in from various sources cleared out. Now having an xpatch issue.

Rimworld>Mods>BoartatoBionics is my root folder, with Defs and Patches inside it. I know I'm having a syntax issue, but without any knowledge of what should work I can't figure it out from the generic "patch failed" error message. I've tried several different pathing options, like including root folders/classes but none of them seem to be the magic combination. Xpatch code is inside Surgery_Inserter.xml and the surgery is inside Recipes_Boart_Surgeries.xml

Surgery_Inserter.xml Code
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationAdd">
<xpath>*/Races_Humanlike[defName = "Human"]/recipes</xpath>
<value>
<li>Boart_InstallPogLeg</li>
</value>
</Operation>
</Patch>


Recipes_Boart_Surgeries.xml code
<?xml version="1.0" encoding="utf-8" ?>
<Defs>

<RecipeDef ParentName="SurgeryFlesh">
<defName>Boart_InstallPogLeg</defName>
<label>install pog leg</label>
<description>Install a pog leg.</description>
<workerClass>Recipe_InstallArtificialBodyPart</workerClass>
<jobString>Installing pog leg.</jobString>
<workAmount>1300</workAmount>
<surgerySuccessChanceFactor>1.30</surgerySuccessChanceFactor>
<skillRequirements>
<Medicine>3</Medicine>
</skillRequirements>
<ingredients>
<li>
<filter>
          <categories>
<li>Medicine</li>
</categories>
</filter>
<count>1</count>
</li>
<li>
<filter>
<thingDefs>
<li>WoodLog</li>
</thingDefs>
</filter>
<count>1</count>
</li>
</ingredients>
<fixedIngredientFilter>
<categories>
<li>Medicine</li>
</categories>
<thingDefs>
<li>WoodLog</li>
</thingDefs>
</fixedIngredientFilter>
<appliedOnFixedBodyParts>
<li>Leg</li>
</appliedOnFixedBodyParts>
<addsHediff>SimpleProstheticLeg</addsHediff>
</RecipeDef>

</Defs>
There are many mods like it, but this mod is mine.

Mehni

Quote from: Boartato on July 19, 2018, 07:38:51 PM
Thanks for the tip, really worked on streamlining my code to get the desperate junk I threw in from various sources cleared out. Now having an xpatch issue.

Rimworld>Mods>BoartatoBionics is my root folder, with Defs and Patches inside it. I know I'm having a syntax issue, but without any knowledge of what should work I can't figure it out from the generic "patch failed" error message. I've tried several different pathing options, like including root folders/classes but none of them seem to be the magic combination. Xpatch code is inside Surgery_Inserter.xml and the surgery is inside Recipes_Boart_Surgeries.xml

Surgery_Inserter.xml Code
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationAdd">
<xpath>*/Races_Humanlike[defName = "Human"]/recipes</xpath>
<value>
<li>Boart_InstallPogLeg</li>
</value>
</Operation>
</Patch>


XML parsers aren't interested in the file name or location, they look at the <tags>. Each tag that gets opened is a childnode. To travel down a childnode with xpath, you use /. Example here, and on basically any other mod that adds surgery. I think the rimworld wiki on writing a patch is decent, and the guides over on w3schools helped me out too. I'll also refer you to this post, and suggest you check out the other resources on these forums.

Boartato

#4
With all due respect, I have been looking at every resource I can find. I know this is a basic question, I understand the concept of nodes and child nodes in Xpath. I've read all the rimworld specific Xpath tutorials I can find. If Xpath doesn't give a hoot about folder paths, and it considers XML files to be nodes (which all the tutorials seem to treat them as) I see no reason why this code shouldn't work:

<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationAdd">
<xpath>*/Races_Humanlike[defName="Human"]/recipes</xpath>
<value>
<li>*/Recipes_Boart_Surgeries[defName="Boart_InstallPogLeg"]</li>
</value>
</Operation>
</Patch>


It doesn't. I'm telling Xpath to search for a node called "Races_Humanlike", and to add something to the node recipes within the child node Human. I'm telling it to add the def "Boart_InstallPogLeg" from the node Recipes_Boart_Surgeries.

This and several other versions I've tried to make seem to follow all the rules tutorials suggest. But it continues to fail patching.

I'm not asking for more tutorials, I'm asking what I'm doing wrong :/

Edit2: Trying to go even more basic, I can't even replace a description of a revolver... The error message suggests that I'm actually getting the pathing right though.

<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationReplace">
<xpath>*/RangedIndustrial[defName="Gun_Revolver"]/description</xpath>
<value>
<description>Why doesn't anything work?</description>
</value>
</Operation>
</Patch>
There are many mods like it, but this mod is mine.

Mehni

With all due respect, it doesn't seem like you do understand the concept. I know it's frustrating, but I referred you to those tutorials because it looks like you haven't mastered the concept. XML and xpath is a standard that applies to more than just RimWorld. I've found the more generic tutorials to be helpful too.

QuoteI'm not asking for more tutorials, I'm asking what I'm doing wrong :/

It's hard to tell you exactly what you're doing wrong without tutorialising, and the beauty of forums is that they act as a stored reference for the future. I've explained the same thing in the two posts I linked, but sure, I'll spell it out for you as well. The xml structure for the recipelist for humans is below, where each tag that gets opened is a childnode. To travel down a childnode, you use /

<Defs>
  <ThingDef ParentName="BasePawn">
    <defName>Human</defName>
    <recipes>

The xpath for that would be /Defs/ThingDef[defName="Human"]/recipes, and if you add a value to that xpath you're good.

If that doesn't work for you, there's a generic "help with xpath" thread where you can ask others for help too.

Boartato

Thanks for all your help. I'll try posting that thread (have definitely tried what you typed out), it hadn't been posted in for a while so I figured a new topic made more sense than a necro.
There are many mods like it, but this mod is mine.