[Mod request]Cremate a dead pawn with all of his gear.

Started by Festen, January 18, 2018, 12:02:35 AM

Previous topic - Next topic

Festen

Hello,

Could it be possible to create a mod that when you cremate a dead raider or any dead pawn, he or she goes up in flame with all his gear. I found really annoying to have to burn the apparel after that. In late game raid, your base can be spammed with death man clothes. If I wanted to save something valuable from them I would just strip them before hand.

I know there are in game solution, like a specific storage place and then using Molotov/Grenade to make everything disapear, but I would prefer the option to cremate a dead pawn with all of this clothe.

Thanks for reading.

BrokenValkyrie

If I can find the code responsible I bet I can make the mod. So far I can't find it, seems to be the most elusive code piece I've ever experienced. XML is not giving any clue, as far as I can tell it strips the corpse by magic.

Canute

I think thats a general vanilia behavior now.
Other mod's who consume corpse at any way, drop the equiped stuff too.
Like the android printer.

JustALittleCrazyTalk

Instead of changing the crematorium (since the code is hiding) could you write entirely new code and overwrite the crematorium?

BrokenValkyrie

No, the plan was not to change the crematorium but to change the behavior. As canute said the behavior is specifically tied to corpse destruction. Its not possible to write a new code for crematorium in this manner.

Unfortunately there a lot of red herring involved in this code. I tried looking at corpse.Destroy(), there no indication it strip the corpse or maybe I missed something, I did look into the inherited code. Corpse.Strip() has no indication its being used in destruction of corpses. Maybe someone with better insight into rimworld code could help.

jamaicancastle

Maybe someone with more knowledge of C# can elucidate, but here's a theory.

Corpse is a subclass of Thing. Both Corpse and Thing have .Destroy methods, which are flagged public virtual. Corpse.Destroy specifically invokes Destroy on all of the equipment and inventory items of the pawn associated with the corpse (if there is one) as part of the PostCorpseDestroy method. Obviously Thing.Destroy doesn't do this.

The cremate recipe doesn't have it own code worker, it just uses the default behavior of all recipes with ingredients, which is to destroy those ingredients when it's done. This is handled by RecipeWorker.ConsumeIngredient, which calls Thing.Destroy. I'm pretty sure that means it won't call Corpse.Destroy even if the object is a corpse.

If it doesn't, the fix would seem to be a Harmony patch that would modify RecipeWorker.ConsumeIngredient such that, if the consumed ingredient was a corpse, it should invoke PostCorpseDestroy to clean up the leftovers.

Jaxxa

I will probably have a look into this and making a mod for it over the weekend but I haven't tried it in game yet.

But from a quick look at the code my guess would be Verse.AI.Toils_Recipe.CalculateIngredients that contains the code:


list.Add(thing);
IStrippable strippable = thing as IStrippable;
if (strippable != null)
{
strippable.Strip();
}


It looks like anything that implements, IStrippable, which Corpse does will be stripped by any Recipe Toil, which cremating is.
So I will try a Harmony Patch and see what that gets me, although to start with that would stop stripping from every recipe, and I don't know what else could be using that.

BrokenValkyrie

#7
Here it is, it works on butchering as well. Making it discriminate on job would be a lot of effort.
https://www.dropbox.com/s/c6p88mdfxwi4o0n/NoStripIngredient.zip?dl=0

I made the first line noOp and removed the second line. There still an operation that tries to cast thing as strippable but I'm not that confident of scrubbing it without messing up the execution flow.

IL_0194: ldloc.s 6
IL_0196: callvirt instance void Verse.IStrippable::Strip()


Thanks Jaxxa, your guess was spot on.

Festen

Quote from: BrokenValkyrie on January 19, 2018, 01:16:36 AM
Here it is, it works on butchering as well. Making it discriminate on job would be a lot of effort.
https://www.dropbox.com/s/c6p88mdfxwi4o0n/NoStripIngredient.zip?dl=0

I made the first line noOp and removed the second line. There still an operation that tries to cast thing as strippable but I'm not that confident of scrubbing it without messing up the execution flow.

IL_0194: ldloc.s 6
IL_0196: callvirt instance void Verse.IStrippable::Strip()


Thanks Jaxxa, your guess was spot on.

You just made my day !!!! Thanks !!!!

Jaxxa

I have also added this as an option to my mod ED-EnhancedOptions.

I am using a Harmony Prefix and am checking if the job.RecipeDef.defName is "CremateCorpse" and strip or not based on that.