X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FObjects%2FPerson.cpp;h=8bd82698909fede4bdd2b22ccee6bb71b74e2bb8;hb=45cf5fc2505a098e6500e9ab2e8a0d003521db76;hp=6af3c02d32ff6b7cde2a0227b27f39296d6ec3ec;hpb=5dfd07829a5eecc87d100dd8825a81eafbaa86be;p=lugaru.git diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index 6af3c02..8bd8269 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -531,7 +531,7 @@ void Person::CatchFire() XYZ flatfacing, flatvelocity; int howmany; for (int i = 0; i < 10; i++) { - howmany = abs(Random() % (skeleton.joints.size())); + howmany = fabs(Random() % (skeleton.joints.size())); if (skeleton.free) { flatvelocity = skeleton.joints[howmany].velocity; flatfacing = skeleton.joints[howmany].position * scale + coords; @@ -1762,30 +1762,29 @@ void Person::RagDoll(bool checkcollision) change.y = (float)(Random() % 100) / 100; change.z = (float)(Random() % 100) / 100; skeleton.joints[i].velocity += change; - skeleton.joints[abs(Random() % skeleton.joints.size())].velocity -= change; + skeleton.joints[fabs(Random() % skeleton.joints.size())].velocity -= change; change.x = (float)(Random() % 100) / 100; change.y = (float)(Random() % 100) / 100; change.z = (float)(Random() % 100) / 100; skeleton.joints[i].velchange += change; - skeleton.joints[abs(Random() % skeleton.joints.size())].velchange -= change; + skeleton.joints[fabs(Random() % skeleton.joints.size())].velchange -= change; } if (checkcollision) { - XYZ average; XYZ lowpoint; XYZ colpoint; - int howmany; - average = 0; - howmany = 0; - for (unsigned j = 0; j < skeleton.joints.size(); j++) { - average += skeleton.joints[j].position; - howmany++; - } - average /= howmany; - coords += average * scale; - for (unsigned j = 0; j < skeleton.joints.size(); j++) { - skeleton.joints[j].position -= average; + if (!skeleton.joints.empty()) { + XYZ average; + average = 0; + for (unsigned j = 0; j < skeleton.joints.size(); j++) { + average += skeleton.joints[j].position; + } + average /= skeleton.joints.size(); + coords += average * scale; + for (unsigned j = 0; j < skeleton.joints.size(); j++) { + skeleton.joints[j].position -= average; + } } whichpatchx = coords.x / (terrain.size / subdivision * terrain.scale); @@ -4287,8 +4286,6 @@ void Person::DoStuff() static XYZ flatvelocity; static float flatvelspeed; static int i, l; - static XYZ average; - static int howmany; static int bloodsize; static int startx, starty, endx, endy; static GLubyte color; @@ -4387,7 +4384,7 @@ void Person::DoStuff() } while (flamedelay < 0 && onfire) { flamedelay += .006; - howmany = abs(Random() % (skeleton.joints.size())); + int howmany = fabs(Random() % (skeleton.joints.size())); if (skeleton.free) { flatvelocity = skeleton.joints[howmany].velocity * scale / 2; flatfacing = skeleton.joints[howmany].position * scale + coords; @@ -4400,7 +4397,7 @@ void Person::DoStuff() while (flamedelay < 0 && !onfire && tutoriallevel == 1 && id != 0) { flamedelay += .05; - howmany = abs(Random() % (skeleton.joints.size())); + int howmany = fabs(Random() % (skeleton.joints.size())); if (skeleton.free) { flatvelocity = skeleton.joints[howmany].velocity * scale / 2; flatfacing = skeleton.joints[howmany].position * scale + coords; @@ -5002,18 +4999,19 @@ void Person::DoStuff() award_bonus(id, deepimpact); DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3)); + XYZ average; average = 0; - howmany = 0; - for (unsigned j = 0; j < skeleton.joints.size(); j++) { - average += skeleton.joints[j].position; - howmany++; - } - average /= howmany; - coords += average * scale; - for (unsigned j = 0; j < skeleton.joints.size(); j++) { - skeleton.joints[j].position -= average; + if (!skeleton.joints.empty()) { + for (unsigned j = 0; j < skeleton.joints.size(); j++) { + average += skeleton.joints[j].position; + } + average /= skeleton.joints.size(); + coords += average * scale; + for (unsigned j = 0; j < skeleton.joints.size(); j++) { + skeleton.joints[j].position -= average; + } + average /= multiplier; } - average /= multiplier; velocity = 0; for (unsigned i = 0; i < skeleton.joints.size(); i++) { @@ -5316,7 +5314,7 @@ void Person::DoStuff() addEnvSound(coords, 4 * findLength(&velocity)); } - int howmany; + int howmany = 0; if (environment == grassyenvironment) howmany = findLength(&velocity) * 4; if (environment == snowyenvironment) @@ -5376,7 +5374,7 @@ void Person::DoStuff() addEnvSound(coords, 4 * findLength(&velocity)); } - int howmany; + int howmany = 0; if (environment == grassyenvironment) howmany = findLength(&velocity) * 4; if (environment == snowyenvironment)