2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 #include "Objects/Person.hpp"
23 #include "Animation/Animation.hpp"
24 #include "Audio/Sounds.hpp"
25 #include "Audio/openal_wrapper.hpp"
27 #include "Level/Awards.hpp"
28 #include "Level/Dialog.hpp"
29 #include "Tutorial.hpp"
30 #include "Utils/Folders.hpp"
32 extern float multiplier;
33 extern Terrain terrain;
35 extern int environment;
37 extern FRUSTUM frustum;
39 extern float realmultiplier;
41 extern float slomodelay;
42 extern bool cellophane;
43 extern float texdetail;
44 extern float realtexdetail;
45 extern int bloodtoggle;
46 extern bool autoslomo;
47 extern float camerashake;
49 extern float viewdistance;
50 extern float blackout;
51 extern int difficulty;
52 extern bool decalstoggle;
53 extern float fadestart;
55 extern bool winfreeze;
56 extern bool showpoints;
57 extern bool immediate;
58 extern float smoketex;
59 extern bool reversaltrain;
60 extern bool canattack;
62 extern float damagedealt;
64 extern float hostiletime;
66 extern bool gamestarted;
68 extern XYZ envsound[30];
69 extern float envsoundvol[30];
70 extern int numenvsounds;
71 extern float envsoundlife[30];
73 extern XYZ windvector;
75 std::vector<std::shared_ptr<Person>> Person::players;
80 , animCurrent(bounceidleanim)
81 , animTarget(bounceidleanim)
88 , howactive(typeactive)
90 , superruntoggle(false)
124 , rabbitkickenabled(false)
137 , superpermanentdamage(0)
175 , normalsupdatedelay(0)
179 , forwardkeydown(false)
180 , forwardstogglekeydown(false)
181 , rightkeydown(false)
185 , jumptogglekeydown(false)
186 , crouchkeydown(false)
187 , crouchtogglekeydown(false)
189 , drawtogglekeydown(false)
190 , throwkeydown(false)
191 , throwtogglekeydown(false)
192 , attackkeydown(false)
214 , whichdirection(false)
215 , whichdirectiondelay(0)
216 , avoidsomething(false)
226 , lefthandmorphness(0)
227 , righthandmorphness(0)
231 , targetlefthandmorphness(0)
232 , targetrighthandmorphness(0)
233 , targetheadmorphness(1)
234 , targetchestmorphness(0)
235 , targettailmorphness(0)
236 , lefthandmorphstart(0)
237 , lefthandmorphend(0)
238 , righthandmorphstart(0)
239 , righthandmorphend(0)
249 , highreversaldelay(0)
250 , lowreversaldelay(0)
299 , weaponstuckwhere(0)
312 , finalpathfindpoint(0)
313 , targetpathfindpoint(0)
314 , lastpathfindpoint(0)
315 , lastpathfindpoint2(0)
316 , lastpathfindpoint3(0)
317 , lastpathfindpoint4(0)
337 , neckspurtparticledelay(0)
341 , rabbitkickragdoll(false)
343 , tempanimation("Tempanim", lowheight, neutral)
347 damagetolerance = PersonType::types[creature].defaultDamageTolerance;
348 setProportions(1, 1, 1, 1);
351 /* Read a person in tfile. Throws an error if it’s not valid */
352 Person::Person(FILE* tfile, int mapvers, unsigned i)
356 funpackf(tfile, "Bi Bi Bf Bf Bf Bi", &whichskin, &creature, &coords.x, &coords.y, &coords.z, &num_weapons);
358 funpackf(tfile, "Bi", &howactive);
360 howactive = typeactive;
363 funpackf(tfile, "Bf", &scale);
368 funpackf(tfile, "Bb", &immobile);
373 funpackf(tfile, "Bf", &yaw);
378 if (num_weapons < 0 || num_weapons > 5) {
379 throw InvalidPersonException();
381 if (num_weapons > 0 && num_weapons < 5) {
382 for (int j = 0; j < num_weapons; j++) {
383 weaponids[j] = weapons.size();
385 funpackf(tfile, "Bi", &type);
386 weapons.push_back(Weapon(type, id));
389 funpackf(tfile, "Bi", &numwaypoints);
390 for (int j = 0; j < numwaypoints; j++) {
391 funpackf(tfile, "Bf", &waypoints[j].x);
392 funpackf(tfile, "Bf", &waypoints[j].y);
393 funpackf(tfile, "Bf", &waypoints[j].z);
395 funpackf(tfile, "Bi", &waypointtype[j]);
397 waypointtype[j] = wpkeepwalking;
401 funpackf(tfile, "Bi", &waypoint);
402 if (waypoint > (numwaypoints - 1)) {
406 funpackf(tfile, "Bf Bf Bf", &armorhead, &armorhigh, &armorlow);
407 funpackf(tfile, "Bf Bf Bf", &protectionhead, &protectionhigh, &protectionlow);
408 funpackf(tfile, "Bf Bf Bf", &metalhead, &metalhigh, &metallow);
409 funpackf(tfile, "Bf Bf", &power, &speedmult);
412 funpackf(tfile, "Bf Bf Bf Bf", &proportions[0], &proportions[1], &proportions[2], &proportions[3]);
414 setProportions(1, 1, 1, 1);
417 funpackf(tfile, "Bi", &numclothes);
418 for (int k = 0; k < numclothes; k++) {
420 funpackf(tfile, "Bi", &templength);
421 for (int l = 0; l < templength; l++) {
422 funpackf(tfile, "Bb", &clothes[k][l]);
424 clothes[k][templength] = '\0';
425 funpackf(tfile, "Bf Bf Bf", &clothestintr[k], &clothestintg[k], &clothestintb[k]);
430 damagetolerance = PersonType::types[creature].defaultDamageTolerance;
433 scale = PersonType::types[creature].defaultScale;
437 realoldcoords = coords;
440 void Person::changeCreatureType(person_type type)
445 scale = PersonType::types[creature].defaultScale;
446 damagetolerance = PersonType::types[creature].defaultDamageTolerance;
449 void Person::skeletonLoad()
453 PersonType::types[creature].figureFileName,
454 PersonType::types[creature].lowFigureFileName,
455 PersonType::types[creature].clothesFileName,
456 PersonType::types[creature].modelFileNames[0],
457 PersonType::types[creature].modelFileNames[1],
458 PersonType::types[creature].modelFileNames[2],
459 PersonType::types[creature].modelFileNames[3],
460 PersonType::types[creature].modelFileNames[4],
461 PersonType::types[creature].modelFileNames[5],
462 PersonType::types[creature].modelFileNames[6],
463 PersonType::types[creature].lowModelFileName,
464 PersonType::types[creature].modelClothesFileName,
465 PersonType::types[creature].clothes);
467 skeleton.drawmodel.textureptr.load(PersonType::types[creature].skins[whichskin], 1, &skeleton.skinText[0], &skeleton.skinsize);
470 void Person::setProportions(float head, float body, float arms, float legs)
472 proportions[0] = head;
473 proportions[1] = body;
474 proportions[2] = arms;
475 proportions[3] = legs;
478 float Person::getProportion(int part) const
480 return proportions[part];
483 XYZ Person::getProportionXYZ(int part) const
485 XYZ prop = PersonType::types[creature].proportions[part] * proportions[part];
495 * GameTick/doPlayerCollisions
497 void Person::CheckKick()
499 if (!(hasvictim && (animTarget == rabbitkickanim && victim && victim != this->shared_from_this() && frameCurrent >= 2 && animCurrent == rabbitkickanim) && distsq(&coords, &victim->coords) < 1.2 && !victim->skeleton.free)) {
503 if (Animation::animations[victim->animTarget].height != lowheight) {
504 float damagemult = PersonType::types[creature].power * power * power;
505 XYZ relative = velocity;
507 Normalise(&relative);
511 if (!Tutorial::active) {
512 emit_sound_at(heavyimpactsound, victim->coords);
515 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
516 victim->skeleton.joints[i].velocity += relative * 120 * damagemult;
519 victim->DoDamage(100 * damagemult / victim->protectionhigh);
526 animTarget = backflipanim;
528 velocity = facing * -10;
532 resume_stream(whooshsound);
535 award_bonus(id, cannon);
536 } else if (victim->isCrouch()) {
537 animTarget = rabbitkickreversedanim;
538 animCurrent = rabbitkickreversedanim;
539 victim->animCurrent = rabbitkickreversalanim;
540 victim->animTarget = rabbitkickreversalanim;
546 victim->oldcoords = victim->coords;
547 coords = victim->coords;
548 victim->targetyaw = targetyaw;
549 victim->victim = this->shared_from_this();
556 * GameTick::doPlayerCollisions - spread fire between players
557 * GameTick::ProcessDevKeys - press f to ignite
558 * Person::DoStuff - spread fire from lit campfires and bushes
560 void Person::CatchFire()
562 XYZ flatfacing, flatvelocity;
564 for (int i = 0; i < 10; i++) {
565 howmany = fabs(Random() % (skeleton.joints.size()));
567 flatvelocity = skeleton.joints[howmany].velocity;
568 flatfacing = skeleton.joints[howmany].position * scale + coords;
570 flatvelocity = velocity;
571 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
573 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
578 emit_sound_at(firestartsound, coords);
580 emit_stream_at(stream_firesound, coords);
588 * idle animation for this creature (depending on status)
590 int Person::getIdle()
592 if (Dialog::inDialog() && (howactive == typeactive) && PersonType::types[creature].hasAnimTalkIdle()) {
593 return PersonType::types[creature].animTalkIdle;
595 if (hasvictim && (victim != this->shared_from_this())) {
596 if ((!victim->dead && victim->aitype != passivetype &&
597 victim->aitype != searchtype && aitype != passivetype && aitype != searchtype &&
598 victim->id < Person::players.size())) {
599 if ((isPlayerControlled() && (stunned <= 0) && !hasWeapon()) || pause) {
600 return PersonType::types[creature].animFightIdle;
602 if (isPlayerControlled() && (stunned <= 0) && hasWeapon()) {
603 if (weapons[weaponids[weaponactive]].getType() == knife) {
604 return knifefightidleanim;
606 if (weapons[weaponids[weaponactive]].getType() == sword && victim->hasWeapon()) {
607 return swordfightidlebothanim;
609 if (weapons[weaponids[weaponactive]].getType() == sword) {
610 return swordfightidleanim;
612 if (weapons[weaponids[weaponactive]].getType() == staff) {
613 return swordfightidleanim;
616 if (!isPlayerControlled() && (stunned <= 0) && creature != wolftype) {
617 return fightsidestep;
621 if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && PersonType::types[creature].hasAnimHurtIdle()) {
622 return PersonType::types[creature].animHurtIdle;
624 if (howactive == typesitting) {
627 if (howactive == typesittingwall) {
630 if (howactive == typesleeping) {
633 if (howactive == typedead1) {
636 if (howactive == typedead2) {
639 if (howactive == typedead3) {
642 if (howactive == typedead4) {
645 return PersonType::types[creature].animBounceIdle;
649 * crouch animation for this creature
651 int Person::getCrouch()
653 return PersonType::types[creature].animCrouch;
657 * running animation for this creature (can be upright or all fours)
661 if (superruntoggle && (!hasWeapon())) {
662 return PersonType::types[creature].animRunning;
664 return PersonType::types[creature].animRun;
670 int Person::getStop()
672 return PersonType::types[creature].animStop;
677 int Person::getLanding()
679 return PersonType::types[creature].animLanding;
684 int Person::getLandhard()
686 return PersonType::types[creature].animLandingHard;
692 * Person::DoAnimations
695 SolidHitBonus(int playerid)
697 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo) {
698 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
700 award_bonus(playerid, solidhit);
705 * spawns blood effects
707 void Person::DoBlood(float howmuch, int which)
709 // FIXME: should abstract out inputs
710 static int bleedxint, bleedyint;
712 if (bloodtoggle && !Tutorial::active) {
713 if (bleeding <= 0 && spurt) {
715 for (int i = 0; i < 3; i++) {
716 // emit blood particles
719 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
720 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
721 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
722 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
725 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
726 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
727 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
728 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
731 if (Random() % 2 == 0) { // 50% chance
732 for (int i = 0; i < 3; i++) {
733 if (Random() % 2 != 0) {
734 // emit teeth particles
737 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
738 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
741 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
742 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
746 Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
748 Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
750 Sprite::setLastSpriteSpecial(3); // sets it to teeth
756 // FIXME: manipulating attributes
757 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
760 while (PersonType::types[creature].bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || PersonType::types[creature].bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
761 bleedxint = abs(Random() % 512);
762 bleedyint = abs(Random() % 512);
766 bleedy /= realtexdetail;
767 bleedx /= realtexdetail;
768 direction = abs(Random() % 2) * 2 - 1;
777 * spawns big blood effects and ???
778 * modifies character's skin texture
780 void Person::DoBloodBig(float howmuch, int which)
782 static int bleedxint, bleedyint, i, j;
784 if (howmuch && id == 0) {
788 if (!Tutorial::active || id == 0) {
789 if (!isPlayerControlled() && howmuch > 0) {
793 if (creature == wolftype) {
794 int i = abs(Random() % 2);
796 whichsound = snarlsound;
799 whichsound = snarl2sound;
802 if (creature == rabbittype) {
803 int i = abs(Random() % 2);
805 whichsound = rabbitpainsound;
807 if (i == 1 && howmuch >= 2) {
808 whichsound = rabbitpain1sound;
812 if (whichsound != -1) {
813 emit_sound_at(whichsound, coords);
819 if (id == 0 && howmuch > 0) {
823 if (bloodtoggle && decalstoggle && !Tutorial::active) {
824 if (bleeding <= 0 && spurt) {
826 for (int i = 0; i < 3; i++) {
827 // emit blood particles
828 // FIXME: copypaste from above
831 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
832 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
833 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
834 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
837 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
838 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
839 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
840 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
845 // weird texture manipulation code follows.
846 // looks like this is painting blood onto the character's skin texture
847 // FIXME: surely there's a better way
849 int offsetx = 0, offsety = 0;
851 offsety = Random() % 40;
852 offsetx = abs(Random() % 60);
854 if (which == 190 || which == 185) {
855 offsety = Random() % 40;
856 offsetx = abs(Random() % 100) - 20;
859 offsety = Random() % 10;
860 offsetx = Random() % 10;
863 offsety = Random() % 20;
864 offsetx = Random() % 20;
866 if (which == 220 || which == 215) {
875 for (i = 0; i < 512; i++) {
876 for (j = 0; j < 512; j++) {
877 if (PersonType::types[creature].bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && PersonType::types[creature].bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
905 if (endx > 512 - 1) {
908 if (endy > 512 - 1) {
918 startx /= realtexdetail;
919 starty /= realtexdetail;
920 endx /= realtexdetail;
921 endy /= realtexdetail;
923 int texdetailint = realtexdetail;
925 for (i = startx; i < endx; i++) {
926 for (j = starty; j < endy; j++) {
927 if (PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
928 color = Random() % 85 + 170;
929 where = i * skeleton.skinsize * 3 + j * 3;
930 if (skeleton.skinText[where + 0] > color / 2) {
931 skeleton.skinText[where + 0] = color / 2;
933 skeleton.skinText[where + 1] = 0;
934 skeleton.skinText[where + 2] = 0;
938 skeleton.drawmodel.textureptr.bind();
943 while (PersonType::types[creature].bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || PersonType::types[creature].bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
944 bleedxint = abs(Random() % 512);
945 bleedyint = abs(Random() % 512);
947 bleedy = bleedxint + offsetx;
948 bleedx = bleedyint + offsety;
949 bleedy /= realtexdetail;
950 bleedx /= realtexdetail;
957 if (bleedx > skeleton.skinsize - 1) {
958 bleedx = skeleton.skinsize - 1;
960 if (bleedy > skeleton.skinsize - 1) {
961 bleedy = skeleton.skinsize - 1;
963 direction = abs(Random() % 2) * 2 - 1;
965 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
966 deathbleeding += bleeding;
967 bloodloss += bleeding * 3;
969 if (!Tutorial::active && !isPlayerControlled() && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
970 if (abs(Random() % 2) == 0) {
971 aitype = gethelptype;
974 aitype = attacktypecutoff;
984 * similar to DoBloodBig
986 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
990 static XYZ startpoint, endpoint, colpoint, movepoint;
991 static float rotationpoint;
993 static XYZ p1, p2, p3, p0;
996 float coordsx, coordsy;
999 if (bloodtoggle && decalstoggle && !Tutorial::active) {
1001 if (!skeleton.free) {
1002 where = DoRotation(where, 0, -yaw, 0);
1006 startpoint.y += 100;
1011 // ray testing for a tri in the character model
1012 whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
1013 if (whichtri != -1) {
1014 // low level geometry math
1016 p1 = skeleton.drawmodel.getTriangleVertex(whichtri, 0);
1017 p2 = skeleton.drawmodel.getTriangleVertex(whichtri, 1);
1018 p3 = skeleton.drawmodel.getTriangleVertex(whichtri, 2);
1020 bary.x = distsq(&p0, &p1);
1021 bary.y = distsq(&p0, &p2);
1022 bary.z = distsq(&p0, &p3);
1024 total = bary.x + bary.y + bary.z;
1029 bary.x = 1 - bary.x;
1030 bary.y = 1 - bary.y;
1031 bary.z = 1 - bary.z;
1033 total = bary.x + bary.y + bary.z;
1038 gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0];
1039 gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1];
1040 gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2];
1041 gyy.x = skeleton.drawmodel.Triangles[whichtri].gy[0];
1042 gyy.y = skeleton.drawmodel.Triangles[whichtri].gy[1];
1043 gyy.z = skeleton.drawmodel.Triangles[whichtri].gy[2];
1044 coordsx = skeleton.drawmodel.Triangles[whichtri].gx[0] * bary.x + skeleton.drawmodel.Triangles[whichtri].gx[1] * bary.y + skeleton.drawmodel.Triangles[whichtri].gx[2] * bary.z;
1045 coordsy = skeleton.drawmodel.Triangles[whichtri].gy[0] * bary.x + skeleton.drawmodel.Triangles[whichtri].gy[1] * bary.y + skeleton.drawmodel.Triangles[whichtri].gy[2] * bary.z;
1047 if (bleeding <= 0 && spurt) {
1049 for (int i = 0; i < 3; i++) {
1050 // emit blood particles
1051 // FIXME: more copypaste code
1053 if (skeleton.free) {
1054 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
1055 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
1056 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
1057 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
1060 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
1061 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
1062 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
1063 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
1068 // texture manipulation follows
1070 int offsetx = 0, offsety = 0;
1071 offsetx = (1 + coordsy) * 512 - 291;
1072 offsety = coordsx * 512 - 437;
1079 for (i = 0; i < 512; i++) {
1080 for (j = 0; j < 512; j++) {
1081 if (PersonType::types[creature].bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && PersonType::types[creature].bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
1108 if (endx > 512 - 1) {
1111 if (endy > 512 - 1) {
1114 if (endx < startx) {
1117 if (endy < starty) {
1121 startx /= realtexdetail;
1122 starty /= realtexdetail;
1123 endx /= realtexdetail;
1124 endy /= realtexdetail;
1126 int texdetailint = realtexdetail;
1128 for (i = startx; i < endx; i++) {
1129 for (j = starty; j < endy; j++) {
1130 if (PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
1131 color = Random() % 85 + 170;
1132 where = i * skeleton.skinsize * 3 + j * 3;
1133 if (skeleton.skinText[where + 0] > color / 2) {
1134 skeleton.skinText[where + 0] = color / 2;
1136 skeleton.skinText[where + 1] = 0;
1137 skeleton.skinText[where + 2] = 0;
1138 } else if (PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= 160 + 4 && PersonType::types[creature].bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= 160 - 4) {
1139 color = Random() % 85 + 170;
1140 where = i * skeleton.skinsize * 3 + j * 3;
1141 if (skeleton.skinText[where + 0] > color / 2) {
1142 skeleton.skinText[where + 0] = color / 2;
1144 skeleton.skinText[where + 1] = 0;
1145 skeleton.skinText[where + 2] = 0;
1149 skeleton.drawmodel.textureptr.bind();
1152 bleedy = (1 + coordsy) * 512;
1153 bleedx = coordsx * 512;
1154 bleedy /= realtexdetail;
1155 bleedx /= realtexdetail;
1162 if (bleedx > skeleton.skinsize - 1) {
1163 bleedx = skeleton.skinsize - 1;
1165 if (bleedy > skeleton.skinsize - 1) {
1166 bleedy = skeleton.skinsize - 1;
1168 direction = abs(Random() % 2) * 2 - 1;
1170 if (whichtri == -1) {
1174 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
1175 deathbleeding += bleeding;
1176 bloodloss += bleeding * 3;
1178 if (!Tutorial::active && !isPlayerControlled() && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
1179 if (abs(Random() % 2) == 0) {
1180 aitype = gethelptype;
1183 aitype = attacktypecutoff;
1194 * guessing this performs a reversal
1196 void Person::Reverse()
1198 if (!((victim->isPlayerControlled() || hostiletime > 1 || staggerdelay <= 0) && victim->animTarget != jumpupanim && victim->animTarget != jumpdownanim && (!Tutorial::active || cananger) && hostile)) {
1202 if (normaldotproduct(victim->facing, victim->coords - coords) > 0 && (victim->id != 0 || difficulty >= 2) && (creature != wolftype || victim->creature == wolftype)) {
1206 if (animTarget == sweepanim) {
1207 animTarget = sweepreversedanim;
1208 animCurrent = sweepreversedanim;
1209 victim->animCurrent = sweepreversalanim;
1210 victim->animTarget = sweepreversalanim;
1212 if (animTarget == spinkickanim) {
1213 animTarget = spinkickreversedanim;
1214 animCurrent = spinkickreversedanim;
1215 victim->animCurrent = spinkickreversalanim;
1216 victim->animTarget = spinkickreversalanim;
1218 if (animTarget == upunchanim || animTarget == rabbittacklinganim) {
1219 if (animTarget == rabbittacklinganim) {
1222 victim->frameCurrent = 6;
1223 victim->frameTarget = 7;
1225 animTarget = upunchreversedanim;
1226 animCurrent = upunchreversedanim;
1227 victim->animCurrent = upunchreversalanim;
1228 victim->animTarget = upunchreversalanim;
1230 if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
1231 if (victim->hasWeapon()) {
1232 victim->throwtogglekeydown = 1;
1233 XYZ tempVelocity = victim->velocity * .2;
1234 if (tempVelocity.x == 0) {
1235 tempVelocity.x = .1;
1237 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1238 victim->num_weapons--;
1239 if (victim->num_weapons) {
1240 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1241 if (victim->weaponstuck == victim->num_weapons) {
1242 victim->weaponstuck = 0;
1246 victim->weaponactive = -1;
1247 for (unsigned j = 0; j < Person::players.size(); j++) {
1248 Person::players[j]->wentforweapon = 0;
1252 animTarget = staffhitreversedanim;
1253 animCurrent = staffhitreversedanim;
1254 victim->animCurrent = staffhitreversalanim;
1255 victim->animTarget = staffhitreversalanim;
1257 if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
1258 if (victim->hasWeapon()) {
1259 victim->throwtogglekeydown = 1;
1260 XYZ tempVelocity = victim->velocity * .2;
1261 if (tempVelocity.x == 0) {
1262 tempVelocity.x = .1;
1264 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1265 victim->num_weapons--;
1266 if (victim->num_weapons) {
1267 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1268 if (victim->weaponstuck == victim->num_weapons) {
1269 victim->weaponstuck = 0;
1273 victim->weaponactive = -1;
1274 for (unsigned j = 0; j < Person::players.size(); j++) {
1275 Person::players[j]->wentforweapon = 0;
1278 animTarget = staffspinhitreversedanim;
1279 animCurrent = staffspinhitreversedanim;
1280 victim->animCurrent = staffspinhitreversalanim;
1281 victim->animTarget = staffspinhitreversalanim;
1283 if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
1284 if (victim->hasWeapon()) {
1285 victim->throwtogglekeydown = 1;
1286 XYZ tempVelocity = victim->velocity * .2;
1287 if (tempVelocity.x == 0) {
1288 tempVelocity.x = .1;
1290 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1291 victim->num_weapons--;
1292 if (victim->num_weapons) {
1293 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1294 if (victim->weaponstuck == victim->num_weapons) {
1295 victim->weaponstuck = 0;
1299 victim->weaponactive = -1;
1300 for (unsigned j = 0; j < Person::players.size(); j++) {
1301 Person::players[j]->wentforweapon = 0;
1304 animTarget = swordslashreversedanim;
1305 animCurrent = swordslashreversedanim;
1306 victim->animCurrent = swordslashreversalanim;
1307 victim->animTarget = swordslashreversalanim;
1309 if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
1310 if (victim->hasWeapon()) {
1311 victim->throwtogglekeydown = 1;
1312 XYZ tempVelocity = victim->velocity * .2;
1313 if (tempVelocity.x == 0) {
1314 tempVelocity.x = .1;
1316 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
1317 victim->num_weapons--;
1318 if (victim->num_weapons) {
1319 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1320 if (victim->weaponstuck == victim->num_weapons) {
1321 victim->weaponstuck = 0;
1325 victim->weaponactive = -1;
1326 for (unsigned j = 0; j < Person::players.size(); j++) {
1327 Person::players[j]->wentforweapon = 0;
1330 animTarget = knifeslashreversedanim;
1331 animCurrent = knifeslashreversedanim;
1332 victim->animCurrent = knifeslashreversalanim;
1333 victim->animTarget = knifeslashreversalanim;
1335 if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim) {
1336 victim->targettilt2 = targettilt2;
1337 victim->frameCurrent = frameCurrent;
1338 victim->frameTarget = frameTarget;
1339 victim->target = target;
1340 victim->velocity = 0;
1341 victim->oldcoords = victim->coords;
1342 victim->coords = coords;
1343 victim->targetyaw = targetyaw;
1344 victim->yaw = targetyaw;
1345 victim->victim = this->shared_from_this();
1347 if (animTarget == winduppunchanim) {
1348 animTarget = winduppunchblockedanim;
1349 victim->animTarget = blockhighleftanim;
1350 victim->frameTarget = 1;
1351 victim->target = .5;
1352 victim->victim = this->shared_from_this();
1353 victim->targetyaw = targetyaw + 180;
1355 if (animTarget == wolfslapanim) {
1356 animTarget = winduppunchblockedanim;
1357 victim->animTarget = blockhighleftanim;
1358 victim->frameTarget = 1;
1359 victim->target = .5;
1360 victim->victim = this->shared_from_this();
1361 victim->targetyaw = targetyaw + 180;
1363 if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->hasWeapon()) {
1364 animTarget = swordslashparriedanim;
1365 parriedrecently = .4;
1366 victim->parriedrecently = 0;
1367 victim->animTarget = swordslashparryanim;
1368 victim->frameTarget = 1;
1369 victim->target = .5;
1370 victim->victim = this->shared_from_this();
1371 victim->targetyaw = targetyaw + 180;
1373 if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
1374 if (victim->hasWeapon()) {
1375 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1376 if (weapons[victim->weaponids[0]].getType() == staff) {
1377 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1379 if (weapons[weaponids[0]].getType() == staff) {
1380 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1382 emit_sound_at(swordstaffsound, victim->coords);
1384 emit_sound_at(metalhitsound, victim->coords);
1388 victim->Puff(righthand);
1390 victim->frameTarget = 0;
1391 victim->animTarget = staggerbackhighanim;
1392 victim->targetyaw = targetyaw + 180;
1394 aim = DoRotation(facing, 0, 90, 0) * 21;
1396 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
1397 victim->num_weapons--;
1398 if (victim->num_weapons) {
1399 victim->weaponids[0] = victim->weaponids[num_weapons];
1400 if (victim->weaponstuck == victim->num_weapons) {
1401 victim->weaponstuck = 0;
1404 victim->weaponactive = -1;
1405 for (unsigned i = 0; i < Person::players.size(); i++) {
1406 Person::players[i]->wentforweapon = 0;
1410 if (abs(Random() % 20) == 0) {
1412 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1413 if (weapons[victim->weaponids[0]].getType() == staff) {
1414 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1416 if (weapons[weaponids[0]].getType() == staff) {
1417 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1420 emit_sound_at(swordstaffsound, coords);
1422 emit_sound_at(metalhitsound, coords);
1430 animTarget = staggerbackhighanim;
1431 targetyaw = targetyaw + 180;
1433 aim = DoRotation(facing, 0, 90, 0) * 21;
1435 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
1438 weaponids[0] = weaponids[num_weapons];
1439 if (weaponstuck == num_weapons) {
1444 for (unsigned i = 0; i < Person::players.size(); i++) {
1445 Person::players[i]->wentforweapon = 0;
1450 if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) {
1451 if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) {
1452 victim->animTarget = dodgebackanim;
1453 victim->frameTarget = 0;
1457 rotatetarget = coords - victim->coords;
1458 Normalise(&rotatetarget);
1459 victim->targetyaw = -asin(0 - rotatetarget.x);
1460 victim->targetyaw *= 360 / 6.28;
1461 if (rotatetarget.z < 0) {
1462 victim->targetyaw = 180 - victim->targetyaw;
1465 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1467 victim->lastattack3 = victim->lastattack2;
1468 victim->lastattack2 = victim->lastattack;
1469 victim->lastattack = victim->animTarget;
1471 victim->animTarget = sweepanim;
1472 victim->frameTarget = 0;
1476 rotatetarget = coords - victim->coords;
1477 Normalise(&rotatetarget);
1478 victim->targetyaw = -asin(0 - rotatetarget.x);
1479 victim->targetyaw *= 360 / 6.28;
1480 if (rotatetarget.z < 0) {
1481 victim->targetyaw = 180 - victim->targetyaw;
1484 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1486 victim->lastattack3 = victim->lastattack2;
1487 victim->lastattack2 = victim->lastattack;
1488 victim->lastattack = victim->animTarget;
1494 victim->velocity = 0;
1496 if (!isPlayerControlled()) {
1498 if (escapednum < 2) {
1499 int chances = ((difficulty == 2) ? 3 : ((difficulty == 1) ? 5 : 10));
1500 if ((Random() % chances) == 0) {
1506 if (victim->id == 0 && Animation::animations[victim->animTarget].attack == reversal) {
1514 void Person::DoDamage(float howmuch)
1518 damagetaken += howmuch / power;
1520 damagedealt += howmuch / power;
1524 if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo)) {
1529 if (!Tutorial::active) {
1530 damage += howmuch / power;
1531 permanentdamage += howmuch / 2 / power;
1532 superpermanentdamage += howmuch / 4 / power;
1535 if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2) {
1538 if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt) {
1543 camerashake += howmuch / 100;
1544 if ((howmuch > 50 && damage > damagetolerance / 2)) {
1545 blackout = damage / damagetolerance;
1553 if (aitype == passivetype && damage < damagetolerance && ((!Tutorial::active || cananger) && hostile)) {
1554 aitype = attacktypecutoff;
1556 if (!Tutorial::active && !isPlayerControlled() && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
1557 if (abs(Random() % 2) == 0) {
1558 aitype = gethelptype;
1561 aitype = attacktypecutoff;
1566 if (howmuch > damagetolerance * 50 && skeleton.free != 2) {
1569 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1570 if (skeleton.free) {
1571 flatvelocity2 = skeleton.joints[i].velocity;
1572 flatfacing2 = skeleton.joints[i].position * scale + coords;
1574 flatvelocity2 = velocity;
1575 flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
1577 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1578 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1579 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1580 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1581 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1582 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1585 emit_sound_at(splattersound, coords);
1590 if (!dead && creature == wolftype) {
1591 award_bonus(0, Wolfbonus);
1598 if (!Tutorial::active || id == 0) {
1599 if (speechdelay <= 0 && !dead && !isPlayerControlled()) {
1600 int whichsound = -1;
1602 if (creature == wolftype) {
1603 int i = abs(Random() % 2);
1605 whichsound = snarlsound;
1608 whichsound = snarl2sound;
1611 if (creature == rabbittype) {
1612 int i = abs(Random() % 2);
1614 whichsound = rabbitpainsound;
1616 if (i == 1 && damage > damagetolerance) {
1617 whichsound = rabbitpain1sound;
1621 if (whichsound != -1) {
1622 emit_sound_at(whichsound, coords);
1623 addEnvSound(coords);
1631 * calculate/animate head facing direction?
1633 void Person::DoHead()
1635 static XYZ rotatearound;
1637 static float lookspeed = 500;
1639 if (!freeze && !winfreeze) {
1642 targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100;
1643 targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100;
1645 while (targetheadyaw > 180) {
1646 targetheadyaw -= 360;
1648 while (targetheadyaw < -180) {
1649 targetheadyaw += 360;
1652 if (targetheadyaw > 160) {
1653 targetheadpitch = targetheadpitch * -1;
1655 if (targetheadyaw < -160) {
1656 targetheadpitch = targetheadpitch * -1;
1658 if (targetheadyaw > 160) {
1659 targetheadyaw = targetheadyaw - 180;
1661 if (targetheadyaw < -160) {
1662 targetheadyaw = targetheadyaw + 180;
1665 if (targetheadpitch > 120) {
1666 targetheadpitch = 120;
1668 if (targetheadpitch < -120) {
1669 targetheadpitch = -120;
1671 if (targetheadyaw > 120) {
1672 targetheadyaw = 120;
1674 if (targetheadyaw < -120) {
1675 targetheadyaw = -120;
1679 targetheadpitch = 0;
1682 if (targetheadyaw > 80) {
1685 if (targetheadyaw < -80) {
1686 targetheadyaw = -80;
1688 if (targetheadpitch > 50) {
1689 targetheadpitch = 50;
1691 if (targetheadpitch < -50) {
1692 targetheadpitch = -50;
1696 if (abs(headyaw - targetheadyaw) < multiplier * lookspeed) {
1697 headyaw = targetheadyaw;
1698 } else if (headyaw > targetheadyaw) {
1699 headyaw -= multiplier * lookspeed;
1700 } else if (headyaw < targetheadyaw) {
1701 headyaw += multiplier * lookspeed;
1704 if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2) {
1705 headpitch = targetheadpitch;
1706 } else if (headpitch > targetheadpitch) {
1707 headpitch -= multiplier * lookspeed / 2;
1708 } else if (headpitch < targetheadpitch) {
1709 headpitch += multiplier * lookspeed / 2;
1712 rotatearound = jointPos(neck);
1713 jointPos(head) = rotatearound + DoRotation(jointPos(head) - rotatearound, headpitch, 0, 0);
1717 if (animTarget != bounceidleanim && animTarget != fightidleanim && animTarget != wolfidle && animTarget != knifefightidleanim && animTarget != drawrightanim && animTarget != drawleftanim && animTarget != walkanim) {
1718 facing = DoRotation(facing, headpitch * .4, 0, 0);
1719 facing = DoRotation(facing, 0, headyaw * .4, 0);
1722 if (animTarget == bounceidleanim || animTarget == fightidleanim || animTarget == wolfidle || animTarget == knifefightidleanim || animTarget == drawrightanim || animTarget == drawleftanim) {
1723 facing = DoRotation(facing, headpitch * .8, 0, 0);
1724 facing = DoRotation(facing, 0, headyaw * .8, 0);
1727 if (animTarget == walkanim) {
1728 facing = DoRotation(facing, headpitch * .6, 0, 0);
1729 facing = DoRotation(facing, 0, headyaw * .6, 0);
1732 skeleton.specialforward[0] = facing;
1733 //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1734 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
1735 if (skeleton.muscles[i].visible && (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)) {
1736 skeleton.FindRotationMuscle(i, animTarget);
1743 * ragdolls character?
1745 void Person::RagDoll(bool checkcollision)
1750 if (!skeleton.free) {
1754 if (id == 0 && isFlip()) {
1762 facing = DoRotation(facing, 0, yaw, 0);
1764 skeleton.freetime = 0;
1766 skeleton.longdead = 0;
1769 skeleton.broken = 0;
1770 skeleton.spinny = 1;
1772 skeleton.freefall = 1;
1774 if (!isnormal(velocity.x)) {
1777 if (!isnormal(velocity.y)) {
1780 if (!isnormal(velocity.z)) {
1783 if (!isnormal(yaw)) {
1786 if (!isnormal(coords.x)) {
1789 if (!isnormal(tilt)) {
1792 if (!isnormal(tilt2)) {
1796 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1797 skeleton.joints[i].delay = 0;
1798 skeleton.joints[i].locked = 0;
1799 skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1800 if (!isnormal(skeleton.joints[i].position.x)) {
1801 skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0);
1803 if (!isnormal(skeleton.joints[i].position.x)) {
1804 skeleton.joints[i].position = coords;
1806 skeleton.joints[i].position.y += .1;
1807 skeleton.joints[i].oldposition = skeleton.joints[i].position;
1808 skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords;
1811 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1812 skeleton.joints[i].velocity = 0;
1813 skeleton.joints[i].velchange = 0;
1815 skeleton.DoConstraints(&coords, &scale);
1816 if (Animation::animations[animCurrent].height == lowheight || Animation::animations[animTarget].height == lowheight) {
1817 skeleton.DoConstraints(&coords, &scale);
1818 skeleton.DoConstraints(&coords, &scale);
1819 skeleton.DoConstraints(&coords, &scale);
1820 skeleton.DoConstraints(&coords, &scale);
1823 speed = targetFrame().speed * 2;
1824 if (currentFrame().speed > targetFrame().speed) {
1825 speed = currentFrame().speed * 2;
1828 speed = transspeed * 2;
1833 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1834 if ((Animation::animations[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && Animation::animations[animCurrent].height == Animation::animations[animTarget].height) {
1835 skeleton.joints[i].velocity = velocity / scale + facing * 5 + DoRotation(DoRotation(DoRotation((targetFrame().joints[i].position - currentFrame().joints[i].position) * speed, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1837 skeleton.joints[i].velocity = velocity / scale + facing * 5;
1839 change.x = (float)(Random() % 100) / 100;
1840 change.y = (float)(Random() % 100) / 100;
1841 change.z = (float)(Random() % 100) / 100;
1842 skeleton.joints[i].velocity += change;
1843 skeleton.joints[fabs(Random() % skeleton.joints.size())].velocity -= change;
1845 change.x = (float)(Random() % 100) / 100;
1846 change.y = (float)(Random() % 100) / 100;
1847 change.z = (float)(Random() % 100) / 100;
1848 skeleton.joints[i].velchange += change;
1849 skeleton.joints[fabs(Random() % skeleton.joints.size())].velchange -= change;
1852 if (checkcollision) {
1855 if (!skeleton.joints.empty()) {
1858 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
1859 average += skeleton.joints[j].position;
1861 average /= skeleton.joints.size();
1862 coords += average * scale;
1863 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
1864 skeleton.joints[j].position -= average;
1868 whichpatchx = coords.x / (terrain.size / subdivision * terrain.scale);
1869 whichpatchz = coords.z / (terrain.size / subdivision * terrain.scale);
1870 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
1871 i = terrain.patchobjects[whichpatchx][whichpatchz][l];
1874 if (SphereCheck(&lowpoint, 3, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw, &Object::objects[i]->model) != -1) {
1875 coords.x = lowpoint.x;
1876 coords.z = lowpoint.z;
1885 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
1886 velocity += skeleton.joints[i].velocity * scale;
1888 velocity /= skeleton.joints.size();
1891 if (Random() % 2 == 0) {
1892 if (hasWeapon() && animTarget != rabbitkickanim && num_weapons > 0) {
1893 weapons[weaponids[0]].drop(jointVel(righthand) * scale * -.3, jointVel(righthand) * scale);
1894 weapons[weaponids[0]].velocity.x += .01;
1897 weaponids[0] = weaponids[num_weapons];
1898 if (weaponstuck == num_weapons) {
1903 for (unsigned i = 0; i < Person::players.size(); i++) {
1904 Person::players[i]->wentforweapon = 0;
1909 animTarget = bounceidleanim;
1910 animCurrent = bounceidleanim;
1918 void Person::FootLand(bodypart whichfoot, float opacity)
1920 if ((whichfoot != leftfoot) && (whichfoot != rightfoot)) {
1921 cerr << "FootLand called on wrong bodypart" << endl;
1924 static XYZ terrainlight;
1925 static XYZ footvel, footpoint;
1926 if (opacity >= 1 || skiddelay <= 0) {
1929 footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords;
1930 if (distsq(&footpoint, &viewer)) {
1931 Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity);
1933 } else if (onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1934 footvel = velocity / 5;
1935 if (footvel.y < .8) {
1938 footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords;
1939 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1940 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1941 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) {
1942 if (environment == snowyenvironment) {
1943 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity);
1945 terrain.MakeDecal(footprintdecal, footpoint, .2, 1 * opacity, yaw);
1947 } else if (environment == grassyenvironment) {
1948 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity);
1949 } else if (environment == desertenvironment) {
1950 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity);
1952 terrain.MakeDecal(footprintdecal, footpoint, .2, .25 * opacity, yaw);
1956 } else if (isLanding() || (animTarget == jumpupanim) || isLandhard()) {
1957 footvel = velocity / 5;
1958 if (footvel.y < .8) {
1961 footpoint = DoRotation(jointPos(whichfoot), 0, yaw, 0) * scale + coords;
1962 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4) {
1963 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity);
1970 * make a puff effect at a body part (dust effect?)
1972 void Person::Puff(int whichlabel)
1974 static XYZ footvel, footpoint;
1977 footpoint = DoRotation(jointPos(whichlabel), 0, yaw, 0) * scale + coords;
1978 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .9, .3);
1982 * I think I added this in an attempt to clean up code
1984 void Person::setTargetAnimation(int animation)
1986 animTarget = animation;
1995 void Person::DoAnimations()
1997 if (!skeleton.free) {
1998 static float oldtarget;
2000 if (isIdle() && animCurrent != getIdle()) {
2001 normalsupdatedelay = 0;
2004 if (animTarget == tempanim || animCurrent == tempanim) {
2005 Animation::animations[tempanim] = tempanimation;
2007 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
2014 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc);
2015 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
2017 if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z)) {
2020 if (!crouchkeydown && velocity.y >= -15) {
2024 if ((animCurrent == jumpupanim || animTarget == jumpdownanim) /*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) {
2029 targfacing = DoRotation(targfacing, 0, targetyaw, 0);
2031 if (normaldotproduct(targfacing, velocity) >= -.3) {
2032 animTarget = flipanim;
2034 animTarget = backflipanim;
2036 crouchtogglekeydown = 1;
2045 if (Animation::animations[animTarget].attack != reversed) {
2048 if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) {
2049 crouchtogglekeydown = 0;
2050 if (isPlayerControlled()) {
2054 if (!crouchtogglekeydown && Animation::animations[animTarget].attack == reversed && isPlayerControlled() && (escapednum < 2 || reversaltrain)) {
2058 crouchtogglekeydown = 1;
2062 if (Animation::animations[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) {
2064 normalsupdatedelay = 0;
2069 if (animTarget == rollanim && frameTarget == 3 && onfire) {
2071 emit_sound_at(fireendsound, coords);
2072 pause_sound(stream_firesound);
2076 if (animTarget == rabbittacklinganim && frameTarget == 1) {
2077 if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0) {
2080 if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) {
2081 if (normaldotproduct(victim->facing, facing) > 0) {
2082 victim->animTarget = rabbittackledbackanim;
2084 victim->animTarget = rabbittackledfrontanim;
2086 victim->frameTarget = 2;
2089 victim->targetyaw = yaw;
2090 if (victim->aitype == gethelptype) {
2091 victim->DoDamage(victim->damagetolerance - victim->damage);
2093 if (PersonType::types[creature].hasClaws) {
2095 emit_sound_at(clawslicesound, victim->coords);
2097 victim->DoBloodBig(1 / victim->armorhead, 210);
2099 award_bonus(id, TackleBonus,
2100 victim->aitype == gethelptype ? 50 : 0);
2104 if (!drawtogglekeydown && drawkeydown && (!hasWeapon() || num_weapons == 1) && (targetFrame().label || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) {
2105 if (weapons[weaponids[0]].getType() == knife) {
2108 emit_sound_at(knifedrawsound, coords, 128);
2109 } else if (weaponactive == 0) {
2111 emit_sound_at(knifesheathesound, coords);
2114 drawtogglekeydown = 1;
2117 if (!Tutorial::active || id == 0) {
2118 if ((targetFrame().label && (targetFrame().label < 5 || targetFrame().label == 8))) {
2119 int whichsound = -1;
2121 if (terrain.getOpacity(coords.x, coords.z) < .2) {
2122 if (targetFrame().label == 1) {
2123 whichsound = footstepsound;
2125 whichsound = footstepsound2;
2127 if (targetFrame().label == 1) {
2128 FootLand(leftfoot, 1);
2130 if (targetFrame().label == 2) {
2131 FootLand(rightfoot, 1);
2133 if (targetFrame().label == 3 && isRun()) {
2134 FootLand(rightfoot, 1);
2135 FootLand(leftfoot, 1);
2138 if (terrain.getOpacity(coords.x, coords.z) >= .2) {
2139 if (targetFrame().label == 1) {
2140 whichsound = footstepsound3;
2142 whichsound = footstepsound4;
2147 if (targetFrame().label == 1) {
2148 whichsound = footstepsound3;
2150 whichsound = footstepsound4;
2153 if (targetFrame().label == 4 && (!hasWeapon() || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
2154 if (Animation::animations[animTarget].attack != neutral) {
2155 unsigned r = abs(Random() % 3);
2157 whichsound = lowwhooshsound;
2160 whichsound = midwhooshsound;
2163 whichsound = highwhooshsound;
2166 if (Animation::animations[animTarget].attack == neutral) {
2167 whichsound = movewhooshsound;
2169 } else if (targetFrame().label == 4) {
2170 whichsound = knifeswishsound;
2172 if (targetFrame().label == 8 && !Tutorial::active) {
2173 whichsound = landsound2;
2176 if (whichsound != -1) {
2177 emit_sound_at(whichsound, coords, 256.);
2180 if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
2181 if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim) {
2182 addEnvSound(coords, 15);
2184 addEnvSound(coords, 6);
2189 if (targetFrame().label == 3) {
2191 emit_sound_at(whichsound, coords, 128.);
2198 if (!Tutorial::active || id == 0) {
2199 if (speechdelay <= 0) {
2200 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) {
2201 if ((targetFrame().label && (targetFrame().label < 5 || targetFrame().label == 8))) {
2202 int whichsound = -1;
2203 if (targetFrame().label == 4 && !isPlayerControlled()) {
2204 if (Animation::animations[animTarget].attack != neutral) {
2205 unsigned r = abs(Random() % 4);
2206 whichsound = PersonType::types[creature].soundsAttack[r];
2211 if (whichsound != -1) {
2212 emit_sound_at(whichsound, coords);
2219 if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) {
2220 FootLand(leftfoot, 1);
2221 FootLand(rightfoot, 1);
2225 currentoffset = targetoffset;
2226 frameTarget = frameCurrent;
2227 animCurrent = animTarget;
2230 if (animCurrent == removeknifeanim && currentFrame().label == 5) {
2231 for (unsigned i = 0; i < weapons.size(); i++) {
2232 if (weapons[i].owner == -1) {
2233 if (distsqflat(&coords, &weapons[i].position) < 4 && !hasWeapon()) {
2234 if (distsq(&coords, &weapons[i].position) >= 1) {
2235 if (weapons[i].getType() != staff) {
2236 emit_sound_at(knifedrawsound, coords, 128.);
2246 if (animCurrent == crouchremoveknifeanim && currentFrame().label == 5) {
2247 for (unsigned i = 0; i < weapons.size(); i++) {
2248 bool willwork = true;
2249 if (weapons[i].owner != -1) {
2250 if (Person::players[weapons[i].owner]->weaponstuck != -1) {
2251 if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == int(i)) {
2252 if (Person::players[weapons[i].owner]->num_weapons > 1) {
2258 if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free)) {
2259 if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && !hasWeapon()) {
2260 if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
2261 bool fleshstuck = false;
2262 if (weapons[i].owner != -1) {
2263 if (victim->weaponstuck != -1) {
2264 if (victim->weaponids[victim->weaponstuck] == int(i)) {
2270 emit_sound_at(fleshstabremovesound, coords, 128.);
2272 if (weapons[i].getType() != staff) {
2273 emit_sound_at(knifedrawsound, coords, 128.);
2276 if (weapons[i].owner != -1) {
2277 victim = Person::players[weapons[i].owner];
2278 if (victim->num_weapons == 1) {
2279 victim->num_weapons = 0;
2281 victim->num_weapons = 1;
2284 //victim->weaponactive=-1;
2285 victim->skeleton.longdead = 0;
2286 victim->skeleton.free = 1;
2287 victim->skeleton.broken = 0;
2289 for (unsigned j = 0; j < victim->skeleton.joints.size(); j++) {
2290 victim->skeleton.joints[j].velchange = 0;
2291 victim->skeleton.joints[j].locked = 0;
2297 Normalise(&relative);
2298 XYZ footvel, footpoint;
2300 footpoint = weapons[i].position;
2301 if (victim->weaponstuck != -1) {
2302 if (victim->weaponids[victim->weaponstuck] == int(i)) {
2304 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2306 weapons[i].bloody = 2;
2307 weapons[i].blooddrip = 5;
2308 victim->weaponstuck = -1;
2311 if (victim->num_weapons > 0) {
2312 if (victim->weaponstuck != 0 && victim->weaponstuck != -1) {
2313 victim->weaponstuck = 0;
2315 if (victim->weaponids[0] == int(i)) {
2316 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
2320 victim->jointVel(abdomen) += relative * 6;
2321 victim->jointVel(neck) += relative * 6;
2322 victim->jointVel(rightshoulder) += relative * 6;
2323 victim->jointVel(leftshoulder) += relative * 6;
2332 if (animCurrent == drawleftanim && currentFrame().label == 5) {
2335 emit_sound_at(knifedrawsound, coords, 128.);
2336 } else if (weaponactive == 0) {
2338 if (num_weapons == 2) {
2340 buffer = weaponids[0];
2341 weaponids[0] = weaponids[1];
2342 weaponids[1] = buffer;
2344 emit_sound_at(knifesheathesound, coords, 128.);
2348 if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) {
2349 XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0);
2350 Normalise(&rotatetarget);
2351 targetyaw = -asin(0 - rotatetarget.x);
2352 targetyaw *= 360 / 6.28;
2353 if (rotatetarget.z < 0) {
2354 targetyaw = 180 - targetyaw;
2357 if (animTarget == walljumprightkickanim) {
2360 if (animTarget == walljumpleftkickanim) {
2367 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0)) {
2371 if (distsq(&victim->coords, &/*Person::players[i]->*/ coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1) {
2379 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) {
2380 animTarget = rabbittackleanim;
2382 emit_sound_at(jumpsound, coords);
2390 targetloc = velocity;
2391 Normalise(&targetloc);
2392 targetloc += coords;
2393 for (unsigned i = 0; i < Person::players.size(); i++) {
2395 if (distsq(&targetloc, &Person::players[i]->coords) < closestdist || closestdist == 0) {
2396 closestdist = distsq(&targetloc, &Person::players[i]->coords);
2401 if (closestid != -1) {
2402 if (closestdist < 5 && !Person::players[closestid]->dead && Animation::animations[Person::players[closestid]->animTarget].height != lowheight && Person::players[closestid]->animTarget != backhandspringanim) {
2404 victim = Person::players[closestid];
2405 coords = victim->coords;
2406 animCurrent = rabbittacklinganim;
2407 animTarget = rabbittacklinganim;
2411 if (coords.z != victim->coords.z || coords.x != victim->coords.x) {
2412 rotatetarget = coords - victim->coords;
2413 Normalise(&rotatetarget);
2414 targetyaw = -asin(0 - rotatetarget.x);
2415 targetyaw *= 360 / 6.28;
2416 if (rotatetarget.z < 0) {
2417 targetyaw = 180 - targetyaw;
2420 if (animTarget != rabbitrunninganim) {
2421 emit_sound_at(jumpsound, coords, 128.);
2428 float damagemult = PersonType::types[creature].power * power;
2430 damagemult /= victim->damagetolerance / 200;
2432 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)) {
2433 if (animCurrent == spinkickanim && currentFrame().label == 5) {
2434 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2439 if (Random() % 2 || PersonType::types[creature].hasClaws) {
2442 if (PersonType::types[creature].hasClaws) {
2446 if (!Tutorial::active) {
2447 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2449 if (PersonType::types[creature].hasClaws) {
2450 emit_sound_at(clawslicesound, victim->coords, 128.);
2452 victim->DoBloodBig(2 / victim->armorhead, 175);
2456 relative = victim->coords - coords;
2458 Normalise(&relative);
2459 relative = DoRotation(relative, 0, -90, 0);
2460 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2461 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2463 victim->jointVel(head) += relative * damagemult * 200;
2465 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2471 if (animCurrent == wolfslapanim && currentFrame().label == 5) {
2472 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2477 if (Random() % 2 || PersonType::types[creature].hasClaws) {
2479 if (PersonType::types[creature].hasClaws) {
2483 emit_sound_at(whooshhitsound, victim->coords);
2484 if (PersonType::types[creature].hasClaws) {
2485 emit_sound_at(clawslicesound, victim->coords, 128.);
2487 victim->DoBloodBig(2, 175);
2491 relative = victim->coords - coords;
2493 Normalise(&relative);
2495 Normalise(&relative);
2496 relative = DoRotation(relative, 0, 90, 0);
2497 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2498 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2500 victim->jointVel(head) += relative * damagemult * 100;
2502 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2506 if (animCurrent == walljumprightkickanim && currentFrame().label == 5) {
2507 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2514 if (!Tutorial::active) {
2515 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2517 if (PersonType::types[creature].hasClaws) {
2518 emit_sound_at(clawslicesound, victim->coords, 128.);
2520 victim->DoBloodBig(2 / victim->armorhead, 175);
2526 Normalise(&relative);
2527 relative = DoRotation(relative, 0, -90, 0);
2528 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2529 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2531 victim->jointVel(head) += relative * damagemult * 200;
2533 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2535 if (victim->damage > victim->damagetolerance) {
2536 award_bonus(id, style);
2543 if (animCurrent == walljumpleftkickanim && currentFrame().label == 5) {
2544 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2551 if (!Tutorial::active) {
2552 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2554 if (PersonType::types[creature].hasClaws) {
2555 emit_sound_at(clawslicesound, victim->coords, 128.);
2557 victim->DoBloodBig(2 / victim->armorhead, 175);
2563 Normalise(&relative);
2564 relative = DoRotation(relative, 0, 90, 0);
2565 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2566 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2568 victim->jointVel(head) += relative * damagemult * 200;
2570 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2572 if (victim->damage > victim->damagetolerance) {
2573 award_bonus(id, style);
2580 if (animCurrent == blockhighleftstrikeanim && currentFrame().label == 5) {
2581 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != lowheight) {
2590 emit_sound_at(whooshhitsound, victim->coords);
2593 relative = victim->coords - coords;
2595 Normalise(&relative);
2596 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2597 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
2599 victim->jointVel(head) += relative * damagemult * 100;
2601 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2605 if (animCurrent == killanim && currentFrame().label == 8) {
2606 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) {
2611 emit_sound_at(whooshhitsound, victim->coords, 128.);
2613 victim->skeleton.longdead = 0;
2614 victim->skeleton.free = 1;
2615 victim->skeleton.broken = 0;
2616 victim->skeleton.spinny = 1;
2618 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2619 victim->skeleton.joints[i].velchange = 0;
2620 victim->skeleton.joints[i].delay = 0;
2621 victim->skeleton.joints[i].locked = 0;
2622 //victim->skeleton.joints[i].velocity=0;
2628 Normalise(&relative);
2629 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2630 victim->skeleton.joints[i].velocity.y = relative.y * 10;
2631 victim->skeleton.joints[i].position.y += relative.y * .3;
2632 victim->skeleton.joints[i].oldposition.y += relative.y * .3;
2633 victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
2635 victim->Puff(abdomen);
2636 victim->jointVel(abdomen).y = relative.y * 400;
2640 if (animCurrent == killanim && currentFrame().label == 5) {
2641 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) {
2646 if (!Tutorial::active) {
2647 emit_sound_at(heavyimpactsound, coords, 128.);
2650 relative = victim->coords - coords;
2652 Normalise(&relative);
2653 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2654 victim->skeleton.joints[i].velocity += relative * damagemult * 90;
2656 victim->Puff(abdomen);
2657 if (victim->dead != 2 && victim->permanentdamage > victim->damagetolerance - 250 && autoslomo) {
2661 victim->DoDamage(damagemult * 500 / victim->protectionhigh);
2662 victim->jointVel(abdomen) += relative * damagemult * 300;
2666 if (animCurrent == dropkickanim && currentFrame().label == 7) {
2667 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) {
2672 if (!Tutorial::active) {
2673 emit_sound_at(thudsound, coords);
2676 victim->skeleton.longdead = 0;
2677 victim->skeleton.free = 1;
2678 victim->skeleton.broken = 0;
2679 victim->skeleton.spinny = 1;
2681 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2682 victim->skeleton.joints[i].velchange = 0;
2683 //victim->skeleton.joints[i].delay=0;
2684 victim->skeleton.joints[i].locked = 0;
2687 relative = victim->coords - coords;
2688 Normalise(&relative);
2690 Normalise(&relative);
2691 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2692 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2694 if (!victim->dead) {
2698 victim->Puff(abdomen);
2699 victim->DoDamage(damagemult * 20 / victim->protectionhigh);
2700 victim->jointVel(abdomen) += relative * damagemult * 200;
2702 if (!victim->dead) {
2708 if ((animCurrent == crouchstabanim || animCurrent == swordgroundstabanim) && currentFrame().label == 5) {
2711 if (!victim->skeleton.free) {
2717 terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360);
2718 emit_sound_at(knifesheathesound, coords, 128.);
2721 if (victim && hasvictim) {
2722 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2724 XYZ where, startpoint, endpoint, movepoint, colpoint;
2725 float rotationpoint;
2727 if (weapons[weaponids[weaponactive]].getType() == knife) {
2728 where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4);
2729 where -= victim->coords;
2730 if (!victim->skeleton.free) {
2731 where = DoRotation(where, 0, -victim->yaw, 0);
2735 startpoint.y += 100;
2739 if (weapons[weaponids[weaponactive]].getType() == sword) {
2740 where = weapons[weaponids[weaponactive]].position;
2741 where -= victim->coords;
2742 if (!victim->skeleton.free) {
2743 where = DoRotation(where, 0, -victim->yaw, 0);
2746 where = weapons[weaponids[weaponactive]].tippoint;
2747 where -= victim->coords;
2748 if (!victim->skeleton.free) {
2749 where = DoRotation(where, 0, -victim->yaw, 0);
2753 if (weapons[weaponids[weaponactive]].getType() == staff) {
2754 where = weapons[weaponids[weaponactive]].position;
2755 where -= victim->coords;
2756 if (!victim->skeleton.free) {
2757 where = DoRotation(where, 0, -victim->yaw, 0);
2760 where = weapons[weaponids[weaponactive]].tippoint;
2761 where -= victim->coords;
2762 if (!victim->skeleton.free) {
2763 where = DoRotation(where, 0, -victim->yaw, 0);
2769 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
2771 if (whichtri != -1) {
2772 if (victim->dead != 2) {
2773 victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2));
2774 if (!victim->dead) {
2775 award_bonus(id, FinishedBonus);
2779 weapons[weaponids[weaponactive]].bloody = 2;
2782 victim->skeleton.longdead = 0;
2783 victim->skeleton.free = 1;
2784 victim->skeleton.broken = 0;
2786 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2787 victim->skeleton.joints[i].velchange = 0;
2788 victim->skeleton.joints[i].locked = 0;
2789 //victim->skeleton.joints[i].velocity=0;
2791 emit_sound_at(fleshstabsound, coords, 128);
2793 if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) {
2794 weapons[weaponids[weaponactive]].blooddrip += 5;
2795 weapons[weaponids[weaponactive]].blooddripdelay = 0;
2797 if (whichtri == -1) {
2799 emit_sound_at(knifesheathesound, coords, 128.);
2805 if ((animCurrent == crouchstabanim || animCurrent == swordgroundstabanim) && currentFrame().label == 6) {
2807 emit_sound_at(knifedrawsound, coords, 128);
2810 if (victim && hasvictim) {
2811 XYZ footvel, footpoint;
2813 emit_sound_at(fleshstabremovesound, coords, 128.);
2816 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2818 if (weapons[weaponids[weaponactive]].getType() == sword) {
2819 XYZ where, startpoint, endpoint, movepoint;
2820 float rotationpoint;
2823 where = weapons[weaponids[weaponactive]].position;
2824 where -= victim->coords;
2825 if (!victim->skeleton.free) {
2826 where = DoRotation(where, 0, -victim->yaw, 0);
2829 where = weapons[weaponids[weaponactive]].tippoint;
2830 where -= victim->coords;
2831 if (!victim->skeleton.free) {
2832 where = DoRotation(where, 0, -victim->yaw, 0);
2838 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2839 footpoint += victim->coords;
2841 if (whichtri == -1) {
2842 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2845 if (weapons[weaponids[weaponactive]].getType() == staff) {
2846 XYZ where, startpoint, endpoint, movepoint;
2847 float rotationpoint;
2850 where = weapons[weaponids[weaponactive]].position;
2851 where -= victim->coords;
2852 if (!victim->skeleton.free) {
2853 where = DoRotation(where, 0, -victim->yaw, 0);
2856 where = weapons[weaponids[weaponactive]].tippoint;
2857 where -= victim->coords;
2858 if (!victim->skeleton.free) {
2859 where = DoRotation(where, 0, -victim->yaw, 0);
2865 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2866 footpoint += victim->coords;
2868 if (whichtri == -1) {
2869 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2872 hasvictim = victim->DoBloodBigWhere(2, 220, footpoint);
2874 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2875 victim->skeleton.longdead = 0;
2876 victim->skeleton.free = 1;
2877 victim->skeleton.broken = 0;
2879 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2880 victim->skeleton.joints[i].velchange = 0;
2881 victim->skeleton.joints[i].locked = 0;
2882 //victim->skeleton.joints[i].velocity=0;
2888 Normalise(&relative);
2889 //victim->Puff(abdomen);
2891 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2894 if (victim->bloodloss < victim->damagetolerance) {
2895 victim->bloodloss += 1000;
2899 victim->jointVel(abdomen) += relative * damagemult * 20;
2903 if (!hasvictim && onterrain) {
2904 weapons[weaponids[weaponactive]].bloody = 0;
2905 weapons[weaponids[weaponactive]].blooddrip = 0;
2909 if (animCurrent == upunchanim && currentFrame().label == 5) {
2910 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2919 if (!Tutorial::active) {
2920 emit_sound_at(heavyimpactsound, victim->coords, 128);
2925 relative = victim->coords - coords;
2927 Normalise(&relative);
2928 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2929 victim->skeleton.joints[i].velocity = relative * 30;
2931 victim->jointVel(head) += relative * damagemult * 150;
2933 victim->frameTarget = 0;
2934 victim->animTarget = staggerbackhardanim;
2935 victim->targetyaw = targetyaw + 180;
2937 victim->stunned = 1;
2940 victim->Puff(abdomen);
2941 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2947 if (animCurrent == winduppunchanim && currentFrame().label == 5) {
2948 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) {
2953 if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && Animation::animations[victim->animTarget].height != lowheight) {
2954 if (!Tutorial::active) {
2955 emit_sound_at(thudsound, victim->coords);
2957 } else if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && Animation::animations[victim->animTarget].height == lowheight) {
2958 if (!Tutorial::active) {
2959 emit_sound_at(whooshhitsound, victim->coords);
2962 if (!Tutorial::active) {
2963 emit_sound_at(heavyimpactsound, victim->coords);
2967 if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || Animation::animations[victim->animTarget].height == lowheight) {
2971 relative = victim->coords - coords;
2973 Normalise(&relative);
2975 Normalise(&relative);
2976 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
2977 victim->skeleton.joints[i].velocity = relative * 5;
2979 victim->jointVel(abdomen) += relative * damagemult * 400;
2981 victim->frameTarget = 0;
2982 victim->animTarget = staggerbackhardanim;
2983 victim->targetyaw = targetyaw + 180;
2985 victim->stunned = 1;
2987 victim->Puff(abdomen);
2988 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2994 if (animCurrent == blockhighleftanim && currentFrame().label == 5) {
2995 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2996 if (victim->id == 0) {
2999 emit_sound_at(landsound2, victim->coords);
3005 if (animCurrent == swordslashparryanim && currentFrame().label == 5) {
3006 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
3007 if (victim->id == 0) {
3012 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
3013 if (weapons[victim->weaponids[0]].getType() == staff) {
3014 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3016 if (weapons[weaponids[0]].getType() == staff) {
3017 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3020 emit_sound_at(swordstaffsound, victim->coords);
3022 emit_sound_at(metalhitsound, victim->coords);
3030 if (animCurrent == knifethrowanim && currentFrame().label == 5) {
3034 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);
3036 weapons[weaponids[0]].thrown(aim * 50);
3039 weaponids[0] = weaponids[num_weapons];
3045 if (animCurrent == knifeslashstartanim && currentFrame().label == 5) {
3047 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 && victim->animTarget != dodgebackanim && victim->animTarget != rollanim) {
3049 if (!Tutorial::active) {
3050 victim->DoBloodBig(1.5 / victim->armorhigh, 225);
3053 award_bonus(id, Slicebonus);
3054 if (!Tutorial::active) {
3055 emit_sound_at(knifeslicesound, victim->coords);
3057 //victim->jointVel(abdomen)+=relative*damagemult*200;
3058 if (Animation::animations[victim->animTarget].attack && (!victim->isPlayerControlled() || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
3059 if (victim->id != 0 || difficulty == 2) {
3060 victim->frameTarget = 0;
3061 victim->animTarget = staggerbackhardanim;
3062 victim->targetyaw = targetyaw + 180;
3066 victim->lowreversaldelay = 0;
3067 victim->highreversaldelay = 0;
3068 if (!isPlayerControlled()) {
3069 weaponmissdelay = .6;
3072 if (!Tutorial::active) {
3073 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3074 weapons[weaponids[weaponactive]].bloody = 1;
3076 weapons[weaponids[weaponactive]].blooddrip += 3;
3079 XYZ footvel, footpoint;
3081 if (skeleton.free) {
3082 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
3084 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
3086 if (Tutorial::active) {
3087 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .6, .3);
3090 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .6, .3);
3092 footvel = DoRotation(facing, 0, 90, 0) * .8;
3093 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3094 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3095 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3096 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3098 victim->DoDamage(damagemult * 0);
3102 if (animCurrent == swordslashanim && currentFrame().label == 5 && victim->animTarget != rollanim) {
3103 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) {
3104 if (!victim->hasWeapon() || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) {
3105 award_bonus(id, Slashbonus);
3107 if (!Tutorial::active) {
3108 if (normaldotproduct(victim->facing, victim->coords - coords) < 0) {
3109 victim->DoBloodBig(2 / victim->armorhigh, 190);
3111 victim->DoBloodBig(2 / victim->armorhigh, 185);
3113 victim->deathbleeding = 1;
3114 emit_sound_at(swordslicesound, victim->coords);
3115 victim->frameTarget = 0;
3116 victim->animTarget = staggerbackhardanim;
3117 victim->targetyaw = targetyaw + 180;
3119 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3120 weapons[weaponids[weaponactive]].bloody = 1;
3122 weapons[weaponids[weaponactive]].blooddrip += 3;
3124 float bloodlossamount;
3125 bloodlossamount = 200 + abs((float)(Random() % 40)) - 20;
3126 victim->bloodloss += bloodlossamount / victim->armorhigh;
3127 victim->DoDamage(damagemult * 0);
3129 XYZ footvel, footpoint;
3131 if (skeleton.free) {
3132 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
3134 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
3137 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3139 footvel = DoRotation(facing, 0, 90, 0) * .8;
3141 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3142 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3143 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3144 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3147 if (victim->hasWeapon()) {
3148 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
3149 if (weapons[victim->weaponids[0]].getType() == staff) {
3150 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3152 if (weapons[weaponids[0]].getType() == staff) {
3153 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
3156 emit_sound_at(swordstaffsound, victim->coords);
3158 emit_sound_at(metalhitsound, victim->coords);
3163 victim->Puff(righthand);
3165 victim->frameTarget = 0;
3166 victim->animTarget = staggerbackhighanim;
3167 victim->targetyaw = targetyaw + 180;
3169 aim = DoRotation(facing, 0, 90, 0) * 21;
3171 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
3172 victim->num_weapons--;
3173 if (victim->num_weapons) {
3174 victim->weaponids[0] = victim->weaponids[num_weapons];
3175 if (victim->weaponstuck == victim->num_weapons) {
3176 victim->weaponstuck = 0;
3179 victim->weaponactive = -1;
3180 for (unsigned i = 0; i < Person::players.size(); i++) {
3181 Person::players[i]->wentforweapon = 0;
3187 if (animCurrent == staffhitanim && currentFrame().label == 5 && victim->animTarget != rollanim) {
3188 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
3189 if (!Tutorial::active) {
3190 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 250;
3195 if (Random() % 2 || PersonType::types[creature].hasClaws) {
3198 emit_sound_at(staffheadsound, victim->coords);
3202 relative = victim->coords - coords;
3204 Normalise(&relative);
3205 relative = DoRotation(relative, 0, 90, 0);
3207 Normalise(&relative);
3208 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3209 victim->skeleton.joints[i].velocity += relative * damagemult * 60;
3211 victim->jointVel(head) += relative * damagemult * 230;
3212 victim->jointVel(neck) += relative * damagemult * 230;
3214 if (!Tutorial::active) {
3215 victim->DoDamage(damagemult * 120 / victim->protectionhigh);
3217 award_bonus(id, solidhit, 30);
3222 if (animCurrent == staffspinhitanim && currentFrame().label == 5 && victim->animTarget != rollanim) {
3223 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
3224 if (!Tutorial::active) {
3225 weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250;
3230 if (Random() % 2 || PersonType::types[creature].hasClaws) {
3233 emit_sound_at(staffheadsound, victim->coords);
3237 relative = victim->coords - coords;
3239 Normalise(&relative);
3240 relative = DoRotation(relative, 0, -90, 0);
3241 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3242 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3244 victim->jointVel(head) += relative * damagemult * 220;
3245 victim->jointVel(neck) += relative * damagemult * 220;
3247 if (!Tutorial::active) {
3248 victim->DoDamage(damagemult * 350 / victim->protectionhead);
3250 award_bonus(id, solidhit, 60);
3255 if (animCurrent == staffgroundsmashanim && currentFrame().label == 5) {
3256 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) {
3258 if (!Tutorial::active) {
3259 if (!victim->dead) {
3260 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500;
3265 if (Random() % 2 || PersonType::types[creature].hasClaws) {
3268 emit_sound_at(staffbodysound, victim->coords);
3270 victim->skeleton.longdead = 0;
3271 victim->skeleton.free = 1;
3272 victim->skeleton.broken = 0;
3274 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3275 victim->skeleton.joints[i].velchange = 0;
3276 victim->skeleton.joints[i].locked = 0;
3277 //victim->skeleton.joints[i].velocity=0;
3284 Normalise(&relative);
3285 if (!victim->dead) {
3286 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3287 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
3289 victim->jointVel(abdomen) += relative * damagemult * 40;
3292 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3293 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
3296 victim->Puff(abdomen);
3297 if (!Tutorial::active) {
3298 victim->DoDamage(damagemult * 100 / victim->protectionhigh);
3300 if (!victim->dead) {
3301 award_bonus(id, solidhit, 40);
3307 if (animCurrent == lowkickanim && currentFrame().label == 5) {
3308 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && Animation::animations[victim->animTarget].height != highheight) {
3314 relative = victim->coords - coords;
3316 Normalise(&relative);
3320 if (Animation::animations[victim->animTarget].height == lowheight) {
3326 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3327 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3329 victim->jointVel(head) += relative * damagemult * 200;
3330 if (!Tutorial::active) {
3331 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3334 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3335 if (victim->howactive == typesleeping) {
3336 victim->DoDamage(damagemult * 150 / victim->protectionhead);
3338 if (PersonType::types[creature].hasClaws) {
3339 emit_sound_at(clawslicesound, victim->coords, 128.);
3341 victim->DoBloodBig(2 / victim->armorhead, 175);
3344 if (victim->damage >= victim->damagetolerance) {
3347 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3348 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3350 victim->jointVel(abdomen) += relative * damagemult * 200;
3351 victim->frameTarget = 0;
3352 victim->animTarget = staggerbackhighanim;
3353 victim->targetyaw = targetyaw + 180;
3355 if (!Tutorial::active) {
3356 emit_sound_at(landsound2, victim->coords, 128.);
3358 victim->Puff(abdomen);
3359 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3360 if (PersonType::types[creature].hasClaws) {
3361 emit_sound_at(clawslicesound, victim->coords, 128.);
3363 victim->DoBloodBig(2 / victim->armorhigh, 170);
3369 if (animCurrent == sweepanim && currentFrame().label == 5) {
3370 if ((victim->animTarget != jumpupanim) &&
3371 (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) &&
3372 (victim != this->shared_from_this())) {
3377 if (!Tutorial::active) {
3378 emit_sound_at(landsound2, victim->coords, 128.);
3381 relative = victim->coords - coords;
3383 Normalise(&relative);
3385 if (Animation::animations[victim->animTarget].height == middleheight || Animation::animations[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
3388 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3389 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
3391 relative = DoRotation(relative, 0, -90, 0);
3393 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3394 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) {
3395 victim->skeleton.joints[i].velocity = relative * 80;
3398 victim->Puff(rightankle);
3399 victim->Puff(leftankle);
3400 victim->DoDamage(damagemult * 40 / victim->protectionlow);
3402 if (victim->damage >= victim->damagetolerance) {
3405 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3406 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3408 relative = DoRotation(relative, 0, -90, 0);
3409 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3410 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) {
3411 victim->skeleton.joints[i].velocity += relative * damagemult * 80;
3414 victim->jointVel(abdomen) += relative * damagemult * 200;
3415 victim->frameTarget = 0;
3416 victim->animTarget = staggerbackhighanim;
3417 victim->targetyaw = targetyaw + 180;
3419 if (!Tutorial::active) {
3420 emit_sound_at(landsound2, victim->coords, 128.);
3422 victim->Puff(abdomen);
3423 victim->DoDamage(damagemult * 30 / victim->protectionlow);
3430 if (Animation::animations[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) {
3431 if (animCurrent == spinkickreversalanim && currentFrame().label == 7) {
3440 if (!Tutorial::active) {
3441 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3443 if (PersonType::types[creature].hasClaws) {
3444 emit_sound_at(clawslicesound, victim->coords, 128);
3446 victim->DoBloodBig(2 / victim->armorhigh, 170);
3450 relative = victim->coords - oldcoords;
3452 Normalise(&relative);
3453 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3454 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3456 victim->jointVel(abdomen) += relative * damagemult * 200;
3457 victim->Puff(abdomen);
3458 victim->DoDamage(damagemult * 150 / victim->protectionhigh);
3460 award_bonus(id, Reversal);
3463 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && Animation::animations[animTarget].frames[frameCurrent].label == 5) {
3464 if (victim->hasWeapon() && victim->num_weapons > 0) {
3465 if (weapons[victim->weaponids[victim->weaponactive]].owner == int(victim->id)) {
3466 takeWeapon(victim->weaponids[victim->weaponactive]);
3467 victim->num_weapons--;
3468 if (victim->num_weapons > 0) {
3469 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
3471 victim->weaponactive = -1;
3476 if (animCurrent == staffhitreversalanim && currentFrame().label == 5) {
3485 emit_sound_at(whooshhitsound, victim->coords, 128.);
3488 relative = victim->coords - oldcoords;
3490 Normalise(&relative);
3491 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3492 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3494 victim->jointVel(abdomen) += relative * damagemult * 200;
3496 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3499 if (animCurrent == staffspinhitreversalanim && currentFrame().label == 7) {
3509 award_bonus(id, staffreversebonus);
3511 if (!Tutorial::active) {
3512 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3515 award_bonus(id, staffreversebonus); // Huh, again?
3518 relative = victim->coords - oldcoords;
3520 Normalise(&relative);
3521 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3522 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3524 victim->jointVel(abdomen) += relative * damagemult * 200;
3526 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3529 if (animCurrent == upunchreversalanim && currentFrame().label == 7) {
3535 Normalise(&relative);
3537 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3538 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3540 victim->jointVel(lefthand) *= .1;
3541 victim->jointVel(leftwrist) *= .2;
3542 victim->jointVel(leftelbow) *= .5;
3543 victim->jointVel(leftshoulder) *= .7;
3544 victim->jointVel(righthand) *= .1;
3545 victim->jointVel(rightwrist) *= .2;
3546 victim->jointVel(rightelbow) *= .5;
3547 victim->jointVel(rightshoulder) *= .7;
3549 victim->Puff(abdomen);
3550 victim->DoDamage(damagemult * 90 / victim->protectionhigh);
3552 award_bonus(id, Reversal);
3556 doslice = (weapons[weaponids[0]].getType() != staff);
3558 doslice = PersonType::types[creature].hasClaws;
3562 emit_sound_at(clawslicesound, victim->coords, 128.);
3564 victim->DoBloodBig(2 / victim->armorhigh, 175);
3566 victim->DoBloodBig(2 / victim->armorhigh, 225);
3567 emit_sound_at(knifeslicesound, victim->coords);
3568 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3569 weapons[weaponids[weaponactive]].bloody = 1;
3571 weapons[weaponids[weaponactive]].blooddrip += 3;
3576 if (animCurrent == swordslashreversalanim && currentFrame().label == 7) {
3582 Normalise(&relative);
3584 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3585 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3587 victim->jointVel(lefthand) *= .1 - 1;
3588 victim->jointVel(leftwrist) *= .2 - 1;
3589 victim->jointVel(leftelbow) *= .5 - 1;
3590 victim->jointVel(leftshoulder) *= .7 - 1;
3591 victim->jointVel(righthand) *= .1 - 1;
3592 victim->jointVel(rightwrist) *= .2 - 1;
3593 victim->jointVel(rightelbow) *= .5 - 1;
3594 victim->jointVel(rightshoulder) *= .7 - 1;
3596 award_bonus(id, swordreversebonus);
3599 if (hasvictim && animCurrent == knifeslashreversalanim && currentFrame().label == 7) {
3608 if (!Tutorial::active) {
3609 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3613 relative = victim->coords - oldcoords;
3615 Normalise(&relative);
3616 relative = DoRotation(relative, 0, -90, 0);
3617 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3618 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3620 victim->jointVel(abdomen) += relative * damagemult * 200;
3621 victim->Puff(abdomen);
3622 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3624 award_bonus(id, Reversal);
3627 if (hasvictim && animCurrent == sneakattackanim && currentFrame().label == 7) {
3630 victim->skeleton.spinny = 0;
3632 relative = facing * -1;
3634 Normalise(&relative);
3635 if (victim->id == 0) {
3638 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3639 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3641 victim->damage = victim->damagetolerance;
3642 victim->permanentdamage = victim->damagetolerance - 1;
3645 doslice = (weapons[weaponids[0]].getType() != staff);
3647 doslice = PersonType::types[creature].hasClaws;
3651 emit_sound_at(clawslicesound, victim->coords, 128.);
3653 victim->DoBloodBig(2, 175);
3655 victim->DoBloodBig(200, 225);
3656 emit_sound_at(knifeslicesound, victim->coords);
3658 weapons[weaponids[weaponactive]].bloody = 2;
3660 weapons[weaponids[weaponactive]].blooddrip += 5;
3663 award_bonus(id, spinecrusher);
3666 if (hasvictim && (animCurrent == knifefollowanim || animCurrent == knifesneakattackanim) && currentFrame().label == 5) {
3667 if (hasWeapon() && victim->bloodloss < victim->damagetolerance) {
3669 if (animTarget == knifefollowanim) {
3670 victim->DoBloodBig(200, 210);
3672 if (animTarget == knifesneakattackanim) {
3673 XYZ footvel, footpoint;
3675 footpoint = weapons[weaponids[0]].tippoint;
3677 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3679 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3680 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3681 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3682 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3683 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3684 victim->DoBloodBig(200, 195);
3685 award_bonus(id, tracheotomy);
3687 if (animTarget == knifefollowanim) {
3688 award_bonus(id, Stabbonus);
3689 XYZ footvel, footpoint;
3691 footpoint = weapons[weaponids[0]].tippoint;
3693 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3695 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3696 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3697 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3698 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3699 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3701 victim->bloodloss += 10000;
3702 victim->velocity = 0;
3703 emit_sound_at(fleshstabsound, victim->coords);
3705 weapons[weaponids[weaponactive]].bloody = 2;
3707 weapons[weaponids[weaponactive]].blooddrip += 5;
3711 if (hasvictim && (animCurrent == knifefollowanim || animCurrent == knifesneakattackanim) && currentFrame().label == 6) {
3713 victim->velocity = 0;
3714 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3715 victim->skeleton.joints[i].velocity = 0;
3717 if (animTarget == knifefollowanim) {
3719 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3720 victim->skeleton.joints[i].velocity = 0;
3723 if (hasWeapon() && Animation::animations[victim->animTarget].attack != reversal) {
3724 emit_sound_at(fleshstabremovesound, victim->coords);
3726 weapons[weaponids[weaponactive]].bloody = 2;
3728 weapons[weaponids[weaponactive]].blooddrip += 5;
3730 XYZ footvel, footpoint;
3732 footpoint = weapons[weaponids[0]].tippoint;
3734 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3736 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3737 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3738 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3739 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3740 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3744 if (hasvictim && (animCurrent == swordsneakattackanim) && currentFrame().label == 5) {
3745 if (hasWeapon() && victim->bloodloss < victim->damagetolerance) {
3746 award_bonus(id, backstab);
3750 XYZ footvel, footpoint;
3752 footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2;
3754 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3756 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3757 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3758 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3759 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 5, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3760 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3761 victim->DoBloodBig(200, 180);
3762 victim->DoBloodBig(200, 215);
3763 victim->bloodloss += 10000;
3764 victim->velocity = 0;
3765 emit_sound_at(fleshstabsound, victim->coords);
3767 weapons[weaponids[weaponactive]].bloody = 2;
3769 weapons[weaponids[weaponactive]].blooddrip += 5;
3773 if (hasvictim && animCurrent == swordsneakattackanim && currentFrame().label == 6) {
3775 victim->velocity = 0;
3776 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3777 victim->skeleton.joints[i].velocity = 0;
3780 emit_sound_at(fleshstabremovesound, victim->coords);
3782 weapons[weaponids[weaponactive]].bloody = 2;
3784 weapons[weaponids[weaponactive]].blooddrip += 5;
3786 XYZ footvel, footpoint;
3788 footpoint = weapons[weaponids[0]].tippoint;
3790 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3792 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3793 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3794 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3795 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3796 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3800 if (animCurrent == sweepreversalanim && currentFrame().label == 7) {
3810 if (!Tutorial::active) {
3811 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3816 doslice = (weapons[weaponids[0]].getType() != staff);
3818 doslice = PersonType::types[creature].hasClaws;
3822 emit_sound_at(clawslicesound, victim->coords, 128.);
3824 victim->DoBloodBig(2 / victim->armorhead, 175);
3826 victim->DoBloodBig(2 / victim->armorhead, 225);
3827 emit_sound_at(knifeslicesound, victim->coords);
3828 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody) {
3829 weapons[weaponids[weaponactive]].bloody = 1;
3831 weapons[weaponids[weaponactive]].blooddrip += 3;
3835 award_bonus(id, Reversal);
3840 relative = facing * -1;
3842 Normalise(&relative);
3843 relative = DoRotation(relative, 0, 90, 0);
3845 Normalise(&relative);
3846 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3847 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3849 victim->jointVel(head) += relative * damagemult * 200;
3850 if (victim->damage < victim->damagetolerance - 100) {
3851 victim->velocity = relative * 200;
3853 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3854 victim->velocity = 0;
3857 if (animCurrent == sweepreversalanim && ((currentFrame().label == 9 && victim->damage < victim->damagetolerance) || (currentFrame().label == 7 && victim->damage > victim->damagetolerance))) {
3861 relative = facing * -1;
3863 Normalise(&relative);
3864 relative = DoRotation(relative, 0, 90, 0);
3866 Normalise(&relative);
3867 for (unsigned i = 0; i < victim->skeleton.joints.size(); i++) {
3868 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3870 victim->jointVel(head) += relative * damagemult * 200;
3873 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim)) {
3874 if (victim->damage > victim->damagetolerance && bonus != reverseko) {
3875 award_bonus(id, reverseko);
3881 if (frameTarget >= int(Animation::animations[animCurrent].frames.size())) {
3884 animTarget = getIdle();
3885 FootLand(leftfoot, 1);
3886 FootLand(rightfoot, 1);
3888 if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) {
3889 animTarget = rollanim;
3891 emit_sound_at(movewhooshsound, coords, 128.);
3893 if (animCurrent == staggerbackhighanim) {
3894 animTarget = getIdle();
3896 if (animCurrent == staggerbackhardanim) {
3897 animTarget = getIdle();
3899 if (animCurrent == removeknifeanim) {
3900 animTarget = getIdle();
3902 if (animCurrent == crouchremoveknifeanim) {
3903 animTarget = getCrouch();
3905 if (animCurrent == backhandspringanim) {
3906 animTarget = getIdle();
3908 if (animCurrent == dodgebackanim) {
3909 animTarget = getIdle();
3911 if (animCurrent == drawleftanim) {
3912 animTarget = getIdle();
3914 if (animCurrent == drawrightanim || animCurrent == crouchdrawrightanim) {
3915 animTarget = getIdle();
3916 if (animCurrent == crouchdrawrightanim) {
3917 animTarget = getCrouch();
3921 emit_sound_at(knifedrawsound, coords, 128.);
3922 } else if (weaponactive == 0) {
3924 if (num_weapons == 2) {
3926 buffer = weaponids[0];
3927 weaponids[0] = weaponids[1];
3928 weaponids[1] = buffer;
3930 emit_sound_at(knifesheathesound, coords, 128.);
3933 if (animCurrent == rollanim) {
3934 animTarget = getCrouch();
3935 FootLand(leftfoot, 1);
3936 FootLand(rightfoot, 1);
3939 if (animTarget == walljumprightkickanim) {
3942 if (animTarget == walljumpleftkickanim) {
3945 animTarget = jumpdownanim;
3947 if (animCurrent == climbanim) {
3948 animTarget = getCrouch();
3950 coords += facing * .1;
3951 if (!isnormal(coords.x)) {
3962 if (animTarget == rabbitkickreversalanim) {
3963 animTarget = getCrouch();
3966 if (animTarget == jumpreversalanim) {
3967 animTarget = getCrouch();
3970 if (animTarget == walljumprightanim || animTarget == walljumpbackanim || animTarget == walljumpfrontanim) {
3971 if (attackkeydown && animTarget != walljumpfrontanim) {
3973 float closestdist = -1;
3975 if (Person::players.size() > 1) {
3976 for (unsigned i = 0; i < Person::players.size(); i++) {
3977 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3978 distance = distsq(&Person::players[i]->coords, &coords);
3979 if (closestdist == -1 || distance < closestdist) {
3980 closestdist = distance;
3986 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3987 victim = Person::players[closest];
3988 animTarget = walljumprightkickanim;
3990 XYZ rotatetarget = victim->coords - coords;
3991 Normalise(&rotatetarget);
3992 yaw = -asin(0 - rotatetarget.x);
3994 if (rotatetarget.z < 0) {
3997 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3998 velocity = (victim->coords - coords) * 4;
4003 if (animTarget == walljumpbackanim) {
4004 animTarget = backflipanim;
4006 velocity = facing * -8;
4009 resume_stream(whooshsound);
4012 if (animTarget == walljumprightanim) {
4013 animTarget = rightflipanim;
4017 velocity = DoRotation(facing, 0, 30, 0) * -8;
4020 if (animTarget == walljumpfrontanim) {
4021 animTarget = frontflipanim;
4025 velocity = facing * 8;
4029 resume_stream(whooshsound);
4032 if (animTarget == walljumpleftanim) {
4033 if (attackkeydown) {
4035 float closestdist = -1;
4037 if (Person::players.size() > 1) {
4038 for (unsigned i = 0; i < Person::players.size(); i++) {
4039 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
4040 distance = distsq(&Person::players[i]->coords, &coords);
4041 if (closestdist == -1 || distance < closestdist) {
4042 closestdist = distance;
4048 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
4049 victim = Person::players[closest];
4050 animTarget = walljumpleftkickanim;
4052 XYZ rotatetarget = victim->coords - coords;
4053 Normalise(&rotatetarget);
4054 yaw = -asin(0 - rotatetarget.x);
4056 if (rotatetarget.z < 0) {
4059 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
4060 velocity = (victim->coords - coords) * 4;
4065 if (animTarget != walljumpleftkickanim) {
4066 animTarget = leftflipanim;
4070 velocity = DoRotation(facing, 0, -30, 0) * -8;
4074 resume_stream(whooshsound);
4077 if (animTarget == sneakattackanim) {
4078 animCurrent = getCrouch();
4079 animTarget = getCrouch();
4086 transspeed = 1000000;
4087 targetheadyaw += 180;
4088 coords -= facing * .7;
4090 coords.y = terrain.getHeight(coords.x, coords.z);
4095 if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) {
4096 animTarget = getIdle();
4099 coords.y = terrain.getHeight(coords.x, coords.z);
4104 if (animCurrent == knifefollowanim) {
4105 animTarget = getIdle();
4108 if (Animation::animations[animTarget].attack == reversal && animCurrent != sneakattackanim && animCurrent != knifesneakattackanim && animCurrent != swordsneakattackanim && animCurrent != knifefollowanim) {
4109 float ycoords = oldcoords.y;
4110 animTarget = getStop();
4115 transspeed = 1000000;
4116 targetheadyaw += 180;
4117 if (!isnormal(coords.x)) {
4120 if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim) {
4121 oldcoords = coords + facing * .5;
4122 } else if (animCurrent == sweepreversalanim) {
4123 oldcoords = coords + facing * 1.1;
4124 } else if (animCurrent == upunchreversalanim) {
4125 oldcoords = coords + facing * 1.5;
4128 targetheadyaw += 180;
4131 } else if (animCurrent == knifeslashreversalanim) {
4132 oldcoords = coords + facing * .5;
4135 targetheadyaw += 90;
4138 } else if (animCurrent == staffspinhitreversalanim) {
4141 targetheadyaw += 180;
4146 oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z);
4148 oldcoords.y = ycoords;
4150 currentoffset = coords - oldcoords;
4156 if (animCurrent == knifesneakattackedanim || animCurrent == swordsneakattackedanim) {
4161 if (Animation::animations[animTarget].attack == reversed) {
4163 if (animTarget == sweepreversedanim) {
4166 animTarget = backhandspringanim;
4168 emit_sound_at(landsound, coords, 128);
4170 if (animCurrent == upunchreversedanim || animCurrent == swordslashreversedanim) {
4171 animTarget = rollanim;
4174 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
4175 coords.y = oldcoords.y;
4177 if (animCurrent == knifeslashreversedanim) {
4178 animTarget = rollanim;
4183 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
4184 coords.y = oldcoords.y;
4188 animTarget = jumpdownanim;
4191 animTarget = getIdle();
4193 if (wasLandhard()) {
4194 animTarget = getIdle();
4196 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
4197 animTarget = getIdle();
4199 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
4200 coords.y = oldcoords.y;
4201 //coords+=DoRotation(Animation::animations[animCurrent].offset,0,yaw,0)*scale;
4202 targetoffset.y = coords.y;
4204 targetoffset.y = terrain.getHeight(coords.x, coords.z);
4206 currentoffset = DoRotation(Animation::animations[animCurrent].offset * -1, 0, yaw, 0) * scale;
4207 currentoffset.y -= (coords.y - targetoffset.y);
4208 coords.y = targetoffset.y;
4210 normalsupdatedelay = 0;
4212 if (animCurrent == upunchanim) {
4213 animTarget = getStop();
4214 normalsupdatedelay = 0;
4217 if (animCurrent == rabbitkickanim && animTarget != backflipanim) {
4221 if (num_weapons > 0) {
4222 if (weapons[0].getType() == staff) {
4231 rabbitkickragdoll = 1;
4233 if (animCurrent == rabbitkickreversedanim) {
4239 skeleton.spinny = 0;
4240 SolidHitBonus(!id); // FIXME: tricky id
4244 animTarget = rollanim;
4247 pause_sound(whooshsound);
4252 if (animCurrent == rabbittackledbackanim || animCurrent == rabbittackledfrontanim) {
4256 skeleton.spinny = 0;
4258 if (animCurrent == jumpreversedanim) {
4264 skeleton.spinny = 0;
4265 SolidHitBonus(!id); // FIXME: tricky id
4269 animTarget = rollanim;
4270 coords += facing * 2;
4272 pause_sound(whooshsound);
4278 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) {
4279 animTarget = getupfromfrontanim;
4281 } else if (Animation::animations[animCurrent].attack == normalattack) {
4282 animTarget = getIdle();
4285 if (animCurrent == blockhighleftanim && !isPlayerControlled()) {
4286 animTarget = blockhighleftstrikeanim;
4288 if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) {
4289 animTarget = getIdle();
4292 if (animCurrent == spinkickanim && victim->skeleton.free) {
4293 if (creature == rabbittype) {
4294 animTarget = fightidleanim;
4300 if (isIdle() && !wasIdle()) {
4301 normalsupdatedelay = 0;
4304 if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) {
4305 animTarget = jumpdownanim;
4308 if (!skeleton.free) {
4310 if (!transspeed && Animation::animations[animTarget].attack != 2 && Animation::animations[animTarget].attack != 3) {
4311 if (!isRun() || !wasRun()) {
4312 if (targetFrame().speed > currentFrame().speed) {
4313 target += multiplier * targetFrame().speed * speed * 2;
4315 if (targetFrame().speed <= currentFrame().speed) {
4316 target += multiplier * currentFrame().speed * speed * 2;
4319 if (isRun() && wasRun()) {
4321 tempspeed = velspeed;
4322 if (tempspeed < 10 * speedmult) {
4323 tempspeed = 10 * speedmult;
4325 /* FIXME - mixed of target and current here, is that intended? */
4326 target += multiplier * Animation::animations[animTarget].frames[frameCurrent].speed * speed * 1.7 * tempspeed / (speed * 45 * scale);
4328 } else if (transspeed) {
4329 target += multiplier * transspeed * speed * 2;
4331 if (!isRun() || !wasRun()) {
4332 if (targetFrame().speed > currentFrame().speed) {
4333 target += multiplier * targetFrame().speed * 2;
4335 if (targetFrame().speed <= currentFrame().speed) {
4336 target += multiplier * currentFrame().speed * 2;
4341 if (animCurrent != animTarget) {
4342 target = (target + oldtarget) / 2;
4346 frameCurrent = frameTarget;
4350 if (frameCurrent >= int(Animation::animations[animCurrent].frames.size())) {
4351 frameCurrent = Animation::animations[animCurrent].frames.size() - 1;
4355 rot = targetrot * target;
4356 yaw += rot - oldrot;
4363 if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
4365 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4366 skeleton.joints[i].position = currentFrame().joints[i].position;
4369 skeleton.FindForwards();
4371 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4372 if (skeleton.muscles[i].visible) {
4373 skeleton.FindRotationMuscle(i, animTarget);
4376 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4377 if (skeleton.muscles[i].visible) {
4378 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100)) {
4379 skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4381 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100)) {
4382 skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4384 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100)) {
4385 skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4391 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4392 skeleton.joints[i].position = targetFrame().joints[i].position;
4395 skeleton.FindForwards();
4397 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4398 if (skeleton.muscles[i].visible) {
4399 skeleton.FindRotationMuscle(i, animTarget);
4402 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4403 if (skeleton.muscles[i].visible) {
4404 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100)) {
4405 skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4407 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100)) {
4408 skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4410 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100)) {
4411 skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4413 if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) {
4414 skeleton.muscles[i].newrotate3 -= 360;
4416 if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) {
4417 skeleton.muscles[i].newrotate3 += 360;
4419 if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) {
4420 skeleton.muscles[i].newrotate2 -= 360;
4422 if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) {
4423 skeleton.muscles[i].newrotate2 += 360;
4425 if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) {
4426 skeleton.muscles[i].newrotate1 -= 360;
4428 if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) {
4429 skeleton.muscles[i].newrotate1 += 360;
4435 oldanimCurrent = animCurrent;
4436 oldanimTarget = animTarget;
4437 oldframeTarget = frameTarget;
4438 oldframeCurrent = frameCurrent;
4440 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4441 skeleton.joints[i].velocity = (currentFrame().joints[i].position * (1 - target) + targetFrame().joints[i].position * target - skeleton.joints[i].position) / multiplier;
4442 skeleton.joints[i].position = currentFrame().joints[i].position * (1 - target) + targetFrame().joints[i].position * target;
4444 offset = currentoffset * (1 - target) + targetoffset * target;
4445 for (unsigned i = 0; i < skeleton.muscles.size(); i++) {
4446 if (skeleton.muscles[i].visible) {
4447 skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * target;
4448 skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * target;
4449 skeleton.muscles[i].rotate3 = skeleton.muscles[i].oldrotate3 * (1 - target) + skeleton.muscles[i].newrotate3 * target;
4454 if (isLanding() && landhard) {
4458 animTarget = getLandhard();
4471 void Person::DoStuff()
4473 static XYZ terrainnormal;
4474 static XYZ flatfacing;
4475 static XYZ flatvelocity;
4476 static float flatvelspeed;
4477 static int bloodsize;
4478 static int startx, starty, endx, endy;
4479 static GLubyte color;
4480 static XYZ bloodvel;
4482 onfiredelay -= multiplier;
4483 if (onfiredelay < 0 && onfire) {
4484 if (Random() % 2 == 0) {
4490 crouchkeydowntime += multiplier;
4491 if (!crouchkeydown) {
4492 crouchkeydowntime = 0;
4494 jumpkeydowntime += multiplier;
4495 if (!jumpkeydown && skeleton.free) {
4496 jumpkeydowntime = 0;
4499 if (hostile || damage > 0 || bloodloss > 0) {
4503 if (isIdle() || isRun()) {
4507 if (num_weapons == 1 && hasWeapon()) {
4512 blooddimamount -= multiplier * .3;
4514 speechdelay -= multiplier;
4515 texupdatedelay -= multiplier;
4516 interestdelay -= multiplier;
4517 flamedelay -= multiplier;
4518 parriedrecently -= multiplier;
4520 victim = this->shared_from_this();
4525 speed = 1.1 * speedmult;
4527 speed = 1.0 * speedmult;
4529 if (!skeleton.free) {
4530 rabbitkickragdoll = 0;
4535 if (id != 0 && (creature == rabbittype || difficulty != 2)) {
4538 if (id != 0 && creature == wolftype && difficulty == 2) {
4540 if (aitype != passivetype) {
4542 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) {
4549 if (animTarget == wolfrunninganim && !superruntoggle) {
4550 animTarget = getRun();
4554 if (!hasWeapon() && num_weapons > 0) {
4555 if (weapons[weaponids[0]].getType() == staff) {
4561 burnt += multiplier;
4566 OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3);
4568 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
4575 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc);
4576 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
4580 while (flamedelay < 0 && onfire) {
4582 int howmany = fabs(Random() % (skeleton.joints.size()));
4583 if (skeleton.free) {
4584 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4585 flatfacing = skeleton.joints[howmany].position * scale + coords;
4587 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4588 flatvelocity = (coords - oldcoords) / multiplier / 2;
4590 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
4593 while (flamedelay < 0 && !onfire && Tutorial::active && id != 0) {
4595 int howmany = fabs(Random() % (skeleton.joints.size()));
4596 if (skeleton.free) {
4597 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4598 flatfacing = skeleton.joints[howmany].position * scale + coords;
4600 flatvelocity = (coords - oldcoords) / multiplier / 2;
4601 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4603 Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
4607 bleeding -= multiplier * .3;
4608 if (bloodtoggle == 2) {
4609 skeleton.drawmodel.textureptr.bind();
4610 if ((bleeding <= 0) && (detail != 2)) {
4616 if (neckspurtamount > 0) {
4617 neckspurtamount -= multiplier;
4618 neckspurtdelay -= multiplier * 3;
4619 neckspurtparticledelay -= multiplier * 3;
4620 if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
4623 if (skeleton.free) {
4624 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
4625 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4626 Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5) * scale + coords, bloodvel, 1, 1, 1, .05, .9);
4628 bloodvel.z = 5 * neckspurtamount;
4629 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4630 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
4631 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, .9);
4633 neckspurtparticledelay = .05;
4635 if (neckspurtdelay < 0) {
4640 if (deathbleeding > 0 && dead != 2) {
4641 if (deathbleeding < 5) {
4642 bleeddelay -= deathbleeding * multiplier / 4;
4644 bleeddelay -= 5 * multiplier / 4;
4646 if (bleeddelay < 0 && bloodtoggle) {
4651 if (skeleton.free) {
4652 bloodvel += DoRotation(jointVel(abdomen), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
4653 Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4655 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
4656 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4660 bloodloss += deathbleeding * multiplier * 80;
4661 deathbleeding -= multiplier * 1.6;
4662 if (deathbleeding < 0) {
4665 if (bloodloss > damagetolerance && Animation::animations[animTarget].attack == neutral) {
4667 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
4668 weapons[weaponids[0]].velocity.x += .01;
4671 weaponids[0] = weaponids[num_weapons];
4672 if (weaponstuck == num_weapons) {
4677 for (unsigned i = 0; i < Person::players.size(); i++) {
4678 Person::players[i]->wentforweapon = 0;
4686 if (!dead && creature == wolftype) {
4687 award_bonus(0, Wolfbonus);
4690 if (animTarget == knifefollowedanim && !skeleton.free) {
4691 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
4692 skeleton.joints[i].velocity = 0;
4693 skeleton.joints[i].velocity.y = -2;
4696 if (id != 0 && unconscioustime > .1) {
4704 if (texupdatedelay < 0 && bleeding > 0 && bloodtoggle == 2 && distsq(&viewer, &coords) < 9) {
4705 texupdatedelay = .12;
4707 bloodsize = 5 - realtexdetail;
4711 startx = bleedy; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4712 starty = bleedx; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4713 endx = startx + bloodsize;
4714 endy = starty + bloodsize;
4724 if (endx > skeleton.skinsize - 1) {
4725 endx = skeleton.skinsize - 1;
4728 if (endy > skeleton.skinsize - 1) {
4729 endy = skeleton.skinsize - 1;
4732 if (endx < startx) {
4735 if (endy < starty) {
4739 for (int i = startx; i < endx; i++) {
4740 for (int j = starty; j < endy; j++) {
4741 if (Random() % 2 == 0) {
4742 color = Random() % 85 + 170;
4743 if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2) {
4744 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2;
4746 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0;
4747 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0;
4752 skeleton.drawmodel.textureptr.bind();
4756 if (skeleton.free) {
4757 bleedx += 4 * direction / realtexdetail;
4759 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4761 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4764 bleedy -= 4 / realtexdetail;
4766 bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4768 bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4773 if (abs(righthandmorphness - targetrighthandmorphness) < multiplier * 4) {
4774 righthandmorphness = targetrighthandmorphness;
4775 righthandmorphstart = righthandmorphend;
4776 } else if (righthandmorphness > targetrighthandmorphness) {
4777 righthandmorphness -= multiplier * 4;
4778 } else if (righthandmorphness < targetrighthandmorphness) {
4779 righthandmorphness += multiplier * 4;
4782 if (abs(lefthandmorphness - targetlefthandmorphness) < multiplier * 4) {
4783 lefthandmorphness = targetlefthandmorphness;
4784 lefthandmorphstart = lefthandmorphend;
4785 } else if (lefthandmorphness > targetlefthandmorphness) {
4786 lefthandmorphness -= multiplier * 4;
4787 } else if (lefthandmorphness < targetlefthandmorphness) {
4788 lefthandmorphness += multiplier * 4;
4791 if (creature == rabbittype || targettailmorphness == 5 || targettailmorphness == 0) {
4792 if (abs(tailmorphness - targettailmorphness) < multiplier * 10) {
4793 tailmorphness = targettailmorphness;
4794 tailmorphstart = tailmorphend;
4795 } else if (tailmorphness > targettailmorphness) {
4796 tailmorphness -= multiplier * 10;
4797 } else if (tailmorphness < targettailmorphness) {
4798 tailmorphness += multiplier * 10;
4802 if (creature == wolftype) {
4803 if (abs(tailmorphness - targettailmorphness) < multiplier * 4) {
4804 tailmorphness = targettailmorphness;
4805 tailmorphstart = tailmorphend;
4806 } else if (tailmorphness > targettailmorphness) {
4807 tailmorphness -= multiplier * 2;
4808 } else if (tailmorphness < targettailmorphness) {
4809 tailmorphness += multiplier * 2;
4813 if (headmorphend == 3 || headmorphstart == 3) {
4814 if (abs(headmorphness - targetheadmorphness) < multiplier * 7) {
4815 headmorphness = targetheadmorphness;
4816 headmorphstart = headmorphend;
4817 } else if (headmorphness > targetheadmorphness) {
4818 headmorphness -= multiplier * 7;
4819 } else if (headmorphness < targetheadmorphness) {
4820 headmorphness += multiplier * 7;
4822 } else if (headmorphend == 5 || headmorphstart == 5) {
4823 if (abs(headmorphness - targetheadmorphness) < multiplier * 10) {
4824 headmorphness = targetheadmorphness;
4825 headmorphstart = headmorphend;
4826 } else if (headmorphness > targetheadmorphness) {
4827 headmorphness -= multiplier * 10;
4828 } else if (headmorphness < targetheadmorphness) {
4829 headmorphness += multiplier * 10;
4832 if (abs(headmorphness - targetheadmorphness) < multiplier * 4) {
4833 headmorphness = targetheadmorphness;
4834 headmorphstart = headmorphend;
4835 } else if (headmorphness > targetheadmorphness) {
4836 headmorphness -= multiplier * 4;
4837 } else if (headmorphness < targetheadmorphness) {
4838 headmorphness += multiplier * 4;
4842 if (abs(chestmorphness - targetchestmorphness) < multiplier) {
4843 chestmorphness = targetchestmorphness;
4844 chestmorphstart = chestmorphend;
4845 } else if (chestmorphness > targetchestmorphness) {
4846 chestmorphness -= multiplier;
4847 } else if (chestmorphness < targetchestmorphness) {
4848 chestmorphness += multiplier;
4851 if (dead != 2 && howactive <= typesleeping) {
4852 if (chestmorphstart == 0 && chestmorphend == 0) {
4854 targetchestmorphness = 1;
4857 if (chestmorphstart != 0 && chestmorphend != 0) {
4859 targetchestmorphness = 1;
4861 if (environment == snowyenvironment) {
4864 if (skeleton.free) {
4865 footvel = skeleton.specialforward[0] * -1;
4866 footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
4868 footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
4869 footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
4871 if (animTarget == sleepanim) {
4872 footvel = DoRotation(footvel, 0, 90, 0);
4874 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
4878 if (!dead && howactive < typesleeping) {
4879 blinkdelay -= multiplier * 2;
4880 if (headmorphstart == 0 && headmorphend == 0 && blinkdelay <= 0) {
4882 targetheadmorphness = 1;
4884 blinkdelay = (float)(abs(Random() % 40)) / 5;
4886 if (headmorphstart == 3 && headmorphend == 3) {
4888 targetheadmorphness = 1;
4893 twitchdelay -= multiplier * 1.5;
4894 if (animTarget != hurtidleanim) {
4895 if (headmorphstart == 0 && headmorphend == 0 && twitchdelay <= 0) {
4897 targetheadmorphness = 1;
4899 twitchdelay = (float)(abs(Random() % 40)) / 5;
4901 if (headmorphstart == 5 && headmorphend == 5) {
4903 targetheadmorphness = 1;
4907 if ((isIdle() || isCrouch()) && animTarget != hurtidleanim) {
4908 twitchdelay3 -= multiplier * 1;
4909 if (Random() % 2 == 0) {
4910 if (righthandmorphstart == 0 && righthandmorphend == 0 && twitchdelay3 <= 0) {
4911 righthandmorphness = 0;
4912 targetrighthandmorphness = 1;
4913 righthandmorphend = 1;
4914 if (Random() % 2 == 0) {
4915 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4918 if (righthandmorphstart == 1 && righthandmorphend == 1) {
4919 righthandmorphness = 0;
4920 targetrighthandmorphness = 1;
4921 righthandmorphend = 0;
4924 if (Random() % 2 == 0) {
4925 if (lefthandmorphstart == 0 && lefthandmorphend == 0 && twitchdelay3 <= 0) {
4926 lefthandmorphness = 0;
4927 targetlefthandmorphness = 1;
4928 lefthandmorphend = 1;
4929 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4931 if (lefthandmorphstart == 1 && lefthandmorphend == 1) {
4932 lefthandmorphness = 0;
4933 targetlefthandmorphness = 1;
4934 lefthandmorphend = 0;
4940 if (creature == rabbittype) {
4941 if (howactive < typesleeping) {
4942 twitchdelay2 -= multiplier * 1.5;
4944 twitchdelay2 -= multiplier * 0.5;
4946 if (howactive <= typesleeping) {
4947 if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) {
4949 targettailmorphness = 1;
4951 twitchdelay2 = (float)(abs(Random() % 40)) / 5;
4953 if (tailmorphstart == 1 && tailmorphend == 1) {
4955 targettailmorphness = 1;
4958 if (tailmorphstart == 2 && tailmorphend == 2) {
4960 targettailmorphness = 1;
4967 if (creature == wolftype) {
4968 twitchdelay2 -= multiplier * 1.5;
4969 if (tailmorphend != 0) {
4970 if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) {
4972 targettailmorphness = 1;
4977 if (tailmorphend != 5) {
4978 if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) {
4980 targettailmorphness = 1;
4985 if (twitchdelay2 <= 0) {
4986 if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) {
4988 targettailmorphness = 1;
4991 if (tailmorphstart == 1 && tailmorphend == 1) {
4993 targettailmorphness = 1;
4996 if (tailmorphstart == 2 && tailmorphend == 2) {
4998 targettailmorphness = 1;
5001 if (tailmorphstart == 3 && tailmorphend == 3) {
5003 targettailmorphness = 1;
5006 if (tailmorphstart == 4 && tailmorphend == 4) {
5008 targettailmorphness = 1;
5015 unconscioustime = 0;
5018 if (dead == 1 || howactive == typesleeping) {
5019 unconscioustime += multiplier;
5020 //If unconscious, close eyes and mouth
5021 if (righthandmorphend != 0) {
5022 righthandmorphness = 0;
5024 righthandmorphend = 0;
5025 targetrighthandmorphness = 1;
5027 if (lefthandmorphend != 0) {
5028 lefthandmorphness = 0;
5030 lefthandmorphend = 0;
5031 targetlefthandmorphness = 1;
5033 if (headmorphend != 3 && headmorphend != 5) {
5037 targetheadmorphness = 1;
5040 if (howactive > typesleeping) {
5043 if (bloodtoggle && !bled) {
5044 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
5045 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
5046 unsigned int j = terrain.patchobjects[whichpatchx][whichpatchz][l];
5047 XYZ point = DoRotation(headpoint - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
5051 Object::objects[j]->model.MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
5057 if (dead == 2 || howactive > typesleeping) {
5058 //If dead, open mouth and hands
5059 if (righthandmorphend != 0) {
5060 righthandmorphness = 0;
5062 righthandmorphend = 0;
5063 targetrighthandmorphness = 1;
5065 if (lefthandmorphend != 0) {
5066 lefthandmorphness = 0;
5068 lefthandmorphend = 0;
5069 targetlefthandmorphness = 1;
5071 if (headmorphend != 2) {
5075 targetheadmorphness = 1;
5078 if (stunned > 0 && !dead && headmorphend != 2) {
5079 if (headmorphend != 4) {
5083 targetheadmorphness = 1;
5086 if (damage > damagetolerance && !dead) {
5089 unconscioustime = 0;
5091 if (creature == wolftype) {
5092 award_bonus(0, Wolfbonus);
5098 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
5099 weapons[weaponids[0]].velocity.x += .01;
5102 weaponids[0] = weaponids[num_weapons];
5103 if (weaponstuck == num_weapons) {
5108 for (unsigned i = 0; i < Person::players.size(); i++) {
5109 Person::players[i]->wentforweapon = 0;
5113 if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) {
5122 damage -= multiplier * 13;
5123 permanentdamage -= multiplier * 4;
5124 if (isIdle() || isCrouch()) {
5125 permanentdamage -= multiplier * 4;
5131 if (permanentdamage < 0) {
5132 permanentdamage = 0;
5134 if (superpermanentdamage < 0) {
5135 superpermanentdamage = 0;
5137 if (permanentdamage < superpermanentdamage) {
5138 permanentdamage = superpermanentdamage;
5140 if (damage < permanentdamage) {
5141 damage = permanentdamage;
5143 if (dead == 1 && damage < damagetolerance) {
5147 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5148 skeleton.joints[i].velocity = 0;
5151 if (permanentdamage > damagetolerance && dead != 2) {
5155 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
5156 weapons[weaponids[0]].velocity.x += .01;
5159 weaponids[0] = weaponids[num_weapons];
5160 if (weaponstuck == num_weapons) {
5165 for (unsigned i = 0; i < Person::players.size(); i++) {
5166 Person::players[i]->wentforweapon = 0;
5172 if (!dead && creature == wolftype) {
5173 award_bonus(0, Wolfbonus);
5176 if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance) {
5177 award_bonus(id, touchofdeath);
5179 if (id != 0 && unconscioustime > .1) {
5187 emit_sound_at(breaksound, coords);
5190 if (skeleton.free == 1) {
5192 pause_sound(whooshsound);
5196 //If knocked over, open hands and close mouth
5197 if (righthandmorphend != 0) {
5198 righthandmorphness = 0;
5200 righthandmorphend = 0;
5201 targetrighthandmorphness = 1;
5203 if (lefthandmorphend != 0) {
5204 lefthandmorphness = 0;
5206 lefthandmorphend = 0;
5207 targetlefthandmorphness = 1;
5209 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) {
5210 if (headmorphend != 0) {
5214 targetheadmorphness = 1;
5218 skeleton.DoGravity(&scale);
5220 damageamount = skeleton.DoConstraints(&coords, &scale) * 5;
5221 if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1)) {
5222 award_bonus(id, deepimpact);
5224 DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3));
5228 if (!skeleton.joints.empty()) {
5229 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
5230 average += skeleton.joints[j].position;
5232 average /= skeleton.joints.size();
5233 coords += average * scale;
5234 for (unsigned j = 0; j < skeleton.joints.size(); j++) {
5235 skeleton.joints[j].position -= average;
5237 average /= multiplier;
5241 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5242 velocity += skeleton.joints[i].velocity * scale;
5244 velocity /= skeleton.joints.size();
5246 if (!isnormal(velocity.x) && velocity.x) {
5250 if (findLength(&average) < 10 && dead && skeleton.free) {
5251 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
5252 if (skeleton.longdead > 2000) {
5253 if (skeleton.longdead > 6000) {
5255 pause_sound(whooshsound);
5261 if (dead == 2 && bloodloss < damagetolerance) {
5263 headpoint = (jointPos(head) + jointPos(neck)) / 2 * scale + coords;
5265 if (bloodtoggle && !bled) {
5266 terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
5267 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
5268 unsigned int j = terrain.patchobjects[whichpatchx][whichpatchz][l];
5269 XYZ point = DoRotation(headpoint - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
5270 float size = .2 * 1.2;
5273 Object::objects[j]->model.MakeDecal(blooddecal, &point, &size, &opacity, &yaw);
5278 if (dead == 2 && bloodloss >= damagetolerance) {
5280 headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords;
5281 if (bleeding <= 0) {
5284 if (bloodtoggle && !bled) {
5285 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
5286 for (unsigned int l = 0; l < terrain.patchobjects[whichpatchx][whichpatchz].size(); l++) {
5287 unsigned int j = terrain.patchobjects[whichpatchx][whichpatchz][l];
5288 XYZ point = DoRotation(headpoint - Object::objects[j]->position, 0, -Object::objects[j]->yaw, 0);
5292 Object::objects[j]->model.MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
5300 if (!dead && crouchkeydown && skeleton.freetime > .5 && id == 0 && skeleton.free) {
5301 bool canrecover = 1;
5302 XYZ startpoint, endpoint, colpoint, colviewer, coltarget;
5303 startpoint = coords;
5306 if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1) {
5309 if (velocity.y < -30) {
5312 for (unsigned int i = 0; i < Object::objects.size(); i++) {
5313 if (Object::objects[i]->type != treeleavestype && Object::objects[i]->type != bushtype && Object::objects[i]->type != firetype) {
5314 colviewer = startpoint;
5315 coltarget = endpoint;
5316 if (Object::objects[i]->model.LineCheck(&colviewer, &coltarget, &colpoint, &Object::objects[i]->position, &Object::objects[i]->yaw) != -1) {
5326 terrainnormal = jointPos(groin) - jointPos(abdomen);
5327 if (joint(groin).locked && joint(abdomen).locked) {
5328 terrainnormal = jointPos(groin) - jointPos(abdomen);
5329 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
5331 if (joint(abdomen).locked && joint(neck).locked) {
5332 terrainnormal = jointPos(abdomen) - jointPos(neck);
5333 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
5335 if (joint(groin).locked && joint(neck).locked) {
5336 terrainnormal = jointPos(groin) - jointPos(neck);
5337 middle = (jointPos(groin) + jointPos(neck)) / 2;
5339 Normalise(&terrainnormal);
5341 targetyaw = -asin(0 - terrainnormal.x);
5342 targetyaw *= 360 / 6.28;
5343 if (terrainnormal.z < 0) {
5344 targetyaw = 180 - targetyaw;
5349 animTarget = flipanim;
5350 crouchtogglekeydown = 1;
5355 animCurrent = tempanim;
5359 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5360 tempanimation.frames[0].joints[i].position = skeleton.joints[i].position;
5361 tempanimation.frames[0].joints[i].position = DoRotation(tempanimation.frames[0].joints[i].position, 0, -yaw, 0);
5366 if (findLength(&average) < 10 && !dead && skeleton.free) {
5367 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
5368 if (skeleton.longdead > (damage + 500) * 1.5) {
5370 pause_sound(whooshsound);
5377 terrainnormal = jointPos(groin) - jointPos(abdomen);
5378 if (joint(groin).locked && joint(abdomen).locked) {
5379 terrainnormal = jointPos(groin) - jointPos(abdomen);
5380 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
5382 if (joint(abdomen).locked && joint(neck).locked) {
5383 terrainnormal = jointPos(abdomen) - jointPos(neck);
5384 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
5386 if (joint(groin).locked && joint(neck).locked) {
5387 terrainnormal = jointPos(groin) - jointPos(neck);
5388 middle = (jointPos(groin) + jointPos(neck)) / 2;
5390 Normalise(&terrainnormal);
5392 targetyaw = -asin(0 - terrainnormal.x);
5393 targetyaw *= 360 / 6.28;
5394 if (terrainnormal.z < 0) {
5395 targetyaw = 180 - targetyaw;
5399 targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1;
5401 if (skeleton.forward.y < 0) {
5402 animTarget = getupfrombackanim;
5406 if (skeleton.forward.y > -.3) {
5407 animTarget = getupfromfrontanim;
5415 if ((Random() % 8 == 0 && id != 0 && creature == rabbittype) || (Random() % 2 == 0 && id != 0 && creature == wolftype) || (id == 0 && crouchkeydown && (forwardkeydown || backkeydown || leftkeydown || rightkeydown))) {
5416 animTarget = rollanim;
5417 targetyaw = lookyaw;
5421 if (forwardkeydown) {
5430 if (forwardkeydown) {
5438 if (!leftkeydown && !rightkeydown) {
5446 if (abs(targettilt2) > 50) {
5449 animCurrent = tempanim;
5452 tilt2 = targettilt2;
5454 if (middle.y > 0 && animTarget != rollanim) {
5455 targetoffset.y = middle.y + 1;
5458 for (unsigned i = 0; i < skeleton.joints.size(); i++) {
5459 tempanimation.frames[0].joints[i].position = skeleton.joints[i].position;
5460 tempanimation.frames[0].joints[i].position = DoRotation(tempanimation.frames[0].joints[i].position, 0, -yaw, 0);
5467 if (num_weapons > 0) {
5468 if (weapons[0].getType() == staff) {
5472 if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) {
5473 if (velocity.y > -30) {
5475 tempvelocity = velocity;
5476 Normalise(&tempvelocity);
5477 targetyaw = -asin(0 - tempvelocity.x);
5478 targetyaw *= 360 / 6.28;
5479 if (velocity.z < 0) {
5480 targetyaw = 180 - targetyaw;
5485 if (dotproduct(&skeleton.forward, &tempvelocity) < 0) {
5486 animTarget = rollanim;
5489 animTarget = backhandspringanim;
5495 emit_sound_at(movewhooshsound, coords, 128.);
5497 animCurrent = animTarget;
5498 frameCurrent = frameTarget - 1;
5510 if (skeleton.freefall == 0) {
5515 if (aitype != passivetype || skeleton.free == 1) {
5516 if (findLengthfast(&velocity) > .1) {
5517 for (unsigned int i = 0; i < Object::objects.size(); i++) {
5518 if (Object::objects[i]->type == firetype) {
5519 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) {
5521 if (!Object::objects[i]->onfire) {
5522 emit_sound_at(firestartsound, Object::objects[i]->position);
5524 Object::objects[i]->onfire = 1;
5527 if (Object::objects[i]->onfire) {
5533 if (Object::objects[i]->type == bushtype) {
5534 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) {
5536 if (!Object::objects[i]->onfire) {
5537 emit_sound_at(firestartsound, Object::objects[i]->position);
5539 Object::objects[i]->onfire = 1;
5543 if (Object::objects[i]->onfire) {
5547 if (Object::objects[i]->messedwith <= 0) {
5551 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5554 addEnvSound(coords, 4 * findLength(&velocity));
5558 if (environment == grassyenvironment) {
5559 howmany = findLength(&velocity) * 4;
5561 if (environment == snowyenvironment) {
5562 howmany = findLength(&velocity) * 2;
5565 if (environment != desertenvironment) {
5566 for (int j = 0; j < howmany; j++) {
5567 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5568 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5569 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5572 pos.x += float(abs(Random() % 100) - 50) / 200;
5573 pos.y += float(abs(Random() % 100) - 50) / 200;
5574 pos.z += float(abs(Random() % 100) - 50) / 200;
5575 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);
5576 Sprite::setLastSpriteSpecial(1);
5580 howmany = findLength(&velocity) * 4;
5582 if (environment == snowyenvironment) {
5583 for (int j = 0; j < howmany; j++) {
5584 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5585 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5586 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5589 pos.x += float(abs(Random() % 100) - 50) / 200;
5590 pos.y += float(abs(Random() % 100) - 50) / 200;
5591 pos.z += float(abs(Random() % 100) - 50) / 200;
5592 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5593 Sprite::setLastSpriteSpecial(2);
5598 Object::objects[i]->rotx += velocity.x * multiplier * 6;
5599 Object::objects[i]->roty += velocity.z * multiplier * 6;
5600 Object::objects[i]->messedwith = .5;
5604 if (Object::objects[i]->type == treeleavestype && environment != desertenvironment) {
5605 if (Object::objects[i]->pitch == 0) {
5608 tempcoord = coords - Object::objects[i]->position;
5609 tempcoord = DoRotation(tempcoord, 0, -Object::objects[i]->yaw, 0);
5610 tempcoord = DoRotation(tempcoord, -Object::objects[i]->pitch, 0, 0);
5611 tempcoord += Object::objects[i]->position;
5613 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) {
5614 if (Object::objects[i]->messedwith <= 0) {
5618 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5621 addEnvSound(coords, 4 * findLength(&velocity));
5625 if (environment == grassyenvironment) {
5626 howmany = findLength(&velocity) * 4;
5628 if (environment == snowyenvironment) {
5629 howmany = findLength(&velocity) * 2;
5632 if (environment != desertenvironment) {
5633 for (int j = 0; j < howmany; j++) {
5634 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5635 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5636 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5638 pos += velocity * .1;
5640 pos.x += float(abs(Random() % 100) - 50) / 150;
5641 pos.y += float(abs(Random() % 100) - 50) / 150;
5642 pos.z += float(abs(Random() % 100) - 50) / 150;
5643 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);
5644 Sprite::setLastSpriteSpecial(1);
5648 howmany = findLength(&velocity) * 4;
5650 if (environment == snowyenvironment) {
5651 for (int j = 0; j < howmany; j++) {
5652 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5653 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5654 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5656 pos += velocity * .1;
5658 pos.x += float(abs(Random() % 100) - 50) / 150;
5659 pos.y += float(abs(Random() % 100) - 50) / 150;
5660 pos.z += float(abs(Random() % 100) - 50) / 150;
5661 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5662 Sprite::setLastSpriteSpecial(2);
5667 Object::objects[i]->messedwith = .5;
5674 if (!skeleton.free) {
5677 if ((stunned > 0 || surprised > 0) && Person::players.size() > 2 && aitype != passivetype) {
5681 if (aitype != passivetype && victim->skeleton.free && !victim->dead) {
5685 if (Tutorial::active && id != 0) {
5688 if (play && !isPlayerControlled()) {
5689 int whichsound = -1;
5690 if (speechdelay <= 0) {
5691 unsigned int i = abs(Random() % 4);
5693 whichsound = PersonType::types[creature].soundsTalk[i];
5698 if (whichsound != -1) {
5699 emit_sound_at(whichsound, coords);
5703 if (animTarget == staggerbackhighanim) {
5706 if (animTarget == staggerbackhardanim) {
5709 staggerdelay -= multiplier;
5710 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim) {
5713 if (velocity.y < -30 && animTarget == jumpdownanim) {
5716 if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) {
5717 animTarget = getIdle();
5721 weaponmissdelay -= multiplier;
5722 highreversaldelay -= multiplier;
5723 lowreversaldelay -= multiplier;
5724 lastcollide -= multiplier;
5725 skiddelay -= multiplier;
5726 if (!isnormal(velocity.x) && velocity.x) {
5729 if (!isnormal(targettilt) && targettilt) {
5732 if (!isnormal(targettilt2) && targettilt2) {
5735 if (!isnormal(targetyaw) && targetyaw) {
5739 if (animTarget == bounceidleanim || animTarget == wolfidle || animTarget == walkanim || animTarget == drawrightanim || animTarget == crouchdrawrightanim || animTarget == drawleftanim || animTarget == fightidleanim || animTarget == fightsidestep || animTarget == hanganim || isCrouch() || animTarget == backhandspringanim) {
5740 //open hands and close mouth
5741 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5742 righthandmorphness = 0;
5743 righthandmorphend = 0;
5744 targetrighthandmorphness = 1;
5747 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5748 lefthandmorphness = 0;
5749 lefthandmorphend = 0;
5750 targetlefthandmorphness = 1;
5753 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5 && headmorphend != 0 && headmorphness == targetheadmorphness) {
5756 targetheadmorphness = 1;
5760 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) {
5761 //open hands and mouth
5762 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5763 righthandmorphness = 0;
5764 righthandmorphend = 0;
5765 targetrighthandmorphness = 1;
5768 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5769 lefthandmorphness = 0;
5770 lefthandmorphend = 0;
5771 targetlefthandmorphness = 1;
5774 if (headmorphend != 1 && headmorphness == targetheadmorphness) {
5777 targetheadmorphness = 1;
5781 if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim) {
5782 //close hands and mouth
5783 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5784 righthandmorphness = 0;
5785 righthandmorphend = 1;
5786 targetrighthandmorphness = 1;
5789 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5790 lefthandmorphness = 0;
5791 lefthandmorphend = 1;
5792 targetlefthandmorphness = 1;
5795 if (headmorphend != 0 && headmorphness == targetheadmorphness) {
5798 targetheadmorphness = 1;
5802 if (animTarget == spinkickanim ||
5803 animTarget == staffspinhitreversalanim ||
5804 animTarget == staffspinhitreversedanim ||
5805 animTarget == staffhitreversalanim ||
5806 animTarget == staffhitreversedanim ||
5807 animTarget == hurtidleanim ||
5808 animTarget == winduppunchanim ||
5809 animTarget == swordslashreversalanim ||
5810 animTarget == swordslashreversedanim ||
5811 animTarget == knifeslashreversalanim ||
5812 animTarget == knifeslashreversedanim ||
5813 animTarget == knifethrowanim ||
5814 animTarget == knifefollowanim ||
5815 animTarget == knifefollowedanim ||
5816 animTarget == killanim ||
5817 animTarget == dropkickanim ||
5818 animTarget == upunchanim ||
5819 animTarget == knifeslashstartanim ||
5820 animTarget == swordslashanim ||
5821 animTarget == staffhitanim ||
5822 animTarget == staffspinhitanim ||
5823 animTarget == staffgroundsmashanim ||
5824 animTarget == spinkickreversalanim ||
5825 animTarget == sweepreversalanim ||
5826 animTarget == lowkickanim ||
5827 animTarget == sweepreversedanim ||
5828 animTarget == rabbitkickreversalanim ||
5829 animTarget == rabbitkickreversedanim ||
5830 animTarget == jumpreversalanim ||
5831 animTarget == jumpreversedanim) {
5832 //close hands and yell
5833 if (righthandmorphend != 1 &&
5834 righthandmorphness == targetrighthandmorphness) {
5835 righthandmorphness = 0;
5836 righthandmorphend = 1;
5837 targetrighthandmorphness = 1;
5840 if (lefthandmorphend != 1 &&
5841 lefthandmorphness == targetlefthandmorphness) {
5842 lefthandmorphness = 0;
5843 lefthandmorphend = 1;
5844 targetlefthandmorphness = 1;
5847 if (headmorphend != 2 && headmorphness == targetheadmorphness) {
5850 targetheadmorphness = 1;
5857 if ((victim != this->shared_from_this()) && !victim->dead && (victim->aitype != passivetype) &&
5858 (victim->aitype != searchtype) && (aitype != passivetype) &&
5859 (aitype != searchtype) && (victim->id < Person::players.size())) {
5860 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
5864 if (!dead && animTarget != hurtidleanim) {
5865 if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) {
5866 if (headmorphend != 4 || headmorphness == targetheadmorphness) {
5869 targetheadmorphness = 1;
5875 if (weapons[weaponids[weaponactive]].getType() != staff) {
5876 righthandmorphstart = 1;
5877 righthandmorphend = 1;
5879 if (weapons[weaponids[weaponactive]].getType() == staff) {
5880 righthandmorphstart = 2;
5881 righthandmorphend = 2;
5883 targetrighthandmorphness = 1;
5886 terrainnormal = terrain.getNormal(coords.x, coords.z);
5888 if (Animation::animations[animTarget].attack != reversal) {
5889 if (!isnormal(coords.x)) {
5898 flatfacing = DoRotation(flatfacing, 0, yaw, 0);
5899 facing = flatfacing;
5900 ReflectVector(&facing, terrainnormal);
5904 animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) {
5906 targettilt2 = -facing.y * 20;
5912 if (!isRun() && !Animation::animations[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim) {
5915 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5916 flatvelocity = velocity;
5918 flatvelspeed = findLength(&flatvelocity);
5919 targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity);
5920 targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity);
5921 if (velocity.y < 0) {
5924 if (velocity.y < 0) {
5927 if (targettilt > 25) {
5930 if (targettilt < -25) {
5935 if (targettilt2 > 45) {
5938 if (targettilt2 < -45) {
5941 if (abs(tilt2 - targettilt2) < multiplier * 400) {
5942 tilt2 = targettilt2;
5943 } else if (tilt2 > targettilt2) {
5944 tilt2 -= multiplier * 400;
5945 } else if (tilt2 < targettilt2) {
5946 tilt2 += multiplier * 400;
5948 if (!Animation::animations[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) {
5957 if (!isnormal(targettilt) && targettilt) {
5960 if (!isnormal(targettilt2) && targettilt2) {
5965 if (animTarget == rabbittackleanim) {
5966 velocity += facing * multiplier * speed * 700 * scale;
5967 velspeed = findLength(&velocity);
5968 if (velspeed > speed * 65 * scale) {
5969 velocity /= velspeed;
5970 velspeed = speed * 65 * scale;
5971 velocity *= velspeed;
5973 velocity.y += gravity * multiplier * 20;
5974 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5975 velspeed = findLength(&velocity);
5976 velocity = flatfacing * velspeed;
5978 if (animTarget != rabbitrunninganim && animTarget != wolfrunninganim) {
5979 if (isRun() || animTarget == rabbitkickanim) {
5980 velocity += facing * multiplier * speed * 700 * scale;
5981 velspeed = findLength(&velocity);
5982 if (velspeed > speed * 45 * scale) {
5983 velocity /= velspeed;
5984 velspeed = speed * 45 * scale;
5985 velocity *= velspeed;
5987 velocity.y += gravity * multiplier * 20;
5988 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5989 velspeed = findLength(&velocity);
5990 if (velspeed < speed * 30 * scale) {
5991 velspeed = speed * 30 * scale;
5993 velocity = flatfacing * velspeed;
5995 } else if (isRun()) {
5996 velocity += facing * multiplier * speed * 700 * scale;
5997 velspeed = findLength(&velocity);
5998 if (velspeed > speed * PersonType::types[creature].maxRunSpeed * scale) {
5999 velocity /= velspeed;
6000 velspeed = speed * PersonType::types[creature].maxRunSpeed * scale;
6001 velocity *= velspeed;
6003 velocity.y += gravity * multiplier * 20;
6004 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6005 velspeed = findLength(&velocity);
6006 velocity = flatfacing * velspeed;
6009 if (animTarget == rollanim && targetFrame().label != 6) {
6010 velocity += facing * multiplier * speed * 700 * scale;
6011 velspeed = findLength(&velocity);
6012 if (velspeed > speed * 45 * scale) {
6013 velocity /= velspeed;
6014 velspeed = speed * 45 * scale;
6015 velocity *= velspeed;
6017 velocity.y += gravity * multiplier * 20;
6018 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6019 velspeed = findLength(&velocity);
6020 velocity = flatfacing * velspeed;
6023 if (animTarget == sneakanim || animTarget == walkanim) {
6024 velocity += facing * multiplier * speed * 700 * scale;
6025 velspeed = findLength(&velocity);
6026 if (velspeed > speed * 12 * scale) {
6027 velocity /= velspeed;
6028 velspeed = speed * 12 * scale;
6029 velocity *= velspeed;
6031 velocity.y += gravity * multiplier * 20;
6032 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6033 velspeed = findLength(&velocity);
6034 velocity = flatfacing * velspeed;
6037 if ((animTarget == fightidleanim || animTarget == knifefightidleanim) && (animCurrent == bounceidleanim || animCurrent == hurtidleanim)) {
6038 velocity += facing * multiplier * speed * 700 * scale;
6039 velspeed = findLength(&velocity);
6040 if (velspeed > speed * 2 * scale) {
6041 velocity /= velspeed;
6042 velspeed = speed * 2 * scale;
6043 velocity *= velspeed;
6045 velocity.y += gravity * multiplier * 20;
6046 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6047 velspeed = findLength(&velocity);
6048 velocity = flatfacing * velspeed;
6051 if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) {
6052 velocity -= facing * multiplier * speed * 700 * scale;
6053 velspeed = findLength(&velocity);
6054 if (velspeed > speed * 2 * scale) {
6055 velocity /= velspeed;
6056 velspeed = speed * 2 * scale;
6057 velocity *= velspeed;
6059 velocity.y += gravity * multiplier * 20;
6060 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6061 velspeed = findLength(&velocity);
6062 velocity = flatfacing * velspeed * -1;
6065 if (animTarget == fightsidestep) {
6066 velocity += DoRotation(facing * multiplier * speed * 700 * scale, 0, -90, 0);
6067 velspeed = findLength(&velocity);
6068 if (velspeed > speed * 12 * scale) {
6069 velocity /= velspeed;
6070 velspeed = speed * 12 * scale;
6071 velocity *= velspeed;
6073 velocity.y += gravity * multiplier * 20;
6074 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6075 velspeed = findLength(&velocity);
6076 velocity = DoRotation(flatfacing * velspeed, 0, -90, 0);
6079 if (animTarget == staggerbackhighanim) {
6080 coords -= facing * multiplier * speed * 16 * scale;
6083 if (animTarget == staggerbackhardanim && Animation::animations[staggerbackhardanim].frames[frameTarget].label != 6) {
6084 coords -= facing * multiplier * speed * 20 * scale;
6088 if (animTarget == backhandspringanim) {
6089 //coords-=facing*multiplier*50*scale;
6090 velocity += facing * multiplier * speed * 700 * scale * -1;
6091 velspeed = findLength(&velocity);
6092 if (velspeed > speed * 50 * scale) {
6093 velocity /= velspeed;
6094 velspeed = speed * 50 * scale;
6095 velocity *= velspeed;
6097 velocity.y += gravity * multiplier * 20;
6098 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6099 velspeed = findLength(&velocity);
6100 velocity = flatfacing * velspeed * -1;
6102 if (animTarget == dodgebackanim) {
6103 //coords-=facing*multiplier*50*scale;
6104 velocity += facing * multiplier * speed * 700 * scale * -1;
6105 velspeed = findLength(&velocity);
6106 if (velspeed > speed * 60 * scale) {
6107 velocity /= velspeed;
6108 velspeed = speed * 60 * scale;
6109 velocity *= velspeed;
6111 velocity.y += gravity * multiplier * 20;
6112 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
6113 velspeed = findLength(&velocity);
6114 velocity = flatfacing * velspeed * -1;
6117 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
6118 velspeed = findLength(&velocity);
6121 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
6122 velocity.y += gravity * multiplier;
6125 if (animTarget != climbanim && animTarget != hanganim && !isWallJump()) {
6126 coords += velocity * multiplier;
6129 if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
6130 if (isFlip() && targetFrame().label == 7) {
6134 if (animTarget == jumpupanim) {
6136 animTarget = getIdle();
6143 pause_sound(whooshsound);
6144 OPENAL_SetVolume(channels[whooshsound], 0);
6147 if (animTarget == jumpdownanim || isFlip()) {
6151 animTarget = getLanding();
6152 emit_sound_at(landsound, coords, 128.);
6155 addEnvSound(coords);
6160 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump()) {
6161 coords.y += gravity * multiplier * 2;
6163 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) {
6164 coords.y = terrain.getHeight(coords.x, coords.z);
6168 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)) {
6169 velspeed = findLength(&velocity);
6171 if (velspeed < multiplier * 300 * scale) {
6174 velocity -= velocity / velspeed * multiplier * 300 * scale;
6176 if (velspeed > 5 && (isLanding() || isLandhard())) {
6177 skiddingdelay += multiplier;
6178 if (skiddelay <= 0) {
6179 FootLand(leftfoot, .5);
6180 FootLand(rightfoot, .5);
6189 velspeed = findLength(&velocity);
6191 if (velspeed > 5 && (isLanding() || isLandhard())) {
6192 skiddingdelay += multiplier;
6193 if (skiddelay <= 0) {
6194 FootLand(leftfoot, .5);
6195 FootLand(rightfoot, .5);
6203 if (skiddingdelay < 0) {
6204 skiddingdelay += multiplier;
6206 if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) {
6208 if (!onterrain || environment == grassyenvironment) {
6209 emit_sound_at(skidsound, coords, 128 * velspeed / 10);
6211 emit_sound_at(snowskidsound, coords, 128 * velspeed / 10);
6215 if (Animation::animations[animTarget].attack == normalattack && animTarget != rabbitkickanim && !victim->skeleton.free) {
6216 terrainnormal = victim->coords - coords;
6217 Normalise(&terrainnormal);
6218 targetyaw = -asin(0 - terrainnormal.x);
6219 targetyaw *= 360 / 6.28;
6220 if (terrainnormal.z < 0) {
6221 targetyaw = 180 - targetyaw;
6223 targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70;
6226 if (Animation::animations[animTarget].attack == reversal && animTarget != rabbittacklinganim) {
6227 targetyaw = victim->targetyaw;
6229 if (animTarget == rabbittacklinganim) {
6230 coords = victim->coords;
6233 skeleton.oldfree = skeleton.free;
6237 midterrain.x = terrain.size * terrain.scale / 2;
6238 midterrain.z = terrain.size * terrain.scale / 2;
6239 if (distsqflat(&coords, &midterrain) > (terrain.size * terrain.scale / 2 - viewdistance) * (terrain.size * terrain.scale / 2 - viewdistance)) {
6241 tempposit = coords - midterrain;
6243 Normalise(&tempposit);
6244 tempposit *= (terrain.size * terrain.scale / 2 - viewdistance);
6245 coords.x = tempposit.x + midterrain.x;
6246 coords.z = tempposit.z + midterrain.z;
6251 * inverse kinematics helper function
6253 void IKHelper(Person* p, float interp)
6255 XYZ point, change, change2;
6256 float heightleft, heightright;
6258 // TODO: implement localToWorld and worldToLocal
6259 // but keep in mind it won't be the same math if player is ragdolled or something
6260 // - localToWorldStanding / worldToLocalStanding (or crouching or...?)
6261 // then comb through code for places where to use it
6263 // point = localToWorld(jointPos(leftfoot))
6264 point = DoRotation(p->jointPos(leftfoot), 0, p->yaw, 0) * p->scale + p->coords;
6265 // adjust height of foot
6266 heightleft = terrain.getHeight(point.x, point.z) + .04;
6267 point.y = heightleft;
6268 change = p->jointPos(leftankle) - p->jointPos(leftfoot);
6269 change2 = p->jointPos(leftknee) - p->jointPos(leftfoot);
6270 // jointPos(leftfoot) = interpolate(worldToLocal(point), jointPos(leftfoot), interp)
6271 p->jointPos(leftfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(leftfoot) * (1 - interp);
6272 // move ankle along with foot
6273 p->jointPos(leftankle) = p->jointPos(leftfoot) + change;
6274 // average knee pos between old and new pos
6275 p->jointPos(leftknee) = (p->jointPos(leftfoot) + change2) / 2 + (p->jointPos(leftknee)) / 2;
6277 // do same as above for right leg
6278 point = DoRotation(p->jointPos(rightfoot), 0, p->yaw, 0) * p->scale + p->coords;
6279 heightright = terrain.getHeight(point.x, point.z) + .04;
6280 point.y = heightright;
6281 change = p->jointPos(rightankle) - p->jointPos(rightfoot);
6282 change2 = p->jointPos(rightknee) - p->jointPos(rightfoot);
6283 p->jointPos(rightfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(rightfoot) * (1 - interp);
6284 p->jointPos(rightankle) = p->jointPos(rightfoot) + change;
6285 p->jointPos(rightknee) = (p->jointPos(rightfoot) + change2) / 2 + (p->jointPos(rightknee)) / 2;
6287 // fix up skeleton now that we've moved body parts?
6288 p->skeleton.DoConstraints(&p->coords, &p->scale);
6295 int Person::DrawSkeleton()
6297 int oldplayerdetail;
6298 if ((frustum.SphereInFrustum(coords.x, coords.y + scale * 3, coords.z, scale * 8) && distsq(&viewer, &coords) < viewdistance * viewdistance) || skeleton.free == 3) {
6299 if (onterrain && (isIdle() || isCrouch() || wasIdle() || wasCrouch()) && !skeleton.free) {
6309 glAlphaFunc(GL_GREATER, 0.0001);
6311 float terrainheight;
6313 if (!isnormal(yaw)) {
6316 if (!isnormal(tilt)) {
6319 if (!isnormal(tilt2)) {
6322 oldplayerdetail = playerdetail;
6324 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) {
6327 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 128 && detail == 1) {
6330 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) {
6336 if (playerdetail != oldplayerdetail) {
6338 normalsupdatedelay = 0;
6340 static float updatedelaychange;
6341 static float morphness;
6342 static float framemult;
6344 skeleton.FindForwards();
6345 if (howactive == typesittingwall) {
6346 skeleton.specialforward[1] = 0;
6347 skeleton.specialforward[1].z = 1;
6353 static int weaponattachmuscle;
6354 static int weaponrotatemuscle;
6355 static XYZ weaponpoint;
6356 static int start, endthing;
6357 if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
6358 if (!isSleeping() && !isSitting()) {
6359 // TODO: give these meaningful names
6360 const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim);
6361 const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard() || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim);
6363 if (onterrain && (cond1 && cond2) && !skeleton.free) {
6365 if (creature == wolftype) {
6370 if (onterrain && (cond1 && !cond2) && !skeleton.free) {
6371 IKHelper(this, target);
6372 if (creature == wolftype) {
6373 IKHelper(this, target);
6377 if (onterrain && (!cond1 && cond2) && !skeleton.free) {
6378 IKHelper(this, 1 - target);
6379 if (creature == wolftype) {
6380 IKHelper(this, 1 - target);
6385 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())) {
6388 targetheadyaw = -targetyaw;
6389 targetheadpitch = 0;
6390 if (Animation::animations[animTarget].attack == 3) {
6391 targetheadyaw += 180;
6394 for (int i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6395 skeleton.drawmodel.vertex[i] = 0;
6396 skeleton.drawmodel.vertex[i].y = 999;
6398 for (int i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
6399 skeleton.drawmodellow.vertex[i] = 0;
6400 skeleton.drawmodellow.vertex[i].y = 999;
6402 for (int i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
6403 skeleton.drawmodelclothes.vertex[i] = 0;
6404 skeleton.drawmodelclothes.vertex[i].y = 999;
6406 for (unsigned int i = 0; i < skeleton.muscles.size(); i++) {
6407 // convenience renames
6408 const int p1 = skeleton.muscles[i].parent1->label;
6409 const int p2 = skeleton.muscles[i].parent2->label;
6411 if ((skeleton.muscles[i].vertices.size() > 0 && playerdetail) || (skeleton.muscles[i].verticeslow.size() > 0 && !playerdetail)) {
6416 if (p1 == righthand || p2 == righthand) {
6417 morphness = righthandmorphness;
6418 start = righthandmorphstart;
6419 endthing = righthandmorphend;
6421 if (p1 == lefthand || p2 == lefthand) {
6422 morphness = lefthandmorphness;
6423 start = lefthandmorphstart;
6424 endthing = lefthandmorphend;
6426 if (p1 == head || p2 == head) {
6427 morphness = headmorphness;
6428 start = headmorphstart;
6429 endthing = headmorphend;
6431 if ((p1 == neck && p2 == abdomen) || (p2 == neck && p1 == abdomen)) {
6432 morphness = chestmorphness;
6433 start = chestmorphstart;
6434 endthing = chestmorphend;
6436 if ((p1 == groin && p2 == abdomen) || (p2 == groin && p1 == abdomen)) {
6437 morphness = tailmorphness;
6438 start = tailmorphstart;
6439 endthing = tailmorphend;
6442 skeleton.FindRotationMuscle(i, animTarget);
6444 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6445 glMatrixMode(GL_MODELVIEW);
6448 if (!skeleton.free) {
6449 glRotatef(tilt2, 1, 0, 0);
6451 if (!skeleton.free) {
6452 glRotatef(tilt, 0, 0, 1);
6455 glTranslatef(mid.x, mid.y, mid.z);
6457 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6458 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6460 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6461 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6463 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6464 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6466 if (playerdetail || skeleton.free == 3) {
6467 for (unsigned j = 0; j < skeleton.muscles[i].vertices.size(); j++) {
6468 XYZ& v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
6469 XYZ& v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
6470 glMatrixMode(GL_MODELVIEW);
6472 if (p1 == abdomen || p2 == abdomen) {
6473 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * getProportionXYZ(1).x,
6474 (v0.y * (1 - morphness) + v1.y * morphness) * getProportionXYZ(1).y,
6475 (v0.z * (1 - morphness) + v1.z * morphness) * getProportionXYZ(1).z);
6477 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) {
6478 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * getProportionXYZ(2).x,
6479 (v0.y * (1 - morphness) + v1.y * morphness) * getProportionXYZ(2).y,
6480 (v0.z * (1 - morphness) + v1.z * morphness) * getProportionXYZ(2).z);
6482 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) {
6483 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * getProportionXYZ(3).x,
6484 (v0.y * (1 - morphness) + v1.y * morphness) * getProportionXYZ(3).y,
6485 (v0.z * (1 - morphness) + v1.z * morphness) * getProportionXYZ(3).z);
6487 if (p1 == head || p2 == head) {
6488 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * getProportionXYZ(0).x,
6489 (v0.y * (1 - morphness) + v1.y * morphness) * getProportionXYZ(0).y,
6490 (v0.z * (1 - morphness) + v1.z * morphness) * getProportionXYZ(0).z);
6492 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6493 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale;
6494 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale;
6495 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z = M[14] * scale;
6499 if (!playerdetail || skeleton.free == 3) {
6500 for (unsigned j = 0; j < skeleton.muscles[i].verticeslow.size(); j++) {
6501 XYZ& v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
6502 glMatrixMode(GL_MODELVIEW);
6504 if (p1 == abdomen || p2 == abdomen) {
6505 glTranslatef(v0.x * getProportionXYZ(1).x,
6506 v0.y * getProportionXYZ(1).y,
6507 v0.z * getProportionXYZ(1).z);
6509 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) {
6510 glTranslatef(v0.x * getProportionXYZ(2).x,
6511 v0.y * getProportionXYZ(2).y,
6512 v0.z * getProportionXYZ(2).z);
6514 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) {
6515 glTranslatef(v0.x * getProportionXYZ(3).x,
6516 v0.y * getProportionXYZ(3).y,
6517 v0.z * getProportionXYZ(3).z);
6519 if (p1 == head || p2 == head) {
6520 glTranslatef(v0.x * getProportionXYZ(0).x,
6521 v0.y * getProportionXYZ(0).y,
6522 v0.z * getProportionXYZ(0).z);
6525 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6526 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
6527 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y = M[13] * scale;
6528 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z = M[14] * scale;
6534 if (skeleton.clothes && skeleton.muscles[i].verticesclothes.size() > 0) {
6535 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6537 glMatrixMode(GL_MODELVIEW);
6540 if (!skeleton.free) {
6541 glRotatef(tilt2, 1, 0, 0);
6543 if (!skeleton.free) {
6544 glRotatef(tilt, 0, 0, 1);
6546 glTranslatef(mid.x, mid.y, mid.z);
6547 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6548 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6550 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6551 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6553 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6554 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6556 for (unsigned j = 0; j < skeleton.muscles[i].verticesclothes.size(); j++) {
6557 XYZ& v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
6558 glMatrixMode(GL_MODELVIEW);
6560 if (p1 == abdomen || p2 == abdomen) {
6561 glTranslatef(v0.x * getProportionXYZ(1).x,
6562 v0.y * getProportionXYZ(1).y,
6563 v0.z * getProportionXYZ(1).z);
6565 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow) {
6566 glTranslatef(v0.x * getProportionXYZ(2).x,
6567 v0.y * getProportionXYZ(2).y,
6568 v0.z * getProportionXYZ(2).z);
6570 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee) {
6571 glTranslatef(v0.x * getProportionXYZ(3).x,
6572 v0.y * getProportionXYZ(3).y,
6573 v0.z * getProportionXYZ(3).z);
6575 if (p1 == head || p2 == head) {
6576 glTranslatef(v0.x * getProportionXYZ(0).x,
6577 v0.y * getProportionXYZ(0).y,
6578 v0.z * getProportionXYZ(0).z);
6580 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6581 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
6582 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
6583 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z = M[14] * scale;
6588 updatedelay = 1 + (float)(Random() % 100) / 1000;
6590 if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) {
6591 normalsupdatedelay = 1;
6592 if (playerdetail || skeleton.free == 3) {
6593 skeleton.drawmodel.CalculateNormals(0);
6595 if (!playerdetail || skeleton.free == 3) {
6596 skeleton.drawmodellow.CalculateNormals(0);
6598 if (skeleton.clothes) {
6599 skeleton.drawmodelclothes.CalculateNormals(0);
6602 if (playerdetail || skeleton.free == 3) {
6603 skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
6605 if (!playerdetail || skeleton.free == 3) {
6606 skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
6608 if (skeleton.clothes) {
6609 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6614 updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1);
6615 if (updatedelaychange > -realmultiplier * 30) {
6616 updatedelaychange = -realmultiplier * 30;
6618 if (updatedelaychange > -framemult * 4) {
6619 updatedelaychange = -framemult * 4;
6621 if (skeleton.free == 1) {
6622 updatedelaychange *= 6;
6625 updatedelaychange *= 8;
6627 updatedelay += updatedelaychange;
6629 glMatrixMode(GL_MODELVIEW);
6631 glTranslatef(coords.x, coords.y - .02, coords.z);
6632 if (!skeleton.free) {
6633 glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
6634 glRotatef(yaw, 0, 1, 0);
6638 glColor4f(.4, 1, .4, 1);
6639 glDisable(GL_LIGHTING);
6640 glDisable(GL_TEXTURE_2D);
6643 for (int i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6644 XYZ& v0 = skeleton.drawmodel.vertex[i];
6645 glVertex3f(v0.x, v0.y, v0.z);
6652 for (unsigned int i = 0; i < skeleton.drawmodel.Triangles.size(); i++) {
6653 const XYZ& v0 = skeleton.drawmodel.getTriangleVertex(i, 0);
6654 const XYZ& v1 = skeleton.drawmodel.getTriangleVertex(i, 1);
6655 const XYZ& v2 = skeleton.drawmodel.getTriangleVertex(i, 2);
6656 glVertex3f(v0.x, v0.y, v0.z);
6657 glVertex3f(v1.x, v1.y, v1.z);
6658 glVertex3f(v1.x, v1.y, v1.z);
6659 glVertex3f(v2.x, v2.y, v2.z);
6660 glVertex3f(v2.x, v2.y, v2.z);
6661 glVertex3f(v0.x, v0.y, v0.z);
6668 terrainlight = terrain.getLighting(coords.x, coords.z);
6669 distance = distsq(&viewer, &coords);
6670 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
6675 terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1;
6676 if (terrainheight < 1) {
6679 if (terrainheight > 1.7) {
6680 terrainheight = 1.7;
6683 glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance);
6684 glDisable(GL_BLEND);
6685 glAlphaFunc(GL_GREATER, 0.0001);
6686 glEnable(GL_TEXTURE_2D);
6688 glDisable(GL_TEXTURE_2D);
6689 glColor4f(.7, .35, 0, .5);
6691 glEnable(GL_LIGHTING);
6694 if (Tutorial::active && id != 0) {
6695 glColor4f(.7, .7, .7, 0.6);
6697 glEnable(GL_LIGHTING);
6699 if (canattack && cananger) {
6700 if (Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed) {
6701 glDisable(GL_TEXTURE_2D);
6702 glColor4f(1, 0, 0, 0.8);
6705 glMatrixMode(GL_TEXTURE);
6707 glTranslatef(0, -smoketex, 0);
6708 glTranslatef(-smoketex, 0, 0);
6712 if (Tutorial::active && (id != 0)) {
6713 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6715 skeleton.drawmodel.draw();
6719 if (!playerdetail) {
6720 if (Tutorial::active && (id != 0)) {
6721 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6723 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6727 if (!(Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed)) {
6728 if (Tutorial::active && id != 0) {
6730 glMatrixMode(GL_MODELVIEW);
6731 glEnable(GL_TEXTURE_2D);
6732 glColor4f(.7, .7, .7, 0.6);
6734 glEnable(GL_LIGHTING);
6736 if (canattack && cananger) {
6737 if (Animation::animations[animTarget].attack == normalattack || Animation::animations[animTarget].attack == reversed) {
6738 glDisable(GL_TEXTURE_2D);
6739 glColor4f(1, 0, 0, 0.8);
6742 glMatrixMode(GL_TEXTURE);
6744 glTranslatef(0, -smoketex * .6, 0);
6745 glTranslatef(smoketex * .6, 0, 0);
6748 if (Tutorial::active && (id != 0)) {
6749 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6751 skeleton.drawmodel.draw();
6755 if (!playerdetail) {
6756 if (Tutorial::active && (id != 0)) {
6757 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6759 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6765 if (Tutorial::active && id != 0) {
6767 glMatrixMode(GL_MODELVIEW);
6768 glEnable(GL_TEXTURE_2D);
6770 if (skeleton.clothes) {
6774 skeleton.drawmodelclothes.draw();
6777 skeleton.drawmodelclothes.drawimmediate();
6784 if (num_weapons > 0) {
6785 for (k = 0; k < num_weapons; k++) {
6786 int i = weaponids[k];
6787 if (weaponactive == k) {
6788 if (weapons[i].getType() != staff) {
6789 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6790 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].vertices.size() > 0) {
6791 weaponattachmuscle = j;
6794 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6795 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) {
6796 weaponrotatemuscle = j;
6799 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6800 if (creature == wolftype) {
6801 weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3);
6804 if (weapons[i].getType() == staff) {
6805 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6806 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].vertices.size() > 0) {
6807 weaponattachmuscle = j;
6810 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6811 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) {
6812 weaponrotatemuscle = j;
6815 //weaponpoint=jointPos(rightwrist);
6816 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6817 //weaponpoint+=skeleton.specialforward[1]*.1+(jointPos(rightwrist)-jointPos(rightelbow));
6818 XYZ tempnormthing, vec1, vec2;
6819 vec1 = (jointPos(rightwrist) - jointPos(rightelbow));
6820 vec2 = (jointPos(rightwrist) - jointPos(rightshoulder));
6821 CrossProduct(&vec1, &vec2, &tempnormthing);
6822 Normalise(&tempnormthing);
6823 if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim) {
6824 weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow));
6828 if (weaponactive != k && weaponstuck != k) {
6829 if (weapons[i].getType() == knife) {
6830 weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35;
6832 if (weapons[i].getType() == sword) {
6833 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6835 if (weapons[i].getType() == staff) {
6836 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6838 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6839 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) {
6840 weaponrotatemuscle = j;
6844 if (weaponstuck == k) {
6845 if (weaponstuckwhere == 0) {
6846 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8;
6848 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
6850 for (unsigned j = 0; j < skeleton.muscles.size(); j++) {
6851 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) {
6852 weaponrotatemuscle = j;
6856 if (skeleton.free) {
6857 weapons[i].position = weaponpoint * scale + coords;
6858 weapons[i].bigrotation = 0;
6859 weapons[i].bigtilt = 0;
6860 weapons[i].bigtilt2 = 0;
6862 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;
6863 weapons[i].bigrotation = yaw;
6864 weapons[i].bigtilt = tilt;
6865 weapons[i].bigtilt2 = tilt2;
6867 weapons[i].rotation1 = skeleton.muscles[weaponrotatemuscle].lastrotate1;
6868 weapons[i].rotation2 = skeleton.muscles[weaponrotatemuscle].lastrotate2;
6869 weapons[i].rotation3 = skeleton.muscles[weaponrotatemuscle].lastrotate3;
6870 if (weaponactive == k) {
6871 if (weapons[i].getType() == knife) {
6872 weapons[i].smallrotation = 180;
6873 weapons[i].smallrotation2 = 0;
6874 if (isCrouch() || wasCrouch()) {
6875 weapons[i].smallrotation2 = 20;
6877 if (animTarget == hurtidleanim) {
6878 weapons[i].smallrotation2 = 50;
6880 if ((animCurrent == crouchstabanim && animTarget == crouchstabanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
6881 XYZ temppoint1, temppoint2;
6884 temppoint1 = jointPos(righthand);
6885 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
6886 distance = findDistance(&temppoint1, &temppoint2);
6887 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6888 weapons[i].rotation2 *= 360 / 6.28;
6891 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6892 weapons[i].rotation1 *= 360 / 6.28;
6893 weapons[i].rotation3 = 0;
6894 weapons[i].smallrotation = -90;
6895 weapons[i].smallrotation2 = 0;
6896 if (temppoint1.x > temppoint2.x) {
6897 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6900 if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) {
6901 XYZ temppoint1, temppoint2;
6904 temppoint1 = jointPos(righthand);
6905 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
6906 distance = findDistance(&temppoint1, &temppoint2);
6907 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6908 weapons[i].rotation2 *= 360 / 6.28;
6911 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6912 weapons[i].rotation1 *= 360 / 6.28;
6913 weapons[i].rotation3 = 0;
6914 weapons[i].smallrotation = 90;
6915 weapons[i].smallrotation2 = 0;
6916 if (temppoint1.x > temppoint2.x) {
6917 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6920 if (animTarget == knifethrowanim) {
6921 weapons[i].smallrotation = 90;
6922 //weapons[i].smallrotation2=-90;
6923 weapons[i].smallrotation2 = 0;
6924 weapons[i].rotation1 = 0;
6925 weapons[i].rotation2 = 0;
6926 weapons[i].rotation3 = 0;
6928 if (animTarget == knifesneakattackanim && frameTarget < 5) {
6929 weapons[i].smallrotation = -90;
6930 weapons[i].rotation1 = 0;
6931 weapons[i].rotation2 = 0;
6932 weapons[i].rotation3 = 0;
6935 if (weapons[i].getType() == sword) {
6936 weapons[i].smallrotation = 0;
6937 weapons[i].smallrotation2 = 0;
6938 if (animTarget == knifethrowanim) {
6939 weapons[i].smallrotation = -90;
6940 weapons[i].smallrotation2 = 0;
6941 weapons[i].rotation1 = 0;
6942 weapons[i].rotation2 = 0;
6943 weapons[i].rotation3 = 0;
6945 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)) {
6946 XYZ temppoint1, temppoint2;
6949 temppoint1 = currentFrame().joints[skeleton.jointlabels[righthand]].position * (1 - target) + targetFrame().joints[skeleton.jointlabels[righthand]].position * (target); //jointPos(righthand);
6950 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
6951 distance = findDistance(&temppoint1, &temppoint2);
6952 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6953 weapons[i].rotation2 *= 360 / 6.28;
6956 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6957 weapons[i].rotation1 *= 360 / 6.28;
6958 weapons[i].rotation3 = 0;
6959 weapons[i].smallrotation = 90;
6960 weapons[i].smallrotation2 = 0;
6961 if (temppoint1.x > temppoint2.x) {
6962 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6966 if (weapons[i].getType() == staff) {
6967 weapons[i].smallrotation = 100;
6968 weapons[i].smallrotation2 = 0;
6969 if ((animTarget == staffhitanim && animCurrent == staffhitanim) || (animTarget == staffhitreversedanim && animCurrent == staffhitreversedanim) || (animTarget == staffspinhitreversedanim && animCurrent == staffspinhitreversedanim) || (animTarget == staffgroundsmashanim && animCurrent == staffgroundsmashanim) || (animTarget == staffspinhitanim && animCurrent == staffspinhitanim)) {
6970 XYZ temppoint1, temppoint2;
6973 temppoint1 = currentFrame().joints[skeleton.jointlabels[righthand]].position * (1 - target) + targetFrame().joints[skeleton.jointlabels[righthand]].position * (target); //jointPos(righthand);
6974 temppoint2 = currentFrame().weapontarget * (1 - target) + targetFrame().weapontarget * (target);
6975 distance = findDistance(&temppoint1, &temppoint2);
6976 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6977 weapons[i].rotation2 *= 360 / 6.28;
6980 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6981 weapons[i].rotation1 *= 360 / 6.28;
6982 weapons[i].rotation3 = 0;
6983 weapons[i].smallrotation = 90;
6984 weapons[i].smallrotation2 = 0;
6985 if (temppoint1.x > temppoint2.x) {
6986 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6991 if (weaponactive != k && weaponstuck != k) {
6992 if (weapons[i].getType() == knife) {
6993 weapons[i].smallrotation = -70;
6994 weapons[i].smallrotation2 = 10;
6996 if (weapons[i].getType() == sword) {
6997 weapons[i].smallrotation = -100;
6998 weapons[i].smallrotation2 = -8;
7000 if (weapons[i].getType() == staff) {
7001 weapons[i].smallrotation = -100;
7002 weapons[i].smallrotation2 = -8;
7005 if (weaponstuck == k) {
7006 if (weaponstuckwhere == 0) {
7007 weapons[i].smallrotation = 180;
7009 weapons[i].smallrotation = 0;
7011 weapons[i].smallrotation2 = 10;
7018 if (skeleton.free) {
7021 if (Animation::animations[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isWallJump()) {
7024 if (animCurrent != animTarget) {
7027 if (skeleton.free == 2) {
7036 int Person::SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, Model* model)
7038 static float distance;
7039 static float olddistance;
7040 static int intersecting;
7041 static int firstintersecting;
7044 static XYZ start, end;
7045 static float slopethreshold = -.4;
7047 firstintersecting = -1;
7051 if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius) {
7055 *p1 = DoRotation(*p1, 0, -*rotate, 0);
7057 for (int i = 0; i < 4; i++) {
7058 for (unsigned int j = 0; j < model->Triangles.size(); j++) {
7059 if (model->Triangles[j].facenormal.y <= slopethreshold) {
7061 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)));
7062 if (distance < radius) {
7063 point = *p1 - model->Triangles[j].facenormal * distance;
7064 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]])) {
7067 if (!intersecting) {
7068 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
7069 &model->vertex[model->Triangles[j].vertex[1]],
7072 if (!intersecting) {
7073 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
7074 &model->vertex[model->Triangles[j].vertex[2]],
7077 if (!intersecting) {
7078 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
7079 &model->vertex[model->Triangles[j].vertex[2]],
7083 if (dotproduct(&model->Triangles[j].facenormal, &end) > 0 && intersecting) {
7087 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)) {
7088 p1->y = point.y + radius;
7089 if ((animTarget == jumpdownanim || isFlip())) {
7090 if (isFlip() && (frameTarget < 5 || targetFrame().label == 7 || targetFrame().label == 4)) {
7094 if (animTarget == jumpupanim) {
7096 animTarget = getIdle();
7103 pause_sound(whooshsound);
7104 OPENAL_SetVolume(channels[whooshsound], 0);
7107 if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) {
7111 animTarget = getLanding();
7112 emit_sound_at(landsound, coords, 128.);
7115 addEnvSound(coords);
7122 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
7123 olddistance = distance;
7124 firstintersecting = j;
7129 for (unsigned int j = 0; j < model->Triangles.size(); j++) {
7130 if (model->Triangles[j].facenormal.y > slopethreshold) {
7133 start.y -= radius / 4;
7134 XYZ& v0 = model->vertex[model->Triangles[j].vertex[0]];
7135 XYZ& v1 = model->vertex[model->Triangles[j].vertex[1]];
7136 XYZ& v2 = model->vertex[model->Triangles[j].vertex[2]];
7137 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)));
7138 if (distance < radius * .5) {
7139 point = start - model->Triangles[j].facenormal * distance;
7140 if (PointInTriangle(&point, model->Triangles[j].facenormal, &v0, &v1, &v2)) {
7143 if (!intersecting) {
7144 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
7146 if (!intersecting) {
7147 intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
7149 if (!intersecting) {
7150 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
7153 if (dotproduct(&model->Triangles[j].facenormal, &end) > 0 && intersecting) {
7154 if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
7156 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;
7157 if (findLengthfast(&start) < findLengthfast(&velocity)) {
7161 *p1 += model->Triangles[j].facenormal * (distance - radius * .5);
7164 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
7165 olddistance = distance;
7166 firstintersecting = j;
7173 *p = DoRotation(*p, 0, *rotate, 0);
7177 *p1 = DoRotation(*p1, 0, *rotate, 0);
7180 return firstintersecting;
7183 int findPathDist(int start, int end)
7188 unsigned int smallestcount = 1000;
7189 for (char i = 0; i < 50; i++) {
7190 unsigned int count = 0;
7195 while (last != end && count < 30) {
7197 for (int j = 0; j < Game::numpathpoints; j++) {
7198 if (j != last && j != last2 && j != last3 && j != last4) {
7200 if (Game::numpathpointconnect[j]) {
7201 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7202 if (Game::pathpointconnect[j][k] == last) {
7208 if (Game::numpathpointconnect[last]) {
7209 for (int k = 0; k < Game::numpathpointconnect[last]; k++) {
7210 if (Game::pathpointconnect[last][k] == j) {
7217 if (closest == -1 || Random() % 2 == 0) {
7229 if (count < smallestcount) {
7230 smallestcount = count;
7233 return smallestcount;
7236 void Person::takeWeapon(int weaponId)
7239 weapons[weaponId].owner = id;
7240 if (num_weapons > 0) {
7241 weaponids[num_weapons] = weaponids[0];
7244 weaponids[0] = weaponId;
7247 void Person::addClothes()
7249 if (numclothes > 0) {
7250 for (int i = 0; i < numclothes; i++) {
7257 bool Person::addClothes(const int& clothesId)
7260 const std::string fileName = clothes[clothesId];
7262 GLubyte* array = &skeleton.skinText[0];
7266 bool opened = load_image(Folders::getResourcePath(fileName).c_str(), texture);
7271 float tintr = clothestintr[clothesId];
7272 float tintg = clothestintg[clothesId];
7273 float tintb = clothestintb[clothesId];
7295 int bytesPerPixel = texture.bpp / 8;
7299 for (int i = 0; i < (int)(texture.sizeY * texture.sizeX * bytesPerPixel); i++) {
7300 if (bytesPerPixel == 3) {
7302 } else if ((i + 1) % 4 == 0) {
7303 alphanum = texture.data[i];
7305 if ((i + 1) % 4 || bytesPerPixel == 3) {
7307 texture.data[i] *= tintr;
7310 texture.data[i] *= tintg;
7313 texture.data[i] *= tintb;
7315 array[tempnum] = (float)array[tempnum] * (1 - alphanum / 255) + (float)texture.data[i] * (alphanum / 255);
7327 if (!isPlayerControlled() && !Dialog::inDialog()) {
7329 //disable movement in editor
7330 if (Game::editorenabled) {
7335 if (distsqflat(&Person::players[0]->coords, &coords) < 30 &&
7336 Person::players[0]->coords.y > coords.y + 2 &&
7337 !Person::players[0]->onterrain) {
7342 if (aitype == pathfindtype) {
7343 if (finalpathfindpoint == -1) {
7344 float closestdistance;
7345 float tempdist = 0.0f;
7349 closestdistance = -1;
7350 for (int j = 0; j < Game::numpathpoints; j++) {
7351 if (closest == -1 || distsq(&finalfinaltarget, &Game::pathpoint[j]) < closestdistance) {
7352 closestdistance = distsq(&finalfinaltarget, &Game::pathpoint[j]);
7354 finaltarget = Game::pathpoint[j];
7357 finalpathfindpoint = closest;
7358 for (int j = 0; j < Game::numpathpoints; j++) {
7359 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7360 DistancePointLine(&finalfinaltarget, &Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]], &tempdist, &colpoint);
7361 if (sq(tempdist) < closestdistance) {
7362 if (findDistance(&colpoint, &Game::pathpoint[j]) + findDistance(&colpoint, &Game::pathpoint[Game::pathpointconnect[j][k]]) <
7363 findDistance(&Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]]) + .1) {
7364 closestdistance = sq(tempdist);
7366 finaltarget = colpoint;
7371 finalpathfindpoint = closest;
7373 if (targetpathfindpoint == -1) {
7374 float closestdistance;
7375 float tempdist = 0.0f;
7379 closestdistance = -1;
7380 if (lastpathfindpoint == -1) {
7381 for (int j = 0; j < Game::numpathpoints; j++) {
7382 if (j != lastpathfindpoint) {
7383 if (closest == -1 || (distsq(&coords, &Game::pathpoint[j]) < closestdistance)) {
7384 closestdistance = distsq(&coords, &Game::pathpoint[j]);
7389 targetpathfindpoint = closest;
7390 for (int j = 0; j < Game::numpathpoints; j++) {
7391 if (j != lastpathfindpoint) {
7392 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7393 DistancePointLine(&coords, &Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]], &tempdist, &colpoint);
7394 if (sq(tempdist) < closestdistance) {
7395 if (findDistance(&colpoint, &Game::pathpoint[j]) + findDistance(&colpoint, &Game::pathpoint[Game::pathpointconnect[j][k]]) <
7396 findDistance(&Game::pathpoint[j], &Game::pathpoint[Game::pathpointconnect[j][k]]) + .1) {
7397 closestdistance = sq(tempdist);
7404 targetpathfindpoint = closest;
7406 for (int j = 0; j < Game::numpathpoints; j++) {
7407 if (j != lastpathfindpoint &&
7408 j != lastpathfindpoint2 &&
7409 j != lastpathfindpoint3 &&
7410 j != lastpathfindpoint4) {
7412 if (Game::numpathpointconnect[j]) {
7413 for (int k = 0; k < Game::numpathpointconnect[j]; k++) {
7414 if (Game::pathpointconnect[j][k] == lastpathfindpoint) {
7420 if (Game::numpathpointconnect[lastpathfindpoint]) {
7421 for (int k = 0; k < Game::numpathpointconnect[lastpathfindpoint]; k++) {
7422 if (Game::pathpointconnect[lastpathfindpoint][k] == j) {
7429 tempdist = findPathDist(j, finalpathfindpoint);
7430 if (closest == -1 || tempdist < closestdistance) {
7431 closestdistance = tempdist;
7437 targetpathfindpoint = closest;
7440 losupdatedelay -= multiplier;
7442 targetyaw = roughDirectionTo(coords, Game::pathpoint[targetpathfindpoint]);
7443 lookyaw = targetyaw;
7445 //reached target point
7446 if (distsqflat(&coords, &Game::pathpoint[targetpathfindpoint]) < .6) {
7447 lastpathfindpoint4 = lastpathfindpoint3;
7448 lastpathfindpoint3 = lastpathfindpoint2;
7449 lastpathfindpoint2 = lastpathfindpoint;
7450 lastpathfindpoint = targetpathfindpoint;
7451 if (lastpathfindpoint2 == -1) {
7452 lastpathfindpoint2 = lastpathfindpoint;
7454 if (lastpathfindpoint3 == -1) {
7455 lastpathfindpoint3 = lastpathfindpoint2;
7457 if (lastpathfindpoint4 == -1) {
7458 lastpathfindpoint4 = lastpathfindpoint3;
7460 targetpathfindpoint = -1;
7462 if (distsqflat(&coords, &finalfinaltarget) <
7463 distsqflat(&coords, &finaltarget) ||
7464 distsqflat(&coords, &finaltarget) < .6 * sq(scale * 5) ||
7465 lastpathfindpoint == finalpathfindpoint) {
7466 aitype = passivetype;
7477 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
7478 targetyaw += 90 * (whichdirection * 2 - 1);
7481 if (collided < 1 || animTarget != jumpupanim) {
7484 if ((collided > .8 && jumppower >= 5)) {
7488 if ((!Tutorial::active || cananger) &&
7490 !Person::players[0]->dead &&
7491 distsq(&coords, &Person::players[0]->coords) < 400 &&
7493 if (distsq(&coords, &Person::players[0]->coords) < 12 &&
7494 Animation::animations[Person::players[0]->animTarget].height != lowheight &&
7495 !Game::editorenabled &&
7496 (Person::players[0]->coords.y < coords.y + 5 || Person::players[0]->onterrain)) {
7497 aitype = attacktypecutoff;
7499 if (distsq(&coords, &Person::players[0]->coords) < 30 &&
7500 Animation::animations[Person::players[0]->animTarget].height == highheight &&
7501 !Game::editorenabled) {
7502 aitype = attacktypecutoff;
7505 if (losupdatedelay < 0 && !Game::editorenabled && occluded < 2) {
7506 losupdatedelay = .2;
7507 for (unsigned j = 0; j < Person::players.size(); j++) {
7508 if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) {
7509 if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) {
7510 if (distsq(&coords, &Person::players[j]->coords) < 400) {
7511 if (normaldotproduct(facing, Person::players[j]->coords - coords) > 0) {
7512 if (Person::players[j]->coords.y < coords.y + 5 || Person::players[j]->onterrain) {
7513 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) ||
7514 (Person::players[j]->animTarget == hanganim &&
7515 normaldotproduct(Person::players[j]->facing, coords - Person::players[j]->coords) < 0)) {
7516 aitype = searchtype;
7518 lastseen = Person::players[j]->coords;
7529 if (aitype == attacktypecutoff && Game::musictype != 2) {
7530 if (creature != wolftype) {
7537 if (aitype != passivetype && Game::leveltime > .5) {
7538 howactive = typeactive;
7541 if (aitype == passivetype) {
7542 aiupdatedelay -= multiplier;
7543 losupdatedelay -= multiplier;
7544 lastseentime += multiplier;
7545 pausetime -= multiplier;
7546 if (lastseentime > 1) {
7550 if (aiupdatedelay < 0) {
7551 if (numwaypoints > 1 && howactive == typeactive && pausetime <= 0) {
7552 targetyaw = roughDirectionTo(coords, waypoints[waypoint]);
7553 lookyaw = targetyaw;
7554 aiupdatedelay = .05;
7556 if (distsqflat(&coords, &waypoints[waypoint]) < 1) {
7557 if (waypointtype[waypoint] == wppause) {
7561 if (waypoint > numwaypoints - 1) {
7567 if (numwaypoints > 1 && howactive == typeactive && pausetime <= 0) {
7579 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
7580 if (!avoidsomething) {
7581 targetyaw += 90 * (whichdirection * 2 - 1);
7583 XYZ leftpos, rightpos;
7584 float leftdist, rightdist;
7585 leftpos = coords + DoRotation(facing, 0, 90, 0);
7586 rightpos = coords - DoRotation(facing, 0, 90, 0);
7587 leftdist = distsq(&leftpos, &avoidwhere);
7588 rightdist = distsq(&rightpos, &avoidwhere);
7589 if (leftdist < rightdist) {
7597 if (collided < 1 || animTarget != jumpupanim) {
7600 if ((collided > .8 && jumppower >= 5)) {
7605 if (!Game::editorenabled) {
7606 if (howactive <= typesleeping) {
7607 if (numenvsounds > 0 && (!Tutorial::active || cananger) && hostile) {
7608 for (int j = 0; j < numenvsounds; j++) {
7609 float vol = howactive == typesleeping ? envsoundvol[j] - 14 : envsoundvol[j];
7610 if (vol > 0 && distsq(&coords, &envsound[j]) < 2 * (vol + vol * (creature == rabbittype) * 3)) {
7611 aitype = attacktypecutoff;
7617 if (aitype != passivetype) {
7618 if (howactive == typesleeping) {
7619 setTargetAnimation(getupfromfrontanim);
7621 howactive = typeactive;
7625 if (howactive < typesleeping &&
7626 ((!Tutorial::active || cananger) && hostile) &&
7627 !Person::players[0]->dead &&
7628 distsq(&coords, &Person::players[0]->coords) < 400 &&
7630 if (distsq(&coords, &Person::players[0]->coords) < 12 &&
7631 Animation::animations[Person::players[0]->animTarget].height != lowheight && !Game::editorenabled) {
7632 aitype = attacktypecutoff;
7634 if (distsq(&coords, &Person::players[0]->coords) < 30 &&
7635 Animation::animations[Person::players[0]->animTarget].height == highheight && !Game::editorenabled) {
7636 aitype = attacktypecutoff;
7640 if (creature == wolftype) {
7642 for (unsigned j = 0; j < Person::players.size(); j++) {
7643 if (j == 0 || (Person::players[j]->dead && Person::players[j]->bloodloss > 0)) {
7644 float smelldistance = 50;
7645 if (j == 0 && Person::players[j]->num_weapons > 0) {
7646 if (weapons[Person::players[j]->weaponids[0]].bloody) {
7647 smelldistance = 100;
7649 if (Person::players[j]->num_weapons == 2) {
7650 if (weapons[Person::players[j]->weaponids[1]].bloody) {
7651 smelldistance = 100;
7656 smelldistance = 100;
7658 windsmell = windvector;
7659 Normalise(&windsmell);
7660 windsmell = windsmell * 2 + Person::players[j]->coords;
7661 if (distsq(&coords, &windsmell) < smelldistance && !Game::editorenabled) {
7662 aitype = attacktypecutoff;
7668 if (howactive < typesleeping && losupdatedelay < 0 && !Game::editorenabled && occluded < 2) {
7669 losupdatedelay = .2;
7670 for (unsigned j = 0; j < Person::players.size(); j++) {
7671 if (j == 0 || Person::players[j]->skeleton.free || Person::players[j]->aitype != passivetype) {
7672 if (abs(Random() % 2) || Animation::animations[Person::players[j]->animTarget].height != lowheight || j != 0) {
7673 if (distsq(&coords, &Person::players[j]->coords) < 400) {
7674 if (normaldotproduct(facing, Person::players[j]->coords - coords) > 0) {
7675 if ((-1 == Object::checkcollide(
7676 DoRotation(jointPos(head), 0, yaw, 0) *
7679 DoRotation(Person::players[j]->jointPos(head), 0, Person::players[j]->yaw, 0) *
7680 Person::players[j]->scale +
7681 Person::players[j]->coords) &&
7682 !Person::players[j]->isWallJump()) ||
7683 (Person::players[j]->animTarget == hanganim &&
7684 normaldotproduct(Person::players[j]->facing, coords - Person::players[j]->coords) < 0)) {
7686 if (j == 0 && Animation::animations[Person::players[j]->animTarget].height == lowheight) {
7695 if (lastseentime <= 0) {
7696 aitype = searchtype;
7698 lastseen = Person::players[j]->coords;
7706 if (aitype == attacktypecutoff && Game::musictype != 2) {
7707 if (creature != wolftype) {
7711 if (creature == wolftype) {
7721 if (aitype == searchtype) {
7722 aiupdatedelay -= multiplier;
7723 losupdatedelay -= multiplier;
7725 lastseentime -= multiplier;
7727 lastchecktime -= multiplier;
7729 if (isRun() && !onground) {
7730 if (coords.y > terrain.getHeight(coords.x, coords.z) + 10) {
7731 XYZ test2 = coords + facing;
7733 XYZ test = coords + facing;
7735 j = Object::checkcollide(test2, test, laststanding);
7737 j = Object::checkcollide(test2, test);
7741 setTargetAnimation(getStop());
7744 //aitype=passivetype;
7745 aitype = pathfindtype;
7746 finalfinaltarget = waypoints[waypoint];
7747 finalpathfindpoint = -1;
7748 targetpathfindpoint = -1;
7749 lastpathfindpoint = -1;
7750 lastpathfindpoint2 = -1;
7751 lastpathfindpoint3 = -1;
7752 lastpathfindpoint4 = -1;
7758 //check out last seen location
7759 if (aiupdatedelay < 0) {
7760 targetyaw = roughDirectionTo(coords, lastseen);
7761 lookyaw = targetyaw;
7762 aiupdatedelay = .05;
7765 if (distsqflat(&coords, &lastseen) < 1 * sq(scale * 5) || lastchecktime < 0) {
7768 lastseen.x += (float(Random() % 100) - 50) / 25;
7769 lastseen.z += (float(Random() % 100) - 50) / 25;
7780 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
7781 if (!avoidsomething) {
7782 targetyaw += 90 * (whichdirection * 2 - 1);
7784 XYZ leftpos, rightpos;
7785 float leftdist, rightdist;
7786 leftpos = coords + DoRotation(facing, 0, 90, 0);
7787 rightpos = coords - DoRotation(facing, 0, 90, 0);
7788 leftdist = distsq(&leftpos, &avoidwhere);
7789 rightdist = distsq(&rightpos, &avoidwhere);
7790 if (leftdist < rightdist) {
7798 if (collided < 1 || animTarget != jumpupanim) {
7801 if ((collided > .8 && jumppower >= 5)) {
7805 if (numenvsounds > 0 && ((!Tutorial::active || cananger) && hostile)) {
7806 for (int k = 0; k < numenvsounds; k++) {
7807 if (distsq(&coords, &envsound[k]) < 2 * (envsoundvol[k] + envsoundvol[k] * (creature == rabbittype) * 3)) {
7808 aitype = attacktypecutoff;
7813 if (!Person::players[0]->dead &&
7814 losupdatedelay < 0 &&
7815 !Game::editorenabled &&
7817 ((!Tutorial::active || cananger) && hostile)) {
7818 losupdatedelay = .2;
7819 if (distsq(&coords, &Person::players[0]->coords) < 4 && Animation::animations[animTarget].height != lowheight) {
7820 aitype = attacktypecutoff;
7823 if (abs(Random() % 2) || Animation::animations[animTarget].height != lowheight) {
7824 //TODO: factor out canSeePlayer()
7825 if (distsq(&coords, &Person::players[0]->coords) < 400) {
7826 if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) {
7827 if ((Object::checkcollide(
7828 DoRotation(jointPos(head), 0, yaw, 0) *
7831 DoRotation(Person::players[0]->jointPos(head), 0, Person::players[0]->yaw, 0) *
7832 Person::players[0]->scale +
7833 Person::players[0]->coords) == -1) ||
7834 (Person::players[0]->animTarget == hanganim && normaldotproduct(Person::players[0]->facing, coords - Person::players[0]->coords) < 0)) {
7835 /* //TODO: changed j to 0 on a whim, make sure this is correct
7836 (Person::players[j]->animTarget==hanganim&&normaldotproduct(
7837 Person::players[j]->facing,coords-Person::players[j]->coords)<0)
7839 aitype = attacktypecutoff;
7847 if (lastseentime < 0) {
7848 //aitype=passivetype;
7850 aitype = pathfindtype;
7851 finalfinaltarget = waypoints[waypoint];
7852 finalpathfindpoint = -1;
7853 targetpathfindpoint = -1;
7854 lastpathfindpoint = -1;
7855 lastpathfindpoint2 = -1;
7856 lastpathfindpoint3 = -1;
7857 lastpathfindpoint4 = -1;
7861 if (aitype != gethelptype) {
7865 //get help from buddies
7866 if (aitype == gethelptype) {
7867 runninghowlong += multiplier;
7868 aiupdatedelay -= multiplier;
7870 if (aiupdatedelay < 0 || ally == 0) {
7874 //TODO: factor out closest search somehow
7877 float closestdist = -1;
7878 for (unsigned k = 0; k < Person::players.size(); k++) {
7879 if ((k != id) && (k != 0) && !Person::players[k]->dead &&
7880 (Person::players[k]->howactive < typedead1) &&
7881 !Person::players[k]->skeleton.free &&
7882 (Person::players[k]->aitype == passivetype)) {
7883 float distance = distsq(&coords, &Person::players[k]->coords);
7884 if (closestdist == -1 || distance < closestdist) {
7885 closestdist = distance;
7890 if (closest != -1) {
7895 lastseen = Person::players[0]->coords;
7901 XYZ facing = coords;
7902 XYZ flatfacing = Person::players[ally]->coords;
7903 facing.y += jointPos(head).y * scale;
7904 flatfacing.y += Person::players[ally]->jointPos(head).y * Person::players[ally]->scale;
7905 if (-1 != Object::checkcollide(facing, flatfacing)) {
7909 //no available ally, run back to player
7911 Person::players[ally]->skeleton.free ||
7912 Person::players[ally]->aitype != passivetype ||
7913 lastseentime <= 0) {
7914 aitype = searchtype;
7920 targetyaw = roughDirectionTo(coords, Person::players[ally]->coords);
7921 lookyaw = targetyaw;
7922 aiupdatedelay = .05;
7925 if (distsqflat(&coords, &Person::players[ally]->coords) < 3) {
7926 aitype = searchtype;
7928 Person::players[ally]->aitype = searchtype;
7929 if (Person::players[ally]->lastseentime < lastseentime) {
7930 Person::players[ally]->lastseen = lastseen;
7931 Person::players[ally]->lastseentime = lastseentime;
7932 Person::players[ally]->lastchecktime = lastchecktime;
7936 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
7937 if (!avoidsomething) {
7938 targetyaw += 90 * (whichdirection * 2 - 1);
7940 XYZ leftpos, rightpos;
7941 float leftdist, rightdist;
7942 leftpos = coords + DoRotation(facing, 0, 90, 0);
7943 rightpos = coords - DoRotation(facing, 0, 90, 0);
7944 leftdist = distsq(&leftpos, &avoidwhere);
7945 rightdist = distsq(&rightpos, &avoidwhere);
7946 if (leftdist < rightdist) {
7961 if (collided < 1 || animTarget != jumpupanim) {
7964 if (collided > .8 && jumppower >= 5) {
7969 //retreiving a weapon on the ground
7970 if (aitype == getweapontype) {
7971 aiupdatedelay -= multiplier;
7972 lastchecktime -= multiplier;
7974 if (aiupdatedelay < 0) {
7980 float closestdist = -1;
7981 for (unsigned k = 0; k < weapons.size(); k++) {
7982 if (weapons[k].owner == -1) {
7983 float distance = distsq(&coords, &weapons[k].position);
7984 if (closestdist == -1 || distance < closestdist) {
7985 closestdist = distance;
7990 if (closest != -1) {
7999 if (!Person::players[0]->dead && ((!Tutorial::active || cananger) && hostile)) {
8000 if (ally < 0 || hasWeapon() || lastchecktime <= 0) {
8001 aitype = attacktypecutoff;
8005 if (!Person::players[0]->dead) {
8007 if (weapons[ally].owner != -1 ||
8008 distsq(&coords, &weapons[ally].position) > 16) {
8009 aitype = attacktypecutoff;
8012 //TODO: factor these out as moveToward()
8013 targetyaw = roughDirectionTo(coords, weapons[ally].position);
8014 lookyaw = targetyaw;
8015 aiupdatedelay = .05;
8018 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
8019 if (!avoidsomething) {
8020 targetyaw += 90 * (whichdirection * 2 - 1);
8022 XYZ leftpos, rightpos;
8023 float leftdist, rightdist;
8024 leftpos = coords + DoRotation(facing, 0, 90, 0);
8025 rightpos = coords - DoRotation(facing, 0, 90, 0);
8026 leftdist = distsq(&leftpos, &avoidwhere);
8027 rightdist = distsq(&rightpos, &avoidwhere);
8028 if (leftdist < rightdist) {
8044 if (animTarget != crouchremoveknifeanim &&
8045 animTarget != removeknifeanim) {
8046 throwtogglekeydown = 0;
8050 if (collided < 1 || animTarget != jumpupanim) {
8053 if ((collided > .8 && jumppower >= 5)) {
8058 if (aitype == attacktypecutoff) {
8059 aiupdatedelay -= multiplier;
8060 //dodge or reverse rabbit kicks, knife throws, flips
8061 if (damage < damagetolerance * 2 / 3) {
8062 if ((Person::players[0]->animTarget == rabbitkickanim ||
8063 Person::players[0]->animTarget == knifethrowanim ||
8064 (Person::players[0]->isFlip() &&
8065 normaldotproduct(Person::players[0]->facing, Person::players[0]->coords - coords) < 0)) &&
8066 !Person::players[0]->skeleton.free &&
8067 (aiupdatedelay < .1)) {
8072 if (Person::players[0]->animTarget != rabbitkickanim && Person::players[0]->hasWeapon()) {
8073 if (weapons[Person::players[0]->weaponids[0]].getType() == knife) {
8074 if (isIdle() || isCrouch() || isRun() || isFlip()) {
8075 if (abs(Random() % 2) == 0) {
8076 setTargetAnimation(backhandspringanim);
8078 setTargetAnimation(rollanim);
8080 targetyaw += 90 * (abs(Random() % 2) * 2 - 1);
8083 if (animTarget == jumpupanim || animTarget == jumpdownanim) {
8084 setTargetAnimation(flipanim);
8089 aiupdatedelay = .02;
8092 //get confused by flips
8093 if (Person::players[0]->isFlip() &&
8094 !Person::players[0]->skeleton.free &&
8095 Person::players[0]->animTarget != walljumprightkickanim &&
8096 Person::players[0]->animTarget != walljumpleftkickanim) {
8097 if (distsq(&Person::players[0]->coords, &coords) < 25) {
8098 if ((1 - damage / damagetolerance) > .5) {
8103 //go for weapon on the ground
8104 if (wentforweapon < 3) {
8105 for (unsigned k = 0; k < weapons.size(); k++) {
8106 if (creature != wolftype) {
8107 if (num_weapons == 0 &&
8108 weapons[k].owner == -1 &&
8109 weapons[k].velocity.x == 0 &&
8110 weapons[k].velocity.z == 0 &&
8111 weapons[k].velocity.y == 0) {
8112 if (distsq(&coords, &weapons[k].position) < 16) {
8115 aitype = getweapontype;
8122 //dodge/reverse walljump kicks
8123 if (damage < damagetolerance / 2) {
8124 if (Animation::animations[animTarget].height != highheight) {
8125 if (damage < damagetolerance * .5 &&
8126 ((Person::players[0]->animTarget == walljumprightkickanim ||
8127 Person::players[0]->animTarget == walljumpleftkickanim) &&
8128 ((aiupdatedelay < .15 &&
8130 (aiupdatedelay < .08 &&
8131 difficulty != 2)))) {
8136 //walked off a ledge (?)
8137 if (isRun() && !onground) {
8138 if (coords.y > terrain.getHeight(coords.x, coords.z) + 10) {
8139 XYZ test2 = coords + facing;
8141 XYZ test = coords + facing;
8143 j = Object::checkcollide(test2, test, laststanding);
8145 j = Object::checkcollide(test2, test);
8149 setTargetAnimation(getStop());
8152 aitype = pathfindtype;
8153 finalfinaltarget = waypoints[waypoint];
8154 finalpathfindpoint = -1;
8155 targetpathfindpoint = -1;
8156 lastpathfindpoint = -1;
8157 lastpathfindpoint2 = -1;
8158 lastpathfindpoint3 = -1;
8159 lastpathfindpoint4 = -1;
8165 //lose sight of player in the air (?)
8166 if (Person::players[0]->coords.y > coords.y + 5 &&
8167 Animation::animations[Person::players[0]->animTarget].height != highheight &&
8168 !Person::players[0]->onterrain) {
8169 aitype = pathfindtype;
8170 finalfinaltarget = waypoints[waypoint];
8171 finalpathfindpoint = -1;
8172 targetpathfindpoint = -1;
8173 lastpathfindpoint = -1;
8174 lastpathfindpoint2 = -1;
8175 lastpathfindpoint3 = -1;
8176 lastpathfindpoint4 = -1;
8178 //it's time to think (?)
8179 if (aiupdatedelay < 0 &&
8180 !Animation::animations[animTarget].attack &&
8181 animTarget != staggerbackhighanim &&
8182 animTarget != staggerbackhardanim &&
8183 animTarget != backhandspringanim &&
8184 animTarget != dodgebackanim) {
8186 if (!hasWeapon() && num_weapons > 0) {
8187 drawkeydown = Random() % 2;
8191 rabbitkickenabled = Random() % 2;
8193 XYZ rotatetarget = Person::players[0]->coords + Person::players[0]->velocity;
8194 XYZ targetpoint = Person::players[0]->coords;
8195 float vellength = findLength(&velocity);
8196 if (vellength != 0 &&
8197 distsq(&Person::players[0]->coords, &coords) < distsq(&rotatetarget, &coords)) {
8198 targetpoint += Person::players[0]->velocity *
8199 findDistance(&Person::players[0]->coords, &coords) / vellength;
8201 targetyaw = roughDirectionTo(coords, targetpoint);
8202 lookyaw = targetyaw;
8203 aiupdatedelay = .2 + fabs((float)(Random() % 100) / 1000);
8205 if (distsq(&coords, &Person::players[0]->coords) > 5 && (!Person::players[0]->hasWeapon() || hasWeapon())) {
8207 } else if ((distsq(&coords, &Person::players[0]->coords) > 16 ||
8208 distsq(&coords, &Person::players[0]->coords) < 9) &&
8209 Person::players[0]->hasWeapon()) {
8211 } else if (Random() % 6 == 0 || (creature == wolftype && Random() % 3 == 0)) {
8216 //chill out around the corpse
8217 if (Person::players[0]->dead) {
8219 if (Random() % 10 == 0) {
8222 if (Random() % 100 == 0) {
8223 aitype = pathfindtype;
8224 finalfinaltarget = waypoints[waypoint];
8225 finalpathfindpoint = -1;
8226 targetpathfindpoint = -1;
8227 lastpathfindpoint = -1;
8228 lastpathfindpoint2 = -1;
8229 lastpathfindpoint3 = -1;
8230 lastpathfindpoint4 = -1;
8239 if (avoidcollided > .8 && !jumpkeydown && collided < .8) {
8240 targetyaw += 90 * (whichdirection * 2 - 1);
8243 if (Random() % 2 == 0 || hasWeapon() || creature == wolftype) {
8248 if (isRun() && Random() % 6 && distsq(&coords, &Person::players[0]->coords) > 7) {
8253 if (!isPlayerControlled() &&
8258 for (unsigned j = 0; j < Person::players.size(); j++) {
8259 if (j != id && !Person::players[j]->skeleton.free &&
8260 Person::players[j]->hasvictim &&
8261 (Tutorial::active && reversaltrain ||
8262 Random() % 2 == 0 && difficulty == 2 ||
8263 Random() % 4 == 0 && difficulty == 1 ||
8264 Random() % 8 == 0 && difficulty == 0 ||
8265 Person::players[j]->lastattack2 == Person::players[j]->animTarget &&
8266 Person::players[j]->lastattack3 == Person::players[j]->animTarget &&
8267 (Random() % 2 == 0 || difficulty == 2) ||
8268 (isIdle() || isRun()) &&
8269 Person::players[j]->hasWeapon() ||
8270 Person::players[j]->animTarget == swordslashanim &&
8272 Person::players[j]->animTarget == staffhitanim ||
8273 Person::players[j]->animTarget == staffspinhitanim)) {
8274 if (distsq(&Person::players[j]->coords, &Person::players[j]->victim->coords) < 4 &&
8275 Person::players[j]->victim == Person::players[id] &&
8276 (Person::players[j]->animTarget == sweepanim ||
8277 Person::players[j]->animTarget == spinkickanim ||
8278 Person::players[j]->animTarget == staffhitanim ||
8279 Person::players[j]->animTarget == staffspinhitanim ||
8280 Person::players[j]->animTarget == winduppunchanim ||
8281 Person::players[j]->animTarget == upunchanim ||
8282 Person::players[j]->animTarget == wolfslapanim ||
8283 Person::players[j]->animTarget == knifeslashstartanim ||
8284 Person::players[j]->animTarget == swordslashanim &&
8285 (distsq(&Person::players[j]->coords, &coords) < 2 ||
8296 Person::players[target]->Reverse();
8303 if (collided > .8 && jumppower >= 5 ||
8304 distsq(&coords, &Person::players[0]->coords) > 400 &&
8306 creature == rabbittype) {
8309 //TODO: why are we controlling the human?
8310 if (normaldotproduct(facing, Person::players[0]->coords - coords) > 0) {
8311 Person::players[0]->jumpkeydown = 0;
8313 if (Person::players[0]->animTarget == jumpdownanim &&
8314 distsq(&Person::players[0]->coords, &coords) < 40) {
8321 if (Tutorial::active) {
8327 XYZ facing = coords;
8328 XYZ flatfacing = Person::players[0]->coords;
8329 facing.y += jointPos(head).y * scale;
8330 flatfacing.y += Person::players[0]->jointPos(head).y * Person::players[0]->scale;
8331 if (occluded >= 2) {
8332 if (-1 != Object::checkcollide(facing, flatfacing)) {
8336 if (lastseentime <= 0 &&
8337 (creature != wolftype ||
8338 weaponstuck == -1)) {
8339 aitype = searchtype;
8341 lastseen = Person::players[0]->coords;
8350 if (Animation::animations[Person::players[0]->animTarget].height == highheight &&
8351 (aitype == attacktypecutoff ||
8352 aitype == searchtype)) {
8353 if (Person::players[0]->coords.y > terrain.getHeight(Person::players[0]->coords.x, Person::players[0]->coords.z) + 10) {
8354 XYZ test = Person::players[0]->coords;
8356 if (-1 == Object::checkcollide(Person::players[0]->coords, test)) {
8362 if (aitype == passivetype && !(numwaypoints > 1) ||
8364 pause && damage > superpermanentdamage) {
8383 XYZ flatfacing = DoRotation(facing, 0, yaw + 180, 0);
8384 facing = flatfacing;
8386 if (aitype == attacktypecutoff) {
8387 targetheadyaw = 180 - roughDirectionTo(coords, Person::players[0]->coords);
8388 targetheadpitch = pitchTo(coords, Person::players[0]->coords);
8389 } else if (howactive >= typesleeping) {
8390 targetheadyaw = targetyaw;
8391 targetheadpitch = 0;
8393 if (interestdelay <= 0) {
8394 interestdelay = .7 + (float)(abs(Random() % 100)) / 100;
8395 headtarget = coords;
8396 headtarget.x += (float)(abs(Random() % 200) - 100) / 100;
8397 headtarget.z += (float)(abs(Random() % 200) - 100) / 100;
8398 headtarget.y += (float)(abs(Random() % 200) - 100) / 300;
8399 headtarget += facing * 1.5;
8401 targetheadyaw = 180 - roughDirectionTo(coords, headtarget);
8402 targetheadpitch = pitchTo(coords, headtarget);
8407 bool Person::catchKnife()
8410 ((PersonType::types[creature].knifeCatchingType == 0) && (Random() % 2 != 0) && (!hasWeapon()) && (aitype == attacktypecutoff)) ||
8411 ((PersonType::types[creature].knifeCatchingType == 1) && (Random() % 3 != 0) && (!hasWeapon()) && (isIdle() || isRun() || animTarget == walkanim));