]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Person.cpp
Cleaned up some code in Person.cpp
[lugaru.git] / Source / Person.cpp
index 95e06b9b554d333a3562673063f8c752cc63ceb0..8bcf81e43f458aa76a694a8bab93c18e1efa2fc2 100644 (file)
@@ -1,5 +1,6 @@
 /*
 Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
 
 This file is part of Lugaru.
 
@@ -42,7 +43,6 @@ extern GLubyte bloodText[512 * 512 * 3];
 extern GLubyte wolfbloodText[512 * 512 * 3];
 extern int bloodtoggle;
 extern Objects objects;
-extern bool osx;
 extern bool autoslomo;
 extern float camerashake;
 extern float woozy;
@@ -160,14 +160,13 @@ void Person::CatchFire()
     int howmany;
     for (int i = 0; i < 10; i++) {
         howmany = abs(Random() % (skeleton.num_joints));
-        if (!skeleton.free)
-            flatvelocity = velocity;
-        if (skeleton.free)
+        if (skeleton.free) {
             flatvelocity = skeleton.joints[howmany].velocity;
-        if (!skeleton.free)
-            flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
-        if (skeleton.free)
             flatfacing = skeleton.joints[howmany].position * scale + coords;
+        } else {
+            flatvelocity = velocity;
+            flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
+        }
         Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
     }
 
@@ -316,22 +315,15 @@ void Person::DoBlood(float howmuch, int which)
             for (int i = 0; i < 3; i++) {
                 // emit blood particles
                 bloodvel = 0;
-                if (!skeleton.free) {
-                    bloodvel.z = 10;
-                    bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
-                }
                 if (skeleton.free) {
                     bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
-                }
-                if (skeleton.free)
                     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, 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) {
+                } else {
+                    bloodvel.z = 10;
+                    bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
+                    bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
                     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);
                 }
@@ -446,22 +438,15 @@ void Person::DoBloodBig(float howmuch, int which)
                 // emit blood particles
                 // FIXME: copypaste from above
                 bloodvel = 0;
-                if (!skeleton.free) {
-                    bloodvel.z = 10;
-                    bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
-                }
                 if (skeleton.free) {
                     bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
-                }
-                if (skeleton.free)
                     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, 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) {
+                } else {
+                    bloodvel.z = 10;
+                    bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
+                    bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
                     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);
                 }
@@ -694,22 +679,15 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
                     // emit blood particles
                     // FIXME: more copypaste code
                     bloodvel = 0;
-                    if (!skeleton.free) {
-                        bloodvel.z = 10;
-                        bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
-                    }
                     if (skeleton.free) {
                         bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
-                    }
-                    if (skeleton.free)
                         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, 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) {
+                    } else {
+                        bloodvel.z = 10;
+                        bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
+                        bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
                         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);
                     }
@@ -893,15 +871,10 @@ void Person::Reverse()
     if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
         if (victim->weaponactive != -1) {
             victim->throwtogglekeydown = 1;
-            weapons[victim->weaponids[0]].owner = -1;
-            weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
-            if (weapons[victim->weaponids[0]].velocity.x == 0)
-                weapons[victim->weaponids[0]].velocity.x = .1;
-            weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
-            weapons[victim->weaponids[0]].missed = 1;
-            weapons[victim->weaponids[0]].freetime = 0;
-            weapons[victim->weaponids[0]].firstfree = 1;
-            weapons[victim->weaponids[0]].physics = 1;
+            XYZ tempVelocity = victim->velocity * .2;
+            if (tempVelocity.x == 0)
+                tempVelocity.x = .1;
+            weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
             victim->num_weapons--;
             if (victim->num_weapons) {
                 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
@@ -923,15 +896,10 @@ void Person::Reverse()
     if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
         if (victim->weaponactive != -1) {
             victim->throwtogglekeydown = 1;
-            weapons[victim->weaponids[0]].owner = -1;
-            weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
-            if (weapons[victim->weaponids[0]].velocity.x == 0)
-                weapons[victim->weaponids[0]].velocity.x = .1;
-            weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
-            weapons[victim->weaponids[0]].missed = 1;
-            weapons[victim->weaponids[0]].freetime = 0;
-            weapons[victim->weaponids[0]].firstfree = 1;
-            weapons[victim->weaponids[0]].physics = 1;
+            XYZ tempVelocity = victim->velocity * .2;
+            if (tempVelocity.x == 0)
+                tempVelocity.x = .1;
+            weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
             victim->num_weapons--;
             if (victim->num_weapons) {
                 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
@@ -952,15 +920,10 @@ void Person::Reverse()
     if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
         if (victim->weaponactive != -1) {
             victim->throwtogglekeydown = 1;
-            weapons[victim->weaponids[0]].owner = -1;
-            weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
-            if (weapons[victim->weaponids[0]].velocity.x == 0)
-                weapons[victim->weaponids[0]].velocity.x = .1;
-            weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
-            weapons[victim->weaponids[0]].missed = 1;
-            weapons[victim->weaponids[0]].freetime = 0;
-            weapons[victim->weaponids[0]].firstfree = 1;
-            weapons[victim->weaponids[0]].physics = 1;
+            XYZ tempVelocity = victim->velocity * .2;
+            if (tempVelocity.x == 0)
+                tempVelocity.x = .1;
+            weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
             victim->num_weapons--;
             if (victim->num_weapons) {
                 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
@@ -981,15 +944,10 @@ void Person::Reverse()
     if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
         if (victim->weaponactive != -1) {
             victim->throwtogglekeydown = 1;
-            weapons[victim->weaponids[0]].owner = -1;
-            weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
-            if (weapons[victim->weaponids[0]].velocity.x == 0)
-                weapons[victim->weaponids[0]].velocity.x = .1;
-            weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
-            weapons[victim->weaponids[0]].missed = 1;
-            weapons[victim->weaponids[0]].freetime = 0;
-            weapons[victim->weaponids[0]].firstfree = 1;
-            weapons[victim->weaponids[0]].physics = 1;
+            XYZ tempVelocity = victim->velocity * .2;
+            if (tempVelocity.x == 0)
+                tempVelocity.x = .1;
+            weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
             victim->num_weapons--;
             if (victim->num_weapons) {
                 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
@@ -1064,16 +1022,9 @@ void Person::Reverse()
             victim->animTarget = staggerbackhighanim;
             victim->targetyaw = targetyaw + 180;
             victim->target = 0;
-            weapons[victim->weaponids[0]].owner = -1;
             aim = DoRotation(facing, 0, 90, 0) * 21;
             aim.y += 7;
-            weapons[victim->weaponids[0]].velocity = aim * -.2;
-            weapons[victim->weaponids[0]].tipvelocity = aim;
-            weapons[victim->weaponids[0]].missed = 1;
-            weapons[victim->weaponids[0]].hitsomething = 0;
-            weapons[victim->weaponids[0]].freetime = 0;
-            weapons[victim->weaponids[0]].firstfree = 1;
-            weapons[victim->weaponids[0]].physics = 1;
+            weapons[victim->weaponids[0]].drop(aim * -.2, aim);
             victim->num_weapons--;
             if (victim->num_weapons) {
                 victim->weaponids[0] = victim->weaponids[num_weapons];
@@ -1107,16 +1058,9 @@ void Person::Reverse()
             animTarget = staggerbackhighanim;
             targetyaw = targetyaw + 180;
             target = 0;
-            weapons[weaponids[0]].owner = -1;
             aim = DoRotation(facing, 0, 90, 0) * 21;
             aim.y += 7;
-            weapons[weaponids[0]].velocity = aim * -.2;
-            weapons[weaponids[0]].tipvelocity = aim;
-            weapons[weaponids[0]].hitsomething = 0;
-            weapons[weaponids[0]].missed = 1;
-            weapons[weaponids[0]].freetime = 0;
-            weapons[weaponids[0]].firstfree = 1;
-            weapons[weaponids[0]].physics = 1;
+            weapons[victim->weaponids[0]].drop(aim * -.2, aim);
             num_weapons--;
             if (num_weapons) {
                 weaponids[0] = weaponids[num_weapons];
@@ -1239,14 +1183,13 @@ void Person::DoDamage(float howmuch)
         XYZ flatvelocity2;
         XYZ flatfacing2;
         for (int i = 0; i < skeleton.num_joints; i++) {
-            if (!skeleton.free)
-                flatvelocity2 = velocity;
-            if (skeleton.free)
+            if (skeleton.free) {
                 flatvelocity2 = skeleton.joints[i].velocity;
-            if (!skeleton.free)
-                flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
-            if (skeleton.free)
                 flatfacing2 = skeleton.joints[i].position * scale + coords;
+            } else {
+                flatvelocity2 = velocity;
+                flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
+            }
             flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
             flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
             flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
@@ -1528,15 +1471,8 @@ void Person::RagDoll(bool checkcollision)
         // 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 = jointVel(righthand) * scale * -.3;
+                weapons[weaponids[0]].drop(jointVel(righthand) * scale * -.3, jointVel(righthand) * scale);
                 weapons[weaponids[0]].velocity.x += .01;
-                weapons[weaponids[0]].tipvelocity = jointVel(righthand) * scale;
-                weapons[weaponids[0]].missed = 1;
-                weapons[weaponids[0]].freetime = 0;
-                weapons[weaponids[0]].firstfree = 1;
-                weapons[weaponids[0]].physics = 1;
                 num_weapons--;
                 if (num_weapons) {
                     weaponids[0] = weaponids[num_weapons];
@@ -1898,13 +1834,7 @@ void Person::DoAnimations()
                                     emit_sound_at(knifedrawsound, coords, 128.);
                                 }
 
-                                weaponactive = 0;
-                                weapons[i].owner = id;
-                                if (num_weapons > 0) {
-                                    weaponids[num_weapons] = weaponids[0];
-                                }
-                                num_weapons++;
-                                weaponids[0] = i;
+                                takeWeapon(i);
                             }
                         }
                 }
@@ -1935,9 +1865,7 @@ void Person::DoAnimations()
                                         emit_sound_at(knifedrawsound, coords, 128.);
                                     }
                                 }
-                                weaponactive = 0;
                                 if (weapons[i].owner != -1) {
-
                                     victim = Person::players[weapons[i].owner];
                                     if (victim->num_weapons == 1)
                                         victim->num_weapons = 0;
@@ -1982,12 +1910,7 @@ void Person::DoAnimations()
                                     victim->jointVel(rightshoulder) += relative * 6;
                                     victim->jointVel(leftshoulder) += relative * 6;
                                 }
-                                weapons[i].owner = id;
-                                if (num_weapons > 0) {
-                                    weaponids[num_weapons] = weaponids[0];
-                                }
-                                num_weapons++;
-                                weaponids[0] = i;
+                                takeWeapon(i);
                             }
                         }
                 }
@@ -2666,16 +2589,9 @@ void Person::DoAnimations()
                     if (weaponactive != -1) {
                         escapednum = 0;
                         XYZ aim;
-                        weapons[weaponids[0]].owner = -1;
                         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);
-                        weapons[weaponids[0]].velocity = aim * 50;
-                        weapons[weaponids[0]].tipvelocity = aim * 50;
-                        weapons[weaponids[0]].missed = 0;
-                        weapons[weaponids[0]].hitsomething = 0;
-                        weapons[weaponids[0]].freetime = 0;
-                        weapons[weaponids[0]].firstfree = 1;
-                        weapons[weaponids[0]].physics = 0;
+                        weapons[weaponids[0]].thrown(aim * 50);
                         num_weapons--;
                         if (num_weapons) {
                             weaponids[0] = weaponids[num_weapons];
@@ -2719,8 +2635,7 @@ void Person::DoAnimations()
                             footvel = 0;
                             if (skeleton.free) {
                                 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
-                            }
-                            if (!skeleton.free) {
+                            } else {
                                 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
                             }
                             if (tutoriallevel != 1) {
@@ -2775,8 +2690,7 @@ void Person::DoAnimations()
                                 footvel = 0;
                                 if (skeleton.free) {
                                     footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
-                                }
-                                if (!skeleton.free) {
+                                } else {
                                     footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
                                 }
                                 if (bloodtoggle)
@@ -2810,16 +2724,9 @@ void Person::DoAnimations()
                             victim->animTarget = staggerbackhighanim;
                             victim->targetyaw = targetyaw + 180;
                             victim->target = 0;
-                            weapons[victim->weaponids[0]].owner = -1;
                             aim = DoRotation(facing, 0, 90, 0) * 21;
                             aim.y += 7;
-                            weapons[victim->weaponids[0]].velocity = aim * -.2;
-                            weapons[victim->weaponids[0]].tipvelocity = aim;
-                            weapons[victim->weaponids[0]].missed = 1;
-                            weapons[weaponids[0]].hitsomething = 0;
-                            weapons[victim->weaponids[0]].freetime = 0;
-                            weapons[victim->weaponids[0]].firstfree = 1;
-                            weapons[victim->weaponids[0]].physics = 1;
+                            weapons[victim->weaponids[0]].drop(aim * -.2, aim);
                             victim->num_weapons--;
                             if (victim->num_weapons) {
                                 victim->weaponids[0] = victim->weaponids[num_weapons];
@@ -3115,13 +3022,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 == int(victim->id)) {
-                            weapons[victim->weaponids[victim->weaponactive]].owner = id;
-                            weaponactive = 0;
-                            if (num_weapons > 0) {
-                                weaponids[num_weapons] = weaponids[victim->weaponactive];
-                            }
-                            num_weapons++;
-                            weaponids[0] = victim->weaponids[victim->weaponactive];
+                            takeWeapon(victim->weaponids[victim->weaponactive]);
                             victim->num_weapons--;
                             if (victim->num_weapons > 0) {
                                 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
@@ -4179,28 +4080,26 @@ void Person::DoStuff()
     while (flamedelay < 0 && onfire) {
         flamedelay += .006;
         howmany = abs(Random() % (skeleton.num_joints));
-        if (!skeleton.free)
-            flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
-        if (skeleton.free)
+        if (skeleton.free) {
             flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
-        if (!skeleton.free)
-            flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
-        if (skeleton.free)
             flatfacing = skeleton.joints[howmany].position * scale + coords;
+        } else {
+            flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
+            flatvelocity = (coords - oldcoords) / multiplier / 2;
+        }
         Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
     }
 
     while (flamedelay < 0 && !onfire && tutoriallevel == 1 && id != 0) {
         flamedelay += .05;
         howmany = abs(Random() % (skeleton.num_joints));
-        if (!skeleton.free)
-            flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
-        if (skeleton.free)
+        if (skeleton.free) {
             flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
-        if (!skeleton.free)
-            flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
-        if (skeleton.free)
             flatfacing = skeleton.joints[howmany].position * scale + coords;
+        } else {
+            flatvelocity = (coords - oldcoords) / multiplier / 2;
+            flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
+        }
         Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
     }
 
@@ -4208,7 +4107,7 @@ void Person::DoStuff()
         bleeding -= multiplier * .3;
         if (bloodtoggle == 2) {
             skeleton.drawmodel.textureptr.bind();
-            if (bleeding <= 0 && (detail != 2 || osx))
+            if ((bleeding <= 0) && (detail != 2))
                 DoMipmaps();
         }
     }
@@ -4220,21 +4119,16 @@ void Person::DoStuff()
         if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
             spurt = 0;
             bloodvel = 0;
-            if (!skeleton.free) {
-                bloodvel.z = 5 * neckspurtamount;
-                bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
-            }
             if (skeleton.free) {
                 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
-            }
-            if (skeleton.free)
                 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, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
-            if (!skeleton.free)
+            } else {
+                bloodvel.z = 5 * neckspurtamount;
+                bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
+                bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
                 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) {
@@ -4252,14 +4146,13 @@ void Person::DoStuff()
             XYZ bloodvel;
             if (bloodtoggle) {
                 bloodvel = 0;
-                if (skeleton.free)
+                if (skeleton.free) {
                     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, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
-                if (!skeleton.free)
+                } else {
+                    bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
                     Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
+                }
             }
         }
         bloodloss += deathbleeding * multiplier * 80;
@@ -4268,15 +4161,8 @@ void Person::DoStuff()
             deathbleeding = 0;
         if (bloodloss > damagetolerance && animation[animTarget].attack == neutral) {
             if (weaponactive != -1) {
-                weapons[weaponids[0]].owner = -1;
-                weapons[weaponids[0]].velocity = velocity * scale * -.3;
+                weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
                 weapons[weaponids[0]].velocity.x += .01;
-                weapons[weaponids[0]].tipvelocity = velocity * scale;
-                weapons[weaponids[0]].missed = 1;
-                weapons[weaponids[0]].hitsomething = 0;
-                weapons[weaponids[0]].freetime = 0;
-                weapons[weaponids[0]].firstfree = 1;
-                weapons[weaponids[0]].physics = 1;
                 num_weapons--;
                 if (num_weapons) {
                     weaponids[0] = weaponids[num_weapons];
@@ -4359,24 +4245,23 @@ void Person::DoStuff()
                 }
             }
         }
-        if (!osx && detail > 1) {
+        if (detail > 1) {
             skeleton.drawmodel.textureptr.bind();
             DoMipmaps();
         }
 
-        if (!skeleton.free) {
-            bleedy -= 4 / realtexdetail;
-            if (detail == 2)
-                bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
-            else
-                bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
-        }
         if (skeleton.free) {
             bleedx += 4 * direction / realtexdetail;
             if (detail == 2)
                 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
             else
                 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
+        } else {
+            bleedy -= 4 / realtexdetail;
+            if (detail == 2)
+                bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
+            else
+                bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
         }
     }
 
@@ -4471,14 +4356,13 @@ void Person::DoStuff()
             if (environment == snowyenvironment) {
                 XYZ footpoint;
                 XYZ footvel;
-                if (!skeleton.free)
-                    footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
-                if (skeleton.free)
+                if (skeleton.free) {
                     footvel = skeleton.specialforward[0] * -1;
-                if (!skeleton.free)
-                    footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
-                if (skeleton.free)
                     footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
+                } else {
+                    footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
+                    footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
+                }
                 if (animTarget == sleepanim)
                     footvel = DoRotation(footvel, 0, 90, 0);
                 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
@@ -4694,15 +4578,8 @@ void Person::DoStuff()
         RagDoll(0);
 
         if (weaponactive != -1) {
-            weapons[weaponids[0]].owner = -1;
-            weapons[weaponids[0]].velocity = velocity * scale * -.3;
+            weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
             weapons[weaponids[0]].velocity.x += .01;
-            weapons[weaponids[0]].tipvelocity = velocity * scale;
-            weapons[weaponids[0]].missed = 1;
-            weapons[weaponids[0]].hitsomething = 0;
-            weapons[weaponids[0]].freetime = 0;
-            weapons[weaponids[0]].firstfree = 1;
-            weapons[weaponids[0]].physics = 1;
             num_weapons--;
             if (num_weapons) {
                 weaponids[0] = weaponids[num_weapons];
@@ -4757,15 +4634,8 @@ void Person::DoStuff()
         DoBlood(1, 255);
 
         if (weaponactive != -1) {
-            weapons[weaponids[0]].owner = -1;
-            weapons[weaponids[0]].velocity = velocity * scale * -.3;
+            weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
             weapons[weaponids[0]].velocity.x += .01;
-            weapons[weaponids[0]].tipvelocity = velocity * scale;
-            weapons[weaponids[0]].missed = 1;
-            weapons[weaponids[0]].hitsomething = 0;
-            weapons[weaponids[0]].freetime = 0;
-            weapons[weaponids[0]].firstfree = 1;
-            weapons[weaponids[0]].physics = 1;
             num_weapons--;
             if (num_weapons) {
                 weaponids[0] = weaponids[num_weapons];
@@ -4841,7 +4711,6 @@ void Person::DoStuff()
         }
         average /= multiplier;
 
-        //velocity=jointVel(groin)*scale;
         velocity = 0;
         for (int i = 0; i < skeleton.num_joints; i++) {
             velocity += skeleton.joints[i].velocity * scale;
@@ -6144,14 +6013,11 @@ int Person::DrawSkeleton()
 
         glMatrixMode(GL_MODELVIEW);
         glPushMatrix();
-        if (!skeleton.free)
-            glTranslatef(coords.x, coords.y - .02, coords.z);
-        if (skeleton.free)
-            glTranslatef(coords.x, coords.y - .02, coords.z);
-        if (!skeleton.free)
+        glTranslatef(coords.x, coords.y - .02, coords.z);
+        if (!skeleton.free) {
             glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
-        if (!skeleton.free)
             glRotatef(yaw, 0, 1, 0);
+        }
         if (showpoints) {
             glPointSize(5);
             glColor4f(.4, 1, .4, 1);
@@ -6667,3 +6533,14 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate,
     return firstintersecting;
 }
 
+void Person::takeWeapon(int weaponId)
+{
+    weaponactive = 0;
+    weapons[weaponId].owner = id;
+    if (num_weapons > 0) {
+        weaponids[num_weapons] = weaponids[0];
+    }
+    num_weapons++;
+    weaponids[0] = weaponId;
+}
+