2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 #include "Objects/Person.hpp"
23 #include "Animation/Animation.hpp"
24 #include "Audio/Sounds.hpp"
25 #include "Audio/openal_wrapper.hpp"
27 #include "Level/Awards.hpp"
28 #include "Level/Dialog.hpp"
29 #include "Tutorial.hpp"
30 #include "Utils/Folders.hpp"
32 extern float multiplier;
33 extern Terrain terrain;
35 extern int environment;
37 extern FRUSTUM frustum;
39 extern float realmultiplier;
41 extern float slomodelay;
42 extern bool cellophane;
43 extern float texdetail;
44 extern float realtexdetail;
45 extern int bloodtoggle;
46 extern bool autoslomo;
47 extern float camerashake;
49 extern float viewdistance;
50 extern float blackout;
51 extern int difficulty;
52 extern bool decalstoggle;
53 extern float fadestart;
55 extern bool winfreeze;
56 extern bool showpoints;
57 extern bool immediate;
58 extern float smoketex;
59 extern bool reversaltrain;
60 extern bool canattack;
62 extern float damagedealt;
64 extern float hostiletime;
66 extern bool gamestarted;
68 extern XYZ envsound[30];
69 extern float envsoundvol[30];
70 extern int numenvsounds;
71 extern float envsoundlife[30];
73 extern XYZ windvector;
75 std::vector<std::shared_ptr<Person>> Person::players(1, std::shared_ptr<Person>(new Person()));
80 , animCurrent(bounceidleanim)
81 , animTarget(bounceidleanim)
88 , howactive(typeactive)
90 , superruntoggle(false)
124 , rabbitkickenabled(false)
138 , superpermanentdamage(0)
181 , normalsupdatedelay(0)
185 , forwardkeydown(false)
186 , forwardstogglekeydown(false)
187 , rightkeydown(false)
191 , jumptogglekeydown(false)
192 , crouchkeydown(false)
193 , crouchtogglekeydown(false)
195 , drawtogglekeydown(false)
196 , throwkeydown(false)
197 , throwtogglekeydown(false)
198 , attackkeydown(false)
220 , whichdirection(false)
221 , whichdirectiondelay(0)
222 , avoidsomething(false)
232 , lefthandmorphness(0)
233 , righthandmorphness(0)
237 , targetlefthandmorphness(0)
238 , targetrighthandmorphness(0)
239 , targetheadmorphness(1)
240 , targetchestmorphness(0)
241 , targettailmorphness(0)
242 , lefthandmorphstart(0)
243 , lefthandmorphend(0)
244 , righthandmorphstart(0)
245 , righthandmorphend(0)
255 , highreversaldelay(0)
256 , lowreversaldelay(0)
305 , weaponstuckwhere(0)
318 , finalpathfindpoint(0)
319 , targetpathfindpoint(0)
320 , lastpathfindpoint(0)
321 , lastpathfindpoint2(0)
322 , lastpathfindpoint3(0)
323 , lastpathfindpoint4(0)
343 , neckspurtparticledelay(0)
348 , rabbitkickragdoll(false)
356 setProportions(1, 1, 1, 1);
359 /* Read a person in tfile. Throws an error if it’s not valid */
360 Person::Person(FILE* tfile, int mapvers, unsigned i)
364 funpackf(tfile, "Bi Bi Bf Bf Bf Bi", &whichskin, &creature, &coords.x, &coords.y, &coords.z, &num_weapons);
366 funpackf(tfile, "Bi", &howactive);
368 howactive = typeactive;
371 funpackf(tfile, "Bf", &scale);
376 funpackf(tfile, "Bb", &immobile);
381 funpackf(tfile, "Bf", &yaw);
386 if (num_weapons < 0 || num_weapons > 5) {
387 throw InvalidPersonException();
389 if (num_weapons > 0 && num_weapons < 5) {
390 for (int j = 0; j < num_weapons; j++) {
391 weaponids[j] = weapons.size();
393 funpackf(tfile, "Bi", &type);
394 weapons.push_back(Weapon(type, id));
397 funpackf(tfile, "Bi", &numwaypoints);
398 for (int j = 0; j < numwaypoints; j++) {
399 funpackf(tfile, "Bf", &waypoints[j].x);
400 funpackf(tfile, "Bf", &waypoints[j].y);
401 funpackf(tfile, "Bf", &waypoints[j].z);
403 funpackf(tfile, "Bi", &waypointtype[j]);
405 waypointtype[j] = wpkeepwalking;
409 funpackf(tfile, "Bi", &waypoint);
410 if (waypoint > (numwaypoints - 1)) {
414 funpackf(tfile, "Bf Bf Bf", &armorhead, &armorhigh, &armorlow);
415 funpackf(tfile, "Bf Bf Bf", &protectionhead, &protectionhigh, &protectionlow);
416 funpackf(tfile, "Bf Bf Bf", &metalhead, &metalhigh, &metallow);
417 funpackf(tfile, "Bf Bf", &power, &speedmult);
420 funpackf(tfile, "Bf Bf Bf Bf", &proportions[0], &proportions[1], &proportions[2], &proportions[3]);
422 setProportions(1, 1, 1, 1);
425 funpackf(tfile, "Bi", &numclothes);
426 for (int k = 0; k < numclothes; k++) {
428 funpackf(tfile, "Bi", &templength);
429 for (int l = 0; l < templength; l++) {
430 funpackf(tfile, "Bb", &clothes[k][l]);
432 clothes[k][templength] = '\0';
433 funpackf(tfile, "Bf Bf Bf", &clothestintr[k], &clothestintg[k], &clothestintb[k]);
438 if (creature == wolftype) {
439 damagetolerance = 300;
443 if (creature == wolftype) {
451 realoldcoords = coords;
454 void Person::skeletonLoad(bool clothes)
458 PersonType::types[creature].figureFileName,
459 PersonType::types[creature].lowFigureFileName,
460 PersonType::types[creature].clothesFileName,
461 PersonType::types[creature].modelFileNames[0],
462 PersonType::types[creature].modelFileNames[1],
463 PersonType::types[creature].modelFileNames[2],
464 PersonType::types[creature].modelFileNames[3],
465 PersonType::types[creature].modelFileNames[4],
466 PersonType::types[creature].modelFileNames[5],
467 PersonType::types[creature].modelFileNames[6],
468 PersonType::types[creature].lowModelFileName,
469 PersonType::types[creature].modelClothesFileName,
472 skeleton.drawmodel.textureptr.load(PersonType::types[creature].skins[whichskin], 1, &skeleton.skinText[0], &skeleton.skinsize);
475 void Person::setProportions(float head, float body, float arms, float legs)
477 proportions[0] = head;
478 proportions[1] = body;
479 proportions[2] = arms;
480 proportions[3] = legs;
483 XYZ Person::getProportion(int part) const
485 XYZ prop = PersonType::types[creature].proportions[part] * proportions[part];
495 * GameTick/doPlayerCollisions
497 void Person::CheckKick()
499 if (!(hasvictim && (animTarget == rabbitkickanim && victim && victim != this->shared_from_this() && frameCurrent >= 2 && animCurrent == rabbitkickanim) && distsq(&coords, &victim->coords) < 1.2 && !victim->skeleton.free)) {
503 if (Animation::animations[victim->animTarget].height != lowheight) {
504 float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
505 XYZ relative = velocity;
507 Normalise(&relative);
511 if (!Tutorial::active) {
512 emit_sound_at(heavyimpactsound, victim->coords);
515 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
516 victim->skeleton.joints[i].velocity += relative * 120 * damagemult;
519 victim->DoDamage(100 * damagemult / victim->protectionhigh);
526 animTarget = backflipanim;
528 velocity = facing * -10;
532 resume_stream(whooshsound);
535 award_bonus(id, cannon);
536 } else if (victim->isCrouch()) {
537 animTarget = rabbitkickreversedanim;
538 animCurrent = rabbitkickreversedanim;
539 victim->animCurrent = rabbitkickreversalanim;
540 victim->animTarget = rabbitkickreversalanim;
546 victim->oldcoords = victim->coords;
547 coords = victim->coords;
548 victim->targetyaw = targetyaw;
549 victim->victim = this->shared_from_this();
556 * GameTick::doPlayerCollisions - spread fire between players
557 * GameTick::ProcessDevKeys - press f to ignite
558 * Person::DoStuff - spread fire from lit campfires and bushes
560 void Person::CatchFire()
562 XYZ flatfacing, flatvelocity;
564 for (int i = 0; i < 10; i++) {
565 howmany = fabs(Random() % (skeleton.joints.size()));
567 flatvelocity = skeleton.joints[howmany].velocity;
568 flatfacing = skeleton.joints[howmany].position * scale + coords;
570 flatvelocity = velocity;
571 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
573 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
578 emit_sound_at(firestartsound, coords);
580 emit_stream_at(stream_firesound, coords);
588 * idle animation for this creature (depending on status)
590 int Person::getIdle()
592 if (Dialog::inDialog() && (howactive == typeactive) && PersonType::types[creature].hasAnimTalkIdle()) {
593 return PersonType::types[creature].animTalkIdle;
595 if (hasvictim && (victim != this->shared_from_this())) {
596 if ((!victim->dead && victim->aitype != passivetype &&
597 victim->aitype != searchtype && aitype != passivetype && aitype != searchtype &&
598 victim->id < Person::players.size())) {
599 if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) {
600 return PersonType::types[creature].animFightIdle;
602 if (aitype == playercontrolled && stunned <= 0 && weaponactive != -1) {
603 if (weapons[weaponids[weaponactive]].getType() == knife) {
604 return knifefightidleanim;
606 if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1) {
607 return swordfightidlebothanim;
609 if (weapons[weaponids[weaponactive]].getType() == sword) {
610 return swordfightidleanim;
612 if (weapons[weaponids[weaponactive]].getType() == staff) {
613 return swordfightidleanim;
616 if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause) {
617 return fightsidestep;
621 if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype) {
624 if (howactive == typesitting) {
627 if (howactive == typesittingwall) {
630 if (howactive == typesleeping) {
633 if (howactive == typedead1) {
636 if (howactive == typedead2) {
639 if (howactive == typedead3) {
642 if (howactive == typedead4) {
645 return PersonType::types[creature].animBounceIdle;
649 * crouch animation for this creature
651 int Person::getCrouch()
653 return PersonType::types[creature].animCrouch;
657 * running animation for this creature (can be upright or all fours)
661 if (superruntoggle && (weaponactive == -1)) {
662 return PersonType::types[creature].animRunning;
664 return PersonType::types[creature].animRun;
670 int Person::getStop()
672 return PersonType::types[creature].animStop;
677 int Person::getLanding()
679 return PersonType::types[creature].animLanding;
684 int Person::getLandhard()
686 return PersonType::types[creature].animLandingHard;
692 * Person::DoAnimations
695 SolidHitBonus(int playerid)
697 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo) {
698 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
700 award_bonus(playerid, solidhit);
705 * spawns blood effects
707 void Person::DoBlood(float howmuch, int which)
709 // FIXME: should abstract out inputs
710 static int bleedxint, bleedyint;
712 if (bloodtoggle && !Tutorial::active) {
713 if (bleeding <= 0 && spurt) {
715 for (int i = 0; i < 3; i++) {
716 // emit blood particles
719 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
720 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
721 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
722 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
725 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
726 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
727 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
728 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
731 if (Random() % 2 == 0) { // 50% chance
732 for (int i = 0; i < 3; i++) {
733 if (Random() % 2 != 0) {
734 // emit teeth particles
737 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
738 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
741 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
742 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
746 Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
748 Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
750 Sprite::setLastSpriteSpecial(3); // sets it to teeth
756 // FIXME: manipulating attributes
757 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
760 while (PersonType::types[creature].bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || PersonType::types[creature].bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
761 bleedxint = abs(Random() % 512);
762 bleedyint = abs(Random() % 512);
766 bleedy /= realtexdetail;
767 bleedx /= realtexdetail;
768 direction = abs(Random() % 2) * 2 - 1;
777 * spawns big blood effects and ???
778 * modifies character's skin texture
780 void Person::DoBloodBig(float howmuch, int which)
782 static int bleedxint, bleedyint, i, j;
784 if (howmuch && id == 0) {
788 if (!Tutorial::active || id == 0) {
789 if (aitype != playercontrolled && howmuch > 0) {
793 if (creature == wolftype) {
794 int i = abs(Random() % 2);
796 whichsound = snarlsound;
799 whichsound = snarl2sound;
802 if (creature == rabbittype) {
803 int i = abs(Random() % 2);
805 whichsound = rabbitpainsound;
807 if (i == 1 && howmuch >= 2) {
808 whichsound = rabbitpain1sound;
812 if (whichsound != -1) {
813 emit_sound_at(whichsound, coords);
819 if (id == 0 && howmuch > 0) {
823 if (bloodtoggle && decalstoggle && !Tutorial::active) {
824 if (bleeding <= 0 && spurt) {
826 for (int i = 0; i < 3; i++) {
827 // emit blood particles
828 // FIXME: copypaste from above
831 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
832 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
833 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
834 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
837 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
838 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
839 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
840 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
845 // weird texture manipulation code follows.
846 // looks like this is painting blood onto the character's skin texture
847 // FIXME: surely there's a better way
849 int offsetx = 0, offsety = 0;
851 offsety = Random() % 40;
852 offsetx = abs(Random() % 60);
854 if (which == 190 || which == 185) {
855 offsety = Random() % 40;
856 offsetx = abs(Random() % 100) - 20;
859 offsety = Random() % 10;
860 offsetx = Random() % 10;
863 offsety = Random() % 20;
864 offsetx = Random() % 20;
866 if (which == 220 || which == 215) {
875 for (i = 0; i < 512; i++) {
876 for (j = 0; j < 512; j++) {
877 if (PersonType::types[creature].bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && PersonType::types[creature].bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
905 if (endx > 512 - 1) {
908 if (endy > 512 - 1) {
918 startx /= realtexdetail;
919 starty /= realtexdetail;
920 endx /= realtexdetail;
921 endy /= realtexdetail;
923 int texdetailint = realtexdetail;
925 for (i = startx; i < endx; i++) {
926 for (j = starty; j < endy; j++) {
927 if (PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
928 color = Random() % 85 + 170;
929 where = i * skeleton.skinsize * 3 + j * 3;
930 if (skeleton.skinText[where + 0] > color / 2) {
931 skeleton.skinText[where + 0] = color / 2;
933 skeleton.skinText[where + 1] = 0;
934 skeleton.skinText[where + 2] = 0;
938 skeleton.drawmodel.textureptr.bind();
943 while (PersonType::types[creature].bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || PersonType::types[creature].bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
944 bleedxint = abs(Random() % 512);
945 bleedyint = abs(Random() % 512);
947 bleedy = bleedxint + offsetx;
948 bleedx = bleedyint + offsety;
949 bleedy /= realtexdetail;
950 bleedx /= realtexdetail;
957 if (bleedx > skeleton.skinsize - 1) {
958 bleedx = skeleton.skinsize - 1;
960 if (bleedy > skeleton.skinsize - 1) {
961 bleedy = skeleton.skinsize - 1;
963 direction = abs(Random() % 2) * 2 - 1;
965 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
966 deathbleeding += bleeding;
967 bloodloss += bleeding * 3;
969 if (!Tutorial::active && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
970 if (abs(Random() % 2) == 0) {
971 aitype = gethelptype;
974 aitype = attacktypecutoff;
984 * similar to DoBloodBig
986 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
990 static XYZ startpoint, endpoint, colpoint, movepoint;
991 static float rotationpoint;
993 static XYZ p1, p2, p3, p0;
996 float coordsx, coordsy;
999 if (bloodtoggle && decalstoggle && !Tutorial::active) {
1001 if (!skeleton.free) {
1002 where = DoRotation(where, 0, -yaw, 0);
1006 startpoint.y += 100;
1011 // ray testing for a tri in the character model
1012 whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
1013 if (whichtri != -1) {
1014 // low level geometry math
1016 p1 = skeleton.drawmodel.getTriangleVertex(whichtri, 0);
1017 p2 = skeleton.drawmodel.getTriangleVertex(whichtri, 1);
1018 p3 = skeleton.drawmodel.getTriangleVertex(whichtri, 2);
1020 bary.x = distsq(&p0, &p1);
1021 bary.y = distsq(&p0, &p2);
1022 bary.z = distsq(&p0, &p3);
1024 total = bary.x + bary.y + bary.z;
1029 bary.x = 1 - bary.x;
1030 bary.y = 1 - bary.y;
1031 bary.z = 1 - bary.z;
1033 total = bary.x + bary.y + bary.z;
1038 gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0];
1039 gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1];
1040 gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2];
1041 gyy.x = skeleton.drawmodel.Triangles[whichtri].gy[0];
1042 gyy.y = skeleton.drawmodel.Triangles[whichtri].gy[1];
1043 gyy.z = skeleton.drawmodel.Triangles[whichtri].gy[2];
1044 coordsx = skeleton.drawmodel.Triangles[whichtri].gx[0] * bary.x + skeleton.drawmodel.Triangles[whichtri].gx[1] * bary.y + skeleton.drawmodel.Triangles[whichtri].gx[2] * bary.z;
1045 coordsy = skeleton.drawmodel.Triangles[whichtri].gy[0] * bary.x + skeleton.drawmodel.Triangles[whichtri].gy[1] * bary.y + skeleton.drawmodel.Triangles[whichtri].gy[2] * bary.z;
1047 if (bleeding <= 0 && spurt) {
1049 for (int i = 0; i < 3; i++) {
1050 // emit blood particles
1051 // FIXME: more copypaste code
1053 if (skeleton.free) {
1054 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
1055 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
1056 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
1057 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
1060 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
1061 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
1062 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
1063 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
1068 // texture manipulation follows
1070 int offsetx = 0, offsety = 0;
1071 offsetx = (1 + coordsy) * 512 - 291;
1072 offsety = coordsx * 512 - 437;
1079 for (i = 0; i < 512; i++) {
1080 for (j = 0; j < 512; j++) {
1081 if (PersonType::types[creature].bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && PersonType::types[creature].bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
1108 if (endx > 512 - 1) {
1111 if (endy > 512 - 1) {
1114 if (endx < startx) {
1117 if (endy < starty) {
1121 startx /= realtexdetail;
1122 starty /= realtexdetail;
1123 endx /= realtexdetail;
1124 endy /= realtexdetail;
1126 int texdetailint = realtexdetail;
1128 for (i = startx; i < endx; i++) {
1129 for (j = starty; j < endy; j++) {
1130 if (PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
1131 color = Random() % 85 + 170;
1132 where = i * skeleton.skinsize * 3 + j * 3;
1133 if (skeleton.skinText[where + 0] > color / 2) {
1134 skeleton.skinText[where + 0] = color / 2;
1136 skeleton.skinText[where + 1] = 0;
1137 skeleton.skinText[where + 2] = 0;
1138 } else if (PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= 160 + 4 && PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= 160 - 4) {
1139 color = Random() % 85 + 170;
1140 where = i * skeleton.skinsize * 3 + j * 3;
1141 if (skeleton.skinText[where + 0] > color / 2) {
1142 skeleton.skinText[where + 0] = color / 2;
1144 skeleton.skinText[where + 1] = 0;
1145 skeleton.skinText[where + 2] = 0;
1149 skeleton.drawmodel.textureptr.bind();
1152 bleedy = (1 + coordsy) * 512;
1153 bleedx = coordsx * 512;
1154 bleedy /= realtexdetail;
1155 bleedx /= realtexdetail;
1162 if (bleedx > skeleton.skinsize - 1) {
1163 bleedx = skeleton.skinsize - 1;
1165 if (bleedy > skeleton.skinsize - 1) {
1166 bleedy = skeleton.skinsize - 1;
1168 direction = abs(Random() % 2) * 2 - 1;
1170 if (whichtri == -1) {
1174 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
1175 deathbleeding += bleeding;
1176 bloodloss += bleeding * 3;
1178 if (!Tutorial::active && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
1179 if (abs(Random() % 2) == 0) {
1180 aitype = gethelptype;
1183 aitype = attacktypecutoff;
1194 * guessing this performs a reversal
1196 void Person::Reverse()
1198 if (!((victim->aitype == playercontrolled || hostiletime > 1 || staggerdelay <= 0) && victim->animTarget != jumpupanim && victim->animTarget != jumpdownanim && (!Tutorial::active || cananger) && hostile)) {
1202 if (normaldotproduct(victim->facing, victim->coords - coords) > 0 && (victim->id != 0 || difficulty >= 2) && (creature != wolftype || victim->creature == wolftype)) {
1206 if (animTarget == sweepanim) {
1207 animTarget = sweepreversedanim;
1208 animCurrent = sweepreversedanim;
1209 victim->animCurrent = sweepreversalanim;
1210 victim->animTarget = sweepreversalanim;
1212 if (animTarget == spinkickanim) {
1213 animTarget = spinkickreversedanim;
1214 animCurrent = spinkickreversedanim;
1215 victim->animCurrent = spinkickreversalanim;
1216 victim->animTarget = spinkickreversalanim;
1218 if (animTarget == upunchanim || animTarget == rabbittacklinganim) {
1219 if (animTarget == rabbittacklinganim) {
1222 victim->frameCurrent = 6;
1223 victim->frameTarget = 7;
1225 animTarget = upunchreversedanim;
1226 animCurrent = upunchreversedanim;
1227 victim->animCurrent = upunchreversalanim;
1228 victim->animTarget = upunchreversalanim;
1230 if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
1231 if (victim->weaponactive != -1) {
1232 victim->throwtogglekeydown = 1;
1233 XYZ tempVelocity = victim->velocity * .2;
1234 if (tempVelocity.x == 0) {
1235 tempVelocity.x = .1;
1237 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1238 victim->num_weapons--;
1239 if (victim->num_weapons) {
1240 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1241 if (victim->weaponstuck == victim->num_weapons) {
1242 victim->weaponstuck = 0;
1246 victim->weaponactive = -1;
1247 for (unsigned j = 0; j < Person::players.size(); j++) {
1248 Person::players[j]->wentforweapon = 0;
1252 animTarget = staffhitreversedanim;
1253 animCurrent = staffhitreversedanim;
1254 victim->animCurrent = staffhitreversalanim;
1255 victim->animTarget = staffhitreversalanim;
1257 if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
1258 if (victim->weaponactive != -1) {
1259 victim->throwtogglekeydown = 1;
1260 XYZ tempVelocity = victim->velocity * .2;
1261 if (tempVelocity.x == 0) {
1262 tempVelocity.x = .1;
1264 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1265 victim->num_weapons--;
1266 if (victim->num_weapons) {
1267 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1268 if (victim->weaponstuck == victim->num_weapons) {
1269 victim->weaponstuck = 0;
1273 victim->weaponactive = -1;
1274 for (unsigned j = 0; j < Person::players.size(); j++) {
1275 Person::players[j]->wentforweapon = 0;
1278 animTarget = staffspinhitreversedanim;
1279 animCurrent = staffspinhitreversedanim;
1280 victim->animCurrent = staffspinhitreversalanim;
1281 victim->animTarget = staffspinhitreversalanim;
1283 if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
1284 if (victim->weaponactive != -1) {
1285 victim->throwtogglekeydown = 1;
1286 XYZ tempVelocity = victim->velocity * .2;
1287 if (tempVelocity.x == 0) {
1288 tempVelocity.x = .1;
1290 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1291 victim->num_weapons--;
1292 if (victim->num_weapons) {
1293 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1294 if (victim->weaponstuck == victim->num_weapons) {
1295 victim->weaponstuck = 0;
1299 victim->weaponactive = -1;
1300 for (unsigned j = 0; j < Person::players.size(); j++) {
1301 Person::players[j]->wentforweapon = 0;
1304 animTarget = swordslashreversedanim;
1305 animCurrent = swordslashreversedanim;
1306 victim->animCurrent = swordslashreversalanim;
1307 victim->animTarget = swordslashreversalanim;
1309 if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
1310 if (victim->weaponactive != -1) {
1311 victim->throwtogglekeydown = 1;
1312 XYZ tempVelocity = victim->velocity * .2;
1313 if (tempVelocity.x == 0) {
1314 tempVelocity.x = .1;
1316 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1317 victim->num_weapons--;
1318 if (victim->num_weapons) {
1319 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1320 if (victim->weaponstuck == victim->num_weapons) {
1321 victim->weaponstuck = 0;
1325 victim->weaponactive = -1;
1326 for (unsigned j = 0; j < Person::players.size(); j++) {
1327 Person::players[j]->wentforweapon = 0;
1330 animTarget = knifeslashreversedanim;
1331 animCurrent = knifeslashreversedanim;
1332 victim->animCurrent = knifeslashreversalanim;
1333 victim->animTarget = knifeslashreversalanim;
1335 if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim) {
1336 victim->targettilt2 = targettilt2;
1337 victim->frameCurrent = frameCurrent;
1338 victim->frameTarget = frameTarget;
1339 victim->target = target;
1340 victim->velocity = 0;
1341 victim->oldcoords = victim->coords;
1342 victim->coords = coords;
1343 victim->targetyaw = targetyaw;
1344 victim->yaw = targetyaw;
1345 victim->victim = this->shared_from_this();
1347 if (animTarget == winduppunchanim) {
1348 animTarget = winduppunchblockedanim;
1349 victim->animTarget = blockhighleftanim;
1350 victim->frameTarget = 1;
1351 victim->target = .5;
1352 victim->victim = this->shared_from_this();
1353 victim->targetyaw = targetyaw + 180;
1355 if (animTarget == wolfslapanim) {
1356 animTarget = winduppunchblockedanim;
1357 victim->animTarget = blockhighleftanim;
1358 victim->frameTarget = 1;
1359 victim->target = .5;
1360 victim->victim = this->shared_from_this();
1361 victim->targetyaw = targetyaw + 180;
1363 if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) {
1364 animTarget = swordslashparriedanim;
1365 parriedrecently = .4;
1366 victim->parriedrecently = 0;
1367 victim->animTarget = swordslashparryanim;
1368 victim->frameTarget = 1;
1369 victim->target = .5;
1370 victim->victim = this->shared_from_this();
1371 victim->targetyaw = targetyaw + 180;
1373 if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
1374 if (victim->weaponactive != -1) {
1375 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1376 if (weapons[victim->weaponids[0]].getType() == staff) {
1377 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1379 if (weapons[weaponids[0]].getType() == staff) {
1380 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1382 emit_sound_at(swordstaffsound, victim->coords);
1384 emit_sound_at(metalhitsound, victim->coords);
1388 victim->Puff(righthand);
1390 victim->frameTarget = 0;
1391 victim->animTarget = staggerbackhighanim;
1392 victim->targetyaw = targetyaw + 180;
1394 aim = DoRotation(facing, 0, 90, 0) * 21;
1396 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
1397 victim->num_weapons--;
1398 if (victim->num_weapons) {
1399 victim->weaponids[0] = victim->weaponids[num_weapons];
1400 if (victim->weaponstuck == victim->num_weapons) {
1401 victim->weaponstuck = 0;
1404 victim->weaponactive = -1;
1405 for (unsigned i = 0; i < Person::players.size(); i++) {
1406 Person::players[i]->wentforweapon = 0;
1410 if (abs(Random() % 20) == 0) {
1411 if (weaponactive != -1) {
1412 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1413 if (weapons[victim->weaponids[0]].getType() == staff) {
1414 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1416 if (weapons[weaponids[0]].getType() == staff) {
1417 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1420 emit_sound_at(swordstaffsound, coords);
1422 emit_sound_at(metalhitsound, coords);
1430 animTarget = staggerbackhighanim;
1431 targetyaw = targetyaw + 180;
1433 aim = DoRotation(facing, 0, 90, 0) * 21;
1435 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
1438 weaponids[0] = weaponids[num_weapons];
1439 if (weaponstuck == num_weapons) {
1444 for (unsigned i = 0; i < Person::players.size(); i++) {
1445 Person::players[i]->wentforweapon = 0;
1450 if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) {
1451 if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) {
1452 victim->animTarget = dodgebackanim;
1453 victim->frameTarget = 0;
1457 rotatetarget = coords - victim->coords;
1458 Normalise(&rotatetarget);
1459 victim->targetyaw = -asin(0 - rotatetarget.x);
1460 victim->targetyaw *= 360 / 6.28;
1461 if (rotatetarget.z < 0) {
1462 victim->targetyaw = 180 - victim->targetyaw;
1465 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1467 victim->lastattack3 = victim->lastattack2;
1468 victim->lastattack2 = victim->lastattack;
1469 victim->lastattack = victim->animTarget;
1471 victim->animTarget = sweepanim;
1472 victim->frameTarget = 0;
1476 rotatetarget = coords - victim->coords;
1477 Normalise(&rotatetarget);
1478 victim->targetyaw = -asin(0 - rotatetarget.x);
1479 victim->targetyaw *= 360 / 6.28;
1480 if (rotatetarget.z < 0) {
1481 victim->targetyaw = 180 - victim->targetyaw;
1484 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1486 victim->lastattack3 = victim->lastattack2;
1487 victim->lastattack2 = victim->lastattack;
1488 victim->lastattack = victim->animTarget;
1494 victim->velocity = 0;
1496 if (aitype != playercontrolled) {
1498 if (escapednum < 2) {
1499 int chances = ((difficulty == 2) ? 3 : ((difficulty == 1) ? 5 : 10));
1500 if ((Random() % chances) == 0) {
1506 if (victim->id == 0 && Animation::animations[victim->animTarget].attack == reversal) {
1514 void Person::DoDamage(float howmuch)
1518 damagetaken += howmuch / power;
1520 damagedealt += howmuch / power;
1524 if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo)) {
1529 if (!Tutorial::active) {
1530 damage += howmuch / power;
1531 permanentdamage += howmuch / 2 / power;
1532 superpermanentdamage += howmuch / 4 / power;
1535 if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2) {
1538 if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt) {
1543 camerashake += howmuch / 100;
1544 if ((howmuch > 50 && damage > damagetolerance / 2)) {
1545 blackout = damage / damagetolerance;
1553 if (aitype == passivetype && damage < damagetolerance && ((!Tutorial::active || cananger) && hostile)) {
1554 aitype = attacktypecutoff;
1556 if (!Tutorial::active && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
1557 if (abs(Random() % 2) == 0) {
1558 aitype = gethelptype;
1561 aitype = attacktypecutoff;
1566 if (howmuch > damagetolerance * 50 && skeleton.free != 2) {
1569 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1570 if (skeleton.free) {
1571 flatvelocity2 = skeleton.joints[i].velocity;
1572 flatfacing2 = skeleton.joints[i].position * scale + coords;
1574 flatvelocity2 = velocity;
1575 flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
1577 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1578 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1579 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1580 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1581 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1582 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1585 emit_sound_at(splattersound, coords);
1590 if (!dead && creature == wolftype) {
1591 award_bonus(0, Wolfbonus);
1598 if (!Tutorial::active || id == 0) {
1599 if (speechdelay <= 0 && !dead && aitype != playercontrolled) {
1600 int whichsound = -1;
1602 if (creature == wolftype) {
1603 int i = abs(Random() % 2);
1605 whichsound = snarlsound;
1608 whichsound = snarl2sound;
1611 if (creature == rabbittype) {
1612 int i = abs(Random() % 2);
1614 whichsound = rabbitpainsound;
1616 if (i == 1 && damage > damagetolerance) {
1617 whichsound = rabbitpain1sound;
1621 if (whichsound != -1) {
1622 emit_sound_at(whichsound, coords);
1623 addEnvSound(coords);
1631 * calculate/animate head facing direction?
1633 void Person::DoHead()
1635 static XYZ rotatearound;
1637 static float lookspeed = 500;
1639 if (!freeze && !winfreeze) {
1642 targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100;
1643 targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100;
1645 while (targetheadyaw > 180) {
1646 targetheadyaw -= 360;
1648 while (targetheadyaw < -180) {
1649 targetheadyaw += 360;
1652 if (targetheadyaw > 160) {
1653 targetheadpitch = targetheadpitch * -1;
1655 if (targetheadyaw < -160) {
1656 targetheadpitch = targetheadpitch * -1;
1658 if (targetheadyaw > 160) {
1659 targetheadyaw = targetheadyaw - 180;
1661 if (targetheadyaw < -160) {
1662 targetheadyaw = targetheadyaw + 180;
1665 if (targetheadpitch > 120) {
1666 targetheadpitch = 120;
1668 if (targetheadpitch < -120) {
1669 targetheadpitch = -120;
1671 if (targetheadyaw > 120) {
1672 targetheadyaw = 120;
1674 if (targetheadyaw < -120) {
1675 targetheadyaw = -120;
1679 targetheadpitch = 0;
1682 if (targetheadyaw > 80) {
1685 if (targetheadyaw < -80) {
1686 targetheadyaw = -80;
1688 if (targetheadpitch > 50) {
1689 targetheadpitch = 50;
1691 if (targetheadpitch < -50) {
1692 targetheadpitch = -50;
1696 if (abs(headyaw - targetheadyaw) < multiplier * lookspeed) {
1697 headyaw = targetheadyaw;
1698 } else if (headyaw > targetheadyaw) {
1699 headyaw -= multiplier * lookspeed;
1700 } else if (headyaw < targetheadyaw) {
1701 headyaw += multiplier * lookspeed;
1704 if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2) {
1705 headpitch = targetheadpitch;
1706 } else if (headpitch > targetheadpitch) {
1707 headpitch -= multiplier * lookspeed / 2;
1708 } else if (headpitch < targetheadpitch) {
1709 headpitch += multiplier * lookspeed / 2;
1712 rotatearound = jointPos(neck);
1713 jointPos(head) = rotatearound + DoRotation(jointPos(head) - rotatearound, headpitch, 0, 0);
1717 if (animTarget != bounceidleanim && animTarget != fightidleanim && animTarget != wolfidle && animTarget != knifefightidleanim && animTarget != drawrightanim && animTarget != drawleftanim && animTarget != walkanim) {
1718 facing = DoRotation(facing, headpitch * .4, 0, 0);
1719 facing = DoRotation(facing, 0, headyaw * .4, 0);
1722 if (animTarget == bounceidleanim || animTarget == fightidleanim || animTarget == wolfidle || animTarget == knifefightidleanim || animTarget == drawrightanim || animTarget == drawleftanim) {
1723 facing = DoRotation(facing, headpitch * .8, 0, 0);
1724 facing = DoRotation(facing, 0, headyaw * .8, 0);
1727 if (animTarget == walkanim) {
1728 facing = DoRotation(facing, headpitch * .6, 0, 0);
1729 facing = DoRotation(facing, 0, headyaw * .6, 0);
1732 skeleton.specialforward[0] = facing;
1733 //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1734 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
1735 if (skeleton.muscles[i].visible && (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)) {
1736 skeleton.FindRotationMuscle(i, animTarget);
1743 * ragdolls character?
1745 void Person::RagDoll(bool checkcollision)
1750 if (!skeleton.free) {
1754 if (id == 0 && isFlip()) {
1762 facing = DoRotation(facing, 0, yaw, 0);
1764 skeleton.freetime = 0;
1766 skeleton.longdead = 0;
1769 skeleton.broken = 0;
1770 skeleton.spinny = 1;
1772 skeleton.freefall = 1;
1774 if (!isnormal(velocity.x)) {
1777 if (!isnormal(velocity.y)) {
1780 if (!isnormal(velocity.z)) {
1783 if (!isnormal(yaw)) {
1786 if (!isnormal(coords.x)) {
1789 if (!isnormal(tilt)) {
1792 if (!isnormal(tilt2)) {
1796 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1797 skeleton.joints[i].delay = 0;
1798 skeleton.joints[i].locked = 0;
1799 skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1800 if (!isnormal(skeleton.joints[i].position.x)) {
1801 skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0);
1803 if (!isnormal(skeleton.joints[i].position.x)) {
1804 skeleton.joints[i].position = coords;
1806 skeleton.joints[i].position.y += .1;
1807 skeleton.joints[i].oldposition = skeleton.joints[i].position;
1808 skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords;
1811 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1812 skeleton.joints[i].velocity = 0;
1813 skeleton.joints[i].velchange = 0;
1815 skeleton.DoConstraints(&coords, &scale);
1816 if (Animation::animations[animCurrent].height == lowheight || Animation::animations[animTarget].height == lowheight) {
1817 skeleton.DoConstraints(&coords, &scale);
1818 skeleton.DoConstraints(&coords, &scale);
1819 skeleton.DoConstraints(&coords, &scale);
1820 skeleton.DoConstraints(&coords, &scale);
1823 speed = targetFrame().speed * 2;
1824 if (currentFrame().speed > targetFrame().speed) {
1825 speed = currentFrame().speed * 2;
1828 speed = transspeed * 2;
1833 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1834 if ((Animation::animations[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && Animation::animations[animCurrent].height == Animation::animations[animTarget].height) {
1835 skeleton.joints[i].velocity = velocity / scale + facing * 5 + DoRotation(DoRotation(DoRotation((targetFrame().joints[i].position - currentFrame().joints[i].position) * speed, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1837 skeleton.joints[i].velocity = velocity / scale + facing * 5;
1839 change.x = (float)(Random() % 100) / 100;
1840 change.y = (float)(Random() % 100) / 100;
1841 change.z = (float)(Random() % 100) / 100;
1842 skeleton.joints[i].velocity += change;
1843 skeleton.joints[fabs(Random() % skeleton.joints.size())].velocity -= change;
1845 change.x = (float)(Random() % 100) / 100;
1846 change.y = (float)(Random() % 100) / 100;
1847 change.z = (float)(Random() % 100) / 100;
1848 skeleton.joints[i].velchange += change;
1849 skeleton.joints[fabs(Random() % skeleton.joints.size())].velchange -= change;
1852 if (checkcollision) {
1855 if (!skeleton.joints.empty()) {
1858 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
1859 average += skeleton.joints[j].position;
1861 average /= skeleton.joints.size();
1862 coords += average * scale;
1863 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
1864 skeleton.joints[j].position -= average;
1868 whichpatchx = coords.x / (terrain.size / subdivision * terrain.scale);
1869 whichpatchz = coords.z / (terrain.size / subdivision * terrain.scale);
1870 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
1871 i = terrain.patchobjects[whichpatchx][whichpatchz][l];
1874 if (SphereCheck(&lowpoint, 3, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
1875 coords.x = lowpoint.x;
1876 coords.z = lowpoint.z;
1885 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1886 velocity += skeleton.joints[i].velocity * scale;
1888 velocity /= skeleton.joints.size();
1891 if (Random() % 2 == 0) {
1892 if (weaponactive != -1 && animTarget != rabbitkickanim && num_weapons > 0) {
1893 weapons[weaponids[0]].drop(jointVel(righthand) * scale * -.3, jointVel(righthand) * scale);
1894 weapons[weaponids[0]].velocity.x += .01;
1897 weaponids[0] = weaponids[num_weapons];
1898 if (weaponstuck == num_weapons) {
1903 for (unsigned i = 0; i < Person::players.size(); i++) {
1904 Person::players[i]->wentforweapon = 0;
1909 animTarget = bounceidleanim;
1910 animCurrent = bounceidleanim;
1918 void Person::FootLand(bodypart whichfoot, float opacity)
1920 if ((whichfoot != leftfoot) && (whichfoot != rightfoot)) {
1921 cerr << "FootLand called on wrong bodypart" << endl;
1924 static XYZ terrainlight;
1925 static XYZ footvel, footpoint;
1926 if (opacity >= 1 || skiddelay <= 0) {
1929 footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords;
1930 if (distsq(&footpoint, &viewer)) {
1931 Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity);
1933 } else if (onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1934 footvel = velocity / 5;
1935 if (footvel.y < .8) {
1938 footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords;
1939 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1940 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1941 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) {
1942 if (environment == snowyenvironment) {
1943 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity);
1945 terrain.MakeDecal(footprintdecal, footpoint, .2, 1 * opacity, yaw);
1947 } else if (environment == grassyenvironment) {
1948 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity);
1949 } else if (environment == desertenvironment) {
1950 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity);
1952 terrain.MakeDecal(footprintdecal, footpoint, .2, .25 * opacity, yaw);
1956 } else if (isLanding() || (animTarget == jumpupanim) || isLandhard()) {
1957 footvel = velocity / 5;
1958 if (footvel.y < .8) {
1961 footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords;
1962 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) {
1963 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity);
1970 * make a puff effect at a body part (dust effect?)
1972 void Person::Puff(int whichlabel)
1974 static XYZ footvel, footpoint;
1977 footpoint = DoRotation(jointPos(whichlabel), 0, yaw, 0) * scale + coords;
1978 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .9, .3);
1982 * I think I added this in an attempt to clean up code
1984 void Person::setTargetAnimation(int animation)
1986 animTarget = animation;
1995 void Person::DoAnimations()
1997 if (!skeleton.free) {
1998 static float oldtarget;
2000 if (isIdle() && animCurrent != getIdle()) {
2001 normalsupdatedelay = 0;
2004 if (animTarget == tempanim || animCurrent == tempanim) {
2005 Animation::animations[tempanim] = tempanimation;
2007 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
2014 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc);
2015 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
2017 if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z)) {
2020 if (!crouchkeydown && velocity.y >= -15) {
2024 if ((animCurrent == jumpupanim || animTarget == jumpdownanim) /*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) {
2029 targfacing = DoRotation(targfacing, 0, targetyaw, 0);
2031 if (normaldotproduct(targfacing, velocity) >= -.3) {
2032 animTarget = flipanim;
2034 animTarget = backflipanim;
2036 crouchtogglekeydown = 1;
2045 if (Animation::animations[animTarget].attack != reversed) {
2048 if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) {
2049 crouchtogglekeydown = 0;
2050 if (aitype == playercontrolled) {
2054 if (!crouchtogglekeydown && Animation::animations[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain)) {
2058 crouchtogglekeydown = 1;
2062 if (Animation::animations[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) {
2064 normalsupdatedelay = 0;
2069 if (animTarget == rollanim && frameTarget == 3 && onfire) {
2071 emit_sound_at(fireendsound, coords);
2072 pause_sound(stream_firesound);
2076 if (animTarget == rabbittacklinganim && frameTarget == 1) {
2077 if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0) {
2080 if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) {
2081 if (normaldotproduct(victim->facing, facing) > 0) {
2082 victim->animTarget = rabbittackledbackanim;
2084 victim->animTarget = rabbittackledfrontanim;
2086 victim->frameTarget = 2;
2089 victim->targetyaw = yaw;
2090 if (victim->aitype == gethelptype) {
2091 victim->DoDamage(victim->damagetolerance - victim->damage);
2093 //victim->DoDamage(30);
2094 if (creature == wolftype) {
2096 emit_sound_at(clawslicesound, victim->coords);
2098 victim->DoBloodBig(1 / victim->armorhead, 210);
2100 award_bonus(id, TackleBonus,
2101 victim->aitype == gethelptype ? 50 : 0);
2105 if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (targetFrame().label || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) {
2106 if (weapons[weaponids[0]].getType() == knife) {
2107 if (weaponactive == -1) {
2109 } else if (weaponactive == 0) {
2113 if (weaponactive == -1) {
2114 emit_sound_at(knifesheathesound, coords);
2116 if (weaponactive != -1) {
2117 emit_sound_at(knifedrawsound, coords, 128);
2120 drawtogglekeydown = 1;
2123 if (!Tutorial::active || id == 0) {
2124 if ((targetFrame().label && (targetFrame().label < 5 || targetFrame().label == 8))) {
2125 int whichsound = -1;
2127 if (terrain.getOpacity(coords.x, coords.z) < .2) {
2128 if (targetFrame().label == 1) {
2129 whichsound = footstepsound;
2131 whichsound = footstepsound2;
2133 if (targetFrame().label == 1) {
2134 FootLand(leftfoot, 1);
2136 if (targetFrame().label == 2) {
2137 FootLand(rightfoot, 1);
2139 if (targetFrame().label == 3 && isRun()) {
2140 FootLand(rightfoot, 1);
2141 FootLand(leftfoot, 1);
2144 if (terrain.getOpacity(coords.x, coords.z) >= .2) {
2145 if (targetFrame().label == 1) {
2146 whichsound = footstepsound3;
2148 whichsound = footstepsound4;
2153 if (targetFrame().label == 1) {
2154 whichsound = footstepsound3;
2156 whichsound = footstepsound4;
2159 if (targetFrame().label == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
2160 if (Animation::animations[animTarget].attack != neutral) {
2161 unsigned r = abs(Random() % 3);
2163 whichsound = lowwhooshsound;
2166 whichsound = midwhooshsound;
2169 whichsound = highwhooshsound;
2172 if (Animation::animations[animTarget].attack == neutral) {
2173 whichsound = movewhooshsound;
2175 } else if (targetFrame().label == 4) {
2176 whichsound = knifeswishsound;
2178 if (targetFrame().label == 8 && !Tutorial::active) {
2179 whichsound = landsound2;
2182 if (whichsound != -1) {
2183 emit_sound_at(whichsound, coords, 256.);
2186 if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
2187 if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim) {
2188 addEnvSound(coords, 15);
2190 addEnvSound(coords, 6);
2195 if (targetFrame().label == 3) {
2197 emit_sound_at(whichsound, coords, 128.);
2204 if (!Tutorial::active || id == 0) {
2205 if (speechdelay <= 0) {
2206 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) {
2207 if ((targetFrame().label && (targetFrame().label < 5 || targetFrame().label == 8))) {
2208 int whichsound = -1;
2209 if (targetFrame().label == 4 && aitype != playercontrolled) {
2210 if (Animation::animations[animTarget].attack != neutral) {
2211 unsigned r = abs(Random() % 4);
2212 whichsound = PersonType::types[creature].soundsAttack[r];
2217 if (whichsound != -1) {
2218 emit_sound_at(whichsound, coords);
2225 if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) {
2226 FootLand(leftfoot, 1);
2227 FootLand(rightfoot, 1);
2231 currentoffset = targetoffset;
2232 frameTarget = frameCurrent;
2233 animCurrent = animTarget;
2236 if (animTarget == removeknifeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2237 for (unsigned i = 0; i < weapons.size(); i++) {
2238 if (weapons[i].owner == -1) {
2239 if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
2240 if (distsq(&coords, &weapons[i].position) >= 1) {
2241 if (weapons[i].getType() != staff) {
2242 emit_sound_at(knifedrawsound, coords, 128.);
2252 if (animTarget == crouchremoveknifeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2253 for (unsigned i = 0; i < weapons.size(); i++) {
2254 bool willwork = true;
2255 if (weapons[i].owner != -1) {
2256 if (Person::players[weapons[i].owner]->weaponstuck != -1) {
2257 if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == int(i)) {
2258 if (Person::players[weapons[i].owner]->num_weapons > 1) {
2264 if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free)) {
2265 if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) {
2266 if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
2267 bool fleshstuck = false;
2268 if (weapons[i].owner != -1) {
2269 if (victim->weaponstuck != -1) {
2270 if (victim->weaponids[victim->weaponstuck] == int(i)) {
2276 emit_sound_at(fleshstabremovesound, coords, 128.);
2278 if (weapons[i].getType() != staff) {
2279 emit_sound_at(knifedrawsound, coords, 128.);
2282 if (weapons[i].owner != -1) {
2283 victim = Person::players[weapons[i].owner];
2284 if (victim->num_weapons == 1) {
2285 victim->num_weapons = 0;
2287 victim->num_weapons = 1;
2290 //victim->weaponactive=-1;
2291 victim->skeleton.longdead = 0;
2292 victim->skeleton.free = 1;
2293 victim->skeleton.broken = 0;
2295 for (unsigned j = 0; j < victim->skeleton.joints.size(); j++) {
2296 victim->skeleton.joints[j].velchange = 0;
2297 victim->skeleton.joints[j].locked = 0;
2303 Normalise(&relative);
2304 XYZ footvel, footpoint;
2306 footpoint = weapons[i].position;
2307 if (victim->weaponstuck != -1) {
2308 if (victim->weaponids[victim->weaponstuck] == int(i)) {
2310 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2312 weapons[i].bloody = 2;
2313 weapons[i].blooddrip = 5;
2314 victim->weaponstuck = -1;
2317 if (victim->num_weapons > 0) {
2318 if (victim->weaponstuck != 0 && victim->weaponstuck != -1) {
2319 victim->weaponstuck = 0;
2321 if (victim->weaponids[0] == int(i)) {
2322 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
2326 victim->jointVel(abdomen) += relative * 6;
2327 victim->jointVel(neck) += relative * 6;
2328 victim->jointVel(rightshoulder) += relative * 6;
2329 victim->jointVel(leftshoulder) += relative * 6;
2338 if (animCurrent == drawleftanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2339 if (weaponactive == -1) {
2341 } else if (weaponactive == 0) {
2343 if (num_weapons == 2) {
2345 buffer = weaponids[0];
2346 weaponids[0] = weaponids[1];
2347 weaponids[1] = buffer;
2350 if (weaponactive == -1) {
2351 emit_sound_at(knifesheathesound, coords, 128.);
2353 if (weaponactive != -1) {
2354 emit_sound_at(knifedrawsound, coords, 128.);
2358 if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) {
2359 XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0);
2360 Normalise(&rotatetarget);
2361 targetyaw = -asin(0 - rotatetarget.x);
2362 targetyaw *= 360 / 6.28;
2363 if (rotatetarget.z < 0) {
2364 targetyaw = 180 - targetyaw;
2367 if (animTarget == walljumprightkickanim) {
2370 if (animTarget == walljumpleftkickanim) {
2377 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0)) {
2381 if (distsq(&victim->coords, &/*Person::players[i]->*/ coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1) {
2389 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) {
2390 animTarget = rabbittackleanim;
2392 emit_sound_at(jumpsound, coords);
2400 targetloc = velocity;
2401 Normalise(&targetloc);
2402 targetloc += coords;
2403 for (unsigned i = 0; i < Person::players.size(); i++) {
2405 if (distsq(&targetloc, &Person::players[i]->coords) < closestdist || closestdist == 0) {
2406 closestdist = distsq(&targetloc, &Person::players[i]->coords);
2411 if (closestid != -1) {
2412 if (closestdist < 5 && !Person::players[closestid]->dead && Animation::animations[Person::players[closestid]->animTarget].height != lowheight && Person::players[closestid]->animTarget != backhandspringanim) {
2414 victim = Person::players[closestid];
2415 coords = victim->coords;
2416 animCurrent = rabbittacklinganim;
2417 animTarget = rabbittacklinganim;
2421 if (coords.z != victim->coords.z || coords.x != victim->coords.x) {
2422 rotatetarget = coords - victim->coords;
2423 Normalise(&rotatetarget);
2424 targetyaw = -asin(0 - rotatetarget.x);
2425 targetyaw *= 360 / 6.28;
2426 if (rotatetarget.z < 0) {
2427 targetyaw = 180 - targetyaw;
2430 if (animTarget != rabbitrunninganim) {
2431 emit_sound_at(jumpsound, coords, 128.);
2438 float damagemult = 1 * power;
2439 if (creature == wolftype) {
2440 damagemult = 2.5 * power;
2443 damagemult /= victim->damagetolerance / 200;
2445 if ((Animation::animations[animTarget].attack == normalattack || animTarget == walljumprightkickanim || animTarget == walljumpleftkickanim) && (!feint) && (victim->skeleton.free != 2 || animTarget == killanim || animTarget == dropkickanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == staffgroundsmashanim)) {
2446 if (animTarget == spinkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2447 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2452 if (Random() % 2 || creature == wolftype) {
2455 if (creature == wolftype) {
2459 if (!Tutorial::active) {
2460 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2462 if (creature == wolftype) {
2463 emit_sound_at(clawslicesound, victim->coords, 128.);
2465 victim->DoBloodBig(2 / victim->armorhead, 175);
2469 relative = victim->coords - coords;
2471 Normalise(&relative);
2472 relative = DoRotation(relative, 0, -90, 0);
2473 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2474 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2476 victim->jointVel(head) += relative * damagemult * 200;
2478 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2484 if (animTarget == wolfslapanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2485 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2490 if (Random() % 2 || creature == wolftype) {
2492 if (creature == wolftype) {
2496 emit_sound_at(whooshhitsound, victim->coords);
2497 if (creature == wolftype) {
2498 emit_sound_at(clawslicesound, victim->coords, 128.);
2500 victim->DoBloodBig(2, 175);
2504 relative = victim->coords - coords;
2506 Normalise(&relative);
2508 Normalise(&relative);
2509 relative = DoRotation(relative, 0, 90, 0);
2510 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2511 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2513 victim->jointVel(head) += relative * damagemult * 100;
2515 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2519 if (animTarget == walljumprightkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2520 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2527 if (!Tutorial::active) {
2528 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2530 if (creature == wolftype) {
2531 emit_sound_at(clawslicesound, victim->coords, 128.);
2533 victim->DoBloodBig(2 / victim->armorhead, 175);
2539 Normalise(&relative);
2540 relative = DoRotation(relative, 0, -90, 0);
2541 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2542 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2544 victim->jointVel(head) += relative * damagemult * 200;
2546 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2548 if (victim->damage > victim->damagetolerance) {
2549 award_bonus(id, style);
2556 if (animTarget == walljumpleftkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2557 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2564 if (!Tutorial::active) {
2565 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2567 if (creature == wolftype) {
2568 emit_sound_at(clawslicesound, victim->coords, 128.);
2570 victim->DoBloodBig(2 / victim->armorhead, 175);
2576 Normalise(&relative);
2577 relative = DoRotation(relative, 0, 90, 0);
2578 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2579 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2581 victim->jointVel(head) += relative * damagemult * 200;
2583 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2585 if (victim->damage > victim->damagetolerance) {
2586 award_bonus(id, style);
2593 if (animTarget == blockhighleftstrikeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2594 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2603 emit_sound_at(whooshhitsound, victim->coords);
2606 relative = victim->coords - coords;
2608 Normalise(&relative);
2609 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2610 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
2612 victim->jointVel(head) += relative * damagemult * 100;
2614 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2618 if (animTarget == killanim && Animation::animations[animTarget].frames[frameCurrent].label == 8) {
2619 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) {
2624 emit_sound_at(whooshhitsound, victim->coords, 128.);
2626 victim->skeleton.longdead = 0;
2627 victim->skeleton.free = 1;
2628 victim->skeleton.broken = 0;
2629 victim->skeleton.spinny = 1;
2631 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2632 victim->skeleton.joints[i].velchange = 0;
2633 victim->skeleton.joints[i].delay = 0;
2634 victim->skeleton.joints[i].locked = 0;
2635 //victim->skeleton.joints[i].velocity=0;
2641 Normalise(&relative);
2642 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2643 victim->skeleton.joints[i].velocity.y = relative.y * 10;
2644 victim->skeleton.joints[i].position.y += relative.y * .3;
2645 victim->skeleton.joints[i].oldposition.y += relative.y * .3;
2646 victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
2648 victim->Puff(abdomen);
2649 victim->jointVel(abdomen).y = relative.y * 400;
2653 if (animTarget == killanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2654 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) {
2659 if (!Tutorial::active) {
2660 emit_sound_at(heavyimpactsound, coords, 128.);
2663 relative = victim->coords - coords;
2665 Normalise(&relative);
2666 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2667 victim->skeleton.joints[i].velocity += relative * damagemult * 90;
2669 victim->Puff(abdomen);
2670 if (victim->dead != 2 && victim->permanentdamage > victim->damagetolerance - 250 && autoslomo) {
2674 victim->DoDamage(damagemult * 500 / victim->protectionhigh);
2675 victim->jointVel(abdomen) += relative * damagemult * 300;
2679 if (animTarget == dropkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
2680 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) {
2685 if (!Tutorial::active) {
2686 emit_sound_at(thudsound, coords);
2689 victim->skeleton.longdead = 0;
2690 victim->skeleton.free = 1;
2691 victim->skeleton.broken = 0;
2692 victim->skeleton.spinny = 1;
2694 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2695 victim->skeleton.joints[i].velchange = 0;
2696 //victim->skeleton.joints[i].delay=0;
2697 victim->skeleton.joints[i].locked = 0;
2700 relative = victim->coords - coords;
2701 Normalise(&relative);
2703 Normalise(&relative);
2704 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2705 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2707 if (!victim->dead) {
2711 victim->Puff(abdomen);
2712 victim->DoDamage(damagemult * 20 / victim->protectionhigh);
2713 victim->jointVel(abdomen) += relative * damagemult * 200;
2715 if (!victim->dead) {
2721 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2724 if (!victim->skeleton.free) {
2730 terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360);
2731 emit_sound_at(knifesheathesound, coords, 128.);
2734 if (victim && hasvictim) {
2735 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2737 XYZ where, startpoint, endpoint, movepoint, colpoint;
2738 float rotationpoint;
2740 if (weapons[weaponids[weaponactive]].getType() == knife) {
2741 where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4);
2742 where -= victim->coords;
2743 if (!victim->skeleton.free) {
2744 where = DoRotation(where, 0, -victim->yaw, 0);
2748 startpoint.y += 100;
2752 if (weapons[weaponids[weaponactive]].getType() == sword) {
2753 where = weapons[weaponids[weaponactive]].position;
2754 where -= victim->coords;
2755 if (!victim->skeleton.free) {
2756 where = DoRotation(where, 0, -victim->yaw, 0);
2759 where = weapons[weaponids[weaponactive]].tippoint;
2760 where -= victim->coords;
2761 if (!victim->skeleton.free) {
2762 where = DoRotation(where, 0, -victim->yaw, 0);
2766 if (weapons[weaponids[weaponactive]].getType() == staff) {
2767 where = weapons[weaponids[weaponactive]].position;
2768 where -= victim->coords;
2769 if (!victim->skeleton.free) {
2770 where = DoRotation(where, 0, -victim->yaw, 0);
2773 where = weapons[weaponids[weaponactive]].tippoint;
2774 where -= victim->coords;
2775 if (!victim->skeleton.free) {
2776 where = DoRotation(where, 0, -victim->yaw, 0);
2782 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
2784 if (whichtri != -1) {
2785 if (victim->dead != 2) {
2786 victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2));
2787 if (!victim->dead) {
2788 award_bonus(id, FinishedBonus);
2792 weapons[weaponids[weaponactive]].bloody = 2;
2795 victim->skeleton.longdead = 0;
2796 victim->skeleton.free = 1;
2797 victim->skeleton.broken = 0;
2799 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2800 victim->skeleton.joints[i].velchange = 0;
2801 victim->skeleton.joints[i].locked = 0;
2802 //victim->skeleton.joints[i].velocity=0;
2804 emit_sound_at(fleshstabsound, coords, 128);
2806 if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) {
2807 weapons[weaponids[weaponactive]].blooddrip += 5;
2808 weapons[weaponids[weaponactive]].blooddripdelay = 0;
2810 if (whichtri == -1) {
2812 emit_sound_at(knifesheathesound, coords, 128.);
2818 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && Animation::animations[animTarget].frames[frameCurrent].label == 6) {
2820 emit_sound_at(knifedrawsound, coords, 128);
2823 if (victim && hasvictim) {
2824 XYZ footvel, footpoint;
2826 emit_sound_at(fleshstabremovesound, coords, 128.);
2829 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2831 if (weapons[weaponids[weaponactive]].getType() == sword) {
2832 XYZ where, startpoint, endpoint, movepoint;
2833 float rotationpoint;
2836 where = weapons[weaponids[weaponactive]].position;
2837 where -= victim->coords;
2838 if (!victim->skeleton.free) {
2839 where = DoRotation(where, 0, -victim->yaw, 0);
2842 where = weapons[weaponids[weaponactive]].tippoint;
2843 where -= victim->coords;
2844 if (!victim->skeleton.free) {
2845 where = DoRotation(where, 0, -victim->yaw, 0);
2851 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2852 footpoint += victim->coords;
2854 if (whichtri == -1) {
2855 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2858 if (weapons[weaponids[weaponactive]].getType() == staff) {
2859 XYZ where, startpoint, endpoint, movepoint;
2860 float rotationpoint;
2863 where = weapons[weaponids[weaponactive]].position;
2864 where -= victim->coords;
2865 if (!victim->skeleton.free) {
2866 where = DoRotation(where, 0, -victim->yaw, 0);
2869 where = weapons[weaponids[weaponactive]].tippoint;
2870 where -= victim->coords;
2871 if (!victim->skeleton.free) {
2872 where = DoRotation(where, 0, -victim->yaw, 0);
2878 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2879 footpoint += victim->coords;
2881 if (whichtri == -1) {
2882 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2885 hasvictim = victim->DoBloodBigWhere(2, 220, footpoint);
2887 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2888 victim->skeleton.longdead = 0;
2889 victim->skeleton.free = 1;
2890 victim->skeleton.broken = 0;
2892 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2893 victim->skeleton.joints[i].velchange = 0;
2894 victim->skeleton.joints[i].locked = 0;
2895 //victim->skeleton.joints[i].velocity=0;
2901 Normalise(&relative);
2902 //victim->Puff(abdomen);
2904 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2907 if (victim->bloodloss < victim->damagetolerance) {
2908 victim->bloodloss += 1000;
2912 victim->jointVel(abdomen) += relative * damagemult * 20;
2916 if (!hasvictim && onterrain) {
2917 weapons[weaponids[weaponactive]].bloody = 0;
2918 weapons[weaponids[weaponactive]].blooddrip = 0;
2922 if (animTarget == upunchanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2923 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2932 if (!Tutorial::active) {
2933 emit_sound_at(heavyimpactsound, victim->coords, 128);
2938 relative = victim->coords - coords;
2940 Normalise(&relative);
2941 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2942 victim->skeleton.joints[i].velocity = relative * 30;
2944 victim->jointVel(head) += relative * damagemult * 150;
2946 victim->frameTarget = 0;
2947 victim->animTarget = staggerbackhardanim;
2948 victim->targetyaw = targetyaw + 180;
2950 victim->stunned = 1;
2953 victim->Puff(abdomen);
2954 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2960 if (animTarget == winduppunchanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2961 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) {
2966 if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && Animation::animations[victim->animTarget].height != lowheight) {
2967 if (!Tutorial::active) {
2968 emit_sound_at(thudsound, victim->coords);
2970 } else if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && Animation::animations[victim->animTarget].height == lowheight) {
2971 if (!Tutorial::active) {
2972 emit_sound_at(whooshhitsound, victim->coords);
2975 if (!Tutorial::active) {
2976 emit_sound_at(heavyimpactsound, victim->coords);
2980 if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || Animation::animations[victim->animTarget].height == lowheight) {
2984 relative = victim->coords - coords;
2986 Normalise(&relative);
2988 Normalise(&relative);
2989 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2990 victim->skeleton.joints[i].velocity = relative * 5;
2992 victim->jointVel(abdomen) += relative * damagemult * 400;
2994 victim->frameTarget = 0;
2995 victim->animTarget = staggerbackhardanim;
2996 victim->targetyaw = targetyaw + 180;
2998 victim->stunned = 1;
3000 victim->Puff(abdomen);
3001 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
3007 if (animTarget == blockhighleftanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3008 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
3009 if (victim->id == 0) {
3012 emit_sound_at(landsound2, victim->coords);
3018 if (animTarget == swordslashparryanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3019 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
3020 if (victim->id == 0) {
3024 if (weaponactive != -1) {
3025 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
3026 if (weapons[victim->weaponids[0]].getType() == staff) {
3027 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3029 if (weapons[weaponids[0]].getType() == staff) {
3030 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3033 emit_sound_at(swordstaffsound, victim->coords);
3035 emit_sound_at(metalhitsound, victim->coords);
3043 if (animTarget == knifethrowanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3044 if (weaponactive != -1) {
3047 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);
3049 weapons[weaponids[0]].thrown(aim * 50);
3052 weaponids[0] = weaponids[num_weapons];
3058 if (animTarget == knifeslashstartanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3060 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 && /*Animation::animations[victim->animTarget].height!=lowheight&&*/ victim->animTarget != dodgebackanim && victim->animTarget != rollanim) {
3062 if (!Tutorial::active) {
3063 victim->DoBloodBig(1.5 / victim->armorhigh, 225);
3066 award_bonus(id, Slicebonus);
3067 if (!Tutorial::active) {
3068 emit_sound_at(knifeslicesound, victim->coords);
3070 //victim->jointVel(abdomen)+=relative*damagemult*200;
3071 if (Animation::animations[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
3072 if (victim->id != 0 || difficulty == 2) {
3073 victim->frameTarget = 0;
3074 victim->animTarget = staggerbackhardanim;
3075 victim->targetyaw = targetyaw + 180;
3079 victim->lowreversaldelay = 0;
3080 victim->highreversaldelay = 0;
3081 if (aitype != playercontrolled) {
3082 weaponmissdelay = .6;
3085 if (!Tutorial::active) {
3086 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3087 weapons[weaponids[weaponactive]].bloody = 1;
3089 weapons[weaponids[weaponactive]].blooddrip += 3;
3092 XYZ footvel, footpoint;
3094 if (skeleton.free) {
3095 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
3097 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
3099 if (Tutorial::active) {
3100 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .6, .3);
3103 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .6, .3);
3105 footvel = DoRotation(facing, 0, 90, 0) * .8;
3106 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3107 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3108 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3109 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3111 victim->DoDamage(damagemult * 0);
3115 if (animTarget == swordslashanim && Animation::animations[animTarget].frames[frameCurrent].label == 5 && victim->animTarget != rollanim) {
3116 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) {
3117 if (victim->weaponactive == -1 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) {
3118 award_bonus(id, Slashbonus);
3120 if (!Tutorial::active) {
3121 if (normaldotproduct(victim->facing, victim->coords - coords) < 0) {
3122 victim->DoBloodBig(2 / victim->armorhigh, 190);
3124 victim->DoBloodBig(2 / victim->armorhigh, 185);
3126 victim->deathbleeding = 1;
3127 emit_sound_at(swordslicesound, victim->coords);
3128 victim->frameTarget = 0;
3129 victim->animTarget = staggerbackhardanim;
3130 victim->targetyaw = targetyaw + 180;
3132 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3133 weapons[weaponids[weaponactive]].bloody = 1;
3135 weapons[weaponids[weaponactive]].blooddrip += 3;
3137 float bloodlossamount;
3138 bloodlossamount = 200 + abs((float)(Random() % 40)) - 20;
3139 victim->bloodloss += bloodlossamount / victim->armorhigh;
3140 victim->DoDamage(damagemult * 0);
3142 XYZ footvel, footpoint;
3144 if (skeleton.free) {
3145 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
3147 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
3150 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3152 footvel = DoRotation(facing, 0, 90, 0) * .8;
3154 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3155 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3156 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3157 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3160 if (victim->weaponactive != -1) {
3161 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
3162 if (weapons[victim->weaponids[0]].getType() == staff) {
3163 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3165 if (weapons[weaponids[0]].getType() == staff) {
3166 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3169 emit_sound_at(swordstaffsound, victim->coords);
3171 emit_sound_at(metalhitsound, victim->coords);
3176 victim->Puff(righthand);
3178 victim->frameTarget = 0;
3179 victim->animTarget = staggerbackhighanim;
3180 victim->targetyaw = targetyaw + 180;
3182 aim = DoRotation(facing, 0, 90, 0) * 21;
3184 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
3185 victim->num_weapons--;
3186 if (victim->num_weapons) {
3187 victim->weaponids[0] = victim->weaponids[num_weapons];
3188 if (victim->weaponstuck == victim->num_weapons) {
3189 victim->weaponstuck = 0;
3192 victim->weaponactive = -1;
3193 for (unsigned i = 0; i < Person::players.size(); i++) {
3194 Person::players[i]->wentforweapon = 0;
3200 if (animTarget == staffhitanim && Animation::animations[animTarget].frames[frameCurrent].label == 5 && victim->animTarget != rollanim) {
3201 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
3202 if (!Tutorial::active) {
3203 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 250;
3208 if (Random() % 2 || creature == wolftype) {
3211 emit_sound_at(staffheadsound, victim->coords);
3215 relative = victim->coords - coords;
3217 Normalise(&relative);
3218 relative = DoRotation(relative, 0, 90, 0);
3220 Normalise(&relative);
3221 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3222 victim->skeleton.joints[i].velocity += relative * damagemult * 60;
3224 victim->jointVel(head) += relative * damagemult * 230;
3225 victim->jointVel(neck) += relative * damagemult * 230;
3227 if (!Tutorial::active) {
3228 victim->DoDamage(damagemult * 120 / victim->protectionhigh);
3230 award_bonus(id, solidhit, 30);
3235 if (animTarget == staffspinhitanim && Animation::animations[animTarget].frames[frameCurrent].label == 5 && victim->animTarget != rollanim) {
3236 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
3237 if (!Tutorial::active) {
3238 weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250;
3243 if (Random() % 2 || creature == wolftype) {
3246 emit_sound_at(staffheadsound, victim->coords);
3250 relative = victim->coords - coords;
3252 Normalise(&relative);
3253 relative = DoRotation(relative, 0, -90, 0);
3254 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3255 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3257 victim->jointVel(head) += relative * damagemult * 220;
3258 victim->jointVel(neck) += relative * damagemult * 220;
3260 if (!Tutorial::active) {
3261 victim->DoDamage(damagemult * 350 / victim->protectionhead);
3263 award_bonus(id, solidhit, 60);
3268 if (animTarget == staffgroundsmashanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3269 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) {
3271 if (!Tutorial::active) {
3272 if (!victim->dead) {
3273 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500;
3278 if (Random() % 2 || creature == wolftype) {
3281 emit_sound_at(staffbodysound, victim->coords);
3283 victim->skeleton.longdead = 0;
3284 victim->skeleton.free = 1;
3285 victim->skeleton.broken = 0;
3287 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3288 victim->skeleton.joints[i].velchange = 0;
3289 victim->skeleton.joints[i].locked = 0;
3290 //victim->skeleton.joints[i].velocity=0;
3297 Normalise(&relative);
3298 if (!victim->dead) {
3299 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3300 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
3302 victim->jointVel(abdomen) += relative * damagemult * 40;
3305 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3306 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
3309 victim->Puff(abdomen);
3310 if (!Tutorial::active) {
3311 victim->DoDamage(damagemult * 100 / victim->protectionhigh);
3313 if (!victim->dead) {
3314 award_bonus(id, solidhit, 40);
3320 if (animTarget == lowkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3321 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != highheight) {
3327 relative = victim->coords - coords;
3329 Normalise(&relative);
3333 if (Animation::animations[victim->animTarget].height == lowheight) {
3339 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3340 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3342 victim->jointVel(head) += relative * damagemult * 200;
3343 if (!Tutorial::active) {
3344 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3347 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3348 if (victim->howactive == typesleeping) {
3349 victim->DoDamage(damagemult * 150 / victim->protectionhead);
3351 if (creature == wolftype) {
3352 emit_sound_at(clawslicesound, victim->coords, 128.);
3354 victim->DoBloodBig(2 / victim->armorhead, 175);
3357 if (victim->damage >= victim->damagetolerance) {
3360 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3361 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3363 victim->jointVel(abdomen) += relative * damagemult * 200;
3364 victim->frameTarget = 0;
3365 victim->animTarget = staggerbackhighanim;
3366 victim->targetyaw = targetyaw + 180;
3368 if (!Tutorial::active) {
3369 emit_sound_at(landsound2, victim->coords, 128.);
3371 victim->Puff(abdomen);
3372 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3373 if (creature == wolftype) {
3374 emit_sound_at(clawslicesound, victim->coords, 128.);
3376 victim->DoBloodBig(2 / victim->armorhigh, 170);
3382 if (animTarget == sweepanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3383 if ((victim->animTarget != jumpupanim) &&
3384 (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) &&
3385 (victim != this->shared_from_this())) {
3390 if (!Tutorial::active) {
3391 emit_sound_at(landsound2, victim->coords, 128.);
3394 relative = victim->coords - coords;
3396 Normalise(&relative);
3398 if (Animation::animations[victim->animTarget].height == middleheight || Animation::animations[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
3401 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3402 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
3404 relative = DoRotation(relative, 0, -90, 0);
3406 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3407 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) {
3408 victim->skeleton.joints[i].velocity = relative * 80;
3411 victim->Puff(rightankle);
3412 victim->Puff(leftankle);
3413 victim->DoDamage(damagemult * 40 / victim->protectionlow);
3415 if (victim->damage >= victim->damagetolerance) {
3418 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3419 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3421 relative = DoRotation(relative, 0, -90, 0);
3422 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3423 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) {
3424 victim->skeleton.joints[i].velocity += relative * damagemult * 80;
3427 victim->jointVel(abdomen) += relative * damagemult * 200;
3428 victim->frameTarget = 0;
3429 victim->animTarget = staggerbackhighanim;
3430 victim->targetyaw = targetyaw + 180;
3432 if (!Tutorial::active) {
3433 emit_sound_at(landsound2, victim->coords, 128.);
3435 victim->Puff(abdomen);
3436 victim->DoDamage(damagemult * 30 / victim->protectionlow);
3443 if (Animation::animations[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) {
3444 if (animTarget == spinkickreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3453 if (!Tutorial::active) {
3454 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3456 if (creature == wolftype) {
3457 emit_sound_at(clawslicesound, victim->coords, 128);
3459 victim->DoBloodBig(2 / victim->armorhigh, 170);
3463 relative = victim->coords - oldcoords;
3465 Normalise(&relative);
3466 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3467 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3469 victim->jointVel(abdomen) += relative * damagemult * 200;
3470 victim->Puff(abdomen);
3471 victim->DoDamage(damagemult * 150 / victim->protectionhigh);
3473 award_bonus(id, Reversal);
3476 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3477 if (victim->weaponactive != -1 && victim->num_weapons > 0) {
3478 if (weapons[victim->weaponids[victim->weaponactive]].owner == int(victim->id)) {
3479 takeWeapon(victim->weaponids[victim->weaponactive]);
3480 victim->num_weapons--;
3481 if (victim->num_weapons > 0) {
3482 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
3484 victim->weaponactive = -1;
3489 if (animTarget == staffhitreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3498 emit_sound_at(whooshhitsound, victim->coords, 128.);
3501 relative = victim->coords - oldcoords;
3503 Normalise(&relative);
3504 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3505 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3507 victim->jointVel(abdomen) += relative * damagemult * 200;
3509 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3512 if (animTarget == staffspinhitreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3522 award_bonus(id, staffreversebonus);
3524 if (!Tutorial::active) {
3525 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3528 award_bonus(id, staffreversebonus); // Huh, again?
3531 relative = victim->coords - oldcoords;
3533 Normalise(&relative);
3534 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3535 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3537 victim->jointVel(abdomen) += relative * damagemult * 200;
3539 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3542 if (animTarget == upunchreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3548 Normalise(&relative);
3550 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3551 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3553 victim->jointVel(lefthand) *= .1;
3554 victim->jointVel(leftwrist) *= .2;
3555 victim->jointVel(leftelbow) *= .5;
3556 victim->jointVel(leftshoulder) *= .7;
3557 victim->jointVel(righthand) *= .1;
3558 victim->jointVel(rightwrist) *= .2;
3559 victim->jointVel(rightelbow) *= .5;
3560 victim->jointVel(rightshoulder) *= .7;
3562 victim->Puff(abdomen);
3563 victim->DoDamage(damagemult * 90 / victim->protectionhigh);
3565 award_bonus(id, Reversal);
3569 if (weaponactive != -1 || creature == wolftype) {
3572 if (creature == rabbittype && weaponactive != -1) {
3573 if (weapons[weaponids[0]].getType() == staff) {
3578 if (weaponactive != -1) {
3579 victim->DoBloodBig(2 / victim->armorhigh, 225);
3580 emit_sound_at(knifeslicesound, victim->coords);
3581 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3582 weapons[weaponids[weaponactive]].bloody = 1;
3584 weapons[weaponids[weaponactive]].blooddrip += 3;
3586 if (weaponactive == -1 && creature == wolftype) {
3587 emit_sound_at(clawslicesound, victim->coords, 128.);
3589 victim->DoBloodBig(2 / victim->armorhigh, 175);
3594 if (animTarget == swordslashreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3600 Normalise(&relative);
3602 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3603 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3605 victim->jointVel(lefthand) *= .1 - 1;
3606 victim->jointVel(leftwrist) *= .2 - 1;
3607 victim->jointVel(leftelbow) *= .5 - 1;
3608 victim->jointVel(leftshoulder) *= .7 - 1;
3609 victim->jointVel(righthand) *= .1 - 1;
3610 victim->jointVel(rightwrist) *= .2 - 1;
3611 victim->jointVel(rightelbow) *= .5 - 1;
3612 victim->jointVel(rightshoulder) *= .7 - 1;
3614 award_bonus(id, swordreversebonus);
3617 if (hasvictim && animTarget == knifeslashreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3626 if (!Tutorial::active) {
3627 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3631 relative = victim->coords - oldcoords;
3633 Normalise(&relative);
3634 relative = DoRotation(relative, 0, -90, 0);
3635 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3636 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3638 victim->jointVel(abdomen) += relative * damagemult * 200;
3639 victim->Puff(abdomen);
3640 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3642 award_bonus(id, Reversal);
3645 if (hasvictim && animTarget == sneakattackanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3648 victim->skeleton.spinny = 0;
3650 relative = facing * -1;
3652 Normalise(&relative);
3653 if (victim->id == 0) {
3656 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3657 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3659 victim->damage = victim->damagetolerance;
3660 victim->permanentdamage = victim->damagetolerance - 1;
3663 if (weaponactive != -1 || creature == wolftype) {
3666 if (creature == rabbittype && weaponactive != -1) {
3667 if (weapons[weaponids[0]].getType() == staff) {
3672 if (weaponactive != -1) {
3673 victim->DoBloodBig(200, 225);
3674 emit_sound_at(knifeslicesound, victim->coords);
3676 weapons[weaponids[weaponactive]].bloody = 2;
3678 weapons[weaponids[weaponactive]].blooddrip += 5;
3681 if (creature == wolftype && weaponactive == -1) {
3682 emit_sound_at(clawslicesound, victim->coords, 128.);
3684 victim->DoBloodBig(2, 175);
3687 award_bonus(id, spinecrusher);
3690 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3691 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3693 if (animTarget == knifefollowanim) {
3694 victim->DoBloodBig(200, 210);
3696 if (animTarget == knifesneakattackanim) {
3697 XYZ footvel, footpoint;
3699 footpoint = weapons[weaponids[0]].tippoint;
3701 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3703 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3704 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3705 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3706 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3707 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3708 victim->DoBloodBig(200, 195);
3709 award_bonus(id, tracheotomy);
3711 if (animTarget == knifefollowanim) {
3712 award_bonus(id, Stabbonus);
3713 XYZ footvel, footpoint;
3715 footpoint = weapons[weaponids[0]].tippoint;
3717 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3719 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3720 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3721 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3722 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3723 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3725 victim->bloodloss += 10000;
3726 victim->velocity = 0;
3727 emit_sound_at(fleshstabsound, victim->coords);
3729 weapons[weaponids[weaponactive]].bloody = 2;
3731 weapons[weaponids[weaponactive]].blooddrip += 5;
3735 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && Animation::animations[animTarget].frames[frameCurrent].label == 6) {
3737 victim->velocity = 0;
3738 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3739 victim->skeleton.joints[i].velocity = 0;
3741 if (animTarget == knifefollowanim) {
3743 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3744 victim->skeleton.joints[i].velocity = 0;
3747 if (weaponactive != -1 && Animation::animations[victim->animTarget].attack != reversal) {
3748 emit_sound_at(fleshstabremovesound, victim->coords);
3750 weapons[weaponids[weaponactive]].bloody = 2;
3752 weapons[weaponids[weaponactive]].blooddrip += 5;
3754 XYZ footvel, footpoint;
3756 footpoint = weapons[weaponids[0]].tippoint;
3758 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3760 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3761 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3762 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3763 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3764 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3768 if (hasvictim && (animTarget == swordsneakattackanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3769 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3770 award_bonus(id, backstab);
3774 XYZ footvel, footpoint;
3776 footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2;
3778 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3780 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3781 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3782 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3783 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 5, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3784 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3785 victim->DoBloodBig(200, 180);
3786 victim->DoBloodBig(200, 215);
3787 victim->bloodloss += 10000;
3788 victim->velocity = 0;
3789 emit_sound_at(fleshstabsound, victim->coords);
3791 weapons[weaponids[weaponactive]].bloody = 2;
3793 weapons[weaponids[weaponactive]].blooddrip += 5;
3797 if (hasvictim && animTarget == swordsneakattackanim && Animation::animations[animTarget].frames[frameCurrent].label == 6) {
3799 victim->velocity = 0;
3800 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3801 victim->skeleton.joints[i].velocity = 0;
3803 if (weaponactive != -1) {
3804 emit_sound_at(fleshstabremovesound, victim->coords);
3806 weapons[weaponids[weaponactive]].bloody = 2;
3808 weapons[weaponids[weaponactive]].blooddrip += 5;
3810 XYZ footvel, footpoint;
3812 footpoint = weapons[weaponids[0]].tippoint;
3814 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3816 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3817 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3818 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3819 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3820 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3824 if (animTarget == sweepreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3833 if (weaponactive == -1) {
3834 if (!Tutorial::active) {
3835 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3840 if (weaponactive != -1 || creature == wolftype) {
3843 if (creature == rabbittype && weaponactive != -1) {
3844 if (weapons[weaponids[0]].getType() == staff) {
3849 if (weaponactive != -1) {
3850 victim->DoBloodBig(2 / victim->armorhead, 225);
3851 emit_sound_at(knifeslicesound, victim->coords);
3852 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3853 weapons[weaponids[weaponactive]].bloody = 1;
3855 weapons[weaponids[weaponactive]].blooddrip += 3;
3857 if (weaponactive == -1 && creature == wolftype) {
3858 emit_sound_at(clawslicesound, victim->coords, 128.);
3860 victim->DoBloodBig(2 / victim->armorhead, 175);
3864 award_bonus(id, Reversal);
3869 relative = facing * -1;
3871 Normalise(&relative);
3872 relative = DoRotation(relative, 0, 90, 0);
3874 Normalise(&relative);
3875 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3876 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3878 victim->jointVel(head) += relative * damagemult * 200;
3879 if (victim->damage < victim->damagetolerance - 100) {
3880 victim->velocity = relative * 200;
3882 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3883 victim->velocity = 0;
3886 if (animTarget == sweepreversalanim && ((Animation::animations[animTarget].frames[frameCurrent].label == 9 && victim->damage < victim->damagetolerance) || (Animation::animations[animTarget].frames[frameCurrent].label == 7 && victim->damage > victim->damagetolerance))) {
3890 relative = facing * -1;
3892 Normalise(&relative);
3893 relative = DoRotation(relative, 0, 90, 0);
3895 Normalise(&relative);
3896 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3897 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3899 victim->jointVel(head) += relative * damagemult * 200;
3902 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim)) {
3903 if (victim->damage > victim->damagetolerance && bonus != reverseko) {
3904 award_bonus(id, reverseko);
3910 if (frameTarget > int(Animation::animations[animCurrent].frames.size()) - 1) {
3913 animTarget = getIdle();
3914 FootLand(leftfoot, 1);
3915 FootLand(rightfoot, 1);
3917 if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) {
3918 animTarget = rollanim;
3920 emit_sound_at(movewhooshsound, coords, 128.);
3922 if (animCurrent == staggerbackhighanim) {
3923 animTarget = getIdle();
3925 if (animCurrent == staggerbackhardanim) {
3926 animTarget = getIdle();
3928 if (animCurrent == removeknifeanim) {
3929 animTarget = getIdle();
3931 if (animCurrent == crouchremoveknifeanim) {
3932 animTarget = getCrouch();
3934 if (animCurrent == backhandspringanim) {
3935 animTarget = getIdle();
3937 if (animCurrent == dodgebackanim) {
3938 animTarget = getIdle();
3940 if (animCurrent == drawleftanim) {
3941 animTarget = getIdle();
3943 if (animCurrent == drawrightanim || animCurrent == crouchdrawrightanim) {
3944 animTarget = getIdle();
3945 if (animCurrent == crouchdrawrightanim) {
3946 animTarget = getCrouch();
3948 if (weaponactive == -1) {
3950 } else if (weaponactive == 0) {
3952 if (num_weapons == 2) {
3954 buffer = weaponids[0];
3955 weaponids[0] = weaponids[1];
3956 weaponids[1] = buffer;
3960 if (weaponactive == -1) {
3961 emit_sound_at(knifesheathesound, coords, 128.);
3963 if (weaponactive != -1) {
3964 emit_sound_at(knifedrawsound, coords, 128.);
3967 if (animCurrent == rollanim) {
3968 animTarget = getCrouch();
3969 FootLand(leftfoot, 1);
3970 FootLand(rightfoot, 1);
3973 if (animTarget == walljumprightkickanim) {
3976 if (animTarget == walljumpleftkickanim) {
3979 animTarget = jumpdownanim;
3981 if (animCurrent == climbanim) {
3982 animTarget = getCrouch();
3984 coords += facing * .1;
3985 if (!isnormal(coords.x)) {
3996 if (animTarget == rabbitkickreversalanim) {
3997 animTarget = getCrouch();
4000 if (animTarget == jumpreversalanim) {
4001 animTarget = getCrouch();
4004 if (animTarget == walljumprightanim || animTarget == walljumpbackanim || animTarget == walljumpfrontanim) {
4005 if (attackkeydown && animTarget != walljumpfrontanim) {
4007 float closestdist = -1;
4009 if (Person::players.size() > 1) {
4010 for (unsigned i = 0; i < Person::players.size(); i++) {
4011 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
4012 distance = distsq(&Person::players[i]->coords, &coords);
4013 if (closestdist == -1 || distance < closestdist) {
4014 closestdist = distance;
4020 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
4021 victim = Person::players[closest];
4022 animTarget = walljumprightkickanim;
4024 XYZ rotatetarget = victim->coords - coords;
4025 Normalise(&rotatetarget);
4026 yaw = -asin(0 - rotatetarget.x);
4028 if (rotatetarget.z < 0) {
4031 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
4032 velocity = (victim->coords - coords) * 4;
4037 if (animTarget == walljumpbackanim) {
4038 animTarget = backflipanim;
4040 velocity = facing * -8;
4043 resume_stream(whooshsound);
4046 if (animTarget == walljumprightanim) {
4047 animTarget = rightflipanim;
4051 velocity = DoRotation(facing, 0, 30, 0) * -8;
4054 if (animTarget == walljumpfrontanim) {
4055 animTarget = frontflipanim;
4059 velocity = facing * 8;
4063 resume_stream(whooshsound);
4066 if (animTarget == walljumpleftanim) {
4067 if (attackkeydown) {
4069 float closestdist = -1;
4071 if (Person::players.size() > 1) {
4072 for (unsigned i = 0; i < Person::players.size(); i++) {
4073 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
4074 distance = distsq(&Person::players[i]->coords, &coords);
4075 if (closestdist == -1 || distance < closestdist) {
4076 closestdist = distance;
4082 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
4083 victim = Person::players[closest];
4084 animTarget = walljumpleftkickanim;
4086 XYZ rotatetarget = victim->coords - coords;
4087 Normalise(&rotatetarget);
4088 yaw = -asin(0 - rotatetarget.x);
4090 if (rotatetarget.z < 0) {
4093 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
4094 velocity = (victim->coords - coords) * 4;
4099 if (animTarget != walljumpleftkickanim) {
4100 animTarget = leftflipanim;
4104 velocity = DoRotation(facing, 0, -30, 0) * -8;
4108 resume_stream(whooshsound);
4111 if (animTarget == sneakattackanim) {
4112 animCurrent = getCrouch();
4113 animTarget = getCrouch();
4120 transspeed = 1000000;
4121 targetheadyaw += 180;
4122 coords -= facing * .7;
4124 coords.y = terrain.getHeight(coords.x, coords.z);
4129 if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) {
4130 animTarget = getIdle();
4133 coords.y = terrain.getHeight(coords.x, coords.z);
4138 if (animCurrent == knifefollowanim) {
4139 animTarget = getIdle();
4142 if (Animation::animations[animTarget].attack == reversal && animCurrent != sneakattackanim && animCurrent != knifesneakattackanim && animCurrent != swordsneakattackanim && animCurrent != knifefollowanim) {
4143 float ycoords = oldcoords.y;
4144 animTarget = getStop();
4149 transspeed = 1000000;
4150 targetheadyaw += 180;
4151 if (!isnormal(coords.x)) {
4154 if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim) {
4155 oldcoords = coords + facing * .5;
4156 } else if (animCurrent == sweepreversalanim) {
4157 oldcoords = coords + facing * 1.1;
4158 } else if (animCurrent == upunchreversalanim) {
4159 oldcoords = coords + facing * 1.5;
4162 targetheadyaw += 180;
4165 } else if (animCurrent == knifeslashreversalanim) {
4166 oldcoords = coords + facing * .5;
4169 targetheadyaw += 90;
4172 } else if (animCurrent == staffspinhitreversalanim) {
4175 targetheadyaw += 180;
4180 oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z);
4182 oldcoords.y = ycoords;
4184 currentoffset = coords - oldcoords;
4190 if (animCurrent == knifesneakattackedanim || animCurrent == swordsneakattackedanim) {
4195 if (Animation::animations[animTarget].attack == reversed) {
4197 if (animTarget == sweepreversedanim) {
4200 animTarget = backhandspringanim;
4202 emit_sound_at(landsound, coords, 128);
4204 if (animCurrent == upunchreversedanim || animCurrent == swordslashreversedanim) {
4205 animTarget = rollanim;
4208 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
4209 coords.y = oldcoords.y;
4211 if (animCurrent == knifeslashreversedanim) {
4212 animTarget = rollanim;
4217 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
4218 coords.y = oldcoords.y;
4222 animTarget = jumpdownanim;
4225 animTarget = getIdle();
4227 if (wasLandhard()) {
4228 animTarget = getIdle();
4230 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
4231 animTarget = getIdle();
4233 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
4234 coords.y = oldcoords.y;
4235 //coords+=DoRotation(Animation::animations[animCurrent].offset,0,yaw,0)*scale;
4236 targetoffset.y = coords.y;
4238 targetoffset.y = terrain.getHeight(coords.x, coords.z);
4240 currentoffset = DoRotation(Animation::animations[animCurrent].offset * -1, 0, yaw, 0) * scale;
4241 currentoffset.y -= (coords.y - targetoffset.y);
4242 coords.y = targetoffset.y;
4244 normalsupdatedelay = 0;
4246 if (animCurrent == upunchanim) {
4247 animTarget = getStop();
4248 normalsupdatedelay = 0;
4251 if (animCurrent == rabbitkickanim && animTarget != backflipanim) {
4255 if (num_weapons > 0) {
4256 if (weapons[0].getType() == staff) {
4265 rabbitkickragdoll = 1;
4267 if (animCurrent == rabbitkickreversedanim) {
4273 skeleton.spinny = 0;
4274 SolidHitBonus(!id); // FIXME: tricky id
4278 animTarget = rollanim;
4281 pause_sound(whooshsound);
4286 if (animCurrent == rabbittackledbackanim || animCurrent == rabbittackledfrontanim) {
4290 skeleton.spinny = 0;
4292 if (animCurrent == jumpreversedanim) {
4298 skeleton.spinny = 0;
4299 SolidHitBonus(!id); // FIXME: tricky id
4303 animTarget = rollanim;
4304 coords += facing * 2;
4306 pause_sound(whooshsound);
4312 if (Animation::animations[animCurrent].attack == normalattack && !victim->skeleton.free && victim->animTarget != staggerbackhighanim && victim->animTarget != staggerbackhardanim && animTarget != winduppunchblockedanim && animTarget != blockhighleftanim && animTarget != swordslashparryanim && animTarget != swordslashparriedanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim) {
4313 animTarget = getupfromfrontanim;
4315 } else if (Animation::animations[animCurrent].attack == normalattack) {
4316 animTarget = getIdle();
4319 if (animCurrent == blockhighleftanim && aitype != playercontrolled) {
4320 animTarget = blockhighleftstrikeanim;
4322 if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) {
4323 animTarget = getIdle();
4326 if (animCurrent == spinkickanim && victim->skeleton.free) {
4327 if (creature == rabbittype) {
4328 animTarget = fightidleanim;
4334 if (isIdle() && !wasIdle()) {
4335 normalsupdatedelay = 0;
4338 if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) {
4339 animTarget = jumpdownanim;
4342 if (!skeleton.free) {
4344 if (!transspeed && Animation::animations[animTarget].attack != 2 && Animation::animations[animTarget].attack != 3) {
4345 if (!isRun() || !wasRun()) {
4346 if (targetFrame().speed > currentFrame().speed) {
4347 target += multiplier * targetFrame().speed * speed * 2;
4349 if (targetFrame().speed <= currentFrame().speed) {
4350 target += multiplier * currentFrame().speed * speed * 2;
4353 if (isRun() && wasRun()) {
4355 tempspeed = velspeed;
4356 if (tempspeed < 10 * speedmult) {
4357 tempspeed = 10 * speedmult;
4359 /* FIXME - mixed of target and current here, is that intended? */
4360 target += multiplier * Animation::animations[animTarget].frames[frameCurrent].speed * speed * 1.7 * tempspeed / (speed * 45 * scale);
4362 } else if (transspeed) {
4363 target += multiplier * transspeed * speed * 2;
4365 if (!isRun() || !wasRun()) {
4366 if (targetFrame().speed > currentFrame().speed) {
4367 target += multiplier * targetFrame().speed * 2;
4369 if (targetFrame().speed <= currentFrame().speed) {
4370 target += multiplier * currentFrame().speed * 2;
4375 if (animCurrent != animTarget) {
4376 target = (target + oldtarget) / 2;
4380 frameCurrent = frameTarget;
4384 rot = targetrot * target;
4385 yaw += rot - oldrot;
4391 if (frameCurrent >= int(Animation::animations[animCurrent].frames.size())) {
4392 frameCurrent = Animation::animations[animCurrent].frames.size() - 1;
4394 if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
4396 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4397 skeleton.joints[i].position = currentFrame().joints[i].position;
4400 skeleton.FindForwards();
4402 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4403 if (skeleton.muscles[i].visible) {
4404 skeleton.FindRotationMuscle(i, animTarget);
4407 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4408 if (skeleton.muscles[i].visible) {
4409 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100)) {
4410 skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4412 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100)) {
4413 skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4415 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100)) {
4416 skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4422 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4423 skeleton.joints[i].position = targetFrame().joints[i].position;
4426 skeleton.FindForwards();
4428 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4429 if (skeleton.muscles[i].visible) {
4430 skeleton.FindRotationMuscle(i, animTarget);
4433 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4434 if (skeleton.muscles[i].visible) {
4435 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100)) {
4436 skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4438 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100)) {
4439 skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4441 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100)) {
4442 skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4444 if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) {
4445 skeleton.muscles[i].newrotate3 -= 360;
4447 if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) {
4448 skeleton.muscles[i].newrotate3 += 360;
4450 if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) {
4451 skeleton.muscles[i].newrotate2 -= 360;
4453 if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) {
4454 skeleton.muscles[i].newrotate2 += 360;
4456 if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) {
4457 skeleton.muscles[i].newrotate1 -= 360;
4459 if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) {
4460 skeleton.muscles[i].newrotate1 += 360;
4466 oldanimCurrent = animCurrent;
4467 oldanimTarget = animTarget;
4468 oldframeTarget = frameTarget;
4469 oldframeCurrent = frameCurrent;
4471 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4472 skeleton.joints[i].velocity = (currentFrame().joints[i].position * (1 - target) + targetFrame().joints[i].position * target - skeleton.joints[i].position) / multiplier;
4473 skeleton.joints[i].position = currentFrame().joints[i].position * (1 - target) + targetFrame().joints[i].position * target;
4475 offset = currentoffset * (1 - target) + targetoffset * target;
4476 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4477 if (skeleton.muscles[i].visible) {
4478 skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * target;
4479 skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * target;
4480 skeleton.muscles[i].rotate3 = skeleton.muscles[i].oldrotate3 * (1 - target) + skeleton.muscles[i].newrotate3 * target;
4485 if (isLanding() && landhard) {
4489 animTarget = getLandhard();
4502 void Person::DoStuff()
4504 static XYZ terrainnormal;
4505 static XYZ flatfacing;
4506 static XYZ flatvelocity;
4507 static float flatvelspeed;
4508 static int bloodsize;
4509 static int startx, starty, endx, endy;
4510 static GLubyte color;
4511 static XYZ bloodvel;
4513 onfiredelay -= multiplier;
4514 if (onfiredelay < 0 && onfire) {
4515 if (Random() % 2 == 0) {
4521 crouchkeydowntime += multiplier;
4522 if (!crouchkeydown) {
4523 crouchkeydowntime = 0;
4525 jumpkeydowntime += multiplier;
4526 if (!jumpkeydown && skeleton.free) {
4527 jumpkeydowntime = 0;
4530 if (hostile || damage > 0 || bloodloss > 0) {
4534 if (isIdle() || isRun()) {
4538 if (num_weapons == 1 && weaponactive != -1) {
4543 blooddimamount -= multiplier * .3;
4545 speechdelay -= multiplier;
4546 texupdatedelay -= multiplier;
4547 interestdelay -= multiplier;
4548 flamedelay -= multiplier;
4549 parriedrecently -= multiplier;
4551 victim = this->shared_from_this();
4556 speed = 1.1 * speedmult;
4558 speed = 1.0 * speedmult;
4560 if (!skeleton.free) {
4561 rabbitkickragdoll = 0;
4566 if (id != 0 && (creature == rabbittype || difficulty != 2)) {
4569 if (id != 0 && creature == wolftype && difficulty == 2) {
4571 if (aitype != passivetype) {
4573 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) {
4580 if (animTarget == wolfrunninganim && !superruntoggle) {
4581 animTarget = getRun();
4585 if (weaponactive == -1 && num_weapons > 0) {
4586 if (weapons[weaponids[0]].getType() == staff) {
4592 burnt += multiplier;
4597 OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3);
4599 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
4606 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc);
4607 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
4611 while (flamedelay < 0 && onfire) {
4613 int howmany = fabs(Random() % (skeleton.joints.size()));
4614 if (skeleton.free) {
4615 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4616 flatfacing = skeleton.joints[howmany].position * scale + coords;
4618 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4619 flatvelocity = (coords - oldcoords) / multiplier / 2;
4621 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
4624 while (flamedelay < 0 && !onfire && Tutorial::active && id != 0) {
4626 int howmany = fabs(Random() % (skeleton.joints.size()));
4627 if (skeleton.free) {
4628 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4629 flatfacing = skeleton.joints[howmany].position * scale + coords;
4631 flatvelocity = (coords - oldcoords) / multiplier / 2;
4632 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4634 Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
4638 bleeding -= multiplier * .3;
4639 if (bloodtoggle == 2) {
4640 skeleton.drawmodel.textureptr.bind();
4641 if ((bleeding <= 0) && (detail != 2)) {
4647 if (neckspurtamount > 0) {
4648 neckspurtamount -= multiplier;
4649 neckspurtdelay -= multiplier * 3;
4650 neckspurtparticledelay -= multiplier * 3;
4651 if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
4654 if (skeleton.free) {
4655 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
4656 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4657 Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5) * scale + coords, bloodvel, 1, 1, 1, .05, .9);
4659 bloodvel.z = 5 * neckspurtamount;
4660 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4661 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
4662 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, .9);
4664 neckspurtparticledelay = .05;
4666 if (neckspurtdelay < 0) {
4671 if (deathbleeding > 0 && dead != 2) {
4672 if (deathbleeding < 5) {
4673 bleeddelay -= deathbleeding * multiplier / 4;
4675 bleeddelay -= 5 * multiplier / 4;
4677 if (bleeddelay < 0 && bloodtoggle) {
4682 if (skeleton.free) {
4683 bloodvel += DoRotation(jointVel(abdomen), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
4684 Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4686 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
4687 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4691 bloodloss += deathbleeding * multiplier * 80;
4692 deathbleeding -= multiplier * 1.6;
4693 if (deathbleeding < 0) {
4696 if (bloodloss > damagetolerance && Animation::animations[animTarget].attack == neutral) {
4697 if (weaponactive != -1) {
4698 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
4699 weapons[weaponids[0]].velocity.x += .01;
4702 weaponids[0] = weaponids[num_weapons];
4703 if (weaponstuck == num_weapons) {
4708 for (unsigned i = 0; i < Person::players.size(); i++) {
4709 Person::players[i]->wentforweapon = 0;
4717 if (!dead && creature == wolftype) {
4718 award_bonus(0, Wolfbonus);
4721 if (animTarget == knifefollowedanim && !skeleton.free) {
4722 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4723 skeleton.joints[i].velocity = 0;
4724 skeleton.joints[i].velocity.y = -2;
4727 if (id != 0 && unconscioustime > .1) {
4735 if (texupdatedelay < 0 && bleeding > 0 && bloodtoggle == 2 && distsq(&viewer, &coords) < 9) {
4736 texupdatedelay = .12;
4738 bloodsize = 5 - realtexdetail;
4742 startx = bleedy; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4743 starty = bleedx; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4744 endx = startx + bloodsize;
4745 endy = starty + bloodsize;
4755 if (endx > skeleton.skinsize - 1) {
4756 endx = skeleton.skinsize - 1;
4759 if (endy > skeleton.skinsize - 1) {
4760 endy = skeleton.skinsize - 1;
4763 if (endx < startx) {
4766 if (endy < starty) {
4770 for (int i = startx; i < endx; i++) {
4771 for (int j = starty; j < endy; j++) {
4772 if (Random() % 2 == 0) {
4773 color = Random() % 85 + 170;
4774 if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2) {
4775 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2;
4777 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0;
4778 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0;
4783 skeleton.drawmodel.textureptr.bind();
4787 if (skeleton.free) {
4788 bleedx += 4 * direction / realtexdetail;
4790 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4792 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4795 bleedy -= 4 / realtexdetail;
4797 bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4799 bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4804 if (abs(righthandmorphness - targetrighthandmorphness) < multiplier * 4) {
4805 righthandmorphness = targetrighthandmorphness;
4806 righthandmorphstart = righthandmorphend;
4807 } else if (righthandmorphness > targetrighthandmorphness) {
4808 righthandmorphness -= multiplier * 4;
4809 } else if (righthandmorphness < targetrighthandmorphness) {
4810 righthandmorphness += multiplier * 4;
4813 if (abs(lefthandmorphness - targetlefthandmorphness) < multiplier * 4) {
4814 lefthandmorphness = targetlefthandmorphness;
4815 lefthandmorphstart = lefthandmorphend;
4816 } else if (lefthandmorphness > targetlefthandmorphness) {
4817 lefthandmorphness -= multiplier * 4;
4818 } else if (lefthandmorphness < targetlefthandmorphness) {
4819 lefthandmorphness += multiplier * 4;
4822 if (creature == rabbittype || targettailmorphness == 5 || targettailmorphness == 0) {
4823 if (abs(tailmorphness - targettailmorphness) < multiplier * 10) {
4824 tailmorphness = targettailmorphness;
4825 tailmorphstart = tailmorphend;
4826 } else if (tailmorphness > targettailmorphness) {
4827 tailmorphness -= multiplier * 10;
4828 } else if (tailmorphness < targettailmorphness) {
4829 tailmorphness += multiplier * 10;
4833 if (creature == wolftype) {
4834 if (abs(tailmorphness - targettailmorphness) < multiplier * 4) {
4835 tailmorphness = targettailmorphness;
4836 tailmorphstart = tailmorphend;
4837 } else if (tailmorphness > targettailmorphness) {
4838 tailmorphness -= multiplier * 2;
4839 } else if (tailmorphness < targettailmorphness) {
4840 tailmorphness += multiplier * 2;
4844 if (headmorphend == 3 || headmorphstart == 3) {
4845 if (abs(headmorphness - targetheadmorphness) < multiplier * 7) {
4846 headmorphness = targetheadmorphness;
4847 headmorphstart = headmorphend;
4848 } else if (headmorphness > targetheadmorphness) {
4849 headmorphness -= multiplier * 7;
4850 } else if (headmorphness < targetheadmorphness) {
4851 headmorphness += multiplier * 7;
4853 } else if (headmorphend == 5 || headmorphstart == 5) {
4854 if (abs(headmorphness - targetheadmorphness) < multiplier * 10) {
4855 headmorphness = targetheadmorphness;
4856 headmorphstart = headmorphend;
4857 } else if (headmorphness > targetheadmorphness) {
4858 headmorphness -= multiplier * 10;
4859 } else if (headmorphness < targetheadmorphness) {
4860 headmorphness += multiplier * 10;
4863 if (abs(headmorphness - targetheadmorphness) < multiplier * 4) {
4864 headmorphness = targetheadmorphness;
4865 headmorphstart = headmorphend;
4866 } else if (headmorphness > targetheadmorphness) {
4867 headmorphness -= multiplier * 4;
4868 } else if (headmorphness < targetheadmorphness) {
4869 headmorphness += multiplier * 4;
4873 if (abs(chestmorphness - targetchestmorphness) < multiplier) {
4874 chestmorphness = targetchestmorphness;
4875 chestmorphstart = chestmorphend;
4876 } else if (chestmorphness > targetchestmorphness) {
4877 chestmorphness -= multiplier;
4878 } else if (chestmorphness < targetchestmorphness) {
4879 chestmorphness += multiplier;
4882 if (dead != 2 && howactive <= typesleeping) {
4883 if (chestmorphstart == 0 && chestmorphend == 0) {
4885 targetchestmorphness = 1;
4888 if (chestmorphstart != 0 && chestmorphend != 0) {
4890 targetchestmorphness = 1;
4892 if (environment == snowyenvironment) {
4895 if (skeleton.free) {
4896 footvel = skeleton.specialforward[0] * -1;
4897 footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
4899 footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
4900 footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
4902 if (animTarget == sleepanim) {
4903 footvel = DoRotation(footvel, 0, 90, 0);
4905 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
4909 if (!dead && howactive < typesleeping) {
4910 blinkdelay -= multiplier * 2;
4911 if (headmorphstart == 0 && headmorphend == 0 && blinkdelay <= 0) {
4913 targetheadmorphness = 1;
4915 blinkdelay = (float)(abs(Random() % 40)) / 5;
4917 if (headmorphstart == 3 && headmorphend == 3) {
4919 targetheadmorphness = 1;
4924 twitchdelay -= multiplier * 1.5;
4925 if (animTarget != hurtidleanim) {
4926 if (headmorphstart == 0 && headmorphend == 0 && twitchdelay <= 0) {
4928 targetheadmorphness = 1;
4930 twitchdelay = (float)(abs(Random() % 40)) / 5;
4932 if (headmorphstart == 5 && headmorphend == 5) {
4934 targetheadmorphness = 1;
4938 if ((isIdle() || isCrouch()) && animTarget != hurtidleanim) {
4939 twitchdelay3 -= multiplier * 1;
4940 if (Random() % 2 == 0) {
4941 if (righthandmorphstart == 0 && righthandmorphend == 0 && twitchdelay3 <= 0) {
4942 righthandmorphness = 0;
4943 targetrighthandmorphness = 1;
4944 righthandmorphend = 1;
4945 if (Random() % 2 == 0) {
4946 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4949 if (righthandmorphstart == 1 && righthandmorphend == 1) {
4950 righthandmorphness = 0;
4951 targetrighthandmorphness = 1;
4952 righthandmorphend = 0;
4955 if (Random() % 2 == 0) {
4956 if (lefthandmorphstart == 0 && lefthandmorphend == 0 && twitchdelay3 <= 0) {
4957 lefthandmorphness = 0;
4958 targetlefthandmorphness = 1;
4959 lefthandmorphend = 1;
4960 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4962 if (lefthandmorphstart == 1 && lefthandmorphend == 1) {
4963 lefthandmorphness = 0;
4964 targetlefthandmorphness = 1;
4965 lefthandmorphend = 0;
4971 if (creature == rabbittype) {
4972 if (howactive < typesleeping) {
4973 twitchdelay2 -= multiplier * 1.5;
4975 twitchdelay2 -= multiplier * 0.5;
4977 if (howactive <= typesleeping) {
4978 if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) {
4980 targettailmorphness = 1;
4982 twitchdelay2 = (float)(abs(Random() % 40)) / 5;
4984 if (tailmorphstart == 1 && tailmorphend == 1) {
4986 targettailmorphness = 1;
4989 if (tailmorphstart == 2 && tailmorphend == 2) {
4991 targettailmorphness = 1;
4998 if (creature == wolftype) {
4999 twitchdelay2 -= multiplier * 1.5;
5000 if (tailmorphend != 0) {
5001 if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) {
5003 targettailmorphness = 1;
5008 if (tailmorphend != 5) {
5009 if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) {
5011 targettailmorphness = 1;
5016 if (twitchdelay2 <= 0) {
5017 if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) {
5019 targettailmorphness = 1;
5022 if (tailmorphstart == 1 && tailmorphend == 1) {
5024 targettailmorphness = 1;
5027 if (tailmorphstart == 2 && tailmorphend == 2) {
5029 targettailmorphness = 1;
5032 if (tailmorphstart == 3 && tailmorphend == 3) {
5034 targettailmorphness = 1;
5037 if (tailmorphstart == 4 && tailmorphend == 4) {
5039 targettailmorphness = 1;
5046 unconscioustime = 0;
5049 if (dead == 1 || howactive == typesleeping) {
5050 unconscioustime += multiplier;
5051 //If unconscious, close eyes and mouth
5052 if (righthandmorphend != 0) {
5053 righthandmorphness = 0;
5055 righthandmorphend = 0;
5056 targetrighthandmorphness = 1;
5058 if (lefthandmorphend != 0) {
5059 lefthandmorphness = 0;
5061 lefthandmorphend = 0;
5062 targetlefthandmorphness = 1;
5064 if (headmorphend != 3 && headmorphend != 5) {
5068 targetheadmorphness = 1;
5071 if (howactive > typesleeping) {
5074 if (bloodtoggle && !bled) {
5075 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
5076 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
5077 unsigned int j = terrain.patchobjects[whichpatchx][whichpatchz][l];
5078 XYZ point = DoRotation(headpoint - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
5082 Object::objects[j]->model.MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
5088 if (dead == 2 || howactive > typesleeping) {
5089 //If dead, open mouth and hands
5090 if (righthandmorphend != 0) {
5091 righthandmorphness = 0;
5093 righthandmorphend = 0;
5094 targetrighthandmorphness = 1;
5096 if (lefthandmorphend != 0) {
5097 lefthandmorphness = 0;
5099 lefthandmorphend = 0;
5100 targetlefthandmorphness = 1;
5102 if (headmorphend != 2) {
5106 targetheadmorphness = 1;
5109 if (stunned > 0 && !dead && headmorphend != 2) {
5110 if (headmorphend != 4) {
5114 targetheadmorphness = 1;
5117 if (damage > damagetolerance && !dead) {
5120 unconscioustime = 0;
5122 if (creature == wolftype) {
5123 award_bonus(0, Wolfbonus);
5128 if (weaponactive != -1) {
5129 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
5130 weapons[weaponids[0]].velocity.x += .01;
5133 weaponids[0] = weaponids[num_weapons];
5134 if (weaponstuck == num_weapons) {
5139 for (unsigned i = 0; i < Person::players.size(); i++) {
5140 Person::players[i]->wentforweapon = 0;
5144 if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) {
5153 damage -= multiplier * 13;
5154 permanentdamage -= multiplier * 4;
5155 if (isIdle() || isCrouch()) {
5156 permanentdamage -= multiplier * 4;
5162 if (permanentdamage < 0) {
5163 permanentdamage = 0;
5165 if (superpermanentdamage < 0) {
5166 superpermanentdamage = 0;
5168 if (permanentdamage < superpermanentdamage) {
5169 permanentdamage = superpermanentdamage;
5171 if (damage < permanentdamage) {
5172 damage = permanentdamage;
5174 if (dead == 1 && damage < damagetolerance) {
5178 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5179 skeleton.joints[i].velocity = 0;
5182 if (permanentdamage > damagetolerance && dead != 2) {
5185 if (weaponactive != -1) {
5186 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
5187 weapons[weaponids[0]].velocity.x += .01;
5190 weaponids[0] = weaponids[num_weapons];
5191 if (weaponstuck == num_weapons) {
5196 for (unsigned i = 0; i < Person::players.size(); i++) {
5197 Person::players[i]->wentforweapon = 0;
5203 if (!dead && creature == wolftype) {
5204 award_bonus(0, Wolfbonus);
5207 if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance) {
5208 award_bonus(id, touchofdeath);
5210 if (id != 0 && unconscioustime > .1) {
5218 emit_sound_at(breaksound, coords);
5221 if (skeleton.free == 1) {
5223 pause_sound(whooshsound);
5227 //If knocked over, open hands and close mouth
5228 if (righthandmorphend != 0) {
5229 righthandmorphness = 0;
5231 righthandmorphend = 0;
5232 targetrighthandmorphness = 1;
5234 if (lefthandmorphend != 0) {
5235 lefthandmorphness = 0;
5237 lefthandmorphend = 0;
5238 targetlefthandmorphness = 1;
5240 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) {
5241 if (headmorphend != 0) {
5245 targetheadmorphness = 1;
5249 skeleton.DoGravity(&scale);
5251 damageamount = skeleton.DoConstraints(&coords, &scale) * 5;
5252 if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1)) {
5253 award_bonus(id, deepimpact);
5255 DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3));
5259 if (!skeleton.joints.empty()) {
5260 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
5261 average += skeleton.joints[j].position;
5263 average /= skeleton.joints.size();
5264 coords += average * scale;
5265 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
5266 skeleton.joints[j].position -= average;
5268 average /= multiplier;
5272 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5273 velocity += skeleton.joints[i].velocity * scale;
5275 velocity /= skeleton.joints.size();
5277 if (!isnormal(velocity.x) && velocity.x) {
5281 if (findLength(&average) < 10 && dead && skeleton.free) {
5282 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
5283 if (skeleton.longdead > 2000) {
5284 if (skeleton.longdead > 6000) {
5286 pause_sound(whooshsound);
5292 if (dead == 2 && bloodloss < damagetolerance) {
5294 headpoint = (jointPos(head) + jointPos(neck)) / 2 * scale + coords;
5296 if (bloodtoggle && !bled) {
5297 terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
5298 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
5299 unsigned int j = terrain.patchobjects[whichpatchx][whichpatchz][l];
5300 XYZ point = DoRotation(headpoint - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
5301 float size = .2 * 1.2;
5304 Object::objects[j]->model.MakeDecal(blooddecal, &point, &size, &opacity, &yaw);
5309 if (dead == 2 && bloodloss >= damagetolerance) {
5311 headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords;
5312 if (bleeding <= 0) {
5315 if (bloodtoggle && !bled) {
5316 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
5317 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
5318 unsigned int j = terrain.patchobjects[whichpatchx][whichpatchz][l];
5319 XYZ point = DoRotation(headpoint - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
5323 Object::objects[j]->model.MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
5331 if (!dead && crouchkeydown && skeleton.freetime > .5 && id == 0 && skeleton.free) {
5332 bool canrecover = 1;
5333 XYZ startpoint, endpoint, colpoint, colviewer, coltarget;
5334 startpoint = coords;
5337 if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1) {
5340 if (velocity.y < -30) {
5343 for (unsigned int i = 0; i < Object::objects.size(); i++) {
5344 if (Object::objects[i]->type != treeleavestype && Object::objects[i]->type != bushtype && Object::objects[i]->type != firetype) {
5345 colviewer = startpoint;
5346 coltarget = endpoint;
5347 if (Object::objects[i]->model.LineCheck(&colviewer, &coltarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
5357 terrainnormal = jointPos(groin) - jointPos(abdomen);
5358 if (joint(groin).locked && joint(abdomen).locked) {
5359 terrainnormal = jointPos(groin) - jointPos(abdomen);
5360 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
5362 if (joint(abdomen).locked && joint(neck).locked) {
5363 terrainnormal = jointPos(abdomen) - jointPos(neck);
5364 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
5366 if (joint(groin).locked && joint(neck).locked) {
5367 terrainnormal = jointPos(groin) - jointPos(neck);
5368 middle = (jointPos(groin) + jointPos(neck)) / 2;
5370 Normalise(&terrainnormal);
5372 targetyaw = -asin(0 - terrainnormal.x);
5373 targetyaw *= 360 / 6.28;
5374 if (terrainnormal.z < 0) {
5375 targetyaw = 180 - targetyaw;
5380 animTarget = flipanim;
5381 crouchtogglekeydown = 1;
5386 animCurrent = tempanim;
5390 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5391 tempanimation.frames[0].joints[i].position = skeleton.joints[i].position;
5392 tempanimation.frames[0].joints[i].position = DoRotation(tempanimation.frames[0].joints[i].position, 0, -yaw, 0);
5397 if (findLength(&average) < 10 && !dead && skeleton.free) {
5398 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
5399 if (skeleton.longdead > (damage + 500) * 1.5) {
5401 pause_sound(whooshsound);
5408 terrainnormal = jointPos(groin) - jointPos(abdomen);
5409 if (joint(groin).locked && joint(abdomen).locked) {
5410 terrainnormal = jointPos(groin) - jointPos(abdomen);
5411 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
5413 if (joint(abdomen).locked && joint(neck).locked) {
5414 terrainnormal = jointPos(abdomen) - jointPos(neck);
5415 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
5417 if (joint(groin).locked && joint(neck).locked) {
5418 terrainnormal = jointPos(groin) - jointPos(neck);
5419 middle = (jointPos(groin) + jointPos(neck)) / 2;
5421 Normalise(&terrainnormal);
5423 targetyaw = -asin(0 - terrainnormal.x);
5424 targetyaw *= 360 / 6.28;
5425 if (terrainnormal.z < 0) {
5426 targetyaw = 180 - targetyaw;
5430 targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1;
5432 if (skeleton.forward.y < 0) {
5433 animTarget = getupfrombackanim;
5437 if (skeleton.forward.y > -.3) {
5438 animTarget = getupfromfrontanim;
5446 if ((Random() % 8 == 0 && id != 0 && creature == rabbittype) || (Random() % 2 == 0 && id != 0 && creature == wolftype) || (id == 0 && crouchkeydown && (forwardkeydown || backkeydown || leftkeydown || rightkeydown))) {
5447 animTarget = rollanim;
5448 targetyaw = lookyaw;
5452 if (forwardkeydown) {
5461 if (forwardkeydown) {
5469 if (!leftkeydown && !rightkeydown) {
5477 if (abs(targettilt2) > 50) {
5480 animCurrent = tempanim;
5483 tilt2 = targettilt2;
5485 if (middle.y > 0 && animTarget != rollanim) {
5486 targetoffset.y = middle.y + 1;
5489 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5490 tempanimation.frames[0].joints[i].position = skeleton.joints[i].position;
5491 tempanimation.frames[0].joints[i].position = DoRotation(tempanimation.frames[0].joints[i].position, 0, -yaw, 0);
5498 if (num_weapons > 0) {
5499 if (weapons[0].getType() == staff) {
5503 if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) {
5504 if (velocity.y > -30) {
5506 tempvelocity = velocity;
5507 Normalise(&tempvelocity);
5508 targetyaw = -asin(0 - tempvelocity.x);
5509 targetyaw *= 360 / 6.28;
5510 if (velocity.z < 0) {
5511 targetyaw = 180 - targetyaw;
5516 if (dotproduct(&skeleton.forward, &tempvelocity) < 0) {
5517 animTarget = rollanim;
5520 animTarget = backhandspringanim;
5526 emit_sound_at(movewhooshsound, coords, 128.);
5528 animCurrent = animTarget;
5529 frameCurrent = frameTarget - 1;
5541 if (skeleton.freefall == 0) {
5546 if (aitype != passivetype || skeleton.free == 1) {
5547 if (findLengthfast(&velocity) > .1) {
5548 for (unsigned int i = 0; i < Object::objects.size(); i++) {
5549 if (Object::objects[i]->type == firetype) {
5550 if (distsqflat(&coords, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 12 && distsq(&coords, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 49) {
5552 if (!Object::objects[i]->onfire) {
5553 emit_sound_at(firestartsound, Object::objects[i]->position);
5555 Object::objects[i]->onfire = 1;
5558 if (Object::objects[i]->onfire) {
5564 if (Object::objects[i]->type == bushtype) {
5565 if (distsqflat(&coords, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 12 && distsq(&coords, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 49) {
5567 if (!Object::objects[i]->onfire) {
5568 emit_sound_at(firestartsound, Object::objects[i]->position);
5570 Object::objects[i]->onfire = 1;
5574 if (Object::objects[i]->onfire) {
5578 if (Object::objects[i]->messedwith <= 0) {
5582 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5585 addEnvSound(coords, 4 * findLength(&velocity));
5589 if (environment == grassyenvironment) {
5590 howmany = findLength(&velocity) * 4;
5592 if (environment == snowyenvironment) {
5593 howmany = findLength(&velocity) * 2;
5596 if (environment != desertenvironment) {
5597 for (int j = 0; j < howmany; j++) {
5598 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5599 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5600 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5603 pos.x += float(abs(Random() % 100) - 50) / 200;
5604 pos.y += float(abs(Random() % 100) - 50) / 200;
5605 pos.z += float(abs(Random() % 100) - 50) / 200;
5606 Sprite::MakeSprite(splintersprite, pos, tempvel * .5 + velocity * float(abs(Random() % 100)) / 100, 165 / 255 + float(abs(Random() % 100) - 50) / 400, 0, 0, .2 + float(abs(Random() % 100) - 50) / 1300, 1);
5607 Sprite::setLastSpriteSpecial(1);
5611 howmany = findLength(&velocity) * 4;
5613 if (environment == snowyenvironment) {
5614 for (int j = 0; j < howmany; j++) {
5615 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5616 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5617 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5620 pos.x += float(abs(Random() % 100) - 50) / 200;
5621 pos.y += float(abs(Random() % 100) - 50) / 200;
5622 pos.z += float(abs(Random() % 100) - 50) / 200;
5623 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5624 Sprite::setLastSpriteSpecial(2);
5629 Object::objects[i]->rotx += velocity.x * multiplier * 6;
5630 Object::objects[i]->roty += velocity.z * multiplier * 6;
5631 Object::objects[i]->messedwith = .5;
5635 if (Object::objects[i]->type == treeleavestype && environment != desertenvironment) {
5636 if (Object::objects[i]->pitch == 0) {
5639 tempcoord = coords - Object::objects[i]->position;
5640 tempcoord = DoRotation(tempcoord, 0, -Object::objects[i]->yaw, 0);
5641 tempcoord = DoRotation(tempcoord, -Object::objects[i]->pitch, 0, 0);
5642 tempcoord += Object::objects[i]->position;
5644 if (distsqflat(&tempcoord, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 8 && distsq(&tempcoord, &Object::objects[i]->position) < Object::objects[i]->scale * Object::objects[i]->scale * 300 && tempcoord.y > Object::objects[i]->position.y + 3 * Object::objects[i]->scale) {
5645 if (Object::objects[i]->messedwith <= 0) {
5649 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5652 addEnvSound(coords, 4 * findLength(&velocity));
5656 if (environment == grassyenvironment) {
5657 howmany = findLength(&velocity) * 4;
5659 if (environment == snowyenvironment) {
5660 howmany = findLength(&velocity) * 2;
5663 if (environment != desertenvironment) {
5664 for (int j = 0; j < howmany; j++) {
5665 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5666 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5667 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5669 pos += velocity * .1;
5671 pos.x += float(abs(Random() % 100) - 50) / 150;
5672 pos.y += float(abs(Random() % 100) - 50) / 150;
5673 pos.z += float(abs(Random() % 100) - 50) / 150;
5674 Sprite::MakeSprite(splintersprite, pos, tempvel * .5 + velocity * float(abs(Random() % 100)) / 100, 165 / 255 + float(abs(Random() % 100) - 50) / 400, 0, 0, .2 + float(abs(Random() % 100) - 50) / 1300, 1);
5675 Sprite::setLastSpriteSpecial(1);
5679 howmany = findLength(&velocity) * 4;
5681 if (environment == snowyenvironment) {
5682 for (int j = 0; j < howmany; j++) {
5683 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5684 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5685 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5687 pos += velocity * .1;
5689 pos.x += float(abs(Random() % 100) - 50) / 150;
5690 pos.y += float(abs(Random() % 100) - 50) / 150;
5691 pos.z += float(abs(Random() % 100) - 50) / 150;
5692 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5693 Sprite::setLastSpriteSpecial(2);
5698 Object::objects[i]->messedwith = .5;
5705 if (!skeleton.free) {
5708 if ((stunned > 0 || surprised > 0) && Person::players.size() > 2 && aitype != passivetype) {
5712 if (aitype != passivetype && victim->skeleton.free && !victim->dead) {
5716 if (Tutorial::active && id != 0) {
5719 if (play && aitype != playercontrolled) {
5720 int whichsound = -1;
5721 if (speechdelay <= 0) {
5722 unsigned int i = abs(Random() % 4);
5724 whichsound = PersonType::types[creature].soundsTalk[i];
5729 if (whichsound != -1) {
5730 emit_sound_at(whichsound, coords);
5734 if (animTarget == staggerbackhighanim) {
5737 if (animTarget == staggerbackhardanim) {
5740 staggerdelay -= multiplier;
5741 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) {
5744 if (velocity.y < -30 && animTarget == jumpdownanim) {
5747 if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) {
5748 animTarget = getIdle();
5752 weaponmissdelay -= multiplier;
5753 highreversaldelay -= multiplier;
5754 lowreversaldelay -= multiplier;
5755 lastcollide -= multiplier;
5756 skiddelay -= multiplier;
5757 if (!isnormal(velocity.x) && velocity.x) {
5760 if (!isnormal(targettilt) && targettilt) {
5763 if (!isnormal(targettilt2) && targettilt2) {
5766 if (!isnormal(targetyaw) && targetyaw) {
5770 if (animTarget == bounceidleanim || animTarget == wolfidle || animTarget == walkanim || animTarget == drawrightanim || animTarget == crouchdrawrightanim || animTarget == drawleftanim || animTarget == fightidleanim || animTarget == fightsidestep || animTarget == hanganim || isCrouch() || animTarget == backhandspringanim) {
5771 //open hands and close mouth
5772 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5773 righthandmorphness = 0;
5774 righthandmorphend = 0;
5775 targetrighthandmorphness = 1;
5778 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5779 lefthandmorphness = 0;
5780 lefthandmorphend = 0;
5781 targetlefthandmorphness = 1;
5784 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5 && headmorphend != 0 && headmorphness == targetheadmorphness) {
5787 targetheadmorphness = 1;
5791 if (animTarget == rollanim || animTarget == dodgebackanim || animTarget == removeknifeanim || animTarget == knifefightidleanim || animTarget == swordfightidleanim || animTarget == blockhighleftstrikeanim || animTarget == crouchremoveknifeanim || animTarget == sneakanim || animTarget == sweepanim || animTarget == spinkickreversedanim || animTarget == jumpdownanim || isWallJump() || isFlip() || animTarget == climbanim || isRun() || animTarget == getupfrombackanim || animTarget == getupfromfrontanim) {
5792 //open hands and mouth
5793 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5794 righthandmorphness = 0;
5795 righthandmorphend = 0;
5796 targetrighthandmorphness = 1;
5799 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5800 lefthandmorphness = 0;
5801 lefthandmorphend = 0;
5802 targetlefthandmorphness = 1;
5805 if (headmorphend != 1 && headmorphness == targetheadmorphness) {
5808 targetheadmorphness = 1;
5812 if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim) {
5813 //close hands and mouth
5814 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5815 righthandmorphness = 0;
5816 righthandmorphend = 1;
5817 targetrighthandmorphness = 1;
5820 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5821 lefthandmorphness = 0;
5822 lefthandmorphend = 1;
5823 targetlefthandmorphness = 1;
5826 if (headmorphend != 0 && headmorphness == targetheadmorphness) {
5829 targetheadmorphness = 1;
5833 if (animTarget == spinkickanim ||
5834 animTarget == staffspinhitreversalanim ||
5835 animTarget == staffspinhitreversedanim ||
5836 animTarget == staffhitreversalanim ||
5837 animTarget == staffhitreversedanim ||
5838 animTarget == hurtidleanim ||
5839 animTarget == winduppunchanim ||
5840 animTarget == swordslashreversalanim ||
5841 animTarget == swordslashreversedanim ||
5842 animTarget == knifeslashreversalanim ||
5843 animTarget == knifeslashreversedanim ||
5844 animTarget == knifethrowanim ||
5845 animTarget == knifefollowanim ||
5846 animTarget == knifefollowedanim ||
5847 animTarget == killanim ||
5848 animTarget == dropkickanim ||
5849 animTarget == upunchanim ||
5850 animTarget == knifeslashstartanim ||
5851 animTarget == swordslashanim ||
5852 animTarget == staffhitanim ||
5853 animTarget == staffspinhitanim ||
5854 animTarget == staffgroundsmashanim ||
5855 animTarget == spinkickreversalanim ||
5856 animTarget == sweepreversalanim ||
5857 animTarget == lowkickanim ||
5858 animTarget == sweepreversedanim ||
5859 animTarget == rabbitkickreversalanim ||
5860 animTarget == rabbitkickreversedanim ||
5861 animTarget == jumpreversalanim ||
5862 animTarget == jumpreversedanim) {
5863 //close hands and yell
5864 if (righthandmorphend != 1 &&
5865 righthandmorphness == targetrighthandmorphness) {
5866 righthandmorphness = 0;
5867 righthandmorphend = 1;
5868 targetrighthandmorphness = 1;
5871 if (lefthandmorphend != 1 &&
5872 lefthandmorphness == targetlefthandmorphness) {
5873 lefthandmorphness = 0;
5874 lefthandmorphend = 1;
5875 targetlefthandmorphness = 1;
5878 if (headmorphend != 2 && headmorphness == targetheadmorphness) {
5881 targetheadmorphness = 1;
5888 if ((victim != this->shared_from_this()) && !victim->dead && (victim->aitype != passivetype) &&
5889 (victim->aitype != searchtype) && (aitype != passivetype) &&
5890 (aitype != searchtype) && (victim->id < Person::players.size())) {
5891 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
5895 if (!dead && animTarget != hurtidleanim) {
5896 if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) {
5897 if (headmorphend != 4 || headmorphness == targetheadmorphness) {
5900 targetheadmorphness = 1;
5905 if (weaponactive != -1) {
5906 if (weapons[weaponids[weaponactive]].getType() != staff) {
5907 righthandmorphstart = 1;
5908 righthandmorphend = 1;
5910 if (weapons[weaponids[weaponactive]].getType() == staff) {
5911 righthandmorphstart = 2;
5912 righthandmorphend = 2;
5914 targetrighthandmorphness = 1;
5917 terrainnormal = terrain.getNormal(coords.x, coords.z);
5919 if (Animation::animations[animTarget].attack != reversal) {
5920 if (!isnormal(coords.x)) {
5929 flatfacing = DoRotation(flatfacing, 0, yaw, 0);
5930 facing = flatfacing;
5931 ReflectVector(&facing, terrainnormal);
5935 animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) {
5937 targettilt2 = -facing.y * 20;
5943 if (!isRun() && !Animation::animations[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim) {
5946 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5947 flatvelocity = velocity;
5949 flatvelspeed = findLength(&flatvelocity);
5950 targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity);
5951 targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity);
5952 if (velocity.y < 0) {
5955 if (velocity.y < 0) {
5958 if (targettilt > 25) {
5961 if (targettilt < -25) {
5966 if (targettilt2 > 45) {
5969 if (targettilt2 < -45) {
5972 if (abs(tilt2 - targettilt2) < multiplier * 400) {
5973 tilt2 = targettilt2;
5974 } else if (tilt2 > targettilt2) {
5975 tilt2 -= multiplier * 400;
5976 } else if (tilt2 < targettilt2) {
5977 tilt2 += multiplier * 400;
5979 if (!Animation::animations[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) {
5988 if (!isnormal(targettilt) && targettilt) {
5991 if (!isnormal(targettilt2) && targettilt2) {
5996 if (animTarget == rabbittackleanim) {
5997 velocity += facing * multiplier * speed * 700 * scale;
5998 velspeed = findLength(&velocity);
5999 if (velspeed > speed * 65 * scale) {
6000 velocity /= velspeed;
6001 velspeed = speed * 65 * scale;
6002 velocity *= velspeed;
6004 velocity.y += gravity * multiplier * 20;
6005 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6006 velspeed = findLength(&velocity);
6007 velocity = flatfacing * velspeed;
6009 if (animTarget != rabbitrunninganim && animTarget != wolfrunninganim) {
6010 if (isRun() || animTarget == rabbitkickanim) {
6011 velocity += facing * multiplier * speed * 700 * scale;
6012 velspeed = findLength(&velocity);
6013 if (velspeed > speed * 45 * scale) {
6014 velocity /= velspeed;
6015 velspeed = speed * 45 * scale;
6016 velocity *= velspeed;
6018 velocity.y += gravity * multiplier * 20;
6019 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6020 velspeed = findLength(&velocity);
6021 if (velspeed < speed * 30 * scale) {
6022 velspeed = speed * 30 * scale;
6024 velocity = flatfacing * velspeed;
6026 } else if (isRun()) {
6027 velocity += facing * multiplier * speed * 700 * scale;
6028 velspeed = findLength(&velocity);
6029 if (creature == rabbittype) {
6030 if (velspeed > speed * 55 * scale) {
6031 velocity /= velspeed;
6032 velspeed = speed * 55 * scale;
6033 velocity *= velspeed;
6036 if (creature == wolftype) {
6037 if (velspeed > speed * 75 * scale) {
6038 velocity /= velspeed;
6039 velspeed = speed * 75 * scale;
6040 velocity *= velspeed;
6043 velocity.y += gravity * multiplier * 20;
6044 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6045 velspeed = findLength(&velocity);
6046 velocity = flatfacing * velspeed;
6049 if (animTarget == rollanim && targetFrame().label != 6) {
6050 velocity += facing * multiplier * speed * 700 * scale;
6051 velspeed = findLength(&velocity);
6052 if (velspeed > speed * 45 * scale) {
6053 velocity /= velspeed;
6054 velspeed = speed * 45 * scale;
6055 velocity *= velspeed;
6057 velocity.y += gravity * multiplier * 20;
6058 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6059 velspeed = findLength(&velocity);
6060 velocity = flatfacing * velspeed;
6063 if (animTarget == sneakanim || animTarget == walkanim) {
6064 velocity += facing * multiplier * speed * 700 * scale;
6065 velspeed = findLength(&velocity);
6066 if (velspeed > speed * 12 * scale) {
6067 velocity /= velspeed;
6068 velspeed = speed * 12 * scale;
6069 velocity *= velspeed;
6071 velocity.y += gravity * multiplier * 20;
6072 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6073 velspeed = findLength(&velocity);
6074 velocity = flatfacing * velspeed;
6077 if ((animTarget == fightidleanim || animTarget == knifefightidleanim) && (animCurrent == bounceidleanim || animCurrent == hurtidleanim)) {
6078 velocity += facing * multiplier * speed * 700 * scale;
6079 velspeed = findLength(&velocity);
6080 if (velspeed > speed * 2 * scale) {
6081 velocity /= velspeed;
6082 velspeed = speed * 2 * scale;
6083 velocity *= velspeed;
6085 velocity.y += gravity * multiplier * 20;
6086 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6087 velspeed = findLength(&velocity);
6088 velocity = flatfacing * velspeed;
6091 if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) {
6092 velocity -= facing * multiplier * speed * 700 * scale;
6093 velspeed = findLength(&velocity);
6094 if (velspeed > speed * 2 * scale) {
6095 velocity /= velspeed;
6096 velspeed = speed * 2 * scale;
6097 velocity *= velspeed;
6099 velocity.y += gravity * multiplier * 20;
6100 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6101 velspeed = findLength(&velocity);
6102 velocity = flatfacing * velspeed * -1;
6105 if (animTarget == fightsidestep) {
6106 velocity += DoRotation(facing * multiplier * speed * 700 * scale, 0, -90, 0);
6107 velspeed = findLength(&velocity);
6108 if (velspeed > speed * 12 * scale) {
6109 velocity /= velspeed;
6110 velspeed = speed * 12 * scale;
6111 velocity *= velspeed;
6113 velocity.y += gravity * multiplier * 20;
6114 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6115 velspeed = findLength(&velocity);
6116 velocity = DoRotation(flatfacing * velspeed, 0, -90, 0);
6119 if (animTarget == staggerbackhighanim) {
6120 coords -= facing * multiplier * speed * 16 * scale;
6123 if (animTarget == staggerbackhardanim && Animation::animations[staggerbackhardanim].frames[frameTarget].label != 6) {
6124 coords -= facing * multiplier * speed * 20 * scale;
6128 if (animTarget == backhandspringanim) {
6129 //coords-=facing*multiplier*50*scale;
6130 velocity += facing * multiplier * speed * 700 * scale * -1;
6131 velspeed = findLength(&velocity);
6132 if (velspeed > speed * 50 * scale) {
6133 velocity /= velspeed;
6134 velspeed = speed * 50 * scale;
6135 velocity *= velspeed;
6137 velocity.y += gravity * multiplier * 20;
6138 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6139 velspeed = findLength(&velocity);
6140 velocity = flatfacing * velspeed * -1;
6142 if (animTarget == dodgebackanim) {
6143 //coords-=facing*multiplier*50*scale;
6144 velocity += facing * multiplier * speed * 700 * scale * -1;
6145 velspeed = findLength(&velocity);
6146 if (velspeed > speed * 60 * scale) {
6147 velocity /= velspeed;
6148 velspeed = speed * 60 * scale;
6149 velocity *= velspeed;
6151 velocity.y += gravity * multiplier * 20;
6152 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6153 velspeed = findLength(&velocity);
6154 velocity = flatfacing * velspeed * -1;
6157 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
6158 velspeed = findLength(&velocity);
6161 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
6162 velocity.y += gravity * multiplier;
6165 if (animTarget != climbanim && animTarget != hanganim && !isWallJump()) {
6166 coords += velocity * multiplier;
6169 if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
6170 if (isFlip() && targetFrame().label == 7) {
6174 if (animTarget == jumpupanim) {
6176 animTarget = getIdle();
6183 pause_sound(whooshsound);
6184 OPENAL_SetVolume(channels[whooshsound], 0);
6187 if (animTarget == jumpdownanim || isFlip()) {
6191 animTarget = getLanding();
6192 emit_sound_at(landsound, coords, 128.);
6195 addEnvSound(coords);
6200 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump()) {
6201 coords.y += gravity * multiplier * 2;
6203 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) {
6204 coords.y = terrain.getHeight(coords.x, coords.z);
6208 if (isIdle() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || isStop() || animTarget == removeknifeanim || animTarget == crouchremoveknifeanim || isLanding() || isCrouch() || Animation::animations[animTarget].attack || (animTarget == rollanim && targetFrame().label == 6)) {
6209 velspeed = findLength(&velocity);
6211 if (velspeed < multiplier * 300 * scale) {
6214 velocity -= velocity / velspeed * multiplier * 300 * scale;
6216 if (velspeed > 5 && (isLanding() || isLandhard())) {
6217 skiddingdelay += multiplier;
6218 if (skiddelay <= 0) {
6219 FootLand(leftfoot, .5);
6220 FootLand(rightfoot, .5);
6229 velspeed = findLength(&velocity);
6231 if (velspeed > 5 && (isLanding() || isLandhard())) {
6232 skiddingdelay += multiplier;
6233 if (skiddelay <= 0) {
6234 FootLand(leftfoot, .5);
6235 FootLand(rightfoot, .5);
6243 if (skiddingdelay < 0) {
6244 skiddingdelay += multiplier;
6246 if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) {
6248 if (!onterrain || environment == grassyenvironment) {
6249 emit_sound_at(skidsound, coords, 128 * velspeed / 10);
6251 emit_sound_at(snowskidsound, coords, 128 * velspeed / 10);
6255 if (Animation::animations[animTarget].attack == normalattack && animTarget != rabbitkickanim && !victim->skeleton.free) {
6256 terrainnormal = victim->coords - coords;
6257 Normalise(&terrainnormal);
6258 targetyaw = -asin(0 - terrainnormal.x);
6259 targetyaw *= 360 / 6.28;
6260 if (terrainnormal.z < 0) {
6261 targetyaw = 180 - targetyaw;
6263 targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70;
6266 if (Animation::animations[animTarget].attack == reversal && animTarget != rabbittacklinganim) {
6267 targetyaw = victim->targetyaw;
6269 if (animTarget == rabbittacklinganim) {
6270 coords = victim->coords;
6273 skeleton.oldfree = skeleton.free;
6277 midterrain.x = terrain.size * terrain.scale / 2;
6278 midterrain.z = terrain.size * terrain.scale / 2;
6279 if (distsqflat(&coords, &midterrain) > (terrain.size * terrain.scale / 2 - viewdistance) * (terrain.size * terrain.scale / 2 - viewdistance)) {
6281 tempposit = coords - midterrain;
6283 Normalise(&tempposit);
6284 tempposit *= (terrain.size * terrain.scale / 2 - viewdistance);
6285 coords.x = tempposit.x + midterrain.x;
6286 coords.z = tempposit.z + midterrain.z;
6291 * inverse kinematics helper function
6293 void IKHelper(Person* p, float interp)
6295 XYZ point, change, change2;
6296 float heightleft, heightright;
6298 // TODO: implement localToWorld and worldToLocal
6299 // but keep in mind it won't be the same math if player is ragdolled or something
6300 // - localToWorldStanding / worldToLocalStanding (or crouching or...?)
6301 // then comb through code for places where to use it
6303 // point = localToWorld(jointPos(leftfoot))
6304 point = DoRotation(p->jointPos(leftfoot), 0, p->yaw, 0) * p->scale + p->coords;
6305 // adjust height of foot
6306 heightleft = terrain.getHeight(point.x, point.z) + .04;
6307 point.y = heightleft;
6308 change = p->jointPos(leftankle) - p->jointPos(leftfoot);
6309 change2 = p->jointPos(leftknee) - p->jointPos(leftfoot);
6310 // jointPos(leftfoot) = interpolate(worldToLocal(point), jointPos(leftfoot), interp)
6311 p->jointPos(leftfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(leftfoot) * (1 - interp);
6312 // move ankle along with foot
6313 p->jointPos(leftankle) = p->jointPos(leftfoot) + change;
6314 // average knee pos between old and new pos
6315 p->jointPos(leftknee) = (p->jointPos(leftfoot) + change2) / 2 + (p->jointPos(leftknee)) / 2;
6317 // do same as above for right leg
6318 point = DoRotation(p->jointPos(rightfoot), 0, p->yaw, 0) * p->scale + p->coords;
6319 heightright = terrain.getHeight(point.x, point.z) + .04;
6320 point.y = heightright;
6321 change = p->jointPos(rightankle) - p->jointPos(rightfoot);
6322 change2 = p->jointPos(rightknee) - p->jointPos(rightfoot);
6323 p->jointPos(rightfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(rightfoot) * (1 - interp);
6324 p->jointPos(rightankle) = p->jointPos(rightfoot) + change;
6325 p->jointPos(rightknee) = (p->jointPos(rightfoot) + change2) / 2 + (p->jointPos(rightknee)) / 2;
6327 // fix up skeleton now that we've moved body parts?
6328 p->skeleton.DoConstraints(&p->coords, &p->scale);
6335 int Person::DrawSkeleton()
6337 int oldplayerdetail;
6338 if ((frustum.SphereInFrustum(coords.x, coords.y + scale * 3, coords.z, scale * 8) && distsq(&viewer, &coords) < viewdistance * viewdistance) || skeleton.free == 3) {
6339 if (onterrain && (isIdle() || isCrouch() || wasIdle() || wasCrouch()) && !skeleton.free) {
6349 glAlphaFunc(GL_GREATER, 0.0001);
6351 float terrainheight;
6353 if (!isnormal(yaw)) {
6356 if (!isnormal(tilt)) {
6359 if (!isnormal(tilt2)) {
6362 oldplayerdetail = playerdetail;
6364 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) {
6367 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 128 && detail == 1) {
6370 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) {
6376 if (playerdetail != oldplayerdetail) {
6378 normalsupdatedelay = 0;
6380 static float updatedelaychange;
6381 static float morphness;
6382 static float framemult;
6384 skeleton.FindForwards();
6385 if (howactive == typesittingwall) {
6386 skeleton.specialforward[1] = 0;
6387 skeleton.specialforward[1].z = 1;
6393 static int weaponattachmuscle;
6394 static int weaponrotatemuscle;
6395 static XYZ weaponpoint;
6396 static int start, endthing;
6397 if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
6398 if (!isSleeping() && !isSitting()) {
6399 // TODO: give these meaningful names
6400 const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim);
6401 const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard() || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim);
6403 if (onterrain && (cond1 && cond2) && !skeleton.free) {
6405 if (creature == wolftype) {
6410 if (onterrain && (cond1 && !cond2) && !skeleton.free) {
6411 IKHelper(this, target);
6412 if (creature == wolftype) {
6413 IKHelper(this, target);
6417 if (onterrain && (!cond1 && cond2) && !skeleton.free) {
6418 IKHelper(this, 1 - target);
6419 if (creature == wolftype) {
6420 IKHelper(this, 1 - target);
6425 if (!skeleton.free && (!Animation::animations[animTarget].attack && animTarget != getupfrombackanim && ((animTarget != rollanim && !isFlip()) || targetFrame().label == 6) && animTarget != getupfromfrontanim && animTarget != wolfrunninganim && animTarget != rabbitrunninganim && animTarget != backhandspringanim && animTarget != walljumpfrontanim && animTarget != hurtidleanim && !isLandhard() && !isSleeping())) {
6428 targetheadyaw = -targetyaw;
6429 targetheadpitch = 0;
6430 if (Animation::animations[animTarget].attack == 3) {
6431 targetheadyaw += 180;
6434 for (int i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6435 skeleton.drawmodel.vertex[i] = 0;
6436 skeleton.drawmodel.vertex[i].y = 999;
6438 for (int i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
6439 skeleton.drawmodellow.vertex[i] = 0;
6440 skeleton.drawmodellow.vertex[i].y = 999;
6442 for (int i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
6443 skeleton.drawmodelclothes.vertex[i] = 0;
6444 skeleton.drawmodelclothes.vertex[i].y = 999;
6446 for (unsigned int i = 0; i < skeleton.muscles.size(); i++) {
6447 // convenience renames
6448 const int p1 = skeleton.muscles[i].parent1->label;
6449 const int p2 = skeleton.muscles[i].parent2->label;
6451 if ((skeleton.muscles[i].vertices.size() > 0 && playerdetail) || (skeleton.muscles[i].verticeslow.size() > 0 && !playerdetail)) {
6456 if (p1 == righthand || p2 == righthand) {
6457 morphness = righthandmorphness;
6458 start = righthandmorphstart;
6459 endthing = righthandmorphend;
6461 if (p1 == lefthand || p2 == lefthand) {
6462 morphness = lefthandmorphness;
6463 start = lefthandmorphstart;
6464 endthing = lefthandmorphend;
6466 if (p1 == head || p2 == head) {
6467 morphness = headmorphness;
6468 start = headmorphstart;
6469 endthing = headmorphend;
6471 if ((p1 == neck && p2 == abdomen) || (p2 == neck && p1 == abdomen)) {
6472 morphness = chestmorphness;
6473 start = chestmorphstart;
6474 endthing = chestmorphend;
6476 if ((p1 == groin && p2 == abdomen) || (p2 == groin && p1 == abdomen)) {
6477 morphness = tailmorphness;
6478 start = tailmorphstart;
6479 endthing = tailmorphend;
6482 skeleton.FindRotationMuscle(i, animTarget);
6484 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6485 glMatrixMode(GL_MODELVIEW);
6488 if (!skeleton.free) {
6489 glRotatef(tilt2, 1, 0, 0);
6491 if (!skeleton.free) {
6492 glRotatef(tilt, 0, 0, 1);
6495 glTranslatef(mid.x, mid.y, mid.z);
6497 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6498 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6500 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6501 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6503 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6504 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6506 if (playerdetail || skeleton.free == 3) {
6507 for (unsigned j = 0; j < skeleton.muscles[i].vertices.size(); j++) {
6508 XYZ& v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
6509 XYZ& v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
6510 glMatrixMode(GL_MODELVIEW);
6512 if (p1 == abdomen || p2 == abdomen) {
6513 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * getProportion(1).x,
6514 (v0.y * (1 - morphness) + v1.y * morphness) * getProportion(1).y,
6515 (v0.z * (1 - morphness) + v1.z * morphness) * getProportion(1).z);
6517 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) {
6518 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * getProportion(2).x,
6519 (v0.y * (1 - morphness) + v1.y * morphness) * getProportion(2).y,
6520 (v0.z * (1 - morphness) + v1.z * morphness) * getProportion(2).z);
6522 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) {
6523 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * getProportion(3).x,
6524 (v0.y * (1 - morphness) + v1.y * morphness) * getProportion(3).y,
6525 (v0.z * (1 - morphness) + v1.z * morphness) * getProportion(3).z);
6527 if (p1 == head || p2 == head) {
6528 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * getProportion(0).x,
6529 (v0.y * (1 - morphness) + v1.y * morphness) * getProportion(0).y,
6530 (v0.z * (1 - morphness) + v1.z * morphness) * getProportion(0).z);
6532 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6533 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale;
6534 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale;
6535 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z = M[14] * scale;
6539 if (!playerdetail || skeleton.free == 3) {
6540 for (unsigned j = 0; j < skeleton.muscles[i].verticeslow.size(); j++) {
6541 XYZ& v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
6542 glMatrixMode(GL_MODELVIEW);
6544 if (p1 == abdomen || p2 == abdomen) {
6545 glTranslatef(v0.x * getProportion(1).x,
6546 v0.y * getProportion(1).y,
6547 v0.z * getProportion(1).z);
6549 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) {
6550 glTranslatef(v0.x * getProportion(2).x,
6551 v0.y * getProportion(2).y,
6552 v0.z * getProportion(2).z);
6554 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) {
6555 glTranslatef(v0.x * getProportion(3).x,
6556 v0.y * getProportion(3).y,
6557 v0.z * getProportion(3).z);
6559 if (p1 == head || p2 == head) {
6560 glTranslatef(v0.x * getProportion(0).x,
6561 v0.y * getProportion(0).y,
6562 v0.z * getProportion(0).z);
6565 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6566 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
6567 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y = M[13] * scale;
6568 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z = M[14] * scale;
6574 if (skeleton.clothes && skeleton.muscles[i].verticesclothes.size() > 0) {
6575 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6577 glMatrixMode(GL_MODELVIEW);
6580 if (!skeleton.free) {
6581 glRotatef(tilt2, 1, 0, 0);
6583 if (!skeleton.free) {
6584 glRotatef(tilt, 0, 0, 1);
6586 glTranslatef(mid.x, mid.y, mid.z);
6587 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6588 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6590 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6591 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6593 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6594 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6596 for (unsigned j = 0; j < skeleton.muscles[i].verticesclothes.size(); j++) {
6597 XYZ& v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
6598 glMatrixMode(GL_MODELVIEW);
6600 if (p1 == abdomen || p2 == abdomen) {
6601 glTranslatef(v0.x * getProportion(1).x,
6602 v0.y * getProportion(1).y,
6603 v0.z * getProportion(1).z);
6605 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) {
6606 glTranslatef(v0.x * getProportion(2).x,
6607 v0.y * getProportion(2).y,
6608 v0.z * getProportion(2).z);
6610 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) {
6611 glTranslatef(v0.x * getProportion(3).x,
6612 v0.y * getProportion(3).y,
6613 v0.z * getProportion(3).z);
6615 if (p1 == head || p2 == head) {
6616 glTranslatef(v0.x * getProportion(0).x,
6617 v0.y * getProportion(0).y,
6618 v0.z * getProportion(0).z);
6620 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6621 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
6622 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
6623 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z = M[14] * scale;
6628 updatedelay = 1 + (float)(Random() % 100) / 1000;
6630 if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) {
6631 normalsupdatedelay = 1;
6632 if (playerdetail || skeleton.free == 3) {
6633 skeleton.drawmodel.CalculateNormals(0);
6635 if (!playerdetail || skeleton.free == 3) {
6636 skeleton.drawmodellow.CalculateNormals(0);
6638 if (skeleton.clothes) {
6639 skeleton.drawmodelclothes.CalculateNormals(0);
6642 if (playerdetail || skeleton.free == 3) {
6643 skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
6645 if (!playerdetail || skeleton.free == 3) {
6646 skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
6648 if (skeleton.clothes) {
6649 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6654 updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1);
6655 if (updatedelaychange > -realmultiplier * 30) {
6656 updatedelaychange = -realmultiplier * 30;
6658 if (updatedelaychange > -framemult * 4) {
6659 updatedelaychange = -framemult * 4;
6661 if (skeleton.free == 1) {
6662 updatedelaychange *= 6;
6665 updatedelaychange *= 8;
6667 updatedelay += updatedelaychange;
6669 glMatrixMode(GL_MODELVIEW);
6671 glTranslatef(coords.x, coords.y - .02, coords.z);
6672 if (!skeleton.free) {
6673 glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
6674 glRotatef(yaw, 0, 1, 0);
6678 glColor4f(.4, 1, .4, 1);
6679 glDisable(GL_LIGHTING);
6680 glDisable(GL_TEXTURE_2D);
6683 for (int i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6684 XYZ& v0 = skeleton.drawmodel.vertex[i];
6685 glVertex3f(v0.x, v0.y, v0.z);
6692 for (unsigned int i = 0; i < skeleton.drawmodel.Triangles.size(); i++) {
6693 const XYZ& v0 = skeleton.drawmodel.getTriangleVertex(i, 0);
6694 const XYZ& v1 = skeleton.drawmodel.getTriangleVertex(i, 1);
6695 const XYZ& v2 = skeleton.drawmodel.getTriangleVertex(i, 2);
6696 glVertex3f(v0.x, v0.y, v0.z);
6697 glVertex3f(v1.x, v1.y, v1.z);
6698 glVertex3f(v1.x, v1.y, v1.z);
6699 glVertex3f(v2.x, v2.y, v2.z);
6700 glVertex3f(v2.x, v2.y, v2.z);
6701 glVertex3f(v0.x, v0.y, v0.z);
6708 terrainlight = terrain.getLighting(coords.x, coords.z);
6709 distance = distsq(&viewer, &coords);
6710 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
6715 terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1;
6716 if (terrainheight < 1) {
6719 if (terrainheight > 1.7) {
6720 terrainheight = 1.7;
6723 glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance);
6724 glDisable(GL_BLEND);
6725 glAlphaFunc(GL_GREATER, 0.0001);
6726 glEnable(GL_TEXTURE_2D);
6728 glDisable(GL_TEXTURE_2D);
6729 glColor4f(.7, .35, 0, .5);
6731 glEnable(GL_LIGHTING);
6734 if (Tutorial::active && id != 0) {
6735 glColor4f(.7, .7, .7, 0.6);
6737 glEnable(GL_LIGHTING);
6739 if (canattack && cananger) {
6740 if (Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed) {
6741 glDisable(GL_TEXTURE_2D);
6742 glColor4f(1, 0, 0, 0.8);
6745 glMatrixMode(GL_TEXTURE);
6747 glTranslatef(0, -smoketex, 0);
6748 glTranslatef(-smoketex, 0, 0);
6752 if (Tutorial::active && (id != 0)) {
6753 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6755 skeleton.drawmodel.draw();
6759 if (!playerdetail) {
6760 if (Tutorial::active && (id != 0)) {
6761 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6763 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6767 if (!(Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed)) {
6768 if (Tutorial::active && id != 0) {
6770 glMatrixMode(GL_MODELVIEW);
6771 glEnable(GL_TEXTURE_2D);
6772 glColor4f(.7, .7, .7, 0.6);
6774 glEnable(GL_LIGHTING);
6776 if (canattack && cananger) {
6777 if (Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed) {
6778 glDisable(GL_TEXTURE_2D);
6779 glColor4f(1, 0, 0, 0.8);
6782 glMatrixMode(GL_TEXTURE);
6784 glTranslatef(0, -smoketex * .6, 0);
6785 glTranslatef(smoketex * .6, 0, 0);
6788 if (Tutorial::active && (id != 0)) {
6789 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6791 skeleton.drawmodel.draw();
6795 if (!playerdetail) {
6796 if (Tutorial::active && (id != 0)) {
6797 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6799 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6805 if (Tutorial::active && id != 0) {
6807 glMatrixMode(GL_MODELVIEW);
6808 glEnable(GL_TEXTURE_2D);
6810 if (skeleton.clothes) {
6814 skeleton.drawmodelclothes.draw();
6817 skeleton.drawmodelclothes.drawimmediate();
6824 if (num_weapons > 0) {
6825 for (k = 0; k < num_weapons; k++) {
6826 int i = weaponids[k];
6827 if (weaponactive == k) {
6828 if (weapons[i].getType() != staff) {
6829 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6830 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].vertices.size() > 0) {
6831 weaponattachmuscle = j;
6834 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6835 if ((skeleton.muscles[j].parent1->label == rightwrist || skeleton.muscles[j].parent2->label == rightwrist) && (skeleton.muscles[j].parent1->label != righthand && skeleton.muscles[j].parent2->label != righthand) && skeleton.muscles[j].vertices.size() > 0) {
6836 weaponrotatemuscle = j;
6839 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6840 if (creature == wolftype) {
6841 weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3);
6844 if (weapons[i].getType() == staff) {
6845 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6846 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].vertices.size() > 0) {
6847 weaponattachmuscle = j;
6850 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6851 if ((skeleton.muscles[j].parent1->label == rightelbow || skeleton.muscles[j].parent2->label == rightelbow) && (skeleton.muscles[j].parent1->label != rightshoulder && skeleton.muscles[j].parent2->label != rightshoulder) && skeleton.muscles[j].vertices.size() > 0) {
6852 weaponrotatemuscle = j;
6855 //weaponpoint=jointPos(rightwrist);
6856 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6857 //weaponpoint+=skeleton.specialforward[1]*.1+(jointPos(rightwrist)-jointPos(rightelbow));
6858 XYZ tempnormthing, vec1, vec2;
6859 vec1 = (jointPos(rightwrist) - jointPos(rightelbow));
6860 vec2 = (jointPos(rightwrist) - jointPos(rightshoulder));
6861 CrossProduct(&vec1, &vec2, &tempnormthing);
6862 Normalise(&tempnormthing);
6863 if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim) {
6864 weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow));
6868 if (weaponactive != k && weaponstuck != k) {
6869 if (weapons[i].getType() == knife) {
6870 weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35;
6872 if (weapons[i].getType() == sword) {
6873 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6875 if (weapons[i].getType() == staff) {
6876 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6878 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6879 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].vertices.size() > 0) {
6880 weaponrotatemuscle = j;
6884 if (weaponstuck == k) {
6885 if (weaponstuckwhere == 0) {
6886 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8;
6888 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
6890 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6891 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].vertices.size() > 0) {
6892 weaponrotatemuscle = j;
6896 if (skeleton.free) {
6897 weapons[i].position = weaponpoint * scale + coords;
6898 weapons[i].bigrotation = 0;
6899 weapons[i].bigtilt = 0;
6900 weapons[i].bigtilt2 = 0;
6902 weapons[i].position = DoRotation(DoRotation(DoRotation(weaponpoint, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords + currentoffset * (1 - target) * scale + targetoffset * target * scale;
6903 weapons[i].bigrotation = yaw;
6904 weapons[i].bigtilt = tilt;
6905 weapons[i].bigtilt2 = tilt2;
6907 weapons[i].rotation1 = skeleton.muscles[weaponrotatemuscle].lastrotate1;
6908 weapons[i].rotation2 = skeleton.muscles[weaponrotatemuscle].lastrotate2;
6909 weapons[i].rotation3 = skeleton.muscles[weaponrotatemuscle].lastrotate3;
6910 if (weaponactive == k) {
6911 if (weapons[i].getType() == knife) {
6912 weapons[i].smallrotation = 180;
6913 weapons[i].smallrotation2 = 0;
6914 if (isCrouch() || wasCrouch()) {
6915 weapons[i].smallrotation2 = 20;
6917 if (animTarget == hurtidleanim) {
6918 weapons[i].smallrotation2 = 50;
6920 if ((animCurrent == crouchstabanim && animTarget == crouchstabanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
6921 XYZ temppoint1, temppoint2;
6924 temppoint1 = jointPos(righthand);
6925 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
6926 distance = findDistance(&temppoint1, &temppoint2);
6927 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6928 weapons[i].rotation2 *= 360 / 6.28;
6931 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6932 weapons[i].rotation1 *= 360 / 6.28;
6933 weapons[i].rotation3 = 0;
6934 weapons[i].smallrotation = -90;
6935 weapons[i].smallrotation2 = 0;
6936 if (temppoint1.x > temppoint2.x) {
6937 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6940 if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) {
6941 XYZ temppoint1, temppoint2;
6944 temppoint1 = jointPos(righthand);
6945 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
6946 distance = findDistance(&temppoint1, &temppoint2);
6947 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6948 weapons[i].rotation2 *= 360 / 6.28;
6951 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6952 weapons[i].rotation1 *= 360 / 6.28;
6953 weapons[i].rotation3 = 0;
6954 weapons[i].smallrotation = 90;
6955 weapons[i].smallrotation2 = 0;
6956 if (temppoint1.x > temppoint2.x) {
6957 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6960 if (animTarget == knifethrowanim) {
6961 weapons[i].smallrotation = 90;
6962 //weapons[i].smallrotation2=-90;
6963 weapons[i].smallrotation2 = 0;
6964 weapons[i].rotation1 = 0;
6965 weapons[i].rotation2 = 0;
6966 weapons[i].rotation3 = 0;
6968 if (animTarget == knifesneakattackanim && frameTarget < 5) {
6969 weapons[i].smallrotation = -90;
6970 weapons[i].rotation1 = 0;
6971 weapons[i].rotation2 = 0;
6972 weapons[i].rotation3 = 0;
6975 if (weapons[i].getType() == sword) {
6976 weapons[i].smallrotation = 0;
6977 weapons[i].smallrotation2 = 0;
6978 if (animTarget == knifethrowanim) {
6979 weapons[i].smallrotation = -90;
6980 weapons[i].smallrotation2 = 0;
6981 weapons[i].rotation1 = 0;
6982 weapons[i].rotation2 = 0;
6983 weapons[i].rotation3 = 0;
6985 if ((animTarget == swordgroundstabanim && animCurrent == swordgroundstabanim) || (animTarget == swordsneakattackanim && animCurrent == swordsneakattackanim) || (animTarget == swordslashparryanim && animCurrent == swordslashparryanim) || (animTarget == swordslashparriedanim && animCurrent == swordslashparriedanim) || (animTarget == swordslashreversalanim && animCurrent == swordslashreversalanim) || (animTarget == swordslashreversedanim && animCurrent == swordslashreversedanim) || (animTarget == knifeslashreversalanim && animCurrent == knifeslashreversalanim) || (animTarget == knifeslashreversedanim && animCurrent == knifeslashreversedanim) || (animTarget == swordslashanim && animCurrent == swordslashanim) || (animTarget == drawleftanim && animCurrent == drawleftanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
6986 XYZ temppoint1, temppoint2;
6989 temppoint1 = currentFrame().joints[skeleton.jointlabels[righthand]].position * (1 - target) + targetFrame().joints[skeleton.jointlabels[righthand]].position * (target); //jointPos(righthand);
6990 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
6991 distance = findDistance(&temppoint1, &temppoint2);
6992 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6993 weapons[i].rotation2 *= 360 / 6.28;
6996 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6997 weapons[i].rotation1 *= 360 / 6.28;
6998 weapons[i].rotation3 = 0;
6999 weapons[i].smallrotation = 90;
7000 weapons[i].smallrotation2 = 0;
7001 if (temppoint1.x > temppoint2.x) {
7002 weapons[i].rotation1 = 360 - weapons[i].rotation1;
7006 if (weapons[i].getType() == staff) {
7007 weapons[i].smallrotation = 100;
7008 weapons[i].smallrotation2 = 0;
7009 if ((animTarget == staffhitanim && animCurrent == staffhitanim) || (animTarget == staffhitreversedanim && animCurrent == staffhitreversedanim) || (animTarget == staffspinhitreversedanim && animCurrent == staffspinhitreversedanim) || (animTarget == staffgroundsmashanim && animCurrent == staffgroundsmashanim) || (animTarget == staffspinhitanim && animCurrent == staffspinhitanim)) {
7010 XYZ temppoint1, temppoint2;
7013 temppoint1 = currentFrame().joints[skeleton.jointlabels[righthand]].position * (1 - target) + targetFrame().joints[skeleton.jointlabels[righthand]].position * (target); //jointPos(righthand);
7014 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
7015 distance = findDistance(&temppoint1, &temppoint2);
7016 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
7017 weapons[i].rotation2 *= 360 / 6.28;
7020 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
7021 weapons[i].rotation1 *= 360 / 6.28;
7022 weapons[i].rotation3 = 0;
7023 weapons[i].smallrotation = 90;
7024 weapons[i].smallrotation2 = 0;
7025 if (temppoint1.x > temppoint2.x) {
7026 weapons[i].rotation1 = 360 - weapons[i].rotation1;
7031 if (weaponactive != k && weaponstuck != k) {
7032 if (weapons[i].getType() == knife) {
7033 weapons[i].smallrotation = -70;
7034 weapons[i].smallrotation2 = 10;
7036 if (weapons[i].getType() == sword) {
7037 weapons[i].smallrotation = -100;
7038 weapons[i].smallrotation2 = -8;
7040 if (weapons[i].getType() == staff) {
7041 weapons[i].smallrotation = -100;
7042 weapons[i].smallrotation2 = -8;
7045 if (weaponstuck == k) {
7046 if (weaponstuckwhere == 0) {
7047 weapons[i].smallrotation = 180;
7049 weapons[i].smallrotation = 0;
7051 weapons[i].smallrotation2 = 10;
7058 if (skeleton.free) {
7061 if (Animation::animations[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isWallJump()) {
7064 if (animCurrent != animTarget) {
7067 if (skeleton.free == 2) {
7076 int Person::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, Model* model)
7078 static float distance;
7079 static float olddistance;
7080 static int intersecting;
7081 static int firstintersecting;
7084 static XYZ start, end;
7085 static float slopethreshold = -.4;
7087 firstintersecting = -1;
7091 if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius) {
7095 *p1 = DoRotation(*p1, 0, -*rotate, 0);
7097 for (int i = 0; i < 4; i++) {
7098 for (unsigned int j = 0; j < model->Triangles.size(); j++) {
7099 if (model->Triangles[j].facenormal.y <= slopethreshold) {
7101 distance = abs((model->Triangles[j].facenormal.x * p1->x) + (model->Triangles[j].facenormal.y * p1->y) + (model->Triangles[j].facenormal.z * p1->z) - ((model->Triangles[j].facenormal.x * model->vertex[model->Triangles[j].vertex[0]].x) + (model->Triangles[j].facenormal.y * model->vertex[model->Triangles[j].vertex[0]].y) + (model->Triangles[j].facenormal.z * model->vertex[model->Triangles[j].vertex[0]].z)));
7102 if (distance < radius) {
7103 point = *p1 - model->Triangles[j].facenormal * distance;
7104 if (PointInTriangle(&point, model->Triangles[j].facenormal, &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]])) {
7107 if (!intersecting) {
7108 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
7109 &model->vertex[model->Triangles[j].vertex[1]],
7112 if (!intersecting) {
7113 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
7114 &model->vertex[model->Triangles[j].vertex[2]],
7117 if (!intersecting) {
7118 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
7119 &model->vertex[model->Triangles[j].vertex[2]],
7123 if (dotproduct(&model->Triangles[j].facenormal, &end) > 0 && intersecting) {
7127 if (LineFacetd(&start, &end, &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]], &model->Triangles[j].facenormal, &point)) {
7128 p1->y = point.y + radius;
7129 if ((animTarget == jumpdownanim || isFlip())) {
7130 if (isFlip() && (frameTarget < 5 || targetFrame().label == 7 || targetFrame().label == 4)) {
7134 if (animTarget == jumpupanim) {
7136 animTarget = getIdle();
7143 pause_sound(whooshsound);
7144 OPENAL_SetVolume(channels[whooshsound], 0);
7147 if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) {
7151 animTarget = getLanding();
7152 emit_sound_at(landsound, coords, 128.);
7155 addEnvSound(coords);
7162 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
7163 olddistance = distance;
7164 firstintersecting = j;
7169 for (unsigned int j = 0; j < model->Triangles.size(); j++) {
7170 if (model->Triangles[j].facenormal.y > slopethreshold) {
7173 start.y -= radius / 4;
7174 XYZ& v0 = model->vertex[model->Triangles[j].vertex[0]];
7175 XYZ& v1 = model->vertex[model->Triangles[j].vertex[1]];
7176 XYZ& v2 = model->vertex[model->Triangles[j].vertex[2]];
7177 distance = abs((model->Triangles[j].facenormal.x * start.x) + (model->Triangles[j].facenormal.y * start.y) + (model->Triangles[j].facenormal.z * start.z) - ((model->Triangles[j].facenormal.x * v0.x) + (model->Triangles[j].facenormal.y * v0.y) + (model->Triangles[j].facenormal.z * v0.z)));
7178 if (distance < radius * .5) {
7179 point = start - model->Triangles[j].facenormal * distance;
7180 if (PointInTriangle(&point, model->Triangles[j].facenormal, &v0, &v1, &v2)) {
7183 if (!intersecting) {
7184 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
7186 if (!intersecting) {
7187 intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
7189 if (!intersecting) {
7190 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
7193 if (dotproduct(&model->Triangles[j].facenormal, &end) > 0 && intersecting) {
7194 if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
7196 velocity -= DoRotation(model->Triangles[j].facenormal, 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->Triangles[j].facenormal, 0, *rotate, 0))); //(distance-radius*.5)/multiplier;
7197 if (findLengthfast(&start) < findLengthfast(&velocity)) {
7201 *p1 += model->Triangles[j].facenormal * (distance - radius * .5);
7204 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
7205 olddistance = distance;
7206 firstintersecting = j;
7213 *p = DoRotation(*p, 0, *rotate, 0);
7217 *p1 = DoRotation(*p1, 0, *rotate, 0);
7220 return firstintersecting;
7223 int findPathDist(int start, int end)
7228 unsigned int smallestcount = 1000;
7229 for (char i = 0; i < 50; i++) {
7230 unsigned int count = 0;
7235 while (last != end && count < 30) {
7237 for (int j = 0; j < Game::numpathpoints; j++) {
7238 if (j != last && j != last2 && j != last3 && j != last4) {
7240 if (Game::numpathpointconnect[j]) {
7241 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7242 if (Game::pathpointconnect[j][k] == last) {
7248 if (Game::numpathpointconnect[last]) {
7249 for (int k = 0; k < Game::numpathpointconnect[last]; k++) {
7250 if (Game::pathpointconnect[last][k] == j) {
7257 if (closest == -1 || Random() % 2 == 0) {
7269 if (count < smallestcount) {
7270 smallestcount = count;
7273 return smallestcount;
7276 void Person::takeWeapon(int weaponId)
7279 weapons[weaponId].owner = id;
7280 if (num_weapons > 0) {
7281 weaponids[num_weapons] = weaponids[0];
7284 weaponids[0] = weaponId;
7287 void Person::addClothes()
7289 if (numclothes > 0) {
7290 for (int i = 0; i < numclothes; i++) {
7297 bool Person::addClothes(const int& clothesId)
7300 const std::string fileName = clothes[clothesId];
7302 GLubyte* array = &skeleton.skinText[0];
7306 bool opened = load_image(Folders::getResourcePath(fileName).c_str(), texture);
7311 float tintr = clothestintr[clothesId];
7312 float tintg = clothestintg[clothesId];
7313 float tintb = clothestintb[clothesId];
7335 int bytesPerPixel = texture.bpp / 8;
7339 for (int i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) {
7340 if (bytesPerPixel == 3) {
7342 } else if ((i + 1) % 4 == 0) {
7343 alphanum = texture.data[i];
7345 if ((i + 1) % 4 || bytesPerPixel == 3) {
7347 texture.data[i] *= tintr;
7350 texture.data[i] *= tintg;
7353 texture.data[i] *= tintb;
7355 array[tempnum] = (float)array[tempnum] * (1 - alphanum / 255) + (float)texture.data[i] * (alphanum / 255);
7367 if (aitype != playercontrolled && !Dialog::inDialog()) {
7369 //disable movement in editor
7370 if (Game::editorenabled) {
7375 if (distsqflat(&Person::players[0]->coords, &coords) < 30 &&
7376 Person::players[0]->coords.y > coords.y + 2 &&
7377 !Person::players[0]->onterrain) {
7382 if (aitype == pathfindtype) {
7383 if (finalpathfindpoint == -1) {
7384 float closestdistance;
7385 float tempdist = 0.0f;
7389 closestdistance = -1;
7390 for (int j = 0; j < Game::numpathpoints; j++) {
7391 if (closest == -1 || distsq(&finalfinaltarget, &Game::pathpoint[j]) < closestdistance) {
7392 closestdistance = distsq(&finalfinaltarget, &Game::pathpoint[j]);
7394 finaltarget = Game::pathpoint[j];
7397 finalpathfindpoint = closest;
7398 for (int j = 0; j < Game::numpathpoints; j++) {
7399 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7400 DistancePointLine(&finalfinaltarget, &Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]], &tempdist, &colpoint);
7401 if (sq(tempdist) < closestdistance) {
7402 if (findDistance(&colpoint, &Game::pathpoint[j]) + findDistance(&colpoint, &Game::pathpoint[Game::pathpointconnect[j][k]]) <
7403 findDistance(&Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]]) + .1) {
7404 closestdistance = sq(tempdist);
7406 finaltarget = colpoint;
7411 finalpathfindpoint = closest;
7413 if (targetpathfindpoint == -1) {
7414 float closestdistance;
7415 float tempdist = 0.0f;
7419 closestdistance = -1;
7420 if (lastpathfindpoint == -1) {
7421 for (int j = 0; j < Game::numpathpoints; j++) {
7422 if (j != lastpathfindpoint) {
7423 if (closest == -1 || (distsq(&coords, &Game::pathpoint[j]) < closestdistance)) {
7424 closestdistance = distsq(&coords, &Game::pathpoint[j]);
7429 targetpathfindpoint = closest;
7430 for (int j = 0; j < Game::numpathpoints; j++) {
7431 if (j != lastpathfindpoint) {
7432 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7433 DistancePointLine(&coords, &Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]], &tempdist, &colpoint);
7434 if (sq(tempdist) < closestdistance) {
7435 if (findDistance(&colpoint, &Game::pathpoint[j]) + findDistance(&colpoint, &Game::pathpoint[Game::pathpointconnect[j][k]]) <
7436 findDistance(&Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]]) + .1) {
7437 closestdistance = sq(tempdist);
7444 targetpathfindpoint = closest;
7446 for (int j = 0; j < Game::numpathpoints; j++) {
7447 if (j != lastpathfindpoint &&
7448 j != lastpathfindpoint2 &&
7449 j != lastpathfindpoint3 &&
7450 j != lastpathfindpoint4) {
7452 if (Game::numpathpointconnect[j]) {
7453 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7454 if (Game::pathpointconnect[j][k] == lastpathfindpoint) {
7460 if (Game::numpathpointconnect[lastpathfindpoint]) {
7461 for (int k = 0; k < Game::numpathpointconnect[lastpathfindpoint]; k++) {
7462 if (Game::pathpointconnect[lastpathfindpoint][k] == j) {
7469 tempdist = findPathDist(j, finalpathfindpoint);
7470 if (closest == -1 || tempdist < closestdistance) {
7471 closestdistance = tempdist;
7477 targetpathfindpoint = closest;
7480 losupdatedelay -= multiplier;
7482 targetyaw = roughDirectionTo(coords, Game::pathpoint[targetpathfindpoint]);
7483 lookyaw = targetyaw;
7485 //reached target point
7486 if (distsqflat(&coords, &Game::pathpoint[targetpathfindpoint]) < .6) {
7487 lastpathfindpoint4 = lastpathfindpoint3;
7488 lastpathfindpoint3 = lastpathfindpoint2;
7489 lastpathfindpoint2 = lastpathfindpoint;
7490 lastpathfindpoint = targetpathfindpoint;
7491 if (lastpathfindpoint2 == -1) {
7492 lastpathfindpoint2 = lastpathfindpoint;
7494 if (lastpathfindpoint3 == -1) {
7495 lastpathfindpoint3 = lastpathfindpoint2;
7497 if (lastpathfindpoint4 == -1) {
7498 lastpathfindpoint4 = lastpathfindpoint3;
7500 targetpathfindpoint = -1;
7502 if (distsqflat(&coords, &finalfinaltarget) <
7503 distsqflat(&coords, &finaltarget) ||
7504 distsqflat(&coords, &finaltarget) < .6 * sq(scale * 5) ||
7505 lastpathfindpoint == finalpathfindpoint) {
7506 aitype = passivetype;
7517 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
7518 targetyaw += 90 * (whichdirection * 2 - 1);
7521 if (collided < 1 || animTarget != jumpupanim) {
7524 if ((collided > .8 && jumppower >= 5)) {
7528 if ((!Tutorial::active || cananger) &&
7530 !Person::players[0]->dead &&
7531 distsq(&coords, &Person::players[0]->coords) < 400 &&
7533 if (distsq(&coords, &Person::players[0]->coords) < 12 &&
7534 Animation::animations[Person::players[0]->animTarget].height != lowheight &&
7535 !Game::editorenabled &&
7536 (Person::players[0]->coords.y < coords.y + 5 || Person::players[0]->onterrain)) {
7537 aitype = attacktypecutoff;
7539 if (distsq(&coords, &Person::players[0]->coords) < 30 &&
7540 Animation::animations[Person::players[0]->animTarget].height == highheight &&
7541 !Game::editorenabled) {
7542 aitype = attacktypecutoff;
7545 if (losupdatedelay < 0 && !Game::editorenabled && occluded < 2) {
7546 losupdatedelay = .2;
7547 for (unsigned j = 0; j < Person::players.size(); j++) {
7548 if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) {
7549 if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) {
7550 if (distsq(&coords, &Person::players[j]->coords) < 400) {
7551 if (normaldotproduct(facing, Person::players[j]->coords - coords) > 0) {
7552 if (Person::players[j]->coords.y < coords.y + 5 || Person::players[j]->onterrain) {
7553 if (!Person::players[j]->isWallJump() && -1 == Object::checkcollide(DoRotation(jointPos(head), 0, yaw, 0) * scale + coords, DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0) * Person::players[j]->scale + Person::players[j]->coords) ||
7554 (Person::players[j]->animTarget == hanganim &&
7555 normaldotproduct(Person::players[j]->facing, coords - Person::players[j]->coords) < 0)) {
7556 aitype = searchtype;
7558 lastseen = Person::players[j]->coords;
7569 if (aitype == attacktypecutoff && Game::musictype != 2) {
7570 if (creature != wolftype) {
7577 if (aitype != passivetype && Game::leveltime > .5) {
7578 howactive = typeactive;
7581 if (aitype == passivetype) {
7582 aiupdatedelay -= multiplier;
7583 losupdatedelay -= multiplier;
7584 lastseentime += multiplier;
7585 pausetime -= multiplier;
7586 if (lastseentime > 1) {
7590 if (aiupdatedelay < 0) {
7591 if (numwaypoints > 1 && howactive == typeactive && pausetime <= 0) {
7592 targetyaw = roughDirectionTo(coords, waypoints[waypoint]);
7593 lookyaw = targetyaw;
7594 aiupdatedelay = .05;
7596 if (distsqflat(&coords, &waypoints[waypoint]) < 1) {
7597 if (waypointtype[waypoint] == wppause) {
7601 if (waypoint > numwaypoints - 1) {
7607 if (numwaypoints > 1 && howactive == typeactive && pausetime <= 0) {
7619 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
7620 if (!avoidsomething) {
7621 targetyaw += 90 * (whichdirection * 2 - 1);
7623 XYZ leftpos, rightpos;
7624 float leftdist, rightdist;
7625 leftpos = coords + DoRotation(facing, 0, 90, 0);
7626 rightpos = coords - DoRotation(facing, 0, 90, 0);
7627 leftdist = distsq(&leftpos, &avoidwhere);
7628 rightdist = distsq(&rightpos, &avoidwhere);
7629 if (leftdist < rightdist) {
7637 if (collided < 1 || animTarget != jumpupanim) {
7640 if ((collided > .8 && jumppower >= 5)) {
7645 if (!Game::editorenabled) {
7646 if (howactive <= typesleeping) {
7647 if (numenvsounds > 0 && (!Tutorial::active || cananger) && hostile) {
7648 for (int j = 0; j < numenvsounds; j++) {
7649 float vol = howactive == typesleeping ? envsoundvol[j] - 14 : envsoundvol[j];
7650 if (vol > 0 && distsq(&coords, &envsound[j]) < 2 * (vol + vol * (creature == rabbittype) * 3)) {
7651 aitype = attacktypecutoff;
7657 if (aitype != passivetype) {
7658 if (howactive == typesleeping) {
7659 setTargetAnimation(getupfromfrontanim);
7661 howactive = typeactive;
7665 if (howactive < typesleeping &&
7666 ((!Tutorial::active || cananger) && hostile) &&
7667 !Person::players[0]->dead &&
7668 distsq(&coords, &Person::players[0]->coords) < 400 &&
7670 if (distsq(&coords, &Person::players[0]->coords) < 12 &&
7671 Animation::animations[Person::players[0]->animTarget].height != lowheight && !Game::editorenabled) {
7672 aitype = attacktypecutoff;
7674 if (distsq(&coords, &Person::players[0]->coords) < 30 &&
7675 Animation::animations[Person::players[0]->animTarget].height == highheight && !Game::editorenabled) {
7676 aitype = attacktypecutoff;
7680 if (creature == wolftype) {
7682 for (unsigned j = 0; j < Person::players.size(); j++) {
7683 if (j == 0 || (Person::players[j]->dead && Person::players[j]->bloodloss > 0)) {
7684 float smelldistance = 50;
7685 if (j == 0 && Person::players[j]->num_weapons > 0) {
7686 if (weapons[Person::players[j]->weaponids[0]].bloody) {
7687 smelldistance = 100;
7689 if (Person::players[j]->num_weapons == 2) {
7690 if (weapons[Person::players[j]->weaponids[1]].bloody) {
7691 smelldistance = 100;
7696 smelldistance = 100;
7698 windsmell = windvector;
7699 Normalise(&windsmell);
7700 windsmell = windsmell * 2 + Person::players[j]->coords;
7701 if (distsq(&coords, &windsmell) < smelldistance && !Game::editorenabled) {
7702 aitype = attacktypecutoff;
7708 if (howactive < typesleeping && losupdatedelay < 0 && !Game::editorenabled && occluded < 2) {
7709 losupdatedelay = .2;
7710 for (unsigned j = 0; j < Person::players.size(); j++) {
7711 if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) {
7712 if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) {
7713 if (distsq(&coords, &Person::players[j]->coords) < 400) {
7714 if (normaldotproduct(facing, Person::players[j]->coords - coords) > 0) {
7715 if ((-1 == Object::checkcollide(
7716 DoRotation(jointPos(head), 0, yaw, 0) *
7719 DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0) *
7720 Person::players[j]->scale +
7721 Person::players[j]->coords) &&
7722 !Person::players[j]->isWallJump()) ||
7723 (Person::players[j]->animTarget == hanganim &&
7724 normaldotproduct(Person::players[j]->facing, coords - Person::players[j]->coords) < 0)) {
7726 if (j == 0 && Animation::animations[Person::players[j]->animTarget].height == lowheight) {
7735 if (lastseentime <= 0) {
7736 aitype = searchtype;
7738 lastseen = Person::players[j]->coords;
7746 if (aitype == attacktypecutoff && Game::musictype != 2) {
7747 if (creature != wolftype) {
7751 if (creature == wolftype) {
7761 if (aitype == searchtype) {
7762 aiupdatedelay -= multiplier;
7763 losupdatedelay -= multiplier;
7765 lastseentime -= multiplier;
7767 lastchecktime -= multiplier;
7769 if (isRun() && !onground) {
7770 if (coords.y > terrain.getHeight(coords.x, coords.z) + 10) {
7771 XYZ test2 = coords + facing;
7773 XYZ test = coords + facing;
7775 j = Object::checkcollide(test2, test, laststanding);
7777 j = Object::checkcollide(test2, test);
7781 setTargetAnimation(getStop());
7784 //aitype=passivetype;
7785 aitype = pathfindtype;
7786 finalfinaltarget = waypoints[waypoint];
7787 finalpathfindpoint = -1;
7788 targetpathfindpoint = -1;
7789 lastpathfindpoint = -1;
7790 lastpathfindpoint2 = -1;
7791 lastpathfindpoint3 = -1;
7792 lastpathfindpoint4 = -1;
7798 //check out last seen location
7799 if (aiupdatedelay < 0) {
7800 targetyaw = roughDirectionTo(coords, lastseen);
7801 lookyaw = targetyaw;
7802 aiupdatedelay = .05;
7805 if (distsqflat(&coords, &lastseen) < 1 * sq(scale * 5) || lastchecktime < 0) {
7808 lastseen.x += (float(Random() % 100) - 50) / 25;
7809 lastseen.z += (float(Random() % 100) - 50) / 25;
7820 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
7821 if (!avoidsomething) {
7822 targetyaw += 90 * (whichdirection * 2 - 1);
7824 XYZ leftpos, rightpos;
7825 float leftdist, rightdist;
7826 leftpos = coords + DoRotation(facing, 0, 90, 0);
7827 rightpos = coords - DoRotation(facing, 0, 90, 0);
7828 leftdist = distsq(&leftpos, &avoidwhere);
7829 rightdist = distsq(&rightpos, &avoidwhere);
7830 if (leftdist < rightdist) {
7838 if (collided < 1 || animTarget != jumpupanim) {
7841 if ((collided > .8 && jumppower >= 5)) {
7845 if (numenvsounds > 0 && ((!Tutorial::active || cananger) && hostile)) {
7846 for (int k = 0; k < numenvsounds; k++) {
7847 if (distsq(&coords, &envsound[k]) < 2 * (envsoundvol[k] + envsoundvol[k] * (creature == rabbittype) * 3)) {
7848 aitype = attacktypecutoff;
7853 if (!Person::players[0]->dead &&
7854 losupdatedelay < 0 &&
7855 !Game::editorenabled &&
7857 ((!Tutorial::active || cananger) && hostile)) {
7858 losupdatedelay = .2;
7859 if (distsq(&coords, &Person::players[0]->coords) < 4 && Animation::animations[animTarget].height != lowheight) {
7860 aitype = attacktypecutoff;
7863 if (abs(Random() % 2) || Animation::animations[animTarget].height != lowheight) {
7864 //TODO: factor out canSeePlayer()
7865 if (distsq(&coords, &Person::players[0]->coords) < 400) {
7866 if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) {
7867 if ((Object::checkcollide(
7868 DoRotation(jointPos(head), 0, yaw, 0) *
7871 DoRotation(Person::players[0]->jointPos(head), 0, Person::players[0]->yaw, 0) *
7872 Person::players[0]->scale +
7873 Person::players[0]->coords) == -1) ||
7874 (Person::players[0]->animTarget == hanganim && normaldotproduct(Person::players[0]->facing, coords - Person::players[0]->coords) < 0)) {
7875 /* //TODO: changed j to 0 on a whim, make sure this is correct
7876 (Person::players[j]->animTarget==hanganim&&normaldotproduct(
7877 Person::players[j]->facing,coords-Person::players[j]->coords)<0)
7879 aitype = attacktypecutoff;
7887 if (lastseentime < 0) {
7888 //aitype=passivetype;
7890 aitype = pathfindtype;
7891 finalfinaltarget = waypoints[waypoint];
7892 finalpathfindpoint = -1;
7893 targetpathfindpoint = -1;
7894 lastpathfindpoint = -1;
7895 lastpathfindpoint2 = -1;
7896 lastpathfindpoint3 = -1;
7897 lastpathfindpoint4 = -1;
7901 if (aitype != gethelptype) {
7905 //get help from buddies
7906 if (aitype == gethelptype) {
7907 runninghowlong += multiplier;
7908 aiupdatedelay -= multiplier;
7910 if (aiupdatedelay < 0 || ally == 0) {
7914 //TODO: factor out closest search somehow
7917 float closestdist = -1;
7918 for (unsigned k = 0; k < Person::players.size(); k++) {
7919 if ((k != id) && (k != 0) && !Person::players[k]->dead &&
7920 (Person::players[k]->howactive < typedead1) &&
7921 !Person::players[k]->skeleton.free &&
7922 (Person::players[k]->aitype == passivetype)) {
7923 float distance = distsq(&coords, &Person::players[k]->coords);
7924 if (closestdist == -1 || distance < closestdist) {
7925 closestdist = distance;
7930 if (closest != -1) {
7935 lastseen = Person::players[0]->coords;
7941 XYZ facing = coords;
7942 XYZ flatfacing = Person::players[ally]->coords;
7943 facing.y += jointPos(head).y * scale;
7944 flatfacing.y += Person::players[ally]->jointPos(head).y * Person::players[ally]->scale;
7945 if (-1 != Object::checkcollide(facing, flatfacing)) {
7949 //no available ally, run back to player
7951 Person::players[ally]->skeleton.free ||
7952 Person::players[ally]->aitype != passivetype ||
7953 lastseentime <= 0) {
7954 aitype = searchtype;
7960 targetyaw = roughDirectionTo(coords, Person::players[ally]->coords);
7961 lookyaw = targetyaw;
7962 aiupdatedelay = .05;
7965 if (distsqflat(&coords, &Person::players[ally]->coords) < 3) {
7966 aitype = searchtype;
7968 Person::players[ally]->aitype = searchtype;
7969 if (Person::players[ally]->lastseentime < lastseentime) {
7970 Person::players[ally]->lastseen = lastseen;
7971 Person::players[ally]->lastseentime = lastseentime;
7972 Person::players[ally]->lastchecktime = lastchecktime;
7976 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
7977 if (!avoidsomething) {
7978 targetyaw += 90 * (whichdirection * 2 - 1);
7980 XYZ leftpos, rightpos;
7981 float leftdist, rightdist;
7982 leftpos = coords + DoRotation(facing, 0, 90, 0);
7983 rightpos = coords - DoRotation(facing, 0, 90, 0);
7984 leftdist = distsq(&leftpos, &avoidwhere);
7985 rightdist = distsq(&rightpos, &avoidwhere);
7986 if (leftdist < rightdist) {
8001 if (collided < 1 || animTarget != jumpupanim) {
8004 if (collided > .8 && jumppower >= 5) {
8009 //retreiving a weapon on the ground
8010 if (aitype == getweapontype) {
8011 aiupdatedelay -= multiplier;
8012 lastchecktime -= multiplier;
8014 if (aiupdatedelay < 0) {
8020 float closestdist = -1;
8021 for (unsigned k = 0; k < weapons.size(); k++) {
8022 if (weapons[k].owner == -1) {
8023 float distance = distsq(&coords, &weapons[k].position);
8024 if (closestdist == -1 || distance < closestdist) {
8025 closestdist = distance;
8030 if (closest != -1) {
8039 if (!Person::players[0]->dead && ((!Tutorial::active || cananger) && hostile)) {
8040 if (ally < 0 || weaponactive != -1 || lastchecktime <= 0) {
8041 aitype = attacktypecutoff;
8045 if (!Person::players[0]->dead) {
8047 if (weapons[ally].owner != -1 ||
8048 distsq(&coords, &weapons[ally].position) > 16) {
8049 aitype = attacktypecutoff;
8052 //TODO: factor these out as moveToward()
8053 targetyaw = roughDirectionTo(coords, weapons[ally].position);
8054 lookyaw = targetyaw;
8055 aiupdatedelay = .05;
8058 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
8059 if (!avoidsomething) {
8060 targetyaw += 90 * (whichdirection * 2 - 1);
8062 XYZ leftpos, rightpos;
8063 float leftdist, rightdist;
8064 leftpos = coords + DoRotation(facing, 0, 90, 0);
8065 rightpos = coords - DoRotation(facing, 0, 90, 0);
8066 leftdist = distsq(&leftpos, &avoidwhere);
8067 rightdist = distsq(&rightpos, &avoidwhere);
8068 if (leftdist < rightdist) {
8084 if (animTarget != crouchremoveknifeanim &&
8085 animTarget != removeknifeanim) {
8086 throwtogglekeydown = 0;
8090 if (collided < 1 || animTarget != jumpupanim) {
8093 if ((collided > .8 && jumppower >= 5)) {
8098 if (aitype == attacktypecutoff) {
8099 aiupdatedelay -= multiplier;
8100 //dodge or reverse rabbit kicks, knife throws, flips
8101 if (damage < damagetolerance * 2 / 3) {
8102 if ((Person::players[0]->animTarget == rabbitkickanim ||
8103 Person::players[0]->animTarget == knifethrowanim ||
8104 (Person::players[0]->isFlip() &&
8105 normaldotproduct(Person::players[0]->facing, Person::players[0]->coords - coords) < 0)) &&
8106 !Person::players[0]->skeleton.free &&
8107 (aiupdatedelay < .1)) {
8112 if (Person::players[0]->animTarget != rabbitkickanim && Person::players[0]->weaponactive != -1) {
8113 if (weapons[Person::players[0]->weaponids[0]].getType() == knife) {
8114 if (isIdle() || isCrouch() || isRun() || isFlip()) {
8115 if (abs(Random() % 2) == 0) {
8116 setTargetAnimation(backhandspringanim);
8118 setTargetAnimation(rollanim);
8120 targetyaw += 90 * (abs(Random() % 2) * 2 - 1);
8123 if (animTarget == jumpupanim || animTarget == jumpdownanim) {
8124 setTargetAnimation(flipanim);
8129 aiupdatedelay = .02;
8132 //get confused by flips
8133 if (Person::players[0]->isFlip() &&
8134 !Person::players[0]->skeleton.free &&
8135 Person::players[0]->animTarget != walljumprightkickanim &&
8136 Person::players[0]->animTarget != walljumpleftkickanim) {
8137 if (distsq(&Person::players[0]->coords, &coords) < 25) {
8138 if ((1 - damage / damagetolerance) > .5) {
8143 //go for weapon on the ground
8144 if (wentforweapon < 3) {
8145 for (unsigned k = 0; k < weapons.size(); k++) {
8146 if (creature != wolftype) {
8147 if (num_weapons == 0 &&
8148 weapons[k].owner == -1 &&
8149 weapons[k].velocity.x == 0 &&
8150 weapons[k].velocity.z == 0 &&
8151 weapons[k].velocity.y == 0) {
8152 if (distsq(&coords, &weapons[k].position) < 16) {
8155 aitype = getweapontype;
8162 //dodge/reverse walljump kicks
8163 if (damage < damagetolerance / 2) {
8164 if (Animation::animations[animTarget].height != highheight) {
8165 if (damage < damagetolerance * .5 &&
8166 ((Person::players[0]->animTarget == walljumprightkickanim ||
8167 Person::players[0]->animTarget == walljumpleftkickanim) &&
8168 ((aiupdatedelay < .15 &&
8170 (aiupdatedelay < .08 &&
8171 difficulty != 2)))) {
8176 //walked off a ledge (?)
8177 if (isRun() && !onground) {
8178 if (coords.y > terrain.getHeight(coords.x, coords.z) + 10) {
8179 XYZ test2 = coords + facing;
8181 XYZ test = coords + facing;
8183 j = Object::checkcollide(test2, test, laststanding);
8185 j = Object::checkcollide(test2, test);
8189 setTargetAnimation(getStop());
8192 aitype = pathfindtype;
8193 finalfinaltarget = waypoints[waypoint];
8194 finalpathfindpoint = -1;
8195 targetpathfindpoint = -1;
8196 lastpathfindpoint = -1;
8197 lastpathfindpoint2 = -1;
8198 lastpathfindpoint3 = -1;
8199 lastpathfindpoint4 = -1;
8205 //lose sight of player in the air (?)
8206 if (Person::players[0]->coords.y > coords.y + 5 &&
8207 Animation::animations[Person::players[0]->animTarget].height != highheight &&
8208 !Person::players[0]->onterrain) {
8209 aitype = pathfindtype;
8210 finalfinaltarget = waypoints[waypoint];
8211 finalpathfindpoint = -1;
8212 targetpathfindpoint = -1;
8213 lastpathfindpoint = -1;
8214 lastpathfindpoint2 = -1;
8215 lastpathfindpoint3 = -1;
8216 lastpathfindpoint4 = -1;
8218 //it's time to think (?)
8219 if (aiupdatedelay < 0 &&
8220 !Animation::animations[animTarget].attack &&
8221 animTarget != staggerbackhighanim &&
8222 animTarget != staggerbackhardanim &&
8223 animTarget != backhandspringanim &&
8224 animTarget != dodgebackanim) {
8226 if (weaponactive == -1 && num_weapons > 0) {
8227 drawkeydown = Random() % 2;
8231 rabbitkickenabled = Random() % 2;
8233 XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity;
8234 XYZ targetpoint = Person::players[0]->coords;
8235 float vellength = findLength(&velocity);
8236 if (vellength != 0 &&
8237 distsq(&Person::players[0]->coords, &coords) < distsq(&rotatetarget, &coords)) {
8238 targetpoint += Person::players[0]->velocity *
8239 findDistance(&Person::players[0]->coords, &coords) / vellength;
8241 targetyaw = roughDirectionTo(coords, targetpoint);
8242 lookyaw = targetyaw;
8243 aiupdatedelay = .2 + fabs((float)(Random() % 100) / 1000);
8245 if (distsq(&coords, &Person::players[0]->coords) > 5 && (Person::players[0]->weaponactive == -1 || weaponactive != -1)) {
8247 } else if ((distsq(&coords, &Person::players[0]->coords) > 16 ||
8248 distsq(&coords, &Person::players[0]->coords) < 9) &&
8249 Person::players[0]->weaponactive != -1) {
8251 } else if (Random() % 6 == 0 || (creature == wolftype && Random() % 3 == 0)) {
8256 //chill out around the corpse
8257 if (Person::players[0]->dead) {
8259 if (Random() % 10 == 0) {
8262 if (Random() % 100 == 0) {
8263 aitype = pathfindtype;
8264 finalfinaltarget = waypoints[waypoint];
8265 finalpathfindpoint = -1;
8266 targetpathfindpoint = -1;
8267 lastpathfindpoint = -1;
8268 lastpathfindpoint2 = -1;
8269 lastpathfindpoint3 = -1;
8270 lastpathfindpoint4 = -1;
8279 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
8280 targetyaw += 90 * (whichdirection * 2 - 1);
8283 if (Random() % 2 == 0 || weaponactive != -1 || creature == wolftype) {
8288 if (isRun() && Random() % 6 && distsq(&coords, &Person::players[0]->coords) > 7) {
8293 if (aitype != playercontrolled &&
8298 for (unsigned j = 0; j < Person::players.size(); j++) {
8299 if (j != id && !Person::players[j]->skeleton.free &&
8300 Person::players[j]->hasvictim &&
8301 (Tutorial::active && reversaltrain ||
8302 Random() % 2 == 0 && difficulty == 2 ||
8303 Random() % 4 == 0 && difficulty == 1 ||
8304 Random() % 8 == 0 && difficulty == 0 ||
8305 Person::players[j]->lastattack2 == Person::players[j]->animTarget &&
8306 Person::players[j]->lastattack3 == Person::players[j]->animTarget &&
8307 (Random() % 2 == 0 || difficulty == 2) ||
8308 (isIdle() || isRun()) &&
8309 Person::players[j]->weaponactive != -1 ||
8310 Person::players[j]->animTarget == swordslashanim &&
8311 weaponactive != -1 ||
8312 Person::players[j]->animTarget == staffhitanim ||
8313 Person::players[j]->animTarget == staffspinhitanim)) {
8314 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 4 &&
8315 Person::players[j]->victim == Person::players[id] &&
8316 (Person::players[j]->animTarget == sweepanim ||
8317 Person::players[j]->animTarget == spinkickanim ||
8318 Person::players[j]->animTarget == staffhitanim ||
8319 Person::players[j]->animTarget == staffspinhitanim ||
8320 Person::players[j]->animTarget == winduppunchanim ||
8321 Person::players[j]->animTarget == upunchanim ||
8322 Person::players[j]->animTarget == wolfslapanim ||
8323 Person::players[j]->animTarget == knifeslashstartanim ||
8324 Person::players[j]->animTarget == swordslashanim &&
8325 (distsq(&Person::players[j]->coords, &coords) < 2 ||
8326 weaponactive != -1))) {
8336 Person::players[target]->Reverse();
8343 if (collided > .8 && jumppower >= 5 ||
8344 distsq(&coords, &Person::players[0]->coords) > 400 &&
8346 creature == rabbittype) {
8349 //TODO: why are we controlling the human?
8350 if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) {
8351 Person::players[0]->jumpkeydown = 0;
8353 if (Person::players[0]->animTarget == jumpdownanim &&
8354 distsq(&Person::players[0]->coords, &coords) < 40) {
8361 if (Tutorial::active) {
8367 XYZ facing = coords;
8368 XYZ flatfacing = Person::players[0]->coords;
8369 facing.y += jointPos(head).y * scale;
8370 flatfacing.y += Person::players[0]->jointPos(head).y * Person::players[0]->scale;
8371 if (occluded >= 2) {
8372 if (-1 != Object::checkcollide(facing, flatfacing)) {
8376 if (lastseentime <= 0 &&
8377 (creature != wolftype ||
8378 weaponstuck == -1)) {
8379 aitype = searchtype;
8381 lastseen = Person::players[0]->coords;
8390 if (Animation::animations[Person::players[0]->animTarget].height == highheight &&
8391 (aitype == attacktypecutoff ||
8392 aitype == searchtype)) {
8393 if (Person::players[0]->coords.y > terrain.getHeight(Person::players[0]->coords.x, Person::players[0]->coords.z) + 10) {
8394 XYZ test = Person::players[0]->coords;
8396 if (-1 == Object::checkcollide(Person::players[0]->coords, test)) {
8402 if (aitype == passivetype && !(numwaypoints > 1) ||
8404 pause && damage > superpermanentdamage) {
8423 XYZ flatfacing = DoRotation(facing, 0, yaw + 180, 0);
8424 facing = flatfacing;
8426 if (aitype == attacktypecutoff) {
8427 targetheadyaw = 180 - roughDirectionTo(coords, Person::players[0]->coords);
8428 targetheadpitch = pitchTo(coords, Person::players[0]->coords);
8429 } else if (howactive >= typesleeping) {
8430 targetheadyaw = targetyaw;
8431 targetheadpitch = 0;
8433 if (interestdelay <= 0) {
8434 interestdelay = .7 + (float)(abs(Random() % 100)) / 100;
8435 headtarget = coords;
8436 headtarget.x += (float)(abs(Random() % 200) - 100) / 100;
8437 headtarget.z += (float)(abs(Random() % 200) - 100) / 100;
8438 headtarget.y += (float)(abs(Random() % 200) - 100) / 300;
8439 headtarget += facing * 1.5;
8441 targetheadyaw = 180 - roughDirectionTo(coords, headtarget);
8442 targetheadpitch = pitchTo(coords, headtarget);