2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - 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 GLubyte bloodText[512 * 512 * 3];
46 extern GLubyte wolfbloodText[512 * 512 * 3];
47 extern int bloodtoggle;
48 extern bool autoslomo;
49 extern float camerashake;
51 extern float viewdistance;
52 extern float blackout;
53 extern int difficulty;
54 extern bool decalstoggle;
55 extern float fadestart;
57 extern bool winfreeze;
58 extern bool showpoints;
59 extern bool immediate;
60 extern float smoketex;
61 extern bool reversaltrain;
62 extern bool canattack;
64 extern float damagedealt;
66 extern float hostiletime;
68 extern bool gamestarted;
70 extern XYZ envsound[30];
71 extern float envsoundvol[30];
72 extern int numenvsounds;
73 extern float envsoundlife[30];
75 extern XYZ windvector;
77 std::vector<std::shared_ptr<Person>> Person::players(1, std::shared_ptr<Person>(new Person()));
82 , animCurrent(bounceidleanim)
83 , animTarget(bounceidleanim)
90 , howactive(typeactive)
92 , superruntoggle(false)
135 , rabbitkickenabled(false)
149 , superpermanentdamage(0)
192 , normalsupdatedelay(0)
196 , forwardkeydown(false)
197 , forwardstogglekeydown(false)
198 , rightkeydown(false)
202 , jumptogglekeydown(false)
203 , crouchkeydown(false)
204 , crouchtogglekeydown(false)
206 , drawtogglekeydown(false)
207 , throwkeydown(false)
208 , throwtogglekeydown(false)
209 , attackkeydown(false)
231 , whichdirection(false)
232 , whichdirectiondelay(0)
233 , avoidsomething(false)
243 , lefthandmorphness(0)
244 , righthandmorphness(0)
248 , targetlefthandmorphness(0)
249 , targetrighthandmorphness(0)
250 , targetheadmorphness(1)
251 , targetchestmorphness(0)
252 , targettailmorphness(0)
253 , lefthandmorphstart(0)
254 , lefthandmorphend(0)
255 , righthandmorphstart(0)
256 , righthandmorphend(0)
266 , highreversaldelay(0)
267 , lowreversaldelay(0)
316 , weaponstuckwhere(0)
329 , finalpathfindpoint(0)
330 , targetpathfindpoint(0)
331 , lastpathfindpoint(0)
332 , lastpathfindpoint2(0)
333 , lastpathfindpoint3(0)
334 , lastpathfindpoint4(0)
354 , neckspurtparticledelay(0)
359 , rabbitkickragdoll(false)
369 /* Read a person in tfile. Throws an error if it’s not valid */
370 Person::Person(FILE* tfile, int mapvers, unsigned i)
374 funpackf(tfile, "Bi Bi Bf Bf Bf Bi", &whichskin, &creature, &coords.x, &coords.y, &coords.z, &num_weapons);
376 funpackf(tfile, "Bi", &howactive);
378 howactive = typeactive;
381 funpackf(tfile, "Bf", &scale);
386 funpackf(tfile, "Bb", &immobile);
391 funpackf(tfile, "Bf", &yaw);
396 if (num_weapons < 0 || num_weapons > 5) {
397 throw InvalidPersonException();
399 if (num_weapons > 0 && num_weapons < 5) {
400 for (int j = 0; j < num_weapons; j++) {
401 weaponids[j] = weapons.size();
403 funpackf(tfile, "Bi", &type);
404 weapons.push_back(Weapon(type, id));
407 funpackf(tfile, "Bi", &numwaypoints);
408 for (int j = 0; j < numwaypoints; j++) {
409 funpackf(tfile, "Bf", &waypoints[j].x);
410 funpackf(tfile, "Bf", &waypoints[j].y);
411 funpackf(tfile, "Bf", &waypoints[j].z);
413 funpackf(tfile, "Bi", &waypointtype[j]);
415 waypointtype[j] = wpkeepwalking;
419 funpackf(tfile, "Bi", &waypoint);
420 if (waypoint > (numwaypoints - 1)) {
424 funpackf(tfile, "Bf Bf Bf", &armorhead, &armorhigh, &armorlow);
425 funpackf(tfile, "Bf Bf Bf", &protectionhead, &protectionhigh, &protectionlow);
426 funpackf(tfile, "Bf Bf Bf", &metalhead, &metalhigh, &metallow);
427 funpackf(tfile, "Bf Bf", &power, &speedmult);
429 float headprop, legprop, armprop, bodyprop;
432 funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
440 if (creature == wolftype) {
441 proportionhead = 1.1 * headprop;
442 proportionbody = 1.1 * bodyprop;
443 proportionarms = 1.1 * armprop;
444 proportionlegs = 1.1 * legprop;
445 } else if (creature == rabbittype) {
446 proportionhead = 1.2 * headprop;
447 proportionbody = 1.05 * bodyprop;
448 proportionarms = 1.00 * armprop;
449 proportionlegs = 1.1 * legprop;
450 proportionlegs.y = 1.05 * legprop;
453 funpackf(tfile, "Bi", &numclothes);
454 for (int k = 0; k < numclothes; k++) {
456 funpackf(tfile, "Bi", &templength);
457 for (int l = 0; l < templength; l++) {
458 funpackf(tfile, "Bb", &clothes[k][l]);
460 clothes[k][templength] = '\0';
461 funpackf(tfile, "Bf Bf Bf", &clothestintr[k], &clothestintg[k], &clothestintb[k]);
467 if (creature == wolftype) {
469 damagetolerance = 300;
476 realoldcoords = coords;
479 void Person::skeletonLoad(bool clothes)
482 if (creature != wolftype) {
484 "Skeleton/BasicFigure",
485 "Skeleton/BasicFigureLow",
486 "Skeleton/RabbitBelt",
488 "Models/Body2.solid",
489 "Models/Body3.solid",
490 "Models/Body4.solid",
491 "Models/Body5.solid",
492 "Models/Body6.solid",
493 "Models/Body7.solid",
494 "Models/BodyLow.solid",
499 "Skeleton/BasicFigureWolf",
500 "Skeleton/BasicFigureWolfLow",
501 "Skeleton/RabbitBelt",
503 "Models/Wolf2.solid",
504 "Models/Wolf3.solid",
505 "Models/Wolf4.solid",
506 "Models/Wolf5.solid",
507 "Models/Wolf6.solid",
508 "Models/Wolf7.solid",
509 "Models/WolfLow.solid",
514 skeleton.drawmodel.textureptr.load(creatureskin[creature][whichskin], 1, &skeleton.skinText[0], &skeleton.skinsize);
520 * GameTick/doPlayerCollisions
522 void Person::CheckKick()
524 if (!(hasvictim && (animTarget == rabbitkickanim && victim && victim != this->shared_from_this() && frameCurrent >= 2 && animCurrent == rabbitkickanim) && distsq(&coords, &victim->coords) < 1.2 && !victim->skeleton.free)) {
528 if (Animation::animations[victim->animTarget].height != lowheight) {
529 float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
530 XYZ relative = velocity;
532 Normalise(&relative);
536 if (!Tutorial::active) {
537 emit_sound_at(heavyimpactsound, victim->coords);
540 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
541 victim->skeleton.joints[i].velocity += relative * 120 * damagemult;
544 victim->DoDamage(100 * damagemult / victim->protectionhigh);
551 animTarget = backflipanim;
553 velocity = facing * -10;
557 resume_stream(whooshsound);
560 award_bonus(id, cannon);
561 } else if (victim->isCrouch()) {
562 animTarget = rabbitkickreversedanim;
563 animCurrent = rabbitkickreversedanim;
564 victim->animCurrent = rabbitkickreversalanim;
565 victim->animTarget = rabbitkickreversalanim;
571 victim->oldcoords = victim->coords;
572 coords = victim->coords;
573 victim->targetyaw = targetyaw;
574 victim->victim = this->shared_from_this();
581 * GameTick/doPlayerCollisions - spread fire between players
582 * GameTick/doDevKeys - press f to ignite
583 * Person::DoStuff - spread fire from lit campfires and bushes
585 void Person::CatchFire()
587 XYZ flatfacing, flatvelocity;
589 for (int i = 0; i < 10; i++) {
590 howmany = fabs(Random() % (skeleton.joints.size()));
592 flatvelocity = skeleton.joints[howmany].velocity;
593 flatfacing = skeleton.joints[howmany].position * scale + coords;
595 flatvelocity = velocity;
596 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
598 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
603 emit_sound_at(firestartsound, coords);
605 emit_stream_at(stream_firesound, coords);
613 * idle animation for this creature (depending on status)
615 int Person::getIdle()
617 if (Dialog::inDialog() && (howactive == typeactive) && (creature == rabbittype)) {
620 if (hasvictim && (victim != this->shared_from_this())) {
621 if ((!victim->dead && victim->aitype != passivetype &&
622 victim->aitype != searchtype && aitype != passivetype && aitype != searchtype &&
623 victim->id < Person::players.size())) {
624 if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) {
625 if (creature == rabbittype) {
626 return fightidleanim;
628 if (creature == wolftype) {
632 if (aitype == playercontrolled && stunned <= 0 && weaponactive != -1) {
633 if (weapons[weaponids[weaponactive]].getType() == knife) {
634 return knifefightidleanim;
636 if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1) {
637 return swordfightidlebothanim;
639 if (weapons[weaponids[weaponactive]].getType() == sword) {
640 return swordfightidleanim;
642 if (weapons[weaponids[weaponactive]].getType() == staff) {
643 return swordfightidleanim;
646 if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause) {
647 return fightsidestep;
651 if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype) {
654 if (howactive == typesitting) {
657 if (howactive == typesittingwall) {
660 if (howactive == typesleeping) {
663 if (howactive == typedead1) {
666 if (howactive == typedead2) {
669 if (howactive == typedead3) {
672 if (howactive == typedead4) {
675 if (creature == rabbittype) {
676 return bounceidleanim;
678 if (creature == wolftype) {
685 * crouch animation for this creature
687 int Person::getCrouch()
689 if (creature == rabbittype) {
692 if (creature == wolftype) {
693 return wolfcrouchanim;
699 * running animation for this creature (can be upright or all fours)
703 if (creature == rabbittype && (!superruntoggle || weaponactive != -1)) {
706 if (creature == wolftype && (!superruntoggle)) {
710 if (creature == rabbittype && (superruntoggle && weaponactive == -1)) {
711 return rabbitrunninganim;
713 if (creature == wolftype && (superruntoggle)) {
714 return wolfrunninganim;
721 int Person::getStop()
723 if (creature == rabbittype) {
726 if (creature == wolftype) {
734 int Person::getLanding()
736 if (creature == rabbittype) {
739 if (creature == wolftype) {
747 int Person::getLandhard()
749 if (creature == rabbittype) {
752 if (creature == wolftype) {
753 return wolflandhardanim;
761 * Person::DoAnimations
764 SolidHitBonus(int playerid)
766 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo) {
767 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
769 award_bonus(playerid, solidhit);
774 * spawns blood effects
776 void Person::DoBlood(float howmuch, int which)
778 // FIXME: should abstract out inputs
779 static int bleedxint, bleedyint;
781 if (bloodtoggle && !Tutorial::active) {
782 if (bleeding <= 0 && spurt) {
784 for (int i = 0; i < 3; i++) {
785 // emit blood particles
788 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
789 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
790 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
791 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
794 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
795 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
796 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
797 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
800 if (Random() % 2 == 0) { // 50% chance
801 for (int i = 0; i < 3; i++) {
802 if (Random() % 2 != 0) {
803 // emit teeth particles
806 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
807 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
810 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
811 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
815 Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
817 Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
819 Sprite::setLastSpriteSpecial(3); // sets it to teeth
825 // FIXME: manipulating attributes
826 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
829 if (creature == rabbittype) {
830 while (bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
831 bleedxint = abs(Random() % 512);
832 bleedyint = abs(Random() % 512);
835 if (creature == wolftype) {
836 while (wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
837 bleedxint = abs(Random() % 512);
838 bleedyint = abs(Random() % 512);
843 bleedy /= realtexdetail;
844 bleedx /= realtexdetail;
845 direction = abs(Random() % 2) * 2 - 1;
854 * spawns big blood effects and ???
855 * modifies character's skin texture
857 void Person::DoBloodBig(float howmuch, int which)
859 static int bleedxint, bleedyint, i, j;
861 if (howmuch && id == 0) {
865 if (!Tutorial::active || id == 0) {
866 if (aitype != playercontrolled && howmuch > 0) {
870 if (creature == wolftype) {
871 int i = abs(Random() % 2);
873 whichsound = snarlsound;
876 whichsound = snarl2sound;
879 if (creature == rabbittype) {
880 int i = abs(Random() % 2);
882 whichsound = rabbitpainsound;
884 if (i == 1 && howmuch >= 2) {
885 whichsound = rabbitpain1sound;
889 if (whichsound != -1) {
890 emit_sound_at(whichsound, coords);
896 if (id == 0 && howmuch > 0) {
900 if (bloodtoggle && decalstoggle && !Tutorial::active) {
901 if (bleeding <= 0 && spurt) {
903 for (int i = 0; i < 3; i++) {
904 // emit blood particles
905 // FIXME: copypaste from above
908 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
909 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
910 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
911 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
914 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
915 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
916 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
917 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
922 // weird texture manipulation code follows.
923 // looks like this is painting blood onto the character's skin texture
924 // FIXME: surely there's a better way
926 int offsetx = 0, offsety = 0;
928 offsety = Random() % 40;
929 offsetx = abs(Random() % 60);
931 if (which == 190 || which == 185) {
932 offsety = Random() % 40;
933 offsetx = abs(Random() % 100) - 20;
936 offsety = Random() % 10;
937 offsetx = Random() % 10;
940 offsety = Random() % 20;
941 offsetx = Random() % 20;
943 if (which == 220 || which == 215) {
952 if (creature == rabbittype) {
953 for (i = 0; i < 512; i++) {
954 for (j = 0; j < 512; j++) {
955 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
972 if (creature == wolftype) {
973 for (i = 0; i < 512; i++) {
974 for (j = 0; j < 512; j++) {
975 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
1004 if (endx > 512 - 1) {
1007 if (endy > 512 - 1) {
1010 if (endx < startx) {
1013 if (endy < starty) {
1017 startx /= realtexdetail;
1018 starty /= realtexdetail;
1019 endx /= realtexdetail;
1020 endy /= realtexdetail;
1022 int texdetailint = realtexdetail;
1024 if (creature == rabbittype) {
1025 for (i = startx; i < endx; i++) {
1026 for (j = starty; j < endy; j++) {
1027 if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
1028 color = Random() % 85 + 170;
1029 where = i * skeleton.skinsize * 3 + j * 3;
1030 if (skeleton.skinText[where + 0] > color / 2) {
1031 skeleton.skinText[where + 0] = color / 2;
1033 skeleton.skinText[where + 1] = 0;
1034 skeleton.skinText[where + 2] = 0;
1039 if (creature == wolftype) {
1040 for (i = startx; i < endx; i++) {
1041 for (j = starty; j < endy; j++) {
1042 if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
1043 color = Random() % 85 + 170;
1044 where = i * skeleton.skinsize * 3 + j * 3;
1045 if (skeleton.skinText[where + 0] > color / 2) {
1046 skeleton.skinText[where + 0] = color / 2;
1048 skeleton.skinText[where + 1] = 0;
1049 skeleton.skinText[where + 2] = 0;
1054 skeleton.drawmodel.textureptr.bind();
1059 if (creature == rabbittype) {
1060 while (bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
1061 bleedxint = abs(Random() % 512);
1062 bleedyint = abs(Random() % 512);
1065 if (creature == wolftype) {
1066 while (wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
1067 bleedxint = abs(Random() % 512);
1068 bleedyint = abs(Random() % 512);
1071 bleedy = bleedxint + offsetx;
1072 bleedx = bleedyint + offsety;
1073 bleedy /= realtexdetail;
1074 bleedx /= realtexdetail;
1081 if (bleedx > skeleton.skinsize - 1) {
1082 bleedx = skeleton.skinsize - 1;
1084 if (bleedy > skeleton.skinsize - 1) {
1085 bleedy = skeleton.skinsize - 1;
1087 direction = abs(Random() % 2) * 2 - 1;
1089 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
1090 deathbleeding += bleeding;
1091 bloodloss += bleeding * 3;
1093 if (!Tutorial::active && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
1094 if (abs(Random() % 2) == 0) {
1095 aitype = gethelptype;
1098 aitype = attacktypecutoff;
1108 * similar to DoBloodBig
1110 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
1113 static XYZ bloodvel;
1114 static XYZ startpoint, endpoint, colpoint, movepoint;
1115 static float rotationpoint;
1116 static int whichtri;
1117 static XYZ p1, p2, p3, p0;
1120 float coordsx, coordsy;
1123 if (bloodtoggle && decalstoggle && !Tutorial::active) {
1125 if (!skeleton.free) {
1126 where = DoRotation(where, 0, -yaw, 0);
1130 startpoint.y += 100;
1135 // ray testing for a tri in the character model
1136 whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
1137 if (whichtri != -1) {
1138 // low level geometry math
1140 p1 = skeleton.drawmodel.getTriangleVertex(whichtri, 0);
1141 p2 = skeleton.drawmodel.getTriangleVertex(whichtri, 1);
1142 p3 = skeleton.drawmodel.getTriangleVertex(whichtri, 2);
1144 bary.x = distsq(&p0, &p1);
1145 bary.y = distsq(&p0, &p2);
1146 bary.z = distsq(&p0, &p3);
1148 total = bary.x + bary.y + bary.z;
1153 bary.x = 1 - bary.x;
1154 bary.y = 1 - bary.y;
1155 bary.z = 1 - bary.z;
1157 total = bary.x + bary.y + bary.z;
1162 gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0];
1163 gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1];
1164 gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2];
1165 gyy.x = skeleton.drawmodel.Triangles[whichtri].gy[0];
1166 gyy.y = skeleton.drawmodel.Triangles[whichtri].gy[1];
1167 gyy.z = skeleton.drawmodel.Triangles[whichtri].gy[2];
1168 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;
1169 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;
1171 if (bleeding <= 0 && spurt) {
1173 for (int i = 0; i < 3; i++) {
1174 // emit blood particles
1175 // FIXME: more copypaste code
1177 if (skeleton.free) {
1178 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
1179 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
1180 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
1181 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
1184 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
1185 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
1186 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
1187 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
1192 // texture manipulation follows
1194 int offsetx = 0, offsety = 0;
1195 offsetx = (1 + coordsy) * 512 - 291;
1196 offsety = coordsx * 512 - 437;
1203 if (creature == rabbittype) {
1204 for (i = 0; i < 512; i++) {
1205 for (j = 0; j < 512; j++) {
1206 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
1223 if (creature == wolftype) {
1224 for (i = 0; i < 512; i++) {
1225 for (j = 0; j < 512; j++) {
1226 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
1254 if (endx > 512 - 1) {
1257 if (endy > 512 - 1) {
1260 if (endx < startx) {
1263 if (endy < starty) {
1267 startx /= realtexdetail;
1268 starty /= realtexdetail;
1269 endx /= realtexdetail;
1270 endy /= realtexdetail;
1272 int texdetailint = realtexdetail;
1274 if (creature == rabbittype) {
1275 for (i = startx; i < endx; i++) {
1276 for (j = starty; j < endy; j++) {
1277 if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
1278 color = Random() % 85 + 170;
1279 where = i * skeleton.skinsize * 3 + j * 3;
1280 if (skeleton.skinText[where + 0] > color / 2) {
1281 skeleton.skinText[where + 0] = color / 2;
1283 skeleton.skinText[where + 1] = 0;
1284 skeleton.skinText[where + 2] = 0;
1285 } else if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= 160 + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= 160 - 4) {
1286 color = Random() % 85 + 170;
1287 where = i * skeleton.skinsize * 3 + j * 3;
1288 if (skeleton.skinText[where + 0] > color / 2) {
1289 skeleton.skinText[where + 0] = color / 2;
1291 skeleton.skinText[where + 1] = 0;
1292 skeleton.skinText[where + 2] = 0;
1297 if (creature == wolftype) {
1298 for (i = startx; i < endx; i++) {
1299 for (j = starty; j < endy; j++) {
1300 if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
1301 color = Random() % 85 + 170;
1302 where = i * skeleton.skinsize * 3 + j * 3;
1303 if (skeleton.skinText[where + 0] > color / 2) {
1304 skeleton.skinText[where + 0] = color / 2;
1306 skeleton.skinText[where + 1] = 0;
1307 skeleton.skinText[where + 2] = 0;
1308 } else if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= 160 + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= 160 - 4) {
1309 color = Random() % 85 + 170;
1310 where = i * skeleton.skinsize * 3 + j * 3;
1311 if (skeleton.skinText[where + 0] > color / 2) {
1312 skeleton.skinText[where + 0] = color / 2;
1314 skeleton.skinText[where + 1] = 0;
1315 skeleton.skinText[where + 2] = 0;
1320 skeleton.drawmodel.textureptr.bind();
1323 bleedy = (1 + coordsy) * 512;
1324 bleedx = coordsx * 512;
1325 bleedy /= realtexdetail;
1326 bleedx /= realtexdetail;
1333 if (bleedx > skeleton.skinsize - 1) {
1334 bleedx = skeleton.skinsize - 1;
1336 if (bleedy > skeleton.skinsize - 1) {
1337 bleedy = skeleton.skinsize - 1;
1339 direction = abs(Random() % 2) * 2 - 1;
1341 if (whichtri == -1) {
1345 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
1346 deathbleeding += bleeding;
1347 bloodloss += bleeding * 3;
1349 if (!Tutorial::active && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
1350 if (abs(Random() % 2) == 0) {
1351 aitype = gethelptype;
1354 aitype = attacktypecutoff;
1365 * guessing this performs a reversal
1367 void Person::Reverse()
1369 if (!((victim->aitype == playercontrolled || hostiletime > 1 || staggerdelay <= 0) && victim->animTarget != jumpupanim && victim->animTarget != jumpdownanim && (!Tutorial::active || cananger) && hostile)) {
1373 if (normaldotproduct(victim->facing, victim->coords - coords) > 0 && (victim->id != 0 || difficulty >= 2) && (creature != wolftype || victim->creature == wolftype)) {
1377 if (animTarget == sweepanim) {
1378 animTarget = sweepreversedanim;
1379 animCurrent = sweepreversedanim;
1380 victim->animCurrent = sweepreversalanim;
1381 victim->animTarget = sweepreversalanim;
1383 if (animTarget == spinkickanim) {
1384 animTarget = spinkickreversedanim;
1385 animCurrent = spinkickreversedanim;
1386 victim->animCurrent = spinkickreversalanim;
1387 victim->animTarget = spinkickreversalanim;
1389 if (animTarget == upunchanim || animTarget == rabbittacklinganim) {
1390 if (animTarget == rabbittacklinganim) {
1393 victim->frameCurrent = 6;
1394 victim->frameTarget = 7;
1396 animTarget = upunchreversedanim;
1397 animCurrent = upunchreversedanim;
1398 victim->animCurrent = upunchreversalanim;
1399 victim->animTarget = upunchreversalanim;
1401 if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
1402 if (victim->weaponactive != -1) {
1403 victim->throwtogglekeydown = 1;
1404 XYZ tempVelocity = victim->velocity * .2;
1405 if (tempVelocity.x == 0) {
1406 tempVelocity.x = .1;
1408 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1409 victim->num_weapons--;
1410 if (victim->num_weapons) {
1411 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1412 if (victim->weaponstuck == victim->num_weapons) {
1413 victim->weaponstuck = 0;
1417 victim->weaponactive = -1;
1418 for (unsigned j = 0; j < Person::players.size(); j++) {
1419 Person::players[j]->wentforweapon = 0;
1423 animTarget = staffhitreversedanim;
1424 animCurrent = staffhitreversedanim;
1425 victim->animCurrent = staffhitreversalanim;
1426 victim->animTarget = staffhitreversalanim;
1428 if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
1429 if (victim->weaponactive != -1) {
1430 victim->throwtogglekeydown = 1;
1431 XYZ tempVelocity = victim->velocity * .2;
1432 if (tempVelocity.x == 0) {
1433 tempVelocity.x = .1;
1435 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1436 victim->num_weapons--;
1437 if (victim->num_weapons) {
1438 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1439 if (victim->weaponstuck == victim->num_weapons) {
1440 victim->weaponstuck = 0;
1444 victim->weaponactive = -1;
1445 for (unsigned j = 0; j < Person::players.size(); j++) {
1446 Person::players[j]->wentforweapon = 0;
1449 animTarget = staffspinhitreversedanim;
1450 animCurrent = staffspinhitreversedanim;
1451 victim->animCurrent = staffspinhitreversalanim;
1452 victim->animTarget = staffspinhitreversalanim;
1454 if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
1455 if (victim->weaponactive != -1) {
1456 victim->throwtogglekeydown = 1;
1457 XYZ tempVelocity = victim->velocity * .2;
1458 if (tempVelocity.x == 0) {
1459 tempVelocity.x = .1;
1461 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1462 victim->num_weapons--;
1463 if (victim->num_weapons) {
1464 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1465 if (victim->weaponstuck == victim->num_weapons) {
1466 victim->weaponstuck = 0;
1470 victim->weaponactive = -1;
1471 for (unsigned j = 0; j < Person::players.size(); j++) {
1472 Person::players[j]->wentforweapon = 0;
1475 animTarget = swordslashreversedanim;
1476 animCurrent = swordslashreversedanim;
1477 victim->animCurrent = swordslashreversalanim;
1478 victim->animTarget = swordslashreversalanim;
1480 if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
1481 if (victim->weaponactive != -1) {
1482 victim->throwtogglekeydown = 1;
1483 XYZ tempVelocity = victim->velocity * .2;
1484 if (tempVelocity.x == 0) {
1485 tempVelocity.x = .1;
1487 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1488 victim->num_weapons--;
1489 if (victim->num_weapons) {
1490 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1491 if (victim->weaponstuck == victim->num_weapons) {
1492 victim->weaponstuck = 0;
1496 victim->weaponactive = -1;
1497 for (unsigned j = 0; j < Person::players.size(); j++) {
1498 Person::players[j]->wentforweapon = 0;
1501 animTarget = knifeslashreversedanim;
1502 animCurrent = knifeslashreversedanim;
1503 victim->animCurrent = knifeslashreversalanim;
1504 victim->animTarget = knifeslashreversalanim;
1506 if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim) {
1507 victim->targettilt2 = targettilt2;
1508 victim->frameCurrent = frameCurrent;
1509 victim->frameTarget = frameTarget;
1510 victim->target = target;
1511 victim->velocity = 0;
1512 victim->oldcoords = victim->coords;
1513 victim->coords = coords;
1514 victim->targetyaw = targetyaw;
1515 victim->yaw = targetyaw;
1516 victim->victim = this->shared_from_this();
1518 if (animTarget == winduppunchanim) {
1519 animTarget = winduppunchblockedanim;
1520 victim->animTarget = blockhighleftanim;
1521 victim->frameTarget = 1;
1522 victim->target = .5;
1523 victim->victim = this->shared_from_this();
1524 victim->targetyaw = targetyaw + 180;
1526 if (animTarget == wolfslapanim) {
1527 animTarget = winduppunchblockedanim;
1528 victim->animTarget = blockhighleftanim;
1529 victim->frameTarget = 1;
1530 victim->target = .5;
1531 victim->victim = this->shared_from_this();
1532 victim->targetyaw = targetyaw + 180;
1534 if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) {
1535 animTarget = swordslashparriedanim;
1536 parriedrecently = .4;
1537 victim->parriedrecently = 0;
1538 victim->animTarget = swordslashparryanim;
1539 victim->frameTarget = 1;
1540 victim->target = .5;
1541 victim->victim = this->shared_from_this();
1542 victim->targetyaw = targetyaw + 180;
1544 if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
1545 if (victim->weaponactive != -1) {
1546 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1547 if (weapons[victim->weaponids[0]].getType() == staff) {
1548 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1550 if (weapons[weaponids[0]].getType() == staff) {
1551 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1553 emit_sound_at(swordstaffsound, victim->coords);
1555 emit_sound_at(metalhitsound, victim->coords);
1559 victim->Puff(righthand);
1561 victim->frameTarget = 0;
1562 victim->animTarget = staggerbackhighanim;
1563 victim->targetyaw = targetyaw + 180;
1565 aim = DoRotation(facing, 0, 90, 0) * 21;
1567 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
1568 victim->num_weapons--;
1569 if (victim->num_weapons) {
1570 victim->weaponids[0] = victim->weaponids[num_weapons];
1571 if (victim->weaponstuck == victim->num_weapons) {
1572 victim->weaponstuck = 0;
1575 victim->weaponactive = -1;
1576 for (unsigned i = 0; i < Person::players.size(); i++) {
1577 Person::players[i]->wentforweapon = 0;
1581 if (abs(Random() % 20) == 0) {
1582 if (weaponactive != -1) {
1583 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1584 if (weapons[victim->weaponids[0]].getType() == staff) {
1585 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1587 if (weapons[weaponids[0]].getType() == staff) {
1588 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1591 emit_sound_at(swordstaffsound, coords);
1593 emit_sound_at(metalhitsound, coords);
1601 animTarget = staggerbackhighanim;
1602 targetyaw = targetyaw + 180;
1604 aim = DoRotation(facing, 0, 90, 0) * 21;
1606 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
1609 weaponids[0] = weaponids[num_weapons];
1610 if (weaponstuck == num_weapons) {
1615 for (unsigned i = 0; i < Person::players.size(); i++) {
1616 Person::players[i]->wentforweapon = 0;
1621 if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) {
1622 if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) {
1623 victim->animTarget = dodgebackanim;
1624 victim->frameTarget = 0;
1628 rotatetarget = coords - victim->coords;
1629 Normalise(&rotatetarget);
1630 victim->targetyaw = -asin(0 - rotatetarget.x);
1631 victim->targetyaw *= 360 / 6.28;
1632 if (rotatetarget.z < 0) {
1633 victim->targetyaw = 180 - victim->targetyaw;
1636 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1638 victim->lastattack3 = victim->lastattack2;
1639 victim->lastattack2 = victim->lastattack;
1640 victim->lastattack = victim->animTarget;
1642 victim->animTarget = sweepanim;
1643 victim->frameTarget = 0;
1647 rotatetarget = coords - victim->coords;
1648 Normalise(&rotatetarget);
1649 victim->targetyaw = -asin(0 - rotatetarget.x);
1650 victim->targetyaw *= 360 / 6.28;
1651 if (rotatetarget.z < 0) {
1652 victim->targetyaw = 180 - victim->targetyaw;
1655 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1657 victim->lastattack3 = victim->lastattack2;
1658 victim->lastattack2 = victim->lastattack;
1659 victim->lastattack = victim->animTarget;
1665 victim->velocity = 0;
1667 if (aitype != playercontrolled) {
1669 if (escapednum < 2) {
1670 int chances = ((difficulty == 2) ? 3 : ((difficulty == 1) ? 5 : 10));
1671 if ((Random() % chances) == 0) {
1677 if (victim->id == 0 && Animation::animations[victim->animTarget].attack == reversal) {
1685 void Person::DoDamage(float howmuch)
1689 damagetaken += howmuch / power;
1691 damagedealt += howmuch / power;
1695 if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo)) {
1700 if (!Tutorial::active) {
1701 damage += howmuch / power;
1702 permanentdamage += howmuch / 2 / power;
1703 superpermanentdamage += howmuch / 4 / power;
1706 if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2) {
1709 if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt) {
1714 camerashake += howmuch / 100;
1715 if ((howmuch > 50 && damage > damagetolerance / 2)) {
1716 blackout = damage / damagetolerance;
1724 if (aitype == passivetype && damage < damagetolerance && ((!Tutorial::active || cananger) && hostile)) {
1725 aitype = attacktypecutoff;
1727 if (!Tutorial::active && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
1728 if (abs(Random() % 2) == 0) {
1729 aitype = gethelptype;
1732 aitype = attacktypecutoff;
1737 if (howmuch > damagetolerance * 50 && skeleton.free != 2) {
1740 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1741 if (skeleton.free) {
1742 flatvelocity2 = skeleton.joints[i].velocity;
1743 flatfacing2 = skeleton.joints[i].position * scale + coords;
1745 flatvelocity2 = velocity;
1746 flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
1748 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1749 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1750 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1751 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1752 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1753 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1756 emit_sound_at(splattersound, coords);
1761 if (!dead && creature == wolftype) {
1762 award_bonus(0, Wolfbonus);
1769 if (!Tutorial::active || id == 0) {
1770 if (speechdelay <= 0 && !dead && aitype != playercontrolled) {
1771 int whichsound = -1;
1773 if (creature == wolftype) {
1774 int i = abs(Random() % 2);
1776 whichsound = snarlsound;
1779 whichsound = snarl2sound;
1782 if (creature == rabbittype) {
1783 int i = abs(Random() % 2);
1785 whichsound = rabbitpainsound;
1787 if (i == 1 && damage > damagetolerance) {
1788 whichsound = rabbitpain1sound;
1792 if (whichsound != -1) {
1793 emit_sound_at(whichsound, coords);
1794 addEnvSound(coords);
1802 * calculate/animate head facing direction?
1804 void Person::DoHead()
1806 static XYZ rotatearound;
1808 static float lookspeed = 500;
1810 if (!freeze && !winfreeze) {
1813 targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100;
1814 targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100;
1816 while (targetheadyaw > 180) {
1817 targetheadyaw -= 360;
1819 while (targetheadyaw < -180) {
1820 targetheadyaw += 360;
1823 if (targetheadyaw > 160) {
1824 targetheadpitch = targetheadpitch * -1;
1826 if (targetheadyaw < -160) {
1827 targetheadpitch = targetheadpitch * -1;
1829 if (targetheadyaw > 160) {
1830 targetheadyaw = targetheadyaw - 180;
1832 if (targetheadyaw < -160) {
1833 targetheadyaw = targetheadyaw + 180;
1836 if (targetheadpitch > 120) {
1837 targetheadpitch = 120;
1839 if (targetheadpitch < -120) {
1840 targetheadpitch = -120;
1842 if (targetheadyaw > 120) {
1843 targetheadyaw = 120;
1845 if (targetheadyaw < -120) {
1846 targetheadyaw = -120;
1850 targetheadpitch = 0;
1853 if (targetheadyaw > 80) {
1856 if (targetheadyaw < -80) {
1857 targetheadyaw = -80;
1859 if (targetheadpitch > 50) {
1860 targetheadpitch = 50;
1862 if (targetheadpitch < -50) {
1863 targetheadpitch = -50;
1867 if (abs(headyaw - targetheadyaw) < multiplier * lookspeed) {
1868 headyaw = targetheadyaw;
1869 } else if (headyaw > targetheadyaw) {
1870 headyaw -= multiplier * lookspeed;
1871 } else if (headyaw < targetheadyaw) {
1872 headyaw += multiplier * lookspeed;
1875 if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2) {
1876 headpitch = targetheadpitch;
1877 } else if (headpitch > targetheadpitch) {
1878 headpitch -= multiplier * lookspeed / 2;
1879 } else if (headpitch < targetheadpitch) {
1880 headpitch += multiplier * lookspeed / 2;
1883 rotatearound = jointPos(neck);
1884 jointPos(head) = rotatearound + DoRotation(jointPos(head) - rotatearound, headpitch, 0, 0);
1888 if (animTarget != bounceidleanim && animTarget != fightidleanim && animTarget != wolfidle && animTarget != knifefightidleanim && animTarget != drawrightanim && animTarget != drawleftanim && animTarget != walkanim) {
1889 facing = DoRotation(facing, headpitch * .4, 0, 0);
1890 facing = DoRotation(facing, 0, headyaw * .4, 0);
1893 if (animTarget == bounceidleanim || animTarget == fightidleanim || animTarget == wolfidle || animTarget == knifefightidleanim || animTarget == drawrightanim || animTarget == drawleftanim) {
1894 facing = DoRotation(facing, headpitch * .8, 0, 0);
1895 facing = DoRotation(facing, 0, headyaw * .8, 0);
1898 if (animTarget == walkanim) {
1899 facing = DoRotation(facing, headpitch * .6, 0, 0);
1900 facing = DoRotation(facing, 0, headyaw * .6, 0);
1903 skeleton.specialforward[0] = facing;
1904 //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1905 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
1906 if (skeleton.muscles[i].visible && (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)) {
1907 skeleton.FindRotationMuscle(i, animTarget);
1914 * ragdolls character?
1916 void Person::RagDoll(bool checkcollision)
1921 if (!skeleton.free) {
1925 if (id == 0 && isFlip()) {
1933 facing = DoRotation(facing, 0, yaw, 0);
1935 skeleton.freetime = 0;
1937 skeleton.longdead = 0;
1940 skeleton.broken = 0;
1941 skeleton.spinny = 1;
1943 skeleton.freefall = 1;
1945 if (!isnormal(velocity.x)) {
1948 if (!isnormal(velocity.y)) {
1951 if (!isnormal(velocity.z)) {
1954 if (!isnormal(yaw)) {
1957 if (!isnormal(coords.x)) {
1960 if (!isnormal(tilt)) {
1963 if (!isnormal(tilt2)) {
1967 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1968 skeleton.joints[i].delay = 0;
1969 skeleton.joints[i].locked = 0;
1970 skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1971 if (!isnormal(skeleton.joints[i].position.x)) {
1972 skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0);
1974 if (!isnormal(skeleton.joints[i].position.x)) {
1975 skeleton.joints[i].position = coords;
1977 skeleton.joints[i].position.y += .1;
1978 skeleton.joints[i].oldposition = skeleton.joints[i].position;
1979 skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords;
1982 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1983 skeleton.joints[i].velocity = 0;
1984 skeleton.joints[i].velchange = 0;
1986 skeleton.DoConstraints(&coords, &scale);
1987 if (Animation::animations[animCurrent].height == lowheight || Animation::animations[animTarget].height == lowheight) {
1988 skeleton.DoConstraints(&coords, &scale);
1989 skeleton.DoConstraints(&coords, &scale);
1990 skeleton.DoConstraints(&coords, &scale);
1991 skeleton.DoConstraints(&coords, &scale);
1994 speed = targetFrame().speed * 2;
1995 if (currentFrame().speed > targetFrame().speed) {
1996 speed = currentFrame().speed * 2;
1999 speed = transspeed * 2;
2004 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
2005 if ((Animation::animations[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && Animation::animations[animCurrent].height == Animation::animations[animTarget].height) {
2006 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);
2008 skeleton.joints[i].velocity = velocity / scale + facing * 5;
2010 change.x = (float)(Random() % 100) / 100;
2011 change.y = (float)(Random() % 100) / 100;
2012 change.z = (float)(Random() % 100) / 100;
2013 skeleton.joints[i].velocity += change;
2014 skeleton.joints[fabs(Random() % skeleton.joints.size())].velocity -= change;
2016 change.x = (float)(Random() % 100) / 100;
2017 change.y = (float)(Random() % 100) / 100;
2018 change.z = (float)(Random() % 100) / 100;
2019 skeleton.joints[i].velchange += change;
2020 skeleton.joints[fabs(Random() % skeleton.joints.size())].velchange -= change;
2023 if (checkcollision) {
2026 if (!skeleton.joints.empty()) {
2029 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
2030 average += skeleton.joints[j].position;
2032 average /= skeleton.joints.size();
2033 coords += average * scale;
2034 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
2035 skeleton.joints[j].position -= average;
2039 whichpatchx = coords.x / (terrain.size / subdivision * terrain.scale);
2040 whichpatchz = coords.z / (terrain.size / subdivision * terrain.scale);
2041 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
2042 i = terrain.patchobjects[whichpatchx][whichpatchz][l];
2045 if (SphereCheck(&lowpoint, 3, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
2046 coords.x = lowpoint.x;
2047 coords.z = lowpoint.z;
2056 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
2057 velocity += skeleton.joints[i].velocity * scale;
2059 velocity /= skeleton.joints.size();
2062 if (Random() % 2 == 0) {
2063 if (weaponactive != -1 && animTarget != rabbitkickanim && num_weapons > 0) {
2064 weapons[weaponids[0]].drop(jointVel(righthand) * scale * -.3, jointVel(righthand) * scale);
2065 weapons[weaponids[0]].velocity.x += .01;
2068 weaponids[0] = weaponids[num_weapons];
2069 if (weaponstuck == num_weapons) {
2074 for (unsigned i = 0; i < Person::players.size(); i++) {
2075 Person::players[i]->wentforweapon = 0;
2080 animTarget = bounceidleanim;
2081 animCurrent = bounceidleanim;
2089 void Person::FootLand(bodypart whichfoot, float opacity)
2091 if ((whichfoot != leftfoot) && (whichfoot != rightfoot)) {
2092 cerr << "FootLand called on wrong bodypart" << endl;
2095 static XYZ terrainlight;
2096 static XYZ footvel, footpoint;
2097 if (opacity >= 1 || skiddelay <= 0) {
2100 footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords;
2101 if (distsq(&footpoint, &viewer)) {
2102 Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity);
2104 } else if (onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
2105 footvel = velocity / 5;
2106 if (footvel.y < .8) {
2109 footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords;
2110 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
2111 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
2112 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) {
2113 if (environment == snowyenvironment) {
2114 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity);
2116 terrain.MakeDecal(footprintdecal, footpoint, .2, 1 * opacity, yaw);
2118 } else if (environment == grassyenvironment) {
2119 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity);
2120 } else if (environment == desertenvironment) {
2121 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity);
2123 terrain.MakeDecal(footprintdecal, footpoint, .2, .25 * opacity, yaw);
2127 } else if (isLanding() || (animTarget == jumpupanim) || isLandhard()) {
2128 footvel = velocity / 5;
2129 if (footvel.y < .8) {
2132 footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords;
2133 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) {
2134 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity);
2141 * make a puff effect at a body part (dust effect?)
2143 void Person::Puff(int whichlabel)
2145 static XYZ footvel, footpoint;
2148 footpoint = DoRotation(jointPos(whichlabel), 0, yaw, 0) * scale + coords;
2149 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .9, .3);
2153 * I think I added this in an attempt to clean up code
2155 void Person::setTargetAnimation(int animation)
2157 animTarget = animation;
2166 void Person::DoAnimations()
2168 if (!skeleton.free) {
2169 static float oldtarget;
2171 if (isIdle() && animCurrent != getIdle()) {
2172 normalsupdatedelay = 0;
2175 if (animTarget == tempanim || animCurrent == tempanim) {
2176 Animation::animations[tempanim] = tempanimation;
2178 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
2184 vel[0] = velocity.x;
2185 vel[1] = velocity.y;
2186 vel[2] = velocity.z;
2189 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc);
2190 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
2192 if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z)) {
2195 if (!crouchkeydown && velocity.y >= -15) {
2199 if ((animCurrent == jumpupanim || animTarget == jumpdownanim) /*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) {
2204 targfacing = DoRotation(targfacing, 0, targetyaw, 0);
2206 if (normaldotproduct(targfacing, velocity) >= -.3) {
2207 animTarget = flipanim;
2209 animTarget = backflipanim;
2211 crouchtogglekeydown = 1;
2220 if (Animation::animations[animTarget].attack != reversed) {
2223 if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) {
2224 crouchtogglekeydown = 0;
2225 if (aitype == playercontrolled) {
2229 if (!crouchtogglekeydown && Animation::animations[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain)) {
2233 crouchtogglekeydown = 1;
2237 if (Animation::animations[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) {
2239 normalsupdatedelay = 0;
2244 if (animTarget == rollanim && frameTarget == 3 && onfire) {
2246 emit_sound_at(fireendsound, coords);
2247 pause_sound(stream_firesound);
2251 if (animTarget == rabbittacklinganim && frameTarget == 1) {
2252 if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0) {
2255 if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) {
2256 if (normaldotproduct(victim->facing, facing) > 0) {
2257 victim->animTarget = rabbittackledbackanim;
2259 victim->animTarget = rabbittackledfrontanim;
2261 victim->frameTarget = 2;
2264 victim->targetyaw = yaw;
2265 if (victim->aitype == gethelptype) {
2266 victim->DoDamage(victim->damagetolerance - victim->damage);
2268 //victim->DoDamage(30);
2269 if (creature == wolftype) {
2271 emit_sound_at(clawslicesound, victim->coords);
2273 victim->DoBloodBig(1 / victim->armorhead, 210);
2275 award_bonus(id, TackleBonus,
2276 victim->aitype == gethelptype ? 50 : 0);
2280 if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (targetFrame().label || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) {
2281 if (weapons[weaponids[0]].getType() == knife) {
2282 if (weaponactive == -1) {
2284 } else if (weaponactive == 0) {
2288 if (weaponactive == -1) {
2289 emit_sound_at(knifesheathesound, coords);
2291 if (weaponactive != -1) {
2292 emit_sound_at(knifedrawsound, coords, 128);
2295 drawtogglekeydown = 1;
2298 if (!Tutorial::active || id == 0) {
2299 if ((targetFrame().label && (targetFrame().label < 5 || targetFrame().label == 8))) {
2300 int whichsound = -1;
2302 if (terrain.getOpacity(coords.x, coords.z) < .2) {
2303 if (targetFrame().label == 1) {
2304 whichsound = footstepsound;
2306 whichsound = footstepsound2;
2308 if (targetFrame().label == 1) {
2309 FootLand(leftfoot, 1);
2311 if (targetFrame().label == 2) {
2312 FootLand(rightfoot, 1);
2314 if (targetFrame().label == 3 && isRun()) {
2315 FootLand(rightfoot, 1);
2316 FootLand(leftfoot, 1);
2319 if (terrain.getOpacity(coords.x, coords.z) >= .2) {
2320 if (targetFrame().label == 1) {
2321 whichsound = footstepsound3;
2323 whichsound = footstepsound4;
2328 if (targetFrame().label == 1) {
2329 whichsound = footstepsound3;
2331 whichsound = footstepsound4;
2334 if (targetFrame().label == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
2335 if (Animation::animations[animTarget].attack != neutral) {
2336 unsigned r = abs(Random() % 3);
2338 whichsound = lowwhooshsound;
2341 whichsound = midwhooshsound;
2344 whichsound = highwhooshsound;
2347 if (Animation::animations[animTarget].attack == neutral) {
2348 whichsound = movewhooshsound;
2350 } else if (targetFrame().label == 4) {
2351 whichsound = knifeswishsound;
2353 if (targetFrame().label == 8 && !Tutorial::active) {
2354 whichsound = landsound2;
2357 if (whichsound != -1) {
2358 emit_sound_at(whichsound, coords, 256.);
2361 if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
2362 if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim) {
2363 addEnvSound(coords, 15);
2365 addEnvSound(coords, 6);
2370 if (targetFrame().label == 3) {
2372 emit_sound_at(whichsound, coords, 128.);
2379 if (!Tutorial::active || id == 0) {
2380 if (speechdelay <= 0) {
2381 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) {
2382 if ((targetFrame().label && (targetFrame().label < 5 || targetFrame().label == 8))) {
2383 int whichsound = -1;
2384 if (targetFrame().label == 4 && aitype != playercontrolled) {
2385 if (Animation::animations[animTarget].attack != neutral) {
2386 unsigned r = abs(Random() % 4);
2387 if (creature == rabbittype) {
2389 whichsound = rabbitattacksound;
2392 whichsound = rabbitattack2sound;
2395 whichsound = rabbitattack3sound;
2398 whichsound = rabbitattack4sound;
2401 if (creature == wolftype) {
2403 whichsound = barksound;
2406 whichsound = bark2sound;
2409 whichsound = bark3sound;
2412 whichsound = barkgrowlsound;
2419 if (whichsound != -1) {
2420 emit_sound_at(whichsound, coords);
2427 if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) {
2428 FootLand(leftfoot, 1);
2429 FootLand(rightfoot, 1);
2433 currentoffset = targetoffset;
2434 frameTarget = frameCurrent;
2435 animCurrent = animTarget;
2438 if (animTarget == removeknifeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2439 for (unsigned i = 0; i < weapons.size(); i++) {
2440 if (weapons[i].owner == -1) {
2441 if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
2442 if (distsq(&coords, &weapons[i].position) >= 1) {
2443 if (weapons[i].getType() != staff) {
2444 emit_sound_at(knifedrawsound, coords, 128.);
2454 if (animTarget == crouchremoveknifeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2455 for (unsigned i = 0; i < weapons.size(); i++) {
2456 bool willwork = true;
2457 if (weapons[i].owner != -1) {
2458 if (Person::players[weapons[i].owner]->weaponstuck != -1) {
2459 if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == int(i)) {
2460 if (Person::players[weapons[i].owner]->num_weapons > 1) {
2466 if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free)) {
2467 if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) {
2468 if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
2469 bool fleshstuck = false;
2470 if (weapons[i].owner != -1) {
2471 if (victim->weaponstuck != -1) {
2472 if (victim->weaponids[victim->weaponstuck] == int(i)) {
2478 emit_sound_at(fleshstabremovesound, coords, 128.);
2480 if (weapons[i].getType() != staff) {
2481 emit_sound_at(knifedrawsound, coords, 128.);
2484 if (weapons[i].owner != -1) {
2485 victim = Person::players[weapons[i].owner];
2486 if (victim->num_weapons == 1) {
2487 victim->num_weapons = 0;
2489 victim->num_weapons = 1;
2492 //victim->weaponactive=-1;
2493 victim->skeleton.longdead = 0;
2494 victim->skeleton.free = 1;
2495 victim->skeleton.broken = 0;
2497 for (unsigned j = 0; j < victim->skeleton.joints.size(); j++) {
2498 victim->skeleton.joints[j].velchange = 0;
2499 victim->skeleton.joints[j].locked = 0;
2505 Normalise(&relative);
2506 XYZ footvel, footpoint;
2508 footpoint = weapons[i].position;
2509 if (victim->weaponstuck != -1) {
2510 if (victim->weaponids[victim->weaponstuck] == int(i)) {
2512 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2514 weapons[i].bloody = 2;
2515 weapons[i].blooddrip = 5;
2516 victim->weaponstuck = -1;
2519 if (victim->num_weapons > 0) {
2520 if (victim->weaponstuck != 0 && victim->weaponstuck != -1) {
2521 victim->weaponstuck = 0;
2523 if (victim->weaponids[0] == int(i)) {
2524 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
2528 victim->jointVel(abdomen) += relative * 6;
2529 victim->jointVel(neck) += relative * 6;
2530 victim->jointVel(rightshoulder) += relative * 6;
2531 victim->jointVel(leftshoulder) += relative * 6;
2540 if (animCurrent == drawleftanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2541 if (weaponactive == -1) {
2543 } else if (weaponactive == 0) {
2545 if (num_weapons == 2) {
2547 buffer = weaponids[0];
2548 weaponids[0] = weaponids[1];
2549 weaponids[1] = buffer;
2552 if (weaponactive == -1) {
2553 emit_sound_at(knifesheathesound, coords, 128.);
2555 if (weaponactive != -1) {
2556 emit_sound_at(knifedrawsound, coords, 128.);
2560 if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) {
2561 XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0);
2562 Normalise(&rotatetarget);
2563 targetyaw = -asin(0 - rotatetarget.x);
2564 targetyaw *= 360 / 6.28;
2565 if (rotatetarget.z < 0) {
2566 targetyaw = 180 - targetyaw;
2569 if (animTarget == walljumprightkickanim) {
2572 if (animTarget == walljumpleftkickanim) {
2579 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0)) {
2583 if (distsq(&victim->coords, &/*Person::players[i]->*/ coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1) {
2591 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) {
2592 animTarget = rabbittackleanim;
2594 emit_sound_at(jumpsound, coords);
2602 targetloc = velocity;
2603 Normalise(&targetloc);
2604 targetloc += coords;
2605 for (unsigned i = 0; i < Person::players.size(); i++) {
2607 if (distsq(&targetloc, &Person::players[i]->coords) < closestdist || closestdist == 0) {
2608 closestdist = distsq(&targetloc, &Person::players[i]->coords);
2613 if (closestid != -1) {
2614 if (closestdist < 5 && !Person::players[closestid]->dead && Animation::animations[Person::players[closestid]->animTarget].height != lowheight && Person::players[closestid]->animTarget != backhandspringanim) {
2616 victim = Person::players[closestid];
2617 coords = victim->coords;
2618 animCurrent = rabbittacklinganim;
2619 animTarget = rabbittacklinganim;
2623 if (coords.z != victim->coords.z || coords.x != victim->coords.x) {
2624 rotatetarget = coords - victim->coords;
2625 Normalise(&rotatetarget);
2626 targetyaw = -asin(0 - rotatetarget.x);
2627 targetyaw *= 360 / 6.28;
2628 if (rotatetarget.z < 0) {
2629 targetyaw = 180 - targetyaw;
2632 if (animTarget != rabbitrunninganim) {
2633 emit_sound_at(jumpsound, coords, 128.);
2640 float damagemult = 1 * power;
2641 if (creature == wolftype) {
2642 damagemult = 2.5 * power;
2645 damagemult /= victim->damagetolerance / 200;
2647 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)) {
2648 if (animTarget == spinkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2649 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2654 if (Random() % 2 || creature == wolftype) {
2657 if (creature == wolftype) {
2661 if (!Tutorial::active) {
2662 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2664 if (creature == wolftype) {
2665 emit_sound_at(clawslicesound, victim->coords, 128.);
2667 victim->DoBloodBig(2 / victim->armorhead, 175);
2671 relative = victim->coords - coords;
2673 Normalise(&relative);
2674 relative = DoRotation(relative, 0, -90, 0);
2675 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2676 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2678 victim->jointVel(head) += relative * damagemult * 200;
2680 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2686 if (animTarget == wolfslapanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2687 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2692 if (Random() % 2 || creature == wolftype) {
2694 if (creature == wolftype) {
2698 emit_sound_at(whooshhitsound, victim->coords);
2699 if (creature == wolftype) {
2700 emit_sound_at(clawslicesound, victim->coords, 128.);
2702 victim->DoBloodBig(2, 175);
2706 relative = victim->coords - coords;
2708 Normalise(&relative);
2710 Normalise(&relative);
2711 relative = DoRotation(relative, 0, 90, 0);
2712 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2713 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2715 victim->jointVel(head) += relative * damagemult * 100;
2717 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2721 if (animTarget == walljumprightkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2722 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2729 if (!Tutorial::active) {
2730 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2732 if (creature == wolftype) {
2733 emit_sound_at(clawslicesound, victim->coords, 128.);
2735 victim->DoBloodBig(2 / victim->armorhead, 175);
2741 Normalise(&relative);
2742 relative = DoRotation(relative, 0, -90, 0);
2743 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2744 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2746 victim->jointVel(head) += relative * damagemult * 200;
2748 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2750 if (victim->damage > victim->damagetolerance) {
2751 award_bonus(id, style);
2758 if (animTarget == walljumpleftkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2759 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2766 if (!Tutorial::active) {
2767 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2769 if (creature == wolftype) {
2770 emit_sound_at(clawslicesound, victim->coords, 128.);
2772 victim->DoBloodBig(2 / victim->armorhead, 175);
2778 Normalise(&relative);
2779 relative = DoRotation(relative, 0, 90, 0);
2780 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2781 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2783 victim->jointVel(head) += relative * damagemult * 200;
2785 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2787 if (victim->damage > victim->damagetolerance) {
2788 award_bonus(id, style);
2795 if (animTarget == blockhighleftstrikeanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2796 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2805 emit_sound_at(whooshhitsound, victim->coords);
2808 relative = victim->coords - coords;
2810 Normalise(&relative);
2811 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2812 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
2814 victim->jointVel(head) += relative * damagemult * 100;
2816 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2820 if (animTarget == killanim && Animation::animations[animTarget].frames[frameCurrent].label == 8) {
2821 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) {
2826 emit_sound_at(whooshhitsound, victim->coords, 128.);
2828 victim->skeleton.longdead = 0;
2829 victim->skeleton.free = 1;
2830 victim->skeleton.broken = 0;
2831 victim->skeleton.spinny = 1;
2833 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2834 victim->skeleton.joints[i].velchange = 0;
2835 victim->skeleton.joints[i].delay = 0;
2836 victim->skeleton.joints[i].locked = 0;
2837 //victim->skeleton.joints[i].velocity=0;
2843 Normalise(&relative);
2844 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2845 victim->skeleton.joints[i].velocity.y = relative.y * 10;
2846 victim->skeleton.joints[i].position.y += relative.y * .3;
2847 victim->skeleton.joints[i].oldposition.y += relative.y * .3;
2848 victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
2850 victim->Puff(abdomen);
2851 victim->jointVel(abdomen).y = relative.y * 400;
2855 if (animTarget == killanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2856 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) {
2861 if (!Tutorial::active) {
2862 emit_sound_at(heavyimpactsound, coords, 128.);
2865 relative = victim->coords - coords;
2867 Normalise(&relative);
2868 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2869 victim->skeleton.joints[i].velocity += relative * damagemult * 90;
2871 victim->Puff(abdomen);
2872 if (victim->dead != 2 && victim->permanentdamage > victim->damagetolerance - 250 && autoslomo) {
2876 victim->DoDamage(damagemult * 500 / victim->protectionhigh);
2877 victim->jointVel(abdomen) += relative * damagemult * 300;
2881 if (animTarget == dropkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
2882 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) {
2887 if (!Tutorial::active) {
2888 emit_sound_at(thudsound, coords);
2891 victim->skeleton.longdead = 0;
2892 victim->skeleton.free = 1;
2893 victim->skeleton.broken = 0;
2894 victim->skeleton.spinny = 1;
2896 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2897 victim->skeleton.joints[i].velchange = 0;
2898 //victim->skeleton.joints[i].delay=0;
2899 victim->skeleton.joints[i].locked = 0;
2902 relative = victim->coords - coords;
2903 Normalise(&relative);
2905 Normalise(&relative);
2906 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2907 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2909 if (!victim->dead) {
2913 victim->Puff(abdomen);
2914 victim->DoDamage(damagemult * 20 / victim->protectionhigh);
2915 victim->jointVel(abdomen) += relative * damagemult * 200;
2917 if (!victim->dead) {
2923 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
2926 if (!victim->skeleton.free) {
2932 terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360);
2933 emit_sound_at(knifesheathesound, coords, 128.);
2936 if (victim && hasvictim) {
2937 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2939 XYZ where, startpoint, endpoint, movepoint, colpoint;
2940 float rotationpoint;
2942 if (weapons[weaponids[weaponactive]].getType() == knife) {
2943 where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4);
2944 where -= victim->coords;
2945 if (!victim->skeleton.free) {
2946 where = DoRotation(where, 0, -victim->yaw, 0);
2950 startpoint.y += 100;
2954 if (weapons[weaponids[weaponactive]].getType() == sword) {
2955 where = weapons[weaponids[weaponactive]].position;
2956 where -= victim->coords;
2957 if (!victim->skeleton.free) {
2958 where = DoRotation(where, 0, -victim->yaw, 0);
2961 where = weapons[weaponids[weaponactive]].tippoint;
2962 where -= victim->coords;
2963 if (!victim->skeleton.free) {
2964 where = DoRotation(where, 0, -victim->yaw, 0);
2968 if (weapons[weaponids[weaponactive]].getType() == staff) {
2969 where = weapons[weaponids[weaponactive]].position;
2970 where -= victim->coords;
2971 if (!victim->skeleton.free) {
2972 where = DoRotation(where, 0, -victim->yaw, 0);
2975 where = weapons[weaponids[weaponactive]].tippoint;
2976 where -= victim->coords;
2977 if (!victim->skeleton.free) {
2978 where = DoRotation(where, 0, -victim->yaw, 0);
2984 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
2986 if (whichtri != -1) {
2987 if (victim->dead != 2) {
2988 victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2));
2989 if (!victim->dead) {
2990 award_bonus(id, FinishedBonus);
2994 weapons[weaponids[weaponactive]].bloody = 2;
2997 victim->skeleton.longdead = 0;
2998 victim->skeleton.free = 1;
2999 victim->skeleton.broken = 0;
3001 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3002 victim->skeleton.joints[i].velchange = 0;
3003 victim->skeleton.joints[i].locked = 0;
3004 //victim->skeleton.joints[i].velocity=0;
3006 emit_sound_at(fleshstabsound, coords, 128);
3008 if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) {
3009 weapons[weaponids[weaponactive]].blooddrip += 5;
3010 weapons[weaponids[weaponactive]].blooddripdelay = 0;
3012 if (whichtri == -1) {
3014 emit_sound_at(knifesheathesound, coords, 128.);
3020 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && Animation::animations[animTarget].frames[frameCurrent].label == 6) {
3022 emit_sound_at(knifedrawsound, coords, 128);
3025 if (victim && hasvictim) {
3026 XYZ footvel, footpoint;
3028 emit_sound_at(fleshstabremovesound, coords, 128.);
3031 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
3033 if (weapons[weaponids[weaponactive]].getType() == sword) {
3034 XYZ where, startpoint, endpoint, movepoint;
3035 float rotationpoint;
3038 where = weapons[weaponids[weaponactive]].position;
3039 where -= victim->coords;
3040 if (!victim->skeleton.free) {
3041 where = DoRotation(where, 0, -victim->yaw, 0);
3044 where = weapons[weaponids[weaponactive]].tippoint;
3045 where -= victim->coords;
3046 if (!victim->skeleton.free) {
3047 where = DoRotation(where, 0, -victim->yaw, 0);
3053 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
3054 footpoint += victim->coords;
3056 if (whichtri == -1) {
3057 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
3060 if (weapons[weaponids[weaponactive]].getType() == staff) {
3061 XYZ where, startpoint, endpoint, movepoint;
3062 float rotationpoint;
3065 where = weapons[weaponids[weaponactive]].position;
3066 where -= victim->coords;
3067 if (!victim->skeleton.free) {
3068 where = DoRotation(where, 0, -victim->yaw, 0);
3071 where = weapons[weaponids[weaponactive]].tippoint;
3072 where -= victim->coords;
3073 if (!victim->skeleton.free) {
3074 where = DoRotation(where, 0, -victim->yaw, 0);
3080 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
3081 footpoint += victim->coords;
3083 if (whichtri == -1) {
3084 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
3087 hasvictim = victim->DoBloodBigWhere(2, 220, footpoint);
3089 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
3090 victim->skeleton.longdead = 0;
3091 victim->skeleton.free = 1;
3092 victim->skeleton.broken = 0;
3094 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3095 victim->skeleton.joints[i].velchange = 0;
3096 victim->skeleton.joints[i].locked = 0;
3097 //victim->skeleton.joints[i].velocity=0;
3103 Normalise(&relative);
3104 //victim->Puff(abdomen);
3106 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
3109 if (victim->bloodloss < victim->damagetolerance) {
3110 victim->bloodloss += 1000;
3114 victim->jointVel(abdomen) += relative * damagemult * 20;
3118 if (!hasvictim && onterrain) {
3119 weapons[weaponids[weaponactive]].bloody = 0;
3120 weapons[weaponids[weaponactive]].blooddrip = 0;
3124 if (animTarget == upunchanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3125 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
3134 if (!Tutorial::active) {
3135 emit_sound_at(heavyimpactsound, victim->coords, 128);
3140 relative = victim->coords - coords;
3142 Normalise(&relative);
3143 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3144 victim->skeleton.joints[i].velocity = relative * 30;
3146 victim->jointVel(head) += relative * damagemult * 150;
3148 victim->frameTarget = 0;
3149 victim->animTarget = staggerbackhardanim;
3150 victim->targetyaw = targetyaw + 180;
3152 victim->stunned = 1;
3155 victim->Puff(abdomen);
3156 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
3162 if (animTarget == winduppunchanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3163 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) {
3168 if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && Animation::animations[victim->animTarget].height != lowheight) {
3169 if (!Tutorial::active) {
3170 emit_sound_at(thudsound, victim->coords);
3172 } else if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && Animation::animations[victim->animTarget].height == lowheight) {
3173 if (!Tutorial::active) {
3174 emit_sound_at(whooshhitsound, victim->coords);
3177 if (!Tutorial::active) {
3178 emit_sound_at(heavyimpactsound, victim->coords);
3182 if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || Animation::animations[victim->animTarget].height == lowheight) {
3186 relative = victim->coords - coords;
3188 Normalise(&relative);
3190 Normalise(&relative);
3191 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3192 victim->skeleton.joints[i].velocity = relative * 5;
3194 victim->jointVel(abdomen) += relative * damagemult * 400;
3196 victim->frameTarget = 0;
3197 victim->animTarget = staggerbackhardanim;
3198 victim->targetyaw = targetyaw + 180;
3200 victim->stunned = 1;
3202 victim->Puff(abdomen);
3203 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
3209 if (animTarget == blockhighleftanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3210 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
3211 if (victim->id == 0) {
3214 emit_sound_at(landsound2, victim->coords);
3220 if (animTarget == swordslashparryanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3221 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
3222 if (victim->id == 0) {
3226 if (weaponactive != -1) {
3227 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
3228 if (weapons[victim->weaponids[0]].getType() == staff) {
3229 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3231 if (weapons[weaponids[0]].getType() == staff) {
3232 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3235 emit_sound_at(swordstaffsound, victim->coords);
3237 emit_sound_at(metalhitsound, victim->coords);
3245 if (animTarget == knifethrowanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3246 if (weaponactive != -1) {
3249 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);
3251 weapons[weaponids[0]].thrown(aim * 50);
3254 weaponids[0] = weaponids[num_weapons];
3260 if (animTarget == knifeslashstartanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3262 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 && /*Animation::animations[victim->animTarget].height!=lowheight&&*/ victim->animTarget != dodgebackanim && victim->animTarget != rollanim) {
3264 if (!Tutorial::active) {
3265 victim->DoBloodBig(1.5 / victim->armorhigh, 225);
3268 award_bonus(id, Slicebonus);
3269 if (!Tutorial::active) {
3270 emit_sound_at(knifeslicesound, victim->coords);
3272 //victim->jointVel(abdomen)+=relative*damagemult*200;
3273 if (Animation::animations[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
3274 if (victim->id != 0 || difficulty == 2) {
3275 victim->frameTarget = 0;
3276 victim->animTarget = staggerbackhardanim;
3277 victim->targetyaw = targetyaw + 180;
3281 victim->lowreversaldelay = 0;
3282 victim->highreversaldelay = 0;
3283 if (aitype != playercontrolled) {
3284 weaponmissdelay = .6;
3287 if (!Tutorial::active) {
3288 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3289 weapons[weaponids[weaponactive]].bloody = 1;
3291 weapons[weaponids[weaponactive]].blooddrip += 3;
3294 XYZ footvel, footpoint;
3296 if (skeleton.free) {
3297 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
3299 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
3301 if (Tutorial::active) {
3302 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .6, .3);
3305 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .6, .3);
3307 footvel = DoRotation(facing, 0, 90, 0) * .8;
3308 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3309 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3310 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3311 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3313 victim->DoDamage(damagemult * 0);
3317 if (animTarget == swordslashanim && Animation::animations[animTarget].frames[frameCurrent].label == 5 && victim->animTarget != rollanim) {
3318 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) {
3319 if (victim->weaponactive == -1 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) {
3320 award_bonus(id, Slashbonus);
3322 if (!Tutorial::active) {
3323 if (normaldotproduct(victim->facing, victim->coords - coords) < 0) {
3324 victim->DoBloodBig(2 / victim->armorhigh, 190);
3326 victim->DoBloodBig(2 / victim->armorhigh, 185);
3328 victim->deathbleeding = 1;
3329 emit_sound_at(swordslicesound, victim->coords);
3330 victim->frameTarget = 0;
3331 victim->animTarget = staggerbackhardanim;
3332 victim->targetyaw = targetyaw + 180;
3334 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3335 weapons[weaponids[weaponactive]].bloody = 1;
3337 weapons[weaponids[weaponactive]].blooddrip += 3;
3339 float bloodlossamount;
3340 bloodlossamount = 200 + abs((float)(Random() % 40)) - 20;
3341 victim->bloodloss += bloodlossamount / victim->armorhigh;
3342 victim->DoDamage(damagemult * 0);
3344 XYZ footvel, footpoint;
3346 if (skeleton.free) {
3347 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
3349 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
3352 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3354 footvel = DoRotation(facing, 0, 90, 0) * .8;
3356 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3357 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3358 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3359 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3362 if (victim->weaponactive != -1) {
3363 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
3364 if (weapons[victim->weaponids[0]].getType() == staff) {
3365 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3367 if (weapons[weaponids[0]].getType() == staff) {
3368 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3371 emit_sound_at(swordstaffsound, victim->coords);
3373 emit_sound_at(metalhitsound, victim->coords);
3378 victim->Puff(righthand);
3380 victim->frameTarget = 0;
3381 victim->animTarget = staggerbackhighanim;
3382 victim->targetyaw = targetyaw + 180;
3384 aim = DoRotation(facing, 0, 90, 0) * 21;
3386 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
3387 victim->num_weapons--;
3388 if (victim->num_weapons) {
3389 victim->weaponids[0] = victim->weaponids[num_weapons];
3390 if (victim->weaponstuck == victim->num_weapons) {
3391 victim->weaponstuck = 0;
3394 victim->weaponactive = -1;
3395 for (unsigned i = 0; i < Person::players.size(); i++) {
3396 Person::players[i]->wentforweapon = 0;
3402 if (animTarget == staffhitanim && Animation::animations[animTarget].frames[frameCurrent].label == 5 && victim->animTarget != rollanim) {
3403 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
3404 if (!Tutorial::active) {
3405 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 250;
3410 if (Random() % 2 || creature == wolftype) {
3413 emit_sound_at(staffheadsound, victim->coords);
3417 relative = victim->coords - coords;
3419 Normalise(&relative);
3420 relative = DoRotation(relative, 0, 90, 0);
3422 Normalise(&relative);
3423 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3424 victim->skeleton.joints[i].velocity += relative * damagemult * 60;
3426 victim->jointVel(head) += relative * damagemult * 230;
3427 victim->jointVel(neck) += relative * damagemult * 230;
3429 if (!Tutorial::active) {
3430 victim->DoDamage(damagemult * 120 / victim->protectionhigh);
3432 award_bonus(id, solidhit, 30);
3437 if (animTarget == staffspinhitanim && Animation::animations[animTarget].frames[frameCurrent].label == 5 && victim->animTarget != rollanim) {
3438 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
3439 if (!Tutorial::active) {
3440 weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250;
3445 if (Random() % 2 || creature == wolftype) {
3448 emit_sound_at(staffheadsound, victim->coords);
3452 relative = victim->coords - coords;
3454 Normalise(&relative);
3455 relative = DoRotation(relative, 0, -90, 0);
3456 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3457 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3459 victim->jointVel(head) += relative * damagemult * 220;
3460 victim->jointVel(neck) += relative * damagemult * 220;
3462 if (!Tutorial::active) {
3463 victim->DoDamage(damagemult * 350 / victim->protectionhead);
3465 award_bonus(id, solidhit, 60);
3470 if (animTarget == staffgroundsmashanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3471 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) {
3473 if (!Tutorial::active) {
3474 if (!victim->dead) {
3475 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500;
3480 if (Random() % 2 || creature == wolftype) {
3483 emit_sound_at(staffbodysound, victim->coords);
3485 victim->skeleton.longdead = 0;
3486 victim->skeleton.free = 1;
3487 victim->skeleton.broken = 0;
3489 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3490 victim->skeleton.joints[i].velchange = 0;
3491 victim->skeleton.joints[i].locked = 0;
3492 //victim->skeleton.joints[i].velocity=0;
3499 Normalise(&relative);
3500 if (!victim->dead) {
3501 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3502 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
3504 victim->jointVel(abdomen) += relative * damagemult * 40;
3507 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3508 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
3511 victim->Puff(abdomen);
3512 if (!Tutorial::active) {
3513 victim->DoDamage(damagemult * 100 / victim->protectionhigh);
3515 if (!victim->dead) {
3516 award_bonus(id, solidhit, 40);
3522 if (animTarget == lowkickanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3523 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != highheight) {
3529 relative = victim->coords - coords;
3531 Normalise(&relative);
3535 if (Animation::animations[victim->animTarget].height == lowheight) {
3541 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3542 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3544 victim->jointVel(head) += relative * damagemult * 200;
3545 if (!Tutorial::active) {
3546 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3549 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3550 if (victim->howactive == typesleeping) {
3551 victim->DoDamage(damagemult * 150 / victim->protectionhead);
3553 if (creature == wolftype) {
3554 emit_sound_at(clawslicesound, victim->coords, 128.);
3556 victim->DoBloodBig(2 / victim->armorhead, 175);
3559 if (victim->damage >= victim->damagetolerance) {
3562 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3563 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3565 victim->jointVel(abdomen) += relative * damagemult * 200;
3566 victim->frameTarget = 0;
3567 victim->animTarget = staggerbackhighanim;
3568 victim->targetyaw = targetyaw + 180;
3570 if (!Tutorial::active) {
3571 emit_sound_at(landsound2, victim->coords, 128.);
3573 victim->Puff(abdomen);
3574 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3575 if (creature == wolftype) {
3576 emit_sound_at(clawslicesound, victim->coords, 128.);
3578 victim->DoBloodBig(2 / victim->armorhigh, 170);
3584 if (animTarget == sweepanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3585 if ((victim->animTarget != jumpupanim) &&
3586 (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) &&
3587 (victim != this->shared_from_this())) {
3592 if (!Tutorial::active) {
3593 emit_sound_at(landsound2, victim->coords, 128.);
3596 relative = victim->coords - coords;
3598 Normalise(&relative);
3600 if (Animation::animations[victim->animTarget].height == middleheight || Animation::animations[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
3603 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3604 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
3606 relative = DoRotation(relative, 0, -90, 0);
3608 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3609 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) {
3610 victim->skeleton.joints[i].velocity = relative * 80;
3613 victim->Puff(rightankle);
3614 victim->Puff(leftankle);
3615 victim->DoDamage(damagemult * 40 / victim->protectionlow);
3617 if (victim->damage >= victim->damagetolerance) {
3620 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3621 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3623 relative = DoRotation(relative, 0, -90, 0);
3624 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3625 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) {
3626 victim->skeleton.joints[i].velocity += relative * damagemult * 80;
3629 victim->jointVel(abdomen) += relative * damagemult * 200;
3630 victim->frameTarget = 0;
3631 victim->animTarget = staggerbackhighanim;
3632 victim->targetyaw = targetyaw + 180;
3634 if (!Tutorial::active) {
3635 emit_sound_at(landsound2, victim->coords, 128.);
3637 victim->Puff(abdomen);
3638 victim->DoDamage(damagemult * 30 / victim->protectionlow);
3645 if (Animation::animations[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) {
3646 if (animTarget == spinkickreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3655 if (!Tutorial::active) {
3656 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3658 if (creature == wolftype) {
3659 emit_sound_at(clawslicesound, victim->coords, 128);
3661 victim->DoBloodBig(2 / victim->armorhigh, 170);
3665 relative = victim->coords - oldcoords;
3667 Normalise(&relative);
3668 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3669 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3671 victim->jointVel(abdomen) += relative * damagemult * 200;
3672 victim->Puff(abdomen);
3673 victim->DoDamage(damagemult * 150 / victim->protectionhigh);
3675 award_bonus(id, Reversal);
3678 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3679 if (victim->weaponactive != -1 && victim->num_weapons > 0) {
3680 if (weapons[victim->weaponids[victim->weaponactive]].owner == int(victim->id)) {
3681 takeWeapon(victim->weaponids[victim->weaponactive]);
3682 victim->num_weapons--;
3683 if (victim->num_weapons > 0) {
3684 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
3686 victim->weaponactive = -1;
3691 if (animTarget == staffhitreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3700 emit_sound_at(whooshhitsound, victim->coords, 128.);
3703 relative = victim->coords - oldcoords;
3705 Normalise(&relative);
3706 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3707 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3709 victim->jointVel(abdomen) += relative * damagemult * 200;
3711 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3714 if (animTarget == staffspinhitreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3724 award_bonus(id, staffreversebonus);
3726 if (!Tutorial::active) {
3727 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3730 award_bonus(id, staffreversebonus); // Huh, again?
3733 relative = victim->coords - oldcoords;
3735 Normalise(&relative);
3736 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3737 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3739 victim->jointVel(abdomen) += relative * damagemult * 200;
3741 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3744 if (animTarget == upunchreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3750 Normalise(&relative);
3752 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3753 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3755 victim->jointVel(lefthand) *= .1;
3756 victim->jointVel(leftwrist) *= .2;
3757 victim->jointVel(leftelbow) *= .5;
3758 victim->jointVel(leftshoulder) *= .7;
3759 victim->jointVel(righthand) *= .1;
3760 victim->jointVel(rightwrist) *= .2;
3761 victim->jointVel(rightelbow) *= .5;
3762 victim->jointVel(rightshoulder) *= .7;
3764 victim->Puff(abdomen);
3765 victim->DoDamage(damagemult * 90 / victim->protectionhigh);
3767 award_bonus(id, Reversal);
3771 if (weaponactive != -1 || creature == wolftype) {
3774 if (creature == rabbittype && weaponactive != -1) {
3775 if (weapons[weaponids[0]].getType() == staff) {
3780 if (weaponactive != -1) {
3781 victim->DoBloodBig(2 / victim->armorhigh, 225);
3782 emit_sound_at(knifeslicesound, victim->coords);
3783 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3784 weapons[weaponids[weaponactive]].bloody = 1;
3786 weapons[weaponids[weaponactive]].blooddrip += 3;
3788 if (weaponactive == -1 && creature == wolftype) {
3789 emit_sound_at(clawslicesound, victim->coords, 128.);
3791 victim->DoBloodBig(2 / victim->armorhigh, 175);
3796 if (animTarget == swordslashreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3802 Normalise(&relative);
3804 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3805 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3807 victim->jointVel(lefthand) *= .1 - 1;
3808 victim->jointVel(leftwrist) *= .2 - 1;
3809 victim->jointVel(leftelbow) *= .5 - 1;
3810 victim->jointVel(leftshoulder) *= .7 - 1;
3811 victim->jointVel(righthand) *= .1 - 1;
3812 victim->jointVel(rightwrist) *= .2 - 1;
3813 victim->jointVel(rightelbow) *= .5 - 1;
3814 victim->jointVel(rightshoulder) *= .7 - 1;
3816 award_bonus(id, swordreversebonus);
3819 if (hasvictim && animTarget == knifeslashreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3828 if (!Tutorial::active) {
3829 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3833 relative = victim->coords - oldcoords;
3835 Normalise(&relative);
3836 relative = DoRotation(relative, 0, -90, 0);
3837 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3838 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3840 victim->jointVel(abdomen) += relative * damagemult * 200;
3841 victim->Puff(abdomen);
3842 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3844 award_bonus(id, Reversal);
3847 if (hasvictim && animTarget == sneakattackanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
3850 victim->skeleton.spinny = 0;
3852 relative = facing * -1;
3854 Normalise(&relative);
3855 if (victim->id == 0) {
3858 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3859 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3861 victim->damage = victim->damagetolerance;
3862 victim->permanentdamage = victim->damagetolerance - 1;
3865 if (weaponactive != -1 || creature == wolftype) {
3868 if (creature == rabbittype && weaponactive != -1) {
3869 if (weapons[weaponids[0]].getType() == staff) {
3874 if (weaponactive != -1) {
3875 victim->DoBloodBig(200, 225);
3876 emit_sound_at(knifeslicesound, victim->coords);
3878 weapons[weaponids[weaponactive]].bloody = 2;
3880 weapons[weaponids[weaponactive]].blooddrip += 5;
3883 if (creature == wolftype && weaponactive == -1) {
3884 emit_sound_at(clawslicesound, victim->coords, 128.);
3886 victim->DoBloodBig(2, 175);
3889 award_bonus(id, spinecrusher);
3892 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3893 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3895 if (animTarget == knifefollowanim) {
3896 victim->DoBloodBig(200, 210);
3898 if (animTarget == knifesneakattackanim) {
3899 XYZ footvel, footpoint;
3901 footpoint = weapons[weaponids[0]].tippoint;
3903 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3905 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3906 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3907 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3908 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3909 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3910 victim->DoBloodBig(200, 195);
3911 award_bonus(id, tracheotomy);
3913 if (animTarget == knifefollowanim) {
3914 award_bonus(id, Stabbonus);
3915 XYZ footvel, footpoint;
3917 footpoint = weapons[weaponids[0]].tippoint;
3919 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3921 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3922 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3923 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3924 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3925 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3927 victim->bloodloss += 10000;
3928 victim->velocity = 0;
3929 emit_sound_at(fleshstabsound, victim->coords);
3931 weapons[weaponids[weaponactive]].bloody = 2;
3933 weapons[weaponids[weaponactive]].blooddrip += 5;
3937 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && Animation::animations[animTarget].frames[frameCurrent].label == 6) {
3939 victim->velocity = 0;
3940 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3941 victim->skeleton.joints[i].velocity = 0;
3943 if (animTarget == knifefollowanim) {
3945 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3946 victim->skeleton.joints[i].velocity = 0;
3949 if (weaponactive != -1 && Animation::animations[victim->animTarget].attack != reversal) {
3950 emit_sound_at(fleshstabremovesound, victim->coords);
3952 weapons[weaponids[weaponactive]].bloody = 2;
3954 weapons[weaponids[weaponactive]].blooddrip += 5;
3956 XYZ footvel, footpoint;
3958 footpoint = weapons[weaponids[0]].tippoint;
3960 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3962 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3963 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3964 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3965 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3966 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3970 if (hasvictim && (animTarget == swordsneakattackanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3971 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3972 award_bonus(id, backstab);
3976 XYZ footvel, footpoint;
3978 footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2;
3980 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3982 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3983 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3984 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3985 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 5, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3986 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3987 victim->DoBloodBig(200, 180);
3988 victim->DoBloodBig(200, 215);
3989 victim->bloodloss += 10000;
3990 victim->velocity = 0;
3991 emit_sound_at(fleshstabsound, victim->coords);
3993 weapons[weaponids[weaponactive]].bloody = 2;
3995 weapons[weaponids[weaponactive]].blooddrip += 5;
3999 if (hasvictim && animTarget == swordsneakattackanim && Animation::animations[animTarget].frames[frameCurrent].label == 6) {
4001 victim->velocity = 0;
4002 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
4003 victim->skeleton.joints[i].velocity = 0;
4005 if (weaponactive != -1) {
4006 emit_sound_at(fleshstabremovesound, victim->coords);
4008 weapons[weaponids[weaponactive]].bloody = 2;
4010 weapons[weaponids[weaponactive]].blooddrip += 5;
4012 XYZ footvel, footpoint;
4014 footpoint = weapons[weaponids[0]].tippoint;
4016 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
4018 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
4019 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
4020 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
4021 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
4022 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
4026 if (animTarget == sweepreversalanim && Animation::animations[animTarget].frames[frameCurrent].label == 7) {
4035 if (weaponactive == -1) {
4036 if (!Tutorial::active) {
4037 emit_sound_at(heavyimpactsound, victim->coords, 128.);
4042 if (weaponactive != -1 || creature == wolftype) {
4045 if (creature == rabbittype && weaponactive != -1) {
4046 if (weapons[weaponids[0]].getType() == staff) {
4051 if (weaponactive != -1) {
4052 victim->DoBloodBig(2 / victim->armorhead, 225);
4053 emit_sound_at(knifeslicesound, victim->coords);
4054 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
4055 weapons[weaponids[weaponactive]].bloody = 1;
4057 weapons[weaponids[weaponactive]].blooddrip += 3;
4059 if (weaponactive == -1 && creature == wolftype) {
4060 emit_sound_at(clawslicesound, victim->coords, 128.);
4062 victim->DoBloodBig(2 / victim->armorhead, 175);
4066 award_bonus(id, Reversal);
4071 relative = facing * -1;
4073 Normalise(&relative);
4074 relative = DoRotation(relative, 0, 90, 0);
4076 Normalise(&relative);
4077 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
4078 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
4080 victim->jointVel(head) += relative * damagemult * 200;
4081 if (victim->damage < victim->damagetolerance - 100) {
4082 victim->velocity = relative * 200;
4084 victim->DoDamage(damagemult * 100 / victim->protectionhead);
4085 victim->velocity = 0;
4088 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))) {
4092 relative = facing * -1;
4094 Normalise(&relative);
4095 relative = DoRotation(relative, 0, 90, 0);
4097 Normalise(&relative);
4098 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
4099 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
4101 victim->jointVel(head) += relative * damagemult * 200;
4104 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim)) {
4105 if (victim->damage > victim->damagetolerance && bonus != reverseko) {
4106 award_bonus(id, reverseko);
4112 if (frameTarget > int(Animation::animations[animCurrent].frames.size()) - 1) {
4115 animTarget = getIdle();
4116 FootLand(leftfoot, 1);
4117 FootLand(rightfoot, 1);
4119 if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) {
4120 animTarget = rollanim;
4122 emit_sound_at(movewhooshsound, coords, 128.);
4124 if (animCurrent == staggerbackhighanim) {
4125 animTarget = getIdle();
4127 if (animCurrent == staggerbackhardanim) {
4128 animTarget = getIdle();
4130 if (animCurrent == removeknifeanim) {
4131 animTarget = getIdle();
4133 if (animCurrent == crouchremoveknifeanim) {
4134 animTarget = getCrouch();
4136 if (animCurrent == backhandspringanim) {
4137 animTarget = getIdle();
4139 if (animCurrent == dodgebackanim) {
4140 animTarget = getIdle();
4142 if (animCurrent == drawleftanim) {
4143 animTarget = getIdle();
4145 if (animCurrent == drawrightanim || animCurrent == crouchdrawrightanim) {
4146 animTarget = getIdle();
4147 if (animCurrent == crouchdrawrightanim) {
4148 animTarget = getCrouch();
4150 if (weaponactive == -1) {
4152 } else if (weaponactive == 0) {
4154 if (num_weapons == 2) {
4156 buffer = weaponids[0];
4157 weaponids[0] = weaponids[1];
4158 weaponids[1] = buffer;
4162 if (weaponactive == -1) {
4163 emit_sound_at(knifesheathesound, coords, 128.);
4165 if (weaponactive != -1) {
4166 emit_sound_at(knifedrawsound, coords, 128.);
4169 if (animCurrent == rollanim) {
4170 animTarget = getCrouch();
4171 FootLand(leftfoot, 1);
4172 FootLand(rightfoot, 1);
4175 if (animTarget == walljumprightkickanim) {
4178 if (animTarget == walljumpleftkickanim) {
4181 animTarget = jumpdownanim;
4183 if (animCurrent == climbanim) {
4184 animTarget = getCrouch();
4186 coords += facing * .1;
4187 if (!isnormal(coords.x)) {
4198 if (animTarget == rabbitkickreversalanim) {
4199 animTarget = getCrouch();
4202 if (animTarget == jumpreversalanim) {
4203 animTarget = getCrouch();
4206 if (animTarget == walljumprightanim || animTarget == walljumpbackanim || animTarget == walljumpfrontanim) {
4207 if (attackkeydown && animTarget != walljumpfrontanim) {
4209 float closestdist = -1;
4211 if (Person::players.size() > 1) {
4212 for (unsigned i = 0; i < Person::players.size(); i++) {
4213 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
4214 distance = distsq(&Person::players[i]->coords, &coords);
4215 if (closestdist == -1 || distance < closestdist) {
4216 closestdist = distance;
4222 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
4223 victim = Person::players[closest];
4224 animTarget = walljumprightkickanim;
4226 XYZ rotatetarget = victim->coords - coords;
4227 Normalise(&rotatetarget);
4228 yaw = -asin(0 - rotatetarget.x);
4230 if (rotatetarget.z < 0) {
4233 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
4234 velocity = (victim->coords - coords) * 4;
4239 if (animTarget == walljumpbackanim) {
4240 animTarget = backflipanim;
4242 velocity = facing * -8;
4245 resume_stream(whooshsound);
4248 if (animTarget == walljumprightanim) {
4249 animTarget = rightflipanim;
4253 velocity = DoRotation(facing, 0, 30, 0) * -8;
4256 if (animTarget == walljumpfrontanim) {
4257 animTarget = frontflipanim;
4261 velocity = facing * 8;
4265 resume_stream(whooshsound);
4268 if (animTarget == walljumpleftanim) {
4269 if (attackkeydown) {
4271 float closestdist = -1;
4273 if (Person::players.size() > 1) {
4274 for (unsigned i = 0; i < Person::players.size(); i++) {
4275 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
4276 distance = distsq(&Person::players[i]->coords, &coords);
4277 if (closestdist == -1 || distance < closestdist) {
4278 closestdist = distance;
4284 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
4285 victim = Person::players[closest];
4286 animTarget = walljumpleftkickanim;
4288 XYZ rotatetarget = victim->coords - coords;
4289 Normalise(&rotatetarget);
4290 yaw = -asin(0 - rotatetarget.x);
4292 if (rotatetarget.z < 0) {
4295 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
4296 velocity = (victim->coords - coords) * 4;
4301 if (animTarget != walljumpleftkickanim) {
4302 animTarget = leftflipanim;
4306 velocity = DoRotation(facing, 0, -30, 0) * -8;
4310 resume_stream(whooshsound);
4313 if (animTarget == sneakattackanim) {
4314 animCurrent = getCrouch();
4315 animTarget = getCrouch();
4322 transspeed = 1000000;
4323 targetheadyaw += 180;
4324 coords -= facing * .7;
4326 coords.y = terrain.getHeight(coords.x, coords.z);
4331 if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) {
4332 animTarget = getIdle();
4335 coords.y = terrain.getHeight(coords.x, coords.z);
4340 if (animCurrent == knifefollowanim) {
4341 animTarget = getIdle();
4344 if (Animation::animations[animTarget].attack == reversal && animCurrent != sneakattackanim && animCurrent != knifesneakattackanim && animCurrent != swordsneakattackanim && animCurrent != knifefollowanim) {
4345 float ycoords = oldcoords.y;
4346 animTarget = getStop();
4351 transspeed = 1000000;
4352 targetheadyaw += 180;
4353 if (!isnormal(coords.x)) {
4356 if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim) {
4357 oldcoords = coords + facing * .5;
4358 } else if (animCurrent == sweepreversalanim) {
4359 oldcoords = coords + facing * 1.1;
4360 } else if (animCurrent == upunchreversalanim) {
4361 oldcoords = coords + facing * 1.5;
4364 targetheadyaw += 180;
4367 } else if (animCurrent == knifeslashreversalanim) {
4368 oldcoords = coords + facing * .5;
4371 targetheadyaw += 90;
4374 } else if (animCurrent == staffspinhitreversalanim) {
4377 targetheadyaw += 180;
4382 oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z);
4384 oldcoords.y = ycoords;
4386 currentoffset = coords - oldcoords;
4392 if (animCurrent == knifesneakattackedanim || animCurrent == swordsneakattackedanim) {
4397 if (Animation::animations[animTarget].attack == reversed) {
4399 if (animTarget == sweepreversedanim) {
4402 animTarget = backhandspringanim;
4404 emit_sound_at(landsound, coords, 128);
4406 if (animCurrent == upunchreversedanim || animCurrent == swordslashreversedanim) {
4407 animTarget = rollanim;
4410 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
4411 coords.y = oldcoords.y;
4413 if (animCurrent == knifeslashreversedanim) {
4414 animTarget = rollanim;
4419 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
4420 coords.y = oldcoords.y;
4424 animTarget = jumpdownanim;
4427 animTarget = getIdle();
4429 if (wasLandhard()) {
4430 animTarget = getIdle();
4432 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
4433 animTarget = getIdle();
4435 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
4436 coords.y = oldcoords.y;
4437 //coords+=DoRotation(Animation::animations[animCurrent].offset,0,yaw,0)*scale;
4438 targetoffset.y = coords.y;
4440 targetoffset.y = terrain.getHeight(coords.x, coords.z);
4442 currentoffset = DoRotation(Animation::animations[animCurrent].offset * -1, 0, yaw, 0) * scale;
4443 currentoffset.y -= (coords.y - targetoffset.y);
4444 coords.y = targetoffset.y;
4446 normalsupdatedelay = 0;
4448 if (animCurrent == upunchanim) {
4449 animTarget = getStop();
4450 normalsupdatedelay = 0;
4453 if (animCurrent == rabbitkickanim && animTarget != backflipanim) {
4457 if (num_weapons > 0) {
4458 if (weapons[0].getType() == staff) {
4467 rabbitkickragdoll = 1;
4469 if (animCurrent == rabbitkickreversedanim) {
4475 skeleton.spinny = 0;
4476 SolidHitBonus(!id); // FIXME: tricky id
4480 animTarget = rollanim;
4483 pause_sound(whooshsound);
4488 if (animCurrent == rabbittackledbackanim || animCurrent == rabbittackledfrontanim) {
4492 skeleton.spinny = 0;
4494 if (animCurrent == jumpreversedanim) {
4500 skeleton.spinny = 0;
4501 SolidHitBonus(!id); // FIXME: tricky id
4505 animTarget = rollanim;
4506 coords += facing * 2;
4508 pause_sound(whooshsound);
4514 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) {
4515 animTarget = getupfromfrontanim;
4517 } else if (Animation::animations[animCurrent].attack == normalattack) {
4518 animTarget = getIdle();
4521 if (animCurrent == blockhighleftanim && aitype != playercontrolled) {
4522 animTarget = blockhighleftstrikeanim;
4524 if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) {
4525 animTarget = getIdle();
4528 if (animCurrent == spinkickanim && victim->skeleton.free) {
4529 if (creature == rabbittype) {
4530 animTarget = fightidleanim;
4536 if (isIdle() && !wasIdle()) {
4537 normalsupdatedelay = 0;
4540 if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) {
4541 animTarget = jumpdownanim;
4544 if (!skeleton.free) {
4546 if (!transspeed && Animation::animations[animTarget].attack != 2 && Animation::animations[animTarget].attack != 3) {
4547 if (!isRun() || !wasRun()) {
4548 if (targetFrame().speed > currentFrame().speed) {
4549 target += multiplier * targetFrame().speed * speed * 2;
4551 if (targetFrame().speed <= currentFrame().speed) {
4552 target += multiplier * currentFrame().speed * speed * 2;
4555 if (isRun() && wasRun()) {
4557 tempspeed = velspeed;
4558 if (tempspeed < 10 * speedmult) {
4559 tempspeed = 10 * speedmult;
4561 /* FIXME - mixed of target and current here, is that intended? */
4562 target += multiplier * Animation::animations[animTarget].frames[frameCurrent].speed * speed * 1.7 * tempspeed / (speed * 45 * scale);
4564 } else if (transspeed) {
4565 target += multiplier * transspeed * speed * 2;
4567 if (!isRun() || !wasRun()) {
4568 if (targetFrame().speed > currentFrame().speed) {
4569 target += multiplier * targetFrame().speed * 2;
4571 if (targetFrame().speed <= currentFrame().speed) {
4572 target += multiplier * currentFrame().speed * 2;
4577 if (animCurrent != animTarget) {
4578 target = (target + oldtarget) / 2;
4582 frameCurrent = frameTarget;
4586 rot = targetrot * target;
4587 yaw += rot - oldrot;
4593 if (frameCurrent >= int(Animation::animations[animCurrent].frames.size())) {
4594 frameCurrent = Animation::animations[animCurrent].frames.size() - 1;
4596 if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
4598 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4599 skeleton.joints[i].position = currentFrame().joints[i].position;
4602 skeleton.FindForwards();
4604 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4605 if (skeleton.muscles[i].visible) {
4606 skeleton.FindRotationMuscle(i, animTarget);
4609 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4610 if (skeleton.muscles[i].visible) {
4611 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100)) {
4612 skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4614 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100)) {
4615 skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4617 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100)) {
4618 skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4624 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4625 skeleton.joints[i].position = targetFrame().joints[i].position;
4628 skeleton.FindForwards();
4630 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4631 if (skeleton.muscles[i].visible) {
4632 skeleton.FindRotationMuscle(i, animTarget);
4635 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4636 if (skeleton.muscles[i].visible) {
4637 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100)) {
4638 skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4640 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100)) {
4641 skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4643 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100)) {
4644 skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4646 if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) {
4647 skeleton.muscles[i].newrotate3 -= 360;
4649 if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) {
4650 skeleton.muscles[i].newrotate3 += 360;
4652 if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) {
4653 skeleton.muscles[i].newrotate2 -= 360;
4655 if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) {
4656 skeleton.muscles[i].newrotate2 += 360;
4658 if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) {
4659 skeleton.muscles[i].newrotate1 -= 360;
4661 if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) {
4662 skeleton.muscles[i].newrotate1 += 360;
4668 oldanimCurrent = animCurrent;
4669 oldanimTarget = animTarget;
4670 oldframeTarget = frameTarget;
4671 oldframeCurrent = frameCurrent;
4673 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4674 skeleton.joints[i].velocity = (currentFrame().joints[i].position * (1 - target) + targetFrame().joints[i].position * target - skeleton.joints[i].position) / multiplier;
4675 skeleton.joints[i].position = currentFrame().joints[i].position * (1 - target) + targetFrame().joints[i].position * target;
4677 offset = currentoffset * (1 - target) + targetoffset * target;
4678 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4679 if (skeleton.muscles[i].visible) {
4680 skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * target;
4681 skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * target;
4682 skeleton.muscles[i].rotate3 = skeleton.muscles[i].oldrotate3 * (1 - target) + skeleton.muscles[i].newrotate3 * target;
4687 if (isLanding() && landhard) {
4691 animTarget = getLandhard();
4704 void Person::DoStuff()
4706 static XYZ terrainnormal;
4707 static XYZ flatfacing;
4708 static XYZ flatvelocity;
4709 static float flatvelspeed;
4710 static int bloodsize;
4711 static int startx, starty, endx, endy;
4712 static GLubyte color;
4713 static XYZ bloodvel;
4715 onfiredelay -= multiplier;
4716 if (onfiredelay < 0 && onfire) {
4717 if (Random() % 2 == 0) {
4723 crouchkeydowntime += multiplier;
4724 if (!crouchkeydown) {
4725 crouchkeydowntime = 0;
4727 jumpkeydowntime += multiplier;
4728 if (!jumpkeydown && skeleton.free) {
4729 jumpkeydowntime = 0;
4732 if (hostile || damage > 0 || bloodloss > 0) {
4736 if (isIdle() || isRun()) {
4740 if (num_weapons == 1 && weaponactive != -1) {
4745 blooddimamount -= multiplier * .3;
4747 speechdelay -= multiplier;
4748 texupdatedelay -= multiplier;
4749 interestdelay -= multiplier;
4750 flamedelay -= multiplier;
4751 parriedrecently -= multiplier;
4753 victim = this->shared_from_this();
4758 speed = 1.1 * speedmult;
4760 speed = 1.0 * speedmult;
4762 if (!skeleton.free) {
4763 rabbitkickragdoll = 0;
4768 if (id != 0 && (creature == rabbittype || difficulty != 2)) {
4771 if (id != 0 && creature == wolftype && difficulty == 2) {
4773 if (aitype != passivetype) {
4775 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) {
4782 if (animTarget == wolfrunninganim && !superruntoggle) {
4783 animTarget = getRun();
4787 if (weaponactive == -1 && num_weapons > 0) {
4788 if (weapons[weaponids[0]].getType() == staff) {
4794 burnt += multiplier;
4799 OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3);
4801 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
4807 vel[0] = velocity.x;
4808 vel[1] = velocity.y;
4809 vel[2] = velocity.z;
4812 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc);
4813 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
4817 while (flamedelay < 0 && onfire) {
4819 int howmany = fabs(Random() % (skeleton.joints.size()));
4820 if (skeleton.free) {
4821 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4822 flatfacing = skeleton.joints[howmany].position * scale + coords;
4824 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4825 flatvelocity = (coords - oldcoords) / multiplier / 2;
4827 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
4830 while (flamedelay < 0 && !onfire && Tutorial::active && id != 0) {
4832 int howmany = fabs(Random() % (skeleton.joints.size()));
4833 if (skeleton.free) {
4834 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4835 flatfacing = skeleton.joints[howmany].position * scale + coords;
4837 flatvelocity = (coords - oldcoords) / multiplier / 2;
4838 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4840 Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
4844 bleeding -= multiplier * .3;
4845 if (bloodtoggle == 2) {
4846 skeleton.drawmodel.textureptr.bind();
4847 if ((bleeding <= 0) && (detail != 2)) {
4853 if (neckspurtamount > 0) {
4854 neckspurtamount -= multiplier;
4855 neckspurtdelay -= multiplier * 3;
4856 neckspurtparticledelay -= multiplier * 3;
4857 if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
4860 if (skeleton.free) {
4861 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
4862 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4863 Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5) * scale + coords, bloodvel, 1, 1, 1, .05, .9);
4865 bloodvel.z = 5 * neckspurtamount;
4866 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4867 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
4868 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, .9);
4870 neckspurtparticledelay = .05;
4872 if (neckspurtdelay < 0) {
4877 if (deathbleeding > 0 && dead != 2) {
4878 if (deathbleeding < 5) {
4879 bleeddelay -= deathbleeding * multiplier / 4;
4881 bleeddelay -= 5 * multiplier / 4;
4883 if (bleeddelay < 0 && bloodtoggle) {
4888 if (skeleton.free) {
4889 bloodvel += DoRotation(jointVel(abdomen), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
4890 Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4892 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
4893 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4897 bloodloss += deathbleeding * multiplier * 80;
4898 deathbleeding -= multiplier * 1.6;
4899 if (deathbleeding < 0) {
4902 if (bloodloss > damagetolerance && Animation::animations[animTarget].attack == neutral) {
4903 if (weaponactive != -1) {
4904 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
4905 weapons[weaponids[0]].velocity.x += .01;
4908 weaponids[0] = weaponids[num_weapons];
4909 if (weaponstuck == num_weapons) {
4914 for (unsigned i = 0; i < Person::players.size(); i++) {
4915 Person::players[i]->wentforweapon = 0;
4923 if (!dead && creature == wolftype) {
4924 award_bonus(0, Wolfbonus);
4927 if (animTarget == knifefollowedanim && !skeleton.free) {
4928 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4929 skeleton.joints[i].velocity = 0;
4930 skeleton.joints[i].velocity.y = -2;
4933 if (id != 0 && unconscioustime > .1) {
4941 if (texupdatedelay < 0 && bleeding > 0 && bloodtoggle == 2 && distsq(&viewer, &coords) < 9) {
4942 texupdatedelay = .12;
4944 bloodsize = 5 - realtexdetail;
4948 startx = bleedy; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4949 starty = bleedx; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4950 endx = startx + bloodsize;
4951 endy = starty + bloodsize;
4961 if (endx > skeleton.skinsize - 1) {
4962 endx = skeleton.skinsize - 1;
4965 if (endy > skeleton.skinsize - 1) {
4966 endy = skeleton.skinsize - 1;
4969 if (endx < startx) {
4972 if (endy < starty) {
4976 for (int i = startx; i < endx; i++) {
4977 for (int j = starty; j < endy; j++) {
4978 if (Random() % 2 == 0) {
4979 color = Random() % 85 + 170;
4980 if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2) {
4981 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2;
4983 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0;
4984 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0;
4989 skeleton.drawmodel.textureptr.bind();
4993 if (skeleton.free) {
4994 bleedx += 4 * direction / realtexdetail;
4996 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4998 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
5001 bleedy -= 4 / realtexdetail;
5003 bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
5005 bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
5010 if (abs(righthandmorphness - targetrighthandmorphness) < multiplier * 4) {
5011 righthandmorphness = targetrighthandmorphness;
5012 righthandmorphstart = righthandmorphend;
5013 } else if (righthandmorphness > targetrighthandmorphness) {
5014 righthandmorphness -= multiplier * 4;
5015 } else if (righthandmorphness < targetrighthandmorphness) {
5016 righthandmorphness += multiplier * 4;
5019 if (abs(lefthandmorphness - targetlefthandmorphness) < multiplier * 4) {
5020 lefthandmorphness = targetlefthandmorphness;
5021 lefthandmorphstart = lefthandmorphend;
5022 } else if (lefthandmorphness > targetlefthandmorphness) {
5023 lefthandmorphness -= multiplier * 4;
5024 } else if (lefthandmorphness < targetlefthandmorphness) {
5025 lefthandmorphness += multiplier * 4;
5028 if (creature == rabbittype || targettailmorphness == 5 || targettailmorphness == 0) {
5029 if (abs(tailmorphness - targettailmorphness) < multiplier * 10) {
5030 tailmorphness = targettailmorphness;
5031 tailmorphstart = tailmorphend;
5032 } else if (tailmorphness > targettailmorphness) {
5033 tailmorphness -= multiplier * 10;
5034 } else if (tailmorphness < targettailmorphness) {
5035 tailmorphness += multiplier * 10;
5039 if (creature == wolftype) {
5040 if (abs(tailmorphness - targettailmorphness) < multiplier * 4) {
5041 tailmorphness = targettailmorphness;
5042 tailmorphstart = tailmorphend;
5043 } else if (tailmorphness > targettailmorphness) {
5044 tailmorphness -= multiplier * 2;
5045 } else if (tailmorphness < targettailmorphness) {
5046 tailmorphness += multiplier * 2;
5050 if (headmorphend == 3 || headmorphstart == 3) {
5051 if (abs(headmorphness - targetheadmorphness) < multiplier * 7) {
5052 headmorphness = targetheadmorphness;
5053 headmorphstart = headmorphend;
5054 } else if (headmorphness > targetheadmorphness) {
5055 headmorphness -= multiplier * 7;
5056 } else if (headmorphness < targetheadmorphness) {
5057 headmorphness += multiplier * 7;
5059 } else if (headmorphend == 5 || headmorphstart == 5) {
5060 if (abs(headmorphness - targetheadmorphness) < multiplier * 10) {
5061 headmorphness = targetheadmorphness;
5062 headmorphstart = headmorphend;
5063 } else if (headmorphness > targetheadmorphness) {
5064 headmorphness -= multiplier * 10;
5065 } else if (headmorphness < targetheadmorphness) {
5066 headmorphness += multiplier * 10;
5069 if (abs(headmorphness - targetheadmorphness) < multiplier * 4) {
5070 headmorphness = targetheadmorphness;
5071 headmorphstart = headmorphend;
5072 } else if (headmorphness > targetheadmorphness) {
5073 headmorphness -= multiplier * 4;
5074 } else if (headmorphness < targetheadmorphness) {
5075 headmorphness += multiplier * 4;
5079 if (abs(chestmorphness - targetchestmorphness) < multiplier) {
5080 chestmorphness = targetchestmorphness;
5081 chestmorphstart = chestmorphend;
5082 } else if (chestmorphness > targetchestmorphness) {
5083 chestmorphness -= multiplier;
5084 } else if (chestmorphness < targetchestmorphness) {
5085 chestmorphness += multiplier;
5088 if (dead != 2 && howactive <= typesleeping) {
5089 if (chestmorphstart == 0 && chestmorphend == 0) {
5091 targetchestmorphness = 1;
5094 if (chestmorphstart != 0 && chestmorphend != 0) {
5096 targetchestmorphness = 1;
5098 if (environment == snowyenvironment) {
5101 if (skeleton.free) {
5102 footvel = skeleton.specialforward[0] * -1;
5103 footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
5105 footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
5106 footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
5108 if (animTarget == sleepanim) {
5109 footvel = DoRotation(footvel, 0, 90, 0);
5111 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
5115 if (!dead && howactive < typesleeping) {
5116 blinkdelay -= multiplier * 2;
5117 if (headmorphstart == 0 && headmorphend == 0 && blinkdelay <= 0) {
5119 targetheadmorphness = 1;
5121 blinkdelay = (float)(abs(Random() % 40)) / 5;
5123 if (headmorphstart == 3 && headmorphend == 3) {
5125 targetheadmorphness = 1;
5130 twitchdelay -= multiplier * 1.5;
5131 if (animTarget != hurtidleanim) {
5132 if (headmorphstart == 0 && headmorphend == 0 && twitchdelay <= 0) {
5134 targetheadmorphness = 1;
5136 twitchdelay = (float)(abs(Random() % 40)) / 5;
5138 if (headmorphstart == 5 && headmorphend == 5) {
5140 targetheadmorphness = 1;
5144 if ((isIdle() || isCrouch()) && animTarget != hurtidleanim) {
5145 twitchdelay3 -= multiplier * 1;
5146 if (Random() % 2 == 0) {
5147 if (righthandmorphstart == 0 && righthandmorphend == 0 && twitchdelay3 <= 0) {
5148 righthandmorphness = 0;
5149 targetrighthandmorphness = 1;
5150 righthandmorphend = 1;
5151 if (Random() % 2 == 0) {
5152 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
5155 if (righthandmorphstart == 1 && righthandmorphend == 1) {
5156 righthandmorphness = 0;
5157 targetrighthandmorphness = 1;
5158 righthandmorphend = 0;
5161 if (Random() % 2 == 0) {
5162 if (lefthandmorphstart == 0 && lefthandmorphend == 0 && twitchdelay3 <= 0) {
5163 lefthandmorphness = 0;
5164 targetlefthandmorphness = 1;
5165 lefthandmorphend = 1;
5166 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
5168 if (lefthandmorphstart == 1 && lefthandmorphend == 1) {
5169 lefthandmorphness = 0;
5170 targetlefthandmorphness = 1;
5171 lefthandmorphend = 0;
5177 if (creature == rabbittype) {
5178 if (howactive < typesleeping) {
5179 twitchdelay2 -= multiplier * 1.5;
5181 twitchdelay2 -= multiplier * 0.5;
5183 if (howactive <= typesleeping) {
5184 if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) {
5186 targettailmorphness = 1;
5188 twitchdelay2 = (float)(abs(Random() % 40)) / 5;
5190 if (tailmorphstart == 1 && tailmorphend == 1) {
5192 targettailmorphness = 1;
5195 if (tailmorphstart == 2 && tailmorphend == 2) {
5197 targettailmorphness = 1;
5204 if (creature == wolftype) {
5205 twitchdelay2 -= multiplier * 1.5;
5206 if (tailmorphend != 0) {
5207 if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) {
5209 targettailmorphness = 1;
5214 if (tailmorphend != 5) {
5215 if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) {
5217 targettailmorphness = 1;
5222 if (twitchdelay2 <= 0) {
5223 if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) {
5225 targettailmorphness = 1;
5228 if (tailmorphstart == 1 && tailmorphend == 1) {
5230 targettailmorphness = 1;
5233 if (tailmorphstart == 2 && tailmorphend == 2) {
5235 targettailmorphness = 1;
5238 if (tailmorphstart == 3 && tailmorphend == 3) {
5240 targettailmorphness = 1;
5243 if (tailmorphstart == 4 && tailmorphend == 4) {
5245 targettailmorphness = 1;
5252 unconscioustime = 0;
5255 if (dead == 1 || howactive == typesleeping) {
5256 unconscioustime += multiplier;
5257 //If unconscious, close eyes and mouth
5258 if (righthandmorphend != 0) {
5259 righthandmorphness = 0;
5261 righthandmorphend = 0;
5262 targetrighthandmorphness = 1;
5264 if (lefthandmorphend != 0) {
5265 lefthandmorphness = 0;
5267 lefthandmorphend = 0;
5268 targetlefthandmorphness = 1;
5270 if (headmorphend != 3 && headmorphend != 5) {
5274 targetheadmorphness = 1;
5277 if (howactive > typesleeping) {
5280 if (bloodtoggle && !bled) {
5281 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
5282 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
5283 unsigned int j = terrain.patchobjects[whichpatchx][whichpatchz][l];
5284 XYZ point = DoRotation(headpoint - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
5288 Object::objects[j]->model.MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
5294 if (dead == 2 || howactive > typesleeping) {
5295 //If dead, open mouth and hands
5296 if (righthandmorphend != 0) {
5297 righthandmorphness = 0;
5299 righthandmorphend = 0;
5300 targetrighthandmorphness = 1;
5302 if (lefthandmorphend != 0) {
5303 lefthandmorphness = 0;
5305 lefthandmorphend = 0;
5306 targetlefthandmorphness = 1;
5308 if (headmorphend != 2) {
5312 targetheadmorphness = 1;
5315 if (stunned > 0 && !dead && headmorphend != 2) {
5316 if (headmorphend != 4) {
5320 targetheadmorphness = 1;
5323 if (damage > damagetolerance && !dead) {
5326 unconscioustime = 0;
5328 if (creature == wolftype) {
5329 award_bonus(0, Wolfbonus);
5334 if (weaponactive != -1) {
5335 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
5336 weapons[weaponids[0]].velocity.x += .01;
5339 weaponids[0] = weaponids[num_weapons];
5340 if (weaponstuck == num_weapons) {
5345 for (unsigned i = 0; i < Person::players.size(); i++) {
5346 Person::players[i]->wentforweapon = 0;
5350 if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) {
5359 damage -= multiplier * 13;
5360 permanentdamage -= multiplier * 4;
5361 if (isIdle() || isCrouch()) {
5362 permanentdamage -= multiplier * 4;
5368 if (permanentdamage < 0) {
5369 permanentdamage = 0;
5371 if (superpermanentdamage < 0) {
5372 superpermanentdamage = 0;
5374 if (permanentdamage < superpermanentdamage) {
5375 permanentdamage = superpermanentdamage;
5377 if (damage < permanentdamage) {
5378 damage = permanentdamage;
5380 if (dead == 1 && damage < damagetolerance) {
5384 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5385 skeleton.joints[i].velocity = 0;
5388 if (permanentdamage > damagetolerance && dead != 2) {
5391 if (weaponactive != -1) {
5392 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
5393 weapons[weaponids[0]].velocity.x += .01;
5396 weaponids[0] = weaponids[num_weapons];
5397 if (weaponstuck == num_weapons) {
5402 for (unsigned i = 0; i < Person::players.size(); i++) {
5403 Person::players[i]->wentforweapon = 0;
5409 if (!dead && creature == wolftype) {
5410 award_bonus(0, Wolfbonus);
5413 if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance) {
5414 award_bonus(id, touchofdeath);
5416 if (id != 0 && unconscioustime > .1) {
5424 emit_sound_at(breaksound, coords);
5427 if (skeleton.free == 1) {
5429 pause_sound(whooshsound);
5433 //If knocked over, open hands and close mouth
5434 if (righthandmorphend != 0) {
5435 righthandmorphness = 0;
5437 righthandmorphend = 0;
5438 targetrighthandmorphness = 1;
5440 if (lefthandmorphend != 0) {
5441 lefthandmorphness = 0;
5443 lefthandmorphend = 0;
5444 targetlefthandmorphness = 1;
5446 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) {
5447 if (headmorphend != 0) {
5451 targetheadmorphness = 1;
5455 skeleton.DoGravity(&scale);
5457 damageamount = skeleton.DoConstraints(&coords, &scale) * 5;
5458 if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1)) {
5459 award_bonus(id, deepimpact);
5461 DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3));
5465 if (!skeleton.joints.empty()) {
5466 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
5467 average += skeleton.joints[j].position;
5469 average /= skeleton.joints.size();
5470 coords += average * scale;
5471 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
5472 skeleton.joints[j].position -= average;
5474 average /= multiplier;
5478 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5479 velocity += skeleton.joints[i].velocity * scale;
5481 velocity /= skeleton.joints.size();
5483 if (!isnormal(velocity.x) && velocity.x) {
5487 if (findLength(&average) < 10 && dead && skeleton.free) {
5488 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
5489 if (skeleton.longdead > 2000) {
5490 if (skeleton.longdead > 6000) {
5492 pause_sound(whooshsound);
5498 if (dead == 2 && bloodloss < damagetolerance) {
5500 headpoint = (jointPos(head) + jointPos(neck)) / 2 * scale + coords;
5502 if (bloodtoggle && !bled) {
5503 terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
5504 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
5505 unsigned int j = terrain.patchobjects[whichpatchx][whichpatchz][l];
5506 XYZ point = DoRotation(headpoint - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
5507 float size = .2 * 1.2;
5510 Object::objects[j]->model.MakeDecal(blooddecal, &point, &size, &opacity, &yaw);
5515 if (dead == 2 && bloodloss >= damagetolerance) {
5517 headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords;
5518 if (bleeding <= 0) {
5521 if (bloodtoggle && !bled) {
5522 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
5523 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
5524 unsigned int j = terrain.patchobjects[whichpatchx][whichpatchz][l];
5525 XYZ point = DoRotation(headpoint - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
5529 Object::objects[j]->model.MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
5537 if (!dead && crouchkeydown && skeleton.freetime > .5 && id == 0 && skeleton.free) {
5538 bool canrecover = 1;
5539 XYZ startpoint, endpoint, colpoint, colviewer, coltarget;
5540 startpoint = coords;
5543 if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1) {
5546 if (velocity.y < -30) {
5549 for (unsigned int i = 0; i < Object::objects.size(); i++) {
5550 if (Object::objects[i]->type != treeleavestype && Object::objects[i]->type != bushtype && Object::objects[i]->type != firetype) {
5551 colviewer = startpoint;
5552 coltarget = endpoint;
5553 if (Object::objects[i]->model.LineCheck(&colviewer, &coltarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
5563 terrainnormal = jointPos(groin) - jointPos(abdomen);
5564 if (joint(groin).locked && joint(abdomen).locked) {
5565 terrainnormal = jointPos(groin) - jointPos(abdomen);
5566 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
5568 if (joint(abdomen).locked && joint(neck).locked) {
5569 terrainnormal = jointPos(abdomen) - jointPos(neck);
5570 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
5572 if (joint(groin).locked && joint(neck).locked) {
5573 terrainnormal = jointPos(groin) - jointPos(neck);
5574 middle = (jointPos(groin) + jointPos(neck)) / 2;
5576 Normalise(&terrainnormal);
5578 targetyaw = -asin(0 - terrainnormal.x);
5579 targetyaw *= 360 / 6.28;
5580 if (terrainnormal.z < 0) {
5581 targetyaw = 180 - targetyaw;
5586 animTarget = flipanim;
5587 crouchtogglekeydown = 1;
5592 animCurrent = tempanim;
5596 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5597 tempanimation.frames[0].joints[i].position = skeleton.joints[i].position;
5598 tempanimation.frames[0].joints[i].position = DoRotation(tempanimation.frames[0].joints[i].position, 0, -yaw, 0);
5603 if (findLength(&average) < 10 && !dead && skeleton.free) {
5604 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
5605 if (skeleton.longdead > (damage + 500) * 1.5) {
5607 pause_sound(whooshsound);
5614 terrainnormal = jointPos(groin) - jointPos(abdomen);
5615 if (joint(groin).locked && joint(abdomen).locked) {
5616 terrainnormal = jointPos(groin) - jointPos(abdomen);
5617 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
5619 if (joint(abdomen).locked && joint(neck).locked) {
5620 terrainnormal = jointPos(abdomen) - jointPos(neck);
5621 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
5623 if (joint(groin).locked && joint(neck).locked) {
5624 terrainnormal = jointPos(groin) - jointPos(neck);
5625 middle = (jointPos(groin) + jointPos(neck)) / 2;
5627 Normalise(&terrainnormal);
5629 targetyaw = -asin(0 - terrainnormal.x);
5630 targetyaw *= 360 / 6.28;
5631 if (terrainnormal.z < 0) {
5632 targetyaw = 180 - targetyaw;
5636 targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1;
5638 if (skeleton.forward.y < 0) {
5639 animTarget = getupfrombackanim;
5643 if (skeleton.forward.y > -.3) {
5644 animTarget = getupfromfrontanim;
5652 if ((Random() % 8 == 0 && id != 0 && creature == rabbittype) || (Random() % 2 == 0 && id != 0 && creature == wolftype) || (id == 0 && crouchkeydown && (forwardkeydown || backkeydown || leftkeydown || rightkeydown))) {
5653 animTarget = rollanim;
5654 targetyaw = lookyaw;
5658 if (forwardkeydown) {
5667 if (forwardkeydown) {
5675 if (!leftkeydown && !rightkeydown) {
5683 if (abs(targettilt2) > 50) {
5686 animCurrent = tempanim;
5689 tilt2 = targettilt2;
5691 if (middle.y > 0 && animTarget != rollanim) {
5692 targetoffset.y = middle.y + 1;
5695 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5696 tempanimation.frames[0].joints[i].position = skeleton.joints[i].position;
5697 tempanimation.frames[0].joints[i].position = DoRotation(tempanimation.frames[0].joints[i].position, 0, -yaw, 0);
5704 if (num_weapons > 0) {
5705 if (weapons[0].getType() == staff) {
5709 if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) {
5710 if (velocity.y > -30) {
5712 tempvelocity = velocity;
5713 Normalise(&tempvelocity);
5714 targetyaw = -asin(0 - tempvelocity.x);
5715 targetyaw *= 360 / 6.28;
5716 if (velocity.z < 0) {
5717 targetyaw = 180 - targetyaw;
5722 if (dotproduct(&skeleton.forward, &tempvelocity) < 0) {
5723 animTarget = rollanim;
5726 animTarget = backhandspringanim;
5732 emit_sound_at(movewhooshsound, coords, 128.);
5734 animCurrent = animTarget;
5735 frameCurrent = frameTarget - 1;
5747 if (skeleton.freefall == 0) {
5752 if (aitype != passivetype || skeleton.free == 1) {
5753 if (findLengthfast(&velocity) > .1) {
5754 for (unsigned int i = 0; i < Object::objects.size(); i++) {
5755 if (Object::objects[i]->type == firetype) {
5756 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) {
5758 if (!Object::objects[i]->onfire) {
5759 emit_sound_at(firestartsound, Object::objects[i]->position);
5761 Object::objects[i]->onfire = 1;
5764 if (Object::objects[i]->onfire) {
5770 if (Object::objects[i]->type == bushtype) {
5771 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) {
5773 if (!Object::objects[i]->onfire) {
5774 emit_sound_at(firestartsound, Object::objects[i]->position);
5776 Object::objects[i]->onfire = 1;
5780 if (Object::objects[i]->onfire) {
5784 if (Object::objects[i]->messedwith <= 0) {
5788 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5791 addEnvSound(coords, 4 * findLength(&velocity));
5795 if (environment == grassyenvironment) {
5796 howmany = findLength(&velocity) * 4;
5798 if (environment == snowyenvironment) {
5799 howmany = findLength(&velocity) * 2;
5802 if (environment != desertenvironment) {
5803 for (int j = 0; j < howmany; j++) {
5804 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5805 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5806 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5809 pos.x += float(abs(Random() % 100) - 50) / 200;
5810 pos.y += float(abs(Random() % 100) - 50) / 200;
5811 pos.z += float(abs(Random() % 100) - 50) / 200;
5812 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);
5813 Sprite::setLastSpriteSpecial(1);
5817 howmany = findLength(&velocity) * 4;
5819 if (environment == snowyenvironment) {
5820 for (int j = 0; j < howmany; j++) {
5821 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5822 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5823 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5826 pos.x += float(abs(Random() % 100) - 50) / 200;
5827 pos.y += float(abs(Random() % 100) - 50) / 200;
5828 pos.z += float(abs(Random() % 100) - 50) / 200;
5829 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5830 Sprite::setLastSpriteSpecial(2);
5835 Object::objects[i]->rotx += velocity.x * multiplier * 6;
5836 Object::objects[i]->roty += velocity.z * multiplier * 6;
5837 Object::objects[i]->messedwith = .5;
5841 if (Object::objects[i]->type == treeleavestype && environment != desertenvironment) {
5842 if (Object::objects[i]->pitch == 0) {
5845 tempcoord = coords - Object::objects[i]->position;
5846 tempcoord = DoRotation(tempcoord, 0, -Object::objects[i]->yaw, 0);
5847 tempcoord = DoRotation(tempcoord, -Object::objects[i]->pitch, 0, 0);
5848 tempcoord += Object::objects[i]->position;
5850 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) {
5851 if (Object::objects[i]->messedwith <= 0) {
5855 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5858 addEnvSound(coords, 4 * findLength(&velocity));
5862 if (environment == grassyenvironment) {
5863 howmany = findLength(&velocity) * 4;
5865 if (environment == snowyenvironment) {
5866 howmany = findLength(&velocity) * 2;
5869 if (environment != desertenvironment) {
5870 for (int j = 0; j < howmany; j++) {
5871 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5872 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5873 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5875 pos += velocity * .1;
5877 pos.x += float(abs(Random() % 100) - 50) / 150;
5878 pos.y += float(abs(Random() % 100) - 50) / 150;
5879 pos.z += float(abs(Random() % 100) - 50) / 150;
5880 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);
5881 Sprite::setLastSpriteSpecial(1);
5885 howmany = findLength(&velocity) * 4;
5887 if (environment == snowyenvironment) {
5888 for (int j = 0; j < howmany; j++) {
5889 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5890 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5891 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5893 pos += velocity * .1;
5895 pos.x += float(abs(Random() % 100) - 50) / 150;
5896 pos.y += float(abs(Random() % 100) - 50) / 150;
5897 pos.z += float(abs(Random() % 100) - 50) / 150;
5898 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5899 Sprite::setLastSpriteSpecial(2);
5904 Object::objects[i]->messedwith = .5;
5911 if (!skeleton.free) {
5914 if ((stunned > 0 || surprised > 0) && Person::players.size() > 2 && aitype != passivetype) {
5918 if (aitype != passivetype && victim->skeleton.free && !victim->dead) {
5922 if (Tutorial::active && id != 0) {
5925 if (play && aitype != playercontrolled) {
5926 int whichsound = -1;
5927 if (speechdelay <= 0) {
5928 unsigned int i = abs(Random() % 4);
5929 if (creature == rabbittype) {
5931 whichsound = rabbitchitter;
5934 whichsound = rabbitchitter2;
5937 if (creature == wolftype) {
5939 whichsound = growlsound;
5942 whichsound = growl2sound;
5948 if (whichsound != -1) {
5949 emit_sound_at(whichsound, coords);
5953 if (animTarget == staggerbackhighanim) {
5956 if (animTarget == staggerbackhardanim) {
5959 staggerdelay -= multiplier;
5960 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) {
5963 if (velocity.y < -30 && animTarget == jumpdownanim) {
5966 if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) {
5967 animTarget = getIdle();
5971 weaponmissdelay -= multiplier;
5972 highreversaldelay -= multiplier;
5973 lowreversaldelay -= multiplier;
5974 lastcollide -= multiplier;
5975 skiddelay -= multiplier;
5976 if (!isnormal(velocity.x) && velocity.x) {
5979 if (!isnormal(targettilt) && targettilt) {
5982 if (!isnormal(targettilt2) && targettilt2) {
5985 if (!isnormal(targetyaw) && targetyaw) {
5989 if (animTarget == bounceidleanim || animTarget == wolfidle || animTarget == walkanim || animTarget == drawrightanim || animTarget == crouchdrawrightanim || animTarget == drawleftanim || animTarget == fightidleanim || animTarget == fightsidestep || animTarget == hanganim || isCrouch() || animTarget == backhandspringanim) {
5990 //open hands and close mouth
5991 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5992 righthandmorphness = 0;
5993 righthandmorphend = 0;
5994 targetrighthandmorphness = 1;
5997 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5998 lefthandmorphness = 0;
5999 lefthandmorphend = 0;
6000 targetlefthandmorphness = 1;
6003 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5 && headmorphend != 0 && headmorphness == targetheadmorphness) {
6006 targetheadmorphness = 1;
6010 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) {
6011 //open hands and mouth
6012 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
6013 righthandmorphness = 0;
6014 righthandmorphend = 0;
6015 targetrighthandmorphness = 1;
6018 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
6019 lefthandmorphness = 0;
6020 lefthandmorphend = 0;
6021 targetlefthandmorphness = 1;
6024 if (headmorphend != 1 && headmorphness == targetheadmorphness) {
6027 targetheadmorphness = 1;
6031 if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim) {
6032 //close hands and mouth
6033 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
6034 righthandmorphness = 0;
6035 righthandmorphend = 1;
6036 targetrighthandmorphness = 1;
6039 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
6040 lefthandmorphness = 0;
6041 lefthandmorphend = 1;
6042 targetlefthandmorphness = 1;
6045 if (headmorphend != 0 && headmorphness == targetheadmorphness) {
6048 targetheadmorphness = 1;
6052 if (animTarget == spinkickanim ||
6053 animTarget == staffspinhitreversalanim ||
6054 animTarget == staffspinhitreversedanim ||
6055 animTarget == staffhitreversalanim ||
6056 animTarget == staffhitreversedanim ||
6057 animTarget == hurtidleanim ||
6058 animTarget == winduppunchanim ||
6059 animTarget == swordslashreversalanim ||
6060 animTarget == swordslashreversedanim ||
6061 animTarget == knifeslashreversalanim ||
6062 animTarget == knifeslashreversedanim ||
6063 animTarget == knifethrowanim ||
6064 animTarget == knifefollowanim ||
6065 animTarget == knifefollowedanim ||
6066 animTarget == killanim ||
6067 animTarget == dropkickanim ||
6068 animTarget == upunchanim ||
6069 animTarget == knifeslashstartanim ||
6070 animTarget == swordslashanim ||
6071 animTarget == staffhitanim ||
6072 animTarget == staffspinhitanim ||
6073 animTarget == staffgroundsmashanim ||
6074 animTarget == spinkickreversalanim ||
6075 animTarget == sweepreversalanim ||
6076 animTarget == lowkickanim ||
6077 animTarget == sweepreversedanim ||
6078 animTarget == rabbitkickreversalanim ||
6079 animTarget == rabbitkickreversedanim ||
6080 animTarget == jumpreversalanim ||
6081 animTarget == jumpreversedanim) {
6082 //close hands and yell
6083 if (righthandmorphend != 1 &&
6084 righthandmorphness == targetrighthandmorphness) {
6085 righthandmorphness = 0;
6086 righthandmorphend = 1;
6087 targetrighthandmorphness = 1;
6090 if (lefthandmorphend != 1 &&
6091 lefthandmorphness == targetlefthandmorphness) {
6092 lefthandmorphness = 0;
6093 lefthandmorphend = 1;
6094 targetlefthandmorphness = 1;
6097 if (headmorphend != 2 && headmorphness == targetheadmorphness) {
6100 targetheadmorphness = 1;
6107 if ((victim != this->shared_from_this()) && !victim->dead && (victim->aitype != passivetype) &&
6108 (victim->aitype != searchtype) && (aitype != passivetype) &&
6109 (aitype != searchtype) && (victim->id < Person::players.size())) {
6110 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
6114 if (!dead && animTarget != hurtidleanim) {
6115 if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) {
6116 if (headmorphend != 4 || headmorphness == targetheadmorphness) {
6119 targetheadmorphness = 1;
6124 if (weaponactive != -1) {
6125 if (weapons[weaponids[weaponactive]].getType() != staff) {
6126 righthandmorphstart = 1;
6127 righthandmorphend = 1;
6129 if (weapons[weaponids[weaponactive]].getType() == staff) {
6130 righthandmorphstart = 2;
6131 righthandmorphend = 2;
6133 targetrighthandmorphness = 1;
6136 terrainnormal = terrain.getNormal(coords.x, coords.z);
6138 if (Animation::animations[animTarget].attack != reversal) {
6139 if (!isnormal(coords.x)) {
6148 flatfacing = DoRotation(flatfacing, 0, yaw, 0);
6149 facing = flatfacing;
6150 ReflectVector(&facing, terrainnormal);
6154 animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) {
6156 targettilt2 = -facing.y * 20;
6162 if (!isRun() && !Animation::animations[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim) {
6165 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
6166 flatvelocity = velocity;
6168 flatvelspeed = findLength(&flatvelocity);
6169 targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity);
6170 targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity);
6171 if (velocity.y < 0) {
6174 if (velocity.y < 0) {
6177 if (targettilt > 25) {
6180 if (targettilt < -25) {
6185 if (targettilt2 > 45) {
6188 if (targettilt2 < -45) {
6191 if (abs(tilt2 - targettilt2) < multiplier * 400) {
6192 tilt2 = targettilt2;
6193 } else if (tilt2 > targettilt2) {
6194 tilt2 -= multiplier * 400;
6195 } else if (tilt2 < targettilt2) {
6196 tilt2 += multiplier * 400;
6198 if (!Animation::animations[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) {
6207 if (!isnormal(targettilt) && targettilt) {
6210 if (!isnormal(targettilt2) && targettilt2) {
6215 if (animTarget == rabbittackleanim) {
6216 velocity += facing * multiplier * speed * 700 * scale;
6217 velspeed = findLength(&velocity);
6218 if (velspeed > speed * 65 * scale) {
6219 velocity /= velspeed;
6220 velspeed = speed * 65 * scale;
6221 velocity *= velspeed;
6223 velocity.y += gravity * multiplier * 20;
6224 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6225 velspeed = findLength(&velocity);
6226 velocity = flatfacing * velspeed;
6228 if (animTarget != rabbitrunninganim && animTarget != wolfrunninganim) {
6229 if (isRun() || animTarget == rabbitkickanim) {
6230 velocity += facing * multiplier * speed * 700 * scale;
6231 velspeed = findLength(&velocity);
6232 if (velspeed > speed * 45 * scale) {
6233 velocity /= velspeed;
6234 velspeed = speed * 45 * scale;
6235 velocity *= velspeed;
6237 velocity.y += gravity * multiplier * 20;
6238 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6239 velspeed = findLength(&velocity);
6240 if (velspeed < speed * 30 * scale) {
6241 velspeed = speed * 30 * scale;
6243 velocity = flatfacing * velspeed;
6245 } else if (isRun()) {
6246 velocity += facing * multiplier * speed * 700 * scale;
6247 velspeed = findLength(&velocity);
6248 if (creature == rabbittype) {
6249 if (velspeed > speed * 55 * scale) {
6250 velocity /= velspeed;
6251 velspeed = speed * 55 * scale;
6252 velocity *= velspeed;
6255 if (creature == wolftype) {
6256 if (velspeed > speed * 75 * scale) {
6257 velocity /= velspeed;
6258 velspeed = speed * 75 * scale;
6259 velocity *= velspeed;
6262 velocity.y += gravity * multiplier * 20;
6263 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6264 velspeed = findLength(&velocity);
6265 velocity = flatfacing * velspeed;
6268 if (animTarget == rollanim && targetFrame().label != 6) {
6269 velocity += facing * multiplier * speed * 700 * scale;
6270 velspeed = findLength(&velocity);
6271 if (velspeed > speed * 45 * scale) {
6272 velocity /= velspeed;
6273 velspeed = speed * 45 * scale;
6274 velocity *= velspeed;
6276 velocity.y += gravity * multiplier * 20;
6277 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6278 velspeed = findLength(&velocity);
6279 velocity = flatfacing * velspeed;
6282 if (animTarget == sneakanim || animTarget == walkanim) {
6283 velocity += facing * multiplier * speed * 700 * scale;
6284 velspeed = findLength(&velocity);
6285 if (velspeed > speed * 12 * scale) {
6286 velocity /= velspeed;
6287 velspeed = speed * 12 * scale;
6288 velocity *= velspeed;
6290 velocity.y += gravity * multiplier * 20;
6291 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6292 velspeed = findLength(&velocity);
6293 velocity = flatfacing * velspeed;
6296 if ((animTarget == fightidleanim || animTarget == knifefightidleanim) && (animCurrent == bounceidleanim || animCurrent == hurtidleanim)) {
6297 velocity += facing * multiplier * speed * 700 * scale;
6298 velspeed = findLength(&velocity);
6299 if (velspeed > speed * 2 * scale) {
6300 velocity /= velspeed;
6301 velspeed = speed * 2 * scale;
6302 velocity *= velspeed;
6304 velocity.y += gravity * multiplier * 20;
6305 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6306 velspeed = findLength(&velocity);
6307 velocity = flatfacing * velspeed;
6310 if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) {
6311 velocity -= facing * multiplier * speed * 700 * scale;
6312 velspeed = findLength(&velocity);
6313 if (velspeed > speed * 2 * scale) {
6314 velocity /= velspeed;
6315 velspeed = speed * 2 * scale;
6316 velocity *= velspeed;
6318 velocity.y += gravity * multiplier * 20;
6319 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6320 velspeed = findLength(&velocity);
6321 velocity = flatfacing * velspeed * -1;
6324 if (animTarget == fightsidestep) {
6325 velocity += DoRotation(facing * multiplier * speed * 700 * scale, 0, -90, 0);
6326 velspeed = findLength(&velocity);
6327 if (velspeed > speed * 12 * scale) {
6328 velocity /= velspeed;
6329 velspeed = speed * 12 * scale;
6330 velocity *= velspeed;
6332 velocity.y += gravity * multiplier * 20;
6333 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6334 velspeed = findLength(&velocity);
6335 velocity = DoRotation(flatfacing * velspeed, 0, -90, 0);
6338 if (animTarget == staggerbackhighanim) {
6339 coords -= facing * multiplier * speed * 16 * scale;
6342 if (animTarget == staggerbackhardanim && Animation::animations[staggerbackhardanim].frames[frameTarget].label != 6) {
6343 coords -= facing * multiplier * speed * 20 * scale;
6347 if (animTarget == backhandspringanim) {
6348 //coords-=facing*multiplier*50*scale;
6349 velocity += facing * multiplier * speed * 700 * scale * -1;
6350 velspeed = findLength(&velocity);
6351 if (velspeed > speed * 50 * scale) {
6352 velocity /= velspeed;
6353 velspeed = speed * 50 * scale;
6354 velocity *= velspeed;
6356 velocity.y += gravity * multiplier * 20;
6357 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6358 velspeed = findLength(&velocity);
6359 velocity = flatfacing * velspeed * -1;
6361 if (animTarget == dodgebackanim) {
6362 //coords-=facing*multiplier*50*scale;
6363 velocity += facing * multiplier * speed * 700 * scale * -1;
6364 velspeed = findLength(&velocity);
6365 if (velspeed > speed * 60 * scale) {
6366 velocity /= velspeed;
6367 velspeed = speed * 60 * scale;
6368 velocity *= velspeed;
6370 velocity.y += gravity * multiplier * 20;
6371 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6372 velspeed = findLength(&velocity);
6373 velocity = flatfacing * velspeed * -1;
6376 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
6377 velspeed = findLength(&velocity);
6380 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
6381 velocity.y += gravity * multiplier;
6384 if (animTarget != climbanim && animTarget != hanganim && !isWallJump()) {
6385 coords += velocity * multiplier;
6388 if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
6389 if (isFlip() && targetFrame().label == 7) {
6393 if (animTarget == jumpupanim) {
6395 animTarget = getIdle();
6402 pause_sound(whooshsound);
6403 OPENAL_SetVolume(channels[whooshsound], 0);
6406 if (animTarget == jumpdownanim || isFlip()) {
6410 animTarget = getLanding();
6411 emit_sound_at(landsound, coords, 128.);
6414 addEnvSound(coords);
6419 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump()) {
6420 coords.y += gravity * multiplier * 2;
6422 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) {
6423 coords.y = terrain.getHeight(coords.x, coords.z);
6427 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)) {
6428 velspeed = findLength(&velocity);
6430 if (velspeed < multiplier * 300 * scale) {
6433 velocity -= velocity / velspeed * multiplier * 300 * scale;
6435 if (velspeed > 5 && (isLanding() || isLandhard())) {
6436 skiddingdelay += multiplier;
6437 if (skiddelay <= 0) {
6438 FootLand(leftfoot, .5);
6439 FootLand(rightfoot, .5);
6448 velspeed = findLength(&velocity);
6450 if (velspeed > 5 && (isLanding() || isLandhard())) {
6451 skiddingdelay += multiplier;
6452 if (skiddelay <= 0) {
6453 FootLand(leftfoot, .5);
6454 FootLand(rightfoot, .5);
6462 if (skiddingdelay < 0) {
6463 skiddingdelay += multiplier;
6465 if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) {
6467 if (!onterrain || environment == grassyenvironment) {
6468 emit_sound_at(skidsound, coords, 128 * velspeed / 10);
6470 emit_sound_at(snowskidsound, coords, 128 * velspeed / 10);
6474 if (Animation::animations[animTarget].attack == normalattack && animTarget != rabbitkickanim && !victim->skeleton.free) {
6475 terrainnormal = victim->coords - coords;
6476 Normalise(&terrainnormal);
6477 targetyaw = -asin(0 - terrainnormal.x);
6478 targetyaw *= 360 / 6.28;
6479 if (terrainnormal.z < 0) {
6480 targetyaw = 180 - targetyaw;
6482 targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70;
6485 if (Animation::animations[animTarget].attack == reversal && animTarget != rabbittacklinganim) {
6486 targetyaw = victim->targetyaw;
6488 if (animTarget == rabbittacklinganim) {
6489 coords = victim->coords;
6492 skeleton.oldfree = skeleton.free;
6496 midterrain.x = terrain.size * terrain.scale / 2;
6497 midterrain.z = terrain.size * terrain.scale / 2;
6498 if (distsqflat(&coords, &midterrain) > (terrain.size * terrain.scale / 2 - viewdistance) * (terrain.size * terrain.scale / 2 - viewdistance)) {
6500 tempposit = coords - midterrain;
6502 Normalise(&tempposit);
6503 tempposit *= (terrain.size * terrain.scale / 2 - viewdistance);
6504 coords.x = tempposit.x + midterrain.x;
6505 coords.z = tempposit.z + midterrain.z;
6510 * inverse kinematics helper function
6512 void IKHelper(Person* p, float interp)
6514 XYZ point, change, change2;
6515 float heightleft, heightright;
6517 // TODO: implement localToWorld and worldToLocal
6518 // but keep in mind it won't be the same math if player is ragdolled or something
6519 // - localToWorldStanding / worldToLocalStanding (or crouching or...?)
6520 // then comb through code for places where to use it
6522 // point = localToWorld(jointPos(leftfoot))
6523 point = DoRotation(p->jointPos(leftfoot), 0, p->yaw, 0) * p->scale + p->coords;
6524 // adjust height of foot
6525 heightleft = terrain.getHeight(point.x, point.z) + .04;
6526 point.y = heightleft;
6527 change = p->jointPos(leftankle) - p->jointPos(leftfoot);
6528 change2 = p->jointPos(leftknee) - p->jointPos(leftfoot);
6529 // jointPos(leftfoot) = interpolate(worldToLocal(point), jointPos(leftfoot), interp)
6530 p->jointPos(leftfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(leftfoot) * (1 - interp);
6531 // move ankle along with foot
6532 p->jointPos(leftankle) = p->jointPos(leftfoot) + change;
6533 // average knee pos between old and new pos
6534 p->jointPos(leftknee) = (p->jointPos(leftfoot) + change2) / 2 + (p->jointPos(leftknee)) / 2;
6536 // do same as above for right leg
6537 point = DoRotation(p->jointPos(rightfoot), 0, p->yaw, 0) * p->scale + p->coords;
6538 heightright = terrain.getHeight(point.x, point.z) + .04;
6539 point.y = heightright;
6540 change = p->jointPos(rightankle) - p->jointPos(rightfoot);
6541 change2 = p->jointPos(rightknee) - p->jointPos(rightfoot);
6542 p->jointPos(rightfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(rightfoot) * (1 - interp);
6543 p->jointPos(rightankle) = p->jointPos(rightfoot) + change;
6544 p->jointPos(rightknee) = (p->jointPos(rightfoot) + change2) / 2 + (p->jointPos(rightknee)) / 2;
6546 // fix up skeleton now that we've moved body parts?
6547 p->skeleton.DoConstraints(&p->coords, &p->scale);
6554 int Person::DrawSkeleton()
6556 int oldplayerdetail;
6557 if ((frustum.SphereInFrustum(coords.x, coords.y + scale * 3, coords.z, scale * 8) && distsq(&viewer, &coords) < viewdistance * viewdistance) || skeleton.free == 3) {
6558 if (onterrain && (isIdle() || isCrouch() || wasIdle() || wasCrouch()) && !skeleton.free) {
6568 glAlphaFunc(GL_GREATER, 0.0001);
6570 float terrainheight;
6572 if (!isnormal(yaw)) {
6575 if (!isnormal(tilt)) {
6578 if (!isnormal(tilt2)) {
6581 oldplayerdetail = playerdetail;
6583 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) {
6586 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 128 && detail == 1) {
6589 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) {
6595 if (playerdetail != oldplayerdetail) {
6597 normalsupdatedelay = 0;
6599 static float updatedelaychange;
6600 static float morphness;
6601 static float framemult;
6603 skeleton.FindForwards();
6604 if (howactive == typesittingwall) {
6605 skeleton.specialforward[1] = 0;
6606 skeleton.specialforward[1].z = 1;
6612 static int weaponattachmuscle;
6613 static int weaponrotatemuscle;
6614 static XYZ weaponpoint;
6615 static int start, endthing;
6616 if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
6617 if (!isSleeping() && !isSitting()) {
6618 // TODO: give these meaningful names
6619 const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim);
6620 const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard() || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim);
6622 if (onterrain && (cond1 && cond2) && !skeleton.free) {
6624 if (creature == wolftype) {
6629 if (onterrain && (cond1 && !cond2) && !skeleton.free) {
6630 IKHelper(this, target);
6631 if (creature == wolftype) {
6632 IKHelper(this, target);
6636 if (onterrain && (!cond1 && cond2) && !skeleton.free) {
6637 IKHelper(this, 1 - target);
6638 if (creature == wolftype) {
6639 IKHelper(this, 1 - target);
6644 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())) {
6647 targetheadyaw = -targetyaw;
6648 targetheadpitch = 0;
6649 if (Animation::animations[animTarget].attack == 3) {
6650 targetheadyaw += 180;
6653 for (int i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6654 skeleton.drawmodel.vertex[i] = 0;
6655 skeleton.drawmodel.vertex[i].y = 999;
6657 for (int i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
6658 skeleton.drawmodellow.vertex[i] = 0;
6659 skeleton.drawmodellow.vertex[i].y = 999;
6661 for (int i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
6662 skeleton.drawmodelclothes.vertex[i] = 0;
6663 skeleton.drawmodelclothes.vertex[i].y = 999;
6665 for (unsigned int i = 0; i < skeleton.muscles.size(); i++) {
6666 // convenience renames
6667 const int p1 = skeleton.muscles[i].parent1->label;
6668 const int p2 = skeleton.muscles[i].parent2->label;
6670 if ((skeleton.muscles[i].vertices.size() > 0 && playerdetail) || (skeleton.muscles[i].verticeslow.size() > 0 && !playerdetail)) {
6675 if (p1 == righthand || p2 == righthand) {
6676 morphness = righthandmorphness;
6677 start = righthandmorphstart;
6678 endthing = righthandmorphend;
6680 if (p1 == lefthand || p2 == lefthand) {
6681 morphness = lefthandmorphness;
6682 start = lefthandmorphstart;
6683 endthing = lefthandmorphend;
6685 if (p1 == head || p2 == head) {
6686 morphness = headmorphness;
6687 start = headmorphstart;
6688 endthing = headmorphend;
6690 if ((p1 == neck && p2 == abdomen) || (p2 == neck && p1 == abdomen)) {
6691 morphness = chestmorphness;
6692 start = chestmorphstart;
6693 endthing = chestmorphend;
6695 if ((p1 == groin && p2 == abdomen) || (p2 == groin && p1 == abdomen)) {
6696 morphness = tailmorphness;
6697 start = tailmorphstart;
6698 endthing = tailmorphend;
6701 skeleton.FindRotationMuscle(i, animTarget);
6703 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6704 glMatrixMode(GL_MODELVIEW);
6707 if (!skeleton.free) {
6708 glRotatef(tilt2, 1, 0, 0);
6710 if (!skeleton.free) {
6711 glRotatef(tilt, 0, 0, 1);
6714 glTranslatef(mid.x, mid.y, mid.z);
6716 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6717 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6719 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6720 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6722 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6723 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6725 if (playerdetail || skeleton.free == 3) {
6726 for (unsigned j = 0; j < skeleton.muscles[i].vertices.size(); j++) {
6727 XYZ& v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
6728 XYZ& v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
6729 glMatrixMode(GL_MODELVIEW);
6731 if (p1 == abdomen || p2 == abdomen) {
6732 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionbody.x,
6733 (v0.y * (1 - morphness) + v1.y * morphness) * proportionbody.y,
6734 (v0.z * (1 - morphness) + v1.z * morphness) * proportionbody.z);
6736 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) {
6737 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionarms.x,
6738 (v0.y * (1 - morphness) + v1.y * morphness) * proportionarms.y,
6739 (v0.z * (1 - morphness) + v1.z * morphness) * proportionarms.z);
6741 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) {
6742 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionlegs.x,
6743 (v0.y * (1 - morphness) + v1.y * morphness) * proportionlegs.y,
6744 (v0.z * (1 - morphness) + v1.z * morphness) * proportionlegs.z);
6746 if (p1 == head || p2 == head) {
6747 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionhead.x,
6748 (v0.y * (1 - morphness) + v1.y * morphness) * proportionhead.y,
6749 (v0.z * (1 - morphness) + v1.z * morphness) * proportionhead.z);
6751 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6752 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale;
6753 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale;
6754 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z = M[14] * scale;
6758 if (!playerdetail || skeleton.free == 3) {
6759 for (unsigned j = 0; j < skeleton.muscles[i].verticeslow.size(); j++) {
6760 XYZ& v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
6761 glMatrixMode(GL_MODELVIEW);
6763 if (p1 == abdomen || p2 == abdomen) {
6764 glTranslatef(v0.x * proportionbody.x,
6765 v0.y * proportionbody.y,
6766 v0.z * proportionbody.z);
6768 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) {
6769 glTranslatef(v0.x * proportionarms.x,
6770 v0.y * proportionarms.y,
6771 v0.z * proportionarms.z);
6773 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) {
6774 glTranslatef(v0.x * proportionlegs.x,
6775 v0.y * proportionlegs.y,
6776 v0.z * proportionlegs.z);
6778 if (p1 == head || p2 == head) {
6779 glTranslatef(v0.x * proportionhead.x,
6780 v0.y * proportionhead.y,
6781 v0.z * proportionhead.z);
6784 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6785 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
6786 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y = M[13] * scale;
6787 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z = M[14] * scale;
6793 if (skeleton.clothes && skeleton.muscles[i].verticesclothes.size() > 0) {
6794 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6796 glMatrixMode(GL_MODELVIEW);
6799 if (!skeleton.free) {
6800 glRotatef(tilt2, 1, 0, 0);
6802 if (!skeleton.free) {
6803 glRotatef(tilt, 0, 0, 1);
6805 glTranslatef(mid.x, mid.y, mid.z);
6806 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6807 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6809 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6810 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6812 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6813 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6815 for (unsigned j = 0; j < skeleton.muscles[i].verticesclothes.size(); j++) {
6816 XYZ& v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
6817 glMatrixMode(GL_MODELVIEW);
6819 if (p1 == abdomen || p2 == abdomen) {
6820 glTranslatef(v0.x * proportionbody.x,
6821 v0.y * proportionbody.y,
6822 v0.z * proportionbody.z);
6824 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) {
6825 glTranslatef(v0.x * proportionarms.x,
6826 v0.y * proportionarms.y,
6827 v0.z * proportionarms.z);
6829 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) {
6830 glTranslatef(v0.x * proportionlegs.x,
6831 v0.y * proportionlegs.y,
6832 v0.z * proportionlegs.z);
6834 if (p1 == head || p2 == head) {
6835 glTranslatef(v0.x * proportionhead.x,
6836 v0.y * proportionhead.y,
6837 v0.z * proportionhead.z);
6839 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6840 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
6841 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
6842 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z = M[14] * scale;
6847 updatedelay = 1 + (float)(Random() % 100) / 1000;
6849 if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) {
6850 normalsupdatedelay = 1;
6851 if (playerdetail || skeleton.free == 3) {
6852 skeleton.drawmodel.CalculateNormals(0);
6854 if (!playerdetail || skeleton.free == 3) {
6855 skeleton.drawmodellow.CalculateNormals(0);
6857 if (skeleton.clothes) {
6858 skeleton.drawmodelclothes.CalculateNormals(0);
6861 if (playerdetail || skeleton.free == 3) {
6862 skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
6864 if (!playerdetail || skeleton.free == 3) {
6865 skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
6867 if (skeleton.clothes) {
6868 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6873 updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1);
6874 if (updatedelaychange > -realmultiplier * 30) {
6875 updatedelaychange = -realmultiplier * 30;
6877 if (updatedelaychange > -framemult * 4) {
6878 updatedelaychange = -framemult * 4;
6880 if (skeleton.free == 1) {
6881 updatedelaychange *= 6;
6884 updatedelaychange *= 8;
6886 updatedelay += updatedelaychange;
6888 glMatrixMode(GL_MODELVIEW);
6890 glTranslatef(coords.x, coords.y - .02, coords.z);
6891 if (!skeleton.free) {
6892 glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
6893 glRotatef(yaw, 0, 1, 0);
6897 glColor4f(.4, 1, .4, 1);
6898 glDisable(GL_LIGHTING);
6899 glDisable(GL_TEXTURE_2D);
6902 for (int i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6903 XYZ& v0 = skeleton.drawmodel.vertex[i];
6904 glVertex3f(v0.x, v0.y, v0.z);
6911 for (unsigned int i = 0; i < skeleton.drawmodel.Triangles.size(); i++) {
6912 const XYZ& v0 = skeleton.drawmodel.getTriangleVertex(i, 0);
6913 const XYZ& v1 = skeleton.drawmodel.getTriangleVertex(i, 1);
6914 const XYZ& v2 = skeleton.drawmodel.getTriangleVertex(i, 2);
6915 glVertex3f(v0.x, v0.y, v0.z);
6916 glVertex3f(v1.x, v1.y, v1.z);
6917 glVertex3f(v1.x, v1.y, v1.z);
6918 glVertex3f(v2.x, v2.y, v2.z);
6919 glVertex3f(v2.x, v2.y, v2.z);
6920 glVertex3f(v0.x, v0.y, v0.z);
6927 terrainlight = terrain.getLighting(coords.x, coords.z);
6928 distance = distsq(&viewer, &coords);
6929 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
6934 terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1;
6935 if (terrainheight < 1) {
6938 if (terrainheight > 1.7) {
6939 terrainheight = 1.7;
6942 glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance);
6943 glDisable(GL_BLEND);
6944 glAlphaFunc(GL_GREATER, 0.0001);
6945 glEnable(GL_TEXTURE_2D);
6947 glDisable(GL_TEXTURE_2D);
6948 glColor4f(.7, .35, 0, .5);
6950 glEnable(GL_LIGHTING);
6953 if (Tutorial::active && id != 0) {
6954 glColor4f(.7, .7, .7, 0.6);
6956 glEnable(GL_LIGHTING);
6958 if (canattack && cananger) {
6959 if (Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed) {
6960 glDisable(GL_TEXTURE_2D);
6961 glColor4f(1, 0, 0, 0.8);
6964 glMatrixMode(GL_TEXTURE);
6966 glTranslatef(0, -smoketex, 0);
6967 glTranslatef(-smoketex, 0, 0);
6971 if (Tutorial::active && (id != 0)) {
6972 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6974 skeleton.drawmodel.draw();
6978 if (!playerdetail) {
6979 if (Tutorial::active && (id != 0)) {
6980 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6982 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6986 if (!(Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed)) {
6987 if (Tutorial::active && id != 0) {
6989 glMatrixMode(GL_MODELVIEW);
6990 glEnable(GL_TEXTURE_2D);
6991 glColor4f(.7, .7, .7, 0.6);
6993 glEnable(GL_LIGHTING);
6995 if (canattack && cananger) {
6996 if (Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed) {
6997 glDisable(GL_TEXTURE_2D);
6998 glColor4f(1, 0, 0, 0.8);
7001 glMatrixMode(GL_TEXTURE);
7003 glTranslatef(0, -smoketex * .6, 0);
7004 glTranslatef(smoketex * .6, 0, 0);
7007 if (Tutorial::active && (id != 0)) {
7008 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
7010 skeleton.drawmodel.draw();
7014 if (!playerdetail) {
7015 if (Tutorial::active && (id != 0)) {
7016 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
7018 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
7024 if (Tutorial::active && id != 0) {
7026 glMatrixMode(GL_MODELVIEW);
7027 glEnable(GL_TEXTURE_2D);
7029 if (skeleton.clothes) {
7033 skeleton.drawmodelclothes.draw();
7036 skeleton.drawmodelclothes.drawimmediate();
7043 if (num_weapons > 0) {
7044 for (k = 0; k < num_weapons; k++) {
7045 int i = weaponids[k];
7046 if (weaponactive == k) {
7047 if (weapons[i].getType() != staff) {
7048 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
7049 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].vertices.size() > 0) {
7050 weaponattachmuscle = j;
7053 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
7054 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) {
7055 weaponrotatemuscle = j;
7058 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
7059 if (creature == wolftype) {
7060 weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3);
7063 if (weapons[i].getType() == staff) {
7064 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
7065 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].vertices.size() > 0) {
7066 weaponattachmuscle = j;
7069 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
7070 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) {
7071 weaponrotatemuscle = j;
7074 //weaponpoint=jointPos(rightwrist);
7075 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
7076 //weaponpoint+=skeleton.specialforward[1]*.1+(jointPos(rightwrist)-jointPos(rightelbow));
7077 XYZ tempnormthing, vec1, vec2;
7078 vec1 = (jointPos(rightwrist) - jointPos(rightelbow));
7079 vec2 = (jointPos(rightwrist) - jointPos(rightshoulder));
7080 CrossProduct(&vec1, &vec2, &tempnormthing);
7081 Normalise(&tempnormthing);
7082 if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim) {
7083 weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow));
7087 if (weaponactive != k && weaponstuck != k) {
7088 if (weapons[i].getType() == knife) {
7089 weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35;
7091 if (weapons[i].getType() == sword) {
7092 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
7094 if (weapons[i].getType() == staff) {
7095 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
7097 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
7098 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) {
7099 weaponrotatemuscle = j;
7103 if (weaponstuck == k) {
7104 if (weaponstuckwhere == 0) {
7105 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8;
7107 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
7109 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
7110 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) {
7111 weaponrotatemuscle = j;
7115 if (skeleton.free) {
7116 weapons[i].position = weaponpoint * scale + coords;
7117 weapons[i].bigrotation = 0;
7118 weapons[i].bigtilt = 0;
7119 weapons[i].bigtilt2 = 0;
7121 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;
7122 weapons[i].bigrotation = yaw;
7123 weapons[i].bigtilt = tilt;
7124 weapons[i].bigtilt2 = tilt2;
7126 weapons[i].rotation1 = skeleton.muscles[weaponrotatemuscle].lastrotate1;
7127 weapons[i].rotation2 = skeleton.muscles[weaponrotatemuscle].lastrotate2;
7128 weapons[i].rotation3 = skeleton.muscles[weaponrotatemuscle].lastrotate3;
7129 if (weaponactive == k) {
7130 if (weapons[i].getType() == knife) {
7131 weapons[i].smallrotation = 180;
7132 weapons[i].smallrotation2 = 0;
7133 if (isCrouch() || wasCrouch()) {
7134 weapons[i].smallrotation2 = 20;
7136 if (animTarget == hurtidleanim) {
7137 weapons[i].smallrotation2 = 50;
7139 if ((animCurrent == crouchstabanim && animTarget == crouchstabanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
7140 XYZ temppoint1, temppoint2;
7143 temppoint1 = jointPos(righthand);
7144 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
7145 distance = findDistance(&temppoint1, &temppoint2);
7146 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
7147 weapons[i].rotation2 *= 360 / 6.28;
7150 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
7151 weapons[i].rotation1 *= 360 / 6.28;
7152 weapons[i].rotation3 = 0;
7153 weapons[i].smallrotation = -90;
7154 weapons[i].smallrotation2 = 0;
7155 if (temppoint1.x > temppoint2.x) {
7156 weapons[i].rotation1 = 360 - weapons[i].rotation1;
7159 if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) {
7160 XYZ temppoint1, temppoint2;
7163 temppoint1 = jointPos(righthand);
7164 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
7165 distance = findDistance(&temppoint1, &temppoint2);
7166 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
7167 weapons[i].rotation2 *= 360 / 6.28;
7170 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
7171 weapons[i].rotation1 *= 360 / 6.28;
7172 weapons[i].rotation3 = 0;
7173 weapons[i].smallrotation = 90;
7174 weapons[i].smallrotation2 = 0;
7175 if (temppoint1.x > temppoint2.x) {
7176 weapons[i].rotation1 = 360 - weapons[i].rotation1;
7179 if (animTarget == knifethrowanim) {
7180 weapons[i].smallrotation = 90;
7181 //weapons[i].smallrotation2=-90;
7182 weapons[i].smallrotation2 = 0;
7183 weapons[i].rotation1 = 0;
7184 weapons[i].rotation2 = 0;
7185 weapons[i].rotation3 = 0;
7187 if (animTarget == knifesneakattackanim && frameTarget < 5) {
7188 weapons[i].smallrotation = -90;
7189 weapons[i].rotation1 = 0;
7190 weapons[i].rotation2 = 0;
7191 weapons[i].rotation3 = 0;
7194 if (weapons[i].getType() == sword) {
7195 weapons[i].smallrotation = 0;
7196 weapons[i].smallrotation2 = 0;
7197 if (animTarget == knifethrowanim) {
7198 weapons[i].smallrotation = -90;
7199 weapons[i].smallrotation2 = 0;
7200 weapons[i].rotation1 = 0;
7201 weapons[i].rotation2 = 0;
7202 weapons[i].rotation3 = 0;
7204 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)) {
7205 XYZ temppoint1, temppoint2;
7208 temppoint1 = currentFrame().joints[skeleton.jointlabels[righthand]].position * (1 - target) + targetFrame().joints[skeleton.jointlabels[righthand]].position * (target); //jointPos(righthand);
7209 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
7210 distance = findDistance(&temppoint1, &temppoint2);
7211 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
7212 weapons[i].rotation2 *= 360 / 6.28;
7215 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
7216 weapons[i].rotation1 *= 360 / 6.28;
7217 weapons[i].rotation3 = 0;
7218 weapons[i].smallrotation = 90;
7219 weapons[i].smallrotation2 = 0;
7220 if (temppoint1.x > temppoint2.x) {
7221 weapons[i].rotation1 = 360 - weapons[i].rotation1;
7225 if (weapons[i].getType() == staff) {
7226 weapons[i].smallrotation = 100;
7227 weapons[i].smallrotation2 = 0;
7228 if ((animTarget == staffhitanim && animCurrent == staffhitanim) || (animTarget == staffhitreversedanim && animCurrent == staffhitreversedanim) || (animTarget == staffspinhitreversedanim && animCurrent == staffspinhitreversedanim) || (animTarget == staffgroundsmashanim && animCurrent == staffgroundsmashanim) || (animTarget == staffspinhitanim && animCurrent == staffspinhitanim)) {
7229 XYZ temppoint1, temppoint2;
7232 temppoint1 = currentFrame().joints[skeleton.jointlabels[righthand]].position * (1 - target) + targetFrame().joints[skeleton.jointlabels[righthand]].position * (target); //jointPos(righthand);
7233 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
7234 distance = findDistance(&temppoint1, &temppoint2);
7235 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
7236 weapons[i].rotation2 *= 360 / 6.28;
7239 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
7240 weapons[i].rotation1 *= 360 / 6.28;
7241 weapons[i].rotation3 = 0;
7242 weapons[i].smallrotation = 90;
7243 weapons[i].smallrotation2 = 0;
7244 if (temppoint1.x > temppoint2.x) {
7245 weapons[i].rotation1 = 360 - weapons[i].rotation1;
7250 if (weaponactive != k && weaponstuck != k) {
7251 if (weapons[i].getType() == knife) {
7252 weapons[i].smallrotation = -70;
7253 weapons[i].smallrotation2 = 10;
7255 if (weapons[i].getType() == sword) {
7256 weapons[i].smallrotation = -100;
7257 weapons[i].smallrotation2 = -8;
7259 if (weapons[i].getType() == staff) {
7260 weapons[i].smallrotation = -100;
7261 weapons[i].smallrotation2 = -8;
7264 if (weaponstuck == k) {
7265 if (weaponstuckwhere == 0) {
7266 weapons[i].smallrotation = 180;
7268 weapons[i].smallrotation = 0;
7270 weapons[i].smallrotation2 = 10;
7277 if (skeleton.free) {
7280 if (Animation::animations[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isWallJump()) {
7283 if (animCurrent != animTarget) {
7286 if (skeleton.free == 2) {
7295 int Person::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, Model* model)
7297 static float distance;
7298 static float olddistance;
7299 static int intersecting;
7300 static int firstintersecting;
7303 static XYZ start, end;
7304 static float slopethreshold = -.4;
7306 firstintersecting = -1;
7310 if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius) {
7314 *p1 = DoRotation(*p1, 0, -*rotate, 0);
7316 for (int i = 0; i < 4; i++) {
7317 for (unsigned int j = 0; j < model->Triangles.size(); j++) {
7318 if (model->Triangles[j].facenormal.y <= slopethreshold) {
7320 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)));
7321 if (distance < radius) {
7322 point = *p1 - model->Triangles[j].facenormal * distance;
7323 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]])) {
7326 if (!intersecting) {
7327 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
7328 &model->vertex[model->Triangles[j].vertex[1]],
7331 if (!intersecting) {
7332 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
7333 &model->vertex[model->Triangles[j].vertex[2]],
7336 if (!intersecting) {
7337 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
7338 &model->vertex[model->Triangles[j].vertex[2]],
7342 if (dotproduct(&model->Triangles[j].facenormal, &end) > 0 && intersecting) {
7346 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)) {
7347 p1->y = point.y + radius;
7348 if ((animTarget == jumpdownanim || isFlip())) {
7349 if (isFlip() && (frameTarget < 5 || targetFrame().label == 7 || targetFrame().label == 4)) {
7353 if (animTarget == jumpupanim) {
7355 animTarget = getIdle();
7362 pause_sound(whooshsound);
7363 OPENAL_SetVolume(channels[whooshsound], 0);
7366 if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) {
7370 animTarget = getLanding();
7371 emit_sound_at(landsound, coords, 128.);
7374 addEnvSound(coords);
7381 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
7382 olddistance = distance;
7383 firstintersecting = j;
7388 for (unsigned int j = 0; j < model->Triangles.size(); j++) {
7389 if (model->Triangles[j].facenormal.y > slopethreshold) {
7392 start.y -= radius / 4;
7393 XYZ& v0 = model->vertex[model->Triangles[j].vertex[0]];
7394 XYZ& v1 = model->vertex[model->Triangles[j].vertex[1]];
7395 XYZ& v2 = model->vertex[model->Triangles[j].vertex[2]];
7396 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)));
7397 if (distance < radius * .5) {
7398 point = start - model->Triangles[j].facenormal * distance;
7399 if (PointInTriangle(&point, model->Triangles[j].facenormal, &v0, &v1, &v2)) {
7402 if (!intersecting) {
7403 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
7405 if (!intersecting) {
7406 intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
7408 if (!intersecting) {
7409 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
7412 if (dotproduct(&model->Triangles[j].facenormal, &end) > 0 && intersecting) {
7413 if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
7415 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;
7416 if (findLengthfast(&start) < findLengthfast(&velocity)) {
7420 *p1 += model->Triangles[j].facenormal * (distance - radius * .5);
7423 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
7424 olddistance = distance;
7425 firstintersecting = j;
7432 *p = DoRotation(*p, 0, *rotate, 0);
7436 *p1 = DoRotation(*p1, 0, *rotate, 0);
7439 return firstintersecting;
7442 int findPathDist(int start, int end)
7447 unsigned int smallestcount = 1000;
7448 for (char i = 0; i < 50; i++) {
7449 unsigned int count = 0;
7454 while (last != end && count < 30) {
7456 for (int j = 0; j < Game::numpathpoints; j++) {
7457 if (j != last && j != last2 && j != last3 && j != last4) {
7459 if (Game::numpathpointconnect[j]) {
7460 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7461 if (Game::pathpointconnect[j][k] == last) {
7467 if (Game::numpathpointconnect[last]) {
7468 for (int k = 0; k < Game::numpathpointconnect[last]; k++) {
7469 if (Game::pathpointconnect[last][k] == j) {
7476 if (closest == -1 || Random() % 2 == 0) {
7488 if (count < smallestcount) {
7489 smallestcount = count;
7492 return smallestcount;
7495 void Person::takeWeapon(int weaponId)
7498 weapons[weaponId].owner = id;
7499 if (num_weapons > 0) {
7500 weaponids[num_weapons] = weaponids[0];
7503 weaponids[0] = weaponId;
7506 void Person::addClothes()
7508 if (numclothes > 0) {
7509 for (int i = 0; i < numclothes; i++) {
7516 bool Person::addClothes(const int& clothesId)
7519 const std::string fileName = clothes[clothesId];
7521 GLubyte* array = &skeleton.skinText[0];
7525 bool opened = load_image(Folders::getResourcePath(fileName).c_str(), texture);
7530 float tintr = clothestintr[clothesId];
7531 float tintg = clothestintg[clothesId];
7532 float tintb = clothestintb[clothesId];
7554 int bytesPerPixel = texture.bpp / 8;
7558 for (int i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) {
7559 if (bytesPerPixel == 3) {
7561 } else if ((i + 1) % 4 == 0) {
7562 alphanum = texture.data[i];
7564 if ((i + 1) % 4 || bytesPerPixel == 3) {
7566 texture.data[i] *= tintr;
7569 texture.data[i] *= tintg;
7572 texture.data[i] *= tintb;
7574 array[tempnum] = (float)array[tempnum] * (1 - alphanum / 255) + (float)texture.data[i] * (alphanum / 255);
7586 if (aitype != playercontrolled && !Dialog::inDialog()) {
7588 //disable movement in editor
7589 if (Game::editorenabled) {
7594 if (distsqflat(&Person::players[0]->coords, &coords) < 30 &&
7595 Person::players[0]->coords.y > coords.y + 2 &&
7596 !Person::players[0]->onterrain) {
7601 if (aitype == pathfindtype) {
7602 if (finalpathfindpoint == -1) {
7603 float closestdistance;
7608 closestdistance = -1;
7609 for (int j = 0; j < Game::numpathpoints; j++) {
7610 if (closest == -1 || distsq(&finalfinaltarget, &Game::pathpoint[j]) < closestdistance) {
7611 closestdistance = distsq(&finalfinaltarget, &Game::pathpoint[j]);
7613 finaltarget = Game::pathpoint[j];
7616 finalpathfindpoint = closest;
7617 for (int j = 0; j < Game::numpathpoints; j++) {
7618 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7619 DistancePointLine(&finalfinaltarget, &Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]], &tempdist, &colpoint);
7620 if (sq(tempdist) < closestdistance) {
7621 if (findDistance(&colpoint, &Game::pathpoint[j]) + findDistance(&colpoint, &Game::pathpoint[Game::pathpointconnect[j][k]]) <
7622 findDistance(&Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]]) + .1) {
7623 closestdistance = sq(tempdist);
7625 finaltarget = colpoint;
7630 finalpathfindpoint = closest;
7632 if (targetpathfindpoint == -1) {
7633 float closestdistance;
7638 closestdistance = -1;
7639 if (lastpathfindpoint == -1) {
7640 for (int j = 0; j < Game::numpathpoints; j++) {
7641 if (j != lastpathfindpoint) {
7642 if (closest == -1 || (distsq(&coords, &Game::pathpoint[j]) < closestdistance)) {
7643 closestdistance = distsq(&coords, &Game::pathpoint[j]);
7648 targetpathfindpoint = closest;
7649 for (int j = 0; j < Game::numpathpoints; j++) {
7650 if (j != lastpathfindpoint) {
7651 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7652 DistancePointLine(&coords, &Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]], &tempdist, &colpoint);
7653 if (sq(tempdist) < closestdistance) {
7654 if (findDistance(&colpoint, &Game::pathpoint[j]) + findDistance(&colpoint, &Game::pathpoint[Game::pathpointconnect[j][k]]) <
7655 findDistance(&Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]]) + .1) {
7656 closestdistance = sq(tempdist);
7663 targetpathfindpoint = closest;
7665 for (int j = 0; j < Game::numpathpoints; j++) {
7666 if (j != lastpathfindpoint &&
7667 j != lastpathfindpoint2 &&
7668 j != lastpathfindpoint3 &&
7669 j != lastpathfindpoint4) {
7671 if (Game::numpathpointconnect[j]) {
7672 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7673 if (Game::pathpointconnect[j][k] == lastpathfindpoint) {
7679 if (Game::numpathpointconnect[lastpathfindpoint]) {
7680 for (int k = 0; k < Game::numpathpointconnect[lastpathfindpoint]; k++) {
7681 if (Game::pathpointconnect[lastpathfindpoint][k] == j) {
7688 tempdist = findPathDist(j, finalpathfindpoint);
7689 if (closest == -1 || tempdist < closestdistance) {
7690 closestdistance = tempdist;
7696 targetpathfindpoint = closest;
7699 losupdatedelay -= multiplier;
7701 targetyaw = roughDirectionTo(coords, Game::pathpoint[targetpathfindpoint]);
7702 lookyaw = targetyaw;
7704 //reached target point
7705 if (distsqflat(&coords, &Game::pathpoint[targetpathfindpoint]) < .6) {
7706 lastpathfindpoint4 = lastpathfindpoint3;
7707 lastpathfindpoint3 = lastpathfindpoint2;
7708 lastpathfindpoint2 = lastpathfindpoint;
7709 lastpathfindpoint = targetpathfindpoint;
7710 if (lastpathfindpoint2 == -1) {
7711 lastpathfindpoint2 = lastpathfindpoint;
7713 if (lastpathfindpoint3 == -1) {
7714 lastpathfindpoint3 = lastpathfindpoint2;
7716 if (lastpathfindpoint4 == -1) {
7717 lastpathfindpoint4 = lastpathfindpoint3;
7719 targetpathfindpoint = -1;
7721 if (distsqflat(&coords, &finalfinaltarget) <
7722 distsqflat(&coords, &finaltarget) ||
7723 distsqflat(&coords, &finaltarget) < .6 * sq(scale * 5) ||
7724 lastpathfindpoint == finalpathfindpoint) {
7725 aitype = passivetype;
7736 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
7737 targetyaw += 90 * (whichdirection * 2 - 1);
7740 if (collided < 1 || animTarget != jumpupanim) {
7743 if ((collided > .8 && jumppower >= 5)) {
7747 if ((!Tutorial::active || cananger) &&
7749 !Person::players[0]->dead &&
7750 distsq(&coords, &Person::players[0]->coords) < 400 &&
7752 if (distsq(&coords, &Person::players[0]->coords) < 12 &&
7753 Animation::animations[Person::players[0]->animTarget].height != lowheight &&
7754 !Game::editorenabled &&
7755 (Person::players[0]->coords.y < coords.y + 5 || Person::players[0]->onterrain)) {
7756 aitype = attacktypecutoff;
7758 if (distsq(&coords, &Person::players[0]->coords) < 30 &&
7759 Animation::animations[Person::players[0]->animTarget].height == highheight &&
7760 !Game::editorenabled) {
7761 aitype = attacktypecutoff;
7764 if (losupdatedelay < 0 && !Game::editorenabled && occluded < 2) {
7765 losupdatedelay = .2;
7766 for (unsigned j = 0; j < Person::players.size(); j++) {
7767 if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) {
7768 if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) {
7769 if (distsq(&coords, &Person::players[j]->coords) < 400) {
7770 if (normaldotproduct(facing, Person::players[j]->coords - coords) > 0) {
7771 if (Person::players[j]->coords.y < coords.y + 5 || Person::players[j]->onterrain) {
7772 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) ||
7773 (Person::players[j]->animTarget == hanganim &&
7774 normaldotproduct(Person::players[j]->facing, coords - Person::players[j]->coords) < 0)) {
7775 aitype = searchtype;
7777 lastseen = Person::players[j]->coords;
7788 if (aitype == attacktypecutoff && Game::musictype != 2) {
7789 if (creature != wolftype) {
7796 if (aitype != passivetype && Game::leveltime > .5) {
7797 howactive = typeactive;
7800 if (aitype == passivetype) {
7801 aiupdatedelay -= multiplier;
7802 losupdatedelay -= multiplier;
7803 lastseentime += multiplier;
7804 pausetime -= multiplier;
7805 if (lastseentime > 1) {
7809 if (aiupdatedelay < 0) {
7810 if (numwaypoints > 1 && howactive == typeactive && pausetime <= 0) {
7811 targetyaw = roughDirectionTo(coords, waypoints[waypoint]);
7812 lookyaw = targetyaw;
7813 aiupdatedelay = .05;
7815 if (distsqflat(&coords, &waypoints[waypoint]) < 1) {
7816 if (waypointtype[waypoint] == wppause) {
7820 if (waypoint > numwaypoints - 1) {
7826 if (numwaypoints > 1 && howactive == typeactive && pausetime <= 0) {
7838 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
7839 if (!avoidsomething) {
7840 targetyaw += 90 * (whichdirection * 2 - 1);
7842 XYZ leftpos, rightpos;
7843 float leftdist, rightdist;
7844 leftpos = coords + DoRotation(facing, 0, 90, 0);
7845 rightpos = coords - DoRotation(facing, 0, 90, 0);
7846 leftdist = distsq(&leftpos, &avoidwhere);
7847 rightdist = distsq(&rightpos, &avoidwhere);
7848 if (leftdist < rightdist) {
7856 if (collided < 1 || animTarget != jumpupanim) {
7859 if ((collided > .8 && jumppower >= 5)) {
7864 if (!Game::editorenabled) {
7865 if (howactive <= typesleeping) {
7866 if (numenvsounds > 0 && (!Tutorial::active || cananger) && hostile) {
7867 for (int j = 0; j < numenvsounds; j++) {
7868 float vol = howactive == typesleeping ? envsoundvol[j] - 14 : envsoundvol[j];
7869 if (vol > 0 && distsq(&coords, &envsound[j]) < 2 * (vol + vol * (creature == rabbittype) * 3)) {
7870 aitype = attacktypecutoff;
7876 if (aitype != passivetype) {
7877 if (howactive == typesleeping) {
7878 setTargetAnimation(getupfromfrontanim);
7880 howactive = typeactive;
7884 if (howactive < typesleeping &&
7885 ((!Tutorial::active || cananger) && hostile) &&
7886 !Person::players[0]->dead &&
7887 distsq(&coords, &Person::players[0]->coords) < 400 &&
7889 if (distsq(&coords, &Person::players[0]->coords) < 12 &&
7890 Animation::animations[Person::players[0]->animTarget].height != lowheight && !Game::editorenabled) {
7891 aitype = attacktypecutoff;
7893 if (distsq(&coords, &Person::players[0]->coords) < 30 &&
7894 Animation::animations[Person::players[0]->animTarget].height == highheight && !Game::editorenabled) {
7895 aitype = attacktypecutoff;
7899 if (creature == wolftype) {
7901 for (unsigned j = 0; j < Person::players.size(); j++) {
7902 if (j == 0 || (Person::players[j]->dead && Person::players[j]->bloodloss > 0)) {
7903 float smelldistance = 50;
7904 if (j == 0 && Person::players[j]->num_weapons > 0) {
7905 if (weapons[Person::players[j]->weaponids[0]].bloody) {
7906 smelldistance = 100;
7908 if (Person::players[j]->num_weapons == 2) {
7909 if (weapons[Person::players[j]->weaponids[1]].bloody) {
7910 smelldistance = 100;
7915 smelldistance = 100;
7917 windsmell = windvector;
7918 Normalise(&windsmell);
7919 windsmell = windsmell * 2 + Person::players[j]->coords;
7920 if (distsq(&coords, &windsmell) < smelldistance && !Game::editorenabled) {
7921 aitype = attacktypecutoff;
7927 if (howactive < typesleeping && losupdatedelay < 0 && !Game::editorenabled && occluded < 2) {
7928 losupdatedelay = .2;
7929 for (unsigned j = 0; j < Person::players.size(); j++) {
7930 if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) {
7931 if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) {
7932 if (distsq(&coords, &Person::players[j]->coords) < 400) {
7933 if (normaldotproduct(facing, Person::players[j]->coords - coords) > 0) {
7934 if ((-1 == Object::checkcollide(
7935 DoRotation(jointPos(head), 0, yaw, 0) *
7938 DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0) *
7939 Person::players[j]->scale +
7940 Person::players[j]->coords) &&
7941 !Person::players[j]->isWallJump()) ||
7942 (Person::players[j]->animTarget == hanganim &&
7943 normaldotproduct(Person::players[j]->facing, coords - Person::players[j]->coords) < 0)) {
7945 if (j == 0 && Animation::animations[Person::players[j]->animTarget].height == lowheight) {
7954 if (lastseentime <= 0) {
7955 aitype = searchtype;
7957 lastseen = Person::players[j]->coords;
7965 if (aitype == attacktypecutoff && Game::musictype != 2) {
7966 if (creature != wolftype) {
7970 if (creature == wolftype) {
7980 if (aitype == searchtype) {
7981 aiupdatedelay -= multiplier;
7982 losupdatedelay -= multiplier;
7984 lastseentime -= multiplier;
7986 lastchecktime -= multiplier;
7988 if (isRun() && !onground) {
7989 if (coords.y > terrain.getHeight(coords.x, coords.z) + 10) {
7990 XYZ test2 = coords + facing;
7992 XYZ test = coords + facing;
7994 j = Object::checkcollide(test2, test, laststanding);
7996 j = Object::checkcollide(test2, test);
8000 setTargetAnimation(getStop());
8003 //aitype=passivetype;
8004 aitype = pathfindtype;
8005 finalfinaltarget = waypoints[waypoint];
8006 finalpathfindpoint = -1;
8007 targetpathfindpoint = -1;
8008 lastpathfindpoint = -1;
8009 lastpathfindpoint2 = -1;
8010 lastpathfindpoint3 = -1;
8011 lastpathfindpoint4 = -1;
8017 //check out last seen location
8018 if (aiupdatedelay < 0) {
8019 targetyaw = roughDirectionTo(coords, lastseen);
8020 lookyaw = targetyaw;
8021 aiupdatedelay = .05;
8024 if (distsqflat(&coords, &lastseen) < 1 * sq(scale * 5) || lastchecktime < 0) {
8027 lastseen.x += (float(Random() % 100) - 50) / 25;
8028 lastseen.z += (float(Random() % 100) - 50) / 25;
8039 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
8040 if (!avoidsomething) {
8041 targetyaw += 90 * (whichdirection * 2 - 1);
8043 XYZ leftpos, rightpos;
8044 float leftdist, rightdist;
8045 leftpos = coords + DoRotation(facing, 0, 90, 0);
8046 rightpos = coords - DoRotation(facing, 0, 90, 0);
8047 leftdist = distsq(&leftpos, &avoidwhere);
8048 rightdist = distsq(&rightpos, &avoidwhere);
8049 if (leftdist < rightdist) {
8057 if (collided < 1 || animTarget != jumpupanim) {
8060 if ((collided > .8 && jumppower >= 5)) {
8064 if (numenvsounds > 0 && ((!Tutorial::active || cananger) && hostile)) {
8065 for (int k = 0; k < numenvsounds; k++) {
8066 if (distsq(&coords, &envsound[k]) < 2 * (envsoundvol[k] + envsoundvol[k] * (creature == rabbittype) * 3)) {
8067 aitype = attacktypecutoff;
8072 if (!Person::players[0]->dead &&
8073 losupdatedelay < 0 &&
8074 !Game::editorenabled &&
8076 ((!Tutorial::active || cananger) && hostile)) {
8077 losupdatedelay = .2;
8078 if (distsq(&coords, &Person::players[0]->coords) < 4 && Animation::animations[animTarget].height != lowheight) {
8079 aitype = attacktypecutoff;
8082 if (abs(Random() % 2) || Animation::animations[animTarget].height != lowheight) {
8083 //TODO: factor out canSeePlayer()
8084 if (distsq(&coords, &Person::players[0]->coords) < 400) {
8085 if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) {
8086 if ((Object::checkcollide(
8087 DoRotation(jointPos(head), 0, yaw, 0) *
8090 DoRotation(Person::players[0]->jointPos(head), 0, Person::players[0]->yaw, 0) *
8091 Person::players[0]->scale +
8092 Person::players[0]->coords) == -1) ||
8093 (Person::players[0]->animTarget == hanganim && normaldotproduct(Person::players[0]->facing, coords - Person::players[0]->coords) < 0)) {
8094 /* //TODO: changed j to 0 on a whim, make sure this is correct
8095 (Person::players[j]->animTarget==hanganim&&normaldotproduct(
8096 Person::players[j]->facing,coords-Person::players[j]->coords)<0)
8098 aitype = attacktypecutoff;
8106 if (lastseentime < 0) {
8107 //aitype=passivetype;
8109 aitype = pathfindtype;
8110 finalfinaltarget = waypoints[waypoint];
8111 finalpathfindpoint = -1;
8112 targetpathfindpoint = -1;
8113 lastpathfindpoint = -1;
8114 lastpathfindpoint2 = -1;
8115 lastpathfindpoint3 = -1;
8116 lastpathfindpoint4 = -1;
8120 if (aitype != gethelptype) {
8124 //get help from buddies
8125 if (aitype == gethelptype) {
8126 runninghowlong += multiplier;
8127 aiupdatedelay -= multiplier;
8129 if (aiupdatedelay < 0 || ally == 0) {
8133 //TODO: factor out closest search somehow
8136 float closestdist = -1;
8137 for (unsigned k = 0; k < Person::players.size(); k++) {
8138 if ((k != id) && (k != 0) && !Person::players[k]->dead &&
8139 (Person::players[k]->howactive < typedead1) &&
8140 !Person::players[k]->skeleton.free &&
8141 (Person::players[k]->aitype == passivetype)) {
8142 float distance = distsq(&coords, &Person::players[k]->coords);
8143 if (closestdist == -1 || distance < closestdist) {
8144 closestdist = distance;
8149 if (closest != -1) {
8154 lastseen = Person::players[0]->coords;
8160 XYZ facing = coords;
8161 XYZ flatfacing = Person::players[ally]->coords;
8162 facing.y += jointPos(head).y * scale;
8163 flatfacing.y += Person::players[ally]->jointPos(head).y * Person::players[ally]->scale;
8164 if (-1 != Object::checkcollide(facing, flatfacing)) {
8168 //no available ally, run back to player
8170 Person::players[ally]->skeleton.free ||
8171 Person::players[ally]->aitype != passivetype ||
8172 lastseentime <= 0) {
8173 aitype = searchtype;
8179 targetyaw = roughDirectionTo(coords, Person::players[ally]->coords);
8180 lookyaw = targetyaw;
8181 aiupdatedelay = .05;
8184 if (distsqflat(&coords, &Person::players[ally]->coords) < 3) {
8185 aitype = searchtype;
8187 Person::players[ally]->aitype = searchtype;
8188 if (Person::players[ally]->lastseentime < lastseentime) {
8189 Person::players[ally]->lastseen = lastseen;
8190 Person::players[ally]->lastseentime = lastseentime;
8191 Person::players[ally]->lastchecktime = lastchecktime;
8195 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
8196 if (!avoidsomething) {
8197 targetyaw += 90 * (whichdirection * 2 - 1);
8199 XYZ leftpos, rightpos;
8200 float leftdist, rightdist;
8201 leftpos = coords + DoRotation(facing, 0, 90, 0);
8202 rightpos = coords - DoRotation(facing, 0, 90, 0);
8203 leftdist = distsq(&leftpos, &avoidwhere);
8204 rightdist = distsq(&rightpos, &avoidwhere);
8205 if (leftdist < rightdist) {
8220 if (collided < 1 || animTarget != jumpupanim) {
8223 if (collided > .8 && jumppower >= 5) {
8228 //retreiving a weapon on the ground
8229 if (aitype == getweapontype) {
8230 aiupdatedelay -= multiplier;
8231 lastchecktime -= multiplier;
8233 if (aiupdatedelay < 0) {
8239 float closestdist = -1;
8240 for (unsigned k = 0; k < weapons.size(); k++) {
8241 if (weapons[k].owner == -1) {
8242 float distance = distsq(&coords, &weapons[k].position);
8243 if (closestdist == -1 || distance < closestdist) {
8244 closestdist = distance;
8249 if (closest != -1) {
8258 if (!Person::players[0]->dead && ((!Tutorial::active || cananger) && hostile)) {
8259 if (ally < 0 || weaponactive != -1 || lastchecktime <= 0) {
8260 aitype = attacktypecutoff;
8264 if (!Person::players[0]->dead) {
8266 if (weapons[ally].owner != -1 ||
8267 distsq(&coords, &weapons[ally].position) > 16) {
8268 aitype = attacktypecutoff;
8271 //TODO: factor these out as moveToward()
8272 targetyaw = roughDirectionTo(coords, weapons[ally].position);
8273 lookyaw = targetyaw;
8274 aiupdatedelay = .05;
8277 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
8278 if (!avoidsomething) {
8279 targetyaw += 90 * (whichdirection * 2 - 1);
8281 XYZ leftpos, rightpos;
8282 float leftdist, rightdist;
8283 leftpos = coords + DoRotation(facing, 0, 90, 0);
8284 rightpos = coords - DoRotation(facing, 0, 90, 0);
8285 leftdist = distsq(&leftpos, &avoidwhere);
8286 rightdist = distsq(&rightpos, &avoidwhere);
8287 if (leftdist < rightdist) {
8303 if (animTarget != crouchremoveknifeanim &&
8304 animTarget != removeknifeanim) {
8305 throwtogglekeydown = 0;
8309 if (collided < 1 || animTarget != jumpupanim) {
8312 if ((collided > .8 && jumppower >= 5)) {
8317 if (aitype == attacktypecutoff) {
8318 aiupdatedelay -= multiplier;
8319 //dodge or reverse rabbit kicks, knife throws, flips
8320 if (damage < damagetolerance * 2 / 3) {
8321 if ((Person::players[0]->animTarget == rabbitkickanim ||
8322 Person::players[0]->animTarget == knifethrowanim ||
8323 (Person::players[0]->isFlip() &&
8324 normaldotproduct(Person::players[0]->facing, Person::players[0]->coords - coords) < 0)) &&
8325 !Person::players[0]->skeleton.free &&
8326 (aiupdatedelay < .1)) {
8331 if (Person::players[0]->animTarget != rabbitkickanim && Person::players[0]->weaponactive != -1) {
8332 if (weapons[Person::players[0]->weaponids[0]].getType() == knife) {
8333 if (isIdle() || isCrouch() || isRun() || isFlip()) {
8334 if (abs(Random() % 2) == 0) {
8335 setTargetAnimation(backhandspringanim);
8337 setTargetAnimation(rollanim);
8339 targetyaw += 90 * (abs(Random() % 2) * 2 - 1);
8342 if (animTarget == jumpupanim || animTarget == jumpdownanim) {
8343 setTargetAnimation(flipanim);
8348 aiupdatedelay = .02;
8351 //get confused by flips
8352 if (Person::players[0]->isFlip() &&
8353 !Person::players[0]->skeleton.free &&
8354 Person::players[0]->animTarget != walljumprightkickanim &&
8355 Person::players[0]->animTarget != walljumpleftkickanim) {
8356 if (distsq(&Person::players[0]->coords, &coords) < 25) {
8357 if ((1 - damage / damagetolerance) > .5) {
8362 //go for weapon on the ground
8363 if (wentforweapon < 3) {
8364 for (unsigned k = 0; k < weapons.size(); k++) {
8365 if (creature != wolftype) {
8366 if (num_weapons == 0 &&
8367 weapons[k].owner == -1 &&
8368 weapons[k].velocity.x == 0 &&
8369 weapons[k].velocity.z == 0 &&
8370 weapons[k].velocity.y == 0) {
8371 if (distsq(&coords, &weapons[k].position) < 16) {
8374 aitype = getweapontype;
8381 //dodge/reverse walljump kicks
8382 if (damage < damagetolerance / 2) {
8383 if (Animation::animations[animTarget].height != highheight) {
8384 if (damage < damagetolerance * .5 &&
8385 ((Person::players[0]->animTarget == walljumprightkickanim ||
8386 Person::players[0]->animTarget == walljumpleftkickanim) &&
8387 ((aiupdatedelay < .15 &&
8389 (aiupdatedelay < .08 &&
8390 difficulty != 2)))) {
8395 //walked off a ledge (?)
8396 if (isRun() && !onground) {
8397 if (coords.y > terrain.getHeight(coords.x, coords.z) + 10) {
8398 XYZ test2 = coords + facing;
8400 XYZ test = coords + facing;
8402 j = Object::checkcollide(test2, test, laststanding);
8404 j = Object::checkcollide(test2, test);
8408 setTargetAnimation(getStop());
8411 aitype = pathfindtype;
8412 finalfinaltarget = waypoints[waypoint];
8413 finalpathfindpoint = -1;
8414 targetpathfindpoint = -1;
8415 lastpathfindpoint = -1;
8416 lastpathfindpoint2 = -1;
8417 lastpathfindpoint3 = -1;
8418 lastpathfindpoint4 = -1;
8424 //lose sight of player in the air (?)
8425 if (Person::players[0]->coords.y > coords.y + 5 &&
8426 Animation::animations[Person::players[0]->animTarget].height != highheight &&
8427 !Person::players[0]->onterrain) {
8428 aitype = pathfindtype;
8429 finalfinaltarget = waypoints[waypoint];
8430 finalpathfindpoint = -1;
8431 targetpathfindpoint = -1;
8432 lastpathfindpoint = -1;
8433 lastpathfindpoint2 = -1;
8434 lastpathfindpoint3 = -1;
8435 lastpathfindpoint4 = -1;
8437 //it's time to think (?)
8438 if (aiupdatedelay < 0 &&
8439 !Animation::animations[animTarget].attack &&
8440 animTarget != staggerbackhighanim &&
8441 animTarget != staggerbackhardanim &&
8442 animTarget != backhandspringanim &&
8443 animTarget != dodgebackanim) {
8445 if (weaponactive == -1 && num_weapons > 0) {
8446 drawkeydown = Random() % 2;
8450 rabbitkickenabled = Random() % 2;
8452 XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity;
8453 XYZ targetpoint = Person::players[0]->coords;
8454 if (distsq(&Person::players[0]->coords, &coords) <
8455 distsq(&rotatetarget, &coords)) {
8456 targetpoint += Person::players[0]->velocity *
8457 findDistance(&Person::players[0]->coords, &coords) / findLength(&velocity);
8459 targetyaw = roughDirectionTo(coords, targetpoint);
8460 lookyaw = targetyaw;
8461 aiupdatedelay = .2 + fabs((float)(Random() % 100) / 1000);
8463 if (distsq(&coords, &Person::players[0]->coords) > 5 && (Person::players[0]->weaponactive == -1 || weaponactive != -1)) {
8465 } else if ((distsq(&coords, &Person::players[0]->coords) > 16 ||
8466 distsq(&coords, &Person::players[0]->coords) < 9) &&
8467 Person::players[0]->weaponactive != -1) {
8469 } else if (Random() % 6 == 0 || (creature == wolftype && Random() % 3 == 0)) {
8474 //chill out around the corpse
8475 if (Person::players[0]->dead) {
8477 if (Random() % 10 == 0) {
8480 if (Random() % 100 == 0) {
8481 aitype = pathfindtype;
8482 finalfinaltarget = waypoints[waypoint];
8483 finalpathfindpoint = -1;
8484 targetpathfindpoint = -1;
8485 lastpathfindpoint = -1;
8486 lastpathfindpoint2 = -1;
8487 lastpathfindpoint3 = -1;
8488 lastpathfindpoint4 = -1;
8497 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
8498 targetyaw += 90 * (whichdirection * 2 - 1);
8501 if (Random() % 2 == 0 || weaponactive != -1 || creature == wolftype) {
8506 if (isRun() && Random() % 6 && distsq(&coords, &Person::players[0]->coords) > 7) {
8511 if (aitype != playercontrolled &&
8516 for (unsigned j = 0; j < Person::players.size(); j++) {
8517 if (j != id && !Person::players[j]->skeleton.free &&
8518 Person::players[j]->hasvictim &&
8519 (Tutorial::active && reversaltrain ||
8520 Random() % 2 == 0 && difficulty == 2 ||
8521 Random() % 4 == 0 && difficulty == 1 ||
8522 Random() % 8 == 0 && difficulty == 0 ||
8523 Person::players[j]->lastattack2 == Person::players[j]->animTarget &&
8524 Person::players[j]->lastattack3 == Person::players[j]->animTarget &&
8525 (Random() % 2 == 0 || difficulty == 2) ||
8526 (isIdle() || isRun()) &&
8527 Person::players[j]->weaponactive != -1 ||
8528 Person::players[j]->animTarget == swordslashanim &&
8529 weaponactive != -1 ||
8530 Person::players[j]->animTarget == staffhitanim ||
8531 Person::players[j]->animTarget == staffspinhitanim)) {
8532 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 4 &&
8533 Person::players[j]->victim == Person::players[id] &&
8534 (Person::players[j]->animTarget == sweepanim ||
8535 Person::players[j]->animTarget == spinkickanim ||
8536 Person::players[j]->animTarget == staffhitanim ||
8537 Person::players[j]->animTarget == staffspinhitanim ||
8538 Person::players[j]->animTarget == winduppunchanim ||
8539 Person::players[j]->animTarget == upunchanim ||
8540 Person::players[j]->animTarget == wolfslapanim ||
8541 Person::players[j]->animTarget == knifeslashstartanim ||
8542 Person::players[j]->animTarget == swordslashanim &&
8543 (distsq(&Person::players[j]->coords, &coords) < 2 ||
8544 weaponactive != -1))) {
8554 Person::players[target]->Reverse();
8561 if (collided > .8 && jumppower >= 5 ||
8562 distsq(&coords, &Person::players[0]->coords) > 400 &&
8564 creature == rabbittype) {
8567 //TODO: why are we controlling the human?
8568 if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) {
8569 Person::players[0]->jumpkeydown = 0;
8571 if (Person::players[0]->animTarget == jumpdownanim &&
8572 distsq(&Person::players[0]->coords, &coords) < 40) {
8579 if (Tutorial::active) {
8585 XYZ facing = coords;
8586 XYZ flatfacing = Person::players[0]->coords;
8587 facing.y += jointPos(head).y * scale;
8588 flatfacing.y += Person::players[0]->jointPos(head).y * Person::players[0]->scale;
8589 if (occluded >= 2) {
8590 if (-1 != Object::checkcollide(facing, flatfacing)) {
8594 if (lastseentime <= 0 &&
8595 (creature != wolftype ||
8596 weaponstuck == -1)) {
8597 aitype = searchtype;
8599 lastseen = Person::players[0]->coords;
8608 if (Animation::animations[Person::players[0]->animTarget].height == highheight &&
8609 (aitype == attacktypecutoff ||
8610 aitype == searchtype)) {
8611 if (Person::players[0]->coords.y > terrain.getHeight(Person::players[0]->coords.x, Person::players[0]->coords.z) + 10) {
8612 XYZ test = Person::players[0]->coords;
8614 if (-1 == Object::checkcollide(Person::players[0]->coords, test)) {
8620 if (aitype == passivetype && !(numwaypoints > 1) ||
8622 pause && damage > superpermanentdamage) {
8641 XYZ flatfacing = DoRotation(facing, 0, yaw + 180, 0);
8642 facing = flatfacing;
8644 if (aitype == attacktypecutoff) {
8645 targetheadyaw = 180 - roughDirectionTo(coords, Person::players[0]->coords);
8646 targetheadpitch = pitchTo(coords, Person::players[0]->coords);
8647 } else if (howactive >= typesleeping) {
8648 targetheadyaw = targetyaw;
8649 targetheadpitch = 0;
8651 if (interestdelay <= 0) {
8652 interestdelay = .7 + (float)(abs(Random() % 100)) / 100;
8653 headtarget = coords;
8654 headtarget.x += (float)(abs(Random() % 200) - 100) / 100;
8655 headtarget.z += (float)(abs(Random() % 200) - 100) / 100;
8656 headtarget.y += (float)(abs(Random() % 200) - 100) / 300;
8657 headtarget += facing * 1.5;
8659 targetheadyaw = 180 - roughDirectionTo(coords, headtarget);
8660 targetheadpitch = pitchTo(coords, headtarget);