What does the code look like for the connection of body parts?

Started by The Great Muffalo, November 13, 2018, 07:14:57 PM

Previous topic - Next topic

The Great Muffalo

The finger is connected to the hand, the hand is connected to the arm, the arm is connected to the shoulder, and the shoulder is connected to the torso. Is every body part the same type with a parent of type BodyPart and a list of type BodyPart or are they different classes?
"I was chained up, only able to see shadows. They moved, they danced, they were my world. I couldn't turn my head, I couldn't face the light. But as soon as the light hit my face, I pitied those who were still looking at shapes made only of darkness."

swampslug

You can see the code if you open your Rimworld folder, if you have it installed via Steam the folder path you want is something like this: "D:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\Core\Defs\Bodies\Bodies_Humanlike.xml". You should be able to open this in Notepad or Notepad++.

This file defines how the individual bodyparts are connected into the body. From this you should see that there is a <BodyDef> with a <defName> of Human. It has a <corePart> with a <def> of Torso to which all other bodyparts are ultimately attached. Anything that is attached to the torso is included within its <parts> node. The shoulders then have their own <parts> node containing the clavicle and arm, which has a <parts> node and so on. Using your example the basic structure looks like this:

<BodyDef>
    <defName>Human</defName>
    <label>human</label>
    <corePart>
      <def>Torso</def>
      <parts>
        <li>
          <def>Shoulder</def>
          <parts>
            <li>
              <def>Arm</def>
              <parts>
                <li>
                  <def>Hand</def>
                  <parts>
                    <li>
                      <def>Finger</def>
                    </li>
                    <li>
                      <def>Finger</def>
                    </li>
                    <li>
                      <def>Finger</def>
                    </li>
                    <li>
                      <def>Finger</def>
                    </li>
                    <li>
                      <def>Finger</def>
                    </li>
                  </parts>
                </li>
              </parts>
            </li>
          </parts>
        </li>
      </parts>
    </corePart>
  </BodyDef>


Note: I have excluded a lot code just to show the basic structure, looking at the actual code shows that each element should have a coverage value assigned that determines how likely a bodypart is to hit (and the mass to deduct if that part is missing). A shoulder is 12% of the body, an arm is 77% of the shoulder (9.24% of the total body) and a hand is 14% of the arm (1.29% of the total body).
Bodyparts can also be assigned customLabels, groups and depth values.

It should also be noted that every bodypart has its own <BodyPartDef> defined in the various BodyParts files in the same folder. These define the hit points, and any relevant tags such as ManipulationLimbSegment or BreathingSource that the game uses to determine whether a pawn is capable of moving or even living.

The Great Muffalo

Interesting, I also noticed that organs seem to be simulated to be embedded in the head or torso, such as the brain, heart, or liver. What I mean by embedded is that bullets and sharp weapons have to penetrate the skull before they can damage the brain (and potentially hit armor before that) or damage the torso before they can damage a lung.
"I was chained up, only able to see shadows. They moved, they danced, they were my world. I couldn't turn my head, I couldn't face the light. But as soon as the light hit my face, I pitied those who were still looking at shapes made only of darkness."