Qustion about pawn's body size parameter and if it can be changed.

Started by zloiiojik, September 11, 2020, 10:48:46 PM

Previous topic - Next topic

zloiiojik

So, it's been on my mind for quite a while and I certainly didnt find an answer to it yet - Is it possible to make the body size of a pawn or a creature change over time? Not when a creature matures form an infant or a larva or something, but via some sort of training or operation. There is a mod, for example, the RPG leveling system. When you level strength, yeah, it increases your carry weight, melee damage etc, but it doesnt change the body size at all. And I had this thing on my mind - could there be a way to, sort of, simulate the growth of muscular mass for example? To extent of having stronger pawns have body parts with slightly more hp? Or a pawn could undergo a surgery, or a mutation that could increase or decrease it's body size to some extent, like super soldier serums and stuff?

RawCode

1) dnspy
2) csharp dll
3) most effective way to track values you need is debugger ofc, but start with UI frames used to display such data to player.

it's most effective because you can use keywords from translation files to search places, where keywords are used.

zloiiojik

Well...thats a start I guess...
I wonder if my attempts will fruit something ^_^

RawCode


LWM

Someone was trying to find a way to be able to make a pawn change into a larger size a while ago, and I don't think they ever managed to.  They were going for a superhuman kind of like the Emporer in the warhammer 40k universe, IIRC?  But if you can find that thread, it might help you get an idea.

It's possible it's not easy - I think they gave up with that aspect in the end.

You might be able to make lifestages that cannot actually be reached or something, and trigger going to them?  I don't know...but you might not have much luck.

RawCode

it is easy and does not need any outstanding skills.

if you want specific pawn to have specific body part with more health, like zombie version of pawn, that have absurd amount of HP on all body parts expect head you open rimworld code with dnspy and check, how body part health is stored and processed.

then you modify that value via mod, or probably directly with debugger.

if everything works properly, well, you made it, all you need is to wrap your experimental code into custom pawn class and job is done.

if not, for any reason, and changing that specific value have some side effects, or does not have effect at all, you must check again, again and again, and take in account everything in your custom code.

don't forget about saving and loading game, if your changes are lost on load, well, you did something wrong.

LWM

Quote from: RawCode on September 14, 2020, 04:32:00 AM
it is easy and does not need any outstanding skills.
[...]
if not, for any reason, and changing that specific value have some side effects, or does not have effect at all, you must check again, again and again, and take in account everything in your custom code.

Hehe...

If I recall correctly the size of the body part is stored somehow via the PawnKindDef, so if you just change it, you change it for everyone that's the same kind of pawn, so it may be complicated.

GhostData

BodySize is used in a number of calculations like bullet damage, visibility, and some hediff stuff.
Pawn has a property BodySize which just returns this.ageTracker.CurLifeStage.bodySizeFactor * this.RaceProps.baseBodySize;
The easiest way to get a pawn-specific body size would be at add your own component that tracks your body size factors, then reference it in a patch to this property.

I've never patched a property before, but behind the scenes it just compiles into a standard method. In theory it ought to be possible as long as the compiler doesn't inline the method.

Edit: For giggles, I did a POC
I'm using CNP as a reference since that's the only thing I've got with a pawn comp right now. In the patch below, I check my pawn's lifestage index, and if it's 3 (a child) I slap on an extra 100 to the body size.
[HarmonyPatch(typeof(Pawn), "get_BodySize")]
        public static class Pawn_BodySize_Patch {
            [HarmonyPostfix]
            public static void BodySize_PostFix(Pawn __instance, ref float __result) {
                if (__instance.TryGetComp<LifecycleComp>()?.CurrentLifestageIndex == 3) {
                    __result += 100;
                }
            }
         }

In game, for a child:


for an adult (index 5)


This should be all you need to tie in your own adjustments. Since this method is called at the Pawn level, you have a Pawn instance to reference for any pawn-specific parameters you want to add. I would suggest looking over the uses of BodySize first, as it may impact more than you realize. Also consider looking at other types of pawn for a comparison. Last I checked, an Elephant had a bodysize of 4, so you'll have to be careful with how much you add if you want to keep it believable.