2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 /**> HEADER FILES <**/
23 #include "openal_wrapper.h"
24 #include "Animation.h"
29 extern float multiplier;
30 extern Terrain terrain;
32 extern int environment;
34 extern FRUSTUM frustum;
36 extern float realmultiplier;
38 extern float slomodelay;
39 extern bool cellophane;
40 extern float texdetail;
41 extern float realtexdetail;
42 extern GLubyte bloodText[512 * 512 * 3];
43 extern GLubyte wolfbloodText[512 * 512 * 3];
44 extern int bloodtoggle;
45 extern Objects objects;
46 extern bool autoslomo;
47 extern float camerashake;
49 extern float viewdistance;
50 extern float blackout;
51 extern int difficulty;
53 extern float fadestart;
55 extern bool winfreeze;
56 extern float flashamount, flashr, flashg, flashb;
57 extern int flashdelay;
58 extern bool showpoints;
59 extern bool immediate;
61 extern bool tilt2weird;
62 extern bool tiltweird;
64 extern bool proportionweird;
65 extern bool vertexweird[6];
66 extern XYZ envsound[30];
67 extern float envsoundvol[30];
68 extern float envsoundlife[30];
69 extern int numenvsounds;
70 extern int tutoriallevel;
71 extern float smoketex;
72 extern int tutorialstage;
73 extern bool reversaltrain;
74 extern bool canattack;
76 extern float damagedealt;
78 extern float hostiletime;
80 extern int indialogue;
82 extern bool gamestarted;
84 std::vector<std::shared_ptr<Person>> Person::players(1, std::shared_ptr<Person>(new Person()));
89 * GameTick/doPlayerCollisions
91 void Person::CheckKick()
94 && (animTarget == rabbitkickanim
96 && victim != this->shared_from_this()
98 && animCurrent == rabbitkickanim)
99 && distsq(&coords, &victim->coords) < 1.2
100 && !victim->skeleton.free))
103 if (animation[victim->animTarget].height != lowheight) {
104 float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
105 XYZ relative = velocity;
107 Normalise(&relative);
111 if (tutoriallevel != 1)
112 emit_sound_at(heavyimpactsound, victim->coords);
114 for (int i = 0; i < victim->skeleton.num_joints; i++) {
115 victim->skeleton.joints[i].velocity += relative * 120 * damagemult;
118 victim->DoDamage(100 * damagemult / victim->protectionhigh);
124 animTarget = backflipanim;
126 velocity = facing * -10;
130 resume_stream(whooshsound);
132 award_bonus(id, cannon);
133 } else if (victim->isCrouch()) {
134 animTarget = rabbitkickreversedanim;
135 animCurrent = rabbitkickreversedanim;
136 victim->animCurrent = rabbitkickreversalanim;
137 victim->animTarget = rabbitkickreversalanim;
143 victim->oldcoords = victim->coords;
144 coords = victim->coords;
145 victim->targetyaw = targetyaw;
146 victim->victim = this->shared_from_this();
153 * GameTick/doPlayerCollisions - spread fire between players
154 * GameTick/doDebugKeys - press f to ignite
155 * Person::DoStuff - spread fire from lit campfires and bushes
157 void Person::CatchFire()
159 XYZ flatfacing, flatvelocity;
161 for (int i = 0; i < 10; i++) {
162 howmany = abs(Random() % (skeleton.num_joints));
164 flatvelocity = velocity;
166 flatvelocity = skeleton.joints[howmany].velocity;
168 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
170 flatfacing = skeleton.joints[howmany].position * scale + coords;
171 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
176 emit_sound_at(firestartsound, coords);
178 emit_stream_at(stream_firesound, coords);
186 * idle animation for this creature (depending on status)
188 int Person::getIdle()
190 if (indialogue != -1 && howactive == typeactive && creature == rabbittype)
192 if (hasvictim && (victim != this->shared_from_this())/*||(id==0&&attackkeydown)*/)
193 if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype &&
194 victim->aitype != searchtype && aitype != passivetype && aitype != searchtype &&
195 victim->id < Person::players.size())) {
196 if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) {
197 if (creature == rabbittype)
198 return fightidleanim;
199 if (creature == wolftype)
202 if (aitype == playercontrolled && stunned <= 0 && weaponactive != -1) {
203 if (weapons[weaponids[weaponactive]].getType() == knife)
204 return knifefightidleanim;
205 if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1)
206 return swordfightidlebothanim;
207 if (weapons[weaponids[weaponactive]].getType() == sword)
208 return swordfightidleanim;
209 if (weapons[weaponids[weaponactive]].getType() == staff)
210 return swordfightidleanim;
212 if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause)
213 return fightsidestep;
215 if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype)
217 if (howactive == typesitting) return sitanim;
218 if (howactive == typesittingwall) return sitwallanim;
219 if (howactive == typesleeping) return sleepanim;
220 if (howactive == typedead1) return dead1anim;
221 if (howactive == typedead2) return dead2anim;
222 if (howactive == typedead3) return dead3anim;
223 if (howactive == typedead4) return dead4anim;
224 if (creature == rabbittype) return bounceidleanim;
225 if (creature == wolftype) return wolfidle;
230 * crouch animation for this creature
232 int Person::getCrouch()
234 if (creature == rabbittype)
236 if (creature == wolftype)
237 return wolfcrouchanim;
242 * running animation for this creature (can be upright or all fours)
246 if (creature == rabbittype && (!superruntoggle || weaponactive != -1))
248 if (creature == wolftype && (!superruntoggle))
251 if (creature == rabbittype && (superruntoggle && weaponactive == -1))
252 return rabbitrunninganim;
253 if (creature == wolftype && (superruntoggle))
254 return wolfrunninganim;
260 int Person::getStop()
262 if (creature == rabbittype)
264 if (creature == wolftype)
271 int Person::getLanding()
273 if (creature == rabbittype)
275 if (creature == wolftype)
282 int Person::getLandhard()
284 if (creature == rabbittype)
286 if (creature == wolftype)
287 return wolflandhardanim;
294 * Person::DoAnimations
297 SolidHitBonus(int playerid)
299 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
300 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
302 award_bonus(playerid, solidhit);
306 * spawns blood effects
308 void Person::DoBlood(float howmuch, int which)
310 // FIXME: should abstract out inputs
311 static int bleedxint, bleedyint;
313 if (bloodtoggle && tutoriallevel != 1) {
314 if (bleeding <= 0 && spurt) {
316 for (int i = 0; i < 3; i++) {
317 // emit blood particles
319 if (!skeleton.free) {
321 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
324 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
327 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
329 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
331 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
332 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
334 if (!skeleton.free) {
335 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
336 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
339 if (Random() % 2 == 0) // 50% chance
340 for (int i = 0; i < 3; i++) {
341 if (Random() % 2 != 0) {
342 // emit teeth particles
345 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
346 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
349 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
350 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
354 Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
356 Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
358 Sprite::setLastSpriteSpecial(3); // sets it to teeth
363 // FIXME: manipulating attributes
364 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
367 if (creature == rabbittype)
368 while (bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
369 bleedxint = abs(Random() % 512);
370 bleedyint = abs(Random() % 512);
372 if (creature == wolftype)
373 while (wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
374 bleedxint = abs(Random() % 512);
375 bleedyint = abs(Random() % 512);
379 bleedy /= realtexdetail;
380 bleedx /= realtexdetail;
381 direction = abs(Random() % 2) * 2 - 1;
390 * spawns big blood effects and ???
391 * modifies character's skin texture
393 void Person::DoBloodBig(float howmuch, int which)
395 static int bleedxint, bleedyint, i, j;
397 if (howmuch && id == 0)
400 if (tutoriallevel != 1 || id == 0)
401 if (aitype != playercontrolled && howmuch > 0) {
405 // FIXME: seems to be spawning sounds by manipulating attributes... MESSY!
406 if (creature == wolftype) {
407 int i = abs(Random() % 2);
409 whichsound = snarlsound;
411 whichsound = snarl2sound;
412 envsound[numenvsounds] = coords;
413 envsoundvol[numenvsounds] = 16;
414 envsoundlife[numenvsounds] = .4;
417 if (creature == rabbittype) {
418 int i = abs(Random() % 2);
420 whichsound = rabbitpainsound;
421 if (i == 1 && howmuch >= 2)
422 whichsound = rabbitpain1sound;
423 envsound[numenvsounds] = coords;
424 envsoundvol[numenvsounds] = 16;
425 envsoundlife[numenvsounds] = .4;
429 if (whichsound != -1)
430 emit_sound_at(whichsound, coords);
433 if (id == 0 && howmuch > 0) {
434 // FIXME: manipulating attributes
442 if (bloodtoggle && decals && tutoriallevel != 1) {
443 if (bleeding <= 0 && spurt) {
445 for (int i = 0; i < 3; i++) {
446 // emit blood particles
447 // FIXME: copypaste from above
449 if (!skeleton.free) {
451 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
454 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
457 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
459 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
461 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
462 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
464 if (!skeleton.free) {
465 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
466 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
471 // weird texture manipulation code follows.
472 // looks like this is painting blood onto the character's skin texture
473 // FIXME: surely there's a better way
475 int offsetx = 0, offsety = 0;
477 offsety = Random() % 40;
478 offsetx = abs(Random() % 60);
480 if (which == 190 || which == 185) {
481 offsety = Random() % 40;
482 offsetx = abs(Random() % 100) - 20;
485 offsety = Random() % 10;
486 offsetx = Random() % 10;
489 offsety = Random() % 20;
490 offsetx = Random() % 20;
492 if (which == 220 || which == 215) {
502 if (creature == rabbittype)
503 for (i = 0; i < 512; i++) {
504 for (j = 0; j < 512; j++) {
505 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
506 if (i < startx) startx = i;
507 if (j < starty) starty = j;
508 if (i > endx) endx = i;
509 if (j > endy) endy = j;
513 if (creature == wolftype)
514 for (i = 0; i < 512; i++) {
515 for (j = 0; j < 512; j++) {
516 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
517 if (i < startx) startx = i;
518 if (j < starty) starty = j;
519 if (i > endx) endx = i;
520 if (j > endy) endy = j;
530 if (startx < 0) startx = 0;
531 if (starty < 0) starty = 0;
532 if (endx > 512 - 1) endx = 512 - 1;
533 if (endy > 512 - 1) endy = 512 - 1;
534 if (endx < startx) endx = startx;
535 if (endy < starty) endy = starty;
537 startx /= realtexdetail;
538 starty /= realtexdetail;
539 endx /= realtexdetail;
540 endy /= realtexdetail;
542 int texdetailint = realtexdetail;
544 if (creature == rabbittype)
545 for (i = startx; i < endx; i++) {
546 for (j = starty; j < endy; j++) {
547 if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
548 color = Random() % 85 + 170;
549 where = i * skeleton.skinsize * 3 + j * 3;
550 if (skeleton.skinText[where + 0] > color / 2)
551 skeleton.skinText[where + 0] = color / 2;
552 skeleton.skinText[where + 1] = 0;
553 skeleton.skinText[where + 2] = 0;
557 if (creature == wolftype)
558 for (i = startx; i < endx; i++) {
559 for (j = starty; j < endy; j++) {
560 if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
561 color = Random() % 85 + 170;
562 where = i * skeleton.skinsize * 3 + j * 3;
563 if (skeleton.skinText[where + 0] > color / 2)
564 skeleton.skinText[where + 0] = color / 2;
565 skeleton.skinText[where + 1] = 0;
566 skeleton.skinText[where + 2] = 0;
570 skeleton.drawmodel.textureptr.bind();
575 if (creature == rabbittype)
576 while (bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
577 bleedxint = abs(Random() % 512);
578 bleedyint = abs(Random() % 512);
580 if (creature == wolftype)
581 while (wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
582 bleedxint = abs(Random() % 512);
583 bleedyint = abs(Random() % 512);
585 bleedy = bleedxint + offsetx;
586 bleedx = bleedyint + offsety;
587 bleedy /= realtexdetail;
588 bleedx /= realtexdetail;
593 if (bleedx > skeleton.skinsize - 1)
594 bleedx = skeleton.skinsize - 1;
595 if (bleedy > skeleton.skinsize - 1)
596 bleedy = skeleton.skinsize - 1;
597 direction = abs(Random() % 2) * 2 - 1;
600 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
601 deathbleeding += bleeding;
602 bloodloss += bleeding * 3;
604 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
605 if (abs(Random() % 2) == 0) {
606 aitype = gethelptype;
609 aitype = attacktypecutoff;
617 * similar to DoBloodBig
619 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
623 static XYZ startpoint, endpoint, colpoint, movepoint;
624 static float rotationpoint;
626 static XYZ p1, p2, p3, p0;
630 float coordsx, coordsy;
633 if (bloodtoggle && decals && tutoriallevel != 1) {
636 where = DoRotation(where, 0, -yaw, 0);
644 // ray testing for a tri in the character model
645 whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
646 if (whichtri != -1) {
647 // low level geometry math
649 p1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
650 p2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
651 p3 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
653 CrossProduct(p2-p1,p3-p1,&N);
654 CrossProduct(p0-p1,p3-p1,&temp);
655 s = dotproduct(&temp,&N)/findLength(&N);
656 CrossProduct(p2-p1,p1-p0,&temp);
657 t = dotproduct(&temp,&N)/findLength(&N);
660 bary.x = distsq(&p0, &p1);
661 bary.y = distsq(&p0, &p2);
662 bary.z = distsq(&p0, &p3);
664 total = bary.x + bary.y + bary.z;
673 total = bary.x + bary.y + bary.z;
679 gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0];
680 gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1];
681 gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2];
682 gyy.x = skeleton.drawmodel.Triangles[whichtri].gy[0];
683 gyy.y = skeleton.drawmodel.Triangles[whichtri].gy[1];
684 gyy.z = skeleton.drawmodel.Triangles[whichtri].gy[2];
685 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;
686 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;
688 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
689 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
691 if (bleeding <= 0 && spurt) {
693 for (int i = 0; i < 3; i++) {
694 // emit blood particles
695 // FIXME: more copypaste code
697 if (!skeleton.free) {
699 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
702 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
705 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
707 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
709 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
710 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
712 if (!skeleton.free) {
713 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
714 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
719 // texture manipulation follows
721 int offsetx = 0, offsety = 0;
722 offsetx = (1 + coordsy) * 512 - 291;
723 offsety = coordsx * 512 - 437;
730 if (creature == rabbittype)
731 for (i = 0; i < 512; i++) {
732 for (j = 0; j < 512; j++) {
733 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
734 if (i < startx) startx = i;
735 if (j < starty) starty = j;
736 if (i > endx) endx = i;
737 if (j > endy) endy = j;
741 if (creature == wolftype)
742 for (i = 0; i < 512; i++) {
743 for (j = 0; j < 512; j++) {
744 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
745 if (i < startx) startx = i;
746 if (j < starty) starty = j;
747 if (i > endx) endx = i;
748 if (j > endy) endy = j;
757 if (startx < 0) startx = 0;
758 if (starty < 0) starty = 0;
759 if (endx > 512 - 1) endx = 512 - 1;
760 if (endy > 512 - 1) endy = 512 - 1;
761 if (endx < startx) endx = startx;
762 if (endy < starty) endy = starty;
764 startx /= realtexdetail;
765 starty /= realtexdetail;
766 endx /= realtexdetail;
767 endy /= realtexdetail;
769 int texdetailint = realtexdetail;
771 if (creature == rabbittype)
772 for (i = startx; i < endx; i++) {
773 for (j = starty; j < endy; j++) {
774 if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
775 color = Random() % 85 + 170;
776 where = i * skeleton.skinsize * 3 + j * 3;
777 if (skeleton.skinText[where + 0] > color / 2)
778 skeleton.skinText[where + 0] = color / 2;
779 skeleton.skinText[where + 1] = 0;
780 skeleton.skinText[where + 2] = 0;
781 } else if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= 160 + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= 160 - 4) {
782 color = Random() % 85 + 170;
783 where = i * skeleton.skinsize * 3 + j * 3;
784 if (skeleton.skinText[where + 0] > color / 2)
785 skeleton.skinText[where + 0] = color / 2;
786 skeleton.skinText[where + 1] = 0;
787 skeleton.skinText[where + 2] = 0;
791 if (creature == wolftype)
792 for (i = startx; i < endx; i++) {
793 for (j = starty; j < endy; j++) {
794 if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
795 color = Random() % 85 + 170;
796 where = i * skeleton.skinsize * 3 + j * 3;
797 if (skeleton.skinText[where + 0] > color / 2)
798 skeleton.skinText[where + 0] = color / 2;
799 skeleton.skinText[where + 1] = 0;
800 skeleton.skinText[where + 2] = 0;
801 } else if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= 160 + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= 160 - 4) {
802 color = Random() % 85 + 170;
803 where = i * skeleton.skinsize * 3 + j * 3;
804 if (skeleton.skinText[where + 0] > color / 2)
805 skeleton.skinText[where + 0] = color / 2;
806 skeleton.skinText[where + 1] = 0;
807 skeleton.skinText[where + 2] = 0;
811 skeleton.drawmodel.textureptr.bind();
814 bleedy = (1 + coordsy) * 512;
815 bleedx = coordsx * 512;
816 bleedy /= realtexdetail;
817 bleedx /= realtexdetail;
822 if (bleedx > skeleton.skinsize - 1)
823 bleedx = skeleton.skinsize - 1;
824 if (bleedy > skeleton.skinsize - 1)
825 bleedy = skeleton.skinsize - 1;
826 direction = abs(Random() % 2) * 2 - 1;
831 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
832 deathbleeding += bleeding;
833 bloodloss += bleeding * 3;
835 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
836 if (abs(Random() % 2) == 0) {
837 aitype = gethelptype;
840 aitype = attacktypecutoff;
851 * guessing this performs a reversal
853 void Person::Reverse()
855 if (!((victim->aitype == playercontrolled
857 || staggerdelay <= 0)
858 && victim->animTarget != jumpupanim
859 && victim->animTarget != jumpdownanim
860 && (tutoriallevel != 1 || cananger)
864 if (normaldotproduct (victim->facing, victim->coords - coords) > 0
865 && (victim->id != 0 || difficulty >= 2)
866 && (creature != wolftype || victim->creature == wolftype))
869 if (animTarget == sweepanim) {
870 animTarget = sweepreversedanim;
871 animCurrent = sweepreversedanim;
872 victim->animCurrent = sweepreversalanim;
873 victim->animTarget = sweepreversalanim;
875 if (animTarget == spinkickanim) {
876 animTarget = spinkickreversedanim;
877 animCurrent = spinkickreversedanim;
878 victim->animCurrent = spinkickreversalanim;
879 victim->animTarget = spinkickreversalanim;
881 if (animTarget == upunchanim || animTarget == rabbittacklinganim) {
882 if (animTarget == rabbittacklinganim) {
885 victim->frameCurrent = 6;
886 victim->frameTarget = 7;
888 animTarget = upunchreversedanim;
889 animCurrent = upunchreversedanim;
890 victim->animCurrent = upunchreversalanim;
891 victim->animTarget = upunchreversalanim;
893 if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
894 if (victim->weaponactive != -1) {
895 victim->throwtogglekeydown = 1;
896 XYZ tempVelocity = victim->velocity * .2;
897 if (tempVelocity.x == 0)
899 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
900 victim->num_weapons--;
901 if (victim->num_weapons) {
902 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
903 if (victim->weaponstuck == victim->num_weapons)
904 victim->weaponstuck = 0;
907 victim->weaponactive = -1;
908 for (unsigned j = 0; j < Person::players.size(); j++) {
909 Person::players[j]->wentforweapon = 0;
913 animTarget = staffhitreversedanim;
914 animCurrent = staffhitreversedanim;
915 victim->animCurrent = staffhitreversalanim;
916 victim->animTarget = staffhitreversalanim;
918 if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
919 if (victim->weaponactive != -1) {
920 victim->throwtogglekeydown = 1;
921 XYZ tempVelocity = victim->velocity * .2;
922 if (tempVelocity.x == 0)
924 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
925 victim->num_weapons--;
926 if (victim->num_weapons) {
927 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
928 if (victim->weaponstuck == victim->num_weapons)
929 victim->weaponstuck = 0;
932 victim->weaponactive = -1;
933 for (unsigned j = 0; j < Person::players.size(); j++) {
934 Person::players[j]->wentforweapon = 0;
937 animTarget = staffspinhitreversedanim;
938 animCurrent = staffspinhitreversedanim;
939 victim->animCurrent = staffspinhitreversalanim;
940 victim->animTarget = staffspinhitreversalanim;
942 if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
943 if (victim->weaponactive != -1) {
944 victim->throwtogglekeydown = 1;
945 XYZ tempVelocity = victim->velocity * .2;
946 if (tempVelocity.x == 0)
948 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
949 victim->num_weapons--;
950 if (victim->num_weapons) {
951 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
952 if (victim->weaponstuck == victim->num_weapons)
953 victim->weaponstuck = 0;
956 victim->weaponactive = -1;
957 for (unsigned j = 0; j < Person::players.size(); j++) {
958 Person::players[j]->wentforweapon = 0;
961 animTarget = swordslashreversedanim;
962 animCurrent = swordslashreversedanim;
963 victim->animCurrent = swordslashreversalanim;
964 victim->animTarget = swordslashreversalanim;
966 if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
967 if (victim->weaponactive != -1) {
968 victim->throwtogglekeydown = 1;
969 XYZ tempVelocity = victim->velocity * .2;
970 if (tempVelocity.x == 0)
972 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
973 victim->num_weapons--;
974 if (victim->num_weapons) {
975 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
976 if (victim->weaponstuck == victim->num_weapons)
977 victim->weaponstuck = 0;
980 victim->weaponactive = -1;
981 for (unsigned j = 0; j < Person::players.size(); j++) {
982 Person::players[j]->wentforweapon = 0;
985 animTarget = knifeslashreversedanim;
986 animCurrent = knifeslashreversedanim;
987 victim->animCurrent = knifeslashreversalanim;
988 victim->animTarget = knifeslashreversalanim;
990 if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim) {
991 victim->targettilt2 = targettilt2;
992 victim->frameCurrent = frameCurrent;
993 victim->frameTarget = frameTarget;
994 victim->target = target;
995 victim->velocity = 0;
996 victim->oldcoords = victim->coords;
997 victim->coords = coords;
998 victim->targetyaw = targetyaw;
999 victim->yaw = targetyaw;
1000 victim->victim = this->shared_from_this();
1002 if (animTarget == winduppunchanim) {
1003 animTarget = winduppunchblockedanim;
1004 victim->animTarget = blockhighleftanim;
1005 victim->frameTarget = 1;
1006 victim->target = .5;
1007 victim->victim = this->shared_from_this();
1008 victim->targetyaw = targetyaw + 180;
1010 if (animTarget == wolfslapanim) {
1011 animTarget = winduppunchblockedanim;
1012 victim->animTarget = blockhighleftanim;
1013 victim->frameTarget = 1;
1014 victim->target = .5;
1015 victim->victim = this->shared_from_this();
1016 victim->targetyaw = targetyaw + 180;
1018 if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) {
1019 animTarget = swordslashparriedanim;
1020 parriedrecently = .4;
1021 victim->parriedrecently = 0;
1022 victim->animTarget = swordslashparryanim;
1023 victim->frameTarget = 1;
1024 victim->target = .5;
1025 victim->victim = this->shared_from_this();
1026 victim->targetyaw = targetyaw + 180;
1028 if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
1029 if (victim->weaponactive != -1) {
1030 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1031 if (weapons[victim->weaponids[0]].getType() == staff)
1032 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1033 if (weapons[weaponids[0]].getType() == staff)
1034 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1035 emit_sound_at(swordstaffsound, victim->coords);
1037 emit_sound_at(metalhitsound, victim->coords);
1041 victim->Puff(righthand);
1043 victim->frameTarget = 0;
1044 victim->animTarget = staggerbackhighanim;
1045 victim->targetyaw = targetyaw + 180;
1047 aim = DoRotation(facing, 0, 90, 0) * 21;
1049 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
1050 victim->num_weapons--;
1051 if (victim->num_weapons) {
1052 victim->weaponids[0] = victim->weaponids[num_weapons];
1053 if (victim->weaponstuck == victim->num_weapons)
1054 victim->weaponstuck = 0;
1056 victim->weaponactive = -1;
1057 for (unsigned i = 0; i < Person::players.size(); i++) {
1058 Person::players[i]->wentforweapon = 0;
1062 if (abs(Random() % 20) == 0) {
1063 if (weaponactive != -1) {
1064 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1065 if (weapons[victim->weaponids[0]].getType() == staff)
1066 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1067 if (weapons[weaponids[0]].getType() == staff)
1068 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1070 emit_sound_at(swordstaffsound, coords);
1072 emit_sound_at(metalhitsound, coords);
1080 animTarget = staggerbackhighanim;
1081 targetyaw = targetyaw + 180;
1083 aim = DoRotation(facing, 0, 90, 0) * 21;
1085 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
1088 weaponids[0] = weaponids[num_weapons];
1089 if (weaponstuck == num_weapons)
1093 for (unsigned i = 0; i < Person::players.size(); i++) {
1094 Person::players[i]->wentforweapon = 0;
1101 if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) {
1102 if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) {
1103 victim->animTarget = dodgebackanim;
1104 victim->frameTarget = 0;
1108 rotatetarget = coords - victim->coords;
1109 Normalise(&rotatetarget);
1110 victim->targetyaw = -asin(0 - rotatetarget.x);
1111 victim->targetyaw *= 360 / 6.28;
1112 if (rotatetarget.z < 0)
1113 victim->targetyaw = 180 - victim->targetyaw;
1115 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1117 victim->lastattack3 = victim->lastattack2;
1118 victim->lastattack2 = victim->lastattack;
1119 victim->lastattack = victim->animTarget;
1121 victim->animTarget = sweepanim;
1122 victim->frameTarget = 0;
1126 rotatetarget = coords - victim->coords;
1127 Normalise(&rotatetarget);
1128 victim->targetyaw = -asin(0 - rotatetarget.x);
1129 victim->targetyaw *= 360 / 6.28;
1130 if (rotatetarget.z < 0)
1131 victim->targetyaw = 180 - victim->targetyaw;
1133 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1135 victim->lastattack3 = victim->lastattack2;
1136 victim->lastattack2 = victim->lastattack;
1137 victim->lastattack = victim->animTarget;
1142 victim->velocity = 0;
1144 if (aitype != playercontrolled)
1146 if (aitype != playercontrolled && Random() % 3 == 0 && escapednum < 2 && difficulty == 2)
1148 if (aitype != playercontrolled && Random() % 5 == 0 && escapednum < 2 && difficulty == 1)
1150 if (aitype != playercontrolled && Random() % 10 == 0 && escapednum < 2 && difficulty == 0)
1153 if (victim->id == 0 && animation[victim->animTarget].attack == reversal)
1160 void Person::DoDamage(float howmuch)
1162 // subtract health (temporary?)
1163 if (tutoriallevel != 1)
1164 damage += howmuch / power;
1167 damagedealt += howmuch / power;
1169 damagetaken += howmuch / power;
1172 if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo))
1175 if (tutoriallevel != 1)
1176 permanentdamage += howmuch / 2 / power;
1177 if (tutoriallevel != 1)
1178 superpermanentdamage += howmuch / 4 / power;
1180 if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2)
1182 if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt)
1186 camerashake += howmuch / 100;
1187 if (id == 0 && ((howmuch > 50 && damage > damagetolerance / 2)))
1188 blackout = damage / damagetolerance;
1193 if (aitype == passivetype && damage < damagetolerance && ((tutoriallevel != 1 || cananger) && hostile))
1194 aitype = attacktypecutoff;
1195 if (tutoriallevel != 1 && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
1196 if (abs(Random() % 2) == 0) {
1197 aitype = gethelptype;
1200 aitype = attacktypecutoff;
1204 if (howmuch > damagetolerance * 50 && skeleton.free != 2) {
1207 for (int i = 0; i < skeleton.num_joints; i++) {
1209 flatvelocity2 = velocity;
1211 flatvelocity2 = skeleton.joints[i].velocity;
1213 flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
1215 flatfacing2 = skeleton.joints[i].position * scale + coords;
1216 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1217 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1218 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1219 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1220 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1221 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1224 emit_sound_at(splattersound, coords);
1229 if (!dead && creature == wolftype) {
1230 award_bonus(0, Wolfbonus);
1237 if (tutoriallevel != 1 || id == 0)
1238 if (speechdelay <= 0 && !dead && aitype != playercontrolled) {
1239 int whichsound = -1;
1241 if (creature == wolftype) {
1242 int i = abs(Random() % 2);
1244 whichsound = snarlsound;
1246 whichsound = snarl2sound;
1247 envsound[numenvsounds] = coords;
1248 envsoundvol[numenvsounds] = 16;
1249 envsoundlife[numenvsounds] = .4;
1252 if (creature == rabbittype) {
1253 int i = abs(Random() % 2);
1255 whichsound = rabbitpainsound;
1256 if (i == 1 && damage > damagetolerance)
1257 whichsound = rabbitpain1sound;
1258 envsound[numenvsounds] = coords;
1259 envsoundvol[numenvsounds] = 16;
1260 envsoundlife[numenvsounds] = .4;
1264 if (whichsound != -1) {
1265 emit_sound_at(whichsound, coords);
1272 * calculate/animate head facing direction?
1274 void Person::DoHead()
1276 static XYZ rotatearound;
1278 static float lookspeed = 500;
1280 if (!freeze && !winfreeze) {
1283 targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100;
1284 targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100;
1286 while (targetheadyaw > 180)targetheadyaw -= 360;
1287 while (targetheadyaw < -180)targetheadyaw += 360;
1289 if (targetheadyaw > 160)
1290 targetheadpitch = targetheadpitch * -1;
1291 if (targetheadyaw < -160)
1292 targetheadpitch = targetheadpitch * -1;
1293 if (targetheadyaw > 160)
1294 targetheadyaw = targetheadyaw - 180;
1295 if (targetheadyaw < -160)
1296 targetheadyaw = targetheadyaw + 180;
1298 if (targetheadpitch > 120)
1299 targetheadpitch = 120;
1300 if (targetheadpitch < -120)
1301 targetheadpitch = -120;
1302 if (targetheadyaw > 120)
1303 targetheadyaw = 120;
1304 if (targetheadyaw < -120)
1305 targetheadyaw = -120;
1308 targetheadpitch = 0;
1310 if (targetheadyaw > 80)
1312 if (targetheadyaw < -80)
1313 targetheadyaw = -80;
1314 if (targetheadpitch > 50)
1315 targetheadpitch = 50;
1316 if (targetheadpitch < -50)
1317 targetheadpitch = -50;
1320 if (abs(headyaw - targetheadyaw) < multiplier * lookspeed)
1321 headyaw = targetheadyaw;
1322 else if (headyaw > targetheadyaw) {
1323 headyaw -= multiplier * lookspeed;
1324 } else if (headyaw < targetheadyaw) {
1325 headyaw += multiplier * lookspeed;
1328 if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2)
1329 headpitch = targetheadpitch;
1330 else if (headpitch > targetheadpitch) {
1331 headpitch -= multiplier * lookspeed / 2;
1332 } else if (headpitch < targetheadpitch) {
1333 headpitch += multiplier * lookspeed / 2;
1336 rotatearound = jointPos(neck);
1337 jointPos(head) = rotatearound + DoRotation(jointPos(head) - rotatearound, headpitch, 0, 0);
1341 if (animTarget != bounceidleanim && animTarget != fightidleanim && animTarget != wolfidle && animTarget != knifefightidleanim && animTarget != drawrightanim && animTarget != drawleftanim && animTarget != walkanim) {
1342 facing = DoRotation(facing, headpitch * .4, 0, 0);
1343 facing = DoRotation(facing, 0, headyaw * .4, 0);
1346 if (animTarget == bounceidleanim || animTarget == fightidleanim || animTarget == wolfidle || animTarget == knifefightidleanim || animTarget == drawrightanim || animTarget == drawleftanim) {
1347 facing = DoRotation(facing, headpitch * .8, 0, 0);
1348 facing = DoRotation(facing, 0, headyaw * .8, 0);
1351 if (animTarget == walkanim) {
1352 facing = DoRotation(facing, headpitch * .6, 0, 0);
1353 facing = DoRotation(facing, 0, headyaw * .6, 0);
1356 skeleton.specialforward[0] = facing;
1357 //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1358 for (int i = 0; i < skeleton.num_muscles; i++) {
1359 if (skeleton.muscles[i].visible && (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)) {
1360 skeleton.FindRotationMuscle(i, animTarget);
1367 * ragdolls character?
1369 void Person::RagDoll(bool checkcollision)
1374 if (!skeleton.free) {
1377 if (id == 0 && isFlip())
1384 facing = DoRotation(facing, 0, yaw, 0);
1386 skeleton.freetime = 0;
1388 skeleton.longdead = 0;
1391 skeleton.broken = 0;
1392 skeleton.spinny = 1;
1394 skeleton.freefall = 1;
1396 if (!isnormal(velocity.x)) velocity.x = 0;
1397 if (!isnormal(velocity.y)) velocity.y = 0;
1398 if (!isnormal(velocity.z)) velocity.z = 0;
1399 if (!isnormal(yaw)) yaw = 0;
1400 if (!isnormal(coords.x)) coords = 0;
1401 if (!isnormal(tilt)) tilt = 0;
1402 if (!isnormal(tilt2)) tilt2 = 0;
1404 for (int i = 0; i < skeleton.num_joints; i++) {
1405 skeleton.joints[i].delay = 0;
1406 skeleton.joints[i].locked = 0;
1407 skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1408 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0);
1409 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = coords;
1410 skeleton.joints[i].position.y += .1;
1411 skeleton.joints[i].oldposition = skeleton.joints[i].position;
1412 skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords;
1415 for (int i = 0; i < skeleton.num_joints; i++) {
1416 skeleton.joints[i].velocity = 0;
1417 skeleton.joints[i].velchange = 0;
1419 skeleton.DoConstraints(&coords, &scale);
1420 if (animation[animCurrent].height == lowheight || animation[animTarget].height == lowheight) {
1421 skeleton.DoConstraints(&coords, &scale);
1422 skeleton.DoConstraints(&coords, &scale);
1423 skeleton.DoConstraints(&coords, &scale);
1424 skeleton.DoConstraints(&coords, &scale);
1427 speed = animation[animTarget].speed[frameTarget] * 2;
1428 if (animation[animCurrent].speed[frameCurrent] > animation[animTarget].speed[frameTarget]) {
1429 speed = animation[animCurrent].speed[frameCurrent] * 2;
1432 speed = transspeed * 2;
1436 for (int i = 0; i < skeleton.num_joints; i++) {
1437 if ((animation[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && animation[animCurrent].height == animation[animTarget].height)
1438 skeleton.joints[i].velocity = velocity / scale + facing * 5 + DoRotation(DoRotation(DoRotation((animation[animTarget].position[i][frameTarget] - animation[animCurrent].position[i][frameCurrent]) * speed, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1440 skeleton.joints[i].velocity = velocity / scale + facing * 5;
1441 change.x = (float)(Random() % 100) / 100;
1442 change.y = (float)(Random() % 100) / 100;
1443 change.z = (float)(Random() % 100) / 100;
1444 skeleton.joints[i].velocity += change;
1445 skeleton.joints[abs(Random() % skeleton.num_joints)].velocity -= change;
1447 change.x = (float)(Random() % 100) / 100;
1448 change.y = (float)(Random() % 100) / 100;
1449 change.z = (float)(Random() % 100) / 100;
1450 skeleton.joints[i].velchange += change;
1451 skeleton.joints[abs(Random() % skeleton.num_joints)].velchange -= change;
1454 if (checkcollision) {
1461 for (j = 0; j < skeleton.num_joints; j++) {
1462 average += skeleton.joints[j].position;
1466 coords += average * scale;
1467 for (j = 0; j < skeleton.num_joints; j++) {
1468 skeleton.joints[j].position -= average;
1471 whichpatchx = coords.x / (terrain.size / subdivision * terrain.scale);
1472 whichpatchz = coords.z / (terrain.size / subdivision * terrain.scale);
1473 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
1474 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
1475 i = terrain.patchobjects[whichpatchx][whichpatchz][l];
1478 if (SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.yaw[i], &objects.model[i]) != -1) {
1479 coords.x = lowpoint.x;
1480 coords.z = lowpoint.z;
1489 for (int i = 0; i < skeleton.num_joints; i++) {
1490 velocity += skeleton.joints[i].velocity * scale;
1492 velocity /= skeleton.num_joints;
1495 if (Random() % 2 == 0) {
1496 if (weaponactive != -1 && animTarget != rabbitkickanim && num_weapons > 0) {
1497 weapons[weaponids[0]].drop(jointVel(righthand) * scale * -.3, jointVel(righthand) * scale);
1498 weapons[weaponids[0]].velocity.x += .01;
1501 weaponids[0] = weaponids[num_weapons];
1502 if (weaponstuck == num_weapons)
1506 for (unsigned i = 0; i < Person::players.size(); i++) {
1507 Person::players[i]->wentforweapon = 0;
1512 animTarget = bounceidleanim;
1513 animCurrent = bounceidleanim;
1523 void Person::FootLand(int which, float opacity)
1525 static XYZ terrainlight;
1526 static XYZ footvel, footpoint;
1527 if (opacity >= 1 || skiddelay <= 0)
1531 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1533 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1534 //footpoint.y=coords.y;
1535 if (distsq(&footpoint, &viewer))
1536 Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity);
1537 } else if (environment == snowyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1538 footvel = velocity / 5;
1542 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1544 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1545 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1546 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1547 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1548 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity);
1549 if (opacity >= 1 || detail == 2)
1551 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1552 terrain.MakeDecal(footprintdecal, footpoint, .2, 1 * opacity, yaw);
1553 } else if (environment == grassyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1554 footvel = velocity / 5;
1558 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1560 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1561 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1562 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1563 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1564 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity);
1565 } else if (environment == desertenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1566 footvel = velocity / 5;
1570 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1572 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1573 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1574 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1575 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1576 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity);
1577 if (opacity >= 1 || detail == 2)
1579 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1580 terrain.MakeDecal(footprintdecal, footpoint, .2, .25 * opacity, yaw);
1581 } else if (isLanding() || animTarget == jumpupanim || isLandhard()) {
1582 footvel = velocity / 5;
1586 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1588 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1589 //footpoint.y=coords.y;
1590 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1591 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity);
1596 * make a puff effect at a body part (dust effect?)
1598 void Person::Puff(int whichlabel)
1600 static XYZ footvel, footpoint;
1603 footpoint = DoRotation(jointPos(whichlabel), 0, yaw, 0) * scale + coords;
1604 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .9, .3);
1608 * I think I added this in an attempt to clean up code
1610 void Person::setAnimation(int animation)
1612 animTarget = animation;
1621 void Person::DoAnimations()
1623 if (!skeleton.free) {
1624 static float oldtarget;
1626 if (isIdle() && animCurrent != getIdle())
1627 normalsupdatedelay = 0;
1629 if (animTarget == tempanim || animCurrent == tempanim) {
1630 animation[tempanim] = tempanimation;
1632 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
1638 vel[0] = velocity.x;
1639 vel[1] = velocity.y;
1640 vel[2] = velocity.z;
1643 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1644 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
1646 if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z))
1648 if (!crouchkeydown && velocity.y >= -15)
1651 if ((animCurrent == jumpupanim || animTarget == jumpdownanim)/*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) {
1656 targfacing = DoRotation(targfacing, 0, targetyaw, 0);
1658 if (normaldotproduct(targfacing, velocity) >= -.3)
1659 animTarget = flipanim;
1661 animTarget = backflipanim;
1662 crouchtogglekeydown = 1;
1670 if (animation[animTarget].attack != reversed)
1672 if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) {
1673 crouchtogglekeydown = 0;
1674 if (aitype == playercontrolled)
1677 if (!crouchtogglekeydown && animation[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain))
1680 crouchtogglekeydown = 1;
1684 if (animation[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) {
1686 normalsupdatedelay = 0;
1690 if (animTarget == rollanim && frameTarget == 3 && onfire) {
1692 emit_sound_at(fireendsound, coords);
1693 pause_sound(stream_firesound);
1697 if (animTarget == rabbittacklinganim && frameTarget == 1) {
1698 if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0)
1700 if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) {
1701 if (normaldotproduct(victim->facing, facing) > 0)
1702 victim->animTarget = rabbittackledbackanim;
1704 victim->animTarget = rabbittackledfrontanim;
1705 victim->frameTarget = 2;
1708 victim->targetyaw = yaw;
1709 if (victim->aitype == gethelptype)
1710 victim->DoDamage(victim->damagetolerance - victim->damage);
1711 //victim->DoDamage(30);
1712 if (creature == wolftype) {
1714 emit_sound_at(clawslicesound, victim->coords);
1716 victim->DoBloodBig(1 / victim->armorhead, 210);
1718 award_bonus(id, TackleBonus,
1719 victim->aitype == gethelptype ? 50 : 0);
1723 if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (animation[animTarget].label[frameTarget] || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) {
1724 if (weapons[weaponids[0]].getType() == knife) {
1725 if (weaponactive == -1)
1727 else if (weaponactive == 0)
1730 if (weaponactive == -1) {
1731 emit_sound_at(knifesheathesound, coords);
1733 if (weaponactive != -1) {
1734 emit_sound_at(knifedrawsound, coords, 128);
1737 drawtogglekeydown = 1;
1740 if (tutoriallevel != 1 || id == 0)
1741 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1744 if (terrain.getOpacity(coords.x, coords.z) < .2) {
1745 if (animation[animTarget].label[frameTarget] == 1)
1746 whichsound = footstepsound;
1748 whichsound = footstepsound2;
1749 if (animation[animTarget].label[frameTarget] == 1)
1751 if (animation[animTarget].label[frameTarget] == 2)
1753 if (animation[animTarget].label[frameTarget] == 3 && isRun()) {
1759 if (terrain.getOpacity(coords.x, coords.z) >= .2) {
1760 if (animation[animTarget].label[frameTarget] == 1)
1761 whichsound = footstepsound3;
1763 whichsound = footstepsound4;
1767 if (animation[animTarget].label[frameTarget] == 1)
1768 whichsound = footstepsound3;
1770 whichsound = footstepsound4;
1772 if (animation[animTarget].label[frameTarget] == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
1773 if (animation[animTarget].attack != neutral) {
1774 unsigned r = abs(Random() % 3);
1776 whichsound = lowwhooshsound;
1778 whichsound = midwhooshsound;
1780 whichsound = highwhooshsound;
1782 if (animation[animTarget].attack == neutral)
1783 whichsound = movewhooshsound;
1784 } else if (animation[animTarget].label[frameTarget] == 4)
1785 whichsound = knifeswishsound;
1786 if (animation[animTarget].label[frameTarget] == 8 && tutoriallevel != 1)
1787 whichsound = landsound2;
1789 emit_sound_at(whichsound, coords, 256.);
1792 if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
1793 envsound[numenvsounds] = coords;
1794 if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim)
1795 envsoundvol[numenvsounds] = 15;
1797 envsoundvol[numenvsounds] = 6;
1798 envsoundlife[numenvsounds] = .4;
1802 if (animation[animTarget].label[frameTarget] == 3) {
1804 emit_sound_at(whichsound, coords, 128.);
1809 if (tutoriallevel != 1 || id == 0)
1810 if (speechdelay <= 0)
1811 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
1812 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1813 int whichsound = -1;
1814 if (animation[animTarget].label[frameTarget] == 4 && aitype != playercontrolled) {
1815 if (animation[animTarget].attack != neutral) {
1816 unsigned r = abs(Random() % 4);
1817 if (creature == rabbittype) {
1818 if (r == 0) whichsound = rabbitattacksound;
1819 if (r == 1) whichsound = rabbitattack2sound;
1820 if (r == 2) whichsound = rabbitattack3sound;
1821 if (r == 3) whichsound = rabbitattack4sound;
1823 if (creature == wolftype) {
1824 if (r == 0) whichsound = barksound;
1825 if (r == 1) whichsound = bark2sound;
1826 if (r == 2) whichsound = bark3sound;
1827 if (r == 3) whichsound = barkgrowlsound;
1833 if (whichsound != -1) {
1834 emit_sound_at(whichsound, coords);
1840 if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) {
1846 currentoffset = targetoffset;
1847 frameTarget = frameCurrent;
1848 animCurrent = animTarget;
1851 if (animTarget == removeknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1852 for (unsigned i = 0; i < weapons.size(); i++) {
1853 if (weapons[i].owner == -1)
1854 if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
1855 if (distsq(&coords, &weapons[i].position) >= 1) {
1856 if (weapons[i].getType() != staff) {
1857 emit_sound_at(knifedrawsound, coords, 128.);
1861 weapons[i].owner = id;
1862 if (num_weapons > 0) {
1863 weaponids[num_weapons] = weaponids[0];
1872 if (animTarget == crouchremoveknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1873 for (unsigned i = 0; i < weapons.size(); i++) {
1874 bool willwork = true;
1875 if (weapons[i].owner != -1)
1876 if (Person::players[weapons[i].owner]->weaponstuck != -1)
1877 if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == int(i))
1878 if (Person::players[weapons[i].owner]->num_weapons > 1)
1880 if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free))
1881 if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) {
1882 if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
1883 bool fleshstuck = false;
1884 if (weapons[i].owner != -1)
1885 if (victim->weaponstuck != -1) {
1886 if (victim->weaponids[victim->weaponstuck] == int(i)) {
1891 emit_sound_at(fleshstabremovesound, coords, 128.);
1893 if (weapons[i].getType() != staff) {
1894 emit_sound_at(knifedrawsound, coords, 128.);
1898 if (weapons[i].owner != -1) {
1900 victim = Person::players[weapons[i].owner];
1901 if (victim->num_weapons == 1)
1902 victim->num_weapons = 0;
1904 victim->num_weapons = 1;
1906 //victim->weaponactive=-1;
1907 victim->skeleton.longdead = 0;
1908 victim->skeleton.free = 1;
1909 victim->skeleton.broken = 0;
1911 for (int j = 0; j < victim->skeleton.num_joints; j++) {
1912 victim->skeleton.joints[j].velchange = 0;
1913 victim->skeleton.joints[j].locked = 0;
1919 Normalise(&relative);
1920 XYZ footvel, footpoint;
1922 footpoint = weapons[i].position;
1923 if (victim->weaponstuck != -1) {
1924 if (victim->weaponids[victim->weaponstuck] == int(i)) {
1926 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
1927 weapons[i].bloody = 2;
1928 weapons[i].blooddrip = 5;
1929 victim->weaponstuck = -1;
1932 if (victim->num_weapons > 0) {
1933 if (victim->weaponstuck != 0 && victim->weaponstuck != -1)
1934 victim->weaponstuck = 0;
1935 if (victim->weaponids[0] == int(i))
1936 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1939 victim->jointVel(abdomen) += relative * 6;
1940 victim->jointVel(neck) += relative * 6;
1941 victim->jointVel(rightshoulder) += relative * 6;
1942 victim->jointVel(leftshoulder) += relative * 6;
1944 weapons[i].owner = id;
1945 if (num_weapons > 0) {
1946 weaponids[num_weapons] = weaponids[0];
1955 if (animCurrent == drawleftanim && animation[animTarget].label[frameCurrent] == 5) {
1956 if (weaponactive == -1)
1958 else if (weaponactive == 0) {
1960 if (num_weapons == 2) {
1962 buffer = weaponids[0];
1963 weaponids[0] = weaponids[1];
1964 weaponids[1] = buffer;
1967 if (weaponactive == -1) {
1968 emit_sound_at(knifesheathesound, coords, 128.);
1970 if (weaponactive != -1) {
1971 emit_sound_at(knifedrawsound, coords, 128.);
1976 if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) {
1977 XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0);
1978 Normalise(&rotatetarget);
1979 targetyaw = -asin(0 - rotatetarget.x);
1980 targetyaw *= 360 / 6.28;
1981 if (rotatetarget.z < 0)
1982 targetyaw = 180 - targetyaw;
1984 if (animTarget == walljumprightkickanim)
1986 if (animTarget == walljumpleftkickanim)
1992 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0))
1995 if (distsq(&victim->coords, &/*Person::players[i]->*/coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1)
2000 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) {
2001 animTarget = rabbittackleanim;
2003 emit_sound_at(jumpsound, coords);
2011 targetloc = velocity;
2012 Normalise(&targetloc);
2013 targetloc += coords;
2014 for (unsigned i = 0; i < Person::players.size(); i++) {
2016 if (distsq(&targetloc, &Person::players[i]->coords) < closestdist || closestdist == 0) {
2017 closestdist = distsq(&targetloc, &Person::players[i]->coords);
2021 if (closestid != -1)
2022 if (closestdist < 5 && !Person::players[closestid]->dead && animation[Person::players[closestid]->animTarget].height != lowheight && Person::players[closestid]->animTarget != backhandspringanim) {
2024 victim = Person::players[closestid];
2025 coords = victim->coords;
2026 animCurrent = rabbittacklinganim;
2027 animTarget = rabbittacklinganim;
2031 if (coords.z != victim->coords.z || coords.x != victim->coords.x) {
2032 rotatetarget = coords - victim->coords;
2033 Normalise(&rotatetarget);
2034 targetyaw = -asin(0 - rotatetarget.x);
2035 targetyaw *= 360 / 6.28;
2036 if (rotatetarget.z < 0)
2037 targetyaw = 180 - targetyaw;
2039 if (animTarget != rabbitrunninganim) {
2040 emit_sound_at(jumpsound, coords, 128.);
2046 float damagemult = 1 * power;
2047 if (creature == wolftype)
2048 damagemult = 2.5 * power;
2050 damagemult /= victim->damagetolerance / 200;
2052 if ((animation[animTarget].attack == normalattack || animTarget == walljumprightkickanim || animTarget == walljumpleftkickanim) && (!feint) && (victim->skeleton.free != 2 || animTarget == killanim || animTarget == dropkickanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == staffgroundsmashanim)) {
2053 if (animTarget == spinkickanim && animation[animTarget].label[frameCurrent] == 5) {
2054 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2058 if (Random() % 2 || creature == wolftype) {
2061 if (creature == wolftype)
2064 if (tutoriallevel != 1) {
2065 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2067 if (creature == wolftype) {
2068 emit_sound_at(clawslicesound, victim->coords, 128.);
2070 victim->DoBloodBig(2 / victim->armorhead, 175);
2074 relative = victim->coords - coords;
2076 Normalise(&relative);
2077 relative = DoRotation(relative, 0, -90, 0);
2078 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2079 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2081 victim->jointVel(head) += relative * damagemult * 200;
2084 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2090 if (animTarget == wolfslapanim && animation[animTarget].label[frameCurrent] == 5) {
2091 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2095 if (Random() % 2 || creature == wolftype) {
2097 if (creature == wolftype)
2100 emit_sound_at(whooshhitsound, victim->coords);
2101 if (creature == wolftype) {
2102 emit_sound_at(clawslicesound, victim->coords, 128.);
2104 victim->DoBloodBig(2, 175);
2108 relative = victim->coords - coords;
2110 Normalise(&relative);
2112 Normalise(&relative);
2113 relative = DoRotation(relative, 0, 90, 0);
2114 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2115 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2117 victim->jointVel(head) += relative * damagemult * 100;
2120 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2124 if (animTarget == walljumprightkickanim && animation[animTarget].label[frameCurrent] == 5) {
2125 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2131 if (tutoriallevel != 1) {
2132 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2134 if (creature == wolftype) {
2135 emit_sound_at(clawslicesound, victim->coords, 128.);
2137 victim->DoBloodBig(2 / victim->armorhead, 175);
2143 Normalise(&relative);
2144 relative = DoRotation(relative, 0, -90, 0);
2145 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2146 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2148 victim->jointVel(head) += relative * damagemult * 200;
2151 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2153 if (victim->damage > victim->damagetolerance)
2154 award_bonus(id, style);
2160 if (animTarget == walljumpleftkickanim && animation[animTarget].label[frameCurrent] == 5) {
2161 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2167 if (tutoriallevel != 1) {
2168 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2170 if (creature == wolftype) {
2171 emit_sound_at(clawslicesound, victim->coords, 128.);
2173 victim->DoBloodBig(2 / victim->armorhead, 175);
2179 Normalise(&relative);
2180 relative = DoRotation(relative, 0, 90, 0);
2181 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2182 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2184 victim->jointVel(head) += relative * damagemult * 200;
2187 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2189 if (victim->damage > victim->damagetolerance)
2190 award_bonus(id, style);
2196 if (animTarget == blockhighleftstrikeanim && animation[animTarget].label[frameCurrent] == 5) {
2197 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2205 emit_sound_at(whooshhitsound, victim->coords);
2208 relative = victim->coords - coords;
2210 Normalise(&relative);
2211 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2212 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
2214 victim->jointVel(head) += relative * damagemult * 100;
2217 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2221 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 8) {
2222 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) {
2226 emit_sound_at(whooshhitsound, victim->coords, 128.);
2228 victim->skeleton.longdead = 0;
2229 victim->skeleton.free = 1;
2230 victim->skeleton.broken = 0;
2231 victim->skeleton.spinny = 1;
2233 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2234 victim->skeleton.joints[i].velchange = 0;
2235 victim->skeleton.joints[i].delay = 0;
2236 victim->skeleton.joints[i].locked = 0;
2237 //victim->skeleton.joints[i].velocity=0;
2243 Normalise(&relative);
2244 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2245 victim->skeleton.joints[i].velocity.y = relative.y * 10;
2246 victim->skeleton.joints[i].position.y += relative.y * .3;
2247 victim->skeleton.joints[i].oldposition.y += relative.y * .3;
2248 victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
2250 victim->Puff(abdomen);
2251 victim->jointVel(abdomen).y = relative.y * 400;
2255 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 5) {
2256 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) {
2260 if (tutoriallevel != 1) {
2261 emit_sound_at(heavyimpactsound, coords, 128.);
2264 relative = victim->coords - coords;
2266 Normalise(&relative);
2267 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2268 victim->skeleton.joints[i].velocity += relative * damagemult * 90;
2270 victim->Puff(abdomen);
2271 if (victim->dead != 2 && victim->permanentdamage > victim->damagetolerance - 250 && autoslomo) {
2275 victim->DoDamage(damagemult * 500 / victim->protectionhigh);
2276 victim->jointVel(abdomen) += relative * damagemult * 300;
2280 if (animTarget == dropkickanim && animation[animTarget].label[frameCurrent] == 7) {
2281 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) {
2285 if (tutoriallevel != 1) {
2286 emit_sound_at(thudsound, coords);
2289 victim->skeleton.longdead = 0;
2290 victim->skeleton.free = 1;
2291 victim->skeleton.broken = 0;
2292 victim->skeleton.spinny = 1;
2294 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2295 victim->skeleton.joints[i].velchange = 0;
2296 //victim->skeleton.joints[i].delay=0;
2297 victim->skeleton.joints[i].locked = 0;
2300 relative = victim->coords - coords;
2301 Normalise(&relative);
2303 Normalise(&relative);
2304 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2305 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2310 victim->Puff(abdomen);
2311 victim->DoDamage(damagemult * 20 / victim->protectionhigh);
2312 victim->jointVel(abdomen) += relative * damagemult * 200;
2321 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 5) {
2324 if (!victim->skeleton.free)
2328 terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360);
2329 emit_sound_at(knifesheathesound, coords, 128.);
2332 if (victim && hasvictim) {
2333 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2335 XYZ where, startpoint, endpoint, movepoint, colpoint;
2336 float rotationpoint;
2338 if (weapons[weaponids[weaponactive]].getType() == knife) {
2339 where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4);
2340 where -= victim->coords;
2341 if (!victim->skeleton.free)
2342 where = DoRotation(where, 0, -victim->yaw, 0);
2345 startpoint.y += 100;
2349 if (weapons[weaponids[weaponactive]].getType() == sword) {
2350 where = weapons[weaponids[weaponactive]].position;
2351 where -= victim->coords;
2352 if (!victim->skeleton.free)
2353 where = DoRotation(where, 0, -victim->yaw, 0);
2355 where = weapons[weaponids[weaponactive]].tippoint;
2356 where -= victim->coords;
2357 if (!victim->skeleton.free)
2358 where = DoRotation(where, 0, -victim->yaw, 0);
2361 if (weapons[weaponids[weaponactive]].getType() == staff) {
2362 where = weapons[weaponids[weaponactive]].position;
2363 where -= victim->coords;
2364 if (!victim->skeleton.free)
2365 where = DoRotation(where, 0, -victim->yaw, 0);
2367 where = weapons[weaponids[weaponactive]].tippoint;
2368 where -= victim->coords;
2369 if (!victim->skeleton.free)
2370 where = DoRotation(where, 0, -victim->yaw, 0);
2375 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
2377 if (whichtri != -1) {
2378 if (victim->dead != 2) {
2379 victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2));
2381 award_bonus(id, FinishedBonus);
2384 weapons[weaponids[weaponactive]].bloody = 2;
2386 victim->skeleton.longdead = 0;
2387 victim->skeleton.free = 1;
2388 victim->skeleton.broken = 0;
2390 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2391 victim->skeleton.joints[i].velchange = 0;
2392 victim->skeleton.joints[i].locked = 0;
2393 //victim->skeleton.joints[i].velocity=0;
2395 emit_sound_at(fleshstabsound, coords, 128);
2398 if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) {
2399 weapons[weaponids[weaponactive]].blooddrip += 5;
2400 weapons[weaponids[weaponactive]].blooddripdelay = 0;
2402 if (whichtri == -1) {
2404 emit_sound_at(knifesheathesound, coords, 128.);
2410 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 6) {
2412 emit_sound_at(knifedrawsound, coords, 128);
2415 if (victim && hasvictim) {
2416 XYZ footvel, footpoint;
2418 emit_sound_at(fleshstabremovesound, coords, 128.);
2421 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2423 if (weapons[weaponids[weaponactive]].getType() == sword) {
2424 XYZ where, startpoint, endpoint, movepoint;
2425 float rotationpoint;
2428 where = weapons[weaponids[weaponactive]].position;
2429 where -= victim->coords;
2430 if (!victim->skeleton.free)
2431 where = DoRotation(where, 0, -victim->yaw, 0);
2433 where = weapons[weaponids[weaponactive]].tippoint;
2434 where -= victim->coords;
2435 if (!victim->skeleton.free)
2436 where = DoRotation(where, 0, -victim->yaw, 0);
2441 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2442 footpoint += victim->coords;
2444 if (whichtri == -1) {
2445 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2448 if (weapons[weaponids[weaponactive]].getType() == staff) {
2449 XYZ where, startpoint, endpoint, movepoint;
2450 float rotationpoint;
2453 where = weapons[weaponids[weaponactive]].position;
2454 where -= victim->coords;
2455 if (!victim->skeleton.free)
2456 where = DoRotation(where, 0, -victim->yaw, 0);
2458 where = weapons[weaponids[weaponactive]].tippoint;
2459 where -= victim->coords;
2460 if (!victim->skeleton.free)
2461 where = DoRotation(where, 0, -victim->yaw, 0);
2466 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2467 footpoint += victim->coords;
2469 if (whichtri == -1) {
2470 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2473 hasvictim = victim->DoBloodBigWhere(2, 220, footpoint);
2475 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2476 victim->skeleton.longdead = 0;
2477 victim->skeleton.free = 1;
2478 victim->skeleton.broken = 0;
2480 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2481 victim->skeleton.joints[i].velchange = 0;
2482 victim->skeleton.joints[i].locked = 0;
2483 //victim->skeleton.joints[i].velocity=0;
2489 Normalise(&relative);
2490 //victim->Puff(abdomen);
2492 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2494 if (victim->bloodloss < victim->damagetolerance) {
2495 victim->bloodloss += 1000;
2499 victim->jointVel(abdomen) += relative * damagemult * 20;
2503 if (!hasvictim && onterrain) {
2504 weapons[weaponids[weaponactive]].bloody = 0;
2505 weapons[weaponids[weaponactive]].blooddrip = 0;
2509 if (animTarget == upunchanim && animation[animTarget].label[frameCurrent] == 5) {
2510 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2518 if (tutoriallevel != 1) {
2519 emit_sound_at(heavyimpactsound, victim->coords, 128);
2524 relative = victim->coords - coords;
2526 Normalise(&relative);
2527 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2528 victim->skeleton.joints[i].velocity = relative * 30;
2530 victim->jointVel(head) += relative * damagemult * 150;
2532 victim->frameTarget = 0;
2533 victim->animTarget = staggerbackhardanim;
2534 victim->targetyaw = targetyaw + 180;
2536 victim->stunned = 1;
2539 victim->Puff(abdomen);
2540 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2547 if (animTarget == winduppunchanim && animation[animTarget].label[frameCurrent] == 5) {
2548 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) {
2552 if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height != lowheight) {
2553 if (tutoriallevel != 1) {
2554 emit_sound_at(thudsound, victim->coords);
2556 } else if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height == lowheight) {
2557 if (tutoriallevel != 1) {
2558 emit_sound_at(whooshhitsound, victim->coords);
2561 if (tutoriallevel != 1) {
2562 emit_sound_at(heavyimpactsound, victim->coords);
2566 if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || animation[victim->animTarget].height == lowheight)
2569 relative = victim->coords - coords;
2571 Normalise(&relative);
2573 Normalise(&relative);
2574 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2575 victim->skeleton.joints[i].velocity = relative * 5;
2577 victim->jointVel(abdomen) += relative * damagemult * 400;
2579 victim->frameTarget = 0;
2580 victim->animTarget = staggerbackhardanim;
2581 victim->targetyaw = targetyaw + 180;
2583 victim->stunned = 1;
2585 victim->Puff(abdomen);
2586 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2592 if (animTarget == blockhighleftanim && animation[animTarget].label[frameCurrent] == 5) {
2593 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2594 if (victim->id == 0)
2596 emit_sound_at(landsound2, victim->coords);
2602 if (animTarget == swordslashparryanim && animation[animTarget].label[frameCurrent] == 5) {
2603 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2604 if (victim->id == 0)
2607 if (weaponactive != -1) {
2608 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2609 if (weapons[victim->weaponids[0]].getType() == staff)
2610 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2611 if (weapons[weaponids[0]].getType() == staff)
2612 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2614 emit_sound_at(swordstaffsound, victim->coords);
2616 emit_sound_at(metalhitsound, victim->coords);
2624 if (animTarget == knifethrowanim && animation[animTarget].label[frameCurrent] == 5) {
2625 if (weaponactive != -1) {
2628 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);
2630 weapons[weaponids[0]].thrown(aim * 50);
2633 weaponids[0] = weaponids[num_weapons];
2639 if (animTarget == knifeslashstartanim && animation[animTarget].label[frameCurrent] == 5) {
2641 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 &&/*animation[victim->animTarget].height!=lowheight&&*/victim->animTarget != dodgebackanim && victim->animTarget != rollanim) {
2643 if (tutoriallevel != 1)
2644 victim->DoBloodBig(1.5 / victim->armorhigh, 225);
2646 award_bonus(id, Slicebonus);
2647 if (tutoriallevel != 1) {
2648 emit_sound_at(knifeslicesound, victim->coords);
2650 //victim->jointVel(abdomen)+=relative*damagemult*200;
2651 if (animation[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
2652 if (victim->id != 0 || difficulty == 2) {
2653 victim->frameTarget = 0;
2654 victim->animTarget = staggerbackhardanim;
2655 victim->targetyaw = targetyaw + 180;
2659 victim->lowreversaldelay = 0;
2660 victim->highreversaldelay = 0;
2661 if (aitype != playercontrolled)
2662 weaponmissdelay = .6;
2664 if (tutoriallevel != 1)
2665 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2666 weapons[weaponids[weaponactive]].bloody = 1;
2667 if (tutoriallevel != 1)
2668 weapons[weaponids[weaponactive]].blooddrip += 3;
2670 XYZ footvel, footpoint;
2672 if (skeleton.free) {
2673 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2675 if (!skeleton.free) {
2676 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2678 if (tutoriallevel != 1) {
2680 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .6, .3);
2681 footvel = DoRotation(facing, 0, 90, 0) * .8;
2683 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2684 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2685 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
2686 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
2688 if (tutoriallevel == 1) {
2689 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .6, .3);
2691 victim->DoDamage(damagemult * 0);
2694 if (animTarget == swordslashanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2695 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) {
2696 if (victim->weaponactive == -1 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) {
2697 award_bonus(id, Slashbonus);
2699 if (tutoriallevel != 1) {
2700 if (normaldotproduct(victim->facing, victim->coords - coords) < 0)
2701 victim->DoBloodBig(2 / victim->armorhigh, 190);
2703 victim->DoBloodBig(2 / victim->armorhigh, 185);
2704 victim->deathbleeding = 1;
2705 emit_sound_at(swordslicesound, victim->coords);
2707 //victim->jointVel(abdomen)+=relative*damagemult*200;
2708 if (tutoriallevel != 1) {
2709 victim->frameTarget = 0;
2710 victim->animTarget = staggerbackhardanim;
2711 victim->targetyaw = targetyaw + 180;
2715 if (tutoriallevel != 1) {
2716 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2717 weapons[weaponids[weaponactive]].bloody = 1;
2718 weapons[weaponids[weaponactive]].blooddrip += 3;
2720 float bloodlossamount;
2721 bloodlossamount = 200 + abs((float)(Random() % 40)) - 20;
2722 victim->bloodloss += bloodlossamount / victim->armorhigh;
2723 //victim->bloodloss+=100*(6.5-distsq(&coords,&victim->coords));
2724 victim->DoDamage(damagemult * 0);
2726 XYZ footvel, footpoint;
2728 if (skeleton.free) {
2729 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2731 if (!skeleton.free) {
2732 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2735 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
2736 footvel = DoRotation(facing, 0, 90, 0) * .8;
2738 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2739 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2740 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
2741 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
2744 if (victim->weaponactive != -1) {
2745 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2746 if (weapons[victim->weaponids[0]].getType() == staff)
2747 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2748 if (weapons[weaponids[0]].getType() == staff)
2749 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2751 emit_sound_at(swordstaffsound, victim->coords);
2753 emit_sound_at(metalhitsound, victim->coords);
2759 victim->Puff(righthand);
2761 victim->frameTarget = 0;
2762 victim->animTarget = staggerbackhighanim;
2763 victim->targetyaw = targetyaw + 180;
2765 aim = DoRotation(facing, 0, 90, 0) * 21;
2767 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
2768 victim->num_weapons--;
2769 if (victim->num_weapons) {
2770 victim->weaponids[0] = victim->weaponids[num_weapons];
2771 if (victim->weaponstuck == victim->num_weapons)
2772 victim->weaponstuck = 0;
2774 victim->weaponactive = -1;
2775 for (unsigned i = 0; i < Person::players.size(); i++) {
2776 Person::players[i]->wentforweapon = 0;
2783 if (animTarget == staffhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2784 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2785 if (tutoriallevel != 1) {
2786 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 250;
2790 if (Random() % 2 || creature == wolftype) {
2793 emit_sound_at(staffheadsound, victim->coords);
2797 relative = victim->coords - coords;
2799 Normalise(&relative);
2800 relative = DoRotation(relative, 0, 90, 0);
2802 Normalise(&relative);
2803 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2804 victim->skeleton.joints[i].velocity += relative * damagemult * 60;
2806 victim->jointVel(head) += relative * damagemult * 230;
2807 victim->jointVel(neck) += relative * damagemult * 230;
2810 if (tutoriallevel != 1) {
2811 victim->DoDamage(damagemult * 120 / victim->protectionhigh);
2813 award_bonus(id, solidhit, 30);
2818 if (animTarget == staffspinhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2819 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2820 if (tutoriallevel != 1) {
2821 weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250;
2825 if (Random() % 2 || creature == wolftype) {
2828 emit_sound_at(staffheadsound, victim->coords);
2832 relative = victim->coords - coords;
2834 Normalise(&relative);
2835 relative = DoRotation(relative, 0, -90, 0);
2836 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2837 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2839 victim->jointVel(head) += relative * damagemult * 220;
2840 victim->jointVel(neck) += relative * damagemult * 220;
2843 if (tutoriallevel != 1) {
2844 victim->DoDamage(damagemult * 350 / victim->protectionhead);
2846 award_bonus(id, solidhit, 60);
2851 if (animTarget == staffgroundsmashanim && animation[animTarget].label[frameCurrent] == 5) {
2852 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) {
2854 if (tutoriallevel != 1) {
2856 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500;
2859 if (Random() % 2 || creature == wolftype) {
2862 emit_sound_at(staffbodysound, victim->coords);
2864 victim->skeleton.longdead = 0;
2865 victim->skeleton.free = 1;
2866 victim->skeleton.broken = 0;
2868 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2869 victim->skeleton.joints[i].velchange = 0;
2870 victim->skeleton.joints[i].locked = 0;
2871 //victim->skeleton.joints[i].velocity=0;
2877 /*relative=victim->coords-coords;
2879 Normalise(&relative);
2880 relative=DoRotation(relative,0,90,0);*/
2882 Normalise(&relative);
2883 if (!victim->dead) {
2884 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2885 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
2888 victim->jointVel(abdomen) += relative * damagemult * 40;
2891 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2892 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
2895 //victim->jointVel(abdomen)+=relative*damagemult*20;
2897 victim->Puff(abdomen);
2898 if (tutoriallevel != 1) {
2899 victim->DoDamage(damagemult * 100 / victim->protectionhigh);
2901 if (!victim->dead) {
2902 award_bonus(id, solidhit, 40);
2908 if (animTarget == lowkickanim && animation[animTarget].label[frameCurrent] == 5) {
2909 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != highheight) {
2914 relative = victim->coords - coords;
2916 Normalise(&relative);
2920 if (animation[victim->animTarget].height == lowheight) {
2926 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2927 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2929 victim->jointVel(head) += relative * damagemult * 200;
2930 if (tutoriallevel != 1) {
2931 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2934 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2935 if (victim->howactive == typesleeping)
2936 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2937 if (creature == wolftype) {
2938 emit_sound_at(clawslicesound, victim->coords, 128.);
2940 victim->DoBloodBig(2 / victim->armorhead, 175);
2943 if (victim->damage >= victim->damagetolerance)
2945 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2946 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
2948 victim->jointVel(abdomen) += relative * damagemult * 200;
2949 victim->frameTarget = 0;
2950 victim->animTarget = staggerbackhighanim;
2951 victim->targetyaw = targetyaw + 180;
2953 if (tutoriallevel != 1) {
2954 emit_sound_at(landsound2, victim->coords, 128.);
2956 victim->Puff(abdomen);
2957 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
2958 if (creature == wolftype) {
2959 emit_sound_at(clawslicesound, victim->coords, 128.);
2961 victim->DoBloodBig(2 / victim->armorhigh, 170);
2968 if (animTarget == sweepanim && animation[animTarget].label[frameCurrent] == 5) {
2969 if ((victim->animTarget != jumpupanim) &&
2970 (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) &&
2971 (victim != this->shared_from_this())) {
2975 if (tutoriallevel != 1) {
2976 emit_sound_at(landsound2, victim->coords, 128.);
2979 relative = victim->coords - coords;
2981 Normalise(&relative);
2983 if (animation[victim->animTarget].height == middleheight || animation[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
2986 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2987 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
2989 relative = DoRotation(relative, 0, -90, 0);
2991 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2992 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)
2993 victim->skeleton.joints[i].velocity = relative * 80;
2995 victim->Puff(rightankle);
2996 victim->Puff(leftankle);
2997 victim->DoDamage(damagemult * 40 / victim->protectionlow);
2999 if (victim->damage >= victim->damagetolerance)
3001 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3002 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3004 relative = DoRotation(relative, 0, -90, 0);
3005 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3006 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)
3007 victim->skeleton.joints[i].velocity += relative * damagemult * 80;
3009 victim->jointVel(abdomen) += relative * damagemult * 200;
3010 victim->frameTarget = 0;
3011 victim->animTarget = staggerbackhighanim;
3012 victim->targetyaw = targetyaw + 180;
3014 if (tutoriallevel != 1) {
3015 emit_sound_at(landsound2, victim->coords, 128.);
3017 victim->Puff(abdomen);
3018 victim->DoDamage(damagemult * 30 / victim->protectionlow);
3026 if (animation[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) {
3027 if (animTarget == spinkickreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3035 if (tutoriallevel != 1) {
3036 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3038 if (creature == wolftype) {
3039 emit_sound_at(clawslicesound, victim->coords, 128);
3041 victim->DoBloodBig(2 / victim->armorhigh, 170);
3045 relative = victim->coords - oldcoords;
3047 Normalise(&relative);
3048 //relative=DoRotation(relative,0,-90,0);
3049 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3050 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3052 victim->jointVel(abdomen) += relative * damagemult * 200;
3054 victim->Puff(abdomen);
3055 victim->DoDamage(damagemult * 150 / victim->protectionhigh);
3057 award_bonus(id, Reversal);
3060 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && animation[animTarget].label[frameCurrent] == 5) {
3061 if (victim->weaponactive != -1 && victim->num_weapons > 0) {
3062 if (weapons[victim->weaponids[victim->weaponactive]].owner == int(victim->id)) {
3063 weapons[victim->weaponids[victim->weaponactive]].owner = id;
3065 if (num_weapons > 0) {
3066 weaponids[num_weapons] = weaponids[victim->weaponactive];
3069 weaponids[0] = victim->weaponids[victim->weaponactive];
3070 victim->num_weapons--;
3071 if (victim->num_weapons > 0) {
3072 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
3074 victim->weaponactive = -1;
3079 if (animTarget == staffhitreversalanim && animation[animTarget].label[frameCurrent] == 5) {
3087 emit_sound_at(whooshhitsound, victim->coords, 128.);
3090 relative = victim->coords - oldcoords;
3092 Normalise(&relative);
3093 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3094 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3096 victim->jointVel(abdomen) += relative * damagemult * 200;
3098 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3101 if (animTarget == staffspinhitreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3110 award_bonus(id, staffreversebonus);
3112 if (tutoriallevel != 1) {
3113 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3116 award_bonus(id, staffreversebonus); // Huh, again?
3119 relative = victim->coords - oldcoords;
3121 Normalise(&relative);
3122 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3123 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3125 victim->jointVel(abdomen) += relative * damagemult * 200;
3127 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3130 if (animTarget == upunchreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3136 Normalise(&relative);
3138 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3139 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3141 victim->jointVel(lefthand) *= .1;
3142 victim->jointVel(leftwrist) *= .2;
3143 victim->jointVel(leftelbow) *= .5;
3144 victim->jointVel(leftshoulder) *= .7;
3145 victim->jointVel(righthand) *= .1;
3146 victim->jointVel(rightwrist) *= .2;
3147 victim->jointVel(rightelbow) *= .5;
3148 victim->jointVel(rightshoulder) *= .7;
3150 victim->Puff(abdomen);
3151 victim->DoDamage(damagemult * 90 / victim->protectionhigh);
3153 award_bonus(id, Reversal);
3157 if (weaponactive != -1 || creature == wolftype)
3159 if (creature == rabbittype && weaponactive != -1)
3160 if (weapons[weaponids[0]].getType() == staff)
3163 if (weaponactive != -1) {
3164 victim->DoBloodBig(2 / victim->armorhigh, 225);
3165 emit_sound_at(knifeslicesound, victim->coords);
3166 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3167 weapons[weaponids[weaponactive]].bloody = 1;
3168 weapons[weaponids[weaponactive]].blooddrip += 3;
3170 if (weaponactive == -1 && creature == wolftype) {
3172 emit_sound_at(clawslicesound, victim->coords, 128.);
3174 victim->DoBloodBig(2 / victim->armorhigh, 175);
3181 if (animTarget == swordslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3187 Normalise(&relative);
3189 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3190 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3192 victim->jointVel(lefthand) *= .1 - 1;
3193 victim->jointVel(leftwrist) *= .2 - 1;
3194 victim->jointVel(leftelbow) *= .5 - 1;
3195 victim->jointVel(leftshoulder) *= .7 - 1;
3196 victim->jointVel(righthand) *= .1 - 1;
3197 victim->jointVel(rightwrist) *= .2 - 1;
3198 victim->jointVel(rightelbow) *= .5 - 1;
3199 victim->jointVel(rightshoulder) *= .7 - 1;
3201 award_bonus(id, swordreversebonus);
3204 if (hasvictim && animTarget == knifeslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3212 if (tutoriallevel != 1) {
3213 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3217 relative = victim->coords - oldcoords;
3219 Normalise(&relative);
3220 relative = DoRotation(relative, 0, -90, 0);
3221 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3222 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3224 victim->jointVel(abdomen) += relative * damagemult * 200;
3225 victim->Puff(abdomen);
3226 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3228 award_bonus(id, Reversal);
3231 if (hasvictim && animTarget == sneakattackanim && animation[animTarget].label[frameCurrent] == 7) {
3234 victim->skeleton.spinny = 0;
3236 relative = facing * -1;
3238 Normalise(&relative);
3239 if (victim->id == 0)
3241 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3242 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3244 victim->damage = victim->damagetolerance;
3245 victim->permanentdamage = victim->damagetolerance - 1;
3248 if (weaponactive != -1 || creature == wolftype)
3250 if (creature == rabbittype && weaponactive != -1)
3251 if (weapons[weaponids[0]].getType() == staff)
3254 if (weaponactive != -1) {
3255 victim->DoBloodBig(200, 225);
3256 emit_sound_at(knifeslicesound, victim->coords);
3258 weapons[weaponids[weaponactive]].bloody = 2;
3259 weapons[weaponids[weaponactive]].blooddrip += 5;
3262 if (creature == wolftype && weaponactive == -1) {
3263 emit_sound_at(clawslicesound, victim->coords, 128.);
3265 victim->DoBloodBig(2, 175);
3268 award_bonus(id, spinecrusher);
3271 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3272 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3274 if (animTarget == knifefollowanim)
3275 victim->DoBloodBig(200, 210);
3276 if (animTarget == knifesneakattackanim) {
3277 XYZ footvel, footpoint;
3279 footpoint = weapons[weaponids[0]].tippoint;
3281 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3282 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3283 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3284 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3285 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3286 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3287 victim->DoBloodBig(200, 195);
3288 award_bonus(id, tracheotomy);
3290 if (animTarget == knifefollowanim) {
3291 award_bonus(id, Stabbonus);
3292 XYZ footvel, footpoint;
3294 footpoint = weapons[weaponids[0]].tippoint;
3296 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3297 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3298 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3299 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3300 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3301 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3304 victim->bloodloss += 10000;
3305 victim->velocity = 0;
3306 emit_sound_at(fleshstabsound, victim->coords);
3308 weapons[weaponids[weaponactive]].bloody = 2;
3309 weapons[weaponids[weaponactive]].blooddrip += 5;
3313 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 6) {
3315 victim->velocity = 0;
3316 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3317 victim->skeleton.joints[i].velocity = 0;
3319 if (animTarget == knifefollowanim) {
3321 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3322 victim->skeleton.joints[i].velocity = 0;
3325 if (weaponactive != -1 && animation[victim->animTarget].attack != reversal) {
3326 emit_sound_at(fleshstabremovesound, victim->coords);
3328 weapons[weaponids[weaponactive]].bloody = 2;
3329 weapons[weaponids[weaponactive]].blooddrip += 5;
3331 XYZ footvel, footpoint;
3333 footpoint = weapons[weaponids[0]].tippoint;
3335 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3336 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3337 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3338 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3339 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3340 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3344 if (hasvictim && (animTarget == swordsneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3345 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3346 award_bonus(id, backstab);
3350 XYZ footvel, footpoint;
3352 footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2;
3354 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3355 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3356 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3357 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3358 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 5, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3359 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3360 victim->DoBloodBig(200, 180);
3361 victim->DoBloodBig(200, 215);
3362 victim->bloodloss += 10000;
3363 victim->velocity = 0;
3364 emit_sound_at(fleshstabsound, victim->coords);
3366 weapons[weaponids[weaponactive]].bloody = 2;
3367 weapons[weaponids[weaponactive]].blooddrip += 5;
3371 if (hasvictim && animTarget == swordsneakattackanim && animation[animTarget].label[frameCurrent] == 6) {
3373 victim->velocity = 0;
3374 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3375 victim->skeleton.joints[i].velocity = 0;
3377 if (weaponactive != -1) {
3378 emit_sound_at(fleshstabremovesound, victim->coords);
3380 weapons[weaponids[weaponactive]].bloody = 2;
3381 weapons[weaponids[weaponactive]].blooddrip += 5;
3383 XYZ footvel, footpoint;
3385 footpoint = weapons[weaponids[0]].tippoint;
3387 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3388 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3389 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3390 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3391 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3392 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3396 if (animTarget == sweepreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3404 if (weaponactive == -1) {
3405 if (tutoriallevel != 1) {
3406 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3411 if (weaponactive != -1 || creature == wolftype)
3413 if (creature == rabbittype && weaponactive != -1)
3414 if (weapons[weaponids[0]].getType() == staff)
3417 if (weaponactive != -1) {
3418 victim->DoBloodBig(2 / victim->armorhead, 225);
3419 emit_sound_at(knifeslicesound, victim->coords);
3420 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3421 weapons[weaponids[weaponactive]].bloody = 1;
3422 weapons[weaponids[weaponactive]].blooddrip += 3;
3424 if (weaponactive == -1 && creature == wolftype) {
3425 emit_sound_at(clawslicesound, victim->coords, 128.);
3427 victim->DoBloodBig(2 / victim->armorhead, 175);
3431 award_bonus(id, Reversal);
3436 relative = facing * -1;
3438 Normalise(&relative);
3439 relative = DoRotation(relative, 0, 90, 0);
3441 Normalise(&relative);
3442 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3443 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3445 victim->jointVel(head) += relative * damagemult * 200;
3446 if (victim->damage < victim->damagetolerance - 100)
3447 victim->velocity = relative * 200;
3448 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3449 victim->velocity = 0;
3452 if (animTarget == sweepreversalanim && ((animation[animTarget].label[frameCurrent] == 9 && victim->damage < victim->damagetolerance) || (animation[animTarget].label[frameCurrent] == 7 && victim->damage > victim->damagetolerance))) {
3456 relative = facing * -1;
3458 Normalise(&relative);
3459 relative = DoRotation(relative, 0, 90, 0);
3461 Normalise(&relative);
3462 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3463 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3465 victim->jointVel(head) += relative * damagemult * 200;
3468 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim))
3469 if (victim->damage > victim->damagetolerance && bonus != reverseko) {
3470 award_bonus(id, reverseko);
3476 if (frameTarget > animation[animCurrent].numframes - 1) {
3479 animTarget = getIdle();
3483 if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) {
3484 animTarget = rollanim;
3486 emit_sound_at(movewhooshsound, coords, 128.);
3488 if (animCurrent == staggerbackhighanim) {
3489 animTarget = getIdle();
3491 if (animCurrent == staggerbackhardanim) {
3492 animTarget = getIdle();
3494 if (animCurrent == removeknifeanim) {
3495 animTarget = getIdle();
3497 if (animCurrent == crouchremoveknifeanim) {
3498 animTarget = getCrouch();
3500 if (animCurrent == backhandspringanim) {
3501 animTarget = getIdle();
3503 if (animCurrent == dodgebackanim) {
3504 animTarget = getIdle();
3506 if (animCurrent == drawleftanim) {
3507 animTarget = getIdle();
3509 if (animCurrent == drawrightanim || animCurrent == crouchdrawrightanim) {
3510 animTarget = getIdle();
3511 if (animCurrent == crouchdrawrightanim) {
3512 animTarget = getCrouch();
3514 if (weaponactive == -1)
3516 else if (weaponactive == 0) {
3518 if (num_weapons == 2) {
3520 buffer = weaponids[0];
3521 weaponids[0] = weaponids[1];
3522 weaponids[1] = buffer;
3526 if (weaponactive == -1) {
3527 emit_sound_at(knifesheathesound, coords, 128.);
3529 if (weaponactive != -1) {
3530 emit_sound_at(knifedrawsound, coords, 128.);
3533 if (animCurrent == rollanim) {
3534 animTarget = getCrouch();
3539 if (animTarget == walljumprightkickanim) {
3542 if (animTarget == walljumpleftkickanim) {
3545 animTarget = jumpdownanim;
3547 if (animCurrent == climbanim) {
3548 animTarget = getCrouch();
3550 coords += facing * .1;
3551 if (!isnormal(coords.x))
3562 if (animTarget == rabbitkickreversalanim) {
3563 animTarget = getCrouch();
3566 if (animTarget == jumpreversalanim) {
3567 animTarget = getCrouch();
3570 if (animTarget == walljumprightanim || animTarget == walljumpbackanim || animTarget == walljumpfrontanim) {
3571 if (attackkeydown && animTarget != walljumpfrontanim) {
3573 float closestdist = -1;
3575 if (Person::players.size() > 1)
3576 for (unsigned i = 0; i < Person::players.size(); i++) {
3577 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3578 distance = distsq(&Person::players[i]->coords, &coords);
3579 if (closestdist == -1 || distance < closestdist) {
3580 closestdist = distance;
3585 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3586 victim = Person::players[closest];
3587 animTarget = walljumprightkickanim;
3589 XYZ rotatetarget = victim->coords - coords;
3590 Normalise(&rotatetarget);
3591 yaw = -asin(0 - rotatetarget.x);
3593 if (rotatetarget.z < 0)
3595 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3596 velocity = (victim->coords - coords) * 4;
3601 if (animTarget == walljumpbackanim) {
3602 animTarget = backflipanim;
3604 velocity = facing * -8;
3607 resume_stream(whooshsound);
3609 if (animTarget == walljumprightanim) {
3610 animTarget = rightflipanim;
3614 velocity = DoRotation(facing, 0, 30, 0) * -8;
3617 if (animTarget == walljumpfrontanim) {
3618 animTarget = frontflipanim;
3622 velocity = facing * 8;
3626 resume_stream(whooshsound);
3628 if (animTarget == walljumpleftanim) {
3629 if (attackkeydown) {
3631 float closestdist = -1;
3633 if (Person::players.size() > 1)
3634 for (unsigned i = 0; i < Person::players.size(); i++) {
3635 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3636 distance = distsq(&Person::players[i]->coords, &coords);
3637 if (closestdist == -1 || distance < closestdist) {
3638 closestdist = distance;
3643 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3644 victim = Person::players[closest];
3645 animTarget = walljumpleftkickanim;
3647 XYZ rotatetarget = victim->coords - coords;
3648 Normalise(&rotatetarget);
3649 yaw = -asin(0 - rotatetarget.x);
3651 if (rotatetarget.z < 0)
3653 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3654 velocity = (victim->coords - coords) * 4;
3659 if (animTarget != walljumpleftkickanim) {
3660 animTarget = leftflipanim;
3664 velocity = DoRotation(facing, 0, -30, 0) * -8;
3668 resume_stream(whooshsound);
3670 if (animTarget == sneakattackanim) {
3671 animCurrent = getCrouch();
3672 animTarget = getCrouch();
3679 transspeed = 1000000;
3680 targetheadyaw += 180;
3681 coords -= facing * .7;
3683 coords.y = terrain.getHeight(coords.x, coords.z);
3687 if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) {
3688 animTarget = getIdle();
3691 coords.y = terrain.getHeight(coords.x, coords.z);
3695 if (animCurrent == knifefollowanim) {
3696 animTarget = getIdle();
3699 if (animation[animTarget].attack == reversal && animCurrent != sneakattackanim && animCurrent != knifesneakattackanim && animCurrent != swordsneakattackanim && animCurrent != knifefollowanim) {
3700 float ycoords = oldcoords.y;
3701 animTarget = getStop();
3706 transspeed = 1000000;
3707 targetheadyaw += 180;
3708 if (!isnormal(coords.x))
3710 if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim)
3711 oldcoords = coords + facing * .5;
3712 else if (animCurrent == sweepreversalanim)
3713 oldcoords = coords + facing * 1.1;
3714 else if (animCurrent == upunchreversalanim) {
3715 oldcoords = coords + facing * 1.5;
3718 targetheadyaw += 180;
3721 } else if (animCurrent == knifeslashreversalanim) {
3722 oldcoords = coords + facing * .5;
3725 targetheadyaw += 90;
3728 } else if (animCurrent == staffspinhitreversalanim) {
3731 targetheadyaw += 180;
3736 oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z);
3738 oldcoords.y = ycoords;
3739 currentoffset = coords - oldcoords;
3745 if (animCurrent == knifesneakattackedanim || animCurrent == swordsneakattackedanim) {
3750 if (animation[animTarget].attack == reversed) {
3752 if (animTarget == sweepreversedanim)
3754 animTarget = backhandspringanim;
3756 emit_sound_at(landsound, coords, 128);
3758 if (animCurrent == upunchreversedanim || animCurrent == swordslashreversedanim) {
3759 animTarget = rollanim;
3762 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3763 coords.y = oldcoords.y;
3765 if (animCurrent == knifeslashreversedanim) {
3766 animTarget = rollanim;
3771 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3772 coords.y = oldcoords.y;
3776 animTarget = jumpdownanim;
3779 animTarget = getIdle();
3781 animTarget = getIdle();
3782 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
3783 animTarget = getIdle();
3785 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3786 coords.y = oldcoords.y;
3787 //coords+=DoRotation(animation[animCurrent].offset,0,yaw,0)*scale;
3788 targetoffset.y = coords.y;
3790 targetoffset.y = terrain.getHeight(coords.x, coords.z);
3791 currentoffset = DoRotation(animation[animCurrent].offset * -1, 0, yaw, 0) * scale;
3792 currentoffset.y -= (coords.y - targetoffset.y);
3793 coords.y = targetoffset.y;
3795 normalsupdatedelay = 0;
3797 if (animCurrent == upunchanim) {
3798 animTarget = getStop();
3799 normalsupdatedelay = 0;
3802 if (animCurrent == rabbitkickanim && animTarget != backflipanim) {
3806 if (num_weapons > 0)
3807 if (weapons[0].getType() == staff)
3813 rabbitkickragdoll = 1;
3815 if (animCurrent == rabbitkickreversedanim) {
3821 skeleton.spinny = 0;
3822 SolidHitBonus(!id); // FIXME: tricky id
3826 animTarget = rollanim;
3829 pause_sound(whooshsound);
3833 if (animCurrent == rabbittackledbackanim || animCurrent == rabbittackledfrontanim) {
3837 skeleton.spinny = 0;
3839 if (animCurrent == jumpreversedanim) {
3845 skeleton.spinny = 0;
3846 SolidHitBonus(!id); // FIXME: tricky id
3850 animTarget = rollanim;
3851 coords += facing * 2;
3853 pause_sound(whooshsound);
3858 if (animation[animCurrent].attack == normalattack && !victim->skeleton.free && victim->animTarget != staggerbackhighanim && victim->animTarget != staggerbackhardanim && animTarget != winduppunchblockedanim && animTarget != blockhighleftanim && animTarget != swordslashparryanim && animTarget != swordslashparriedanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim) {
3859 animTarget = getupfromfrontanim;
3861 } else if (animation[animCurrent].attack == normalattack) {
3862 animTarget = getIdle();
3865 if (animCurrent == blockhighleftanim && aitype != playercontrolled) {
3866 animTarget = blockhighleftstrikeanim;
3868 if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) {
3869 animTarget = getIdle();
3872 if (animCurrent == spinkickanim && victim->skeleton.free) {
3873 if (creature == rabbittype)
3874 animTarget = fightidleanim;
3879 if (isIdle() && !wasIdle())
3880 normalsupdatedelay = 0;
3882 if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) {
3883 animTarget = jumpdownanim;
3886 if (!skeleton.free) {
3888 if (!transspeed && animation[animTarget].attack != 2 && animation[animTarget].attack != 3) {
3889 if (!isRun() || !wasRun()) {
3890 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
3891 target += multiplier * animation[animTarget].speed[frameTarget] * speed * 2;
3892 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
3893 target += multiplier * animation[animCurrent].speed[frameCurrent] * speed * 2;
3895 if (isRun() && wasRun()) {
3897 tempspeed = velspeed;
3898 if (tempspeed < 10 * speedmult)
3899 tempspeed = 10 * speedmult;
3900 target += multiplier * animation[animTarget].speed[frameCurrent] * speed * 1.7 * tempspeed / (speed * 45 * scale);
3902 } else if (transspeed)
3903 target += multiplier * transspeed * speed * 2;
3905 if (!isRun() || !wasRun()) {
3906 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
3907 target += multiplier * animation[animTarget].speed[frameTarget] * 2;
3908 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
3909 target += multiplier * animation[animCurrent].speed[frameCurrent] * 2;
3913 if (animCurrent != animTarget)
3914 target = (target + oldtarget) / 2;
3917 frameCurrent = frameTarget;
3921 rot = targetrot * target;
3922 yaw += rot - oldrot;
3928 if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
3930 for (int i = 0; i < skeleton.num_joints; i++) {
3931 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent];
3934 skeleton.FindForwards();
3936 for (int i = 0; i < skeleton.num_muscles; i++) {
3937 if (skeleton.muscles[i].visible) {
3938 skeleton.FindRotationMuscle(i, animTarget);
3941 for (int i = 0; i < skeleton.num_muscles; i++) {
3942 if (skeleton.muscles[i].visible) {
3943 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
3944 skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
3945 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
3946 skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
3947 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
3948 skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
3953 for (int i = 0; i < skeleton.num_joints; i++) {
3954 skeleton.joints[i].position = animation[animTarget].position[i][frameTarget];
3957 skeleton.FindForwards();
3959 for (int i = 0; i < skeleton.num_muscles; i++) {
3960 if (skeleton.muscles[i].visible) {
3961 skeleton.FindRotationMuscle(i, animTarget);
3964 for (int i = 0; i < skeleton.num_muscles; i++) {
3965 if (skeleton.muscles[i].visible) {
3966 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
3967 skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
3968 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
3969 skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
3970 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
3971 skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
3972 if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) skeleton.muscles[i].newrotate3 -= 360;
3973 if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) skeleton.muscles[i].newrotate3 += 360;
3974 if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) skeleton.muscles[i].newrotate2 -= 360;
3975 if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) skeleton.muscles[i].newrotate2 += 360;
3976 if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) skeleton.muscles[i].newrotate1 -= 360;
3977 if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) skeleton.muscles[i].newrotate1 += 360;
3981 if (frameCurrent >= animation[animCurrent].numframes)
3982 frameCurrent = animation[animCurrent].numframes - 1;
3984 oldanimCurrent = animCurrent;
3985 oldanimTarget = animTarget;
3986 oldframeTarget = frameTarget;
3987 oldframeCurrent = frameCurrent;
3989 for (int i = 0; i < skeleton.num_joints; i++) {
3990 skeleton.joints[i].velocity = (animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target) - skeleton.joints[i].position) / multiplier;
3991 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target);
3993 offset = currentoffset * (1 - target) + targetoffset * target;
3994 for (int i = 0; i < skeleton.num_muscles; i++) {
3995 if (skeleton.muscles[i].visible) {
3996 skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * (target);
3997 skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * (target);
3998 skeleton.muscles[i].rotate3 = skeleton.muscles[i].oldrotate3 * (1 - target) + skeleton.muscles[i].newrotate3 * (target);
4003 if (isLanding() && landhard) {
4006 animTarget = getLandhard();
4019 void Person::DoStuff()
4021 static XYZ terrainnormal;
4022 static XYZ flatfacing;
4023 static XYZ flatvelocity;
4024 static float flatvelspeed;
4028 static int bloodsize;
4029 static int startx, starty, endx, endy;
4030 static GLubyte color;
4031 static XYZ bloodvel;
4033 onfiredelay -= multiplier;
4034 if (onfiredelay < 0 && onfire) {
4035 if (Random() % 2 == 0) {
4041 crouchkeydowntime += multiplier;
4043 crouchkeydowntime = 0;
4044 jumpkeydowntime += multiplier;
4045 if (!jumpkeydown && skeleton.free)
4046 jumpkeydowntime = 0;
4048 if (hostile || damage > 0 || bloodloss > 0)
4051 if (isIdle() || isRun())
4054 if (num_weapons == 1 && weaponactive != -1)
4058 blooddimamount -= multiplier * .3;
4059 speechdelay -= multiplier;
4060 texupdatedelay -= multiplier;
4061 interestdelay -= multiplier;
4062 flamedelay -= multiplier;
4063 parriedrecently -= multiplier;
4065 victim = this->shared_from_this();
4070 speed = 1.1 * speedmult;
4072 speed = 1.0 * speedmult;
4074 rabbitkickragdoll = 0;
4078 if (id != 0 && (creature == rabbittype || difficulty != 2))
4080 if (id != 0 && creature == wolftype && difficulty == 2) {
4082 if (aitype != passivetype) {
4084 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) {
4090 if (animTarget == wolfrunninganim && !superruntoggle) {
4091 animTarget = getRun();
4095 if (weaponactive == -1 && num_weapons > 0) {
4096 if (weapons[weaponids[0]].getType() == staff) {
4102 burnt += multiplier;
4106 OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3);
4108 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
4114 vel[0] = velocity.x;
4115 vel[1] = velocity.y;
4116 vel[2] = velocity.z;
4119 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4120 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
4124 while (flamedelay < 0 && onfire) {
4126 howmany = abs(Random() % (skeleton.num_joints));
4128 flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4130 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4132 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4134 flatfacing = skeleton.joints[howmany].position * scale + coords;
4135 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
4138 while (flamedelay < 0 && !onfire && tutoriallevel == 1 && id != 0) {
4140 howmany = abs(Random() % (skeleton.num_joints));
4142 flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4144 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4146 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4148 flatfacing = skeleton.joints[howmany].position * scale + coords;
4149 Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
4153 bleeding -= multiplier * .3;
4154 if (bloodtoggle == 2) {
4155 skeleton.drawmodel.textureptr.bind();
4156 if ((bleeding <= 0) && (detail != 2))
4161 if (neckspurtamount > 0) {
4162 neckspurtamount -= multiplier;
4163 neckspurtdelay -= multiplier * 3;
4164 neckspurtparticledelay -= multiplier * 3;
4165 if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
4168 if (!skeleton.free) {
4169 bloodvel.z = 5 * neckspurtamount;
4170 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4172 if (skeleton.free) {
4173 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
4176 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4178 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
4180 Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4182 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4183 neckspurtparticledelay = .05;
4185 if (neckspurtdelay < 0) {
4190 if (deathbleeding > 0 && dead != 2) {
4191 if (deathbleeding < 5)
4192 bleeddelay -= deathbleeding * multiplier / 4;
4194 bleeddelay -= 5 * multiplier / 4;
4195 if (bleeddelay < 0 && bloodtoggle) {
4201 bloodvel += DoRotation(jointVel(abdomen), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
4203 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
4205 Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4207 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
4210 bloodloss += deathbleeding * multiplier * 80;
4211 deathbleeding -= multiplier * 1.6;
4212 if (deathbleeding < 0)
4214 if (bloodloss > damagetolerance && animation[animTarget].attack == neutral) {
4215 if (weaponactive != -1) {
4216 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
4217 weapons[weaponids[0]].velocity.x += .01;
4220 weaponids[0] = weaponids[num_weapons];
4221 if (weaponstuck == num_weapons)
4225 for (unsigned i = 0; i < Person::players.size(); i++) {
4226 Person::players[i]->wentforweapon = 0;
4238 if (!dead && creature == wolftype) {
4239 award_bonus(0, Wolfbonus);
4242 if (animTarget == knifefollowedanim && !skeleton.free) {
4243 for (int i = 0; i < skeleton.num_joints; i++) {
4244 skeleton.joints[i].velocity = 0;
4245 skeleton.joints[i].velocity.y = -2;
4248 if (id != 0 && unconscioustime > .1) {
4256 if (texupdatedelay < 0 && bleeding > 0 && bloodtoggle == 2 && distsq(&viewer, &coords) < 9) {
4257 texupdatedelay = .12;
4259 bloodsize = 5 - realtexdetail;
4263 startx = bleedy; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4264 starty = bleedx; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4265 endx = startx + bloodsize;
4266 endy = starty + bloodsize;
4276 if (endx > skeleton.skinsize - 1) {
4277 endx = skeleton.skinsize - 1;
4280 if (endy > skeleton.skinsize - 1) {
4281 endy = skeleton.skinsize - 1;
4289 for (i = startx; i < endx; i++) {
4290 for (j = starty; j < endy; j++) {
4291 if (Random() % 2 == 0) {
4292 color = Random() % 85 + 170;
4293 if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2)
4294 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2;
4295 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0;
4296 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0;
4301 skeleton.drawmodel.textureptr.bind();
4305 if (!skeleton.free) {
4306 bleedy -= 4 / realtexdetail;
4308 bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4310 bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4312 if (skeleton.free) {
4313 bleedx += 4 * direction / realtexdetail;
4315 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4317 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4321 if (abs(righthandmorphness - targetrighthandmorphness) < multiplier * 4) {
4322 righthandmorphness = targetrighthandmorphness;
4323 righthandmorphstart = righthandmorphend;
4324 } else if (righthandmorphness > targetrighthandmorphness) {
4325 righthandmorphness -= multiplier * 4;
4326 } else if (righthandmorphness < targetrighthandmorphness) {
4327 righthandmorphness += multiplier * 4;
4330 if (abs(lefthandmorphness - targetlefthandmorphness) < multiplier * 4) {
4331 lefthandmorphness = targetlefthandmorphness;
4332 lefthandmorphstart = lefthandmorphend;
4333 } else if (lefthandmorphness > targetlefthandmorphness) {
4334 lefthandmorphness -= multiplier * 4;
4335 } else if (lefthandmorphness < targetlefthandmorphness) {
4336 lefthandmorphness += multiplier * 4;
4339 if (creature == rabbittype || targettailmorphness == 5 || targettailmorphness == 0) {
4340 if (abs(tailmorphness - targettailmorphness) < multiplier * 10) {
4341 tailmorphness = targettailmorphness;
4342 tailmorphstart = tailmorphend;
4343 } else if (tailmorphness > targettailmorphness) {
4344 tailmorphness -= multiplier * 10;
4345 } else if (tailmorphness < targettailmorphness) {
4346 tailmorphness += multiplier * 10;
4350 if (creature == wolftype) {
4351 if (abs(tailmorphness - targettailmorphness) < multiplier * 4) {
4352 tailmorphness = targettailmorphness;
4353 tailmorphstart = tailmorphend;
4354 } else if (tailmorphness > targettailmorphness) {
4355 tailmorphness -= multiplier * 2;
4356 } else if (tailmorphness < targettailmorphness) {
4357 tailmorphness += multiplier * 2;
4361 if (headmorphend == 3 || headmorphstart == 3) {
4362 if (abs(headmorphness - targetheadmorphness) < multiplier * 7) {
4363 headmorphness = targetheadmorphness;
4364 headmorphstart = headmorphend;
4365 } else if (headmorphness > targetheadmorphness) {
4366 headmorphness -= multiplier * 7;
4367 } else if (headmorphness < targetheadmorphness) {
4368 headmorphness += multiplier * 7;
4370 } else if (headmorphend == 5 || headmorphstart == 5) {
4371 if (abs(headmorphness - targetheadmorphness) < multiplier * 10) {
4372 headmorphness = targetheadmorphness;
4373 headmorphstart = headmorphend;
4374 } else if (headmorphness > targetheadmorphness) {
4375 headmorphness -= multiplier * 10;
4376 } else if (headmorphness < targetheadmorphness) {
4377 headmorphness += multiplier * 10;
4380 if (abs(headmorphness - targetheadmorphness) < multiplier * 4) {
4381 headmorphness = targetheadmorphness;
4382 headmorphstart = headmorphend;
4383 } else if (headmorphness > targetheadmorphness) {
4384 headmorphness -= multiplier * 4;
4385 } else if (headmorphness < targetheadmorphness) {
4386 headmorphness += multiplier * 4;
4390 if (abs(chestmorphness - targetchestmorphness) < multiplier) {
4391 chestmorphness = targetchestmorphness;
4392 chestmorphstart = chestmorphend;
4393 } else if (chestmorphness > targetchestmorphness) {
4394 chestmorphness -= multiplier;
4395 } else if (chestmorphness < targetchestmorphness) {
4396 chestmorphness += multiplier;
4399 if (dead != 2 && howactive <= typesleeping) {
4400 if (chestmorphstart == 0 && chestmorphend == 0) {
4402 targetchestmorphness = 1;
4405 if (chestmorphstart != 0 && chestmorphend != 0) {
4407 targetchestmorphness = 1;
4409 if (environment == snowyenvironment) {
4413 footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
4415 footvel = skeleton.specialforward[0] * -1;
4417 footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
4419 footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
4420 if (animTarget == sleepanim)
4421 footvel = DoRotation(footvel, 0, 90, 0);
4422 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
4426 if (!dead && howactive < typesleeping) {
4427 blinkdelay -= multiplier * 2;
4428 if (headmorphstart == 0 && headmorphend == 0 && blinkdelay <= 0) {
4430 targetheadmorphness = 1;
4432 blinkdelay = (float)(abs(Random() % 40)) / 5;
4434 if (headmorphstart == 3 && headmorphend == 3) {
4436 targetheadmorphness = 1;
4441 twitchdelay -= multiplier * 1.5;
4442 if (animTarget != hurtidleanim) {
4443 if (headmorphstart == 0 && headmorphend == 0 && twitchdelay <= 0) {
4445 targetheadmorphness = 1;
4447 twitchdelay = (float)(abs(Random() % 40)) / 5;
4449 if (headmorphstart == 5 && headmorphend == 5) {
4451 targetheadmorphness = 1;
4455 if ((isIdle() || isCrouch()) && animTarget != hurtidleanim) {
4456 twitchdelay3 -= multiplier * 1;
4457 if (Random() % 2 == 0) {
4458 if (righthandmorphstart == 0 && righthandmorphend == 0 && twitchdelay3 <= 0) {
4459 righthandmorphness = 0;
4460 targetrighthandmorphness = 1;
4461 righthandmorphend = 1;
4462 if (Random() % 2 == 0)twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4464 if (righthandmorphstart == 1 && righthandmorphend == 1) {
4465 righthandmorphness = 0;
4466 targetrighthandmorphness = 1;
4467 righthandmorphend = 0;
4470 if (Random() % 2 == 0) {
4471 if (lefthandmorphstart == 0 && lefthandmorphend == 0 && twitchdelay3 <= 0) {
4472 lefthandmorphness = 0;
4473 targetlefthandmorphness = 1;
4474 lefthandmorphend = 1;
4475 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4477 if (lefthandmorphstart == 1 && lefthandmorphend == 1) {
4478 lefthandmorphness = 0;
4479 targetlefthandmorphness = 1;
4480 lefthandmorphend = 0;
4486 if (creature == rabbittype) {
4487 if (howactive < typesleeping)
4488 twitchdelay2 -= multiplier * 1.5;
4490 twitchdelay2 -= multiplier * 0.5;
4491 if (howactive <= typesleeping) {
4492 if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) {
4494 targettailmorphness = 1;
4496 twitchdelay2 = (float)(abs(Random() % 40)) / 5;
4498 if (tailmorphstart == 1 && tailmorphend == 1) {
4500 targettailmorphness = 1;
4503 if (tailmorphstart == 2 && tailmorphend == 2) {
4505 targettailmorphness = 1;
4512 if (creature == wolftype) {
4513 twitchdelay2 -= multiplier * 1.5;
4514 if (tailmorphend != 0)
4515 if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) {
4517 targettailmorphness = 1;
4521 if (tailmorphend != 5)
4522 if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) {
4524 targettailmorphness = 1;
4528 if (twitchdelay2 <= 0) {
4529 if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) {
4531 targettailmorphness = 1;
4534 if (tailmorphstart == 1 && tailmorphend == 1) {
4536 targettailmorphness = 1;
4539 if (tailmorphstart == 2 && tailmorphend == 2) {
4541 targettailmorphness = 1;
4544 if (tailmorphstart == 3 && tailmorphend == 3) {
4546 targettailmorphness = 1;
4549 if (tailmorphstart == 4 && tailmorphend == 4) {
4551 targettailmorphness = 1;
4558 unconscioustime = 0;
4560 if (dead == 1 || howactive == typesleeping) {
4561 unconscioustime += multiplier;
4562 //If unconscious, close eyes and mouth
4563 if (righthandmorphend != 0)
4564 righthandmorphness = 0;
4565 righthandmorphend = 0;
4566 targetrighthandmorphness = 1;
4568 if (lefthandmorphend != 0)
4569 lefthandmorphness = 0;
4570 lefthandmorphend = 0;
4571 targetlefthandmorphness = 1;
4573 if (headmorphend != 3 && headmorphend != 5)
4576 targetheadmorphness = 1;
4580 if (howactive > typesleeping) {
4583 if (bloodtoggle && !bled) {
4584 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4586 if (bloodtoggle && !bled)
4587 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4588 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4589 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4593 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4598 if (dead == 2 || howactive > typesleeping) {
4599 //If dead, open mouth and hands
4600 if (righthandmorphend != 0)
4601 righthandmorphness = 0;
4602 righthandmorphend = 0;
4603 targetrighthandmorphness = 1;
4605 if (lefthandmorphend != 0)
4606 lefthandmorphness = 0;
4607 lefthandmorphend = 0;
4608 targetlefthandmorphness = 1;
4610 if (headmorphend != 2)
4613 targetheadmorphness = 1;
4616 if (stunned > 0 && !dead && headmorphend != 2) {
4617 if (headmorphend != 4)
4620 targetheadmorphness = 1;
4623 if (damage > damagetolerance && !dead) {
4626 unconscioustime = 0;
4628 if (creature == wolftype) {
4629 award_bonus(0, Wolfbonus);
4634 if (weaponactive != -1) {
4635 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
4636 weapons[weaponids[0]].velocity.x += .01;
4639 weaponids[0] = weaponids[num_weapons];
4640 if (weaponstuck == num_weapons)
4644 for (unsigned i = 0; i < Person::players.size(); i++) {
4645 Person::players[i]->wentforweapon = 0;
4651 if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) {
4660 damage -= multiplier * 13;
4662 permanentdamage -= multiplier * 4;
4663 if (isIdle() || isCrouch()) {
4665 permanentdamage -= multiplier * 4;
4669 if (permanentdamage < 0)
4670 permanentdamage = 0;
4671 if (superpermanentdamage < 0)
4672 superpermanentdamage = 0;
4673 if (permanentdamage < superpermanentdamage) {
4674 permanentdamage = superpermanentdamage;
4676 if (damage < permanentdamage) {
4677 damage = permanentdamage;
4679 if (dead == 1 && damage < damagetolerance) {
4683 for (int i = 0; i < skeleton.num_joints; i++) {
4684 skeleton.joints[i].velocity = 0;
4687 if (permanentdamage > damagetolerance && dead != 2) {
4690 if (weaponactive != -1) {
4691 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
4692 weapons[weaponids[0]].velocity.x += .01;
4695 weaponids[0] = weaponids[num_weapons];
4696 if (weaponstuck == num_weapons)
4700 for (unsigned i = 0; i < Person::players.size(); i++) {
4701 Person::players[i]->wentforweapon = 0;
4707 if (!dead && creature == wolftype) {
4708 award_bonus(0, Wolfbonus);
4711 if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance)
4712 award_bonus(id, touchofdeath);
4713 if (id != 0 && unconscioustime > .1) {
4721 emit_sound_at(breaksound, coords);
4724 if (skeleton.free == 1) {
4726 pause_sound(whooshsound);
4729 //If knocked over, open hands and close mouth
4730 if (righthandmorphend != 0)
4731 righthandmorphness = 0;
4732 righthandmorphend = 0;
4733 targetrighthandmorphness = 1;
4735 if (lefthandmorphend != 0)
4736 lefthandmorphness = 0;
4737 lefthandmorphend = 0;
4738 targetlefthandmorphness = 1;
4740 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) {
4741 if (headmorphend != 0)
4744 targetheadmorphness = 1;
4748 skeleton.DoGravity(&scale);
4750 damageamount = skeleton.DoConstraints(&coords, &scale) * 5;
4751 if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1))
4752 award_bonus(id, deepimpact);
4753 DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3));
4757 for (j = 0; j < skeleton.num_joints; j++) {
4758 average += skeleton.joints[j].position;
4762 coords += average * scale;
4763 for (j = 0; j < skeleton.num_joints; j++) {
4764 skeleton.joints[j].position -= average;
4766 average /= multiplier;
4768 //velocity=jointVel(groin)*scale;
4770 for (int i = 0; i < skeleton.num_joints; i++) {
4771 velocity += skeleton.joints[i].velocity * scale;
4773 velocity /= skeleton.num_joints;
4775 if (!isnormal(velocity.x) && velocity.x) {
4779 if (findLength(&average) < 10 && dead && skeleton.free) {
4780 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
4781 if (skeleton.longdead > 2000) {
4782 if (skeleton.longdead > 6000) {
4784 pause_sound(whooshsound);
4789 if (dead == 2 && bloodloss < damagetolerance) {
4791 headpoint = (jointPos(head) + jointPos(neck)) / 2 * scale + coords;
4793 if (bloodtoggle && !bled) {
4794 terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
4796 if (bloodtoggle && !bled)
4797 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4798 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4799 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4800 float size = .2 * 1.2;
4803 objects.model[j].MakeDecal(blooddecal, &point, &size, &opacity, &yaw);
4807 if (dead == 2 && bloodloss >= damagetolerance) {
4809 headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords;
4812 if (bloodtoggle && !bled) {
4813 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4815 if (bloodtoggle && !bled)
4816 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4817 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4818 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4822 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4829 if (!dead && crouchkeydown && skeleton.freetime > .5 && id == 0 && skeleton.free) {
4830 bool canrecover = 1;
4831 XYZ startpoint, endpoint, colpoint, colviewer, coltarget;
4832 startpoint = coords;
4835 if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1)
4837 if (velocity.y < -30)
4839 for (i = 0; i < objects.numobjects; i++) {
4840 if (objects.type[i] != treeleavestype && objects.type[i] != bushtype && objects.type[i] != firetype) {
4841 colviewer = startpoint;
4842 coltarget = endpoint;
4843 if (objects.model[i].LineCheck(&colviewer, &coltarget, &colpoint, &objects.position[i], &objects.yaw[i]) != -1)
4852 terrainnormal = jointPos(groin) - jointPos(abdomen);
4853 if (joint(groin).locked && joint(abdomen).locked) {
4854 terrainnormal = jointPos(groin) - jointPos(abdomen);
4855 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
4857 if (joint(abdomen).locked && joint(neck).locked) {
4858 terrainnormal = jointPos(abdomen) - jointPos(neck);
4859 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
4861 if (joint(groin).locked && joint(neck).locked) {
4862 terrainnormal = jointPos(groin) - jointPos(neck);
4863 middle = (jointPos(groin) + jointPos(neck)) / 2;
4865 Normalise(&terrainnormal);
4867 targetyaw = -asin(0 - terrainnormal.x);
4868 targetyaw *= 360 / 6.28;
4869 if (terrainnormal.z < 0)
4870 targetyaw = 180 - targetyaw;
4874 animTarget = flipanim;
4875 crouchtogglekeydown = 1;
4880 animCurrent = tempanim;
4884 for (int i = 0; i < skeleton.num_joints; i++) {
4885 tempanimation.position[i][0] = skeleton.joints[i].position;
4886 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
4891 if (findLength(&average) < 10 && !dead && skeleton.free) {
4892 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
4893 if (skeleton.longdead > (damage + 500) * 1.5) {
4895 pause_sound(whooshsound);
4901 terrainnormal = jointPos(groin) - jointPos(abdomen);
4902 if (joint(groin).locked && joint(abdomen).locked) {
4903 terrainnormal = jointPos(groin) - jointPos(abdomen);
4904 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
4906 if (joint(abdomen).locked && joint(neck).locked) {
4907 terrainnormal = jointPos(abdomen) - jointPos(neck);
4908 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
4910 if (joint(groin).locked && joint(neck).locked) {
4911 terrainnormal = jointPos(groin) - jointPos(neck);
4912 middle = (jointPos(groin) + jointPos(neck)) / 2;
4914 Normalise(&terrainnormal);
4916 targetyaw = -asin(0 - terrainnormal.x);
4917 targetyaw *= 360 / 6.28;
4918 if (terrainnormal.z < 0)
4919 targetyaw = 180 - targetyaw;
4922 targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1;
4925 if (skeleton.forward.y < 0) {
4926 animTarget = getupfrombackanim;
4930 if (skeleton.forward.y > -.3) {
4931 animTarget = getupfromfrontanim;
4939 if ((Random() % 8 == 0 && id != 0 && creature == rabbittype) || (Random() % 2 == 0 && id != 0 && creature == wolftype) || (id == 0 && crouchkeydown && (forwardkeydown || backkeydown || leftkeydown || rightkeydown))) {
4940 animTarget = rollanim;
4941 targetyaw = lookyaw;
4958 if ( !leftkeydown && !rightkeydown)
4965 if (abs(targettilt2) > 50)
4967 animCurrent = tempanim;
4970 tilt2 = targettilt2;
4972 if (middle.y > 0 && animTarget != rollanim)
4973 targetoffset.y = middle.y + 1;
4975 for (int i = 0; i < skeleton.num_joints; i++) {
4976 tempanimation.position[i][0] = skeleton.joints[i].position;
4977 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
4984 if (num_weapons > 0)
4985 if (weapons[0].getType() == staff)
4987 if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) {
4988 if (velocity.y > -30) {
4990 tempvelocity = velocity;
4991 Normalise(&tempvelocity);
4992 targetyaw = -asin(0 - tempvelocity.x);
4993 targetyaw *= 360 / 6.28;
4995 targetyaw = 180 - targetyaw;
4999 if (dotproduct(&skeleton.forward, &tempvelocity) < 0) {
5000 animTarget = rollanim;
5003 animTarget = backhandspringanim;
5009 emit_sound_at(movewhooshsound, coords, 128.);
5011 animCurrent = animTarget;
5012 frameCurrent = frameTarget - 1;
5024 if (skeleton.freefall == 0)
5029 if (aitype != passivetype || skeleton.free == 1)
5030 if (findLengthfast(&velocity) > .1)
5031 for (i = 0; i < objects.numobjects; i++) {
5032 if (objects.type[i] == firetype)
5033 if (distsqflat(&coords, &objects.position[i]) < objects.scale[i]*objects.scale[i] * 12 && distsq(&coords, &objects.position[i]) < objects.scale[i]*objects.scale[i] * 49) {
5035 if (!objects.onfire[i]) {
5036 emit_sound_at(firestartsound, objects.position[i]);
5038 objects.onfire[i] = 1;
5041 if (objects.onfire[i]) {
5046 if (objects.type[i] == bushtype)
5047 if (distsqflat(&coords, &objects.position[i]) < objects.scale[i]*objects.scale[i] * 12 && distsq(&coords, &objects.position[i]) < objects.scale[i]*objects.scale[i] * 49) {
5049 if (!objects.onfire[i]) {
5050 emit_sound_at(firestartsound, objects.position[i]);
5052 objects.onfire[i] = 1;
5056 if (objects.onfire[i]) {
5060 if (objects.messedwith[i] <= 0) {
5064 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5067 envsound[numenvsounds] = coords;
5068 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5069 envsoundlife[numenvsounds] = .4;
5074 if (environment == grassyenvironment)
5075 howmany = findLength(&velocity) * 4;
5076 if (environment == snowyenvironment)
5077 howmany = findLength(&velocity) * 2;
5079 if (environment != desertenvironment)
5080 for (j = 0; j < howmany; j++) {
5081 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5082 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5083 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5086 pos.x += float(abs(Random() % 100) - 50) / 200;
5087 pos.y += float(abs(Random() % 100) - 50) / 200;
5088 pos.z += float(abs(Random() % 100) - 50) / 200;
5089 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);
5090 Sprite::setLastSpriteSpecial(1);
5092 howmany = findLength(&velocity) * 4;
5094 if (environment == snowyenvironment)
5095 for (j = 0; j < howmany; j++) {
5096 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5097 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5098 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5101 pos.x += float(abs(Random() % 100) - 50) / 200;
5102 pos.y += float(abs(Random() % 100) - 50) / 200;
5103 pos.z += float(abs(Random() % 100) - 50) / 200;
5104 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5105 Sprite::setLastSpriteSpecial(2);
5108 objects.rotx[i] += velocity.x * multiplier * 6;
5109 objects.roty[i] += velocity.z * multiplier * 6;
5110 objects.messedwith[i] = .5;
5113 if (objects.type[i] == treeleavestype && environment != desertenvironment) {
5114 if (objects.pitch[i] == 0)
5117 tempcoord = coords - objects.position[i];
5118 tempcoord = DoRotation(tempcoord, 0, -objects.yaw[i], 0);
5119 tempcoord = DoRotation(tempcoord, -objects.pitch[i], 0, 0);
5120 tempcoord += objects.position[i];
5122 if (distsqflat(&tempcoord, &objects.position[i]) < objects.scale[i]*objects.scale[i] * 8 && distsq(&tempcoord, &objects.position[i]) < objects.scale[i]*objects.scale[i] * 300 && tempcoord.y > objects.position[i].y + 3 * objects.scale[i]) {
5123 if (objects.messedwith[i] <= 0) {
5127 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5130 envsound[numenvsounds] = coords;
5131 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5132 envsoundlife[numenvsounds] = .4;
5137 if (environment == grassyenvironment)
5138 howmany = findLength(&velocity) * 4;
5139 if (environment == snowyenvironment)
5140 howmany = findLength(&velocity) * 2;
5142 if (environment != desertenvironment)
5143 for (j = 0; j < howmany; j++) {
5144 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5145 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5146 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5148 pos += velocity * .1;
5150 pos.x += float(abs(Random() % 100) - 50) / 150;
5151 pos.y += float(abs(Random() % 100) - 50) / 150;
5152 pos.z += float(abs(Random() % 100) - 50) / 150;
5153 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);
5154 Sprite::setLastSpriteSpecial(1);
5156 howmany = findLength(&velocity) * 4;
5158 if (environment == snowyenvironment)
5159 for (j = 0; j < howmany; j++) {
5160 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5161 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5162 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5164 pos += velocity * .1;
5166 pos.x += float(abs(Random() % 100) - 50) / 150;
5167 pos.y += float(abs(Random() % 100) - 50) / 150;
5168 pos.z += float(abs(Random() % 100) - 50) / 150;
5169 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5170 Sprite::setLastSpriteSpecial(2);
5173 objects.messedwith[i] = .5;
5178 if (!skeleton.free) {
5181 if ((stunned > 0 || surprised > 0) && Person::players.size() > 2 && aitype != passivetype)
5184 if (aitype != passivetype && victim->skeleton.free && !victim->dead)
5186 if (tutoriallevel == 1 && id != 0)
5188 if (play && aitype != playercontrolled) {
5189 int whichsound = -1;
5190 i = abs(Random() % 4);
5191 if (speechdelay <= 0) {
5192 if (creature == rabbittype) {
5194 whichsound = rabbitchitter;
5196 whichsound = rabbitchitter2;
5198 if (creature == wolftype) {
5200 whichsound = growlsound;
5202 whichsound = growl2sound;
5207 if (whichsound != -1) {
5208 emit_sound_at(whichsound, coords);
5212 if (animTarget == staggerbackhighanim)
5214 if (animTarget == staggerbackhardanim)
5216 staggerdelay -= multiplier;
5217 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
5219 if (velocity.y < -30 && animTarget == jumpdownanim)
5221 if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) {
5222 animTarget = getIdle();
5226 weaponmissdelay -= multiplier;
5227 highreversaldelay -= multiplier;
5228 lowreversaldelay -= multiplier;
5229 lastcollide -= multiplier;
5230 skiddelay -= multiplier;
5231 if (!isnormal(velocity.x) && velocity.x) {
5234 if (!isnormal(targettilt) && targettilt) {
5237 if (!isnormal(targettilt2) && targettilt2) {
5240 if (!isnormal(targetyaw) && targetyaw) {
5244 if (animTarget == bounceidleanim || animTarget == wolfidle || animTarget == walkanim || animTarget == drawrightanim || animTarget == crouchdrawrightanim || animTarget == drawleftanim || animTarget == fightidleanim || animTarget == fightsidestep || animTarget == hanganim || isCrouch() || animTarget == backhandspringanim) {
5245 //open hands and close mouth
5246 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5247 righthandmorphness = 0;
5248 righthandmorphend = 0;
5249 targetrighthandmorphness = 1;
5252 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5253 lefthandmorphness = 0;
5254 lefthandmorphend = 0;
5255 targetlefthandmorphness = 1;
5258 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5 && headmorphend != 0 && headmorphness == targetheadmorphness) {
5261 targetheadmorphness = 1;
5265 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) {
5266 //open hands and mouth
5267 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5268 righthandmorphness = 0;
5269 righthandmorphend = 0;
5270 targetrighthandmorphness = 1;
5273 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5274 lefthandmorphness = 0;
5275 lefthandmorphend = 0;
5276 targetlefthandmorphness = 1;
5279 if (headmorphend != 1 && headmorphness == targetheadmorphness) {
5282 targetheadmorphness = 1;
5286 if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim) {
5287 //close hands and mouth
5288 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5289 righthandmorphness = 0;
5290 righthandmorphend = 1;
5291 targetrighthandmorphness = 1;
5294 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5295 lefthandmorphness = 0;
5296 lefthandmorphend = 1;
5297 targetlefthandmorphness = 1;
5300 if (headmorphend != 0 && headmorphness == targetheadmorphness) {
5303 targetheadmorphness = 1;
5307 if (animTarget == spinkickanim || animTarget == staffspinhitreversalanim || animTarget == staffspinhitreversedanim || animTarget == staffhitreversalanim || animTarget == staffhitreversedanim || animTarget == hurtidleanim || animTarget == winduppunchanim || animTarget == swordslashreversalanim || animTarget == swordslashreversedanim || animTarget == knifeslashreversalanim || animTarget == knifeslashreversedanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == knifefollowedanim || animTarget == killanim || animTarget == dropkickanim || animTarget == upunchanim || animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim || animTarget == staffgroundsmashanim || animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == lowkickanim || animTarget == sweepreversedanim || animTarget == rabbitkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversalanim || animTarget == jumpreversedanim) {
5308 //close hands and yell
5309 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5310 righthandmorphness = 0;
5311 righthandmorphend = 1;
5312 targetrighthandmorphness = 1;
5315 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5316 lefthandmorphness = 0;
5317 lefthandmorphend = 1;
5318 targetlefthandmorphness = 1;
5321 if (headmorphend != 2 && headmorphness == targetheadmorphness) {
5324 targetheadmorphness = 1;
5331 if ((victim != this->shared_from_this()) && !victim->dead && (victim->aitype != passivetype) &&
5332 (victim->aitype != searchtype) && (aitype != passivetype) &&
5333 (aitype != searchtype) && (victim->id < Person::players.size()) && (aitype != passivetype)) {
5334 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
5338 if (!dead && animTarget != hurtidleanim)
5339 if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) {
5340 if (headmorphend != 4 || headmorphness == targetheadmorphness) {
5343 targetheadmorphness = 1;
5347 if (weaponactive != -1) {
5348 if (weapons[weaponids[weaponactive]].getType() != staff) {
5349 righthandmorphstart = 1;
5350 righthandmorphend = 1;
5352 if (weapons[weaponids[weaponactive]].getType() == staff) {
5353 righthandmorphstart = 2;
5354 righthandmorphend = 2;
5356 targetrighthandmorphness = 1;
5359 terrainnormal = terrain.getNormal(coords.x, coords.z);
5361 if (animation[animTarget].attack != reversal) {
5362 if (!isnormal(coords.x))
5370 flatfacing = DoRotation(flatfacing, 0, yaw, 0);
5371 facing = flatfacing;
5372 ReflectVector(&facing, terrainnormal);
5375 if (isRun() || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) {
5377 targettilt2 = -facing.y * 20;
5382 if (!isRun() && !animation[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim)
5384 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5385 flatvelocity = velocity;
5387 flatvelspeed = findLength(&flatvelocity);
5388 targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity);
5389 targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity);
5394 if (targettilt > 25)
5396 if (targettilt < -25)
5400 if (targettilt2 > 45)
5402 if (targettilt2 < -45)
5404 if (abs(tilt2 - targettilt2) < multiplier * 400)
5405 tilt2 = targettilt2;
5406 else if (tilt2 > targettilt2) {
5407 tilt2 -= multiplier * 400;
5408 } else if (tilt2 < targettilt2) {
5409 tilt2 += multiplier * 400;
5411 if (!animation[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) {
5418 if (!isnormal(targettilt) && targettilt) {
5421 if (!isnormal(targettilt2) && targettilt2) {
5426 if (animTarget == rabbittackleanim) {
5427 velocity += facing * multiplier * speed * 700 * scale;
5428 velspeed = findLength(&velocity);
5429 if (velspeed > speed * 65 * scale) {
5430 velocity /= velspeed;
5431 velspeed = speed * 65 * scale;
5432 velocity *= velspeed;
5434 velocity.y += gravity * multiplier * 20;
5435 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5436 velspeed = findLength(&velocity);
5437 velocity = flatfacing * velspeed;
5439 if (animTarget != rabbitrunninganim && animTarget != wolfrunninganim) {
5440 if (isRun() || animTarget == rabbitkickanim) {
5441 velocity += facing * multiplier * speed * 700 * scale;
5442 velspeed = findLength(&velocity);
5443 if (velspeed > speed * 45 * scale) {
5444 velocity /= velspeed;
5445 velspeed = speed * 45 * scale;
5446 velocity *= velspeed;
5448 velocity.y += gravity * multiplier * 20;
5449 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5450 velspeed = findLength(&velocity);
5451 if (velspeed < speed * 30 * scale)
5452 velspeed = speed * 30 * scale;
5453 velocity = flatfacing * velspeed;
5455 } else if (isRun()) {
5456 velocity += facing * multiplier * speed * 700 * scale;
5457 velspeed = findLength(&velocity);
5458 if (creature == rabbittype) {
5459 if (velspeed > speed * 55 * scale) {
5460 velocity /= velspeed;
5461 velspeed = speed * 55 * scale;
5462 velocity *= velspeed;
5465 if (creature == wolftype) {
5466 if (velspeed > speed * 75 * scale) {
5467 velocity /= velspeed;
5468 velspeed = speed * 75 * scale;
5469 velocity *= velspeed;
5472 velocity.y += gravity * multiplier * 20;
5473 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5474 velspeed = findLength(&velocity);
5475 velocity = flatfacing * velspeed;
5478 if (animTarget == rollanim && animation[animTarget].label[frameTarget] != 6) {
5479 velocity += facing * multiplier * speed * 700 * scale;
5480 velspeed = findLength(&velocity);
5481 if (velspeed > speed * 45 * scale) {
5482 velocity /= velspeed;
5483 velspeed = speed * 45 * scale;
5484 velocity *= velspeed;
5486 velocity.y += gravity * multiplier * 20;
5487 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5488 velspeed = findLength(&velocity);
5489 velocity = flatfacing * velspeed;
5492 if (animTarget == sneakanim || animTarget == walkanim) {
5493 velocity += facing * multiplier * speed * 700 * scale;
5494 velspeed = findLength(&velocity);
5495 if (velspeed > speed * 12 * scale) {
5496 velocity /= velspeed;
5497 velspeed = speed * 12 * scale;
5498 velocity *= velspeed;
5500 velocity.y += gravity * multiplier * 20;
5501 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5502 velspeed = findLength(&velocity);
5503 velocity = flatfacing * velspeed;
5506 if ((animTarget == fightidleanim || animTarget == knifefightidleanim) && (animCurrent == bounceidleanim || animCurrent == hurtidleanim)) {
5507 velocity += facing * multiplier * speed * 700 * scale;
5508 velspeed = findLength(&velocity);
5509 if (velspeed > speed * 2 * scale) {
5510 velocity /= velspeed;
5511 velspeed = speed * 2 * scale;
5512 velocity *= velspeed;
5514 velocity.y += gravity * multiplier * 20;
5515 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5516 velspeed = findLength(&velocity);
5517 velocity = flatfacing * velspeed;
5521 if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) {
5522 velocity -= facing * multiplier * speed * 700 * scale;
5523 velspeed = findLength(&velocity);
5524 if (velspeed > speed * 2 * scale) {
5525 velocity /= velspeed;
5526 velspeed = speed * 2 * scale;
5527 velocity *= velspeed;
5529 velocity.y += gravity * multiplier * 20;
5530 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5531 velspeed = findLength(&velocity);
5532 velocity = flatfacing * velspeed * -1;
5535 if (animTarget == fightsidestep) {
5536 velocity += DoRotation(facing * multiplier * speed * 700 * scale, 0, -90, 0);
5537 velspeed = findLength(&velocity);
5538 if (velspeed > speed * 12 * scale) {
5539 velocity /= velspeed;
5540 velspeed = speed * 12 * scale;
5541 velocity *= velspeed;
5543 velocity.y += gravity * multiplier * 20;
5544 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5545 velspeed = findLength(&velocity);
5546 velocity = DoRotation(flatfacing * velspeed, 0, -90, 0);
5549 if (animTarget == staggerbackhighanim) {
5550 coords -= facing * multiplier * speed * 16 * scale;
5553 if (animTarget == staggerbackhardanim && animation[staggerbackhardanim].label[frameTarget] != 6) {
5554 coords -= facing * multiplier * speed * 20 * scale;
5558 if (animTarget == backhandspringanim) {
5559 //coords-=facing*multiplier*50*scale;
5560 velocity += facing * multiplier * speed * 700 * scale * -1;
5561 velspeed = findLength(&velocity);
5562 if (velspeed > speed * 50 * scale) {
5563 velocity /= velspeed;
5564 velspeed = speed * 50 * scale;
5565 velocity *= velspeed;
5567 velocity.y += gravity * multiplier * 20;
5568 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5569 velspeed = findLength(&velocity);
5570 velocity = flatfacing * velspeed * -1;
5572 if (animTarget == dodgebackanim) {
5573 //coords-=facing*multiplier*50*scale;
5574 velocity += facing * multiplier * speed * 700 * scale * -1;
5575 velspeed = findLength(&velocity);
5576 if (velspeed > speed * 60 * scale) {
5577 velocity /= velspeed;
5578 velspeed = speed * 60 * scale;
5579 velocity *= velspeed;
5581 velocity.y += gravity * multiplier * 20;
5582 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5583 velspeed = findLength(&velocity);
5584 velocity = flatfacing * velspeed * -1;
5587 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5588 velspeed = findLength(&velocity);
5592 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5593 velocity.y += gravity * multiplier;
5596 if (animTarget != climbanim && animTarget != hanganim && !isWallJump())
5597 coords += velocity * multiplier;
5599 if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
5600 if (isFlip() && animation[animTarget].label[frameTarget] == 7)
5603 if (animTarget == jumpupanim) {
5605 animTarget = getIdle();
5612 pause_sound(whooshsound);
5613 OPENAL_SetVolume(channels[whooshsound], 0);
5616 if (animTarget == jumpdownanim || isFlip()) {
5617 if (isFlip())jumppower = -4;
5618 animTarget = getLanding();
5619 emit_sound_at(landsound, coords, 128.);
5622 envsound[numenvsounds] = coords;
5623 envsoundvol[numenvsounds] = 16;
5624 envsoundlife[numenvsounds] = .4;
5630 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump())
5631 coords.y += gravity * multiplier * 2;
5632 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) {
5633 coords.y = terrain.getHeight(coords.x, coords.z);
5638 if (isIdle() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || isStop() || animTarget == removeknifeanim || animTarget == crouchremoveknifeanim || isLanding() || isCrouch() || animation[animTarget].attack || (animTarget == rollanim && animation[animTarget].label[frameTarget] == 6)) {
5639 velspeed = findLength(&velocity);
5641 if (velspeed < multiplier * 300 * scale) {
5644 velocity -= velocity / velspeed * multiplier * 300 * scale;
5645 if (velspeed > 5 && (isLanding() || isLandhard())) {
5646 skiddingdelay += multiplier;
5647 if (skiddelay <= 0) {
5657 velspeed = findLength(&velocity);
5659 if (velspeed < multiplier * 600 * scale) {
5662 velocity -= velocity / velspeed * multiplier * 600 * scale;
5664 if (velspeed > 5 && (isLanding() || isLandhard())) {
5665 skiddingdelay += multiplier;
5666 if (skiddelay <= 0) {
5675 if (skiddingdelay < 0)
5676 skiddingdelay += multiplier;
5677 if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) {
5679 if (!onterrain || environment == grassyenvironment) {
5680 emit_sound_at(skidsound, coords, 128 * velspeed / 10);
5682 emit_sound_at(snowskidsound, coords, 128 * velspeed / 10);
5686 if (animation[animTarget].attack == normalattack && animTarget != rabbitkickanim && !victim->skeleton.free) {
5687 terrainnormal = victim->coords - coords;
5688 Normalise(&terrainnormal);
5689 targetyaw = -asin(0 - terrainnormal.x);
5690 targetyaw *= 360 / 6.28;
5691 if (terrainnormal.z < 0)
5692 targetyaw = 180 - targetyaw;
5693 targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70;
5696 if (animation[animTarget].attack == reversal && animTarget != rabbittacklinganim) {
5697 targetyaw = victim->targetyaw;
5699 if (animTarget == rabbittacklinganim) {
5700 coords = victim->coords;
5703 skeleton.oldfree = skeleton.free;
5707 midterrain.x = terrain.size * terrain.scale / 2;
5708 midterrain.z = terrain.size * terrain.scale / 2;
5709 if (distsqflat(&coords, &midterrain) > (terrain.size * terrain.scale / 2 - viewdistance) * (terrain.size * terrain.scale / 2 - viewdistance)) {
5711 tempposit = coords - midterrain;
5713 Normalise(&tempposit);
5714 tempposit *= (terrain.size * terrain.scale / 2 - viewdistance);
5715 coords.x = tempposit.x + midterrain.x;
5716 coords.z = tempposit.z + midterrain.z;
5722 * inverse kinematics helper function
5724 void IKHelper(Person *p, float interp)
5726 XYZ point, newpoint, change, change2;
5727 float heightleft, heightright;
5729 // TODO: implement localToWorld and worldToLocal
5730 // but keep in mind it won't be the same math if player is ragdolled or something
5731 // - localToWorldStanding / worldToLocalStanding (or crouching or...?)
5732 // then comb through code for places where to use it
5734 // point = localToWorld(jointPos(leftfoot))
5735 point = DoRotation(p->jointPos(leftfoot), 0, p->yaw, 0) * p->scale + p->coords;
5736 // adjust height of foot
5737 heightleft = terrain.getHeight(point.x, point.z) + .04;
5738 point.y = heightleft;
5739 change = p->jointPos(leftankle) - p->jointPos(leftfoot);
5740 change2 = p->jointPos(leftknee) - p->jointPos(leftfoot);
5741 // jointPos(leftfoot) = interpolate(worldToLocal(point), jointPos(leftfoot), interp)
5742 p->jointPos(leftfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(leftfoot) * (1 - interp);
5743 // move ankle along with foot
5744 p->jointPos(leftankle) = p->jointPos(leftfoot) + change;
5745 // average knee pos between old and new pos
5746 p->jointPos(leftknee) = (p->jointPos(leftfoot) + change2) / 2 + (p->jointPos(leftknee)) / 2;
5748 // do same as above for right leg
5749 point = DoRotation(p->jointPos(rightfoot), 0, p->yaw, 0) * p->scale + p->coords;
5750 heightright = terrain.getHeight(point.x, point.z) + .04;
5751 point.y = heightright;
5752 change = p->jointPos(rightankle) - p->jointPos(rightfoot);
5753 change2 = p->jointPos(rightknee) - p->jointPos(rightfoot);
5754 p->jointPos(rightfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(rightfoot) * (1 - interp);
5755 p->jointPos(rightankle) = p->jointPos(rightfoot) + change;
5756 p->jointPos(rightknee) = (p->jointPos(rightfoot) + change2) / 2 + (p->jointPos(rightknee)) / 2;
5758 // fix up skeleton now that we've moved body parts?
5759 p->skeleton.DoConstraints(&p->coords, &p->scale);
5766 int Person::DrawSkeleton()
5768 int oldplayerdetail;
5769 if ((frustum.SphereInFrustum(coords.x, coords.y + scale * 3, coords.z, scale * 8) && distsq(&viewer, &coords) < viewdistance * viewdistance) || skeleton.free == 3) {
5770 if (onterrain && (isIdle() || isCrouch() || wasIdle() || wasCrouch()) && !skeleton.free) {
5780 glAlphaFunc(GL_GREATER, 0.0001);
5782 float terrainheight;
5786 if (!isnormal(tilt))
5788 if (!isnormal(tilt2))
5790 oldplayerdetail = playerdetail;
5792 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) {
5795 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 128 && detail == 1) {
5798 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) {
5803 if (playerdetail != oldplayerdetail) {
5805 normalsupdatedelay = 0;
5807 static float updatedelaychange;
5808 static float morphness;
5809 static float framemult;
5811 skeleton.FindForwards();
5812 if (howactive == typesittingwall) {
5813 skeleton.specialforward[1] = 0;
5814 skeleton.specialforward[1].z = 1;
5820 static int weaponattachmuscle;
5821 static int weaponrotatemuscle;
5822 static XYZ weaponpoint;
5823 static int start, endthing;
5824 if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
5825 if (!isSleeping() && !isSitting()) {
5826 // TODO: give these meaningful names
5827 const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard()
5828 || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim);
5829 const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard()
5830 || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim);
5832 if (onterrain && (cond1 && cond2) && !skeleton.free) {
5834 if (creature == wolftype)
5838 if (onterrain && (cond1 && !cond2) && !skeleton.free) {
5839 IKHelper(this, target);
5840 if (creature == wolftype)
5841 IKHelper(this, target);
5844 if (onterrain && (!cond1 && cond2) && !skeleton.free) {
5845 IKHelper(this, 1 - target);
5846 if (creature == wolftype)
5847 IKHelper(this, 1 - target);
5851 if (!skeleton.free && (!animation[animTarget].attack && animTarget != getupfrombackanim && ((animTarget != rollanim && !isFlip()) || animation[animTarget].label[frameTarget] == 6) && animTarget != getupfromfrontanim && animTarget != wolfrunninganim && animTarget != rabbitrunninganim && animTarget != backhandspringanim && animTarget != walljumpfrontanim && animTarget != hurtidleanim && !isLandhard() && !isSleeping()))
5854 targetheadyaw = -targetyaw;
5855 targetheadpitch = 0;
5856 if (animation[animTarget].attack == 3)
5857 targetheadyaw += 180;
5859 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
5860 skeleton.drawmodel.vertex[i] = 0;
5861 skeleton.drawmodel.vertex[i].y = 999;
5863 for (i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
5864 skeleton.drawmodellow.vertex[i] = 0;
5865 skeleton.drawmodellow.vertex[i].y = 999;
5867 for (i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
5868 skeleton.drawmodelclothes.vertex[i] = 0;
5869 skeleton.drawmodelclothes.vertex[i].y = 999;
5871 for (int i = 0; i < skeleton.num_muscles; i++) {
5872 // convenience renames
5873 const int p1 = skeleton.muscles[i].parent1->label;
5874 const int p2 = skeleton.muscles[i].parent2->label;
5876 if ((skeleton.muscles[i].numvertices > 0 && playerdetail) || (skeleton.muscles[i].numverticeslow > 0 && !playerdetail)) {
5881 if (p1 == righthand || p2 == righthand) {
5882 morphness = righthandmorphness;
5883 start = righthandmorphstart;
5884 endthing = righthandmorphend;
5886 if (p1 == lefthand || p2 == lefthand) {
5887 morphness = lefthandmorphness;
5888 start = lefthandmorphstart;
5889 endthing = lefthandmorphend;
5891 if (p1 == head || p2 == head) {
5892 morphness = headmorphness;
5893 start = headmorphstart;
5894 endthing = headmorphend;
5896 if ((p1 == neck && p2 == abdomen) || (p2 == neck && p1 == abdomen)) {
5897 morphness = chestmorphness;
5898 start = chestmorphstart;
5899 endthing = chestmorphend;
5901 if ((p1 == groin && p2 == abdomen) || (p2 == groin && p1 == abdomen)) {
5902 morphness = tailmorphness;
5903 start = tailmorphstart;
5904 endthing = tailmorphend;
5907 skeleton.FindRotationMuscle(i, animTarget);
5908 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
5909 glMatrixMode(GL_MODELVIEW);
5913 glRotatef(tilt2, 1, 0, 0);
5915 glRotatef(tilt, 0, 0, 1);
5918 glTranslatef(mid.x, mid.y, mid.z);
5920 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
5921 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
5923 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
5924 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
5926 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
5927 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
5929 if (playerdetail || skeleton.free == 3) {
5930 for (j = 0; j < skeleton.muscles[i].numvertices; j++) {
5931 XYZ &v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
5932 XYZ &v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
5933 glMatrixMode(GL_MODELVIEW);
5935 if (p1 == abdomen || p2 == abdomen)
5936 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionbody.x,
5937 (v0.y * (1 - morphness) + v1.y * morphness) * proportionbody.y,
5938 (v0.z * (1 - morphness) + v1.z * morphness) * proportionbody.z);
5939 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
5940 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionarms.x,
5941 (v0.y * (1 - morphness) + v1.y * morphness) * proportionarms.y,
5942 (v0.z * (1 - morphness) + v1.z * morphness) * proportionarms.z);
5943 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
5944 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionlegs.x,
5945 (v0.y * (1 - morphness) + v1.y * morphness) * proportionlegs.y,
5946 (v0.z * (1 - morphness) + v1.z * morphness) * proportionlegs.z);
5947 if (p1 == head || p2 == head)
5948 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionhead.x,
5949 (v0.y * (1 - morphness) + v1.y * morphness) * proportionhead.y,
5950 (v0.z * (1 - morphness) + v1.z * morphness) * proportionhead.z);
5951 glGetFloatv(GL_MODELVIEW_MATRIX, M);
5952 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale;
5953 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale;
5954 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z = M[14] * scale;
5958 if (!playerdetail || skeleton.free == 3) {
5959 for (j = 0; j < skeleton.muscles[i].numverticeslow; j++) {
5960 XYZ &v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
5961 glMatrixMode(GL_MODELVIEW);
5963 if (p1 == abdomen || p2 == abdomen)
5964 glTranslatef(v0.x * proportionbody.x,
5965 v0.y * proportionbody.y,
5966 v0.z * proportionbody.z);
5967 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
5968 glTranslatef(v0.x * proportionarms.x,
5969 v0.y * proportionarms.y,
5970 v0.z * proportionarms.z);
5971 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
5972 glTranslatef(v0.x * proportionlegs.x,
5973 v0.y * proportionlegs.y,
5974 v0.z * proportionlegs.z);
5975 if (p1 == head || p2 == head)
5976 glTranslatef(v0.x * proportionhead.x,
5977 v0.y * proportionhead.y,
5978 v0.z * proportionhead.z);
5980 glGetFloatv(GL_MODELVIEW_MATRIX, M);
5981 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
5982 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y = M[13] * scale;
5983 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z = M[14] * scale;
5989 if (skeleton.clothes && skeleton.muscles[i].numverticesclothes > 0) {
5990 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
5992 glMatrixMode(GL_MODELVIEW);
5996 glRotatef(tilt2, 1, 0, 0);
5998 glRotatef(tilt, 0, 0, 1);
5999 glTranslatef(mid.x, mid.y, mid.z);
6000 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6001 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6003 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6004 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6006 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6007 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6009 for (j = 0; j < skeleton.muscles[i].numverticesclothes; j++) {
6010 XYZ &v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
6011 glMatrixMode(GL_MODELVIEW);
6013 if (p1 == abdomen || p2 == abdomen)
6014 glTranslatef(v0.x * proportionbody.x,
6015 v0.y * proportionbody.y,
6016 v0.z * proportionbody.z);
6017 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6018 glTranslatef(v0.x * proportionarms.x,
6019 v0.y * proportionarms.y,
6020 v0.z * proportionarms.z);
6021 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6022 glTranslatef(v0.x * proportionlegs.x,
6023 v0.y * proportionlegs.y,
6024 v0.z * proportionlegs.z);
6025 if (p1 == head || p2 == head)
6026 glTranslatef(v0.x * proportionhead.x,
6027 v0.y * proportionhead.y,
6028 v0.z * proportionhead.z);
6029 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6030 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
6031 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
6032 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z = M[14] * scale;
6037 updatedelay = 1 + (float)(Random() % 100) / 1000;
6039 if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) {
6040 normalsupdatedelay = 1;
6041 if (playerdetail || skeleton.free == 3)
6042 skeleton.drawmodel.CalculateNormals(0);
6043 if (!playerdetail || skeleton.free == 3)
6044 skeleton.drawmodellow.CalculateNormals(0);
6045 if (skeleton.clothes)
6046 skeleton.drawmodelclothes.CalculateNormals(0);
6048 if (playerdetail || skeleton.free == 3)
6049 skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
6050 if (!playerdetail || skeleton.free == 3)
6051 skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
6052 if (skeleton.clothes) {
6053 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6058 updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1);
6059 if (updatedelaychange > -realmultiplier * 30)
6060 updatedelaychange = -realmultiplier * 30;
6061 if (updatedelaychange > -framemult * 4)
6062 updatedelaychange = -framemult * 4;
6063 if (skeleton.free == 1)
6064 updatedelaychange *= 6;
6066 updatedelaychange *= 8;
6067 updatedelay += updatedelaychange;
6069 glMatrixMode(GL_MODELVIEW);
6072 glTranslatef(coords.x, coords.y - .02, coords.z);
6074 glTranslatef(coords.x, coords.y - .02, coords.z);
6076 glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
6078 glRotatef(yaw, 0, 1, 0);
6081 glColor4f(.4, 1, .4, 1);
6082 glDisable(GL_LIGHTING);
6083 glDisable(GL_TEXTURE_2D);
6086 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6087 XYZ &v0 = skeleton.drawmodel.vertex[i];
6088 glVertex3f(v0.x, v0.y, v0.z);
6094 for (i = 0; i < skeleton.drawmodel.TriangleNum; i++) {
6095 XYZ &v0 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]];
6096 XYZ &v1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]];
6097 XYZ &v2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]];
6098 glVertex3f(v0.x, v0.y, v0.z);
6099 glVertex3f(v1.x, v1.y, v1.z);
6100 glVertex3f(v1.x, v1.y, v1.z);
6101 glVertex3f(v2.x, v2.y, v2.z);
6102 glVertex3f(v2.x, v2.y, v2.z);
6103 glVertex3f(v0.x, v0.y, v0.z);
6109 terrainlight = terrain.getLighting(coords.x, coords.z);
6110 distance = distsq(&viewer, &coords);
6111 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
6115 terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1;
6116 if (terrainheight < 1)
6118 if (terrainheight > 1.7)
6119 terrainheight = 1.7;
6122 glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance);
6123 glDisable(GL_BLEND);
6124 glAlphaFunc(GL_GREATER, 0.0001);
6125 glEnable(GL_TEXTURE_2D);
6127 glDisable(GL_TEXTURE_2D);
6128 glColor4f(.7, .35, 0, .5);
6130 glEnable(GL_LIGHTING);
6133 if (tutoriallevel && id != 0) {
6134 glColor4f(.7, .7, .7, 0.6);
6136 glEnable(GL_LIGHTING);
6138 if (canattack && cananger)
6139 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6140 glDisable(GL_TEXTURE_2D);
6141 glColor4f(1, 0, 0, 0.8);
6143 glMatrixMode(GL_TEXTURE);
6145 glTranslatef(0, -smoketex, 0);
6146 glTranslatef(-smoketex, 0, 0);
6150 if ((tutoriallevel && id != 0))
6151 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6153 skeleton.drawmodel.draw();
6156 if (!playerdetail) {
6157 if ((tutoriallevel && id != 0))
6158 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6160 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6163 if (!(animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed))
6164 if (tutoriallevel && id != 0) {
6166 glMatrixMode(GL_MODELVIEW);
6167 glEnable(GL_TEXTURE_2D);
6168 glColor4f(.7, .7, .7, 0.6);
6170 glEnable(GL_LIGHTING);
6172 if (canattack && cananger)
6173 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6174 glDisable(GL_TEXTURE_2D);
6175 glColor4f(1, 0, 0, 0.8);
6177 glMatrixMode(GL_TEXTURE);
6179 glTranslatef(0, -smoketex * .6, 0);
6180 glTranslatef(smoketex * .6, 0, 0);
6183 if ((tutoriallevel && id != 0))
6184 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6186 skeleton.drawmodel.draw();
6189 if (!playerdetail) {
6190 if ((tutoriallevel && id != 0))
6191 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6193 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6198 if (tutoriallevel && id != 0) {
6200 glMatrixMode(GL_MODELVIEW);
6201 glEnable(GL_TEXTURE_2D);
6203 if (skeleton.clothes) {
6207 skeleton.drawmodelclothes.draw();
6209 skeleton.drawmodelclothes.drawimmediate();
6215 if (num_weapons > 0) {
6216 for (k = 0; k < num_weapons; k++) {
6218 if (weaponactive == k) {
6219 if (weapons[i].getType() != staff) {
6220 for (j = 0; j < skeleton.num_muscles; j++) {
6221 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6222 weaponattachmuscle = j;
6225 for (j = 0; j < skeleton.num_muscles; j++) {
6226 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].numvertices > 0) {
6227 weaponrotatemuscle = j;
6230 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6231 if (creature == wolftype)
6232 weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3);
6234 if (weapons[i].getType() == staff) {
6235 for (j = 0; j < skeleton.num_muscles; j++) {
6236 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6237 weaponattachmuscle = j;
6240 for (j = 0; j < skeleton.num_muscles; j++) {
6241 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].numvertices > 0) {
6242 weaponrotatemuscle = j;
6245 //weaponpoint=jointPos(rightwrist);
6246 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6247 //weaponpoint+=skeleton.specialforward[1]*.1+(jointPos(rightwrist)-jointPos(rightelbow));
6248 XYZ tempnormthing, vec1, vec2;
6249 vec1 = (jointPos(rightwrist) - jointPos(rightelbow));
6250 vec2 = (jointPos(rightwrist) - jointPos(rightshoulder));
6251 CrossProduct(&vec1, &vec2, &tempnormthing);
6252 Normalise(&tempnormthing);
6253 if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim)
6254 weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow));
6257 if (weaponactive != k && weaponstuck != k) {
6258 if (weapons[i].getType() == knife)
6259 weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35;
6260 if (weapons[i].getType() == sword)
6261 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6262 if (weapons[i].getType() == staff)
6263 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6264 for (j = 0; j < skeleton.num_muscles; j++) {
6265 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].numvertices > 0) {
6266 weaponrotatemuscle = j;
6270 if (weaponstuck == k) {
6271 if (weaponstuckwhere == 0)
6272 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8;
6274 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
6275 for (j = 0; j < skeleton.num_muscles; j++) {
6276 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].numvertices > 0) {
6277 weaponrotatemuscle = j;
6281 if (skeleton.free) {
6282 weapons[i].position = weaponpoint * scale + coords;
6283 weapons[i].bigrotation = 0;
6284 weapons[i].bigtilt = 0;
6285 weapons[i].bigtilt2 = 0;
6287 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;
6288 weapons[i].bigrotation = yaw;
6289 weapons[i].bigtilt = tilt;
6290 weapons[i].bigtilt2 = tilt2;
6292 weapons[i].rotation1 = skeleton.muscles[weaponrotatemuscle].lastrotate1;
6293 weapons[i].rotation2 = skeleton.muscles[weaponrotatemuscle].lastrotate2;
6294 weapons[i].rotation3 = skeleton.muscles[weaponrotatemuscle].lastrotate3;
6295 if (weaponactive == k) {
6296 if (weapons[i].getType() == knife) {
6297 weapons[i].smallrotation = 180;
6298 weapons[i].smallrotation2 = 0;
6299 if (isCrouch() || wasCrouch()) {
6300 weapons[i].smallrotation2 = 20;
6302 if (animTarget == hurtidleanim) {
6303 weapons[i].smallrotation2 = 50;
6305 if ((animCurrent == crouchstabanim && animTarget == crouchstabanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
6306 XYZ temppoint1, temppoint2, tempforward;
6309 temppoint1 = jointPos(righthand);
6310 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6311 distance = findDistance(&temppoint1, &temppoint2);
6312 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6313 weapons[i].rotation2 *= 360 / 6.28;
6316 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6317 weapons[i].rotation1 *= 360 / 6.28;
6318 weapons[i].rotation3 = 0;
6319 weapons[i].smallrotation = -90;
6320 weapons[i].smallrotation2 = 0;
6321 if (temppoint1.x > temppoint2.x)
6322 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6324 if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) {
6325 XYZ temppoint1, temppoint2, tempforward;
6328 temppoint1 = jointPos(righthand);
6329 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6330 distance = findDistance(&temppoint1, &temppoint2);
6331 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6332 weapons[i].rotation2 *= 360 / 6.28;
6335 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6336 weapons[i].rotation1 *= 360 / 6.28;
6337 weapons[i].rotation3 = 0;
6338 weapons[i].smallrotation = 90;
6339 weapons[i].smallrotation2 = 0;
6340 if (temppoint1.x > temppoint2.x)
6341 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6343 if (animTarget == knifethrowanim) {
6344 weapons[i].smallrotation = 90;
6345 //weapons[i].smallrotation2=-90;
6346 weapons[i].smallrotation2 = 0;
6347 weapons[i].rotation1 = 0;
6348 weapons[i].rotation2 = 0;
6349 weapons[i].rotation3 = 0;
6351 if (animTarget == knifesneakattackanim && frameTarget < 5) {
6352 weapons[i].smallrotation = -90;
6353 weapons[i].rotation1 = 0;
6354 weapons[i].rotation2 = 0;
6355 weapons[i].rotation3 = 0;
6358 if (weapons[i].getType() == sword) {
6359 weapons[i].smallrotation = 0;
6360 weapons[i].smallrotation2 = 0;
6361 if (animTarget == knifethrowanim) {
6362 weapons[i].smallrotation = -90;
6363 weapons[i].smallrotation2 = 0;
6364 weapons[i].rotation1 = 0;
6365 weapons[i].rotation2 = 0;
6366 weapons[i].rotation3 = 0;
6368 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)) {
6369 XYZ temppoint1, temppoint2, tempforward;
6372 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6373 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6374 distance = findDistance(&temppoint1, &temppoint2);
6375 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6376 weapons[i].rotation2 *= 360 / 6.28;
6379 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6380 weapons[i].rotation1 *= 360 / 6.28;
6381 weapons[i].rotation3 = 0;
6382 weapons[i].smallrotation = 90;
6383 weapons[i].smallrotation2 = 0;
6384 if (temppoint1.x > temppoint2.x)
6385 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6388 if (weapons[i].getType() == staff) {
6389 weapons[i].smallrotation = 100;
6390 weapons[i].smallrotation2 = 0;
6391 if ((animTarget == staffhitanim && animCurrent == staffhitanim) || (animTarget == staffhitreversedanim && animCurrent == staffhitreversedanim) || (animTarget == staffspinhitreversedanim && animCurrent == staffspinhitreversedanim) || (animTarget == staffgroundsmashanim && animCurrent == staffgroundsmashanim) || (animTarget == staffspinhitanim && animCurrent == staffspinhitanim)) {
6392 XYZ temppoint1, temppoint2, tempforward;
6395 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6396 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6397 distance = findDistance(&temppoint1, &temppoint2);
6398 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6399 weapons[i].rotation2 *= 360 / 6.28;
6402 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6403 weapons[i].rotation1 *= 360 / 6.28;
6404 weapons[i].rotation3 = 0;
6405 weapons[i].smallrotation = 90;
6406 weapons[i].smallrotation2 = 0;
6407 if (temppoint1.x > temppoint2.x)
6408 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6412 if (weaponactive != k && weaponstuck != k) {
6413 if (weapons[i].getType() == knife) {
6414 weapons[i].smallrotation = -70;
6415 weapons[i].smallrotation2 = 10;
6417 if (weapons[i].getType() == sword) {
6418 weapons[i].smallrotation = -100;
6419 weapons[i].smallrotation2 = -8;
6421 if (weapons[i].getType() == staff) {
6422 weapons[i].smallrotation = -100;
6423 weapons[i].smallrotation2 = -8;
6426 if (weaponstuck == k) {
6427 if (weaponstuckwhere == 0)
6428 weapons[i].smallrotation = 180;
6430 weapons[i].smallrotation = 0;
6431 weapons[i].smallrotation2 = 10;
6440 if (animation[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isFlip() || isWallJump())
6442 if (animCurrent != animTarget)
6444 if (skeleton.free == 2)
6453 int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6456 static float distance;
6457 static float olddistance;
6458 static int intersecting;
6459 static int firstintersecting;
6462 static XYZ start, end;
6463 static float slopethreshold = -.4;
6465 firstintersecting = -1;
6469 if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius)
6472 *p1 = DoRotation(*p1, 0, -*rotate, 0);
6473 for (i = 0; i < 4; i++) {
6474 for (j = 0; j < model->TriangleNum; j++) {
6475 if (model->facenormals[j].y <= slopethreshold) {
6477 distance = abs((model->facenormals[j].x * p1->x) + (model->facenormals[j].y * p1->y) + (model->facenormals[j].z * p1->z) - ((model->facenormals[j].x * model->vertex[model->Triangles[j].vertex[0]].x) + (model->facenormals[j].y * model->vertex[model->Triangles[j].vertex[0]].y) + (model->facenormals[j].z * model->vertex[model->Triangles[j].vertex[0]].z)));
6478 if (distance < radius) {
6479 point = *p1 - model->facenormals[j] * distance;
6480 if (PointInTriangle( &point, model->facenormals[j], &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]]))
6483 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6484 &model->vertex[model->Triangles[j].vertex[1]],
6487 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6488 &model->vertex[model->Triangles[j].vertex[2]],
6491 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6492 &model->vertex[model->Triangles[j].vertex[2]],
6495 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6499 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->facenormals[j], &point)) {
6500 p1->y = point.y + radius;
6501 if ((animTarget == jumpdownanim || isFlip())) {
6502 if (isFlip() && (frameTarget < 5 || animation[animTarget].label[frameTarget] == 7 || animation[animTarget].label[frameTarget] == 4))
6505 if (animTarget == jumpupanim) {
6507 animTarget = getIdle();
6514 pause_sound(whooshsound);
6515 OPENAL_SetVolume(channels[whooshsound], 0);
6518 if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) {
6521 animTarget = getLanding();
6522 emit_sound_at(landsound, coords, 128.);
6525 envsound[numenvsounds] = coords;
6526 envsoundvol[numenvsounds] = 16;
6527 envsoundlife[numenvsounds] = .4;
6535 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6536 olddistance = distance;
6537 firstintersecting = j;
6542 for (j = 0; j < model->TriangleNum; j++) {
6543 if (model->facenormals[j].y > slopethreshold) {
6546 start.y -= radius / 4;
6547 XYZ &v0 = model->vertex[model->Triangles[j].vertex[0]];
6548 XYZ &v1 = model->vertex[model->Triangles[j].vertex[1]];
6549 XYZ &v2 = model->vertex[model->Triangles[j].vertex[2]];
6550 distance = abs((model->facenormals[j].x * start.x)
6551 + (model->facenormals[j].y * start.y)
6552 + (model->facenormals[j].z * start.z)
6553 - ((model->facenormals[j].x * v0.x)
6554 + (model->facenormals[j].y * v0.y)
6555 + (model->facenormals[j].z * v0.z)));
6556 if (distance < radius * .5) {
6557 point = start - model->facenormals[j] * distance;
6558 if (PointInTriangle( &point, model->facenormals[j], &v0, &v1, &v2))
6561 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
6563 intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6565 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6567 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6568 if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
6570 velocity -= DoRotation(model->facenormals[j], 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->facenormals[j], 0, *rotate, 0))); //(distance-radius*.5)/multiplier;
6571 if (findLengthfast(&start) < findLengthfast(&velocity))
6574 *p1 += model->facenormals[j] * (distance - radius * .5);
6577 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6578 olddistance = distance;
6579 firstintersecting = j;
6586 *p = DoRotation(*p, 0, *rotate, 0);
6589 *p1 = DoRotation(*p1, 0, *rotate, 0);
6591 return firstintersecting;