]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Person.cpp
License: Update GPLv2+ header to match current FSF recommendation
[lugaru.git] / Source / Person.cpp
index b1e9f0aa2e396c883afbcdf092e4647d14bccbbc..3327f5abc3c139901d5b0f1cd9093c4981b8b67e 100644 (file)
@@ -3,20 +3,18 @@ Copyright (C) 2003, 2010 - Wolfire Games
 
 This file is part of Lugaru.
 
-Lugaru is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
+Lugaru is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
+Lugaru is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-See the GNU General Public License for more details.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /**> HEADER FILES <**/
@@ -83,18 +81,23 @@ extern int indialogue;
 
 extern bool gamestarted;
 
-Person player[maxplayers];
+std::vector<std::shared_ptr<Person>> Person::players(1, std::shared_ptr<Person>(new Person()));
 
+/* EFFECT
+ *
+ * USES:
+ * GameTick/doPlayerCollisions
+ */
 void Person::CheckKick()
 {
     if (!(hasvictim
             && (animTarget == rabbitkickanim
                 && victim
-                && victim != this
+                && victim != this->shared_from_this()
                 && frameCurrent >= 2
                 && animCurrent == rabbitkickanim)
-            && (distsq(&coords, &victim->coords) < 1.2)
-            && (!victim->skeleton.free)))
+            && distsq(&coords, &victim->coords) < 1.2
+            && !victim->skeleton.free))
         return;
 
     if (animation[victim->animTarget].height != lowheight) {
@@ -140,10 +143,17 @@ void Person::CheckKick()
         victim->oldcoords = victim->coords;
         coords = victim->coords;
         victim->targetyaw = targetyaw;
-        victim->victim = this;
+        victim->victim = this->shared_from_this();
     }
 }
 
+/* EFFECT
+ *
+ * USES:
+ * GameTick/doPlayerCollisions - spread fire between players
+ * GameTick/doDebugKeys - press f to ignite
+ * Person::DoStuff - spread fire from lit campfires and bushes
+ */
 void Person::CatchFire()
 {
     XYZ flatfacing, flatvelocity;
@@ -172,12 +182,17 @@ void Person::CatchFire()
     onfire = 1;
 }
 
+/* FUNCTION
+ * idle animation for this creature (depending on status)
+ */
 int Person::getIdle()
 {
     if (indialogue != -1 && howactive == typeactive && creature == rabbittype)
         return talkidleanim;
-    if (hasvictim && victim != this/*||(id==0&&attackkeydown)*/)
-        if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype && victim->aitype != searchtype && aitype != passivetype && aitype != searchtype && victim->id < numplayers)) {
+    if (hasvictim && (victim != this->shared_from_this())/*||(id==0&&attackkeydown)*/)
+        if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype &&
+            victim->aitype != searchtype && aitype != passivetype && aitype != searchtype &&
+            victim->id < Person::players.size())) {
             if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) {
                 if (creature == rabbittype)
                     return fightidleanim;
@@ -211,6 +226,9 @@ int Person::getIdle()
     return 0;
 }
 
+/* FUNCTION
+ * crouch animation for this creature
+ */
 int Person::getCrouch()
 {
     if (creature == rabbittype)
@@ -220,6 +238,9 @@ int Person::getCrouch()
     return 0;
 }
 
+/* FUNCTION
+ * running animation for this creature (can be upright or all fours)
+ */
 int Person::getRun()
 {
     if (creature == rabbittype && (!superruntoggle || weaponactive != -1))
@@ -234,6 +255,8 @@ int Person::getRun()
     return 0;
 }
 
+/* FUNCTION
+ */
 int Person::getStop()
 {
     if (creature == rabbittype)
@@ -243,6 +266,8 @@ int Person::getStop()
     return 0;
 }
 
+/* FUNCTION
+ */
 int Person::getLanding()
 {
     if (creature == rabbittype)
@@ -252,6 +277,8 @@ int Person::getLanding()
     return 0;
 }
 
+/* FUNCTION
+ */
 int Person::getLandhard()
 {
     if (creature == rabbittype)
@@ -261,6 +288,11 @@ int Person::getLandhard()
     return 0;
 }
 
+/* EFFECT
+ *
+ * USES:
+ * Person::DoAnimations
+ */
 static void
 SolidHitBonus(int playerid)
 {
@@ -270,8 +302,12 @@ SolidHitBonus(int playerid)
         award_bonus(playerid, solidhit);
 }
 
+/* EFFECT
+ * spawns blood effects
+ */
 void Person::DoBlood(float howmuch, int which)
 {
+    // FIXME: should abstract out inputs
     static int bleedxint, bleedyint;
     static XYZ bloodvel;
     //if(howmuch&&id==0)blooddimamount=1;
@@ -279,6 +315,7 @@ void Person::DoBlood(float howmuch, int which)
         if (bleeding <= 0 && spurt) {
             spurt = 0;
             for (int i = 0; i < 3; i++) {
+                // emit blood particles
                 bloodvel = 0;
                 if (!skeleton.free) {
                     bloodvel.z = 10;
@@ -288,25 +325,26 @@ void Person::DoBlood(float howmuch, int which)
                     bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
                 }
                 if (skeleton.free)
-                    bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
+                    bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
                 if (!skeleton.free)
                     bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
                 if (skeleton.free) {
-                    Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .05, 1);
-                    Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .3, 1);
+                    Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                    Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
                 }
                 if (!skeleton.free) {
-                    Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
-                    Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
+                    Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                    Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
                 }
             }
-            if (Random() % 2 == 0)
+            if (Random() % 2 == 0) // 50% chance
                 for (int i = 0; i < 3; i++) {
                     if (Random() % 2 != 0) {
+                        // emit teeth particles
                         bloodvel = 0;
                         if (skeleton.free) {
                             bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
-                            bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
+                            bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
                         } else {
                             bloodvel.z = 10;
                             bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
@@ -314,15 +352,16 @@ void Person::DoBlood(float howmuch, int which)
                         }
                         bloodvel *= .2;
                         if (skeleton.free) {
-                            Sprite::MakeSprite(splintersprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                            Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
                         } else {
-                            Sprite::MakeSprite(splintersprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                            Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
                         }
-                        Sprite::setLastSpriteSpecial(3);
+                        Sprite::setLastSpriteSpecial(3); // sets it to teeth
                     }
                 }
         }
         if (decals) {
+            // FIXME: manipulating attributes
             bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
             bleedxint = 0;
             bleedyint = 0;
@@ -348,6 +387,10 @@ void Person::DoBlood(float howmuch, int which)
         bleeding = 2;
 }
 
+/* EFFECT
+ * spawns big blood effects and ???
+ * modifies character's skin texture
+ */
 void Person::DoBloodBig(float howmuch, int which)
 {
     static int bleedxint, bleedyint, i, j;
@@ -357,8 +400,10 @@ void Person::DoBloodBig(float howmuch, int which)
 
     if (tutoriallevel != 1 || id == 0)
         if (aitype != playercontrolled && howmuch > 0) {
+            // play pain sounds
             int whichsound = -1;
 
+            // FIXME: seems to be spawning sounds by manipulating attributes... MESSY!
             if (creature == wolftype) {
                 int i = abs(Random() % 2);
                 if (i == 0)
@@ -388,6 +433,7 @@ void Person::DoBloodBig(float howmuch, int which)
         }
 
     if (id == 0 && howmuch > 0) {
+        // FIXME: manipulating attributes
         flashamount = .5;
         flashr = 1;
         flashg = 0;
@@ -399,6 +445,8 @@ void Person::DoBloodBig(float howmuch, int which)
         if (bleeding <= 0 && spurt) {
             spurt = 0;
             for (int i = 0; i < 3; i++) {
+                // emit blood particles
+                // FIXME: copypaste from above
                 bloodvel = 0;
                 if (!skeleton.free) {
                     bloodvel.z = 10;
@@ -408,19 +456,24 @@ void Person::DoBloodBig(float howmuch, int which)
                     bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
                 }
                 if (skeleton.free)
-                    bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
+                    bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
                 if (!skeleton.free)
                     bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
                 if (skeleton.free) {
-                    Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .05, 1);
-                    Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .3, 1);
+                    Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                    Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
                 }
                 if (!skeleton.free) {
-                    Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
-                    Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
+                    Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                    Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
                 }
             }
         }
+
+        // weird texture manipulation code follows.
+        // looks like this is painting blood onto the character's skin texture
+        // FIXME: surely there's a better way
+
         int offsetx = 0, offsety = 0;
         if (which == 225) {
             offsety = Random() % 40;
@@ -562,6 +615,9 @@ void Person::DoBloodBig(float howmuch, int which)
         bleeding = 2;
 }
 
+/* EFFECT
+ * similar to DoBloodBig
+ */
 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
 {
     static int i, j;
@@ -587,8 +643,10 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
         endpoint.y -= 100;
         movepoint = 0;
         rotationpoint = 0;
+        // ray testing for a tri in the character model
         whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
         if (whichtri != -1) {
+            // low level geometry math
             p0 = colpoint;
             p1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
             p2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
@@ -635,6 +693,8 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
             if (bleeding <= 0 && spurt) {
                 spurt = 0;
                 for (int i = 0; i < 3; i++) {
+                    // emit blood particles
+                    // FIXME: more copypaste code
                     bloodvel = 0;
                     if (!skeleton.free) {
                         bloodvel.z = 10;
@@ -644,19 +704,22 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
                         bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
                     }
                     if (skeleton.free)
-                        bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
+                        bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
                     if (!skeleton.free)
                         bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
                     if (skeleton.free) {
-                        Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .05, 1);
-                        Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .3, 1);
+                        Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                        Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
                     }
                     if (!skeleton.free) {
-                        Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
-                        Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
+                        Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                        Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
                     }
                 }
             }
+
+            // texture manipulation follows
+
             int offsetx = 0, offsety = 0;
             /*if(which==225){
             offsety=Random()%40;
@@ -795,6 +858,9 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
 
 
 
+/* EFFECT
+ * guessing this performs a reversal
+ */
 void Person::Reverse()
 {
     if (!((victim->aitype == playercontrolled
@@ -855,8 +921,8 @@ void Person::Reverse()
             }
 
             victim->weaponactive = -1;
-            for (int j = 0; j < numplayers; j++) {
-                player[j].wentforweapon = 0;
+            for (unsigned j = 0; j < Person::players.size(); j++) {
+                Person::players[j]->wentforweapon = 0;
             }
         }
 
@@ -885,8 +951,8 @@ void Person::Reverse()
             }
 
             victim->weaponactive = -1;
-            for (int j = 0; j < numplayers; j++) {
-                player[j].wentforweapon = 0;
+            for (unsigned j = 0; j < Person::players.size(); j++) {
+                Person::players[j]->wentforweapon = 0;
             }
         }
         animTarget = staffspinhitreversedanim;
@@ -914,8 +980,8 @@ void Person::Reverse()
             }
 
             victim->weaponactive = -1;
-            for (int j = 0; j < numplayers; j++) {
-                player[j].wentforweapon = 0;
+            for (unsigned j = 0; j < Person::players.size(); j++) {
+                Person::players[j]->wentforweapon = 0;
             }
         }
         animTarget = swordslashreversedanim;
@@ -943,8 +1009,8 @@ void Person::Reverse()
             }
 
             victim->weaponactive = -1;
-            for (int j = 0; j < numplayers; j++) {
-                player[j].wentforweapon = 0;
+            for (unsigned j = 0; j < Person::players.size(); j++) {
+                Person::players[j]->wentforweapon = 0;
             }
         }
         animTarget = knifeslashreversedanim;
@@ -962,14 +1028,14 @@ void Person::Reverse()
         victim->coords = coords;
         victim->targetyaw = targetyaw;
         victim->yaw = targetyaw;
-        victim->victim = this;
+        victim->victim = this->shared_from_this();
     }
     if (animTarget == winduppunchanim) {
         animTarget = winduppunchblockedanim;
         victim->animTarget = blockhighleftanim;
         victim->frameTarget = 1;
         victim->target = .5;
-        victim->victim = this;
+        victim->victim = this->shared_from_this();
         victim->targetyaw = targetyaw + 180;
     }
     if (animTarget == wolfslapanim) {
@@ -977,7 +1043,7 @@ void Person::Reverse()
         victim->animTarget = blockhighleftanim;
         victim->frameTarget = 1;
         victim->target = .5;
-        victim->victim = this;
+        victim->victim = this->shared_from_this();
         victim->targetyaw = targetyaw + 180;
     }
     if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) {
@@ -987,7 +1053,7 @@ void Person::Reverse()
         victim->animTarget = swordslashparryanim;
         victim->frameTarget = 1;
         victim->target = .5;
-        victim->victim = this;
+        victim->victim = this->shared_from_this();
         victim->targetyaw = targetyaw + 180;
 
         if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
@@ -1026,8 +1092,8 @@ void Person::Reverse()
                     victim->weaponstuck = 0;
             }
             victim->weaponactive = -1;
-            for (int i = 0; i < numplayers; i++) {
-                player[i].wentforweapon = 0;
+            for (unsigned i = 0; i < Person::players.size(); i++) {
+                Person::players[i]->wentforweapon = 0;
             }
         }
 
@@ -1069,8 +1135,8 @@ void Person::Reverse()
                     weaponstuck = 0;
             }
             weaponactive = -1;
-            for (int i = 0; i < numplayers; i++) {
-                player[i].wentforweapon = 0;
+            for (unsigned i = 0; i < Person::players.size(); i++) {
+                Person::players[i]->wentforweapon = 0;
             }
 
 
@@ -1133,21 +1199,29 @@ void Person::Reverse()
         numreversals++;
 }
 
+/* EFFECT
+ * get hurt
+ */
 void Person::DoDamage(float howmuch)
 {
+    // subtract health (temporary?)
     if (tutoriallevel != 1)
         damage += howmuch / power;
+    // stats?
     if (id != 0)
         damagedealt += howmuch / power;
     if (id == 0)
         damagetaken += howmuch / power;
 
+    // reset bonuses
     if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo))
         bonus = 0;
+    // subtract health
     if (tutoriallevel != 1)
         permanentdamage += howmuch / 2 / power;
     if (tutoriallevel != 1)
         superpermanentdamage += howmuch / 4 / power;
+    // visual effects
     if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2)
         DoBlood(1, 255);
     if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt)
@@ -1160,6 +1234,7 @@ void Person::DoDamage(float howmuch)
     if (blackout > 1)
         blackout = 1;
 
+    // cancel attack?
     if (aitype == passivetype && damage < damagetolerance && ((tutoriallevel != 1 || cananger) && hostile))
         aitype = attacktypecutoff;
     if (tutoriallevel != 1 && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
@@ -1207,6 +1282,7 @@ void Person::DoDamage(float howmuch)
         coords = 20;
     }
 
+    // play sounds
     if (tutoriallevel != 1 || id == 0)
         if (speechdelay <= 0 && !dead && aitype != playercontrolled) {
             int whichsound = -1;
@@ -1245,6 +1321,9 @@ void Person::DoDamage(float howmuch)
     //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
 }
 
+/* EFFECT
+ * calculate/animate head facing direction?
+ */
 void Person::DoHead()
 {
     static XYZ rotatearound;
@@ -1307,8 +1386,8 @@ void Person::DoHead()
             headpitch += multiplier * lookspeed / 2;
         }
 
-        rotatearound = skeleton.joints[skeleton.jointlabels[neck]].position;
-        skeleton.joints[skeleton.jointlabels[head]].position = rotatearound + DoRotation(skeleton.joints[skeleton.jointlabels[head]].position - rotatearound, headpitch, 0, 0);
+        rotatearound = jointPos(neck);
+        jointPos(head) = rotatearound + DoRotation(jointPos(head) - rotatearound, headpitch, 0, 0);
 
         facing = 0;
         facing.z = -1;
@@ -1329,8 +1408,7 @@ void Person::DoHead()
 
         skeleton.specialforward[0] = facing;
         //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
-        static int i;
-        for (i = 0; i < skeleton.num_muscles; i++) {
+        for (int i = 0; i < skeleton.num_muscles; i++) {
             if (skeleton.muscles[i].visible && (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)) {
                 skeleton.FindRotationMuscle(i, animTarget);
             }
@@ -1338,6 +1416,9 @@ void Person::DoHead()
     }
 }
 
+/* EFFECT
+ * ragdolls character?
+ */
 void Person::RagDoll(bool checkcollision)
 {
     static XYZ change;
@@ -1373,7 +1454,7 @@ void Person::RagDoll(bool checkcollision)
         if (!isnormal(tilt)) tilt = 0;
         if (!isnormal(tilt2)) tilt2 = 0;
 
-        for (i = 0; i < skeleton.num_joints; i++) {
+        for (int i = 0; i < skeleton.num_joints; i++) {
             skeleton.joints[i].delay = 0;
             skeleton.joints[i].locked = 0;
             skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
@@ -1385,7 +1466,7 @@ void Person::RagDoll(bool checkcollision)
             skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords;
         }
 
-        for (i = 0; i < skeleton.num_joints; i++) {
+        for (int i = 0; i < skeleton.num_joints; i++) {
             skeleton.joints[i].velocity = 0;
             skeleton.joints[i].velchange = 0;
         }
@@ -1406,7 +1487,7 @@ void Person::RagDoll(bool checkcollision)
 
         speed *= speedmult;
 
-        for (i = 0; i < skeleton.num_joints; i++) {
+        for (int i = 0; i < skeleton.num_joints; i++) {
             if ((animation[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && animation[animCurrent].height == animation[animTarget].height)
                 skeleton.joints[i].velocity = velocity / scale + facing * 5 + DoRotation(DoRotation(DoRotation((animation[animTarget].position[i][frameTarget] - animation[animCurrent].position[i][frameCurrent]) * speed, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
             else
@@ -1459,18 +1540,19 @@ void Person::RagDoll(bool checkcollision)
         updatedelay = 0;
 
         velocity = 0;
-        for (i = 0; i < skeleton.num_joints; i++) {
+        for (int i = 0; i < skeleton.num_joints; i++) {
             velocity += skeleton.joints[i].velocity * scale;
         }
         velocity /= skeleton.num_joints;
 
+        // drop weapon
         if (Random() % 2 == 0) {
             if (weaponactive != -1 && animTarget != rabbitkickanim && num_weapons > 0) {
                 weapons[weaponids[0]].owner = -1;
                 weapons[weaponids[0]].hitsomething = 0;
-                weapons[weaponids[0]].velocity = skeleton.joints[skeleton.jointlabels[righthand]].velocity * scale * -.3;
+                weapons[weaponids[0]].velocity = jointVel(righthand) * scale * -.3;
                 weapons[weaponids[0]].velocity.x += .01;
-                weapons[weaponids[0]].tipvelocity = skeleton.joints[skeleton.jointlabels[righthand]].velocity * scale;
+                weapons[weaponids[0]].tipvelocity = jointVel(righthand) * scale;
                 weapons[weaponids[0]].missed = 1;
                 weapons[weaponids[0]].freetime = 0;
                 weapons[weaponids[0]].firstfree = 1;
@@ -1482,8 +1564,8 @@ void Person::RagDoll(bool checkcollision)
                         weaponstuck = 0;
                 }
                 weaponactive = -1;
-                for (i = 0; i < numplayers; i++) {
-                    player[i].wentforweapon = 0;
+                for (unsigned i = 0; i < Person::players.size(); i++) {
+                    Person::players[i]->wentforweapon = 0;
                 }
             }
         }
@@ -1497,6 +1579,8 @@ void Person::RagDoll(bool checkcollision)
 
 
 
+/* EFFECT
+ */
 void Person::FootLand(int which, float opacity)
 {
     static XYZ terrainlight;
@@ -1505,9 +1589,9 @@ void Person::FootLand(int which, float opacity)
         if (opacity > 1) {
             footvel = 0;
             if (which == 0)
-                footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
+                footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
             if (which == 1)
-                footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
+                footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
             //footpoint.y=coords.y;
             if (distsq(&footpoint, &viewer))
                 Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity);
@@ -1516,9 +1600,9 @@ void Person::FootLand(int which, float opacity)
             if (footvel.y < .8)
                 footvel.y = .8;
             if (which == 0)
-                footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
+                footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
             if (which == 1)
-                footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
+                footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
             footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
             terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
             if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
@@ -1532,9 +1616,9 @@ void Person::FootLand(int which, float opacity)
             if (footvel.y < .8)
                 footvel.y = .8;
             if (which == 0)
-                footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
+                footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
             if (which == 1)
-                footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
+                footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
             footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
             terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
             if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
@@ -1544,9 +1628,9 @@ void Person::FootLand(int which, float opacity)
             if (footvel.y < .8)
                 footvel.y = .8;
             if (which == 0)
-                footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
+                footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
             if (which == 1)
-                footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
+                footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
             footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
             terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
             if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
@@ -1560,29 +1644,30 @@ void Person::FootLand(int which, float opacity)
             if (footvel.y < .8)
                 footvel.y = .8;
             if (which == 0)
-                footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
+                footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
             if (which == 1)
-                footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
+                footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
             //footpoint.y=coords.y;
             if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
                 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity);
         }
 }
 
+/* EFFECT
+ * make a puff effect at a body part (dust effect?)
+ */
 void Person::Puff(int whichlabel)
 {
     static XYZ footvel, footpoint;
 
     footvel = 0;
-    footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position, 0, yaw, 0) * scale + coords;
+    footpoint = DoRotation(jointPos(whichlabel), 0, yaw, 0) * scale + coords;
     Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .9, .3);
 }
 
-Joint& Person::getJointFor(int bodypart)
-{
-    return skeleton.joints[skeleton.jointlabels[bodypart]];
-}
-
+/* EFFECT
+ * I think I added this in an attempt to clean up code
+ */
 void Person::setAnimation(int animation)
 {
     animTarget = animation;
@@ -1590,10 +1675,13 @@ void Person::setAnimation(int animation)
     target = 0;
 }
 
-void   Person::DoAnimations()
+/* EFFECT
+ * MONSTER
+ * TODO: ???
+ */
+void Person::DoAnimations()
 {
     if (!skeleton.free) {
-        int i = 0;
         static float oldtarget;
 
         if (isIdle() && animCurrent != getIdle())
@@ -1745,12 +1833,12 @@ void    Person::DoAnimations()
                     }
                     if (animation[animTarget].label[frameTarget] == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
                         if (animation[animTarget].attack != neutral) {
-                            i = abs(Random() % 3);
-                            if (i == 0)
+                            unsigned r = abs(Random() % 3);
+                            if (r == 0)
                                 whichsound = lowwhooshsound;
-                            if (i == 1)
+                            if (r == 1)
                                 whichsound = midwhooshsound;
-                            if (i == 2)
+                            if (r == 2)
                                 whichsound = highwhooshsound;
                         }
                         if (animation[animTarget].attack == neutral)
@@ -1787,18 +1875,18 @@ void    Person::DoAnimations()
                             int whichsound = -1;
                             if (animation[animTarget].label[frameTarget] == 4 && aitype != playercontrolled) {
                                 if (animation[animTarget].attack != neutral) {
-                                    i = abs(Random() % 4);
+                                    unsigned r = abs(Random() % 4);
                                     if (creature == rabbittype) {
-                                        if (i == 0) whichsound = rabbitattacksound;
-                                        if (i == 1) whichsound = rabbitattack2sound;
-                                        if (i == 2) whichsound = rabbitattack3sound;
-                                        if (i == 3) whichsound = rabbitattack4sound;
+                                        if (r == 0) whichsound = rabbitattacksound;
+                                        if (r == 1) whichsound = rabbitattack2sound;
+                                        if (r == 2) whichsound = rabbitattack3sound;
+                                        if (r == 3) whichsound = rabbitattack4sound;
                                     }
                                     if (creature == wolftype) {
-                                        if (i == 0) whichsound = barksound;
-                                        if (i == 1) whichsound = bark2sound;
-                                        if (i == 2) whichsound = bark3sound;
-                                        if (i == 3) whichsound = barkgrowlsound;
+                                        if (r == 0) whichsound = barksound;
+                                        if (r == 1) whichsound = bark2sound;
+                                        if (r == 2) whichsound = bark3sound;
+                                        if (r == 3) whichsound = barkgrowlsound;
                                     }
                                     speechdelay = .3;
                                 }
@@ -1826,7 +1914,7 @@ void      Person::DoAnimations()
             frameTarget++;
 
             if (animTarget == removeknifeanim && animation[animTarget].label[frameCurrent] == 5) {
-                for (i = 0; i < weapons.size(); i++) {
+                for (unsigned i = 0; i < weapons.size(); i++) {
                     if (weapons[i].owner == -1)
                         if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
                             if (distsq(&coords, &weapons[i].position) >= 1) {
@@ -1847,20 +1935,20 @@ void    Person::DoAnimations()
             }
 
             if (animTarget == crouchremoveknifeanim && animation[animTarget].label[frameCurrent] == 5) {
-                for (i = 0; i < weapons.size(); i++) {
+                for (unsigned i = 0; i < weapons.size(); i++) {
                     bool willwork = true;
                     if (weapons[i].owner != -1)
-                        if (player[weapons[i].owner].weaponstuck != -1)
-                            if (player[weapons[i].owner].weaponids[player[weapons[i].owner].weaponstuck] == i)
-                                if (player[weapons[i].owner].num_weapons > 1)
+                        if (Person::players[weapons[i].owner]->weaponstuck != -1)
+                            if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == int(i))
+                                if (Person::players[weapons[i].owner]->num_weapons > 1)
                                     willwork = 0;
-                    if ((weapons[i].owner == -1) || (hasvictim && weapons[i].owner == victim->id && victim->skeleton.free))
+                    if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free))
                         if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) {
                             if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
                                 bool fleshstuck = false;
                                 if (weapons[i].owner != -1)
                                     if (victim->weaponstuck != -1) {
-                                        if (victim->weaponids[victim->weaponstuck] == i) {
+                                        if (victim->weaponids[victim->weaponstuck] == int(i)) {
                                             fleshstuck = true;
                                         }
                                     }
@@ -1874,7 +1962,7 @@ void      Person::DoAnimations()
                                 weaponactive = 0;
                                 if (weapons[i].owner != -1) {
 
-                                    victim = &player[weapons[i].owner];
+                                    victim = Person::players[weapons[i].owner];
                                     if (victim->num_weapons == 1)
                                         victim->num_weapons = 0;
                                     else
@@ -1898,7 +1986,7 @@ void      Person::DoAnimations()
                                     footvel = 0;
                                     footpoint = weapons[i].position;
                                     if (victim->weaponstuck != -1) {
-                                        if (victim->weaponids[victim->weaponstuck] == i) {
+                                        if (victim->weaponids[victim->weaponstuck] == int(i)) {
                                             if (bloodtoggle)
                                                 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
                                             weapons[i].bloody = 2;
@@ -1909,14 +1997,14 @@ void    Person::DoAnimations()
                                     if (victim->num_weapons > 0) {
                                         if (victim->weaponstuck != 0 && victim->weaponstuck != -1)
                                             victim->weaponstuck = 0;
-                                        if (victim->weaponids[0] == i)
+                                        if (victim->weaponids[0] == int(i))
                                             victim->weaponids[0] = victim->weaponids[victim->num_weapons];
                                     }
 
-                                    victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * 6;
-                                    victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity += relative * 6;
-                                    victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity += relative * 6;
-                                    victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity += relative * 6;
+                                    victim->jointVel(abdomen) += relative * 6;
+                                    victim->jointVel(neck) += relative * 6;
+                                    victim->jointVel(rightshoulder) += relative * 6;
+                                    victim->jointVel(leftshoulder) += relative * 6;
                                 }
                                 weapons[i].owner = id;
                                 if (num_weapons > 0) {
@@ -1969,7 +2057,7 @@ void      Person::DoAnimations()
             if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0))
                 dojumpattack = 1;
             if (hasvictim)
-                if (distsq(&victim->coords, &/*player[i].*/coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1)
+                if (distsq(&victim->coords, &/*Person::players[i]->*/coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1)
                     dojumpattack = 1;
             if (!hostile)
                 dojumpattack = 0;
@@ -1988,17 +2076,17 @@ void    Person::DoAnimations()
                 targetloc = velocity;
                 Normalise(&targetloc);
                 targetloc += coords;
-                for (i = 0; i < numplayers; i++) {
+                for (unsigned i = 0; i < Person::players.size(); i++) {
                     if (i != id)
-                        if (distsq(&targetloc, &player[i].coords) < closestdist || closestdist == 0) {
-                            closestdist = distsq(&targetloc, &player[i].coords);
+                        if (distsq(&targetloc, &Person::players[i]->coords) < closestdist || closestdist == 0) {
+                            closestdist = distsq(&targetloc, &Person::players[i]->coords);
                             closestid = i;
                         }
                 }
                 if (closestid != -1)
-                    if (closestdist < 5 && !player[closestid].dead && animation[player[closestid].animTarget].height != lowheight && player[closestid].animTarget != backhandspringanim) {
+                    if (closestdist < 5 && !Person::players[closestid]->dead && animation[Person::players[closestid]->animTarget].height != lowheight && Person::players[closestid]->animTarget != backhandspringanim) {
                         hasvictim = 1;
-                        victim = &player[closestid];
+                        victim = Person::players[closestid];
                         coords = victim->coords;
                         animCurrent = rabbittacklinganim;
                         animTarget = rabbittacklinganim;
@@ -2053,10 +2141,10 @@ void    Person::DoAnimations()
                         relative.y = 0;
                         Normalise(&relative);
                         relative = DoRotation(relative, 0, -90, 0);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity += relative * damagemult * 40;
                         }
-                        victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
+                        victim->jointVel(head) += relative * damagemult * 200;
                         //FootLand(1,2);
                         victim->Puff(head);
                         victim->DoDamage(damagemult * 100 / victim->protectionhead);
@@ -2089,10 +2177,10 @@ void    Person::DoAnimations()
                         relative.y -= 1;
                         Normalise(&relative);
                         relative = DoRotation(relative, 0, 90, 0);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity += relative * damagemult * 20;
                         }
-                        victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 100;
+                        victim->jointVel(head) += relative * damagemult * 100;
                         //FootLand(1,2);
                         victim->Puff(head);
                         victim->DoDamage(damagemult * 50 / victim->protectionhead);
@@ -2120,10 +2208,10 @@ void    Person::DoAnimations()
                         relative.y = 0;
                         Normalise(&relative);
                         relative = DoRotation(relative, 0, -90, 0);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity += relative * damagemult * 40;
                         }
-                        victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
+                        victim->jointVel(head) += relative * damagemult * 200;
                         //FootLand(1,2);
                         victim->Puff(head);
                         victim->DoDamage(damagemult * 150 / victim->protectionhead);
@@ -2156,10 +2244,10 @@ void    Person::DoAnimations()
                         relative.y = 0;
                         Normalise(&relative);
                         relative = DoRotation(relative, 0, 90, 0);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity += relative * damagemult * 40;
                         }
-                        victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
+                        victim->jointVel(head) += relative * damagemult * 200;
                         //FootLand(1,2);
                         victim->Puff(head);
                         victim->DoDamage(damagemult * 150 / victim->protectionhead);
@@ -2186,10 +2274,10 @@ void    Person::DoAnimations()
                         relative = victim->coords - coords;
                         relative.y = 0;
                         Normalise(&relative);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity += relative * damagemult * 30;
                         }
-                        victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 100;
+                        victim->jointVel(head) += relative * damagemult * 100;
                         //FootLand(1,2);
                         victim->Puff(head);
                         victim->DoDamage(damagemult * 50 / victim->protectionhead);
@@ -2208,7 +2296,7 @@ void      Person::DoAnimations()
                         victim->skeleton.broken = 0;
                         victim->skeleton.spinny = 1;
 
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velchange = 0;
                             victim->skeleton.joints[i].delay = 0;
                             victim->skeleton.joints[i].locked = 0;
@@ -2219,14 +2307,14 @@ void    Person::DoAnimations()
                         relative = 0;
                         relative.y = 1;
                         Normalise(&relative);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity.y = relative.y * 10;
                             victim->skeleton.joints[i].position.y += relative.y * .3;
                             victim->skeleton.joints[i].oldposition.y += relative.y * .3;
                             victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
                         }
                         victim->Puff(abdomen);
-                        victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y = relative.y * 400;
+                        victim->jointVel(abdomen).y = relative.y * 400;
                     }
                 }
 
@@ -2242,7 +2330,7 @@ void      Person::DoAnimations()
                         relative = victim->coords - coords;
                         relative.y = 0;
                         Normalise(&relative);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity += relative * damagemult * 90;
                         }
                         victim->Puff(abdomen);
@@ -2251,7 +2339,7 @@ void      Person::DoAnimations()
                             slomodelay = .2;
                         }
                         victim->DoDamage(damagemult * 500 / victim->protectionhigh);
-                        victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 300;
+                        victim->jointVel(abdomen) += relative * damagemult * 300;
                     }
                 }
 
@@ -2269,7 +2357,7 @@ void      Person::DoAnimations()
                         victim->skeleton.broken = 0;
                         victim->skeleton.spinny = 1;
 
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velchange = 0;
                             //victim->skeleton.joints[i].delay=0;
                             victim->skeleton.joints[i].locked = 0;
@@ -2279,7 +2367,7 @@ void      Person::DoAnimations()
                         Normalise(&relative);
                         relative.y += .3;
                         Normalise(&relative);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity += relative * damagemult * 20;
                         }
                         if (!victim->dead)
@@ -2287,7 +2375,7 @@ void      Person::DoAnimations()
 
                         victim->Puff(abdomen);
                         victim->DoDamage(damagemult * 20 / victim->protectionhigh);
-                        victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
+                        victim->jointVel(abdomen) += relative * damagemult * 200;
                         staggerdelay = .5;
                         if (!victim->dead)
                             staggerdelay = 1.2;
@@ -2366,7 +2454,7 @@ void      Person::DoAnimations()
                                 victim->skeleton.free = 1;
                                 victim->skeleton.broken = 0;
 
-                                for (i = 0; i < victim->skeleton.num_joints; i++) {
+                                for (int i = 0; i < victim->skeleton.num_joints; i++) {
                                     victim->skeleton.joints[i].velchange = 0;
                                     victim->skeleton.joints[i].locked = 0;
                                     //victim->skeleton.joints[i].velocity=0;
@@ -2456,7 +2544,7 @@ void      Person::DoAnimations()
                                 victim->skeleton.free = 1;
                                 victim->skeleton.broken = 0;
 
-                                for (i = 0; i < victim->skeleton.num_joints; i++) {
+                                for (int i = 0; i < victim->skeleton.num_joints; i++) {
                                     victim->skeleton.joints[i].velchange = 0;
                                     victim->skeleton.joints[i].locked = 0;
                                     //victim->skeleton.joints[i].velocity=0;
@@ -2475,7 +2563,7 @@ void      Person::DoAnimations()
                                     victim->bled = 0;
                                 }
 
-                                victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 20;
+                                victim->jointVel(abdomen) += relative * damagemult * 20;
                             }
                         }
                     }
@@ -2503,10 +2591,10 @@ void    Person::DoAnimations()
                         relative = victim->coords - coords;
                         relative.y = 0;
                         Normalise(&relative);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity = relative * 30;
                         }
-                        victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 150;
+                        victim->jointVel(head) += relative * damagemult * 150;
 
                         victim->frameTarget = 0;
                         victim->animTarget = staggerbackhardanim;
@@ -2550,10 +2638,10 @@ void    Person::DoAnimations()
                         Normalise(&relative);
                         relative.y = .3;
                         Normalise(&relative);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity = relative * 5;
                         }
-                        victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 400;
+                        victim->jointVel(abdomen) += relative * damagemult * 400;
 
                         victim->frameTarget = 0;
                         victim->animTarget = staggerbackhardanim;
@@ -2605,7 +2693,7 @@ void      Person::DoAnimations()
                         escapednum = 0;
                         XYZ aim;
                         weapons[weaponids[0]].owner = -1;
-                        aim = victim->coords + DoRotation(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position, 0, victim->yaw, 0) * victim->scale + victim->velocity * findDistance(&victim->coords, &coords) / 50 - (coords + DoRotation(skeleton.joints[skeleton.jointlabels[righthand]].position, 0, yaw, 0) * scale);
+                        aim = victim->coords + DoRotation(victim->jointPos(abdomen), 0, victim->yaw, 0) * victim->scale + victim->velocity * findDistance(&victim->coords, &coords) / 50 - (coords + DoRotation(jointPos(righthand), 0, yaw, 0) * scale);
                         Normalise(&aim);
                         /*if(victim->animTarget==jumpupanim||victim->animTarget==jumpdownanim){
                         aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
@@ -2636,7 +2724,7 @@ void      Person::DoAnimations()
                             if (tutoriallevel != 1) {
                                 emit_sound_at(knifeslicesound, victim->coords);
                             }
-                            //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
+                            //victim->jointVel(abdomen)+=relative*damagemult*200;
                             if (animation[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
                                 if (victim->id != 0 || difficulty == 2) {
                                     victim->frameTarget = 0;
@@ -2659,10 +2747,10 @@ void    Person::DoAnimations()
                             XYZ footvel, footpoint;
                             footvel = 0;
                             if (skeleton.free) {
-                                footpoint = (victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position + victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position) / 2 * victim->scale + victim->coords;
+                                footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
                             }
                             if (!skeleton.free) {
-                                footpoint = DoRotation((victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position + victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
+                                footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
                             }
                             if (tutoriallevel != 1) {
                                 if (bloodtoggle)
@@ -2693,7 +2781,7 @@ void      Person::DoAnimations()
                                 victim->deathbleeding = 1;
                                 emit_sound_at(swordslicesound, victim->coords);
                             }
-                            //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
+                            //victim->jointVel(abdomen)+=relative*damagemult*200;
                             if (tutoriallevel != 1) {
                                 victim->frameTarget = 0;
                                 victim->animTarget = staggerbackhardanim;
@@ -2715,10 +2803,10 @@ void    Person::DoAnimations()
                                 XYZ footvel, footpoint;
                                 footvel = 0;
                                 if (skeleton.free) {
-                                    footpoint = (victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position + victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position) / 2 * victim->scale + victim->coords;
+                                    footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
                                 }
                                 if (!skeleton.free) {
-                                    footpoint = DoRotation((victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position + victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
+                                    footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
                                 }
                                 if (bloodtoggle)
                                     Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
@@ -2768,8 +2856,8 @@ void      Person::DoAnimations()
                                     victim->weaponstuck = 0;
                             }
                             victim->weaponactive = -1;
-                            for (i = 0; i < numplayers; i++) {
-                                player[i].wentforweapon = 0;
+                            for (unsigned i = 0; i < Person::players.size(); i++) {
+                                Person::players[i]->wentforweapon = 0;
                             }
 
                         }
@@ -2796,11 +2884,11 @@ void    Person::DoAnimations()
                         relative = DoRotation(relative, 0, 90, 0);
                         relative.y -= 1;
                         Normalise(&relative);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity += relative * damagemult * 60;
                         }
-                        victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 230;
-                        victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity += relative * damagemult * 230;
+                        victim->jointVel(head) += relative * damagemult * 230;
+                        victim->jointVel(neck) += relative * damagemult * 230;
                         //FootLand(1,2);
                         victim->Puff(head);
                         if (tutoriallevel != 1) {
@@ -2829,11 +2917,11 @@ void    Person::DoAnimations()
                         relative.y = 0;
                         Normalise(&relative);
                         relative = DoRotation(relative, 0, -90, 0);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity += relative * damagemult * 40;
                         }
-                        victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 220;
-                        victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity += relative * damagemult * 220;
+                        victim->jointVel(head) += relative * damagemult * 220;
+                        victim->jointVel(neck) += relative * damagemult * 220;
                         //FootLand(1,2);
                         victim->Puff(head);
                         if (tutoriallevel != 1) {
@@ -2861,7 +2949,7 @@ void      Person::DoAnimations()
                         victim->skeleton.free = 1;
                         victim->skeleton.broken = 0;
 
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velchange = 0;
                             victim->skeleton.joints[i].locked = 0;
                             //victim->skeleton.joints[i].velocity=0;
@@ -2877,18 +2965,18 @@ void    Person::DoAnimations()
                         relative.y = -1;
                         Normalise(&relative);
                         if (!victim->dead) {
-                            for (i = 0; i < victim->skeleton.num_joints; i++) {
+                            for (int i = 0; i < victim->skeleton.num_joints; i++) {
                                 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
                             }
                             //FootLand(1,2);
-                            victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 40;
+                            victim->jointVel(abdomen) += relative * damagemult * 40;
                         }
                         if (victim->dead) {
-                            for (i = 0; i < victim->skeleton.num_joints; i++) {
+                            for (int i = 0; i < victim->skeleton.num_joints; i++) {
                                 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
                             }
                             //FootLand(1,2);
-                            //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
+                            //victim->jointVel(abdomen)+=relative*damagemult*20;
                         }
                         victim->Puff(abdomen);
                         if (tutoriallevel != 1) {
@@ -2919,10 +3007,10 @@ void    Person::DoAnimations()
                                 DoBlood(.2, 250);
                             }
                             victim->RagDoll(0);
-                            for (i = 0; i < victim->skeleton.num_joints; i++) {
+                            for (int i = 0; i < victim->skeleton.num_joints; i++) {
                                 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
                             }
-                            victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
+                            victim->jointVel(head) += relative * damagemult * 200;
                             if (tutoriallevel != 1) {
                                 emit_sound_at(heavyimpactsound, victim->coords, 128.);
                             }
@@ -2938,10 +3026,10 @@ void    Person::DoAnimations()
                         } else {
                             if (victim->damage >= victim->damagetolerance)
                                 victim->RagDoll(0);
-                            for (i = 0; i < victim->skeleton.num_joints; i++) {
+                            for (int i = 0; i < victim->skeleton.num_joints; i++) {
                                 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
                             }
-                            victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
+                            victim->jointVel(abdomen) += relative * damagemult * 200;
                             victim->frameTarget = 0;
                             victim->animTarget = staggerbackhighanim;
                             victim->targetyaw = targetyaw + 180;
@@ -2962,7 +3050,9 @@ void      Person::DoAnimations()
                 }
 
                 if (animTarget == sweepanim && animation[animTarget].label[frameCurrent] == 5) {
-                    if (victim->animTarget != jumpupanim && distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim != this) {
+                    if ((victim->animTarget != jumpupanim) &&
+                        (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) &&
+                        (victim != this->shared_from_this())) {
                         escapednum = 0;
                         if (id == 0)
                             camerashake += .2;
@@ -2977,12 +3067,12 @@ void    Person::DoAnimations()
                         if (animation[victim->animTarget].height == middleheight || animation[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
                             victim->RagDoll(0);
 
-                            for (i = 0; i < victim->skeleton.num_joints; i++) {
+                            for (int i = 0; i < victim->skeleton.num_joints; i++) {
                                 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
                             }
                             relative = DoRotation(relative, 0, -90, 0);
                             relative.y += .1;
-                            for (i = 0; i < victim->skeleton.num_joints; i++) {
+                            for (int i = 0; i < victim->skeleton.num_joints; i++) {
                                 if (victim->skeleton.joints[i].label == leftfoot || victim->skeleton.joints[i].label == rightfoot || victim->skeleton.joints[i].label == leftankle || victim->skeleton.joints[i].label == rightankle)
                                     victim->skeleton.joints[i].velocity = relative * 80;
                             }
@@ -2992,15 +3082,15 @@ void    Person::DoAnimations()
                         } else {
                             if (victim->damage >= victim->damagetolerance)
                                 victim->RagDoll(0);
-                            for (i = 0; i < victim->skeleton.num_joints; i++) {
+                            for (int i = 0; i < victim->skeleton.num_joints; i++) {
                                 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
                             }
                             relative = DoRotation(relative, 0, -90, 0);
-                            for (i = 0; i < victim->skeleton.num_joints; i++) {
+                            for (int i = 0; i < victim->skeleton.num_joints; i++) {
                                 if (victim->skeleton.joints[i].label == leftfoot || victim->skeleton.joints[i].label == rightfoot || victim->skeleton.joints[i].label == leftankle || victim->skeleton.joints[i].label == rightankle)
                                     victim->skeleton.joints[i].velocity += relative * damagemult * 80;
                             }
-                            victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
+                            victim->jointVel(abdomen) += relative * damagemult * 200;
                             victim->frameTarget = 0;
                             victim->animTarget = staggerbackhighanim;
                             victim->targetyaw = targetyaw + 180;
@@ -3040,10 +3130,10 @@ void    Person::DoAnimations()
                     relative.y = 0;
                     Normalise(&relative);
                     //relative=DoRotation(relative,0,-90,0);
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity += relative * damagemult * 40;
                     }
-                    victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
+                    victim->jointVel(abdomen) += relative * damagemult * 200;
                     //FootLand(1,2);
                     victim->Puff(abdomen);
                     victim->DoDamage(damagemult * 150 / victim->protectionhigh);
@@ -3053,7 +3143,7 @@ void      Person::DoAnimations()
 
                 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && animation[animTarget].label[frameCurrent] == 5) {
                     if (victim->weaponactive != -1 && victim->num_weapons > 0) {
-                        if (weapons[victim->weaponids[victim->weaponactive]].owner == victim->id) {
+                        if (weapons[victim->weaponids[victim->weaponactive]].owner == int(victim->id)) {
                             weapons[victim->weaponids[victim->weaponactive]].owner = id;
                             weaponactive = 0;
                             if (num_weapons > 0) {
@@ -3086,10 +3176,10 @@ void    Person::DoAnimations()
                     relative.y = 0;
                     Normalise(&relative);
                     //relative=DoRotation(relative,0,-90,0);
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity += relative * damagemult * 30;
                     }
-                    victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
+                    victim->jointVel(abdomen) += relative * damagemult * 200;
                     //FootLand(1,2);
                     victim->Puff(head);
                     victim->DoDamage(damagemult * 70 / victim->protectionhigh);
@@ -3117,10 +3207,10 @@ void    Person::DoAnimations()
                     relative.y = 0;
                     Normalise(&relative);
                     //relative=DoRotation(relative,0,-90,0);
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity += relative * damagemult * 30;
                     }
-                    victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
+                    victim->jointVel(abdomen) += relative * damagemult * 200;
                     //FootLand(1,2);
                     victim->Puff(head);
                     victim->DoDamage(damagemult * 70 / victim->protectionhigh);
@@ -3135,17 +3225,17 @@ void    Person::DoAnimations()
                     Normalise(&relative);
                     //relative*=-1;
                     relative.y -= .1;
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity += relative * damagemult * 70;
                     }
-                    victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity *= .1;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity *= .2;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity *= .5;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity *= .7;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity *= .1;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity *= .2;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity *= .5;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity *= .7;
+                    victim->jointVel(lefthand) *= .1;
+                    victim->jointVel(leftwrist) *= .2;
+                    victim->jointVel(leftelbow) *= .5;
+                    victim->jointVel(leftshoulder) *= .7;
+                    victim->jointVel(righthand) *= .1;
+                    victim->jointVel(rightwrist) *= .2;
+                    victim->jointVel(rightelbow) *= .5;
+                    victim->jointVel(rightshoulder) *= .7;
 
                     victim->Puff(abdomen);
                     victim->DoDamage(damagemult * 90 / victim->protectionhigh);
@@ -3187,17 +3277,17 @@ void    Person::DoAnimations()
                     Normalise(&relative);
                     //relative*=-1;
                     relative.y -= .1;
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity += relative * damagemult * 70;
                     }
-                    victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity *= .1 - 1;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity *= .2 - 1;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity *= .5 - 1;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity *= .7 - 1;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity *= .1 - 1;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity *= .2 - 1;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity *= .5 - 1;
-                    victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity *= .7 - 1;
+                    victim->jointVel(lefthand) *= .1 - 1;
+                    victim->jointVel(leftwrist) *= .2 - 1;
+                    victim->jointVel(leftelbow) *= .5 - 1;
+                    victim->jointVel(leftshoulder) *= .7 - 1;
+                    victim->jointVel(righthand) *= .1 - 1;
+                    victim->jointVel(rightwrist) *= .2 - 1;
+                    victim->jointVel(rightelbow) *= .5 - 1;
+                    victim->jointVel(rightshoulder) *= .7 - 1;
 
                     award_bonus(id, swordreversebonus);
                 }
@@ -3219,10 +3309,10 @@ void    Person::DoAnimations()
                     relative.y = 0;
                     Normalise(&relative);
                     relative = DoRotation(relative, 0, -90, 0);
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity += relative * damagemult * 40;
                     }
-                    victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
+                    victim->jointVel(abdomen) += relative * damagemult * 200;
                     //FootLand(1,2);
                     victim->Puff(abdomen);
                     victim->DoDamage(damagemult * 30 / victim->protectionhigh);
@@ -3240,7 +3330,7 @@ void      Person::DoAnimations()
                     Normalise(&relative);
                     if (victim->id == 0)
                         relative /= 30;
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity += relative * damagemult * 40;
                     }
                     //victim->DoDamage(1000);
@@ -3283,7 +3373,7 @@ void      Person::DoAnimations()
                             bloodvel.z=20;
                             bloodvel.y=5;
                             bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
-                            Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
+                            Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck),0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
                             */
                             XYZ footvel, footpoint;
                             footvel = 0;
@@ -3324,12 +3414,12 @@ void    Person::DoAnimations()
                 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 6) {
                     escapednum = 0;
                     victim->velocity = 0;
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity = 0;
                     }
                     if (animTarget == knifefollowanim) {
                         victim->RagDoll(0);
-                        for (i = 0; i < victim->skeleton.num_joints; i++) {
+                        for (int i = 0; i < victim->skeleton.num_joints; i++) {
                             victim->skeleton.joints[i].velocity = 0;
                         }
                     }
@@ -3382,7 +3472,7 @@ void      Person::DoAnimations()
                 if (hasvictim && animTarget == swordsneakattackanim && animation[animTarget].label[frameCurrent] == 6) {
                     escapednum = 0;
                     victim->velocity = 0;
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity = 0;
                     }
                     if (weaponactive != -1) {
@@ -3451,10 +3541,10 @@ void    Person::DoAnimations()
                     relative = DoRotation(relative, 0, 90, 0);
                     relative.y = .5;
                     Normalise(&relative);
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity += relative * damagemult * 20;
                     }
-                    victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
+                    victim->jointVel(head) += relative * damagemult * 200;
                     if (victim->damage < victim->damagetolerance - 100)
                         victim->velocity = relative * 200;
                     victim->DoDamage(damagemult * 100 / victim->protectionhead);
@@ -3472,10 +3562,10 @@ void    Person::DoAnimations()
                     relative = DoRotation(relative, 0, 90, 0);
                     relative.y = .5;
                     Normalise(&relative);
-                    for (i = 0; i < victim->skeleton.num_joints; i++) {
+                    for (int i = 0; i < victim->skeleton.num_joints; i++) {
                         victim->skeleton.joints[i].velocity += relative * damagemult * 20;
                     }
-                    victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
+                    victim->jointVel(head) += relative * damagemult * 200;
                 }
 
                 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim))
@@ -3585,10 +3675,10 @@ void    Person::DoAnimations()
                         int closest = -1;
                         float closestdist = -1;
                         float distance;
-                        if (numplayers > 1)
-                            for (i = 0; i < numplayers; i++) {
-                                if (id != i && player[i].coords.y < coords.y && !player[i].skeleton.free) {
-                                    distance = distsq(&player[i].coords, &coords);
+                        if (Person::players.size() > 1)
+                            for (unsigned i = 0; i < Person::players.size(); i++) {
+                                if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
+                                    distance = distsq(&Person::players[i]->coords, &coords);
                                     if (closestdist == -1 || distance < closestdist) {
                                         closestdist = distance;
                                         closest = i;
@@ -3596,7 +3686,7 @@ void      Person::DoAnimations()
                                 }
                             }
                         if (closestdist > 0 && closest >= 0 && closestdist < 16) {
-                            victim = &player[closest];
+                            victim = Person::players[closest];
                             animTarget = walljumprightkickanim;
                             frameTarget = 0;
                             XYZ rotatetarget = victim->coords - coords;
@@ -3643,10 +3733,10 @@ void    Person::DoAnimations()
                         int closest = -1;
                         float closestdist = -1;
                         float distance;
-                        if (numplayers > 1)
-                            for (i = 0; i < numplayers; i++) {
-                                if (id != i && player[i].coords.y < coords.y && !player[i].skeleton.free) {
-                                    distance = distsq(&player[i].coords, &coords);
+                        if (Person::players.size() > 1)
+                            for (unsigned i = 0; i < Person::players.size(); i++) {
+                                if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
+                                    distance = distsq(&Person::players[i]->coords, &coords);
                                     if (closestdist == -1 || distance < closestdist) {
                                         closestdist = distance;
                                         closest = i;
@@ -3654,7 +3744,7 @@ void      Person::DoAnimations()
                                 }
                             }
                         if (closestdist > 0 && closest >= 0 && closestdist < 16) {
-                            victim = &player[closest];
+                            victim = Person::players[closest];
                             animTarget = walljumpleftkickanim;
                             frameTarget = 0;
                             XYZ rotatetarget = victim->coords - coords;
@@ -3772,7 +3862,7 @@ void      Person::DoAnimations()
                         animTarget = rollanim;
                         frameTarget = 5;
                         oldcoords = coords;
-                        coords += (DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) + DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0)) / 2 * scale;
+                        coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
                         coords.y = oldcoords.y;
                     }
                     if (animCurrent == knifeslashreversedanim) {
@@ -3781,7 +3871,7 @@ void      Person::DoAnimations()
                         targetyaw += 90;
                         yaw += 90;
                         oldcoords = coords;
-                        coords += (DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) + DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0)) / 2 * scale;
+                        coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
                         coords.y = oldcoords.y;
                     }
                 }
@@ -3795,7 +3885,7 @@ void      Person::DoAnimations()
                 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
                     animTarget = getIdle();
                     oldcoords = coords;
-                    coords += (DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) + DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0)) / 2 * scale;
+                    coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
                     coords.y = oldcoords.y;
                     //coords+=DoRotation(animation[animCurrent].offset,0,yaw,0)*scale;
                     targetoffset.y = coords.y;
@@ -3940,18 +4030,18 @@ void    Person::DoAnimations()
             }
             if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
                 //Old rotates
-                for (i = 0; i < skeleton.num_joints; i++) {
+                for (int i = 0; i < skeleton.num_joints; i++) {
                     skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent];
                 }
 
                 skeleton.FindForwards();
 
-                for (i = 0; i < skeleton.num_muscles; i++) {
+                for (int i = 0; i < skeleton.num_muscles; i++) {
                     if (skeleton.muscles[i].visible) {
                         skeleton.FindRotationMuscle(i, animTarget);
                     }
                 }
-                for (i = 0; i < skeleton.num_muscles; i++) {
+                for (int i = 0; i < skeleton.num_muscles; i++) {
                     if (skeleton.muscles[i].visible) {
                         if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
                             skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
@@ -3963,18 +4053,18 @@ void    Person::DoAnimations()
                 }
 
                 //New rotates
-                for (i = 0; i < skeleton.num_joints; i++) {
+                for (int i = 0; i < skeleton.num_joints; i++) {
                     skeleton.joints[i].position = animation[animTarget].position[i][frameTarget];
                 }
 
                 skeleton.FindForwards();
 
-                for (i = 0; i < skeleton.num_muscles; i++) {
+                for (int i = 0; i < skeleton.num_muscles; i++) {
                     if (skeleton.muscles[i].visible) {
                         skeleton.FindRotationMuscle(i, animTarget);
                     }
                 }
-                for (i = 0; i < skeleton.num_muscles; i++) {
+                for (int i = 0; i < skeleton.num_muscles; i++) {
                     if (skeleton.muscles[i].visible) {
                         if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
                             skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
@@ -3999,12 +4089,12 @@ void    Person::DoAnimations()
             oldframeTarget = frameTarget;
             oldframeCurrent = frameCurrent;
 
-            for (i = 0; i < skeleton.num_joints; i++) {
+            for (int i = 0; i < skeleton.num_joints; i++) {
                 skeleton.joints[i].velocity = (animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target) - skeleton.joints[i].position) / multiplier;
                 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target);
             }
             offset = currentoffset * (1 - target) + targetoffset * target;
-            for (i = 0; i < skeleton.num_muscles; i++) {
+            for (int i = 0; i < skeleton.num_muscles; i++) {
                 if (skeleton.muscles[i].visible) {
                     skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * (target);
                     skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * (target);
@@ -4026,7 +4116,11 @@ void     Person::DoAnimations()
     //skeleton.DoConstraints();
 }
 
-void   Person::DoStuff()
+/* EFFECT
+ * MONSTER
+ * TODO
+ */
+void Person::DoStuff()
 {
     static XYZ terrainnormal;
     static XYZ flatfacing;
@@ -4072,7 +4166,7 @@ void      Person::DoStuff()
     flamedelay -= multiplier;
     parriedrecently -= multiplier;
     if (!victim) {
-        victim = this;
+        victim = this->shared_from_this();
         hasvictim = 0;
     }
 
@@ -4091,7 +4185,7 @@ void      Person::DoStuff()
         superruntoggle = 0;
         if (aitype != passivetype) {
             superruntoggle = 1;
-            if (aitype == attacktypecutoff && (player[0].isIdle() || player[0].isCrouch() || player[0].skeleton.free || player[0].animTarget == getupfrombackanim || player[0].animTarget == getupfromfrontanim || player[0].animTarget == sneakanim) && distsq(&coords, &player[0].coords) < 16) {
+            if (aitype == attacktypecutoff && (Person::players[0]->isIdle() || Person::players[0]->isCrouch() || Person::players[0]->skeleton.free || Person::players[0]->animTarget == getupfrombackanim || Person::players[0]->animTarget == getupfromfrontanim || Person::players[0]->animTarget == sneakanim) && distsq(&coords, &Person::players[0]->coords) < 16) {
                 superruntoggle = 0;
             }
         }
@@ -4185,13 +4279,13 @@ void    Person::DoStuff()
                 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
             }
             if (skeleton.free)
-                bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
+                bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
             if (!skeleton.free)
                 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
             if (skeleton.free)
-                Sprite::MakeSprite(bloodsprite, (skeleton.joints[skeleton.jointlabels[neck]].position + (skeleton.joints[skeleton.jointlabels[neck]].position - skeleton.joints[skeleton.jointlabels[head]].position) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
+                Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
             if (!skeleton.free)
-                Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position + (skeleton.joints[skeleton.jointlabels[neck]].position - skeleton.joints[skeleton.jointlabels[head]].position) / 5, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
+                Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
             neckspurtparticledelay = .05;
         }
         if (neckspurtdelay < 0) {
@@ -4210,13 +4304,13 @@ void    Person::DoStuff()
             if (bloodtoggle) {
                 bloodvel = 0;
                 if (skeleton.free)
-                    bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
+                    bloodvel += DoRotation(jointVel(abdomen), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
                 if (!skeleton.free)
                     bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
                 if (skeleton.free)
-                    Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position * scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                    Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
                 if (!skeleton.free)
-                    Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[abdomen]].position + skeleton.joints[skeleton.jointlabels[abdomen]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                    Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
             }
         }
         bloodloss += deathbleeding * multiplier * 80;
@@ -4242,8 +4336,8 @@ void      Person::DoStuff()
                         weaponstuck = 0;
                 }
                 weaponactive = -1;
-                for (i = 0; i < numplayers; i++) {
-                    player[i].wentforweapon = 0;
+                for (unsigned i = 0; i < Person::players.size(); i++) {
+                    Person::players[i]->wentforweapon = 0;
                 }
 
                 if (id == 0) {
@@ -4260,7 +4354,7 @@ void      Person::DoStuff()
             }
             dead = 2;
             if (animTarget == knifefollowedanim && !skeleton.free) {
-                for (i = 0; i < skeleton.num_joints; i++) {
+                for (int i = 0; i < skeleton.num_joints; i++) {
                     skeleton.joints[i].velocity = 0;
                     skeleton.joints[i].velocity.y = -2;
                 }
@@ -4434,9 +4528,9 @@ void      Person::DoStuff()
                 if (skeleton.free)
                     footvel = skeleton.specialforward[0] * -1;
                 if (!skeleton.free)
-                    footpoint = DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0) * scale + coords;
+                    footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
                 if (skeleton.free)
-                    footpoint = ((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2) * scale + coords;
+                    footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
                 if (animTarget == sleepanim)
                     footvel = DoRotation(footvel, 0, 90, 0);
                 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
@@ -4668,8 +4762,8 @@ void      Person::DoStuff()
                     weaponstuck = 0;
             }
             weaponactive = -1;
-            for (i = 0; i < numplayers; i++) {
-                player[i].wentforweapon = 0;
+            for (unsigned i = 0; i < Person::players.size(); i++) {
+                Person::players[i]->wentforweapon = 0;
             }
         }
 
@@ -4710,7 +4804,7 @@ void      Person::DoStuff()
         dead = 0;
         skeleton.free = 1;
         damage -= 20;
-        for (i = 0; i < skeleton.num_joints; i++) {
+        for (int i = 0; i < skeleton.num_joints; i++) {
             skeleton.joints[i].velocity = 0;
         }
     }
@@ -4734,8 +4828,8 @@ void      Person::DoStuff()
                     weaponstuck = 0;
             }
             weaponactive = -1;
-            for (i = 0; i < numplayers; i++) {
-                player[i].wentforweapon = 0;
+            for (unsigned i = 0; i < Person::players.size(); i++) {
+                Person::players[i]->wentforweapon = 0;
             }
         }
 
@@ -4802,9 +4896,9 @@ void      Person::DoStuff()
         }
         average /= multiplier;
 
-        //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
+        //velocity=jointVel(groin)*scale;
         velocity = 0;
-        for (i = 0; i < skeleton.num_joints; i++) {
+        for (int i = 0; i < skeleton.num_joints; i++) {
             velocity += skeleton.joints[i].velocity * scale;
         }
         velocity /= skeleton.num_joints;
@@ -4825,7 +4919,7 @@ void      Person::DoStuff()
                 }
                 if (dead == 2 && bloodloss < damagetolerance) {
                     XYZ headpoint;
-                    headpoint = (skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2 * scale + coords;
+                    headpoint = (jointPos(head) + jointPos(neck)) / 2 * scale + coords;
                     DoBlood(1, 255);
                     if (bloodtoggle && !bled) {
                         terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
@@ -4843,7 +4937,7 @@ void      Person::DoStuff()
                 }
                 if (dead == 2 && bloodloss >= damagetolerance) {
                     XYZ headpoint;
-                    headpoint = (skeleton.joints[skeleton.jointlabels[abdomen]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2 * scale + coords;
+                    headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords;
                     if (bleeding <= 0)
                         DoBlood(1, 255);
                     if (bloodtoggle && !bled) {
@@ -4886,18 +4980,18 @@ void    Person::DoStuff()
                 XYZ middle;
                 middle = 0;
 
-                terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[abdomen]].position;
-                if (skeleton.joints[skeleton.jointlabels[groin]].locked && skeleton.joints[skeleton.jointlabels[abdomen]].locked) {
-                    terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[abdomen]].position;
-                    middle = (skeleton.joints[skeleton.jointlabels[groin]].position + skeleton.joints[skeleton.jointlabels[abdomen]].position) / 2;
+                terrainnormal = jointPos(groin) - jointPos(abdomen);
+                if (joint(groin).locked && joint(abdomen).locked) {
+                    terrainnormal = jointPos(groin) - jointPos(abdomen);
+                    middle = (jointPos(groin) + jointPos(abdomen)) / 2;
                 }
-                if (skeleton.joints[skeleton.jointlabels[abdomen]].locked && skeleton.joints[skeleton.jointlabels[neck]].locked) {
-                    terrainnormal = skeleton.joints[skeleton.jointlabels[abdomen]].position - skeleton.joints[skeleton.jointlabels[neck]].position;
-                    middle = (skeleton.joints[skeleton.jointlabels[neck]].position + skeleton.joints[skeleton.jointlabels[abdomen]].position) / 2;
+                if (joint(abdomen).locked && joint(neck).locked) {
+                    terrainnormal = jointPos(abdomen) - jointPos(neck);
+                    middle = (jointPos(neck) + jointPos(abdomen)) / 2;
                 }
-                if (skeleton.joints[skeleton.jointlabels[groin]].locked && skeleton.joints[skeleton.jointlabels[neck]].locked) {
-                    terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[neck]].position;
-                    middle = (skeleton.joints[skeleton.jointlabels[groin]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2;
+                if (joint(groin).locked && joint(neck).locked) {
+                    terrainnormal = jointPos(groin) - jointPos(neck);
+                    middle = (jointPos(groin) + jointPos(neck)) / 2;
                 }
                 Normalise(&terrainnormal);
 
@@ -4908,7 +5002,7 @@ void      Person::DoStuff()
                 yaw = targetyaw;
 
                 frameTarget = 0;
-                //     frameTarget=2;
+                // frameTarget=2;
                 animTarget = flipanim;
                 crouchtogglekeydown = 1;
                 target = 0;
@@ -4922,7 +5016,7 @@ void      Person::DoStuff()
 
                 //if(middle.y>0)targetoffset.y=middle.y+1;
 
-                for (i = 0; i < skeleton.num_joints; i++) {
+                for (int i = 0; i < skeleton.num_joints; i++) {
                     tempanimation.position[i][0] = skeleton.joints[i].position;
                     tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
                 }
@@ -4939,18 +5033,18 @@ void    Person::DoStuff()
                 XYZ middle;
                 middle = 0;
 
-                terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[abdomen]].position;
-                if (skeleton.joints[skeleton.jointlabels[groin]].locked && skeleton.joints[skeleton.jointlabels[abdomen]].locked) {
-                    terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[abdomen]].position;
-                    middle = (skeleton.joints[skeleton.jointlabels[groin]].position + skeleton.joints[skeleton.jointlabels[abdomen]].position) / 2;
+                terrainnormal = jointPos(groin) - jointPos(abdomen);
+                if (joint(groin).locked && joint(abdomen).locked) {
+                    terrainnormal = jointPos(groin) - jointPos(abdomen);
+                    middle = (jointPos(groin) + jointPos(abdomen)) / 2;
                 }
-                if (skeleton.joints[skeleton.jointlabels[abdomen]].locked && skeleton.joints[skeleton.jointlabels[neck]].locked) {
-                    terrainnormal = skeleton.joints[skeleton.jointlabels[abdomen]].position - skeleton.joints[skeleton.jointlabels[neck]].position;
-                    middle = (skeleton.joints[skeleton.jointlabels[neck]].position + skeleton.joints[skeleton.jointlabels[abdomen]].position) / 2;
+                if (joint(abdomen).locked && joint(neck).locked) {
+                    terrainnormal = jointPos(abdomen) - jointPos(neck);
+                    middle = (jointPos(neck) + jointPos(abdomen)) / 2;
                 }
-                if (skeleton.joints[skeleton.jointlabels[groin]].locked && skeleton.joints[skeleton.jointlabels[neck]].locked) {
-                    terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[neck]].position;
-                    middle = (skeleton.joints[skeleton.jointlabels[groin]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2;
+                if (joint(groin).locked && joint(neck).locked) {
+                    terrainnormal = jointPos(groin) - jointPos(neck);
+                    middle = (jointPos(groin) + jointPos(neck)) / 2;
                 }
                 Normalise(&terrainnormal);
 
@@ -5013,7 +5107,7 @@ void      Person::DoStuff()
                 if (middle.y > 0 && animTarget != rollanim)
                     targetoffset.y = middle.y + 1;
 
-                for (i = 0; i < skeleton.num_joints; i++) {
+                for (int i = 0; i < skeleton.num_joints; i++) {
                     tempanimation.position[i][0] = skeleton.joints[i].position;
                     tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
                 }
@@ -5219,7 +5313,7 @@ void      Person::DoStuff()
     if (!skeleton.free) {
         bool play;
         play = 0;
-        if ((stunned > 0 || surprised > 0) && numplayers > 2 && aitype != passivetype)
+        if ((stunned > 0 || surprised > 0) && Person::players.size() > 2 && aitype != passivetype)
             play = 1;
         if (hasvictim)
             if (aitype != passivetype && victim->skeleton.free && !victim->dead)
@@ -5369,7 +5463,9 @@ void      Person::DoStuff()
         bool behind;
         behind = 0;
         if (hasvictim) {
-            if (victim != this && !victim->dead && victim->aitype != passivetype && victim->aitype != searchtype && aitype != passivetype && aitype != searchtype && victim->id < numplayers && aitype != passivetype) {
+            if ((victim != this->shared_from_this()) && !victim->dead && (victim->aitype != passivetype) &&
+                (victim->aitype != searchtype) && (aitype != passivetype) &&
+                (aitype != searchtype) && (victim->id < Person::players.size()) && (aitype != passivetype)) {
                 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
             }
         }
@@ -5772,6 +5868,52 @@ void     Person::DoStuff()
     }
 }
 
+
+/* EFFECT
+ * inverse kinematics helper function
+ */
+void IKHelper(Person *p, float interp)
+{
+    XYZ point, newpoint, change, change2;
+    float heightleft, heightright;
+
+    // TODO: implement localToWorld and worldToLocal
+    //       but keep in mind it won't be the same math if player is ragdolled or something
+    //       - localToWorldStanding / worldToLocalStanding (or crouching or...?)
+    //       then comb through code for places where to use it
+
+    // point = localToWorld(jointPos(leftfoot))
+    point = DoRotation(p->jointPos(leftfoot), 0, p->yaw, 0) * p->scale + p->coords;
+    // adjust height of foot
+    heightleft = terrain.getHeight(point.x, point.z) + .04;
+    point.y = heightleft;
+    change = p->jointPos(leftankle) - p->jointPos(leftfoot);
+    change2 = p->jointPos(leftknee) - p->jointPos(leftfoot);
+    // jointPos(leftfoot) = interpolate(worldToLocal(point), jointPos(leftfoot), interp)
+    p->jointPos(leftfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(leftfoot) * (1 - interp);
+    // move ankle along with foot
+    p->jointPos(leftankle) = p->jointPos(leftfoot) + change;
+    // average knee pos between old and new pos
+    p->jointPos(leftknee) = (p->jointPos(leftfoot) + change2) / 2 + (p->jointPos(leftknee)) / 2;
+
+    // do same as above for right leg
+    point = DoRotation(p->jointPos(rightfoot), 0, p->yaw, 0) * p->scale + p->coords;
+    heightright = terrain.getHeight(point.x, point.z) + .04;
+    point.y = heightright;
+    change = p->jointPos(rightankle) - p->jointPos(rightfoot);
+    change2 = p->jointPos(rightknee) - p->jointPos(rightfoot);
+    p->jointPos(rightfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(rightfoot) * (1 - interp);
+    p->jointPos(rightankle) = p->jointPos(rightfoot) + change;
+    p->jointPos(rightknee) = (p->jointPos(rightfoot) + change2) / 2 + (p->jointPos(rightknee)) / 2;
+
+    // fix up skeleton now that we've moved body parts?
+    p->skeleton.DoConstraints(&p->coords, &p->scale);
+}
+
+/* EFFECT
+ * MONSTER
+ * TODO: ???
+ */
 int Person::DrawSkeleton()
 {
     int oldplayerdetail;
@@ -5832,134 +5974,31 @@ int Person::DrawSkeleton()
         static int start, endthing;
         if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
             if (!isSleeping() && !isSitting()) {
-                if (onterrain && ((isIdle() || isCrouch() || isLanding() || isLandhard() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim) && (wasIdle() || wasCrouch() || wasLanding() || wasLandhard() || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim)) && !skeleton.free) {
-                    XYZ point, newpoint, change, change2;
-                    point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
-                    heightleft = terrain.getHeight(point.x, point.z) + .04;
-                    point.y = heightleft;
-                    change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                    change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                    skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0);
-                    skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
-                    skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
-
-                    point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
-                    heightright = terrain.getHeight(point.x, point.z) + .04;
-                    point.y = heightright;
-                    change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                    change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                    skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0);
-                    skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
-                    skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
-                    skeleton.DoConstraints(&coords, &scale);
+                // TODO: give these meaningful names
+                const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard()
+                                    || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim);
+                const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard()
+                                    || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim);
 
-                    if (creature == wolftype) {
-                        point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
-                        heightleft = terrain.getHeight(point.x, point.z) + .04;
-                        point.y = heightleft;
-                        change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                        change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                        skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0);
-                        skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
-                        skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
-
-                        point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
-                        heightright = terrain.getHeight(point.x, point.z) + .04;
-                        point.y = heightright;
-                        change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                        change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                        skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0);
-                        skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
-                        skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
-                        skeleton.DoConstraints(&coords, &scale);
-                    }
-                }
-                if (onterrain && ((isIdle() || isCrouch() || isLanding() || isLandhard() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim) && !(wasIdle() || wasCrouch() || wasLanding() || wasLandhard() || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim)) && !skeleton.free) {
-                    XYZ point, newpoint, change, change2;
-                    point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
-                    heightleft = terrain.getHeight(point.x, point.z) + .04;
-                    point.y = heightleft;
-                    change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                    change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                    skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * target + skeleton.joints[skeleton.jointlabels[leftfoot]].position * (1 - target);
-                    skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
-                    skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
-
-                    point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
-                    heightright = terrain.getHeight(point.x, point.z) + .04;
-                    point.y = heightright;
-                    change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                    change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                    skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * target + skeleton.joints[skeleton.jointlabels[rightfoot]].position * (1 - target);
-                    skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
-                    skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
-                    skeleton.DoConstraints(&coords, &scale);
+                if (onterrain && (cond1 && cond2) && !skeleton.free) {
+                    IKHelper(this, 1);
+                    if (creature == wolftype)
+                        IKHelper(this, 1);
+                }
 
-                    if (creature == wolftype) {
-                        point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
-                        heightleft = terrain.getHeight(point.x, point.z) + .04;
-                        point.y = heightleft;
-                        change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                        change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                        skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * target + skeleton.joints[skeleton.jointlabels[leftfoot]].position * (1 - target);
-                        skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
-                        skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
-
-                        point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
-                        heightright = terrain.getHeight(point.x, point.z) + .04;
-                        point.y = heightright;
-                        change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                        change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                        skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * target + skeleton.joints[skeleton.jointlabels[rightfoot]].position * (1 - target);
-                        skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
-                        skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
-                        skeleton.DoConstraints(&coords, &scale);
-                    }
-                }
-
-                if (onterrain && (!(isIdle() || isCrouch() || isLanding() || isLandhard() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim) && (wasIdle() || wasCrouch() || wasLanding() || wasLandhard() || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim)) && !skeleton.free) {
-                    XYZ point, newpoint, change, change2;
-                    point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
-                    heightleft = terrain.getHeight(point.x, point.z) + .04;
-                    point.y = heightleft;
-                    change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                    change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                    skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * (1 - target) + skeleton.joints[skeleton.jointlabels[leftfoot]].position * target;
-                    skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
-                    skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
-
-                    point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
-                    heightright = terrain.getHeight(point.x, point.z) + .04;
-                    point.y = heightright;
-                    change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                    change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                    skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * (1 - target) + skeleton.joints[skeleton.jointlabels[rightfoot]].position * target;
-                    skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
-                    skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
-                    skeleton.DoConstraints(&coords, &scale);
+                if (onterrain && (cond1 && !cond2) && !skeleton.free) {
+                    IKHelper(this, target);
+                    if (creature == wolftype)
+                        IKHelper(this, target);
+                }
 
-                    if (creature == wolftype) {
-                        point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
-                        heightleft = terrain.getHeight(point.x, point.z) + .04;
-                        point.y = heightleft;
-                        change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                        change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
-                        skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * (1 - target) + skeleton.joints[skeleton.jointlabels[leftfoot]].position * target;
-                        skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
-                        skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
-
-                        point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
-                        heightright = terrain.getHeight(point.x, point.z) + .04;
-                        point.y = heightright;
-                        change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                        change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
-                        skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * (1 - target) + skeleton.joints[skeleton.jointlabels[rightfoot]].position * target;
-                        skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
-                        skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
-                        skeleton.DoConstraints(&coords, &scale);
-                    }
+                if (onterrain && (!cond1 && cond2) && !skeleton.free) {
+                    IKHelper(this, 1 - target);
+                    if (creature == wolftype)
+                        IKHelper(this, 1 - target);
                 }
             }
+
             if (!skeleton.free && (!animation[animTarget].attack && animTarget != getupfrombackanim && ((animTarget != rollanim && !isFlip()) || animation[animTarget].label[frameTarget] == 6) && animTarget != getupfromfrontanim && animTarget != wolfrunninganim && animTarget != rabbitrunninganim && animTarget != backhandspringanim && animTarget != walljumpfrontanim && animTarget != hurtidleanim && !isLandhard() && !isSleeping()))
                 DoHead();
             else {
@@ -5980,32 +6019,37 @@ int Person::DrawSkeleton()
                 skeleton.drawmodelclothes.vertex[i] = 0;
                 skeleton.drawmodelclothes.vertex[i].y = 999;
             }
-            for (i = 0; i < skeleton.num_muscles; i++) {
+            for (int i = 0; i < skeleton.num_muscles; i++) {
+                // convenience renames
+                const int p1 = skeleton.muscles[i].parent1->label;
+                const int p2 = skeleton.muscles[i].parent2->label;
+
                 if ((skeleton.muscles[i].numvertices > 0 && playerdetail) || (skeleton.muscles[i].numverticeslow > 0 && !playerdetail)) {
                     morphness = 0;
                     start = 0;
                     endthing = 0;
-                    if (skeleton.muscles[i].parent1->label == righthand || skeleton.muscles[i].parent2->label == righthand) {
+
+                    if (p1 == righthand || p2 == righthand) {
                         morphness = righthandmorphness;
                         start = righthandmorphstart;
                         endthing = righthandmorphend;
                     }
-                    if (skeleton.muscles[i].parent1->label == lefthand || skeleton.muscles[i].parent2->label == lefthand) {
+                    if (p1 == lefthand || p2 == lefthand) {
                         morphness = lefthandmorphness;
                         start = lefthandmorphstart;
                         endthing = lefthandmorphend;
                     }
-                    if (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head) {
+                    if (p1 == head || p2 == head) {
                         morphness = headmorphness;
                         start = headmorphstart;
                         endthing = headmorphend;
                     }
-                    if ((skeleton.muscles[i].parent1->label == neck && skeleton.muscles[i].parent2->label == abdomen) || (skeleton.muscles[i].parent2->label == neck && skeleton.muscles[i].parent1->label == abdomen)) {
+                    if ((p1 == neck && p2 == abdomen) || (p2 == neck && p1 == abdomen)) {
                         morphness = chestmorphness;
                         start = chestmorphstart;
                         endthing = chestmorphend;
                     }
-                    if ((skeleton.muscles[i].parent1->label == groin && skeleton.muscles[i].parent2->label == abdomen) || (skeleton.muscles[i].parent2->label == groin && skeleton.muscles[i].parent1->label == abdomen)) {
+                    if ((p1 == groin && p2 == abdomen) || (p2 == groin && p1 == abdomen)) {
                         morphness = tailmorphness;
                         start = tailmorphstart;
                         endthing = tailmorphend;
@@ -6013,7 +6057,7 @@ int Person::DrawSkeleton()
                     if (calcrot)
                         skeleton.FindRotationMuscle(i, animTarget);
                     mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
-                    glMatrixMode(GL_MODELVIEW);                                                        // Select The Modelview Matrix
+                    glMatrixMode(GL_MODELVIEW);
                     glPushMatrix();
                     glLoadIdentity();
                     if (!skeleton.free)
@@ -6035,24 +6079,26 @@ int Person::DrawSkeleton()
 
                     if (playerdetail || skeleton.free == 3) {
                         for (j = 0; j < skeleton.muscles[i].numvertices; j++) {
-                            glMatrixMode(GL_MODELVIEW);                                                        // Select The Modelview Matrix
+                            XYZ &v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
+                            XYZ &v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
+                            glMatrixMode(GL_MODELVIEW);
                             glPushMatrix();
-                            if (skeleton.muscles[i].parent1->label == abdomen || skeleton.muscles[i].parent2->label == abdomen)
-                                glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x * morphness)*proportionbody.x,
-                                             (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y * morphness)*proportionbody.y,
-                                             (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z * morphness)*proportionbody.z);
-                            if (skeleton.muscles[i].parent1->label == lefthand || skeleton.muscles[i].parent1->label == righthand || skeleton.muscles[i].parent1->label == leftwrist || skeleton.muscles[i].parent1->label == rightwrist || skeleton.muscles[i].parent1->label == leftelbow || skeleton.muscles[i].parent1->label == rightelbow || skeleton.muscles[i].parent2->label == leftelbow || skeleton.muscles[i].parent2->label == rightelbow)
-                                glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x * morphness)*proportionarms.x,
-                                             (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y * morphness)*proportionarms.y,
-                                             (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z * morphness)*proportionarms.z);
-                            if (skeleton.muscles[i].parent1->label == leftfoot || skeleton.muscles[i].parent1->label == rightfoot || skeleton.muscles[i].parent1->label == leftankle || skeleton.muscles[i].parent1->label == rightankle || skeleton.muscles[i].parent1->label == leftknee || skeleton.muscles[i].parent1->label == rightknee || skeleton.muscles[i].parent2->label == leftknee || skeleton.muscles[i].parent2->label == rightknee)
-                                glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x * morphness)*proportionlegs.x,
-                                             (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y * morphness)*proportionlegs.y,
-                                             (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z * morphness)*proportionlegs.z);
-                            if (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)
-                                glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x * morphness)*proportionhead.x,
-                                             (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y * morphness)*proportionhead.y,
-                                             (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z * morphness)*proportionhead.z);
+                            if (p1 == abdomen || p2 == abdomen)
+                                glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionbody.x,
+                                             (v0.y * (1 - morphness) + v1.y * morphness) * proportionbody.y,
+                                             (v0.z * (1 - morphness) + v1.z * morphness) * proportionbody.z);
+                            if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
+                                glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionarms.x,
+                                             (v0.y * (1 - morphness) + v1.y * morphness) * proportionarms.y,
+                                             (v0.z * (1 - morphness) + v1.z * morphness) * proportionarms.z);
+                            if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
+                                glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionlegs.x,
+                                             (v0.y * (1 - morphness) + v1.y * morphness) * proportionlegs.y,
+                                             (v0.z * (1 - morphness) + v1.z * morphness) * proportionlegs.z);
+                            if (p1 == head || p2 == head)
+                                glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionhead.x,
+                                             (v0.y * (1 - morphness) + v1.y * morphness) * proportionhead.y,
+                                             (v0.z * (1 - morphness) + v1.z * morphness) * proportionhead.z);
                             glGetFloatv(GL_MODELVIEW_MATRIX, M);
                             //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
                             //if(!isnormal(scale))test=1;
@@ -6065,24 +6111,25 @@ int Person::DrawSkeleton()
                     }
                     if (!playerdetail || skeleton.free == 3) {
                         for (j = 0; j < skeleton.muscles[i].numverticeslow; j++) {
-                            glMatrixMode(GL_MODELVIEW);                                                        // Select The Modelview Matrix
+                            XYZ &v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
+                            glMatrixMode(GL_MODELVIEW);
                             glPushMatrix();
-                            if (skeleton.muscles[i].parent1->label == abdomen || skeleton.muscles[i].parent2->label == abdomen)
-                                glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
-                                             (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
-                                             (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
-                            if (skeleton.muscles[i].parent1->label == lefthand || skeleton.muscles[i].parent1->label == righthand || skeleton.muscles[i].parent1->label == leftwrist || skeleton.muscles[i].parent1->label == rightwrist || skeleton.muscles[i].parent1->label == leftelbow || skeleton.muscles[i].parent1->label == rightelbow || skeleton.muscles[i].parent2->label == leftelbow || skeleton.muscles[i].parent2->label == rightelbow)
-                                glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
-                                             (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
-                                             (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
-                            if (skeleton.muscles[i].parent1->label == leftfoot || skeleton.muscles[i].parent1->label == rightfoot || skeleton.muscles[i].parent1->label == leftankle || skeleton.muscles[i].parent1->label == rightankle || skeleton.muscles[i].parent1->label == leftknee || skeleton.muscles[i].parent1->label == rightknee || skeleton.muscles[i].parent2->label == leftknee || skeleton.muscles[i].parent2->label == rightknee)
-                                glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
-                                             (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
-                                             (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
-                            if (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)
-                                glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
-                                             (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
-                                             (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
+                            if (p1 == abdomen || p2 == abdomen)
+                                glTranslatef(v0.x * proportionbody.x,
+                                             v0.y * proportionbody.y,
+                                             v0.z * proportionbody.z);
+                            if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
+                                glTranslatef(v0.x * proportionarms.x,
+                                             v0.y * proportionarms.y,
+                                             v0.z * proportionarms.z);
+                            if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
+                                glTranslatef(v0.x * proportionlegs.x,
+                                             v0.y * proportionlegs.y,
+                                             v0.z * proportionlegs.z);
+                            if (p1 == head || p2 == head)
+                                glTranslatef(v0.x * proportionhead.x,
+                                             v0.y * proportionhead.y,
+                                             v0.z * proportionhead.z);
 
                             glGetFloatv(GL_MODELVIEW_MATRIX, M);
                             skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
@@ -6096,7 +6143,7 @@ int Person::DrawSkeleton()
                 if (skeleton.clothes && skeleton.muscles[i].numverticesclothes > 0) {
                     mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
 
-                    glMatrixMode(GL_MODELVIEW);                                                        // Select The Modelview Matrix
+                    glMatrixMode(GL_MODELVIEW);
                     glPushMatrix();
                     glLoadIdentity();
                     if (!skeleton.free)
@@ -6114,24 +6161,25 @@ int Person::DrawSkeleton()
                     glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
 
                     for (j = 0; j < skeleton.muscles[i].numverticesclothes; j++) {
-                        glMatrixMode(GL_MODELVIEW);                                                    // Select The Modelview Matrix
+                        XYZ &v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
+                        glMatrixMode(GL_MODELVIEW);
                         glPushMatrix();
-                        if (skeleton.muscles[i].parent1->label == abdomen || skeleton.muscles[i].parent2->label == abdomen)
-                            glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
-                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
-                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
-                        if (skeleton.muscles[i].parent1->label == lefthand || skeleton.muscles[i].parent1->label == righthand || skeleton.muscles[i].parent1->label == leftwrist || skeleton.muscles[i].parent1->label == rightwrist || skeleton.muscles[i].parent1->label == leftelbow || skeleton.muscles[i].parent1->label == rightelbow || skeleton.muscles[i].parent2->label == leftelbow || skeleton.muscles[i].parent2->label == rightelbow)
-                            glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
-                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
-                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
-                        if (skeleton.muscles[i].parent1->label == leftfoot || skeleton.muscles[i].parent1->label == rightfoot || skeleton.muscles[i].parent1->label == leftankle || skeleton.muscles[i].parent1->label == rightankle || skeleton.muscles[i].parent1->label == leftknee || skeleton.muscles[i].parent1->label == rightknee || skeleton.muscles[i].parent2->label == leftknee || skeleton.muscles[i].parent2->label == rightknee)
-                            glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
-                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
-                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
-                        if (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)
-                            glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
-                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
-                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
+                        if (p1 == abdomen || p2 == abdomen)
+                            glTranslatef(v0.x * proportionbody.x,
+                                         v0.y * proportionbody.y,
+                                         v0.z * proportionbody.z);
+                        if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
+                            glTranslatef(v0.x * proportionarms.x,
+                                         v0.y * proportionarms.y,
+                                         v0.z * proportionarms.z);
+                        if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
+                            glTranslatef(v0.x * proportionlegs.x,
+                                         v0.y * proportionlegs.y,
+                                         v0.z * proportionlegs.z);
+                        if (p1 == head || p2 == head)
+                            glTranslatef(v0.x * proportionhead.x,
+                                         v0.y * proportionhead.y,
+                                         v0.z * proportionhead.z);
                         glGetFloatv(GL_MODELVIEW_MATRIX, M);
                         skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
                         skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
@@ -6172,7 +6220,7 @@ int Person::DrawSkeleton()
             updatedelaychange *= 8;
         updatedelay += updatedelaychange;
 
-        glMatrixMode(GL_MODELVIEW);                                                    // Select The Modelview Matrix
+        glMatrixMode(GL_MODELVIEW);
         glPushMatrix();
         if (!skeleton.free)
             glTranslatef(coords.x, coords.y - .02, coords.z);
@@ -6190,19 +6238,23 @@ int Person::DrawSkeleton()
             glBegin(GL_POINTS);
             if (playerdetail)
                 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
-                    glVertex3f(skeleton.drawmodel.vertex[i].x, skeleton.drawmodel.vertex[i].y, skeleton.drawmodel.vertex[i].z);
+                    XYZ &v0 = skeleton.drawmodel.vertex[i];
+                    glVertex3f(v0.x, v0.y, v0.z);
                 }
             glEnd();
             glBegin(GL_LINES);
 
             if (playerdetail)
                 for (i = 0; i < skeleton.drawmodel.TriangleNum; i++) {
-                    glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].z);
-                    glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].z);
-                    glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].z);
-                    glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].z);
-                    glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].z);
-                    glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].z);
+                    XYZ &v0 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]];
+                    XYZ &v1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]];
+                    XYZ &v2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]];
+                    glVertex3f(v0.x, v0.y, v0.z);
+                    glVertex3f(v1.x, v1.y, v1.z);
+                    glVertex3f(v1.x, v1.y, v1.z);
+                    glVertex3f(v2.x, v2.y, v2.z);
+                    glVertex3f(v2.x, v2.y, v2.z);
+                    glVertex3f(v0.x, v0.y, v0.z);
                 }
 
             glEnd();
@@ -6332,7 +6384,7 @@ int Person::DrawSkeleton()
                         }
                         weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
                         if (creature == wolftype)
-                            weaponpoint = (skeleton.joints[skeleton.jointlabels[rightwrist]].position * .7 + skeleton.joints[skeleton.jointlabels[righthand]].position * .3);
+                            weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3);
                     }
                     if (weapons[i].getType() == staff) {
                         for (j = 0; j < skeleton.num_muscles; j++) {
@@ -6345,25 +6397,25 @@ int Person::DrawSkeleton()
                                 weaponrotatemuscle = j;
                             }
                         }
-                        //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
+                        //weaponpoint=jointPos(rightwrist);
                         weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
-                        //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
+                        //weaponpoint+=skeleton.specialforward[1]*.1+(jointPos(rightwrist)-jointPos(rightelbow));
                         XYZ tempnormthing, vec1, vec2;
-                        vec1 = (skeleton.joints[skeleton.jointlabels[rightwrist]].position - skeleton.joints[skeleton.jointlabels[rightelbow]].position);
-                        vec2 = (skeleton.joints[skeleton.jointlabels[rightwrist]].position - skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
+                        vec1 = (jointPos(rightwrist) - jointPos(rightelbow));
+                        vec2 = (jointPos(rightwrist) - jointPos(rightshoulder));
                         CrossProduct(&vec1, &vec2, &tempnormthing);
                         Normalise(&tempnormthing);
                         if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim)
-                            weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (skeleton.joints[skeleton.jointlabels[rightwrist]].position - skeleton.joints[skeleton.jointlabels[rightelbow]].position);
+                            weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow));
                     }
                 }
                 if (weaponactive != k && weaponstuck != k) {
                     if (weapons[i].getType() == knife)
-                        weaponpoint = skeleton.joints[skeleton.jointlabels[abdomen]].position + (skeleton.joints[skeleton.jointlabels[righthip]].position - skeleton.joints[skeleton.jointlabels[lefthip]].position) * .1 + (skeleton.joints[skeleton.jointlabels[rightshoulder]].position - skeleton.joints[skeleton.jointlabels[leftshoulder]].position) * .35;
+                        weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35;
                     if (weapons[i].getType() == sword)
-                        weaponpoint = skeleton.joints[skeleton.jointlabels[abdomen]].position + (skeleton.joints[skeleton.jointlabels[lefthip]].position - skeleton.joints[skeleton.jointlabels[righthip]].position) * .09 + (skeleton.joints[skeleton.jointlabels[leftshoulder]].position - skeleton.joints[skeleton.jointlabels[rightshoulder]].position) * .33;
+                        weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
                     if (weapons[i].getType() == staff)
-                        weaponpoint = skeleton.joints[skeleton.jointlabels[abdomen]].position + (skeleton.joints[skeleton.jointlabels[lefthip]].position - skeleton.joints[skeleton.jointlabels[righthip]].position) * .09 + (skeleton.joints[skeleton.jointlabels[leftshoulder]].position - skeleton.joints[skeleton.jointlabels[rightshoulder]].position) * .33;
+                        weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
                     for (j = 0; j < skeleton.num_muscles; j++) {
                         if ((skeleton.muscles[j].parent1->label == abdomen || skeleton.muscles[j].parent2->label == abdomen) && (skeleton.muscles[j].parent1->label == neck || skeleton.muscles[j].parent2->label == neck) && skeleton.muscles[j].numvertices > 0) {
                             weaponrotatemuscle = j;
@@ -6372,9 +6424,9 @@ int Person::DrawSkeleton()
                 }
                 if (weaponstuck == k) {
                     if (weaponstuckwhere == 0)
-                        weaponpoint = skeleton.joints[skeleton.jointlabels[abdomen]].position * .5 + skeleton.joints[skeleton.jointlabels[neck]].position * .5 - skeleton.forward * .8;
+                        weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8;
                     else
-                        weaponpoint = skeleton.joints[skeleton.jointlabels[abdomen]].position * .5 + skeleton.joints[skeleton.jointlabels[neck]].position * .5 + skeleton.forward * .8;
+                        weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
                     for (j = 0; j < skeleton.num_muscles; j++) {
                         if ((skeleton.muscles[j].parent1->label == abdomen || skeleton.muscles[j].parent2->label == abdomen) && (skeleton.muscles[j].parent1->label == neck || skeleton.muscles[j].parent2->label == neck) && skeleton.muscles[j].numvertices > 0) {
                             weaponrotatemuscle = j;
@@ -6409,7 +6461,7 @@ int Person::DrawSkeleton()
                             XYZ temppoint1, temppoint2, tempforward;
                             float distance;
 
-                            temppoint1 = skeleton.joints[skeleton.jointlabels[righthand]].position;
+                            temppoint1 = jointPos(righthand);
                             temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
                             distance = findDistance(&temppoint1, &temppoint2);
                             weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
@@ -6428,7 +6480,7 @@ int Person::DrawSkeleton()
                             XYZ temppoint1, temppoint2, tempforward;
                             float distance;
 
-                            temppoint1 = skeleton.joints[skeleton.jointlabels[righthand]].position;
+                            temppoint1 = jointPos(righthand);
                             temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
                             distance = findDistance(&temppoint1, &temppoint2);
                             weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
@@ -6472,7 +6524,7 @@ int Person::DrawSkeleton()
                             XYZ temppoint1, temppoint2, tempforward;
                             float distance;
 
-                            temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
+                            temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
                             temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
                             distance = findDistance(&temppoint1, &temppoint2);
                             weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
@@ -6495,7 +6547,7 @@ int Person::DrawSkeleton()
                             XYZ temppoint1, temppoint2, tempforward;
                             float distance;
 
-                            temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
+                            temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
                             temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
                             distance = findDistance(&temppoint1, &temppoint2);
                             weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
@@ -6552,6 +6604,8 @@ int Person::DrawSkeleton()
 }
 
 
+/* FUNCTION?
+ */
 int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
 {
     static int i, j;
@@ -6583,16 +6637,16 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate,
                         intersecting = 1;
                     if (!intersecting)
                         intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
-                                                         &model->vertex[model->Triangles[j].vertex[1]],
-                                                         p1, &radius);
+                                                                &model->vertex[model->Triangles[j].vertex[1]],
+                                                                p1, &radius);
                     if (!intersecting)
                         intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
-                                                         &model->vertex[model->Triangles[j].vertex[2]],
-                                                         p1, &radius);
+                                                                &model->vertex[model->Triangles[j].vertex[2]],
+                                                                p1, &radius);
                     if (!intersecting)
                         intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
-                                                         &model->vertex[model->Triangles[j].vertex[2]],
-                                                         p1, &radius);
+                                                                &model->vertex[model->Triangles[j].vertex[2]],
+                                                                p1, &radius);
                     end = *p1 - point;
                     if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
                         start = *p1;
@@ -6646,23 +6700,25 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate,
                 intersecting = 0;
                 start = *p1;
                 start.y -= radius / 4;
-                distance = abs((model->facenormals[j].x * start.x) + (model->facenormals[j].y * start.y) + (model->facenormals[j].z * start.z) - ((model->facenormals[j].x * model->vertex[model->Triangles[j].vertex[0]].x) + (model->facenormals[j].y * model->vertex[model->Triangles[j].vertex[0]].y) + (model->facenormals[j].z * model->vertex[model->Triangles[j].vertex[0]].z)));
+                XYZ &v0 = model->vertex[model->Triangles[j].vertex[0]];
+                XYZ &v1 = model->vertex[model->Triangles[j].vertex[1]];
+                XYZ &v2 = model->vertex[model->Triangles[j].vertex[2]];
+                distance = abs((model->facenormals[j].x * start.x)
+                               + (model->facenormals[j].y * start.y)
+                               + (model->facenormals[j].z * start.z)
+                               - ((model->facenormals[j].x * v0.x)
+                                  + (model->facenormals[j].y * v0.y)
+                                  + (model->facenormals[j].z * v0.z)));
                 if (distance < radius * .5) {
                     point = start - model->facenormals[j] * distance;
-                    if (PointInTriangle( &point, model->facenormals[j], &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]]))
+                    if (PointInTriangle( &point, model->facenormals[j], &v0, &v1, &v2))
                         intersecting = 1;
                     if (!intersecting)
-                        intersecting = sphere_line_intersection(model->vertex[model->Triangles[j].vertex[0]].x, model->vertex[model->Triangles[j].vertex[0]].y, model->vertex[model->Triangles[j].vertex[0]].z,
-                                                         model->vertex[model->Triangles[j].vertex[1]].x, model->vertex[model->Triangles[j].vertex[1]].y, model->vertex[model->Triangles[j].vertex[1]].z,
-                                                         p1->x, p1->y, p1->z, radius / 2);
+                        intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
                     if (!intersecting)
-                        intersecting = sphere_line_intersection(model->vertex[model->Triangles[j].vertex[1]].x, model->vertex[model->Triangles[j].vertex[1]].y, model->vertex[model->Triangles[j].vertex[1]].z,
-                                                         model->vertex[model->Triangles[j].vertex[2]].x, model->vertex[model->Triangles[j].vertex[2]].y, model->vertex[model->Triangles[j].vertex[2]].z,
-                                                         p1->x, p1->y, p1->z, radius / 2);
+                        intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
                     if (!intersecting)
-                        intersecting = sphere_line_intersection(model->vertex[model->Triangles[j].vertex[0]].x, model->vertex[model->Triangles[j].vertex[0]].y, model->vertex[model->Triangles[j].vertex[0]].z,
-                                                         model->vertex[model->Triangles[j].vertex[2]].x, model->vertex[model->Triangles[j].vertex[2]].y, model->vertex[model->Triangles[j].vertex[2]].z,
-                                                         p1->x, p1->y, p1->z, radius / 2);
+                        intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
                     end = *p1 - point;
                     if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
                         if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
@@ -6690,3 +6746,4 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate,
     *p1 += *move;
     return firstintersecting;
 }
+