RimWorld

RimWorld

Corpse Children
Mod Compatibility, Hediff Severity
I found an incompatibility with RJW -- which adds several new custom body parts, along with some Hediff's for those body parts. These hediffs are used to measure the size of the various body parts, and are used for calculating what happens when various sized body parts interact with other various sized body parts -- and to do so it uses Severity.

Which is triggering your "diseasedParts" enumeration from JobDriver_ConstructCorpseChild.cs specifically this line:

IEnumerable<BodyPartRecord> diseasedParts = targetPawn.health.hediffSet.hediffs.Where(h => !(h is Hediff_Injury || h is Hediff_MissingPart || (h.CurStage?.becomeVisible == false)) && h.Severity > 0).Select(h => h.Part);

This results in the right click menu when selecting a corpse to not display the "Create a corpse child..." option. I believe another player noted that for some races, they were also not seeing this menu option even though the target was not diseased and not missing any parts and it's possible that Severity was being used for those custom races in some way.

I'm not a RimWorld modder, but poking around I discovered the following note from

https://github.com/RimWorldMod/RimworldModdingFiles/blob/master/Defs/HediffDefs/Hediffs.xml


<lethalSeverity>number</lethalSeverity> <!-- Optional. Defaults to -1 (insignificant). If the hediff's severity reaches this level, the pawn will die -->

In the case of RJW, all of the offending hediffs that are causing problems have lethalSeverity set to -1 (insignificant).

I've not done any extensive searches for other hediffs with lethalSeverity of -1 to see if any of them would be something that should prevent the creation of Corpse Children, I'm guessing that if it's flagged as "insignificant" the hediff can probably be safely ignored with something like this alternative line of code:

IEnumerable<BodyPartRecord> diseasedParts = targetPawn.health.hediffSet.hediffs.Where(h => !(h is Hediff_Injury || h is Hediff_MissingPart || (h.CurStage?.becomeVisible == false)) && h.def.lethalSeverity != -1 && h.Severity > 0).Select(h => h.Part);
< >
Showing 1-6 of 6 comments
Static.Sprocket 1 Apr, 2023 @ 3:29pm 
I just tested the change locally, and had an amusing thing happen -- it works, in that the RJW parts no longer prevent the creation of a Corpse Child, but the newly risen pawn lists two of those parts as "Gone" and one as "Destroyed" -- which I'm guessing is because the Hediffs are being modified in the MakeNewToils() probably somewhere in in the following code:

newPawn.health.RemoveAllHediffs(); List<Hediff> targetHediffs = this.TargetPawn.health.hediffSet.hediffs; for (int num = targetHediffs.Count - 1; num >= 0; num--) { Hediff hediff = targetHediffs[num]; if (hediff.Part != null && newPawn.health.hediffSet.GetNotMissingParts().Contains(hediff.Part)) { targetHediffs.RemoveAt(num); if (!(hediff is Hediff_AddedPart || hediff is Hediff_Implant || hediff is Hediff_Injury || hediff is Hediff_MissingPart) && hediff.Severity > 0) { newPawn.health.AddHediff(HediffDefOf.MissingBodyPart, hediff.Part, new DamageInfo(DamageDefOf.Scratch, 99999f, 999f, -1f, null, hediff.Part)); } else { if (hediff is Hediff_Injury) { hediff.Severity = Math.Min(hediff.Severity, 1f); HediffComp_GetsPermanent hediffComp_GetsPermanent = hediff.TryGetComp<HediffComp_GetsPermanent>(); if (hediffComp_GetsPermanent != null) { hediffComp_GetsPermanent.IsPermanent = true; } } newPawn.health.AddHediff(hediff, hediff.Part); } } }

There's one obvious spot where it's checking for Severity > 0 that'll need the lethalSeverity != -1 check, but other than the new pawns missing the extra bits from RJW it's at least working now :)
Last edited by Static.Sprocket; 1 Apr, 2023 @ 3:29pm
Static.Sprocket 1 Apr, 2023 @ 3:50pm 
Adding the lethalSeverity check into the appropriate line in MakeNewToils() appears to have sorted out the issue, and the body parts are now carried over from the corpse to the new pawn
Kayesh  [developer] 1 Apr, 2023 @ 8:55pm 
And you said you weren't a Rimworld modder! Nice work tracking that down. I had reports that this didn't play nice with RJW but I didn't want to grab RJW to investigate.
I'm not playing at modding at the moment, but when I get back to things (and if you don't mind my taking advantage of your work and testing) I may need to steal this and plug it in.
Static.Sprocket 1 Apr, 2023 @ 9:43pm 
If you don't see any other issues with it, feel free to use it -- I'm just not sure if there's any other repercussions of using the lethalSeverity check, it might end up letting people raise up pawns that should otherwise be disallowed. I just couldn't think of any better way of dealing with it. I'd thought about trying to add tags to the body parts or hediffs and using those to filter out the parts, but wanted to keep the change as small as possible.

Heh, I do some C# and PowerShell work in my day job -- but haven't tried my hand at modding RimWorld yet.
Kayesh  [developer] 1 Apr, 2023 @ 10:29pm 
Keeping it small is the way to go: reduces the chance of mod conflicts. But nah, since I've stayed away from any art stuff, it's just C# and XML... so that's nice. It's a bit more of a thing when you need to inject hooks into Rimworld's code, but Harmony helps with that immensely.
Took me a bit of time to work things out when I wrote this mod: Rimworld modding tutorials are a start but are very outdated. Best suggestion I saw was to just get ILSpy to decompile Rimworld binaries into C# and look at how things interact. Snooping on a mod helps: you can follow the XMLs through to their respective classes as a start.
Kayesh  [developer] 1 Apr, 2023 @ 10:32pm 
But yeah, I added the source to the mods (with best intentions of commenting) so folks could mess around and hopefully get a headstart if they wanted to get into modding.
< >
Showing 1-6 of 6 comments
Per page: 1530 50