Natural Bodyparts with added CompRottable not spoil

Started by Old Harry MTX, October 29, 2020, 04:33:38 AM

Previous topic - Next topic

Old Harry MTX

Hi all!
I'm trying to make a simple mod to add the mechanics of food spoiling to harvested organs. I know that there are already mods that do this, but I'm trying to do it also and above all as an exercise to learn.
I have prepared the folders of the mod following various tutorials and I created this .xml under the Patches folder:

<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationConditional">
<xpath>/Defs/ThingDef[@Name="BodyPartNaturalBase"]/comps</xpath>
<nomatch Class="PatchOperationAdd">
<xpath>/Defs/ThingDef[@Name="BodyPartNaturalBase"]</xpath>
<value>
<comps>
<li Class="CompProperties_Rottable">
<daysToRotStart>1</daysToRotStart>
<rotDestroys>true</rotDestroys>
</li>
</comps>
</value>
</nomatch>
<match Class="PatchOperationAdd">
<xpath>/Defs/ThingDef[@Name="BodyPartNaturalBase"]/comps</xpath>
<value>
<li Class="CompProperties_Rottable">
<daysToRotStart>1</daysToRotStart>
<rotDestroys>true</rotDestroys>
</li>
</value>
</match>
</Operation>
</Patch>


That actually adds this to the organs:



The problem is that the organs actually not spoils, and the counter remain always the same, as if the class controlling this effect (That i suppose to be CompRottable) were not active.

I thought that the problem could depend on the fact that BodyPartNaturalBase was not a ThingWithComps, but going to check the Defs from which it inherits (BodyPartBase), we see that it is.

Reading the code, I couldn't find how to initialize this process (I believe the problem is related to ThingComp.Initialize and ThingWithComps.InitializeComps), assuming I'm guessing okay and really the problem isn't somewhere else.

Can you help me?

Thanks in advance!

Old Harry MTX

Ok, maybe i have found a solution here:

https://ludeon.com/forums/index.php?topic=26575.0

I will test it soon as possible and report here.

Canute

I am not a modder so i can't give you an answer.
But you allready mention other mods with that feature. Maybe you should look at them how they solved it.

Old Harry MTX

Quote from: Canute on October 29, 2020, 09:19:53 AM
I am not a modder so i can't give you an answer.
But you allready mention other mods with that feature. Maybe you should look at them how they solved it.

The only mod I found is this one: https://steamcommunity.com/sharedfiles/filedetails/?id=2164584341

But, unlike other mods, I was unable to extract the code to be able to consult it.  :-\


Old Harry MTX

Quote from: Canute on October 29, 2020, 11:05:16 AM
RBSE got it too
- Organs need refrigeration to avoid rot and decay.
https://steamcommunity.com/sharedfiles/filedetails/?id=850429707

Thanks! It seems a nice mod to play also! If the solution in this topic (https://steamcommunity.com/sharedfiles/filedetails/?id=2164584341) will not work i will surely search a way in this code.

Old Harry MTX

Done! As reported in that topic, the problem was that the normal "BodyPartBase" have a <tickerType> set to Never, and so are never updated during runtime. Using PatchOperationReplace i replaced it to Rare, like a normal food, and it started to works perfectly.

Here the final code:

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

<Patch>
<Operation Class="PatchOperationSequence">
<operations>
<li Class="PatchOperationConditional">
<xpath>/Defs/ThingDef[@Name="BodyPartNaturalBase"]/tickerType</xpath>
<nomatch Class="PatchOperationAdd">
<xpath>/Defs/ThingDef[@Name="BodyPartNaturalBase"]</xpath>
<value>
<tickerType>Rare</tickerType>
</value>
</nomatch>
<match Class="PatchOperationReplace">
<xpath>/Defs/ThingDef[@Name="BodyPartNaturalBase"]/tickerType</xpath>
<value>
<tickerType>Rare</tickerType>
</value>
</match>
</li>
<li Class="PatchOperationConditional">
<xpath>/Defs/ThingDef[@Name="BodyPartNaturalBase"]/comps</xpath>
<nomatch Class="PatchOperationAdd">
<xpath>/Defs/ThingDef[@Name="BodyPartNaturalBase"]</xpath>
<value>
<comps>
<li Class="CompProperties_Rottable">
<daysToRotStart>1</daysToRotStart>
<rotDestroys>true</rotDestroys>
</li>
</comps>
</value>
</nomatch>
<match Class="PatchOperationAdd">
<xpath>/Defs/ThingDef[@Name="BodyPartNaturalBase"]/comps</xpath>
<value>
<li Class="CompProperties_Rottable">
<daysToRotStart>1</daysToRotStart>
<rotDestroys>true</rotDestroys>
</li>
</value>
</match>
</li>
</operations>
</Operation>
</Patch>