2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 /**> HEADER FILES <**/
24 #include "openal_wrapper.h"
25 #include "Animation.h"
30 extern float multiplier;
31 extern Terrain terrain;
33 extern int environment;
35 extern FRUSTUM frustum;
37 extern float realmultiplier;
39 extern float slomodelay;
40 extern bool cellophane;
41 extern float texdetail;
42 extern float realtexdetail;
43 extern GLubyte bloodText[512 * 512 * 3];
44 extern GLubyte wolfbloodText[512 * 512 * 3];
45 extern int bloodtoggle;
46 extern Objects objects;
48 extern bool autoslomo;
49 extern float camerashake;
51 extern float viewdistance;
52 extern float blackout;
53 extern int difficulty;
55 extern float fadestart;
57 extern bool winfreeze;
58 extern float flashamount, flashr, flashg, flashb;
59 extern int flashdelay;
60 extern bool showpoints;
61 extern bool immediate;
63 extern bool tilt2weird;
64 extern bool tiltweird;
66 extern bool proportionweird;
67 extern bool vertexweird[6];
68 extern XYZ envsound[30];
69 extern float envsoundvol[30];
70 extern float envsoundlife[30];
71 extern int numenvsounds;
72 extern int tutoriallevel;
73 extern float smoketex;
74 extern int tutorialstage;
75 extern bool reversaltrain;
76 extern bool canattack;
78 extern float damagedealt;
80 extern float hostiletime;
82 extern int indialogue;
84 extern bool gamestarted;
86 Person player[maxplayers];
91 * GameTick/doPlayerCollisions
93 void Person::CheckKick()
96 && (animTarget == rabbitkickanim
100 && animCurrent == rabbitkickanim)
101 && distsq(&coords, &victim->coords) < 1.2
102 && !victim->skeleton.free))
105 if (animation[victim->animTarget].height != lowheight) {
106 float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
107 XYZ relative = velocity;
109 Normalise(&relative);
113 if (tutoriallevel != 1)
114 emit_sound_at(heavyimpactsound, victim->coords);
116 for (int i = 0; i < victim->skeleton.num_joints; i++) {
117 victim->skeleton.joints[i].velocity += relative * 120 * damagemult;
120 victim->DoDamage(100 * damagemult / victim->protectionhigh);
126 animTarget = backflipanim;
128 velocity = facing * -10;
132 resume_stream(whooshsound);
134 award_bonus(id, cannon);
135 } else if (victim->isCrouch()) {
136 animTarget = rabbitkickreversedanim;
137 animCurrent = rabbitkickreversedanim;
138 victim->animCurrent = rabbitkickreversalanim;
139 victim->animTarget = rabbitkickreversalanim;
145 victim->oldcoords = victim->coords;
146 coords = victim->coords;
147 victim->targetyaw = targetyaw;
148 victim->victim = this;
155 * GameTick/doPlayerCollisions - spread fire between players
156 * GameTick/doDebugKeys - press f to ignite
157 * Person::DoStuff - spread fire from lit campfires and bushes
159 void Person::CatchFire()
161 XYZ flatfacing, flatvelocity;
163 for (int i = 0; i < 10; i++) {
164 howmany = abs(Random() % (skeleton.num_joints));
166 flatvelocity = velocity;
168 flatvelocity = skeleton.joints[howmany].velocity;
170 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
172 flatfacing = skeleton.joints[howmany].position * scale + coords;
173 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
178 emit_sound_at(firestartsound, coords);
180 emit_stream_at(stream_firesound, coords);
188 * idle animation for this creature (depending on status)
190 int Person::getIdle()
192 if (indialogue != -1 && howactive == typeactive && creature == rabbittype)
194 if (hasvictim && victim != this/*||(id==0&&attackkeydown)*/)
195 if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype && victim->aitype != searchtype && aitype != passivetype && aitype != searchtype && victim->id < numplayers)) {
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(howmuch&&id==0)blooddimamount=1;
314 if (bloodtoggle && tutoriallevel != 1) {
315 if (bleeding <= 0 && spurt) {
317 for (int i = 0; i < 3; i++) {
318 // emit blood particles
320 if (!skeleton.free) {
322 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
325 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
328 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
330 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
332 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
333 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
335 if (!skeleton.free) {
336 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
337 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
340 if (Random() % 2 == 0) // 50% chance
341 for (int i = 0; i < 3; i++) {
342 if (Random() % 2 != 0) {
343 // emit teeth particles
346 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
347 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
350 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
351 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
355 Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
357 Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
359 Sprite::setLastSpriteSpecial(3); // sets it to teeth
364 // FIXME: manipulating attributes
365 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
368 if (creature == rabbittype)
369 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) {
370 bleedxint = abs(Random() % 512);
371 bleedyint = abs(Random() % 512);
373 if (creature == wolftype)
374 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) {
375 bleedxint = abs(Random() % 512);
376 bleedyint = abs(Random() % 512);
380 bleedy /= realtexdetail;
381 bleedx /= realtexdetail;
382 direction = abs(Random() % 2) * 2 - 1;
391 * spawns big blood effects and ???
392 * modifies character's skin texture
394 void Person::DoBloodBig(float howmuch, int which)
396 static int bleedxint, bleedyint, i, j;
398 if (howmuch && id == 0)
401 if (tutoriallevel != 1 || id == 0)
402 if (aitype != playercontrolled && howmuch > 0) {
406 // FIXME: seems to be spawning sounds by manipulating attributes... MESSY!
407 if (creature == wolftype) {
408 int i = abs(Random() % 2);
410 whichsound = snarlsound;
412 whichsound = snarl2sound;
413 envsound[numenvsounds] = coords;
414 envsoundvol[numenvsounds] = 16;
415 envsoundlife[numenvsounds] = .4;
418 if (creature == rabbittype) {
419 int i = abs(Random() % 2);
421 whichsound = rabbitpainsound;
422 if (i == 1 && howmuch >= 2)
423 whichsound = rabbitpain1sound;
424 envsound[numenvsounds] = coords;
425 envsoundvol[numenvsounds] = 16;
426 envsoundlife[numenvsounds] = .4;
428 //if(i==2)whichsound=rabbitpain2sound;
431 if (whichsound != -1)
432 emit_sound_at(whichsound, coords);
435 if (id == 0 && howmuch > 0) {
436 // FIXME: manipulating attributes
444 if (bloodtoggle && decals && tutoriallevel != 1) {
445 if (bleeding <= 0 && spurt) {
447 for (int i = 0; i < 3; i++) {
448 // emit blood particles
449 // FIXME: copypaste from above
451 if (!skeleton.free) {
453 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
456 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
459 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
461 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
463 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
464 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
466 if (!skeleton.free) {
467 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
468 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
473 // weird texture manipulation code follows.
474 // looks like this is painting blood onto the character's skin texture
475 // FIXME: surely there's a better way
477 int offsetx = 0, offsety = 0;
479 offsety = Random() % 40;
480 offsetx = abs(Random() % 60);
482 if (which == 190 || which == 185) {
483 offsety = Random() % 40;
484 offsetx = abs(Random() % 100) - 20;
487 offsety = Random() % 10;
488 offsetx = Random() % 10;
491 offsety = Random() % 20;
492 offsetx = Random() % 20;
494 if (which == 220 || which == 215) {
504 if (creature == rabbittype)
505 for (i = 0; i < 512; i++) {
506 for (j = 0; j < 512; j++) {
507 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
508 if (i < startx) startx = i;
509 if (j < starty) starty = j;
510 if (i > endx) endx = i;
511 if (j > endy) endy = j;
515 if (creature == wolftype)
516 for (i = 0; i < 512; i++) {
517 for (j = 0; j < 512; j++) {
518 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
519 if (i < startx) startx = i;
520 if (j < starty) starty = j;
521 if (i > endx) endx = i;
522 if (j > endy) endy = j;
532 if (startx < 0) startx = 0;
533 if (starty < 0) starty = 0;
534 if (endx > 512 - 1) endx = 512 - 1;
535 if (endy > 512 - 1) endy = 512 - 1;
536 if (endx < startx) endx = startx;
537 if (endy < starty) endy = starty;
539 startx /= realtexdetail;
540 starty /= realtexdetail;
541 endx /= realtexdetail;
542 endy /= realtexdetail;
544 int texdetailint = realtexdetail;
546 if (creature == rabbittype)
547 for (i = startx; i < endx; i++) {
548 for (j = starty; j < endy; j++) {
549 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) {
550 color = Random() % 85 + 170;
551 where = i * skeleton.skinsize * 3 + j * 3;
552 if (skeleton.skinText[where + 0] > color / 2)
553 skeleton.skinText[where + 0] = color / 2;
554 skeleton.skinText[where + 1] = 0;
555 skeleton.skinText[where + 2] = 0;
559 if (creature == wolftype)
560 for (i = startx; i < endx; i++) {
561 for (j = starty; j < endy; j++) {
562 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) {
563 color = Random() % 85 + 170;
564 where = i * skeleton.skinsize * 3 + j * 3;
565 if (skeleton.skinText[where + 0] > color / 2)
566 skeleton.skinText[where + 0] = color / 2;
567 skeleton.skinText[where + 1] = 0;
568 skeleton.skinText[where + 2] = 0;
572 skeleton.drawmodel.textureptr.bind();
577 if (creature == rabbittype)
578 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) {
579 bleedxint = abs(Random() % 512);
580 bleedyint = abs(Random() % 512);
582 if (creature == wolftype)
583 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) {
584 bleedxint = abs(Random() % 512);
585 bleedyint = abs(Random() % 512);
587 bleedy = bleedxint + offsetx;
588 bleedx = bleedyint + offsety;
589 bleedy /= realtexdetail;
590 bleedx /= realtexdetail;
595 if (bleedx > skeleton.skinsize - 1)
596 bleedx = skeleton.skinsize - 1;
597 if (bleedy > skeleton.skinsize - 1)
598 bleedy = skeleton.skinsize - 1;
599 direction = abs(Random() % 2) * 2 - 1;
602 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
603 deathbleeding += bleeding;
604 bloodloss += bleeding * 3;
606 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
607 if (abs(Random() % 2) == 0) {
608 aitype = gethelptype;
611 aitype = attacktypecutoff;
619 * similar to DoBloodBig
621 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
625 static XYZ startpoint, endpoint, colpoint, movepoint;
626 static float rotationpoint;
628 static XYZ p1, p2, p3, p0;
632 float coordsx, coordsy;
635 if (bloodtoggle && decals && tutoriallevel != 1) {
638 where = DoRotation(where, 0, -yaw, 0);
646 // ray testing for a tri in the character model
647 whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
648 if (whichtri != -1) {
649 // low level geometry math
651 p1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
652 p2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
653 p3 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
655 CrossProduct(p2-p1,p3-p1,&N);
656 CrossProduct(p0-p1,p3-p1,&temp);
657 s = dotproduct(&temp,&N)/findLength(&N);
658 CrossProduct(p2-p1,p1-p0,&temp);
659 t = dotproduct(&temp,&N)/findLength(&N);
662 bary.x = distsq(&p0, &p1);
663 bary.y = distsq(&p0, &p2);
664 bary.z = distsq(&p0, &p3);
666 total = bary.x + bary.y + bary.z;
675 total = bary.x + bary.y + bary.z;
681 gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0];
682 gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1];
683 gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2];
684 gyy.x = skeleton.drawmodel.Triangles[whichtri].gy[0];
685 gyy.y = skeleton.drawmodel.Triangles[whichtri].gy[1];
686 gyy.z = skeleton.drawmodel.Triangles[whichtri].gy[2];
687 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;
688 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;
690 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
691 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
693 if (bleeding <= 0 && spurt) {
695 for (int i = 0; i < 3; i++) {
696 // emit blood particles
697 // FIXME: more copypaste code
699 if (!skeleton.free) {
701 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
704 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
707 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
709 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
711 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
712 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
714 if (!skeleton.free) {
715 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
716 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
721 // texture manipulation follows
723 int offsetx = 0, offsety = 0;
726 offsetx=abs(Random()%120);
728 if(which==220||which==215){
730 offsetx=abs(Random()%80);
733 offsetx = (1 + coordsy) * 512 - 291;
734 offsety = coordsx * 512 - 437;
741 if (creature == rabbittype)
742 for (i = 0; i < 512; i++) {
743 for (j = 0; j < 512; j++) {
744 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[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;
752 if (creature == wolftype)
753 for (i = 0; i < 512; i++) {
754 for (j = 0; j < 512; j++) {
755 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
756 if (i < startx) startx = i;
757 if (j < starty) starty = j;
758 if (i > endx) endx = i;
759 if (j > endy) endy = j;
768 if (startx < 0) startx = 0;
769 if (starty < 0) starty = 0;
770 if (endx > 512 - 1) endx = 512 - 1;
771 if (endy > 512 - 1) endy = 512 - 1;
772 if (endx < startx) endx = startx;
773 if (endy < starty) endy = starty;
775 startx /= realtexdetail;
776 starty /= realtexdetail;
777 endx /= realtexdetail;
778 endy /= realtexdetail;
780 int texdetailint = realtexdetail;
782 if (creature == rabbittype)
783 for (i = startx; i < endx; i++) {
784 for (j = starty; j < endy; j++) {
785 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) {
786 color = Random() % 85 + 170;
787 where = i * skeleton.skinsize * 3 + j * 3;
788 if (skeleton.skinText[where + 0] > color / 2)
789 skeleton.skinText[where + 0] = color / 2;
790 skeleton.skinText[where + 1] = 0;
791 skeleton.skinText[where + 2] = 0;
792 } 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) {
793 color = Random() % 85 + 170;
794 where = i * skeleton.skinsize * 3 + j * 3;
795 if (skeleton.skinText[where + 0] > color / 2)
796 skeleton.skinText[where + 0] = color / 2;
797 skeleton.skinText[where + 1] = 0;
798 skeleton.skinText[where + 2] = 0;
802 if (creature == wolftype)
803 for (i = startx; i < endx; i++) {
804 for (j = starty; j < endy; j++) {
805 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) {
806 color = Random() % 85 + 170;
807 where = i * skeleton.skinsize * 3 + j * 3;
808 if (skeleton.skinText[where + 0] > color / 2)
809 skeleton.skinText[where + 0] = color / 2;
810 skeleton.skinText[where + 1] = 0;
811 skeleton.skinText[where + 2] = 0;
812 } 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) {
813 color = Random() % 85 + 170;
814 where = i * skeleton.skinsize * 3 + j * 3;
815 if (skeleton.skinText[where + 0] > color / 2)
816 skeleton.skinText[where + 0] = color / 2;
817 skeleton.skinText[where + 1] = 0;
818 skeleton.skinText[where + 2] = 0;
822 skeleton.drawmodel.textureptr.bind();
825 bleedy = (1 + coordsy) * 512;
826 bleedx = coordsx * 512;
827 bleedy /= realtexdetail;
828 bleedx /= realtexdetail;
833 if (bleedx > skeleton.skinsize - 1)
834 bleedx = skeleton.skinsize - 1;
835 if (bleedy > skeleton.skinsize - 1)
836 bleedy = skeleton.skinsize - 1;
837 direction = abs(Random() % 2) * 2 - 1;
842 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
843 deathbleeding += bleeding;
844 bloodloss += bleeding * 3;
846 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
847 if (abs(Random() % 2) == 0) {
848 aitype = gethelptype;
851 aitype = attacktypecutoff;
862 * guessing this performs a reversal
864 void Person::Reverse()
866 if (!((victim->aitype == playercontrolled
868 || staggerdelay <= 0)
869 && victim->animTarget != jumpupanim
870 && victim->animTarget != jumpdownanim
871 && (tutoriallevel != 1 || cananger)
875 if (normaldotproduct (victim->facing, victim->coords - coords) > 0
876 && (victim->id != 0 || difficulty >= 2)
877 && (creature != wolftype || victim->creature == wolftype))
880 if (animTarget == sweepanim) {
881 animTarget = sweepreversedanim;
882 animCurrent = sweepreversedanim;
883 victim->animCurrent = sweepreversalanim;
884 victim->animTarget = sweepreversalanim;
886 if (animTarget == spinkickanim) {
887 animTarget = spinkickreversedanim;
888 animCurrent = spinkickreversedanim;
889 victim->animCurrent = spinkickreversalanim;
890 victim->animTarget = spinkickreversalanim;
892 if (animTarget == upunchanim || animTarget == rabbittacklinganim) {
893 if (animTarget == rabbittacklinganim) {
896 victim->frameCurrent = 6;
897 victim->frameTarget = 7;
899 animTarget = upunchreversedanim;
900 animCurrent = upunchreversedanim;
901 victim->animCurrent = upunchreversalanim;
902 victim->animTarget = upunchreversalanim;
904 if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
905 if (victim->weaponactive != -1) {
906 victim->throwtogglekeydown = 1;
907 weapons[victim->weaponids[0]].owner = -1;
908 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
909 if (weapons[victim->weaponids[0]].velocity.x == 0)
910 weapons[victim->weaponids[0]].velocity.x = .1;
911 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
912 weapons[victim->weaponids[0]].missed = 1;
913 weapons[victim->weaponids[0]].freetime = 0;
914 weapons[victim->weaponids[0]].firstfree = 1;
915 weapons[victim->weaponids[0]].physics = 1;
916 victim->num_weapons--;
917 if (victim->num_weapons) {
918 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
919 if (victim->weaponstuck == victim->num_weapons)
920 victim->weaponstuck = 0;
923 victim->weaponactive = -1;
924 for (int j = 0; j < numplayers; j++) {
925 player[j].wentforweapon = 0;
929 animTarget = staffhitreversedanim;
930 animCurrent = staffhitreversedanim;
931 victim->animCurrent = staffhitreversalanim;
932 victim->animTarget = staffhitreversalanim;
934 if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
935 if (victim->weaponactive != -1) {
936 victim->throwtogglekeydown = 1;
937 weapons[victim->weaponids[0]].owner = -1;
938 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
939 if (weapons[victim->weaponids[0]].velocity.x == 0)
940 weapons[victim->weaponids[0]].velocity.x = .1;
941 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
942 weapons[victim->weaponids[0]].missed = 1;
943 weapons[victim->weaponids[0]].freetime = 0;
944 weapons[victim->weaponids[0]].firstfree = 1;
945 weapons[victim->weaponids[0]].physics = 1;
946 victim->num_weapons--;
947 if (victim->num_weapons) {
948 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
949 if (victim->weaponstuck == victim->num_weapons)
950 victim->weaponstuck = 0;
953 victim->weaponactive = -1;
954 for (int j = 0; j < numplayers; j++) {
955 player[j].wentforweapon = 0;
958 animTarget = staffspinhitreversedanim;
959 animCurrent = staffspinhitreversedanim;
960 victim->animCurrent = staffspinhitreversalanim;
961 victim->animTarget = staffspinhitreversalanim;
963 if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
964 if (victim->weaponactive != -1) {
965 victim->throwtogglekeydown = 1;
966 weapons[victim->weaponids[0]].owner = -1;
967 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
968 if (weapons[victim->weaponids[0]].velocity.x == 0)
969 weapons[victim->weaponids[0]].velocity.x = .1;
970 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
971 weapons[victim->weaponids[0]].missed = 1;
972 weapons[victim->weaponids[0]].freetime = 0;
973 weapons[victim->weaponids[0]].firstfree = 1;
974 weapons[victim->weaponids[0]].physics = 1;
975 victim->num_weapons--;
976 if (victim->num_weapons) {
977 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
978 if (victim->weaponstuck == victim->num_weapons)
979 victim->weaponstuck = 0;
982 victim->weaponactive = -1;
983 for (int j = 0; j < numplayers; j++) {
984 player[j].wentforweapon = 0;
987 animTarget = swordslashreversedanim;
988 animCurrent = swordslashreversedanim;
989 victim->animCurrent = swordslashreversalanim;
990 victim->animTarget = swordslashreversalanim;
992 if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
993 if (victim->weaponactive != -1) {
994 victim->throwtogglekeydown = 1;
995 weapons[victim->weaponids[0]].owner = -1;
996 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
997 if (weapons[victim->weaponids[0]].velocity.x == 0)
998 weapons[victim->weaponids[0]].velocity.x = .1;
999 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
1000 weapons[victim->weaponids[0]].missed = 1;
1001 weapons[victim->weaponids[0]].freetime = 0;
1002 weapons[victim->weaponids[0]].firstfree = 1;
1003 weapons[victim->weaponids[0]].physics = 1;
1004 victim->num_weapons--;
1005 if (victim->num_weapons) {
1006 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1007 if (victim->weaponstuck == victim->num_weapons)
1008 victim->weaponstuck = 0;
1011 victim->weaponactive = -1;
1012 for (int j = 0; j < numplayers; j++) {
1013 player[j].wentforweapon = 0;
1016 animTarget = knifeslashreversedanim;
1017 animCurrent = knifeslashreversedanim;
1018 victim->animCurrent = knifeslashreversalanim;
1019 victim->animTarget = knifeslashreversalanim;
1021 if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim && animTarget != swordslashanim) {
1022 victim->targettilt2 = targettilt2;
1023 victim->frameCurrent = frameCurrent;
1024 victim->frameTarget = frameTarget;
1025 victim->target = target;
1026 victim->velocity = 0;
1027 victim->oldcoords = victim->coords;
1028 victim->coords = coords;
1029 victim->targetyaw = targetyaw;
1030 victim->yaw = targetyaw;
1031 victim->victim = this;
1033 if (animTarget == winduppunchanim) {
1034 animTarget = winduppunchblockedanim;
1035 victim->animTarget = blockhighleftanim;
1036 victim->frameTarget = 1;
1037 victim->target = .5;
1038 victim->victim = this;
1039 victim->targetyaw = targetyaw + 180;
1041 if (animTarget == wolfslapanim) {
1042 animTarget = winduppunchblockedanim;
1043 victim->animTarget = blockhighleftanim;
1044 victim->frameTarget = 1;
1045 victim->target = .5;
1046 victim->victim = this;
1047 victim->targetyaw = targetyaw + 180;
1049 if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) {
1050 animTarget = swordslashparriedanim;
1051 parriedrecently = .4;
1052 victim->parriedrecently = 0;
1053 victim->animTarget = swordslashparryanim;
1054 victim->frameTarget = 1;
1055 victim->target = .5;
1056 victim->victim = this;
1057 victim->targetyaw = targetyaw + 180;
1059 if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
1060 if (victim->weaponactive != -1) {
1061 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1062 if (weapons[victim->weaponids[0]].getType() == staff)
1063 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1064 if (weapons[weaponids[0]].getType() == staff)
1065 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1066 emit_sound_at(swordstaffsound, victim->coords);
1068 emit_sound_at(metalhitsound, victim->coords);
1072 victim->Puff(righthand);
1074 victim->frameTarget = 0;
1075 victim->animTarget = staggerbackhighanim;
1076 victim->targetyaw = targetyaw + 180;
1078 weapons[victim->weaponids[0]].owner = -1;
1079 aim = DoRotation(facing, 0, 90, 0) * 21;
1081 weapons[victim->weaponids[0]].velocity = aim * -.2;
1082 weapons[victim->weaponids[0]].tipvelocity = aim;
1083 weapons[victim->weaponids[0]].missed = 1;
1084 weapons[victim->weaponids[0]].hitsomething = 0;
1085 weapons[victim->weaponids[0]].freetime = 0;
1086 weapons[victim->weaponids[0]].firstfree = 1;
1087 weapons[victim->weaponids[0]].physics = 1;
1088 victim->num_weapons--;
1089 if (victim->num_weapons) {
1090 victim->weaponids[0] = victim->weaponids[num_weapons];
1091 if (victim->weaponstuck == victim->num_weapons)
1092 victim->weaponstuck = 0;
1094 victim->weaponactive = -1;
1095 for (int i = 0; i < numplayers; i++) {
1096 player[i].wentforweapon = 0;
1100 if (abs(Random() % 20) == 0) {
1101 if (weaponactive != -1) {
1102 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1103 if (weapons[victim->weaponids[0]].getType() == staff)
1104 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1105 if (weapons[weaponids[0]].getType() == staff)
1106 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1108 emit_sound_at(swordstaffsound, coords);
1110 emit_sound_at(metalhitsound, coords);
1118 animTarget = staggerbackhighanim;
1119 targetyaw = targetyaw + 180;
1121 weapons[weaponids[0]].owner = -1;
1122 aim = DoRotation(facing, 0, 90, 0) * 21;
1124 weapons[weaponids[0]].velocity = aim * -.2;
1125 weapons[weaponids[0]].tipvelocity = aim;
1126 weapons[weaponids[0]].hitsomething = 0;
1127 weapons[weaponids[0]].missed = 1;
1128 weapons[weaponids[0]].freetime = 0;
1129 weapons[weaponids[0]].firstfree = 1;
1130 weapons[weaponids[0]].physics = 1;
1133 weaponids[0] = weaponids[num_weapons];
1134 if (weaponstuck == num_weapons)
1138 for (int i = 0; i < numplayers; i++) {
1139 player[i].wentforweapon = 0;
1146 if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) {
1147 if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) {
1148 victim->animTarget = dodgebackanim;
1149 victim->frameTarget = 0;
1153 rotatetarget = coords - victim->coords;
1154 Normalise(&rotatetarget);
1155 victim->targetyaw = -asin(0 - rotatetarget.x);
1156 victim->targetyaw *= 360 / 6.28;
1157 if (rotatetarget.z < 0)
1158 victim->targetyaw = 180 - victim->targetyaw;
1160 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1162 victim->lastattack3 = victim->lastattack2;
1163 victim->lastattack2 = victim->lastattack;
1164 victim->lastattack = victim->animTarget;
1166 victim->animTarget = sweepanim;
1167 victim->frameTarget = 0;
1171 rotatetarget = coords - victim->coords;
1172 Normalise(&rotatetarget);
1173 victim->targetyaw = -asin(0 - rotatetarget.x);
1174 victim->targetyaw *= 360 / 6.28;
1175 if (rotatetarget.z < 0)
1176 victim->targetyaw = 180 - victim->targetyaw;
1178 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1180 victim->lastattack3 = victim->lastattack2;
1181 victim->lastattack2 = victim->lastattack;
1182 victim->lastattack = victim->animTarget;
1187 victim->velocity = 0;
1189 if (aitype != playercontrolled)
1191 if (aitype != playercontrolled && Random() % 3 == 0 && escapednum < 2 && difficulty == 2)
1193 if (aitype != playercontrolled && Random() % 5 == 0 && escapednum < 2 && difficulty == 1)
1195 if (aitype != playercontrolled && Random() % 10 == 0 && escapednum < 2 && difficulty == 0)
1198 if (victim->id == 0 && animation[victim->animTarget].attack == reversal)
1205 void Person::DoDamage(float howmuch)
1207 // subtract health (temporary?)
1208 if (tutoriallevel != 1)
1209 damage += howmuch / power;
1212 damagedealt += howmuch / power;
1214 damagetaken += howmuch / power;
1217 if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo))
1220 if (tutoriallevel != 1)
1221 permanentdamage += howmuch / 2 / power;
1222 if (tutoriallevel != 1)
1223 superpermanentdamage += howmuch / 4 / power;
1225 if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2)
1227 if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt)
1231 camerashake += howmuch / 100;
1232 if (id == 0 && ((howmuch > 50 && damage > damagetolerance / 2)))
1233 blackout = damage / damagetolerance;
1238 if (aitype == passivetype && damage < damagetolerance && ((tutoriallevel != 1 || cananger) && hostile))
1239 aitype = attacktypecutoff;
1240 if (tutoriallevel != 1 && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
1241 if (abs(Random() % 2) == 0) {
1242 aitype = gethelptype;
1245 aitype = attacktypecutoff;
1249 if (howmuch > damagetolerance * 50 && skeleton.free != 2) {
1252 for (int i = 0; i < skeleton.num_joints; i++) {
1254 flatvelocity2 = velocity;
1256 flatvelocity2 = skeleton.joints[i].velocity;
1258 flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
1260 flatfacing2 = skeleton.joints[i].position * scale + coords;
1261 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1262 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1263 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1264 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1265 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1266 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1269 emit_sound_at(splattersound, coords);
1278 if (!dead && creature == wolftype) {
1279 award_bonus(0, Wolfbonus);
1286 if (tutoriallevel != 1 || id == 0)
1287 if (speechdelay <= 0 && !dead && aitype != playercontrolled) {
1288 int whichsound = -1;
1290 if (creature == wolftype) {
1291 int i = abs(Random() % 2);
1293 whichsound = snarlsound;
1295 whichsound = snarl2sound;
1296 envsound[numenvsounds] = coords;
1297 envsoundvol[numenvsounds] = 16;
1298 envsoundlife[numenvsounds] = .4;
1301 if (creature == rabbittype) {
1302 int i = abs(Random() % 2);
1304 whichsound = rabbitpainsound;
1305 if (i == 1 && damage > damagetolerance)
1306 whichsound = rabbitpain1sound;
1307 envsound[numenvsounds] = coords;
1308 envsoundvol[numenvsounds] = 16;
1309 envsoundlife[numenvsounds] = .4;
1311 //if(i==2)whichsound=rabbitpain2sound;
1314 if (whichsound != -1) {
1315 emit_sound_at(whichsound, coords);
1320 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1321 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1325 * calculate/animate head facing direction?
1327 void Person::DoHead()
1329 static XYZ rotatearound;
1331 static float lookspeed = 500;
1333 if (!freeze && !winfreeze) {
1336 targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100;
1337 targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100;
1339 while (targetheadyaw > 180)targetheadyaw -= 360;
1340 while (targetheadyaw < -180)targetheadyaw += 360;
1342 if (targetheadyaw > 160)
1343 targetheadpitch = targetheadpitch * -1;
1344 if (targetheadyaw < -160)
1345 targetheadpitch = targetheadpitch * -1;
1346 if (targetheadyaw > 160)
1347 targetheadyaw = targetheadyaw - 180;
1348 if (targetheadyaw < -160)
1349 targetheadyaw = targetheadyaw + 180;
1351 if (targetheadpitch > 120)
1352 targetheadpitch = 120;
1353 if (targetheadpitch < -120)
1354 targetheadpitch = -120;
1355 if (targetheadyaw > 120)
1356 targetheadyaw = 120;
1357 if (targetheadyaw < -120)
1358 targetheadyaw = -120;
1361 targetheadpitch = 0;
1363 if (targetheadyaw > 80)
1365 if (targetheadyaw < -80)
1366 targetheadyaw = -80;
1367 if (targetheadpitch > 50)
1368 targetheadpitch = 50;
1369 if (targetheadpitch < -50)
1370 targetheadpitch = -50;
1373 if (abs(headyaw - targetheadyaw) < multiplier * lookspeed)
1374 headyaw = targetheadyaw;
1375 else if (headyaw > targetheadyaw) {
1376 headyaw -= multiplier * lookspeed;
1377 } else if (headyaw < targetheadyaw) {
1378 headyaw += multiplier * lookspeed;
1381 if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2)
1382 headpitch = targetheadpitch;
1383 else if (headpitch > targetheadpitch) {
1384 headpitch -= multiplier * lookspeed / 2;
1385 } else if (headpitch < targetheadpitch) {
1386 headpitch += multiplier * lookspeed / 2;
1389 rotatearound = jointPos(neck);
1390 jointPos(head) = rotatearound + DoRotation(jointPos(head) - rotatearound, headpitch, 0, 0);
1394 if (animTarget != bounceidleanim && animTarget != fightidleanim && animTarget != wolfidle && animTarget != knifefightidleanim && animTarget != drawrightanim && animTarget != drawleftanim && animTarget != walkanim) {
1395 facing = DoRotation(facing, headpitch * .4, 0, 0);
1396 facing = DoRotation(facing, 0, headyaw * .4, 0);
1399 if (animTarget == bounceidleanim || animTarget == fightidleanim || animTarget == wolfidle || animTarget == knifefightidleanim || animTarget == drawrightanim || animTarget == drawleftanim) {
1400 facing = DoRotation(facing, headpitch * .8, 0, 0);
1401 facing = DoRotation(facing, 0, headyaw * .8, 0);
1404 if (animTarget == walkanim) {
1405 facing = DoRotation(facing, headpitch * .6, 0, 0);
1406 facing = DoRotation(facing, 0, headyaw * .6, 0);
1409 skeleton.specialforward[0] = facing;
1410 //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1412 for (i = 0; i < skeleton.num_muscles; i++) {
1413 if (skeleton.muscles[i].visible && (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)) {
1414 skeleton.FindRotationMuscle(i, animTarget);
1421 * ragdolls character?
1423 void Person::RagDoll(bool checkcollision)
1428 if (!skeleton.free) {
1431 if (id == 0 && isFlip())
1438 facing = DoRotation(facing, 0, yaw, 0);
1440 skeleton.freetime = 0;
1442 skeleton.longdead = 0;
1445 skeleton.broken = 0;
1446 skeleton.spinny = 1;
1448 skeleton.freefall = 1;
1450 if (!isnormal(velocity.x)) velocity.x = 0;
1451 if (!isnormal(velocity.y)) velocity.y = 0;
1452 if (!isnormal(velocity.z)) velocity.z = 0;
1453 if (!isnormal(yaw)) yaw = 0;
1454 if (!isnormal(coords.x)) coords = 0;
1455 if (!isnormal(tilt)) tilt = 0;
1456 if (!isnormal(tilt2)) tilt2 = 0;
1458 for (i = 0; i < skeleton.num_joints; i++) {
1459 skeleton.joints[i].delay = 0;
1460 skeleton.joints[i].locked = 0;
1461 skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1462 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0);
1463 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = skeleton.joints[i].position;
1464 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = coords;
1465 skeleton.joints[i].position.y += .1;
1466 skeleton.joints[i].oldposition = skeleton.joints[i].position;
1467 skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords;
1470 for (i = 0; i < skeleton.num_joints; i++) {
1471 skeleton.joints[i].velocity = 0;
1472 skeleton.joints[i].velchange = 0;
1474 skeleton.DoConstraints(&coords, &scale);
1475 if (animation[animCurrent].height == lowheight || animation[animTarget].height == lowheight) {
1476 skeleton.DoConstraints(&coords, &scale);
1477 skeleton.DoConstraints(&coords, &scale);
1478 skeleton.DoConstraints(&coords, &scale);
1479 skeleton.DoConstraints(&coords, &scale);
1482 speed = animation[animTarget].speed[frameTarget] * 2;
1483 if (animation[animCurrent].speed[frameCurrent] > animation[animTarget].speed[frameTarget]) {
1484 speed = animation[animCurrent].speed[frameCurrent] * 2;
1487 speed = transspeed * 2;
1491 for (i = 0; i < skeleton.num_joints; i++) {
1492 if ((animation[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && animation[animCurrent].height == animation[animTarget].height)
1493 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);
1495 skeleton.joints[i].velocity = velocity / scale + facing * 5;
1496 change.x = (float)(Random() % 100) / 100;
1497 change.y = (float)(Random() % 100) / 100;
1498 change.z = (float)(Random() % 100) / 100;
1499 skeleton.joints[i].velocity += change;
1500 skeleton.joints[abs(Random() % skeleton.num_joints)].velocity -= change;
1502 change.x = (float)(Random() % 100) / 100;
1503 change.y = (float)(Random() % 100) / 100;
1504 change.z = (float)(Random() % 100) / 100;
1505 skeleton.joints[i].velchange += change;
1506 skeleton.joints[abs(Random() % skeleton.num_joints)].velchange -= change;
1509 if (checkcollision) {
1516 for (j = 0; j < skeleton.num_joints; j++) {
1517 average += skeleton.joints[j].position;
1521 coords += average * scale;
1522 for (j = 0; j < skeleton.num_joints; j++) {
1523 skeleton.joints[j].position -= average;
1526 whichpatchx = coords.x / (terrain.size / subdivision * terrain.scale);
1527 whichpatchz = coords.z / (terrain.size / subdivision * terrain.scale);
1528 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
1529 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
1530 i = terrain.patchobjects[whichpatchx][whichpatchz][l];
1533 if (SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.yaw[i], &objects.model[i]) != -1) {
1534 coords.x = lowpoint.x;
1535 coords.z = lowpoint.z;
1544 for (i = 0; i < skeleton.num_joints; i++) {
1545 velocity += skeleton.joints[i].velocity * scale;
1547 velocity /= skeleton.num_joints;
1550 if (Random() % 2 == 0) {
1551 if (weaponactive != -1 && animTarget != rabbitkickanim && num_weapons > 0) {
1552 weapons[weaponids[0]].owner = -1;
1553 weapons[weaponids[0]].hitsomething = 0;
1554 weapons[weaponids[0]].velocity = jointVel(righthand) * scale * -.3;
1555 weapons[weaponids[0]].velocity.x += .01;
1556 weapons[weaponids[0]].tipvelocity = jointVel(righthand) * scale;
1557 weapons[weaponids[0]].missed = 1;
1558 weapons[weaponids[0]].freetime = 0;
1559 weapons[weaponids[0]].firstfree = 1;
1560 weapons[weaponids[0]].physics = 1;
1563 weaponids[0] = weaponids[num_weapons];
1564 if (weaponstuck == num_weapons)
1568 for (i = 0; i < numplayers; i++) {
1569 player[i].wentforweapon = 0;
1574 animTarget = bounceidleanim;
1575 animCurrent = bounceidleanim;
1585 void Person::FootLand(int which, float opacity)
1587 static XYZ terrainlight;
1588 static XYZ footvel, footpoint;
1589 if (opacity >= 1 || skiddelay <= 0)
1593 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1595 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1596 //footpoint.y=coords.y;
1597 if (distsq(&footpoint, &viewer))
1598 Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity);
1599 } else if (environment == snowyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1600 footvel = velocity / 5;
1604 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1606 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1607 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1608 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1609 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1610 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity);
1611 if (opacity >= 1 || detail == 2)
1613 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1614 terrain.MakeDecal(footprintdecal, footpoint, .2, 1 * opacity, yaw);
1615 } else if (environment == grassyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1616 footvel = velocity / 5;
1620 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1622 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1623 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1624 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1625 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1626 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity);
1627 } else if (environment == desertenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1628 footvel = velocity / 5;
1632 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1634 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1635 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1636 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1637 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1638 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity);
1639 if (opacity >= 1 || detail == 2)
1641 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1642 terrain.MakeDecal(footprintdecal, footpoint, .2, .25 * opacity, yaw);
1643 } else if (isLanding() || animTarget == jumpupanim || isLandhard()) {
1644 footvel = velocity / 5;
1648 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1650 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1651 //footpoint.y=coords.y;
1652 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1653 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity);
1658 * make a puff effect at a body part (dust effect?)
1660 void Person::Puff(int whichlabel)
1662 static XYZ footvel, footpoint;
1665 footpoint = DoRotation(jointPos(whichlabel), 0, yaw, 0) * scale + coords;
1666 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .9, .3);
1670 * I think I added this in an attempt to clean up code
1672 void Person::setAnimation(int animation)
1674 animTarget = animation;
1683 void Person::DoAnimations()
1685 if (!skeleton.free) {
1687 static float oldtarget;
1689 if (isIdle() && animCurrent != getIdle())
1690 normalsupdatedelay = 0;
1692 if (animTarget == tempanim || animCurrent == tempanim) {
1693 animation[tempanim] = tempanimation;
1695 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
1701 vel[0] = velocity.x;
1702 vel[1] = velocity.y;
1703 vel[2] = velocity.z;
1706 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1707 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
1709 if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z))
1711 if (!crouchkeydown && velocity.y >= -15)
1714 if ((animCurrent == jumpupanim || animTarget == jumpdownanim)/*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) {
1719 targfacing = DoRotation(targfacing, 0, targetyaw, 0);
1721 if (normaldotproduct(targfacing, velocity) >= -.3)
1722 animTarget = flipanim;
1724 animTarget = backflipanim;
1725 crouchtogglekeydown = 1;
1733 if (animation[animTarget].attack != reversed)
1735 if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) {
1736 crouchtogglekeydown = 0;
1737 if (aitype == playercontrolled)
1740 if (!crouchtogglekeydown && animation[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain))
1743 crouchtogglekeydown = 1;
1747 if (animation[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) {
1749 normalsupdatedelay = 0;
1753 if (animTarget == rollanim && frameTarget == 3 && onfire) {
1755 emit_sound_at(fireendsound, coords);
1756 pause_sound(stream_firesound);
1760 if (animTarget == rabbittacklinganim && frameTarget == 1) {
1761 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->animTarget].attack==neutral&&victim->id!=0)Reverse();
1762 if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0)
1764 if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) {
1765 if (normaldotproduct(victim->facing, facing) > 0)
1766 victim->animTarget = rabbittackledbackanim;
1768 victim->animTarget = rabbittackledfrontanim;
1769 victim->frameTarget = 2;
1772 victim->targetyaw = yaw;
1773 if (victim->aitype == gethelptype)
1774 victim->DoDamage(victim->damagetolerance - victim->damage);
1775 //victim->DoDamage(30);
1776 if (creature == wolftype) {
1778 emit_sound_at(clawslicesound, victim->coords);
1780 victim->DoBloodBig(1 / victim->armorhead, 210);
1782 award_bonus(id, TackleBonus,
1783 victim->aitype == gethelptype ? 50 : 0);
1787 if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (animation[animTarget].label[frameTarget] || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) {
1788 if (weapons[weaponids[0]].getType() == knife) {
1789 if (weaponactive == -1)
1791 else if (weaponactive == 0)
1794 if (weaponactive == -1) {
1795 emit_sound_at(knifesheathesound, coords);
1797 if (weaponactive != -1) {
1798 emit_sound_at(knifedrawsound, coords, 128);
1801 drawtogglekeydown = 1;
1804 if (tutoriallevel != 1 || id == 0)
1805 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1808 if (terrain.getOpacity(coords.x, coords.z) < .2) {
1809 if (animation[animTarget].label[frameTarget] == 1)
1810 whichsound = footstepsound;
1812 whichsound = footstepsound2;
1813 if (animation[animTarget].label[frameTarget] == 1)
1815 if (animation[animTarget].label[frameTarget] == 2)
1817 if (animation[animTarget].label[frameTarget] == 3 && isRun()) {
1823 if (terrain.getOpacity(coords.x, coords.z) >= .2) {
1824 if (animation[animTarget].label[frameTarget] == 1)
1825 whichsound = footstepsound3;
1827 whichsound = footstepsound4;
1831 if (animation[animTarget].label[frameTarget] == 1)
1832 whichsound = footstepsound3;
1834 whichsound = footstepsound4;
1836 if (animation[animTarget].label[frameTarget] == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
1837 if (animation[animTarget].attack != neutral) {
1838 i = abs(Random() % 3);
1840 whichsound = lowwhooshsound;
1842 whichsound = midwhooshsound;
1844 whichsound = highwhooshsound;
1846 if (animation[animTarget].attack == neutral)
1847 whichsound = movewhooshsound;
1848 } else if (animation[animTarget].label[frameTarget] == 4)
1849 whichsound = knifeswishsound;
1850 if (animation[animTarget].label[frameTarget] == 8 && tutoriallevel != 1)
1851 whichsound = landsound2;
1853 emit_sound_at(whichsound, coords, 256.);
1856 if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
1857 envsound[numenvsounds] = coords;
1858 if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim)
1859 envsoundvol[numenvsounds] = 15;
1861 envsoundvol[numenvsounds] = 6;
1862 envsoundlife[numenvsounds] = .4;
1866 if (animation[animTarget].label[frameTarget] == 3) {
1868 emit_sound_at(whichsound, coords, 128.);
1873 if (tutoriallevel != 1 || id == 0)
1874 if (speechdelay <= 0)
1875 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
1876 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1877 int whichsound = -1;
1878 if (animation[animTarget].label[frameTarget] == 4 && aitype != playercontrolled) {
1879 if (animation[animTarget].attack != neutral) {
1880 i = abs(Random() % 4);
1881 if (creature == rabbittype) {
1882 if (i == 0) whichsound = rabbitattacksound;
1883 if (i == 1) whichsound = rabbitattack2sound;
1884 if (i == 2) whichsound = rabbitattack3sound;
1885 if (i == 3) whichsound = rabbitattack4sound;
1887 if (creature == wolftype) {
1888 if (i == 0) whichsound = barksound;
1889 if (i == 1) whichsound = bark2sound;
1890 if (i == 2) whichsound = bark3sound;
1891 if (i == 3) whichsound = barkgrowlsound;
1895 //if(animation[animTarget].attack==neutral)whichsound=movewhooshsound;
1897 //else if(animation[animTarget].label[frameTarget]==4)whichsound=knifeswishsound;
1898 //if(animation[animTarget].label[frameTarget]==8)whichsound=landsound2;
1900 if (whichsound != -1) {
1901 emit_sound_at(whichsound, coords);
1907 if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) {
1913 currentoffset = targetoffset;
1914 frameTarget = frameCurrent;
1915 animCurrent = animTarget;
1918 if (animTarget == removeknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1919 for (i = 0; i < weapons.size(); i++) {
1920 if (weapons[i].owner == -1)
1921 if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
1922 if (distsq(&coords, &weapons[i].position) >= 1) {
1923 if (weapons[i].getType() != staff) {
1924 emit_sound_at(knifedrawsound, coords, 128.);
1928 weapons[i].owner = id;
1929 if (num_weapons > 0) {
1930 weaponids[num_weapons] = weaponids[0];
1939 if (animTarget == crouchremoveknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1940 for (i = 0; i < weapons.size(); i++) {
1941 bool willwork = true;
1942 if (weapons[i].owner != -1)
1943 if (player[weapons[i].owner].weaponstuck != -1)
1944 if (player[weapons[i].owner].weaponids[player[weapons[i].owner].weaponstuck] == i)
1945 if (player[weapons[i].owner].num_weapons > 1)
1947 if ((weapons[i].owner == -1) || (hasvictim && weapons[i].owner == victim->id && victim->skeleton.free))
1948 if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) {
1949 if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
1950 bool fleshstuck = false;
1951 if (weapons[i].owner != -1)
1952 if (victim->weaponstuck != -1) {
1953 if (victim->weaponids[victim->weaponstuck] == i) {
1958 emit_sound_at(fleshstabremovesound, coords, 128.);
1960 if (weapons[i].getType() != staff) {
1961 emit_sound_at(knifedrawsound, coords, 128.);
1965 if (weapons[i].owner != -1) {
1967 victim = &player[weapons[i].owner];
1968 if (victim->num_weapons == 1)
1969 victim->num_weapons = 0;
1971 victim->num_weapons = 1;
1973 //victim->weaponactive=-1;
1974 victim->skeleton.longdead = 0;
1975 victim->skeleton.free = 1;
1976 victim->skeleton.broken = 0;
1978 for (int j = 0; j < victim->skeleton.num_joints; j++) {
1979 victim->skeleton.joints[j].velchange = 0;
1980 victim->skeleton.joints[j].locked = 0;
1986 Normalise(&relative);
1987 XYZ footvel, footpoint;
1989 footpoint = weapons[i].position;
1990 if (victim->weaponstuck != -1) {
1991 if (victim->weaponids[victim->weaponstuck] == i) {
1993 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
1994 weapons[i].bloody = 2;
1995 weapons[i].blooddrip = 5;
1996 victim->weaponstuck = -1;
1999 if (victim->num_weapons > 0) {
2000 if (victim->weaponstuck != 0 && victim->weaponstuck != -1)
2001 victim->weaponstuck = 0;
2002 if (victim->weaponids[0] == i)
2003 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
2006 victim->jointVel(abdomen) += relative * 6;
2007 victim->jointVel(neck) += relative * 6;
2008 victim->jointVel(rightshoulder) += relative * 6;
2009 victim->jointVel(leftshoulder) += relative * 6;
2011 weapons[i].owner = id;
2012 if (num_weapons > 0) {
2013 weaponids[num_weapons] = weaponids[0];
2022 if (animCurrent == drawleftanim && animation[animTarget].label[frameCurrent] == 5) {
2023 if (weaponactive == -1)
2025 else if (weaponactive == 0) {
2027 if (num_weapons == 2) {
2029 buffer = weaponids[0];
2030 weaponids[0] = weaponids[1];
2031 weaponids[1] = buffer;
2034 if (weaponactive == -1) {
2035 emit_sound_at(knifesheathesound, coords, 128.);
2037 if (weaponactive != -1) {
2038 emit_sound_at(knifedrawsound, coords, 128.);
2043 if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) {
2044 XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0);
2045 Normalise(&rotatetarget);
2046 targetyaw = -asin(0 - rotatetarget.x);
2047 targetyaw *= 360 / 6.28;
2048 if (rotatetarget.z < 0)
2049 targetyaw = 180 - targetyaw;
2051 if (animTarget == walljumprightkickanim)
2053 if (animTarget == walljumpleftkickanim)
2059 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0))
2062 if (distsq(&victim->coords, &/*player[i].*/coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1)
2067 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) {
2068 animTarget = rabbittackleanim;
2070 emit_sound_at(jumpsound, coords);
2078 targetloc = velocity;
2079 Normalise(&targetloc);
2080 targetloc += coords;
2081 for (i = 0; i < numplayers; i++) {
2083 if (distsq(&targetloc, &player[i].coords) < closestdist || closestdist == 0) {
2084 closestdist = distsq(&targetloc, &player[i].coords);
2088 if (closestid != -1)
2089 if (closestdist < 5 && !player[closestid].dead && animation[player[closestid].animTarget].height != lowheight && player[closestid].animTarget != backhandspringanim) {
2091 victim = &player[closestid];
2092 coords = victim->coords;
2093 animCurrent = rabbittacklinganim;
2094 animTarget = rabbittacklinganim;
2098 if (coords.z != victim->coords.z || coords.x != victim->coords.x) {
2099 rotatetarget = coords - victim->coords;
2100 Normalise(&rotatetarget);
2101 targetyaw = -asin(0 - rotatetarget.x);
2102 targetyaw *= 360 / 6.28;
2103 if (rotatetarget.z < 0)
2104 targetyaw = 180 - targetyaw;
2106 if (animTarget != rabbitrunninganim) {
2107 emit_sound_at(jumpsound, coords, 128.);
2113 float damagemult = 1 * power;
2114 if (creature == wolftype)
2115 damagemult = 2.5 * power;
2117 damagemult /= victim->damagetolerance / 200;
2119 //if(onfire)damagemult=3;
2120 if ((animation[animTarget].attack == normalattack || animTarget == walljumprightkickanim || animTarget == walljumpleftkickanim) && (!feint) && (victim->skeleton.free != 2 || animTarget == killanim || animTarget == dropkickanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == staffgroundsmashanim)) {
2121 if (animTarget == spinkickanim && animation[animTarget].label[frameCurrent] == 5) {
2122 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2126 if (Random() % 2 || creature == wolftype) {
2129 if (creature == wolftype)
2132 if (tutoriallevel != 1) {
2133 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2135 if (creature == wolftype) {
2136 emit_sound_at(clawslicesound, victim->coords, 128.);
2138 victim->DoBloodBig(2 / victim->armorhead, 175);
2142 relative = victim->coords - coords;
2144 Normalise(&relative);
2145 relative = DoRotation(relative, 0, -90, 0);
2146 for (i = 0; i < victim->skeleton.num_joints; i++) {
2147 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2149 victim->jointVel(head) += relative * damagemult * 200;
2152 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2158 if (animTarget == wolfslapanim && animation[animTarget].label[frameCurrent] == 5) {
2159 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2163 if (Random() % 2 || creature == wolftype) {
2165 if (creature == wolftype)
2168 emit_sound_at(whooshhitsound, victim->coords);
2169 if (creature == wolftype) {
2170 emit_sound_at(clawslicesound, victim->coords, 128.);
2172 victim->DoBloodBig(2, 175);
2176 relative = victim->coords - coords;
2178 Normalise(&relative);
2180 Normalise(&relative);
2181 relative = DoRotation(relative, 0, 90, 0);
2182 for (i = 0; i < victim->skeleton.num_joints; i++) {
2183 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2185 victim->jointVel(head) += relative * damagemult * 100;
2188 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2192 if (animTarget == walljumprightkickanim && animation[animTarget].label[frameCurrent] == 5) {
2193 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2199 if (tutoriallevel != 1) {
2200 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2202 if (creature == wolftype) {
2203 emit_sound_at(clawslicesound, victim->coords, 128.);
2205 victim->DoBloodBig(2 / victim->armorhead, 175);
2211 Normalise(&relative);
2212 relative = DoRotation(relative, 0, -90, 0);
2213 for (i = 0; i < victim->skeleton.num_joints; i++) {
2214 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2216 victim->jointVel(head) += relative * damagemult * 200;
2219 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2221 if (victim->damage > victim->damagetolerance)
2222 award_bonus(id, style);
2228 if (animTarget == walljumpleftkickanim && animation[animTarget].label[frameCurrent] == 5) {
2229 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2235 if (tutoriallevel != 1) {
2236 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2238 if (creature == wolftype) {
2239 emit_sound_at(clawslicesound, victim->coords, 128.);
2241 victim->DoBloodBig(2 / victim->armorhead, 175);
2247 Normalise(&relative);
2248 relative = DoRotation(relative, 0, 90, 0);
2249 for (i = 0; i < victim->skeleton.num_joints; i++) {
2250 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2252 victim->jointVel(head) += relative * damagemult * 200;
2255 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2257 if (victim->damage > victim->damagetolerance)
2258 award_bonus(id, style);
2264 if (animTarget == blockhighleftstrikeanim && animation[animTarget].label[frameCurrent] == 5) {
2265 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2273 emit_sound_at(whooshhitsound, victim->coords);
2276 relative = victim->coords - coords;
2278 Normalise(&relative);
2279 for (i = 0; i < victim->skeleton.num_joints; i++) {
2280 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
2282 victim->jointVel(head) += relative * damagemult * 100;
2285 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2289 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 8) {
2290 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) {
2294 emit_sound_at(whooshhitsound, victim->coords, 128.);
2296 victim->skeleton.longdead = 0;
2297 victim->skeleton.free = 1;
2298 victim->skeleton.broken = 0;
2299 victim->skeleton.spinny = 1;
2301 for (i = 0; i < victim->skeleton.num_joints; i++) {
2302 victim->skeleton.joints[i].velchange = 0;
2303 victim->skeleton.joints[i].delay = 0;
2304 victim->skeleton.joints[i].locked = 0;
2305 //victim->skeleton.joints[i].velocity=0;
2311 Normalise(&relative);
2312 for (i = 0; i < victim->skeleton.num_joints; i++) {
2313 victim->skeleton.joints[i].velocity.y = relative.y * 10;
2314 victim->skeleton.joints[i].position.y += relative.y * .3;
2315 victim->skeleton.joints[i].oldposition.y += relative.y * .3;
2316 victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
2318 victim->Puff(abdomen);
2319 victim->jointVel(abdomen).y = relative.y * 400;
2323 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 5) {
2324 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) {
2328 if (tutoriallevel != 1) {
2329 emit_sound_at(heavyimpactsound, coords, 128.);
2332 relative = victim->coords - coords;
2334 Normalise(&relative);
2335 for (i = 0; i < victim->skeleton.num_joints; i++) {
2336 victim->skeleton.joints[i].velocity += relative * damagemult * 90;
2338 victim->Puff(abdomen);
2339 if (victim->dead != 2 && victim->permanentdamage > victim->damagetolerance - 250 && autoslomo) {
2343 victim->DoDamage(damagemult * 500 / victim->protectionhigh);
2344 victim->jointVel(abdomen) += relative * damagemult * 300;
2348 if (animTarget == dropkickanim && animation[animTarget].label[frameCurrent] == 7) {
2349 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) {
2353 if (tutoriallevel != 1) {
2354 emit_sound_at(thudsound, coords);
2357 victim->skeleton.longdead = 0;
2358 victim->skeleton.free = 1;
2359 victim->skeleton.broken = 0;
2360 victim->skeleton.spinny = 1;
2362 for (i = 0; i < victim->skeleton.num_joints; i++) {
2363 victim->skeleton.joints[i].velchange = 0;
2364 //victim->skeleton.joints[i].delay=0;
2365 victim->skeleton.joints[i].locked = 0;
2368 relative = victim->coords - coords;
2369 Normalise(&relative);
2371 Normalise(&relative);
2372 for (i = 0; i < victim->skeleton.num_joints; i++) {
2373 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2378 victim->Puff(abdomen);
2379 victim->DoDamage(damagemult * 20 / victim->protectionhigh);
2380 victim->jointVel(abdomen) += relative * damagemult * 200;
2389 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 5) {
2390 //if(id==0)camerashake+=.4;
2393 if (!victim->skeleton.free)
2397 terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360);
2398 emit_sound_at(knifesheathesound, coords, 128.);
2401 if (victim && hasvictim) {
2402 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2404 XYZ where, startpoint, endpoint, movepoint, colpoint;
2405 float rotationpoint;
2407 if (weapons[weaponids[weaponactive]].getType() == knife) {
2408 where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4);
2409 where -= victim->coords;
2410 if (!victim->skeleton.free)
2411 where = DoRotation(where, 0, -victim->yaw, 0);
2414 startpoint.y += 100;
2418 if (weapons[weaponids[weaponactive]].getType() == sword) {
2419 where = weapons[weaponids[weaponactive]].position;
2420 where -= victim->coords;
2421 if (!victim->skeleton.free)
2422 where = DoRotation(where, 0, -victim->yaw, 0);
2424 where = weapons[weaponids[weaponactive]].tippoint;
2425 where -= victim->coords;
2426 if (!victim->skeleton.free)
2427 where = DoRotation(where, 0, -victim->yaw, 0);
2430 if (weapons[weaponids[weaponactive]].getType() == staff) {
2431 where = weapons[weaponids[weaponactive]].position;
2432 where -= victim->coords;
2433 if (!victim->skeleton.free)
2434 where = DoRotation(where, 0, -victim->yaw, 0);
2436 where = weapons[weaponids[weaponactive]].tippoint;
2437 where -= victim->coords;
2438 if (!victim->skeleton.free)
2439 where = DoRotation(where, 0, -victim->yaw, 0);
2444 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
2446 if (whichtri != -1) {
2447 if (victim->dead != 2) {
2448 victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2));
2450 award_bonus(id, FinishedBonus);
2453 weapons[weaponids[weaponactive]].bloody = 2;
2455 victim->skeleton.longdead = 0;
2456 victim->skeleton.free = 1;
2457 victim->skeleton.broken = 0;
2459 for (i = 0; i < victim->skeleton.num_joints; i++) {
2460 victim->skeleton.joints[i].velchange = 0;
2461 victim->skeleton.joints[i].locked = 0;
2462 //victim->skeleton.joints[i].velocity=0;
2464 emit_sound_at(fleshstabsound, coords, 128);
2467 if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) {
2468 weapons[weaponids[weaponactive]].blooddrip += 5;
2469 weapons[weaponids[weaponactive]].blooddripdelay = 0;
2471 if (whichtri == -1) {
2473 emit_sound_at(knifesheathesound, coords, 128.);
2479 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 6) {
2481 emit_sound_at(knifedrawsound, coords, 128);
2484 if (victim && hasvictim) {
2485 XYZ footvel, footpoint;
2487 emit_sound_at(fleshstabremovesound, coords, 128.);
2490 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2492 if (weapons[weaponids[weaponactive]].getType() == sword) {
2493 XYZ where, startpoint, endpoint, movepoint;
2494 float rotationpoint;
2497 where = weapons[weaponids[weaponactive]].position;
2498 where -= victim->coords;
2499 if (!victim->skeleton.free)
2500 where = DoRotation(where, 0, -victim->yaw, 0);
2502 where = weapons[weaponids[weaponactive]].tippoint;
2503 where -= victim->coords;
2504 if (!victim->skeleton.free)
2505 where = DoRotation(where, 0, -victim->yaw, 0);
2510 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2511 footpoint += victim->coords;
2513 if (whichtri == -1) {
2514 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2517 if (weapons[weaponids[weaponactive]].getType() == staff) {
2518 XYZ where, startpoint, endpoint, movepoint;
2519 float rotationpoint;
2522 where = weapons[weaponids[weaponactive]].position;
2523 where -= victim->coords;
2524 if (!victim->skeleton.free)
2525 where = DoRotation(where, 0, -victim->yaw, 0);
2527 where = weapons[weaponids[weaponactive]].tippoint;
2528 where -= victim->coords;
2529 if (!victim->skeleton.free)
2530 where = DoRotation(where, 0, -victim->yaw, 0);
2535 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2536 footpoint += victim->coords;
2538 if (whichtri == -1) {
2539 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2542 hasvictim = victim->DoBloodBigWhere(2, 220, footpoint);
2544 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2545 victim->skeleton.longdead = 0;
2546 victim->skeleton.free = 1;
2547 victim->skeleton.broken = 0;
2549 for (i = 0; i < victim->skeleton.num_joints; i++) {
2550 victim->skeleton.joints[i].velchange = 0;
2551 victim->skeleton.joints[i].locked = 0;
2552 //victim->skeleton.joints[i].velocity=0;
2558 Normalise(&relative);
2559 //victim->Puff(abdomen);
2561 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2563 if (victim->bloodloss < victim->damagetolerance) {
2564 victim->bloodloss += 1000;
2568 victim->jointVel(abdomen) += relative * damagemult * 20;
2572 if (!hasvictim && onterrain) {
2573 weapons[weaponids[weaponactive]].bloody = 0;
2574 weapons[weaponids[weaponactive]].blooddrip = 0;
2578 if (animTarget == upunchanim && animation[animTarget].label[frameCurrent] == 5) {
2579 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2587 if (tutoriallevel != 1) {
2588 emit_sound_at(heavyimpactsound, victim->coords, 128);
2593 relative = victim->coords - coords;
2595 Normalise(&relative);
2596 for (i = 0; i < victim->skeleton.num_joints; i++) {
2597 victim->skeleton.joints[i].velocity = relative * 30;
2599 victim->jointVel(head) += relative * damagemult * 150;
2601 victim->frameTarget = 0;
2602 victim->animTarget = staggerbackhardanim;
2603 victim->targetyaw = targetyaw + 180;
2605 victim->stunned = 1;
2608 victim->Puff(abdomen);
2609 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2616 if (animTarget == winduppunchanim && animation[animTarget].label[frameCurrent] == 5) {
2617 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) {
2621 if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height != lowheight) {
2622 if (tutoriallevel != 1) {
2623 emit_sound_at(thudsound, victim->coords);
2625 } else if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height == lowheight) {
2626 if (tutoriallevel != 1) {
2627 emit_sound_at(whooshhitsound, victim->coords);
2630 if (tutoriallevel != 1) {
2631 emit_sound_at(heavyimpactsound, victim->coords);
2635 if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || animation[victim->animTarget].height == lowheight)
2638 relative = victim->coords - coords;
2640 Normalise(&relative);
2642 Normalise(&relative);
2643 for (i = 0; i < victim->skeleton.num_joints; i++) {
2644 victim->skeleton.joints[i].velocity = relative * 5;
2646 victim->jointVel(abdomen) += relative * damagemult * 400;
2648 victim->frameTarget = 0;
2649 victim->animTarget = staggerbackhardanim;
2650 victim->targetyaw = targetyaw + 180;
2652 victim->stunned = 1;
2654 victim->Puff(abdomen);
2655 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2661 if (animTarget == blockhighleftanim && animation[animTarget].label[frameCurrent] == 5) {
2662 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2663 if (victim->id == 0)
2665 emit_sound_at(landsound2, victim->coords);
2671 if (animTarget == swordslashparryanim && animation[animTarget].label[frameCurrent] == 5) {
2672 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2673 if (victim->id == 0)
2676 if (weaponactive != -1) {
2677 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2678 if (weapons[victim->weaponids[0]].getType() == staff)
2679 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2680 if (weapons[weaponids[0]].getType() == staff)
2681 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2683 emit_sound_at(swordstaffsound, victim->coords);
2685 emit_sound_at(metalhitsound, victim->coords);
2693 if (animTarget == knifethrowanim && animation[animTarget].label[frameCurrent] == 5) {
2694 if (weaponactive != -1) {
2697 weapons[weaponids[0]].owner = -1;
2698 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);
2700 /*if(victim->animTarget==jumpupanim||victim->animTarget==jumpdownanim){
2701 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2703 weapons[weaponids[0]].velocity = aim * 50;
2704 weapons[weaponids[0]].tipvelocity = aim * 50;
2705 weapons[weaponids[0]].missed = 0;
2706 weapons[weaponids[0]].hitsomething = 0;
2707 weapons[weaponids[0]].freetime = 0;
2708 weapons[weaponids[0]].firstfree = 1;
2709 weapons[weaponids[0]].physics = 0;
2712 weaponids[0] = weaponids[num_weapons];
2718 if (animTarget == knifeslashstartanim && animation[animTarget].label[frameCurrent] == 5) {
2720 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 &&/*animation[victim->animTarget].height!=lowheight&&*/victim->animTarget != dodgebackanim && victim->animTarget != rollanim) {
2722 if (tutoriallevel != 1)
2723 victim->DoBloodBig(1.5 / victim->armorhigh, 225);
2725 award_bonus(id, Slicebonus);
2726 if (tutoriallevel != 1) {
2727 emit_sound_at(knifeslicesound, victim->coords);
2729 //victim->jointVel(abdomen)+=relative*damagemult*200;
2730 if (animation[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
2731 if (victim->id != 0 || difficulty == 2) {
2732 victim->frameTarget = 0;
2733 victim->animTarget = staggerbackhardanim;
2734 victim->targetyaw = targetyaw + 180;
2738 victim->lowreversaldelay = 0;
2739 victim->highreversaldelay = 0;
2740 if (aitype != playercontrolled)
2741 weaponmissdelay = .6;
2743 if (tutoriallevel != 1)
2744 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2745 weapons[weaponids[weaponactive]].bloody = 1;
2746 if (tutoriallevel != 1)
2747 weapons[weaponids[weaponactive]].blooddrip += 3;
2749 XYZ footvel, footpoint;
2751 if (skeleton.free) {
2752 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2754 if (!skeleton.free) {
2755 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2757 if (tutoriallevel != 1) {
2759 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .6, .3);
2760 footvel = DoRotation(facing, 0, 90, 0) * .8;
2762 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2763 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2764 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
2765 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
2767 if (tutoriallevel == 1) {
2768 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .6, .3);
2770 victim->DoDamage(damagemult * 0);
2773 if (animTarget == swordslashanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2774 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) {
2775 if (victim->weaponactive == -1 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) {
2776 award_bonus(id, Slashbonus);
2778 if (tutoriallevel != 1) {
2779 if (normaldotproduct(victim->facing, victim->coords - coords) < 0)
2780 victim->DoBloodBig(2 / victim->armorhigh, 190);
2782 victim->DoBloodBig(2 / victim->armorhigh, 185);
2783 victim->deathbleeding = 1;
2784 emit_sound_at(swordslicesound, victim->coords);
2786 //victim->jointVel(abdomen)+=relative*damagemult*200;
2787 if (tutoriallevel != 1) {
2788 victim->frameTarget = 0;
2789 victim->animTarget = staggerbackhardanim;
2790 victim->targetyaw = targetyaw + 180;
2794 if (tutoriallevel != 1) {
2795 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2796 weapons[weaponids[weaponactive]].bloody = 1;
2797 weapons[weaponids[weaponactive]].blooddrip += 3;
2799 float bloodlossamount;
2800 bloodlossamount = 200 + abs((float)(Random() % 40)) - 20;
2801 victim->bloodloss += bloodlossamount / victim->armorhigh;
2802 //victim->bloodloss+=100*(6.5-distsq(&coords,&victim->coords));
2803 victim->DoDamage(damagemult * 0);
2805 XYZ footvel, footpoint;
2807 if (skeleton.free) {
2808 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2810 if (!skeleton.free) {
2811 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2814 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
2815 footvel = DoRotation(facing, 0, 90, 0) * .8;
2817 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2818 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2819 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
2820 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
2823 if (victim->weaponactive != -1) {
2824 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2825 if (weapons[victim->weaponids[0]].getType() == staff)
2826 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2827 if (weapons[weaponids[0]].getType() == staff)
2828 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2830 emit_sound_at(swordstaffsound, victim->coords);
2832 emit_sound_at(metalhitsound, victim->coords);
2838 victim->Puff(righthand);
2840 victim->frameTarget = 0;
2841 victim->animTarget = staggerbackhighanim;
2842 victim->targetyaw = targetyaw + 180;
2844 weapons[victim->weaponids[0]].owner = -1;
2845 aim = DoRotation(facing, 0, 90, 0) * 21;
2847 weapons[victim->weaponids[0]].velocity = aim * -.2;
2848 weapons[victim->weaponids[0]].tipvelocity = aim;
2849 weapons[victim->weaponids[0]].missed = 1;
2850 weapons[weaponids[0]].hitsomething = 0;
2851 weapons[victim->weaponids[0]].freetime = 0;
2852 weapons[victim->weaponids[0]].firstfree = 1;
2853 weapons[victim->weaponids[0]].physics = 1;
2854 victim->num_weapons--;
2855 if (victim->num_weapons) {
2856 victim->weaponids[0] = victim->weaponids[num_weapons];
2857 if (victim->weaponstuck == victim->num_weapons)
2858 victim->weaponstuck = 0;
2860 victim->weaponactive = -1;
2861 for (i = 0; i < numplayers; i++) {
2862 player[i].wentforweapon = 0;
2869 if (animTarget == staffhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2870 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2871 if (tutoriallevel != 1) {
2872 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 250;
2876 if (Random() % 2 || creature == wolftype) {
2879 emit_sound_at(staffheadsound, victim->coords);
2883 relative = victim->coords - coords;
2885 Normalise(&relative);
2886 relative = DoRotation(relative, 0, 90, 0);
2888 Normalise(&relative);
2889 for (i = 0; i < victim->skeleton.num_joints; i++) {
2890 victim->skeleton.joints[i].velocity += relative * damagemult * 60;
2892 victim->jointVel(head) += relative * damagemult * 230;
2893 victim->jointVel(neck) += relative * damagemult * 230;
2896 if (tutoriallevel != 1) {
2897 victim->DoDamage(damagemult * 120 / victim->protectionhigh);
2899 award_bonus(id, solidhit, 30);
2904 if (animTarget == staffspinhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2905 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2906 if (tutoriallevel != 1) {
2907 weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250;
2911 if (Random() % 2 || creature == wolftype) {
2914 emit_sound_at(staffheadsound, victim->coords);
2918 relative = victim->coords - coords;
2920 Normalise(&relative);
2921 relative = DoRotation(relative, 0, -90, 0);
2922 for (i = 0; i < victim->skeleton.num_joints; i++) {
2923 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2925 victim->jointVel(head) += relative * damagemult * 220;
2926 victim->jointVel(neck) += relative * damagemult * 220;
2929 if (tutoriallevel != 1) {
2930 victim->DoDamage(damagemult * 350 / victim->protectionhead);
2932 award_bonus(id, solidhit, 60);
2937 if (animTarget == staffgroundsmashanim && animation[animTarget].label[frameCurrent] == 5) {
2938 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) {
2940 if (tutoriallevel != 1) {
2942 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500;
2945 if (Random() % 2 || creature == wolftype) {
2948 emit_sound_at(staffbodysound, victim->coords);
2950 victim->skeleton.longdead = 0;
2951 victim->skeleton.free = 1;
2952 victim->skeleton.broken = 0;
2954 for (i = 0; i < victim->skeleton.num_joints; i++) {
2955 victim->skeleton.joints[i].velchange = 0;
2956 victim->skeleton.joints[i].locked = 0;
2957 //victim->skeleton.joints[i].velocity=0;
2963 /*relative=victim->coords-coords;
2965 Normalise(&relative);
2966 relative=DoRotation(relative,0,90,0);*/
2968 Normalise(&relative);
2969 if (!victim->dead) {
2970 for (i = 0; i < victim->skeleton.num_joints; i++) {
2971 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
2974 victim->jointVel(abdomen) += relative * damagemult * 40;
2977 for (i = 0; i < victim->skeleton.num_joints; i++) {
2978 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
2981 //victim->jointVel(abdomen)+=relative*damagemult*20;
2983 victim->Puff(abdomen);
2984 if (tutoriallevel != 1) {
2985 victim->DoDamage(damagemult * 100 / victim->protectionhigh);
2987 if (!victim->dead) {
2988 award_bonus(id, solidhit, 40);
2994 if (animTarget == lowkickanim && animation[animTarget].label[frameCurrent] == 5) {
2995 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != highheight) {
3000 relative = victim->coords - coords;
3002 Normalise(&relative);
3006 if (animation[victim->animTarget].height == lowheight) {
3012 for (i = 0; i < victim->skeleton.num_joints; i++) {
3013 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3015 victim->jointVel(head) += relative * damagemult * 200;
3016 if (tutoriallevel != 1) {
3017 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3020 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3021 if (victim->howactive == typesleeping)
3022 victim->DoDamage(damagemult * 150 / victim->protectionhead);
3023 if (creature == wolftype) {
3024 emit_sound_at(clawslicesound, victim->coords, 128.);
3026 victim->DoBloodBig(2 / victim->armorhead, 175);
3029 if (victim->damage >= victim->damagetolerance)
3031 for (i = 0; i < victim->skeleton.num_joints; i++) {
3032 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3034 victim->jointVel(abdomen) += relative * damagemult * 200;
3035 victim->frameTarget = 0;
3036 victim->animTarget = staggerbackhighanim;
3037 victim->targetyaw = targetyaw + 180;
3039 if (tutoriallevel != 1) {
3040 emit_sound_at(landsound2, victim->coords, 128.);
3042 victim->Puff(abdomen);
3043 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3044 if (creature == wolftype) {
3045 emit_sound_at(clawslicesound, victim->coords, 128.);
3047 victim->DoBloodBig(2 / victim->armorhigh, 170);
3054 if (animTarget == sweepanim && animation[animTarget].label[frameCurrent] == 5) {
3055 if (victim->animTarget != jumpupanim && distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim != this) {
3059 if (tutoriallevel != 1) {
3060 emit_sound_at(landsound2, victim->coords, 128.);
3063 relative = victim->coords - coords;
3065 Normalise(&relative);
3067 if (animation[victim->animTarget].height == middleheight || animation[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
3070 for (i = 0; i < victim->skeleton.num_joints; i++) {
3071 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
3073 relative = DoRotation(relative, 0, -90, 0);
3075 for (i = 0; i < victim->skeleton.num_joints; i++) {
3076 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)
3077 victim->skeleton.joints[i].velocity = relative * 80;
3079 victim->Puff(rightankle);
3080 victim->Puff(leftankle);
3081 victim->DoDamage(damagemult * 40 / victim->protectionlow);
3083 if (victim->damage >= victim->damagetolerance)
3085 for (i = 0; i < victim->skeleton.num_joints; i++) {
3086 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3088 relative = DoRotation(relative, 0, -90, 0);
3089 for (i = 0; i < victim->skeleton.num_joints; i++) {
3090 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)
3091 victim->skeleton.joints[i].velocity += relative * damagemult * 80;
3093 victim->jointVel(abdomen) += relative * damagemult * 200;
3094 victim->frameTarget = 0;
3095 victim->animTarget = staggerbackhighanim;
3096 victim->targetyaw = targetyaw + 180;
3098 if (tutoriallevel != 1) {
3099 emit_sound_at(landsound2, victim->coords, 128.);
3101 victim->Puff(abdomen);
3102 victim->DoDamage(damagemult * 30 / victim->protectionlow);
3110 if (animation[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) {
3111 if (animTarget == spinkickreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3119 if (tutoriallevel != 1) {
3120 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3122 if (creature == wolftype) {
3123 emit_sound_at(clawslicesound, victim->coords, 128);
3125 victim->DoBloodBig(2 / victim->armorhigh, 170);
3129 relative = victim->coords - oldcoords;
3131 Normalise(&relative);
3132 //relative=DoRotation(relative,0,-90,0);
3133 for (i = 0; i < victim->skeleton.num_joints; i++) {
3134 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3136 victim->jointVel(abdomen) += relative * damagemult * 200;
3138 victim->Puff(abdomen);
3139 victim->DoDamage(damagemult * 150 / victim->protectionhigh);
3141 award_bonus(id, Reversal);
3144 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && animation[animTarget].label[frameCurrent] == 5) {
3145 if (victim->weaponactive != -1 && victim->num_weapons > 0) {
3146 if (weapons[victim->weaponids[victim->weaponactive]].owner == victim->id) {
3147 weapons[victim->weaponids[victim->weaponactive]].owner = id;
3149 if (num_weapons > 0) {
3150 weaponids[num_weapons] = weaponids[victim->weaponactive];
3153 weaponids[0] = victim->weaponids[victim->weaponactive];
3154 victim->num_weapons--;
3155 if (victim->num_weapons > 0) {
3156 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
3157 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
3159 victim->weaponactive = -1;
3164 if (animTarget == staffhitreversalanim && animation[animTarget].label[frameCurrent] == 5) {
3172 emit_sound_at(whooshhitsound, victim->coords, 128.);
3175 relative = victim->coords - oldcoords;
3177 Normalise(&relative);
3178 //relative=DoRotation(relative,0,-90,0);
3179 for (i = 0; i < victim->skeleton.num_joints; i++) {
3180 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3182 victim->jointVel(abdomen) += relative * damagemult * 200;
3185 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3188 if (animTarget == staffspinhitreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3197 award_bonus(id, staffreversebonus);
3199 if (tutoriallevel != 1) {
3200 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3203 award_bonus(id, staffreversebonus); // Huh, again?
3206 relative = victim->coords - oldcoords;
3208 Normalise(&relative);
3209 //relative=DoRotation(relative,0,-90,0);
3210 for (i = 0; i < victim->skeleton.num_joints; i++) {
3211 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3213 victim->jointVel(abdomen) += relative * damagemult * 200;
3216 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3219 if (animTarget == upunchreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3225 Normalise(&relative);
3228 for (i = 0; i < victim->skeleton.num_joints; i++) {
3229 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3231 victim->jointVel(lefthand) *= .1;
3232 victim->jointVel(leftwrist) *= .2;
3233 victim->jointVel(leftelbow) *= .5;
3234 victim->jointVel(leftshoulder) *= .7;
3235 victim->jointVel(righthand) *= .1;
3236 victim->jointVel(rightwrist) *= .2;
3237 victim->jointVel(rightelbow) *= .5;
3238 victim->jointVel(rightshoulder) *= .7;
3240 victim->Puff(abdomen);
3241 victim->DoDamage(damagemult * 90 / victim->protectionhigh);
3243 award_bonus(id, Reversal);
3247 if (weaponactive != -1 || creature == wolftype)
3249 if (creature == rabbittype && weaponactive != -1)
3250 if (weapons[weaponids[0]].getType() == staff)
3253 if (weaponactive != -1) {
3254 victim->DoBloodBig(2 / victim->armorhigh, 225);
3255 emit_sound_at(knifeslicesound, victim->coords);
3256 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3257 weapons[weaponids[weaponactive]].bloody = 1;
3258 weapons[weaponids[weaponactive]].blooddrip += 3;
3260 if (weaponactive == -1 && creature == wolftype) {
3262 emit_sound_at(clawslicesound, victim->coords, 128.);
3264 victim->DoBloodBig(2 / victim->armorhigh, 175);
3271 if (animTarget == swordslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3277 Normalise(&relative);
3280 for (i = 0; i < victim->skeleton.num_joints; i++) {
3281 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3283 victim->jointVel(lefthand) *= .1 - 1;
3284 victim->jointVel(leftwrist) *= .2 - 1;
3285 victim->jointVel(leftelbow) *= .5 - 1;
3286 victim->jointVel(leftshoulder) *= .7 - 1;
3287 victim->jointVel(righthand) *= .1 - 1;
3288 victim->jointVel(rightwrist) *= .2 - 1;
3289 victim->jointVel(rightelbow) *= .5 - 1;
3290 victim->jointVel(rightshoulder) *= .7 - 1;
3292 award_bonus(id, swordreversebonus);
3295 if (hasvictim && animTarget == knifeslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3303 if (tutoriallevel != 1) {
3304 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3308 relative = victim->coords - oldcoords;
3310 Normalise(&relative);
3311 relative = DoRotation(relative, 0, -90, 0);
3312 for (i = 0; i < victim->skeleton.num_joints; i++) {
3313 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3315 victim->jointVel(abdomen) += relative * damagemult * 200;
3317 victim->Puff(abdomen);
3318 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3320 award_bonus(id, Reversal);
3323 if (hasvictim && animTarget == sneakattackanim && animation[animTarget].label[frameCurrent] == 7) {
3326 victim->skeleton.spinny = 0;
3328 relative = facing * -1;
3330 Normalise(&relative);
3331 if (victim->id == 0)
3333 for (i = 0; i < victim->skeleton.num_joints; i++) {
3334 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3336 //victim->DoDamage(1000);
3337 victim->damage = victim->damagetolerance;
3338 victim->permanentdamage = victim->damagetolerance - 1;
3341 if (weaponactive != -1 || creature == wolftype)
3343 if (creature == rabbittype && weaponactive != -1)
3344 if (weapons[weaponids[0]].getType() == staff)
3347 if (weaponactive != -1) {
3348 victim->DoBloodBig(200, 225);
3349 emit_sound_at(knifeslicesound, victim->coords);
3351 weapons[weaponids[weaponactive]].bloody = 2;
3352 weapons[weaponids[weaponactive]].blooddrip += 5;
3355 if (creature == wolftype && weaponactive == -1) {
3356 emit_sound_at(clawslicesound, victim->coords, 128.);
3358 victim->DoBloodBig(2, 175);
3361 award_bonus(id, spinecrusher);
3364 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3365 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3367 if (animTarget == knifefollowanim)
3368 victim->DoBloodBig(200, 210);
3369 if (animTarget == knifesneakattackanim) {
3370 /*victim->DoBloodBig(200,195);
3375 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
3376 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck),0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3378 XYZ footvel, footpoint;
3380 footpoint = weapons[weaponids[0]].tippoint;
3382 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3383 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3384 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3385 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3386 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3387 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3388 victim->DoBloodBig(200, 195);
3389 award_bonus(id, tracheotomy);
3391 if (animTarget == knifefollowanim) {
3392 award_bonus(id, Stabbonus);
3393 XYZ footvel, footpoint;
3395 footpoint = weapons[weaponids[0]].tippoint;
3397 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3398 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3399 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3400 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3401 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3402 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3405 victim->bloodloss += 10000;
3406 victim->velocity = 0;
3407 emit_sound_at(fleshstabsound, victim->coords);
3409 weapons[weaponids[weaponactive]].bloody = 2;
3410 weapons[weaponids[weaponactive]].blooddrip += 5;
3414 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 6) {
3416 victim->velocity = 0;
3417 for (i = 0; i < victim->skeleton.num_joints; i++) {
3418 victim->skeleton.joints[i].velocity = 0;
3420 if (animTarget == knifefollowanim) {
3422 for (i = 0; i < victim->skeleton.num_joints; i++) {
3423 victim->skeleton.joints[i].velocity = 0;
3426 if (weaponactive != -1 && animation[victim->animTarget].attack != reversal) {
3427 emit_sound_at(fleshstabremovesound, victim->coords);
3429 weapons[weaponids[weaponactive]].bloody = 2;
3430 weapons[weaponids[weaponactive]].blooddrip += 5;
3432 XYZ footvel, footpoint;
3434 footpoint = weapons[weaponids[0]].tippoint;
3436 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3437 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3438 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3439 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3440 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3441 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3445 if (hasvictim && (animTarget == swordsneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3446 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3447 award_bonus(id, backstab);
3451 XYZ footvel, footpoint;
3453 footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2;
3455 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3456 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3457 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3458 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3459 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 5, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3460 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3461 victim->DoBloodBig(200, 180);
3462 victim->DoBloodBig(200, 215);
3463 victim->bloodloss += 10000;
3464 victim->velocity = 0;
3465 emit_sound_at(fleshstabsound, victim->coords);
3467 weapons[weaponids[weaponactive]].bloody = 2;
3468 weapons[weaponids[weaponactive]].blooddrip += 5;
3472 if (hasvictim && animTarget == swordsneakattackanim && animation[animTarget].label[frameCurrent] == 6) {
3474 victim->velocity = 0;
3475 for (i = 0; i < victim->skeleton.num_joints; i++) {
3476 victim->skeleton.joints[i].velocity = 0;
3478 if (weaponactive != -1) {
3479 emit_sound_at(fleshstabremovesound, victim->coords);
3481 weapons[weaponids[weaponactive]].bloody = 2;
3482 weapons[weaponids[weaponactive]].blooddrip += 5;
3484 XYZ footvel, footpoint;
3486 footpoint = weapons[weaponids[0]].tippoint;
3488 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3489 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3490 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3491 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3492 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3493 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3497 if (animTarget == sweepreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3505 if (weaponactive == -1) {
3506 if (tutoriallevel != 1) {
3507 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3512 if (weaponactive != -1 || creature == wolftype)
3514 if (creature == rabbittype && weaponactive != -1)
3515 if (weapons[weaponids[0]].getType() == staff)
3518 if (weaponactive != -1) {
3519 victim->DoBloodBig(2 / victim->armorhead, 225);
3520 emit_sound_at(knifeslicesound, victim->coords);
3521 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3522 weapons[weaponids[weaponactive]].bloody = 1;
3523 weapons[weaponids[weaponactive]].blooddrip += 3;
3525 if (weaponactive == -1 && creature == wolftype) {
3526 emit_sound_at(clawslicesound, victim->coords, 128.);
3528 victim->DoBloodBig(2 / victim->armorhead, 175);
3532 award_bonus(id, Reversal);
3537 //relative=victim->coords-oldcoords;
3538 relative = facing * -1;
3540 Normalise(&relative);
3541 relative = DoRotation(relative, 0, 90, 0);
3543 Normalise(&relative);
3544 for (i = 0; i < victim->skeleton.num_joints; i++) {
3545 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3547 victim->jointVel(head) += relative * damagemult * 200;
3548 if (victim->damage < victim->damagetolerance - 100)
3549 victim->velocity = relative * 200;
3550 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3551 victim->velocity = 0;
3554 if (animTarget == sweepreversalanim && ((animation[animTarget].label[frameCurrent] == 9 && victim->damage < victim->damagetolerance) || (animation[animTarget].label[frameCurrent] == 7 && victim->damage > victim->damagetolerance))) {
3558 //relative=victim->coords-oldcoords;
3559 relative = facing * -1;
3561 Normalise(&relative);
3562 relative = DoRotation(relative, 0, 90, 0);
3564 Normalise(&relative);
3565 for (i = 0; i < victim->skeleton.num_joints; i++) {
3566 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3568 victim->jointVel(head) += relative * damagemult * 200;
3571 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim))
3572 if (victim->damage > victim->damagetolerance && bonus != reverseko) {
3573 award_bonus(id, reverseko);
3579 if (frameTarget > animation[animCurrent].numframes - 1) {
3582 animTarget = getIdle();
3586 if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) {
3587 animTarget = rollanim;
3589 emit_sound_at(movewhooshsound, coords, 128.);
3591 if (animCurrent == staggerbackhighanim) {
3592 animTarget = getIdle();
3594 if (animCurrent == staggerbackhardanim) {
3595 animTarget = getIdle();
3597 if (animCurrent == removeknifeanim) {
3598 animTarget = getIdle();
3600 if (animCurrent == crouchremoveknifeanim) {
3601 animTarget = getCrouch();
3603 if (animCurrent == backhandspringanim) {
3604 animTarget = getIdle();
3606 if (animCurrent == dodgebackanim) {
3607 animTarget = getIdle();
3609 if (animCurrent == drawleftanim) {
3610 animTarget = getIdle();
3612 if (animCurrent == drawrightanim || animCurrent == crouchdrawrightanim) {
3613 animTarget = getIdle();
3614 if (animCurrent == crouchdrawrightanim) {
3615 animTarget = getCrouch();
3617 if (weaponactive == -1)
3619 else if (weaponactive == 0) {
3621 if (num_weapons == 2) {
3623 buffer = weaponids[0];
3624 weaponids[0] = weaponids[1];
3625 weaponids[1] = buffer;
3629 if (weaponactive == -1) {
3630 emit_sound_at(knifesheathesound, coords, 128.);
3632 if (weaponactive != -1) {
3633 emit_sound_at(knifedrawsound, coords, 128.);
3636 if (animCurrent == rollanim) {
3637 animTarget = getCrouch();
3642 if (animTarget == walljumprightkickanim) {
3645 if (animTarget == walljumpleftkickanim) {
3648 animTarget = jumpdownanim;
3650 if (animCurrent == climbanim) {
3651 animTarget = getCrouch();
3653 coords += facing * .1;
3654 if (!isnormal(coords.x))
3665 if (animTarget == rabbitkickreversalanim) {
3666 animTarget = getCrouch();
3669 if (animTarget == jumpreversalanim) {
3670 animTarget = getCrouch();
3673 if (animTarget == walljumprightanim || animTarget == walljumpbackanim || animTarget == walljumpfrontanim) {
3674 if (attackkeydown && animTarget != walljumpfrontanim) {
3676 float closestdist = -1;
3679 for (i = 0; i < numplayers; i++) {
3680 if (id != i && player[i].coords.y < coords.y && !player[i].skeleton.free) {
3681 distance = distsq(&player[i].coords, &coords);
3682 if (closestdist == -1 || distance < closestdist) {
3683 closestdist = distance;
3688 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3689 victim = &player[closest];
3690 animTarget = walljumprightkickanim;
3692 XYZ rotatetarget = victim->coords - coords;
3693 Normalise(&rotatetarget);
3694 yaw = -asin(0 - rotatetarget.x);
3696 if (rotatetarget.z < 0)
3698 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3699 velocity = (victim->coords - coords) * 4;
3704 if (animTarget == walljumpbackanim) {
3705 animTarget = backflipanim;
3707 velocity = facing * -8;
3710 resume_stream(whooshsound);
3712 if (animTarget == walljumprightanim) {
3713 animTarget = rightflipanim;
3717 velocity = DoRotation(facing, 0, 30, 0) * -8;
3720 if (animTarget == walljumpfrontanim) {
3721 animTarget = frontflipanim;
3725 velocity = facing * 8;
3729 resume_stream(whooshsound);
3731 if (animTarget == walljumpleftanim) {
3732 if (attackkeydown) {
3734 float closestdist = -1;
3737 for (i = 0; i < numplayers; i++) {
3738 if (id != i && player[i].coords.y < coords.y && !player[i].skeleton.free) {
3739 distance = distsq(&player[i].coords, &coords);
3740 if (closestdist == -1 || distance < closestdist) {
3741 closestdist = distance;
3746 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3747 victim = &player[closest];
3748 animTarget = walljumpleftkickanim;
3750 XYZ rotatetarget = victim->coords - coords;
3751 Normalise(&rotatetarget);
3752 yaw = -asin(0 - rotatetarget.x);
3754 if (rotatetarget.z < 0)
3756 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3757 velocity = (victim->coords - coords) * 4;
3762 if (animTarget != walljumpleftkickanim) {
3763 animTarget = leftflipanim;
3767 velocity = DoRotation(facing, 0, -30, 0) * -8;
3771 resume_stream(whooshsound);
3773 if (animTarget == sneakattackanim) {
3774 animCurrent = getCrouch();
3775 animTarget = getCrouch();
3782 transspeed = 1000000;
3783 targetheadyaw += 180;
3784 coords -= facing * .7;
3786 coords.y = terrain.getHeight(coords.x, coords.z);
3790 if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) {
3791 animTarget = getIdle();
3794 coords.y = terrain.getHeight(coords.x, coords.z);
3798 if (animCurrent == knifefollowanim) {
3799 animTarget = getIdle();
3802 if (animation[animTarget].attack == reversal && animCurrent != sneakattackanim && animCurrent != knifesneakattackanim && animCurrent != swordsneakattackanim && animCurrent != knifefollowanim) {
3803 float ycoords = oldcoords.y;
3804 animTarget = getStop();
3809 transspeed = 1000000;
3810 targetheadyaw += 180;
3811 if (!isnormal(coords.x))
3813 if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim)
3814 oldcoords = coords + facing * .5;
3815 else if (animCurrent == sweepreversalanim)
3816 oldcoords = coords + facing * 1.1;
3817 else if (animCurrent == upunchreversalanim) {
3818 oldcoords = coords + facing * 1.5;
3821 targetheadyaw += 180;
3824 } else if (animCurrent == knifeslashreversalanim) {
3825 oldcoords = coords + facing * .5;
3828 targetheadyaw += 90;
3831 } else if (animCurrent == staffspinhitreversalanim) {
3834 targetheadyaw += 180;
3839 oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z);
3841 oldcoords.y = ycoords;
3842 currentoffset = coords - oldcoords;
3848 if (animCurrent == knifesneakattackedanim || animCurrent == swordsneakattackedanim) {
3853 if (animation[animTarget].attack == reversed) {
3855 if (animTarget == sweepreversedanim)
3857 animTarget = backhandspringanim;
3859 emit_sound_at(landsound, coords, 128);
3861 if (animCurrent == upunchreversedanim || animCurrent == swordslashreversedanim) {
3862 animTarget = rollanim;
3865 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3866 coords.y = oldcoords.y;
3868 if (animCurrent == knifeslashreversedanim) {
3869 animTarget = rollanim;
3874 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3875 coords.y = oldcoords.y;
3879 animTarget = jumpdownanim;
3882 animTarget = getIdle();
3884 animTarget = getIdle();
3885 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
3886 animTarget = getIdle();
3888 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3889 coords.y = oldcoords.y;
3890 //coords+=DoRotation(animation[animCurrent].offset,0,yaw,0)*scale;
3891 targetoffset.y = coords.y;
3893 targetoffset.y = terrain.getHeight(coords.x, coords.z);
3894 currentoffset = DoRotation(animation[animCurrent].offset * -1, 0, yaw, 0) * scale;
3895 currentoffset.y -= (coords.y - targetoffset.y);
3896 coords.y = targetoffset.y;
3898 normalsupdatedelay = 0;
3900 if (animCurrent == upunchanim) {
3901 animTarget = getStop();
3902 normalsupdatedelay = 0;
3905 if (animCurrent == rabbitkickanim && animTarget != backflipanim) {
3909 if (num_weapons > 0)
3910 if (weapons[0].getType() == staff)
3916 rabbitkickragdoll = 1;
3918 if (animCurrent == rabbitkickreversedanim) {
3924 skeleton.spinny = 0;
3925 SolidHitBonus(!id); // FIXME: tricky id
3929 animTarget = rollanim;
3932 pause_sound(whooshsound);
3936 if (animCurrent == rabbittackledbackanim || animCurrent == rabbittackledfrontanim) {
3940 skeleton.spinny = 0;
3942 if (animCurrent == jumpreversedanim) {
3948 skeleton.spinny = 0;
3949 SolidHitBonus(!id); // FIXME: tricky id
3953 animTarget = rollanim;
3954 coords += facing * 2;
3956 pause_sound(whooshsound);
3961 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) {
3962 animTarget = getupfromfrontanim;
3964 } else if (animation[animCurrent].attack == normalattack) {
3965 animTarget = getIdle();
3968 if (animCurrent == blockhighleftanim && aitype != playercontrolled) {
3969 animTarget = blockhighleftstrikeanim;
3971 if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) {
3972 animTarget = getIdle();
3975 if (animCurrent == spinkickanim && victim->skeleton.free) {
3976 if (creature == rabbittype)
3977 animTarget = fightidleanim;
3982 if (isIdle() && !wasIdle())
3983 normalsupdatedelay = 0;
3985 if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) {
3986 animTarget = jumpdownanim;
3989 if (!skeleton.free) {
3991 if (!transspeed && animation[animTarget].attack != 2 && animation[animTarget].attack != 3) {
3992 if (!isRun() || !wasRun()) {
3993 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
3994 target += multiplier * animation[animTarget].speed[frameTarget] * speed * 2;
3995 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
3996 target += multiplier * animation[animCurrent].speed[frameCurrent] * speed * 2;
3998 if (isRun() && wasRun()) {
4000 tempspeed = velspeed;
4001 if (tempspeed < 10 * speedmult)
4002 tempspeed = 10 * speedmult;
4003 target += multiplier * animation[animTarget].speed[frameCurrent] * speed * 1.7 * tempspeed / (speed * 45 * scale);
4005 } else if (transspeed)
4006 target += multiplier * transspeed * speed * 2;
4008 if (!isRun() || !wasRun()) {
4009 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
4010 target += multiplier * animation[animTarget].speed[frameTarget] * 2;
4011 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
4012 target += multiplier * animation[animCurrent].speed[frameCurrent] * 2;
4016 if (animCurrent != animTarget)
4017 target = (target + oldtarget) / 2;
4020 frameCurrent = frameTarget;
4024 rot = targetrot * target;
4025 yaw += rot - oldrot;
4031 if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
4033 for (i = 0; i < skeleton.num_joints; i++) {
4034 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent];
4037 skeleton.FindForwards();
4039 for (i = 0; i < skeleton.num_muscles; i++) {
4040 if (skeleton.muscles[i].visible) {
4041 skeleton.FindRotationMuscle(i, animTarget);
4044 for (i = 0; i < skeleton.num_muscles; i++) {
4045 if (skeleton.muscles[i].visible) {
4046 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
4047 skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4048 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
4049 skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4050 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
4051 skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4056 for (i = 0; i < skeleton.num_joints; i++) {
4057 skeleton.joints[i].position = animation[animTarget].position[i][frameTarget];
4060 skeleton.FindForwards();
4062 for (i = 0; i < skeleton.num_muscles; i++) {
4063 if (skeleton.muscles[i].visible) {
4064 skeleton.FindRotationMuscle(i, animTarget);
4067 for (i = 0; i < skeleton.num_muscles; i++) {
4068 if (skeleton.muscles[i].visible) {
4069 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
4070 skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4071 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
4072 skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4073 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
4074 skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4075 if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) skeleton.muscles[i].newrotate3 -= 360;
4076 if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) skeleton.muscles[i].newrotate3 += 360;
4077 if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) skeleton.muscles[i].newrotate2 -= 360;
4078 if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) skeleton.muscles[i].newrotate2 += 360;
4079 if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) skeleton.muscles[i].newrotate1 -= 360;
4080 if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) skeleton.muscles[i].newrotate1 += 360;
4084 if (frameCurrent >= animation[animCurrent].numframes)
4085 frameCurrent = animation[animCurrent].numframes - 1;
4087 oldanimCurrent = animCurrent;
4088 oldanimTarget = animTarget;
4089 oldframeTarget = frameTarget;
4090 oldframeCurrent = frameCurrent;
4092 for (i = 0; i < skeleton.num_joints; i++) {
4093 skeleton.joints[i].velocity = (animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target) - skeleton.joints[i].position) / multiplier;
4094 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target);
4096 offset = currentoffset * (1 - target) + targetoffset * target;
4097 for (i = 0; i < skeleton.num_muscles; i++) {
4098 if (skeleton.muscles[i].visible) {
4099 skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * (target);
4100 skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * (target);
4101 skeleton.muscles[i].rotate3 = skeleton.muscles[i].oldrotate3 * (1 - target) + skeleton.muscles[i].newrotate3 * (target);
4106 if (isLanding() && landhard) {
4109 animTarget = getLandhard();
4116 //skeleton.DoConstraints();
4123 void Person::DoStuff()
4125 static XYZ terrainnormal;
4126 static XYZ flatfacing;
4127 static XYZ flatvelocity;
4128 static float flatvelspeed;
4132 static int bloodsize;
4133 static int startx, starty, endx, endy;
4134 static GLubyte color;
4135 static XYZ bloodvel;
4137 onfiredelay -= multiplier;
4138 if (onfiredelay < 0 && onfire) {
4139 if (Random() % 2 == 0) {
4145 crouchkeydowntime += multiplier;
4147 crouchkeydowntime = 0;
4148 jumpkeydowntime += multiplier;
4149 if (!jumpkeydown && skeleton.free)
4150 jumpkeydowntime = 0;
4152 if (hostile || damage > 0 || bloodloss > 0)
4155 if (isIdle() || isRun())
4158 if (num_weapons == 1 && weaponactive != -1)
4162 blooddimamount -= multiplier * .3;
4163 speechdelay -= multiplier;
4164 texupdatedelay -= multiplier;
4165 interestdelay -= multiplier;
4166 flamedelay -= multiplier;
4167 parriedrecently -= multiplier;
4174 speed = 1.1 * speedmult;
4176 speed = 1.0 * speedmult;
4178 rabbitkickragdoll = 0;
4182 if (id != 0 && (creature == rabbittype || difficulty != 2))
4184 if (id != 0 && creature == wolftype && difficulty == 2) {
4186 if (aitype != passivetype) {
4188 if (aitype == attacktypecutoff && (player[0].isIdle() || player[0].isCrouch() || player[0].skeleton.free || player[0].animTarget == getupfrombackanim || player[0].animTarget == getupfromfrontanim || player[0].animTarget == sneakanim) && distsq(&coords, &player[0].coords) < 16) {
4194 if (animTarget == wolfrunninganim && !superruntoggle) {
4195 animTarget = getRun();
4199 if (weaponactive == -1 && num_weapons > 0) {
4200 if (weapons[weaponids[0]].getType() == staff) {
4206 burnt += multiplier;
4207 /*if(aitype!=playercontrolled)*///deathbleeding=5;
4208 /*if(aitype!=playercontrolled)*/
4212 OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3);
4214 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
4220 vel[0] = velocity.x;
4221 vel[1] = velocity.y;
4222 vel[2] = velocity.z;
4225 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4226 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
4230 while (flamedelay < 0 && onfire) {
4232 howmany = abs(Random() % (skeleton.num_joints));
4234 flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4236 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4238 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4240 flatfacing = skeleton.joints[howmany].position * scale + coords;
4241 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
4244 while (flamedelay < 0 && !onfire && tutoriallevel == 1 && id != 0) {
4246 howmany = abs(Random() % (skeleton.num_joints));
4248 flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4250 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4252 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4254 flatfacing = skeleton.joints[howmany].position * scale + coords;
4255 Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
4259 bleeding -= multiplier * .3;
4260 if (bloodtoggle == 2) {
4261 skeleton.drawmodel.textureptr.bind();
4262 if (bleeding <= 0 && (detail != 2 || osx))
4267 if (neckspurtamount > 0) {
4268 neckspurtamount -= multiplier;
4269 neckspurtdelay -= multiplier * 3;
4270 neckspurtparticledelay -= multiplier * 3;
4271 if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
4274 if (!skeleton.free) {
4275 bloodvel.z = 5 * neckspurtamount;
4276 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4278 if (skeleton.free) {
4279 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
4282 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4284 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
4286 Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4288 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4289 neckspurtparticledelay = .05;
4291 if (neckspurtdelay < 0) {
4296 if (deathbleeding > 0 && dead != 2) {
4297 if (deathbleeding < 5)
4298 bleeddelay -= deathbleeding * multiplier / 4;
4300 bleeddelay -= 5 * multiplier / 4;
4301 if (bleeddelay < 0 && bloodtoggle) {
4307 bloodvel += DoRotation(jointVel(abdomen), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
4309 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
4311 Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4313 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
4316 bloodloss += deathbleeding * multiplier * 80;
4317 deathbleeding -= multiplier * 1.6;
4318 //if(id==0)deathbleeding-=multiplier*.2;
4319 if (deathbleeding < 0)
4321 if (bloodloss > damagetolerance && animation[animTarget].attack == neutral) {
4322 if (weaponactive != -1) {
4323 weapons[weaponids[0]].owner = -1;
4324 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4325 weapons[weaponids[0]].velocity.x += .01;
4326 weapons[weaponids[0]].tipvelocity = velocity * scale;
4327 weapons[weaponids[0]].missed = 1;
4328 weapons[weaponids[0]].hitsomething = 0;
4329 weapons[weaponids[0]].freetime = 0;
4330 weapons[weaponids[0]].firstfree = 1;
4331 weapons[weaponids[0]].physics = 1;
4334 weaponids[0] = weaponids[num_weapons];
4335 if (weaponstuck == num_weapons)
4339 for (i = 0; i < numplayers; i++) {
4340 player[i].wentforweapon = 0;
4352 if (!dead && creature == wolftype) {
4353 award_bonus(0, Wolfbonus);
4356 if (animTarget == knifefollowedanim && !skeleton.free) {
4357 for (i = 0; i < skeleton.num_joints; i++) {
4358 skeleton.joints[i].velocity = 0;
4359 skeleton.joints[i].velocity.y = -2;
4362 if (id != 0 && unconscioustime > .1) {
4370 if (texupdatedelay < 0 && bleeding > 0 && bloodtoggle == 2 && distsq(&viewer, &coords) < 9) {
4371 texupdatedelay = .12;
4373 bloodsize = 5 - realtexdetail;
4377 startx = bleedy; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4378 starty = bleedx; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4379 endx = startx + bloodsize;
4380 endy = starty + bloodsize;
4390 if (endx > skeleton.skinsize - 1) {
4391 endx = skeleton.skinsize - 1;
4394 if (endy > skeleton.skinsize - 1) {
4395 endy = skeleton.skinsize - 1;
4403 for (i = startx; i < endx; i++) {
4404 for (j = starty; j < endy; j++) {
4405 if (Random() % 2 == 0) {
4406 color = Random() % 85 + 170;
4407 if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2)
4408 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2;
4409 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0;
4410 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0;
4414 if (!osx && detail > 1) {
4415 skeleton.drawmodel.textureptr.bind();
4419 if (!skeleton.free) {
4420 bleedy -= 4 / realtexdetail;
4422 bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4424 bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4426 if (skeleton.free) {
4427 bleedx += 4 * direction / realtexdetail;
4429 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4431 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4435 if (abs(righthandmorphness - targetrighthandmorphness) < multiplier * 4) {
4436 righthandmorphness = targetrighthandmorphness;
4437 righthandmorphstart = righthandmorphend;
4438 } else if (righthandmorphness > targetrighthandmorphness) {
4439 righthandmorphness -= multiplier * 4;
4440 } else if (righthandmorphness < targetrighthandmorphness) {
4441 righthandmorphness += multiplier * 4;
4444 if (abs(lefthandmorphness - targetlefthandmorphness) < multiplier * 4) {
4445 lefthandmorphness = targetlefthandmorphness;
4446 lefthandmorphstart = lefthandmorphend;
4447 } else if (lefthandmorphness > targetlefthandmorphness) {
4448 lefthandmorphness -= multiplier * 4;
4449 } else if (lefthandmorphness < targetlefthandmorphness) {
4450 lefthandmorphness += multiplier * 4;
4453 if (creature == rabbittype || targettailmorphness == 5 || targettailmorphness == 0) {
4454 if (abs(tailmorphness - targettailmorphness) < multiplier * 10) {
4455 tailmorphness = targettailmorphness;
4456 tailmorphstart = tailmorphend;
4457 } else if (tailmorphness > targettailmorphness) {
4458 tailmorphness -= multiplier * 10;
4459 } else if (tailmorphness < targettailmorphness) {
4460 tailmorphness += multiplier * 10;
4464 if (creature == wolftype) {
4465 if (abs(tailmorphness - targettailmorphness) < multiplier * 4) {
4466 tailmorphness = targettailmorphness;
4467 tailmorphstart = tailmorphend;
4468 } else if (tailmorphness > targettailmorphness) {
4469 tailmorphness -= multiplier * 2;
4470 } else if (tailmorphness < targettailmorphness) {
4471 tailmorphness += multiplier * 2;
4475 if (headmorphend == 3 || headmorphstart == 3) {
4476 if (abs(headmorphness - targetheadmorphness) < multiplier * 7) {
4477 headmorphness = targetheadmorphness;
4478 headmorphstart = headmorphend;
4479 } else if (headmorphness > targetheadmorphness) {
4480 headmorphness -= multiplier * 7;
4481 } else if (headmorphness < targetheadmorphness) {
4482 headmorphness += multiplier * 7;
4484 } else if (headmorphend == 5 || headmorphstart == 5) {
4485 if (abs(headmorphness - targetheadmorphness) < multiplier * 10) {
4486 headmorphness = targetheadmorphness;
4487 headmorphstart = headmorphend;
4488 } else if (headmorphness > targetheadmorphness) {
4489 headmorphness -= multiplier * 10;
4490 } else if (headmorphness < targetheadmorphness) {
4491 headmorphness += multiplier * 10;
4494 if (abs(headmorphness - targetheadmorphness) < multiplier * 4) {
4495 headmorphness = targetheadmorphness;
4496 headmorphstart = headmorphend;
4497 } else if (headmorphness > targetheadmorphness) {
4498 headmorphness -= multiplier * 4;
4499 } else if (headmorphness < targetheadmorphness) {
4500 headmorphness += multiplier * 4;
4504 if (abs(chestmorphness - targetchestmorphness) < multiplier) {
4505 chestmorphness = targetchestmorphness;
4506 chestmorphstart = chestmorphend;
4507 } else if (chestmorphness > targetchestmorphness) {
4508 chestmorphness -= multiplier;
4509 } else if (chestmorphness < targetchestmorphness) {
4510 chestmorphness += multiplier;
4513 if (dead != 2 && howactive <= typesleeping) {
4514 if (chestmorphstart == 0 && chestmorphend == 0) {
4516 targetchestmorphness = 1;
4519 if (chestmorphstart != 0 && chestmorphend != 0) {
4521 targetchestmorphness = 1;
4523 if (environment == snowyenvironment) {
4527 footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
4529 footvel = skeleton.specialforward[0] * -1;
4531 footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
4533 footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
4534 if (animTarget == sleepanim)
4535 footvel = DoRotation(footvel, 0, 90, 0);
4536 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
4540 if (!dead && howactive < typesleeping) {
4541 blinkdelay -= multiplier * 2;
4542 if (headmorphstart == 0 && headmorphend == 0 && blinkdelay <= 0) {
4544 targetheadmorphness = 1;
4546 blinkdelay = (float)(abs(Random() % 40)) / 5;
4548 if (headmorphstart == 3 && headmorphend == 3) {
4550 targetheadmorphness = 1;
4555 twitchdelay -= multiplier * 1.5;
4556 if (animTarget != hurtidleanim) {
4557 if (headmorphstart == 0 && headmorphend == 0 && twitchdelay <= 0) {
4559 targetheadmorphness = 1;
4561 twitchdelay = (float)(abs(Random() % 40)) / 5;
4563 if (headmorphstart == 5 && headmorphend == 5) {
4565 targetheadmorphness = 1;
4569 if ((isIdle() || isCrouch()) && animTarget != hurtidleanim) {
4570 twitchdelay3 -= multiplier * 1;
4571 if (Random() % 2 == 0) {
4572 if (righthandmorphstart == 0 && righthandmorphend == 0 && twitchdelay3 <= 0) {
4573 righthandmorphness = 0;
4574 targetrighthandmorphness = 1;
4575 righthandmorphend = 1;
4576 if (Random() % 2 == 0)twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4578 if (righthandmorphstart == 1 && righthandmorphend == 1) {
4579 righthandmorphness = 0;
4580 targetrighthandmorphness = 1;
4581 righthandmorphend = 0;
4584 if (Random() % 2 == 0) {
4585 if (lefthandmorphstart == 0 && lefthandmorphend == 0 && twitchdelay3 <= 0) {
4586 lefthandmorphness = 0;
4587 targetlefthandmorphness = 1;
4588 lefthandmorphend = 1;
4589 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4591 if (lefthandmorphstart == 1 && lefthandmorphend == 1) {
4592 lefthandmorphness = 0;
4593 targetlefthandmorphness = 1;
4594 lefthandmorphend = 0;
4600 if (creature == rabbittype) {
4601 if (howactive < typesleeping)
4602 twitchdelay2 -= multiplier * 1.5;
4604 twitchdelay2 -= multiplier * 0.5;
4605 if (howactive <= typesleeping) {
4606 if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) {
4608 targettailmorphness = 1;
4610 twitchdelay2 = (float)(abs(Random() % 40)) / 5;
4612 if (tailmorphstart == 1 && tailmorphend == 1) {
4614 targettailmorphness = 1;
4617 if (tailmorphstart == 2 && tailmorphend == 2) {
4619 targettailmorphness = 1;
4626 if (creature == wolftype) {
4627 twitchdelay2 -= multiplier * 1.5;
4628 if (tailmorphend != 0)
4629 if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) {
4631 targettailmorphness = 1;
4635 if (tailmorphend != 5)
4636 if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) {
4638 targettailmorphness = 1;
4642 if (twitchdelay2 <= 0) {
4643 if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) {
4645 targettailmorphness = 1;
4648 if (tailmorphstart == 1 && tailmorphend == 1) {
4650 targettailmorphness = 1;
4653 if (tailmorphstart == 2 && tailmorphend == 2) {
4655 targettailmorphness = 1;
4658 if (tailmorphstart == 3 && tailmorphend == 3) {
4660 targettailmorphness = 1;
4663 if (tailmorphstart == 4 && tailmorphend == 4) {
4665 targettailmorphness = 1;
4672 unconscioustime = 0;
4674 if (dead == 1 || howactive == typesleeping) {
4675 unconscioustime += multiplier;
4676 //If unconscious, close eyes and mouth
4677 if (righthandmorphend != 0)
4678 righthandmorphness = 0;
4679 righthandmorphend = 0;
4680 targetrighthandmorphness = 1;
4682 if (lefthandmorphend != 0)
4683 lefthandmorphness = 0;
4684 lefthandmorphend = 0;
4685 targetlefthandmorphness = 1;
4687 if (headmorphend != 3 && headmorphend != 5)
4690 targetheadmorphness = 1;
4694 if (howactive > typesleeping) {
4697 if (bloodtoggle && !bled) {
4698 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4700 if (bloodtoggle && !bled)
4701 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4702 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4703 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4707 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4712 if (dead == 2 || howactive > typesleeping) {
4713 //If dead, open mouth and hands
4714 if (righthandmorphend != 0)
4715 righthandmorphness = 0;
4716 righthandmorphend = 0;
4717 targetrighthandmorphness = 1;
4719 if (lefthandmorphend != 0)
4720 lefthandmorphness = 0;
4721 lefthandmorphend = 0;
4722 targetlefthandmorphness = 1;
4724 if (headmorphend != 2)
4727 targetheadmorphness = 1;
4730 if (stunned > 0 && !dead && headmorphend != 2) {
4731 if (headmorphend != 4)
4734 targetheadmorphness = 1;
4737 if (damage > damagetolerance && !dead) {
4740 unconscioustime = 0;
4742 if (creature == wolftype) {
4743 award_bonus(0, Wolfbonus);
4748 if (weaponactive != -1) {
4749 weapons[weaponids[0]].owner = -1;
4750 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4751 weapons[weaponids[0]].velocity.x += .01;
4752 weapons[weaponids[0]].tipvelocity = velocity * scale;
4753 weapons[weaponids[0]].missed = 1;
4754 weapons[weaponids[0]].hitsomething = 0;
4755 weapons[weaponids[0]].freetime = 0;
4756 weapons[weaponids[0]].firstfree = 1;
4757 weapons[weaponids[0]].physics = 1;
4760 weaponids[0] = weaponids[num_weapons];
4761 if (weaponstuck == num_weapons)
4765 for (i = 0; i < numplayers; i++) {
4766 player[i].wentforweapon = 0;
4772 if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) {
4780 //if(dead)damage-=multiplier/4;
4782 damage -= multiplier * 13;
4783 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4785 permanentdamage -= multiplier * 4;
4786 if (isIdle() || isCrouch()) {
4788 permanentdamage -= multiplier * 4;
4789 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4793 if (permanentdamage < 0)
4794 permanentdamage = 0;
4795 if (superpermanentdamage < 0)
4796 superpermanentdamage = 0;
4797 if (permanentdamage < superpermanentdamage) {
4798 permanentdamage = superpermanentdamage;
4800 if (damage < permanentdamage) {
4801 damage = permanentdamage;
4803 if (dead == 1 && damage < damagetolerance) {
4807 for (i = 0; i < skeleton.num_joints; i++) {
4808 skeleton.joints[i].velocity = 0;
4811 if (permanentdamage > damagetolerance && dead != 2) {
4814 if (weaponactive != -1) {
4815 weapons[weaponids[0]].owner = -1;
4816 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4817 weapons[weaponids[0]].velocity.x += .01;
4818 weapons[weaponids[0]].tipvelocity = velocity * scale;
4819 weapons[weaponids[0]].missed = 1;
4820 weapons[weaponids[0]].hitsomething = 0;
4821 weapons[weaponids[0]].freetime = 0;
4822 weapons[weaponids[0]].firstfree = 1;
4823 weapons[weaponids[0]].physics = 1;
4826 weaponids[0] = weaponids[num_weapons];
4827 if (weaponstuck == num_weapons)
4831 for (i = 0; i < numplayers; i++) {
4832 player[i].wentforweapon = 0;
4838 if (!dead && creature == wolftype) {
4839 award_bonus(0, Wolfbonus);
4842 if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance)
4843 award_bonus(id, touchofdeath);
4844 if (id != 0 && unconscioustime > .1) {
4852 emit_sound_at(breaksound, coords);
4855 if (skeleton.free == 1) {
4857 pause_sound(whooshsound);
4860 //If knocked over, open hands and close mouth
4861 if (righthandmorphend != 0)
4862 righthandmorphness = 0;
4863 righthandmorphend = 0;
4864 targetrighthandmorphness = 1;
4866 if (lefthandmorphend != 0)
4867 lefthandmorphness = 0;
4868 lefthandmorphend = 0;
4869 targetlefthandmorphness = 1;
4871 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) {
4872 if (headmorphend != 0)
4875 targetheadmorphness = 1;
4879 skeleton.DoGravity(&scale);
4881 damageamount = skeleton.DoConstraints(&coords, &scale) * 5;
4882 if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1))
4883 award_bonus(id, deepimpact);
4884 DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3));
4888 for (j = 0; j < skeleton.num_joints; j++) {
4889 average += skeleton.joints[j].position;
4893 coords += average * scale;
4894 for (j = 0; j < skeleton.num_joints; j++) {
4895 skeleton.joints[j].position -= average;
4897 average /= multiplier;
4899 //velocity=jointVel(groin)*scale;
4901 for (i = 0; i < skeleton.num_joints; i++) {
4902 velocity += skeleton.joints[i].velocity * scale;
4904 velocity /= skeleton.num_joints;
4906 if (!isnormal(velocity.x) && velocity.x) {
4910 if (findLength(&average) < 10 && dead && skeleton.free) {
4911 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
4912 if (skeleton.longdead > 2000) {
4913 if (skeleton.longdead > 6000) {
4915 pause_sound(whooshsound);
4920 if (dead == 2 && bloodloss < damagetolerance) {
4922 headpoint = (jointPos(head) + jointPos(neck)) / 2 * scale + coords;
4924 if (bloodtoggle && !bled) {
4925 terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
4927 if (bloodtoggle && !bled)
4928 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4929 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4930 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4931 float size = .2 * 1.2;
4934 objects.model[j].MakeDecal(blooddecal, &point, &size, &opacity, &yaw);
4938 if (dead == 2 && bloodloss >= damagetolerance) {
4940 headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords;
4943 if (bloodtoggle && !bled) {
4944 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4946 if (bloodtoggle && !bled)
4947 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4948 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4949 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4953 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4960 if (!dead && crouchkeydown && skeleton.freetime > .5 && id == 0 && skeleton.free) {
4961 bool canrecover = 1;
4962 XYZ startpoint, endpoint, colpoint, colviewer, coltarget;
4963 startpoint = coords;
4966 if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1)
4968 if (velocity.y < -30)
4970 for (i = 0; i < objects.numobjects; i++) {
4971 if (objects.type[i] != treeleavestype && objects.type[i] != bushtype && objects.type[i] != firetype) {
4972 colviewer = startpoint;
4973 coltarget = endpoint;
4974 if (objects.model[i].LineCheck(&colviewer, &coltarget, &colpoint, &objects.position[i], &objects.yaw[i]) != -1)
4983 terrainnormal = jointPos(groin) - jointPos(abdomen);
4984 if (joint(groin).locked && joint(abdomen).locked) {
4985 terrainnormal = jointPos(groin) - jointPos(abdomen);
4986 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
4988 if (joint(abdomen).locked && joint(neck).locked) {
4989 terrainnormal = jointPos(abdomen) - jointPos(neck);
4990 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
4992 if (joint(groin).locked && joint(neck).locked) {
4993 terrainnormal = jointPos(groin) - jointPos(neck);
4994 middle = (jointPos(groin) + jointPos(neck)) / 2;
4996 Normalise(&terrainnormal);
4998 targetyaw = -asin(0 - terrainnormal.x);
4999 targetyaw *= 360 / 6.28;
5000 if (terrainnormal.z < 0)
5001 targetyaw = 180 - targetyaw;
5006 animTarget = flipanim;
5007 crouchtogglekeydown = 1;
5012 animCurrent = tempanim;
5015 //tilt2=targettilt2;
5017 //if(middle.y>0)targetoffset.y=middle.y+1;
5019 for (i = 0; i < skeleton.num_joints; i++) {
5020 tempanimation.position[i][0] = skeleton.joints[i].position;
5021 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
5026 if (findLength(&average) < 10 && !dead && skeleton.free) {
5027 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
5028 if (skeleton.longdead > (damage + 500) * 1.5) {
5030 pause_sound(whooshsound);
5036 terrainnormal = jointPos(groin) - jointPos(abdomen);
5037 if (joint(groin).locked && joint(abdomen).locked) {
5038 terrainnormal = jointPos(groin) - jointPos(abdomen);
5039 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
5041 if (joint(abdomen).locked && joint(neck).locked) {
5042 terrainnormal = jointPos(abdomen) - jointPos(neck);
5043 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
5045 if (joint(groin).locked && joint(neck).locked) {
5046 terrainnormal = jointPos(groin) - jointPos(neck);
5047 middle = (jointPos(groin) + jointPos(neck)) / 2;
5049 Normalise(&terrainnormal);
5051 targetyaw = -asin(0 - terrainnormal.x);
5052 targetyaw *= 360 / 6.28;
5053 if (terrainnormal.z < 0)
5054 targetyaw = 180 - targetyaw;
5057 targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1;
5060 if (skeleton.forward.y < 0) {
5061 animTarget = getupfrombackanim;
5065 if (skeleton.forward.y > -.3) {
5066 animTarget = getupfromfrontanim;
5074 if ((Random() % 8 == 0 && id != 0 && creature == rabbittype) || (Random() % 2 == 0 && id != 0 && creature == wolftype) || (id == 0 && crouchkeydown && (forwardkeydown || backkeydown || leftkeydown || rightkeydown))) {
5075 animTarget = rollanim;
5076 targetyaw = lookyaw;
5093 if ( !leftkeydown && !rightkeydown)
5100 if (abs(targettilt2) > 50)
5102 animCurrent = tempanim;
5105 tilt2 = targettilt2;
5107 if (middle.y > 0 && animTarget != rollanim)
5108 targetoffset.y = middle.y + 1;
5110 for (i = 0; i < skeleton.num_joints; i++) {
5111 tempanimation.position[i][0] = skeleton.joints[i].position;
5112 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
5119 if (num_weapons > 0)
5120 if (weapons[0].getType() == staff)
5122 if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) {
5123 if (velocity.y > -30) {
5125 tempvelocity = velocity;
5126 Normalise(&tempvelocity);
5127 targetyaw = -asin(0 - tempvelocity.x);
5128 targetyaw *= 360 / 6.28;
5130 targetyaw = 180 - targetyaw;
5134 if (dotproduct(&skeleton.forward, &tempvelocity) < 0) {
5135 animTarget = rollanim;
5138 animTarget = backhandspringanim;
5144 emit_sound_at(movewhooshsound, coords, 128.);
5146 animCurrent = animTarget;
5147 frameCurrent = frameTarget - 1;
5159 if (skeleton.freefall == 0)
5164 if (aitype != passivetype || skeleton.free == 1)
5165 if (findLengthfast(&velocity) > .1)
5166 for (i = 0; i < objects.numobjects; i++) {
5167 if (objects.type[i] == firetype)
5168 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) {
5170 if (!objects.onfire[i]) {
5171 emit_sound_at(firestartsound, objects.position[i]);
5173 objects.onfire[i] = 1;
5176 if (objects.onfire[i]) {
5181 if (objects.type[i] == bushtype)
5182 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) {
5184 if (!objects.onfire[i]) {
5185 emit_sound_at(firestartsound, objects.position[i]);
5187 objects.onfire[i] = 1;
5191 if (objects.onfire[i]) {
5195 if (objects.messedwith[i] <= 0) {
5199 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5202 envsound[numenvsounds] = coords;
5203 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5204 envsoundlife[numenvsounds] = .4;
5209 if (environment == grassyenvironment)
5210 howmany = findLength(&velocity) * 4;
5211 if (environment == snowyenvironment)
5212 howmany = findLength(&velocity) * 2;
5214 if (environment != desertenvironment)
5215 for (j = 0; j < howmany; j++) {
5216 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5217 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5218 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5221 pos.x += float(abs(Random() % 100) - 50) / 200;
5222 pos.y += float(abs(Random() % 100) - 50) / 200;
5223 pos.z += float(abs(Random() % 100) - 50) / 200;
5224 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);
5225 Sprite::setLastSpriteSpecial(1);
5227 howmany = findLength(&velocity) * 4;
5229 if (environment == snowyenvironment)
5230 for (j = 0; j < howmany; j++) {
5231 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5232 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5233 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5236 pos.x += float(abs(Random() % 100) - 50) / 200;
5237 pos.y += float(abs(Random() % 100) - 50) / 200;
5238 pos.z += float(abs(Random() % 100) - 50) / 200;
5239 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5240 Sprite::setLastSpriteSpecial(2);
5243 objects.rotx[i] += velocity.x * multiplier * 6;
5244 objects.roty[i] += velocity.z * multiplier * 6;
5245 objects.messedwith[i] = .5;
5248 if (objects.type[i] == treeleavestype && environment != desertenvironment) {
5249 if (objects.pitch[i] == 0)
5252 tempcoord = coords - objects.position[i];
5253 tempcoord = DoRotation(tempcoord, 0, -objects.yaw[i], 0);
5254 tempcoord = DoRotation(tempcoord, -objects.pitch[i], 0, 0);
5255 tempcoord += objects.position[i];
5257 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]) {
5258 if (objects.messedwith[i] <= 0) {
5262 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5265 envsound[numenvsounds] = coords;
5266 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5267 envsoundlife[numenvsounds] = .4;
5272 if (environment == grassyenvironment)
5273 howmany = findLength(&velocity) * 4;
5274 if (environment == snowyenvironment)
5275 howmany = findLength(&velocity) * 2;
5277 if (environment != desertenvironment)
5278 for (j = 0; j < howmany; j++) {
5279 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5280 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5281 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5283 pos += velocity * .1;
5285 pos.x += float(abs(Random() % 100) - 50) / 150;
5286 pos.y += float(abs(Random() % 100) - 50) / 150;
5287 pos.z += float(abs(Random() % 100) - 50) / 150;
5288 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);
5289 Sprite::setLastSpriteSpecial(1);
5291 howmany = findLength(&velocity) * 4;
5293 if (environment == snowyenvironment)
5294 for (j = 0; j < howmany; j++) {
5295 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5296 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5297 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5299 pos += velocity * .1;
5301 pos.x += float(abs(Random() % 100) - 50) / 150;
5302 pos.y += float(abs(Random() % 100) - 50) / 150;
5303 pos.z += float(abs(Random() % 100) - 50) / 150;
5304 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5305 Sprite::setLastSpriteSpecial(2);
5308 objects.messedwith[i] = .5;
5313 if (!skeleton.free) {
5316 if ((stunned > 0 || surprised > 0) && numplayers > 2 && aitype != passivetype)
5319 if (aitype != passivetype && victim->skeleton.free && !victim->dead)
5321 if (tutoriallevel == 1 && id != 0)
5323 if (play && aitype != playercontrolled) {
5324 int whichsound = -1;
5325 i = abs(Random() % 4);
5326 if (speechdelay <= 0) {
5327 if (creature == rabbittype) {
5329 whichsound = rabbitchitter;
5331 whichsound = rabbitchitter2;
5333 if (creature == wolftype) {
5335 whichsound = growlsound;
5337 whichsound = growl2sound;
5342 if (whichsound != -1) {
5343 emit_sound_at(whichsound, coords);
5347 if (animTarget == staggerbackhighanim)
5349 if (animTarget == staggerbackhardanim)
5351 staggerdelay -= multiplier;
5352 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
5354 if (velocity.y < -30 && animTarget == jumpdownanim)
5356 if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) {
5357 animTarget = getIdle();
5361 weaponmissdelay -= multiplier;
5362 highreversaldelay -= multiplier;
5363 lowreversaldelay -= multiplier;
5364 lastcollide -= multiplier;
5365 skiddelay -= multiplier;
5366 if (!isnormal(velocity.x) && velocity.x) {
5369 if (!isnormal(targettilt) && targettilt) {
5372 if (!isnormal(targettilt2) && targettilt2) {
5375 if (!isnormal(targetyaw) && targetyaw) {
5379 if (animTarget == bounceidleanim || animTarget == wolfidle || animTarget == walkanim || animTarget == drawrightanim || animTarget == crouchdrawrightanim || animTarget == drawleftanim || animTarget == fightidleanim || animTarget == fightsidestep || animTarget == hanganim || isCrouch() || animTarget == backhandspringanim) {
5380 //open hands and close mouth
5381 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5382 righthandmorphness = 0;
5383 righthandmorphend = 0;
5384 targetrighthandmorphness = 1;
5387 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5388 lefthandmorphness = 0;
5389 lefthandmorphend = 0;
5390 targetlefthandmorphness = 1;
5393 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5 && headmorphend != 0 && headmorphness == targetheadmorphness) {
5396 targetheadmorphness = 1;
5400 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) {
5401 //open hands and mouth
5402 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5403 righthandmorphness = 0;
5404 righthandmorphend = 0;
5405 targetrighthandmorphness = 1;
5408 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5409 lefthandmorphness = 0;
5410 lefthandmorphend = 0;
5411 targetlefthandmorphness = 1;
5414 if (headmorphend != 1 && headmorphness == targetheadmorphness) {
5417 targetheadmorphness = 1;
5421 if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim || animTarget == blockhighleftanim) {
5422 //close hands and mouth
5423 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5424 righthandmorphness = 0;
5425 righthandmorphend = 1;
5426 targetrighthandmorphness = 1;
5429 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5430 lefthandmorphness = 0;
5431 lefthandmorphend = 1;
5432 targetlefthandmorphness = 1;
5435 if (headmorphend != 0 && headmorphness == targetheadmorphness) {
5438 targetheadmorphness = 1;
5442 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) {
5443 //close hands and yell
5444 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5445 righthandmorphness = 0;
5446 righthandmorphend = 1;
5447 targetrighthandmorphness = 1;
5450 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5451 lefthandmorphness = 0;
5452 lefthandmorphend = 1;
5453 targetlefthandmorphness = 1;
5456 if (headmorphend != 2 && headmorphness == targetheadmorphness) {
5459 targetheadmorphness = 1;
5466 if (victim != this && !victim->dead && victim->aitype != passivetype && victim->aitype != searchtype && aitype != passivetype && aitype != searchtype && victim->id < numplayers && aitype != passivetype) {
5467 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
5471 if (!dead && animTarget != hurtidleanim)
5472 if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) {
5473 if (headmorphend != 4 || headmorphness == targetheadmorphness) {
5476 targetheadmorphness = 1;
5480 if (weaponactive != -1) {
5481 if (weapons[weaponids[weaponactive]].getType() != staff) {
5482 righthandmorphstart = 1;
5483 righthandmorphend = 1;
5485 if (weapons[weaponids[weaponactive]].getType() == staff) {
5486 righthandmorphstart = 2;
5487 righthandmorphend = 2;
5489 targetrighthandmorphness = 1;
5492 terrainnormal = terrain.getNormal(coords.x, coords.z);
5494 if (animation[animTarget].attack != reversal) {
5495 if (!isnormal(coords.x))
5503 flatfacing = DoRotation(flatfacing, 0, yaw, 0);
5504 facing = flatfacing;
5505 ReflectVector(&facing, terrainnormal);
5508 if (isRun() || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) {
5510 targettilt2 = -facing.y * 20;
5515 if (!isRun() && !animation[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim)
5517 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5518 flatvelocity = velocity;
5520 flatvelspeed = findLength(&flatvelocity);
5521 targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity);
5522 targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity);
5527 if (targettilt > 25)
5529 if (targettilt < -25)
5533 if (targettilt2 > 45)
5535 if (targettilt2 < -45)
5537 if (abs(tilt2 - targettilt2) < multiplier * 400)
5538 tilt2 = targettilt2;
5539 else if (tilt2 > targettilt2) {
5540 tilt2 -= multiplier * 400;
5541 } else if (tilt2 < targettilt2) {
5542 tilt2 += multiplier * 400;
5544 if (!animation[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) {
5551 if (!isnormal(targettilt) && targettilt) {
5554 if (!isnormal(targettilt2) && targettilt2) {
5559 //if(!creature==wolftype||animTarget==rabbitkickanim)
5560 if (animTarget == rabbittackleanim) {
5561 velocity += facing * multiplier * speed * 700 * scale;
5562 velspeed = findLength(&velocity);
5563 if (velspeed > speed * 65 * scale) {
5564 velocity /= velspeed;
5565 velspeed = speed * 65 * scale;
5566 velocity *= velspeed;
5568 velocity.y += gravity * multiplier * 20;
5569 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5570 velspeed = findLength(&velocity);
5571 velocity = flatfacing * velspeed;
5573 if (animTarget != rabbitrunninganim && animTarget != wolfrunninganim) {
5574 if (isRun() || animTarget == rabbitkickanim) {
5575 velocity += facing * multiplier * speed * 700 * scale;
5576 velspeed = findLength(&velocity);
5577 if (velspeed > speed * 45 * scale) {
5578 velocity /= velspeed;
5579 velspeed = speed * 45 * scale;
5580 velocity *= velspeed;
5582 velocity.y += gravity * multiplier * 20;
5583 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5584 velspeed = findLength(&velocity);
5585 if (velspeed < speed * 30 * scale)
5586 velspeed = speed * 30 * scale;
5587 velocity = flatfacing * velspeed;
5589 } else if (isRun()) {
5590 velocity += facing * multiplier * speed * 700 * scale;
5591 velspeed = findLength(&velocity);
5592 if (creature == rabbittype) {
5593 if (velspeed > speed * 55 * scale) {
5594 velocity /= velspeed;
5595 velspeed = speed * 55 * scale;
5596 velocity *= velspeed;
5599 if (creature == wolftype) {
5600 if (velspeed > speed * 75 * scale) {
5601 velocity /= velspeed;
5602 velspeed = speed * 75 * scale;
5603 velocity *= velspeed;
5606 velocity.y += gravity * multiplier * 20;
5607 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5608 velspeed = findLength(&velocity);
5609 velocity = flatfacing * velspeed;
5612 if (animTarget == rollanim && animation[animTarget].label[frameTarget] != 6) {
5613 velocity += facing * multiplier * speed * 700 * scale;
5614 velspeed = findLength(&velocity);
5615 if (velspeed > speed * 45 * scale) {
5616 velocity /= velspeed;
5617 velspeed = speed * 45 * scale;
5618 velocity *= velspeed;
5620 velocity.y += gravity * multiplier * 20;
5621 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5622 velspeed = findLength(&velocity);
5623 velocity = flatfacing * velspeed;
5627 /*if(animCurrent==rollanim&&(isCrouch()||isIdle())){
5628 velocity+=facing*multiplier*speed*700*scale;
5629 velspeed=findLength(&velocity);
5630 if(velspeed>speed*25*scale){
5632 velspeed=speed*25*scale;
5635 velocity.y+=gravity*multiplier*20;
5636 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5637 velspeed=findLength(&velocity);
5638 velocity=flatfacing*velspeed;
5641 if (animTarget == sneakanim || animTarget == walkanim) {
5642 velocity += facing * multiplier * speed * 700 * scale;
5643 velspeed = findLength(&velocity);
5644 if (velspeed > speed * 12 * scale) {
5645 velocity /= velspeed;
5646 velspeed = speed * 12 * scale;
5647 velocity *= velspeed;
5649 velocity.y += gravity * multiplier * 20;
5650 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5651 velspeed = findLength(&velocity);
5652 velocity = flatfacing * velspeed;
5655 if ((animTarget == fightidleanim || animTarget == knifefightidleanim) && (animCurrent == bounceidleanim || animCurrent == hurtidleanim)) {
5656 velocity += facing * multiplier * speed * 700 * scale;
5657 velspeed = findLength(&velocity);
5658 if (velspeed > speed * 2 * scale) {
5659 velocity /= velspeed;
5660 velspeed = speed * 2 * scale;
5661 velocity *= velspeed;
5663 velocity.y += gravity * multiplier * 20;
5664 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5665 velspeed = findLength(&velocity);
5666 velocity = flatfacing * velspeed;
5670 if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) {
5671 velocity -= facing * multiplier * speed * 700 * scale;
5672 velspeed = findLength(&velocity);
5673 if (velspeed > speed * 2 * scale) {
5674 velocity /= velspeed;
5675 velspeed = speed * 2 * scale;
5676 velocity *= velspeed;
5678 velocity.y += gravity * multiplier * 20;
5679 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5680 velspeed = findLength(&velocity);
5681 velocity = flatfacing * velspeed * -1;
5684 if (animTarget == fightsidestep) {
5685 velocity += DoRotation(facing * multiplier * speed * 700 * scale, 0, -90, 0);
5686 velspeed = findLength(&velocity);
5687 if (velspeed > speed * 12 * scale) {
5688 velocity /= velspeed;
5689 velspeed = speed * 12 * scale;
5690 velocity *= velspeed;
5692 velocity.y += gravity * multiplier * 20;
5693 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5694 velspeed = findLength(&velocity);
5695 velocity = DoRotation(flatfacing * velspeed, 0, -90, 0);
5698 if (animTarget == staggerbackhighanim) {
5699 coords -= facing * multiplier * speed * 16 * scale;
5702 if (animTarget == staggerbackhardanim && animation[staggerbackhardanim].label[frameTarget] != 6) {
5703 coords -= facing * multiplier * speed * 20 * scale;
5707 if (animTarget == backhandspringanim) {
5708 //coords-=facing*multiplier*50*scale;
5709 velocity += facing * multiplier * speed * 700 * scale * -1;
5710 velspeed = findLength(&velocity);
5711 if (velspeed > speed * 50 * scale) {
5712 velocity /= velspeed;
5713 velspeed = speed * 50 * scale;
5714 velocity *= velspeed;
5716 velocity.y += gravity * multiplier * 20;
5717 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5718 velspeed = findLength(&velocity);
5719 velocity = flatfacing * velspeed * -1;
5721 if (animTarget == dodgebackanim) {
5722 //coords-=facing*multiplier*50*scale;
5723 velocity += facing * multiplier * speed * 700 * scale * -1;
5724 velspeed = findLength(&velocity);
5725 if (velspeed > speed * 60 * scale) {
5726 velocity /= velspeed;
5727 velspeed = speed * 60 * scale;
5728 velocity *= velspeed;
5730 velocity.y += gravity * multiplier * 20;
5731 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5732 velspeed = findLength(&velocity);
5733 velocity = flatfacing * velspeed * -1;
5736 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5737 velspeed = findLength(&velocity);
5741 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5742 velocity.y += gravity * multiplier;
5745 if (animTarget != climbanim && animTarget != hanganim && !isWallJump())
5746 coords += velocity * multiplier;
5748 if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
5749 if (isFlip() && animation[animTarget].label[frameTarget] == 7)
5752 if (animTarget == jumpupanim) {
5754 animTarget = getIdle();
5761 pause_sound(whooshsound);
5762 OPENAL_SetVolume(channels[whooshsound], 0);
5765 if (animTarget == jumpdownanim || isFlip()) {
5766 if (isFlip())jumppower = -4;
5767 animTarget = getLanding();
5768 emit_sound_at(landsound, coords, 128.);
5771 envsound[numenvsounds] = coords;
5772 envsoundvol[numenvsounds] = 16;
5773 envsoundlife[numenvsounds] = .4;
5779 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump())
5780 coords.y += gravity * multiplier * 2;
5781 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) {
5782 coords.y = terrain.getHeight(coords.x, coords.z);
5787 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)) {
5788 velspeed = findLength(&velocity);
5790 if (velspeed < multiplier * 300 * scale) {
5793 velocity -= velocity / velspeed * multiplier * 300 * scale;
5794 if (velspeed > 5 && (isLanding() || isLandhard())) {
5795 skiddingdelay += multiplier;
5796 if (skiddelay <= 0) {
5806 velspeed = findLength(&velocity);
5808 if (velspeed < multiplier * 600 * scale) {
5811 velocity -= velocity / velspeed * multiplier * 600 * scale;
5813 if (velspeed > 5 && (isLanding() || isLandhard())) {
5814 skiddingdelay += multiplier;
5815 if (skiddelay <= 0) {
5824 if (skiddingdelay < 0)
5825 skiddingdelay += multiplier;
5826 if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) {
5828 if (!onterrain || environment == grassyenvironment) {
5829 emit_sound_at(skidsound, coords, 128 * velspeed / 10);
5831 emit_sound_at(snowskidsound, coords, 128 * velspeed / 10);
5835 if (animation[animTarget].attack == normalattack && animTarget != rabbitkickanim && !victim->skeleton.free) {
5836 terrainnormal = victim->coords - coords;
5837 Normalise(&terrainnormal);
5838 targetyaw = -asin(0 - terrainnormal.x);
5839 targetyaw *= 360 / 6.28;
5840 if (terrainnormal.z < 0)
5841 targetyaw = 180 - targetyaw;
5842 targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70;
5845 if (animation[animTarget].attack == reversal && animTarget != rabbittacklinganim) {
5846 targetyaw = victim->targetyaw;
5848 if (animTarget == rabbittacklinganim) {
5849 coords = victim->coords;
5852 skeleton.oldfree = skeleton.free;
5856 midterrain.x = terrain.size * terrain.scale / 2;
5857 midterrain.z = terrain.size * terrain.scale / 2;
5858 if (distsqflat(&coords, &midterrain) > (terrain.size * terrain.scale / 2 - viewdistance) * (terrain.size * terrain.scale / 2 - viewdistance)) {
5860 tempposit = coords - midterrain;
5862 Normalise(&tempposit);
5863 tempposit *= (terrain.size * terrain.scale / 2 - viewdistance);
5864 coords.x = tempposit.x + midterrain.x;
5865 coords.z = tempposit.z + midterrain.z;
5871 * inverse kinematics helper function
5873 void IKHelper(Person *p, float interp)
5875 XYZ point, newpoint, change, change2;
5876 float heightleft, heightright;
5878 // TODO: implement localToWorld and worldToLocal
5879 // but keep in mind it won't be the same math if player is ragdolled or something
5880 // - localToWorldStanding / worldToLocalStanding (or crouching or...?)
5881 // then comb through code for places where to use it
5883 // point = localToWorld(jointPos(leftfoot))
5884 point = DoRotation(p->jointPos(leftfoot), 0, p->yaw, 0) * p->scale + p->coords;
5885 // adjust height of foot
5886 heightleft = terrain.getHeight(point.x, point.z) + .04;
5887 point.y = heightleft;
5888 change = p->jointPos(leftankle) - p->jointPos(leftfoot);
5889 change2 = p->jointPos(leftknee) - p->jointPos(leftfoot);
5890 // jointPos(leftfoot) = interpolate(worldToLocal(point), jointPos(leftfoot), interp)
5891 p->jointPos(leftfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(leftfoot) * (1 - interp);
5892 // move ankle along with foot
5893 p->jointPos(leftankle) = p->jointPos(leftfoot) + change;
5894 // average knee pos between old and new pos
5895 p->jointPos(leftknee) = (p->jointPos(leftfoot) + change2) / 2 + (p->jointPos(leftknee)) / 2;
5897 // do same as above for right leg
5898 point = DoRotation(p->jointPos(rightfoot), 0, p->yaw, 0) * p->scale + p->coords;
5899 heightright = terrain.getHeight(point.x, point.z) + .04;
5900 point.y = heightright;
5901 change = p->jointPos(rightankle) - p->jointPos(rightfoot);
5902 change2 = p->jointPos(rightknee) - p->jointPos(rightfoot);
5903 p->jointPos(rightfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(rightfoot) * (1 - interp);
5904 p->jointPos(rightankle) = p->jointPos(rightfoot) + change;
5905 p->jointPos(rightknee) = (p->jointPos(rightfoot) + change2) / 2 + (p->jointPos(rightknee)) / 2;
5907 // fix up skeleton now that we've moved body parts?
5908 p->skeleton.DoConstraints(&p->coords, &p->scale);
5915 int Person::DrawSkeleton()
5917 int oldplayerdetail;
5918 if ((frustum.SphereInFrustum(coords.x, coords.y + scale * 3, coords.z, scale * 8) && distsq(&viewer, &coords) < viewdistance * viewdistance) || skeleton.free == 3) {
5919 if (onterrain && (isIdle() || isCrouch() || wasIdle() || wasCrouch()) && !skeleton.free) {
5929 glAlphaFunc(GL_GREATER, 0.0001);
5931 float terrainheight;
5935 if (!isnormal(tilt))
5937 if (!isnormal(tilt2))
5939 oldplayerdetail = playerdetail;
5941 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) {
5944 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 128 && detail == 1) {
5947 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) {
5952 if (playerdetail != oldplayerdetail) {
5954 normalsupdatedelay = 0;
5956 static float updatedelaychange;
5957 static float morphness;
5958 static float framemult;
5960 skeleton.FindForwards();
5961 if (howactive == typesittingwall) {
5962 skeleton.specialforward[1] = 0;
5963 skeleton.specialforward[1].z = 1;
5969 static int weaponattachmuscle;
5970 static int weaponrotatemuscle;
5971 static XYZ weaponpoint;
5972 static int start, endthing;
5973 if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
5974 if (!isSleeping() && !isSitting()) {
5975 // TODO: give these meaningful names
5976 const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard()
5977 || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim);
5978 const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard()
5979 || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim);
5981 if (onterrain && (cond1 && cond2) && !skeleton.free) {
5983 if (creature == wolftype)
5987 if (onterrain && (cond1 && !cond2) && !skeleton.free) {
5988 IKHelper(this, target);
5989 if (creature == wolftype)
5990 IKHelper(this, target);
5993 if (onterrain && (!cond1 && cond2) && !skeleton.free) {
5994 IKHelper(this, 1 - target);
5995 if (creature == wolftype)
5996 IKHelper(this, 1 - target);
6000 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()))
6003 targetheadyaw = -targetyaw;
6004 targetheadpitch = 0;
6005 if (animation[animTarget].attack == 3)
6006 targetheadyaw += 180;
6008 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6009 skeleton.drawmodel.vertex[i] = 0;
6010 skeleton.drawmodel.vertex[i].y = 999;
6012 for (i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
6013 skeleton.drawmodellow.vertex[i] = 0;
6014 skeleton.drawmodellow.vertex[i].y = 999;
6016 for (i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
6017 skeleton.drawmodelclothes.vertex[i] = 0;
6018 skeleton.drawmodelclothes.vertex[i].y = 999;
6020 for (i = 0; i < skeleton.num_muscles; i++) {
6021 // convenience renames
6022 const int p1 = skeleton.muscles[i].parent1->label;
6023 const int p2 = skeleton.muscles[i].parent2->label;
6025 if ((skeleton.muscles[i].numvertices > 0 && playerdetail) || (skeleton.muscles[i].numverticeslow > 0 && !playerdetail)) {
6030 if (p1 == righthand || p2 == righthand) {
6031 morphness = righthandmorphness;
6032 start = righthandmorphstart;
6033 endthing = righthandmorphend;
6035 if (p1 == lefthand || p2 == lefthand) {
6036 morphness = lefthandmorphness;
6037 start = lefthandmorphstart;
6038 endthing = lefthandmorphend;
6040 if (p1 == head || p2 == head) {
6041 morphness = headmorphness;
6042 start = headmorphstart;
6043 endthing = headmorphend;
6045 if ((p1 == neck && p2 == abdomen) || (p2 == neck && p1 == abdomen)) {
6046 morphness = chestmorphness;
6047 start = chestmorphstart;
6048 endthing = chestmorphend;
6050 if ((p1 == groin && p2 == abdomen) || (p2 == groin && p1 == abdomen)) {
6051 morphness = tailmorphness;
6052 start = tailmorphstart;
6053 endthing = tailmorphend;
6056 skeleton.FindRotationMuscle(i, animTarget);
6057 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6058 glMatrixMode(GL_MODELVIEW);
6062 glRotatef(tilt2, 1, 0, 0);
6064 glRotatef(tilt, 0, 0, 1);
6067 glTranslatef(mid.x, mid.y, mid.z);
6069 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6070 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6072 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6073 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6075 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6076 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6078 if (playerdetail || skeleton.free == 3) {
6079 for (j = 0; j < skeleton.muscles[i].numvertices; j++) {
6080 XYZ &v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
6081 XYZ &v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
6082 glMatrixMode(GL_MODELVIEW);
6084 if (p1 == abdomen || p2 == abdomen)
6085 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionbody.x,
6086 (v0.y * (1 - morphness) + v1.y * morphness) * proportionbody.y,
6087 (v0.z * (1 - morphness) + v1.z * morphness) * proportionbody.z);
6088 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6089 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionarms.x,
6090 (v0.y * (1 - morphness) + v1.y * morphness) * proportionarms.y,
6091 (v0.z * (1 - morphness) + v1.z * morphness) * proportionarms.z);
6092 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6093 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionlegs.x,
6094 (v0.y * (1 - morphness) + v1.y * morphness) * proportionlegs.y,
6095 (v0.z * (1 - morphness) + v1.z * morphness) * proportionlegs.z);
6096 if (p1 == head || p2 == head)
6097 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionhead.x,
6098 (v0.y * (1 - morphness) + v1.y * morphness) * proportionhead.y,
6099 (v0.z * (1 - morphness) + v1.z * morphness) * proportionhead.z);
6100 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6101 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
6102 //if(!isnormal(scale))test=1;
6103 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale;
6104 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale;
6105 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z = M[14] * scale;
6110 if (!playerdetail || skeleton.free == 3) {
6111 for (j = 0; j < skeleton.muscles[i].numverticeslow; j++) {
6112 XYZ &v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
6113 glMatrixMode(GL_MODELVIEW);
6115 if (p1 == abdomen || p2 == abdomen)
6116 glTranslatef(v0.x * proportionbody.x,
6117 v0.y * proportionbody.y,
6118 v0.z * proportionbody.z);
6119 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6120 glTranslatef(v0.x * proportionarms.x,
6121 v0.y * proportionarms.y,
6122 v0.z * proportionarms.z);
6123 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6124 glTranslatef(v0.x * proportionlegs.x,
6125 v0.y * proportionlegs.y,
6126 v0.z * proportionlegs.z);
6127 if (p1 == head || p2 == head)
6128 glTranslatef(v0.x * proportionhead.x,
6129 v0.y * proportionhead.y,
6130 v0.z * proportionhead.z);
6132 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6133 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
6134 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y = M[13] * scale;
6135 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z = M[14] * scale;
6141 if (skeleton.clothes && skeleton.muscles[i].numverticesclothes > 0) {
6142 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6144 glMatrixMode(GL_MODELVIEW);
6148 glRotatef(tilt2, 1, 0, 0);
6150 glRotatef(tilt, 0, 0, 1);
6151 glTranslatef(mid.x, mid.y, mid.z);
6152 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6153 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6155 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6156 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6158 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6159 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6161 for (j = 0; j < skeleton.muscles[i].numverticesclothes; j++) {
6162 XYZ &v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
6163 glMatrixMode(GL_MODELVIEW);
6165 if (p1 == abdomen || p2 == abdomen)
6166 glTranslatef(v0.x * proportionbody.x,
6167 v0.y * proportionbody.y,
6168 v0.z * proportionbody.z);
6169 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6170 glTranslatef(v0.x * proportionarms.x,
6171 v0.y * proportionarms.y,
6172 v0.z * proportionarms.z);
6173 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6174 glTranslatef(v0.x * proportionlegs.x,
6175 v0.y * proportionlegs.y,
6176 v0.z * proportionlegs.z);
6177 if (p1 == head || p2 == head)
6178 glTranslatef(v0.x * proportionhead.x,
6179 v0.y * proportionhead.y,
6180 v0.z * proportionhead.z);
6181 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6182 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
6183 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
6184 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z = M[14] * scale;
6189 updatedelay = 1 + (float)(Random() % 100) / 1000;
6191 if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) {
6192 normalsupdatedelay = 1;
6193 if (playerdetail || skeleton.free == 3)
6194 skeleton.drawmodel.CalculateNormals(0);
6195 if (!playerdetail || skeleton.free == 3)
6196 skeleton.drawmodellow.CalculateNormals(0);
6197 if (skeleton.clothes)
6198 skeleton.drawmodelclothes.CalculateNormals(0);
6200 if (playerdetail || skeleton.free == 3)
6201 skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
6202 if (!playerdetail || skeleton.free == 3)
6203 skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
6204 if (skeleton.clothes) {
6205 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6210 updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1);
6211 if (updatedelaychange > -realmultiplier * 30)
6212 updatedelaychange = -realmultiplier * 30;
6213 if (updatedelaychange > -framemult * 4)
6214 updatedelaychange = -framemult * 4;
6215 if (skeleton.free == 1)
6216 updatedelaychange *= 6;
6218 updatedelaychange *= 8;
6219 updatedelay += updatedelaychange;
6221 glMatrixMode(GL_MODELVIEW);
6224 glTranslatef(coords.x, coords.y - .02, coords.z);
6226 glTranslatef(coords.x, coords.y - .02, coords.z);
6228 glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
6230 glRotatef(yaw, 0, 1, 0);
6233 glColor4f(.4, 1, .4, 1);
6234 glDisable(GL_LIGHTING);
6235 glDisable(GL_TEXTURE_2D);
6238 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6239 XYZ &v0 = skeleton.drawmodel.vertex[i];
6240 glVertex3f(v0.x, v0.y, v0.z);
6246 for (i = 0; i < skeleton.drawmodel.TriangleNum; i++) {
6247 XYZ &v0 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]];
6248 XYZ &v1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]];
6249 XYZ &v2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]];
6250 glVertex3f(v0.x, v0.y, v0.z);
6251 glVertex3f(v1.x, v1.y, v1.z);
6252 glVertex3f(v1.x, v1.y, v1.z);
6253 glVertex3f(v2.x, v2.y, v2.z);
6254 glVertex3f(v2.x, v2.y, v2.z);
6255 glVertex3f(v0.x, v0.y, v0.z);
6261 terrainlight = terrain.getLighting(coords.x, coords.z);
6262 distance = distsq(&viewer, &coords);
6263 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
6267 terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1;
6268 if (terrainheight < 1)
6270 if (terrainheight > 1.7)
6271 terrainheight = 1.7;
6274 glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance);
6275 glDisable(GL_BLEND);
6276 glAlphaFunc(GL_GREATER, 0.0001);
6277 glEnable(GL_TEXTURE_2D);
6279 glDisable(GL_TEXTURE_2D);
6280 glColor4f(.7, .35, 0, .5);
6282 glEnable(GL_LIGHTING);
6285 if (tutoriallevel && id != 0) {
6286 //glDisable(GL_TEXTURE_2D);
6287 glColor4f(.7, .7, .7, 0.6);
6289 glEnable(GL_LIGHTING);
6291 if (canattack && cananger)
6292 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6293 glDisable(GL_TEXTURE_2D);
6294 glColor4f(1, 0, 0, 0.8);
6296 glMatrixMode(GL_TEXTURE);
6298 glTranslatef(0, -smoketex, 0);
6299 glTranslatef(-smoketex, 0, 0);
6303 if ((tutoriallevel && id != 0))
6304 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6306 skeleton.drawmodel.draw();
6309 if (!playerdetail) {
6310 if ((tutoriallevel && id != 0))
6311 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6313 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6316 if (!(animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed))
6317 if (tutoriallevel && id != 0) {
6319 glMatrixMode(GL_MODELVIEW);
6320 glEnable(GL_TEXTURE_2D);
6321 glColor4f(.7, .7, .7, 0.6);
6323 glEnable(GL_LIGHTING);
6325 if (canattack && cananger)
6326 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6327 glDisable(GL_TEXTURE_2D);
6328 glColor4f(1, 0, 0, 0.8);
6330 glMatrixMode(GL_TEXTURE);
6332 glTranslatef(0, -smoketex * .6, 0);
6333 glTranslatef(smoketex * .6, 0, 0);
6336 if ((tutoriallevel && id != 0))
6337 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6339 skeleton.drawmodel.draw();
6342 if (!playerdetail) {
6343 if ((tutoriallevel && id != 0))
6344 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6346 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6351 if (tutoriallevel && id != 0) {
6353 glMatrixMode(GL_MODELVIEW);
6354 glEnable(GL_TEXTURE_2D);
6356 if (skeleton.clothes) {
6360 skeleton.drawmodelclothes.draw();
6362 skeleton.drawmodelclothes.drawimmediate();
6368 if (num_weapons > 0) {
6369 for (k = 0; k < num_weapons; k++) {
6371 if (weaponactive == k) {
6372 if (weapons[i].getType() != staff) {
6373 for (j = 0; j < skeleton.num_muscles; j++) {
6374 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6375 weaponattachmuscle = j;
6378 for (j = 0; j < skeleton.num_muscles; j++) {
6379 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) {
6380 weaponrotatemuscle = j;
6383 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6384 if (creature == wolftype)
6385 weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3);
6387 if (weapons[i].getType() == staff) {
6388 for (j = 0; j < skeleton.num_muscles; j++) {
6389 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6390 weaponattachmuscle = j;
6393 for (j = 0; j < skeleton.num_muscles; j++) {
6394 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) {
6395 weaponrotatemuscle = j;
6398 //weaponpoint=jointPos(rightwrist);
6399 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6400 //weaponpoint+=skeleton.specialforward[1]*.1+(jointPos(rightwrist)-jointPos(rightelbow));
6401 XYZ tempnormthing, vec1, vec2;
6402 vec1 = (jointPos(rightwrist) - jointPos(rightelbow));
6403 vec2 = (jointPos(rightwrist) - jointPos(rightshoulder));
6404 CrossProduct(&vec1, &vec2, &tempnormthing);
6405 Normalise(&tempnormthing);
6406 if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim)
6407 weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow));
6410 if (weaponactive != k && weaponstuck != k) {
6411 if (weapons[i].getType() == knife)
6412 weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35;
6413 if (weapons[i].getType() == sword)
6414 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6415 if (weapons[i].getType() == staff)
6416 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6417 for (j = 0; j < skeleton.num_muscles; j++) {
6418 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) {
6419 weaponrotatemuscle = j;
6423 if (weaponstuck == k) {
6424 if (weaponstuckwhere == 0)
6425 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8;
6427 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
6428 for (j = 0; j < skeleton.num_muscles; j++) {
6429 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) {
6430 weaponrotatemuscle = j;
6434 if (skeleton.free) {
6435 weapons[i].position = weaponpoint * scale + coords;
6436 weapons[i].bigrotation = 0;
6437 weapons[i].bigtilt = 0;
6438 weapons[i].bigtilt2 = 0;
6440 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;
6441 weapons[i].bigrotation = yaw;
6442 weapons[i].bigtilt = tilt;
6443 weapons[i].bigtilt2 = tilt2;
6445 weapons[i].rotation1 = skeleton.muscles[weaponrotatemuscle].lastrotate1;
6446 weapons[i].rotation2 = skeleton.muscles[weaponrotatemuscle].lastrotate2;
6447 weapons[i].rotation3 = skeleton.muscles[weaponrotatemuscle].lastrotate3;
6448 if (weaponactive == k) {
6449 if (weapons[i].getType() == knife) {
6450 weapons[i].smallrotation = 180;
6451 weapons[i].smallrotation2 = 0;
6452 if (isCrouch() || wasCrouch()) {
6453 weapons[i].smallrotation2 = 20;
6455 if (animTarget == hurtidleanim) {
6456 weapons[i].smallrotation2 = 50;
6458 if ((animCurrent == crouchstabanim && animTarget == crouchstabanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
6459 XYZ temppoint1, temppoint2, tempforward;
6462 temppoint1 = jointPos(righthand);
6463 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6464 distance = findDistance(&temppoint1, &temppoint2);
6465 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6466 weapons[i].rotation2 *= 360 / 6.28;
6469 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6470 weapons[i].rotation1 *= 360 / 6.28;
6471 weapons[i].rotation3 = 0;
6472 weapons[i].smallrotation = -90;
6473 weapons[i].smallrotation2 = 0;
6474 if (temppoint1.x > temppoint2.x)
6475 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6477 if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) {
6478 XYZ temppoint1, temppoint2, tempforward;
6481 temppoint1 = jointPos(righthand);
6482 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6483 distance = findDistance(&temppoint1, &temppoint2);
6484 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6485 weapons[i].rotation2 *= 360 / 6.28;
6488 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6489 weapons[i].rotation1 *= 360 / 6.28;
6490 weapons[i].rotation3 = 0;
6491 weapons[i].smallrotation = 90;
6492 weapons[i].smallrotation2 = 0;
6493 if (temppoint1.x > temppoint2.x)
6494 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6496 if (animTarget == knifethrowanim) {
6497 weapons[i].smallrotation = 90;
6498 //weapons[i].smallrotation2=-90;
6499 weapons[i].smallrotation2 = 0;
6500 weapons[i].rotation1 = 0;
6501 weapons[i].rotation2 = 0;
6502 weapons[i].rotation3 = 0;
6504 if (animTarget == knifesneakattackanim && frameTarget < 5) {
6505 weapons[i].smallrotation = -90;
6506 weapons[i].rotation1 = 0;
6507 weapons[i].rotation2 = 0;
6508 weapons[i].rotation3 = 0;
6511 if (weapons[i].getType() == sword) {
6512 weapons[i].smallrotation = 0;
6513 weapons[i].smallrotation2 = 0;
6514 if (animTarget == knifethrowanim) {
6515 weapons[i].smallrotation = -90;
6516 weapons[i].smallrotation2 = 0;
6517 weapons[i].rotation1 = 0;
6518 weapons[i].rotation2 = 0;
6519 weapons[i].rotation3 = 0;
6521 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)) {
6522 XYZ temppoint1, temppoint2, tempforward;
6525 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6526 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6527 distance = findDistance(&temppoint1, &temppoint2);
6528 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6529 weapons[i].rotation2 *= 360 / 6.28;
6532 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6533 weapons[i].rotation1 *= 360 / 6.28;
6534 weapons[i].rotation3 = 0;
6535 weapons[i].smallrotation = 90;
6536 weapons[i].smallrotation2 = 0;
6537 if (temppoint1.x > temppoint2.x)
6538 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6541 if (weapons[i].getType() == staff) {
6542 weapons[i].smallrotation = 100;
6543 weapons[i].smallrotation2 = 0;
6544 if ((animTarget == staffhitanim && animCurrent == staffhitanim) || (animTarget == staffhitreversedanim && animCurrent == staffhitreversedanim) || (animTarget == staffspinhitreversedanim && animCurrent == staffspinhitreversedanim) || (animTarget == staffgroundsmashanim && animCurrent == staffgroundsmashanim) || (animTarget == staffspinhitanim && animCurrent == staffspinhitanim)) {
6545 XYZ temppoint1, temppoint2, tempforward;
6548 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6549 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6550 distance = findDistance(&temppoint1, &temppoint2);
6551 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6552 weapons[i].rotation2 *= 360 / 6.28;
6555 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6556 weapons[i].rotation1 *= 360 / 6.28;
6557 weapons[i].rotation3 = 0;
6558 weapons[i].smallrotation = 90;
6559 weapons[i].smallrotation2 = 0;
6560 if (temppoint1.x > temppoint2.x)
6561 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6565 if (weaponactive != k && weaponstuck != k) {
6566 if (weapons[i].getType() == knife) {
6567 weapons[i].smallrotation = -70;
6568 weapons[i].smallrotation2 = 10;
6570 if (weapons[i].getType() == sword) {
6571 weapons[i].smallrotation = -100;
6572 weapons[i].smallrotation2 = -8;
6574 if (weapons[i].getType() == staff) {
6575 weapons[i].smallrotation = -100;
6576 weapons[i].smallrotation2 = -8;
6579 if (weaponstuck == k) {
6580 if (weaponstuckwhere == 0)
6581 weapons[i].smallrotation = 180;
6583 weapons[i].smallrotation = 0;
6584 weapons[i].smallrotation2 = 10;
6593 if (animation[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isFlip() || isWallJump())
6595 if (animCurrent != animTarget)
6597 //if(id==0)calcrot=1;
6598 if (skeleton.free == 2)
6607 int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6610 static float distance;
6611 static float olddistance;
6612 static int intersecting;
6613 static int firstintersecting;
6616 static XYZ start, end;
6617 static float slopethreshold = -.4;
6619 firstintersecting = -1;
6623 if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius)
6626 *p1 = DoRotation(*p1, 0, -*rotate, 0);
6627 for (i = 0; i < 4; i++) {
6628 for (j = 0; j < model->TriangleNum; j++) {
6629 if (model->facenormals[j].y <= slopethreshold) {
6631 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)));
6632 if (distance < radius) {
6633 point = *p1 - model->facenormals[j] * distance;
6634 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]]))
6637 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6638 &model->vertex[model->Triangles[j].vertex[1]],
6641 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6642 &model->vertex[model->Triangles[j].vertex[2]],
6645 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6646 &model->vertex[model->Triangles[j].vertex[2]],
6649 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6653 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)) {
6654 p1->y = point.y + radius;
6655 if ((animTarget == jumpdownanim || isFlip())) {
6656 if (isFlip() && (frameTarget < 5 || animation[animTarget].label[frameTarget] == 7 || animation[animTarget].label[frameTarget] == 4))
6659 if (animTarget == jumpupanim) {
6661 animTarget = getIdle();
6668 pause_sound(whooshsound);
6669 OPENAL_SetVolume(channels[whooshsound], 0);
6672 if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) {
6675 animTarget = getLanding();
6676 emit_sound_at(landsound, coords, 128.);
6679 envsound[numenvsounds] = coords;
6680 envsoundvol[numenvsounds] = 16;
6681 envsoundlife[numenvsounds] = .4;
6689 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6690 olddistance = distance;
6691 firstintersecting = j;
6696 for (j = 0; j < model->TriangleNum; j++) {
6697 if (model->facenormals[j].y > slopethreshold) {
6700 start.y -= radius / 4;
6701 XYZ &v0 = model->vertex[model->Triangles[j].vertex[0]];
6702 XYZ &v1 = model->vertex[model->Triangles[j].vertex[1]];
6703 XYZ &v2 = model->vertex[model->Triangles[j].vertex[2]];
6704 distance = abs((model->facenormals[j].x * start.x)
6705 + (model->facenormals[j].y * start.y)
6706 + (model->facenormals[j].z * start.z)
6707 - ((model->facenormals[j].x * v0.x)
6708 + (model->facenormals[j].y * v0.y)
6709 + (model->facenormals[j].z * v0.z)));
6710 if (distance < radius * .5) {
6711 point = start - model->facenormals[j] * distance;
6712 if (PointInTriangle( &point, model->facenormals[j], &v0, &v1, &v2))
6715 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
6717 intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6719 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6721 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6722 if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
6724 velocity -= DoRotation(model->facenormals[j], 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->facenormals[j], 0, *rotate, 0))); //(distance-radius*.5)/multiplier;
6725 if (findLengthfast(&start) < findLengthfast(&velocity))
6728 *p1 += model->facenormals[j] * (distance - radius * .5);
6731 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6732 olddistance = distance;
6733 firstintersecting = j;
6740 *p = DoRotation(*p, 0, *rotate, 0);
6743 *p1 = DoRotation(*p1, 0, *rotate, 0);
6745 return firstintersecting;