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];
87 std::vector<std::shared_ptr<Person>> Person::players(1, std::shared_ptr<Person>(new Person()));
92 * GameTick/doPlayerCollisions
94 void Person::CheckKick()
97 && (animTarget == rabbitkickanim
99 && victim != this->shared_from_this()
101 && animCurrent == rabbitkickanim)
102 && distsq(&coords, &victim->coords) < 1.2
103 && !victim->skeleton.free))
106 if (animation[victim->animTarget].height != lowheight) {
107 float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
108 XYZ relative = velocity;
110 Normalise(&relative);
114 if (tutoriallevel != 1)
115 emit_sound_at(heavyimpactsound, victim->coords);
117 for (int i = 0; i < victim->skeleton.num_joints; i++) {
118 victim->skeleton.joints[i].velocity += relative * 120 * damagemult;
121 victim->DoDamage(100 * damagemult / victim->protectionhigh);
127 animTarget = backflipanim;
129 velocity = facing * -10;
133 resume_stream(whooshsound);
135 award_bonus(id, cannon);
136 } else if (victim->isCrouch()) {
137 animTarget = rabbitkickreversedanim;
138 animCurrent = rabbitkickreversedanim;
139 victim->animCurrent = rabbitkickreversalanim;
140 victim->animTarget = rabbitkickreversalanim;
146 victim->oldcoords = victim->coords;
147 coords = victim->coords;
148 victim->targetyaw = targetyaw;
149 victim->victim = this->shared_from_this();
156 * GameTick/doPlayerCollisions - spread fire between players
157 * GameTick/doDebugKeys - press f to ignite
158 * Person::DoStuff - spread fire from lit campfires and bushes
160 void Person::CatchFire()
162 XYZ flatfacing, flatvelocity;
164 for (int i = 0; i < 10; i++) {
165 howmany = abs(Random() % (skeleton.num_joints));
167 flatvelocity = velocity;
169 flatvelocity = skeleton.joints[howmany].velocity;
171 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
173 flatfacing = skeleton.joints[howmany].position * scale + coords;
174 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
179 emit_sound_at(firestartsound, coords);
181 emit_stream_at(stream_firesound, coords);
189 * idle animation for this creature (depending on status)
191 int Person::getIdle()
193 if (indialogue != -1 && howactive == typeactive && creature == rabbittype)
195 if (hasvictim && (victim != this->shared_from_this())/*||(id==0&&attackkeydown)*/)
196 if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype && victim->aitype != searchtype && aitype != passivetype && aitype != searchtype && victim->id < numplayers)) {
197 if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) {
198 if (creature == rabbittype)
199 return fightidleanim;
200 if (creature == wolftype)
203 if (aitype == playercontrolled && stunned <= 0 && weaponactive != -1) {
204 if (weapons[weaponids[weaponactive]].getType() == knife)
205 return knifefightidleanim;
206 if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1)
207 return swordfightidlebothanim;
208 if (weapons[weaponids[weaponactive]].getType() == sword)
209 return swordfightidleanim;
210 if (weapons[weaponids[weaponactive]].getType() == staff)
211 return swordfightidleanim;
213 if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause)
214 return fightsidestep;
216 if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype)
218 if (howactive == typesitting) return sitanim;
219 if (howactive == typesittingwall) return sitwallanim;
220 if (howactive == typesleeping) return sleepanim;
221 if (howactive == typedead1) return dead1anim;
222 if (howactive == typedead2) return dead2anim;
223 if (howactive == typedead3) return dead3anim;
224 if (howactive == typedead4) return dead4anim;
225 if (creature == rabbittype) return bounceidleanim;
226 if (creature == wolftype) return wolfidle;
231 * crouch animation for this creature
233 int Person::getCrouch()
235 if (creature == rabbittype)
237 if (creature == wolftype)
238 return wolfcrouchanim;
243 * running animation for this creature (can be upright or all fours)
247 if (creature == rabbittype && (!superruntoggle || weaponactive != -1))
249 if (creature == wolftype && (!superruntoggle))
252 if (creature == rabbittype && (superruntoggle && weaponactive == -1))
253 return rabbitrunninganim;
254 if (creature == wolftype && (superruntoggle))
255 return wolfrunninganim;
261 int Person::getStop()
263 if (creature == rabbittype)
265 if (creature == wolftype)
272 int Person::getLanding()
274 if (creature == rabbittype)
276 if (creature == wolftype)
283 int Person::getLandhard()
285 if (creature == rabbittype)
287 if (creature == wolftype)
288 return wolflandhardanim;
295 * Person::DoAnimations
298 SolidHitBonus(int playerid)
300 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
301 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
303 award_bonus(playerid, solidhit);
307 * spawns blood effects
309 void Person::DoBlood(float howmuch, int which)
311 // FIXME: should abstract out inputs
312 static int bleedxint, bleedyint;
314 //if(howmuch&&id==0)blooddimamount=1;
315 if (bloodtoggle && tutoriallevel != 1) {
316 if (bleeding <= 0 && spurt) {
318 for (int i = 0; i < 3; i++) {
319 // emit blood particles
321 if (!skeleton.free) {
323 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
326 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
329 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
331 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
333 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
334 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
336 if (!skeleton.free) {
337 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
338 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
341 if (Random() % 2 == 0) // 50% chance
342 for (int i = 0; i < 3; i++) {
343 if (Random() % 2 != 0) {
344 // emit teeth particles
347 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
348 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
351 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
352 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
356 Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
358 Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
360 Sprite::setLastSpriteSpecial(3); // sets it to teeth
365 // FIXME: manipulating attributes
366 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
369 if (creature == rabbittype)
370 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) {
371 bleedxint = abs(Random() % 512);
372 bleedyint = abs(Random() % 512);
374 if (creature == wolftype)
375 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) {
376 bleedxint = abs(Random() % 512);
377 bleedyint = abs(Random() % 512);
381 bleedy /= realtexdetail;
382 bleedx /= realtexdetail;
383 direction = abs(Random() % 2) * 2 - 1;
392 * spawns big blood effects and ???
393 * modifies character's skin texture
395 void Person::DoBloodBig(float howmuch, int which)
397 static int bleedxint, bleedyint, i, j;
399 if (howmuch && id == 0)
402 if (tutoriallevel != 1 || id == 0)
403 if (aitype != playercontrolled && howmuch > 0) {
407 // FIXME: seems to be spawning sounds by manipulating attributes... MESSY!
408 if (creature == wolftype) {
409 int i = abs(Random() % 2);
411 whichsound = snarlsound;
413 whichsound = snarl2sound;
414 envsound[numenvsounds] = coords;
415 envsoundvol[numenvsounds] = 16;
416 envsoundlife[numenvsounds] = .4;
419 if (creature == rabbittype) {
420 int i = abs(Random() % 2);
422 whichsound = rabbitpainsound;
423 if (i == 1 && howmuch >= 2)
424 whichsound = rabbitpain1sound;
425 envsound[numenvsounds] = coords;
426 envsoundvol[numenvsounds] = 16;
427 envsoundlife[numenvsounds] = .4;
429 //if(i==2)whichsound=rabbitpain2sound;
432 if (whichsound != -1)
433 emit_sound_at(whichsound, coords);
436 if (id == 0 && howmuch > 0) {
437 // FIXME: manipulating attributes
445 if (bloodtoggle && decals && tutoriallevel != 1) {
446 if (bleeding <= 0 && spurt) {
448 for (int i = 0; i < 3; i++) {
449 // emit blood particles
450 // FIXME: copypaste from above
452 if (!skeleton.free) {
454 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
457 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
460 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
462 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
464 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
465 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
467 if (!skeleton.free) {
468 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
469 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
474 // weird texture manipulation code follows.
475 // looks like this is painting blood onto the character's skin texture
476 // FIXME: surely there's a better way
478 int offsetx = 0, offsety = 0;
480 offsety = Random() % 40;
481 offsetx = abs(Random() % 60);
483 if (which == 190 || which == 185) {
484 offsety = Random() % 40;
485 offsetx = abs(Random() % 100) - 20;
488 offsety = Random() % 10;
489 offsetx = Random() % 10;
492 offsety = Random() % 20;
493 offsetx = Random() % 20;
495 if (which == 220 || which == 215) {
505 if (creature == rabbittype)
506 for (i = 0; i < 512; i++) {
507 for (j = 0; j < 512; j++) {
508 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
509 if (i < startx) startx = i;
510 if (j < starty) starty = j;
511 if (i > endx) endx = i;
512 if (j > endy) endy = j;
516 if (creature == wolftype)
517 for (i = 0; i < 512; i++) {
518 for (j = 0; j < 512; j++) {
519 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
520 if (i < startx) startx = i;
521 if (j < starty) starty = j;
522 if (i > endx) endx = i;
523 if (j > endy) endy = j;
533 if (startx < 0) startx = 0;
534 if (starty < 0) starty = 0;
535 if (endx > 512 - 1) endx = 512 - 1;
536 if (endy > 512 - 1) endy = 512 - 1;
537 if (endx < startx) endx = startx;
538 if (endy < starty) endy = starty;
540 startx /= realtexdetail;
541 starty /= realtexdetail;
542 endx /= realtexdetail;
543 endy /= realtexdetail;
545 int texdetailint = realtexdetail;
547 if (creature == rabbittype)
548 for (i = startx; i < endx; i++) {
549 for (j = starty; j < endy; j++) {
550 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) {
551 color = Random() % 85 + 170;
552 where = i * skeleton.skinsize * 3 + j * 3;
553 if (skeleton.skinText[where + 0] > color / 2)
554 skeleton.skinText[where + 0] = color / 2;
555 skeleton.skinText[where + 1] = 0;
556 skeleton.skinText[where + 2] = 0;
560 if (creature == wolftype)
561 for (i = startx; i < endx; i++) {
562 for (j = starty; j < endy; j++) {
563 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) {
564 color = Random() % 85 + 170;
565 where = i * skeleton.skinsize * 3 + j * 3;
566 if (skeleton.skinText[where + 0] > color / 2)
567 skeleton.skinText[where + 0] = color / 2;
568 skeleton.skinText[where + 1] = 0;
569 skeleton.skinText[where + 2] = 0;
573 skeleton.drawmodel.textureptr.bind();
578 if (creature == rabbittype)
579 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) {
580 bleedxint = abs(Random() % 512);
581 bleedyint = abs(Random() % 512);
583 if (creature == wolftype)
584 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) {
585 bleedxint = abs(Random() % 512);
586 bleedyint = abs(Random() % 512);
588 bleedy = bleedxint + offsetx;
589 bleedx = bleedyint + offsety;
590 bleedy /= realtexdetail;
591 bleedx /= realtexdetail;
596 if (bleedx > skeleton.skinsize - 1)
597 bleedx = skeleton.skinsize - 1;
598 if (bleedy > skeleton.skinsize - 1)
599 bleedy = skeleton.skinsize - 1;
600 direction = abs(Random() % 2) * 2 - 1;
603 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
604 deathbleeding += bleeding;
605 bloodloss += bleeding * 3;
607 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
608 if (abs(Random() % 2) == 0) {
609 aitype = gethelptype;
612 aitype = attacktypecutoff;
620 * similar to DoBloodBig
622 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
626 static XYZ startpoint, endpoint, colpoint, movepoint;
627 static float rotationpoint;
629 static XYZ p1, p2, p3, p0;
633 float coordsx, coordsy;
636 if (bloodtoggle && decals && tutoriallevel != 1) {
639 where = DoRotation(where, 0, -yaw, 0);
647 // ray testing for a tri in the character model
648 whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
649 if (whichtri != -1) {
650 // low level geometry math
652 p1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
653 p2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
654 p3 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
656 CrossProduct(p2-p1,p3-p1,&N);
657 CrossProduct(p0-p1,p3-p1,&temp);
658 s = dotproduct(&temp,&N)/findLength(&N);
659 CrossProduct(p2-p1,p1-p0,&temp);
660 t = dotproduct(&temp,&N)/findLength(&N);
663 bary.x = distsq(&p0, &p1);
664 bary.y = distsq(&p0, &p2);
665 bary.z = distsq(&p0, &p3);
667 total = bary.x + bary.y + bary.z;
676 total = bary.x + bary.y + bary.z;
682 gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0];
683 gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1];
684 gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2];
685 gyy.x = skeleton.drawmodel.Triangles[whichtri].gy[0];
686 gyy.y = skeleton.drawmodel.Triangles[whichtri].gy[1];
687 gyy.z = skeleton.drawmodel.Triangles[whichtri].gy[2];
688 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;
689 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;
691 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
692 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
694 if (bleeding <= 0 && spurt) {
696 for (int i = 0; i < 3; i++) {
697 // emit blood particles
698 // FIXME: more copypaste code
700 if (!skeleton.free) {
702 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
705 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
708 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
710 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
712 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
713 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
715 if (!skeleton.free) {
716 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
717 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
722 // texture manipulation follows
724 int offsetx = 0, offsety = 0;
727 offsetx=abs(Random()%120);
729 if(which==220||which==215){
731 offsetx=abs(Random()%80);
734 offsetx = (1 + coordsy) * 512 - 291;
735 offsety = coordsx * 512 - 437;
742 if (creature == rabbittype)
743 for (i = 0; i < 512; i++) {
744 for (j = 0; j < 512; j++) {
745 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
746 if (i < startx) startx = i;
747 if (j < starty) starty = j;
748 if (i > endx) endx = i;
749 if (j > endy) endy = j;
753 if (creature == wolftype)
754 for (i = 0; i < 512; i++) {
755 for (j = 0; j < 512; j++) {
756 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
757 if (i < startx) startx = i;
758 if (j < starty) starty = j;
759 if (i > endx) endx = i;
760 if (j > endy) endy = j;
769 if (startx < 0) startx = 0;
770 if (starty < 0) starty = 0;
771 if (endx > 512 - 1) endx = 512 - 1;
772 if (endy > 512 - 1) endy = 512 - 1;
773 if (endx < startx) endx = startx;
774 if (endy < starty) endy = starty;
776 startx /= realtexdetail;
777 starty /= realtexdetail;
778 endx /= realtexdetail;
779 endy /= realtexdetail;
781 int texdetailint = realtexdetail;
783 if (creature == rabbittype)
784 for (i = startx; i < endx; i++) {
785 for (j = starty; j < endy; j++) {
786 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) {
787 color = Random() % 85 + 170;
788 where = i * skeleton.skinsize * 3 + j * 3;
789 if (skeleton.skinText[where + 0] > color / 2)
790 skeleton.skinText[where + 0] = color / 2;
791 skeleton.skinText[where + 1] = 0;
792 skeleton.skinText[where + 2] = 0;
793 } 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) {
794 color = Random() % 85 + 170;
795 where = i * skeleton.skinsize * 3 + j * 3;
796 if (skeleton.skinText[where + 0] > color / 2)
797 skeleton.skinText[where + 0] = color / 2;
798 skeleton.skinText[where + 1] = 0;
799 skeleton.skinText[where + 2] = 0;
803 if (creature == wolftype)
804 for (i = startx; i < endx; i++) {
805 for (j = starty; j < endy; j++) {
806 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) {
807 color = Random() % 85 + 170;
808 where = i * skeleton.skinsize * 3 + j * 3;
809 if (skeleton.skinText[where + 0] > color / 2)
810 skeleton.skinText[where + 0] = color / 2;
811 skeleton.skinText[where + 1] = 0;
812 skeleton.skinText[where + 2] = 0;
813 } 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) {
814 color = Random() % 85 + 170;
815 where = i * skeleton.skinsize * 3 + j * 3;
816 if (skeleton.skinText[where + 0] > color / 2)
817 skeleton.skinText[where + 0] = color / 2;
818 skeleton.skinText[where + 1] = 0;
819 skeleton.skinText[where + 2] = 0;
823 skeleton.drawmodel.textureptr.bind();
826 bleedy = (1 + coordsy) * 512;
827 bleedx = coordsx * 512;
828 bleedy /= realtexdetail;
829 bleedx /= realtexdetail;
834 if (bleedx > skeleton.skinsize - 1)
835 bleedx = skeleton.skinsize - 1;
836 if (bleedy > skeleton.skinsize - 1)
837 bleedy = skeleton.skinsize - 1;
838 direction = abs(Random() % 2) * 2 - 1;
843 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
844 deathbleeding += bleeding;
845 bloodloss += bleeding * 3;
847 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
848 if (abs(Random() % 2) == 0) {
849 aitype = gethelptype;
852 aitype = attacktypecutoff;
863 * guessing this performs a reversal
865 void Person::Reverse()
867 if (!((victim->aitype == playercontrolled
869 || staggerdelay <= 0)
870 && victim->animTarget != jumpupanim
871 && victim->animTarget != jumpdownanim
872 && (tutoriallevel != 1 || cananger)
876 if (normaldotproduct (victim->facing, victim->coords - coords) > 0
877 && (victim->id != 0 || difficulty >= 2)
878 && (creature != wolftype || victim->creature == wolftype))
881 if (animTarget == sweepanim) {
882 animTarget = sweepreversedanim;
883 animCurrent = sweepreversedanim;
884 victim->animCurrent = sweepreversalanim;
885 victim->animTarget = sweepreversalanim;
887 if (animTarget == spinkickanim) {
888 animTarget = spinkickreversedanim;
889 animCurrent = spinkickreversedanim;
890 victim->animCurrent = spinkickreversalanim;
891 victim->animTarget = spinkickreversalanim;
893 if (animTarget == upunchanim || animTarget == rabbittacklinganim) {
894 if (animTarget == rabbittacklinganim) {
897 victim->frameCurrent = 6;
898 victim->frameTarget = 7;
900 animTarget = upunchreversedanim;
901 animCurrent = upunchreversedanim;
902 victim->animCurrent = upunchreversalanim;
903 victim->animTarget = upunchreversalanim;
905 if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
906 if (victim->weaponactive != -1) {
907 victim->throwtogglekeydown = 1;
908 weapons[victim->weaponids[0]].owner = -1;
909 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
910 if (weapons[victim->weaponids[0]].velocity.x == 0)
911 weapons[victim->weaponids[0]].velocity.x = .1;
912 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
913 weapons[victim->weaponids[0]].missed = 1;
914 weapons[victim->weaponids[0]].freetime = 0;
915 weapons[victim->weaponids[0]].firstfree = 1;
916 weapons[victim->weaponids[0]].physics = 1;
917 victim->num_weapons--;
918 if (victim->num_weapons) {
919 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
920 if (victim->weaponstuck == victim->num_weapons)
921 victim->weaponstuck = 0;
924 victim->weaponactive = -1;
925 for (int j = 0; j < numplayers; j++) {
926 Person::players[j]->wentforweapon = 0;
930 animTarget = staffhitreversedanim;
931 animCurrent = staffhitreversedanim;
932 victim->animCurrent = staffhitreversalanim;
933 victim->animTarget = staffhitreversalanim;
935 if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
936 if (victim->weaponactive != -1) {
937 victim->throwtogglekeydown = 1;
938 weapons[victim->weaponids[0]].owner = -1;
939 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
940 if (weapons[victim->weaponids[0]].velocity.x == 0)
941 weapons[victim->weaponids[0]].velocity.x = .1;
942 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
943 weapons[victim->weaponids[0]].missed = 1;
944 weapons[victim->weaponids[0]].freetime = 0;
945 weapons[victim->weaponids[0]].firstfree = 1;
946 weapons[victim->weaponids[0]].physics = 1;
947 victim->num_weapons--;
948 if (victim->num_weapons) {
949 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
950 if (victim->weaponstuck == victim->num_weapons)
951 victim->weaponstuck = 0;
954 victim->weaponactive = -1;
955 for (int j = 0; j < numplayers; j++) {
956 Person::players[j]->wentforweapon = 0;
959 animTarget = staffspinhitreversedanim;
960 animCurrent = staffspinhitreversedanim;
961 victim->animCurrent = staffspinhitreversalanim;
962 victim->animTarget = staffspinhitreversalanim;
964 if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
965 if (victim->weaponactive != -1) {
966 victim->throwtogglekeydown = 1;
967 weapons[victim->weaponids[0]].owner = -1;
968 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
969 if (weapons[victim->weaponids[0]].velocity.x == 0)
970 weapons[victim->weaponids[0]].velocity.x = .1;
971 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
972 weapons[victim->weaponids[0]].missed = 1;
973 weapons[victim->weaponids[0]].freetime = 0;
974 weapons[victim->weaponids[0]].firstfree = 1;
975 weapons[victim->weaponids[0]].physics = 1;
976 victim->num_weapons--;
977 if (victim->num_weapons) {
978 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
979 if (victim->weaponstuck == victim->num_weapons)
980 victim->weaponstuck = 0;
983 victim->weaponactive = -1;
984 for (int j = 0; j < numplayers; j++) {
985 Person::players[j]->wentforweapon = 0;
988 animTarget = swordslashreversedanim;
989 animCurrent = swordslashreversedanim;
990 victim->animCurrent = swordslashreversalanim;
991 victim->animTarget = swordslashreversalanim;
993 if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
994 if (victim->weaponactive != -1) {
995 victim->throwtogglekeydown = 1;
996 weapons[victim->weaponids[0]].owner = -1;
997 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
998 if (weapons[victim->weaponids[0]].velocity.x == 0)
999 weapons[victim->weaponids[0]].velocity.x = .1;
1000 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
1001 weapons[victim->weaponids[0]].missed = 1;
1002 weapons[victim->weaponids[0]].freetime = 0;
1003 weapons[victim->weaponids[0]].firstfree = 1;
1004 weapons[victim->weaponids[0]].physics = 1;
1005 victim->num_weapons--;
1006 if (victim->num_weapons) {
1007 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1008 if (victim->weaponstuck == victim->num_weapons)
1009 victim->weaponstuck = 0;
1012 victim->weaponactive = -1;
1013 for (int j = 0; j < numplayers; j++) {
1014 Person::players[j]->wentforweapon = 0;
1017 animTarget = knifeslashreversedanim;
1018 animCurrent = knifeslashreversedanim;
1019 victim->animCurrent = knifeslashreversalanim;
1020 victim->animTarget = knifeslashreversalanim;
1022 if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim && animTarget != swordslashanim) {
1023 victim->targettilt2 = targettilt2;
1024 victim->frameCurrent = frameCurrent;
1025 victim->frameTarget = frameTarget;
1026 victim->target = target;
1027 victim->velocity = 0;
1028 victim->oldcoords = victim->coords;
1029 victim->coords = coords;
1030 victim->targetyaw = targetyaw;
1031 victim->yaw = targetyaw;
1032 victim->victim = this->shared_from_this();
1034 if (animTarget == winduppunchanim) {
1035 animTarget = winduppunchblockedanim;
1036 victim->animTarget = blockhighleftanim;
1037 victim->frameTarget = 1;
1038 victim->target = .5;
1039 victim->victim = this->shared_from_this();
1040 victim->targetyaw = targetyaw + 180;
1042 if (animTarget == wolfslapanim) {
1043 animTarget = winduppunchblockedanim;
1044 victim->animTarget = blockhighleftanim;
1045 victim->frameTarget = 1;
1046 victim->target = .5;
1047 victim->victim = this->shared_from_this();
1048 victim->targetyaw = targetyaw + 180;
1050 if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) {
1051 animTarget = swordslashparriedanim;
1052 parriedrecently = .4;
1053 victim->parriedrecently = 0;
1054 victim->animTarget = swordslashparryanim;
1055 victim->frameTarget = 1;
1056 victim->target = .5;
1057 victim->victim = this->shared_from_this();
1058 victim->targetyaw = targetyaw + 180;
1060 if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
1061 if (victim->weaponactive != -1) {
1062 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1063 if (weapons[victim->weaponids[0]].getType() == staff)
1064 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1065 if (weapons[weaponids[0]].getType() == staff)
1066 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1067 emit_sound_at(swordstaffsound, victim->coords);
1069 emit_sound_at(metalhitsound, victim->coords);
1073 victim->Puff(righthand);
1075 victim->frameTarget = 0;
1076 victim->animTarget = staggerbackhighanim;
1077 victim->targetyaw = targetyaw + 180;
1079 weapons[victim->weaponids[0]].owner = -1;
1080 aim = DoRotation(facing, 0, 90, 0) * 21;
1082 weapons[victim->weaponids[0]].velocity = aim * -.2;
1083 weapons[victim->weaponids[0]].tipvelocity = aim;
1084 weapons[victim->weaponids[0]].missed = 1;
1085 weapons[victim->weaponids[0]].hitsomething = 0;
1086 weapons[victim->weaponids[0]].freetime = 0;
1087 weapons[victim->weaponids[0]].firstfree = 1;
1088 weapons[victim->weaponids[0]].physics = 1;
1089 victim->num_weapons--;
1090 if (victim->num_weapons) {
1091 victim->weaponids[0] = victim->weaponids[num_weapons];
1092 if (victim->weaponstuck == victim->num_weapons)
1093 victim->weaponstuck = 0;
1095 victim->weaponactive = -1;
1096 for (int i = 0; i < numplayers; i++) {
1097 Person::players[i]->wentforweapon = 0;
1101 if (abs(Random() % 20) == 0) {
1102 if (weaponactive != -1) {
1103 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1104 if (weapons[victim->weaponids[0]].getType() == staff)
1105 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1106 if (weapons[weaponids[0]].getType() == staff)
1107 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1109 emit_sound_at(swordstaffsound, coords);
1111 emit_sound_at(metalhitsound, coords);
1119 animTarget = staggerbackhighanim;
1120 targetyaw = targetyaw + 180;
1122 weapons[weaponids[0]].owner = -1;
1123 aim = DoRotation(facing, 0, 90, 0) * 21;
1125 weapons[weaponids[0]].velocity = aim * -.2;
1126 weapons[weaponids[0]].tipvelocity = aim;
1127 weapons[weaponids[0]].hitsomething = 0;
1128 weapons[weaponids[0]].missed = 1;
1129 weapons[weaponids[0]].freetime = 0;
1130 weapons[weaponids[0]].firstfree = 1;
1131 weapons[weaponids[0]].physics = 1;
1134 weaponids[0] = weaponids[num_weapons];
1135 if (weaponstuck == num_weapons)
1139 for (int i = 0; i < numplayers; i++) {
1140 Person::players[i]->wentforweapon = 0;
1147 if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) {
1148 if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) {
1149 victim->animTarget = dodgebackanim;
1150 victim->frameTarget = 0;
1154 rotatetarget = coords - victim->coords;
1155 Normalise(&rotatetarget);
1156 victim->targetyaw = -asin(0 - rotatetarget.x);
1157 victim->targetyaw *= 360 / 6.28;
1158 if (rotatetarget.z < 0)
1159 victim->targetyaw = 180 - victim->targetyaw;
1161 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1163 victim->lastattack3 = victim->lastattack2;
1164 victim->lastattack2 = victim->lastattack;
1165 victim->lastattack = victim->animTarget;
1167 victim->animTarget = sweepanim;
1168 victim->frameTarget = 0;
1172 rotatetarget = coords - victim->coords;
1173 Normalise(&rotatetarget);
1174 victim->targetyaw = -asin(0 - rotatetarget.x);
1175 victim->targetyaw *= 360 / 6.28;
1176 if (rotatetarget.z < 0)
1177 victim->targetyaw = 180 - victim->targetyaw;
1179 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1181 victim->lastattack3 = victim->lastattack2;
1182 victim->lastattack2 = victim->lastattack;
1183 victim->lastattack = victim->animTarget;
1188 victim->velocity = 0;
1190 if (aitype != playercontrolled)
1192 if (aitype != playercontrolled && Random() % 3 == 0 && escapednum < 2 && difficulty == 2)
1194 if (aitype != playercontrolled && Random() % 5 == 0 && escapednum < 2 && difficulty == 1)
1196 if (aitype != playercontrolled && Random() % 10 == 0 && escapednum < 2 && difficulty == 0)
1199 if (victim->id == 0 && animation[victim->animTarget].attack == reversal)
1206 void Person::DoDamage(float howmuch)
1208 // subtract health (temporary?)
1209 if (tutoriallevel != 1)
1210 damage += howmuch / power;
1213 damagedealt += howmuch / power;
1215 damagetaken += howmuch / power;
1218 if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo))
1221 if (tutoriallevel != 1)
1222 permanentdamage += howmuch / 2 / power;
1223 if (tutoriallevel != 1)
1224 superpermanentdamage += howmuch / 4 / power;
1226 if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2)
1228 if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt)
1232 camerashake += howmuch / 100;
1233 if (id == 0 && ((howmuch > 50 && damage > damagetolerance / 2)))
1234 blackout = damage / damagetolerance;
1239 if (aitype == passivetype && damage < damagetolerance && ((tutoriallevel != 1 || cananger) && hostile))
1240 aitype = attacktypecutoff;
1241 if (tutoriallevel != 1 && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
1242 if (abs(Random() % 2) == 0) {
1243 aitype = gethelptype;
1246 aitype = attacktypecutoff;
1250 if (howmuch > damagetolerance * 50 && skeleton.free != 2) {
1253 for (int i = 0; i < skeleton.num_joints; i++) {
1255 flatvelocity2 = velocity;
1257 flatvelocity2 = skeleton.joints[i].velocity;
1259 flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
1261 flatfacing2 = skeleton.joints[i].position * scale + coords;
1262 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1263 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1264 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1265 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1266 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1267 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1270 emit_sound_at(splattersound, coords);
1279 if (!dead && creature == wolftype) {
1280 award_bonus(0, Wolfbonus);
1287 if (tutoriallevel != 1 || id == 0)
1288 if (speechdelay <= 0 && !dead && aitype != playercontrolled) {
1289 int whichsound = -1;
1291 if (creature == wolftype) {
1292 int i = abs(Random() % 2);
1294 whichsound = snarlsound;
1296 whichsound = snarl2sound;
1297 envsound[numenvsounds] = coords;
1298 envsoundvol[numenvsounds] = 16;
1299 envsoundlife[numenvsounds] = .4;
1302 if (creature == rabbittype) {
1303 int i = abs(Random() % 2);
1305 whichsound = rabbitpainsound;
1306 if (i == 1 && damage > damagetolerance)
1307 whichsound = rabbitpain1sound;
1308 envsound[numenvsounds] = coords;
1309 envsoundvol[numenvsounds] = 16;
1310 envsoundlife[numenvsounds] = .4;
1312 //if(i==2)whichsound=rabbitpain2sound;
1315 if (whichsound != -1) {
1316 emit_sound_at(whichsound, coords);
1321 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1322 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1326 * calculate/animate head facing direction?
1328 void Person::DoHead()
1330 static XYZ rotatearound;
1332 static float lookspeed = 500;
1334 if (!freeze && !winfreeze) {
1337 targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100;
1338 targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100;
1340 while (targetheadyaw > 180)targetheadyaw -= 360;
1341 while (targetheadyaw < -180)targetheadyaw += 360;
1343 if (targetheadyaw > 160)
1344 targetheadpitch = targetheadpitch * -1;
1345 if (targetheadyaw < -160)
1346 targetheadpitch = targetheadpitch * -1;
1347 if (targetheadyaw > 160)
1348 targetheadyaw = targetheadyaw - 180;
1349 if (targetheadyaw < -160)
1350 targetheadyaw = targetheadyaw + 180;
1352 if (targetheadpitch > 120)
1353 targetheadpitch = 120;
1354 if (targetheadpitch < -120)
1355 targetheadpitch = -120;
1356 if (targetheadyaw > 120)
1357 targetheadyaw = 120;
1358 if (targetheadyaw < -120)
1359 targetheadyaw = -120;
1362 targetheadpitch = 0;
1364 if (targetheadyaw > 80)
1366 if (targetheadyaw < -80)
1367 targetheadyaw = -80;
1368 if (targetheadpitch > 50)
1369 targetheadpitch = 50;
1370 if (targetheadpitch < -50)
1371 targetheadpitch = -50;
1374 if (abs(headyaw - targetheadyaw) < multiplier * lookspeed)
1375 headyaw = targetheadyaw;
1376 else if (headyaw > targetheadyaw) {
1377 headyaw -= multiplier * lookspeed;
1378 } else if (headyaw < targetheadyaw) {
1379 headyaw += multiplier * lookspeed;
1382 if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2)
1383 headpitch = targetheadpitch;
1384 else if (headpitch > targetheadpitch) {
1385 headpitch -= multiplier * lookspeed / 2;
1386 } else if (headpitch < targetheadpitch) {
1387 headpitch += multiplier * lookspeed / 2;
1390 rotatearound = jointPos(neck);
1391 jointPos(head) = rotatearound + DoRotation(jointPos(head) - rotatearound, headpitch, 0, 0);
1395 if (animTarget != bounceidleanim && animTarget != fightidleanim && animTarget != wolfidle && animTarget != knifefightidleanim && animTarget != drawrightanim && animTarget != drawleftanim && animTarget != walkanim) {
1396 facing = DoRotation(facing, headpitch * .4, 0, 0);
1397 facing = DoRotation(facing, 0, headyaw * .4, 0);
1400 if (animTarget == bounceidleanim || animTarget == fightidleanim || animTarget == wolfidle || animTarget == knifefightidleanim || animTarget == drawrightanim || animTarget == drawleftanim) {
1401 facing = DoRotation(facing, headpitch * .8, 0, 0);
1402 facing = DoRotation(facing, 0, headyaw * .8, 0);
1405 if (animTarget == walkanim) {
1406 facing = DoRotation(facing, headpitch * .6, 0, 0);
1407 facing = DoRotation(facing, 0, headyaw * .6, 0);
1410 skeleton.specialforward[0] = facing;
1411 //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1413 for (i = 0; i < skeleton.num_muscles; i++) {
1414 if (skeleton.muscles[i].visible && (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)) {
1415 skeleton.FindRotationMuscle(i, animTarget);
1422 * ragdolls character?
1424 void Person::RagDoll(bool checkcollision)
1429 if (!skeleton.free) {
1432 if (id == 0 && isFlip())
1439 facing = DoRotation(facing, 0, yaw, 0);
1441 skeleton.freetime = 0;
1443 skeleton.longdead = 0;
1446 skeleton.broken = 0;
1447 skeleton.spinny = 1;
1449 skeleton.freefall = 1;
1451 if (!isnormal(velocity.x)) velocity.x = 0;
1452 if (!isnormal(velocity.y)) velocity.y = 0;
1453 if (!isnormal(velocity.z)) velocity.z = 0;
1454 if (!isnormal(yaw)) yaw = 0;
1455 if (!isnormal(coords.x)) coords = 0;
1456 if (!isnormal(tilt)) tilt = 0;
1457 if (!isnormal(tilt2)) tilt2 = 0;
1459 for (i = 0; i < skeleton.num_joints; i++) {
1460 skeleton.joints[i].delay = 0;
1461 skeleton.joints[i].locked = 0;
1462 skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1463 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0);
1464 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = skeleton.joints[i].position;
1465 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = coords;
1466 skeleton.joints[i].position.y += .1;
1467 skeleton.joints[i].oldposition = skeleton.joints[i].position;
1468 skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords;
1471 for (i = 0; i < skeleton.num_joints; i++) {
1472 skeleton.joints[i].velocity = 0;
1473 skeleton.joints[i].velchange = 0;
1475 skeleton.DoConstraints(&coords, &scale);
1476 if (animation[animCurrent].height == lowheight || animation[animTarget].height == lowheight) {
1477 skeleton.DoConstraints(&coords, &scale);
1478 skeleton.DoConstraints(&coords, &scale);
1479 skeleton.DoConstraints(&coords, &scale);
1480 skeleton.DoConstraints(&coords, &scale);
1483 speed = animation[animTarget].speed[frameTarget] * 2;
1484 if (animation[animCurrent].speed[frameCurrent] > animation[animTarget].speed[frameTarget]) {
1485 speed = animation[animCurrent].speed[frameCurrent] * 2;
1488 speed = transspeed * 2;
1492 for (i = 0; i < skeleton.num_joints; i++) {
1493 if ((animation[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && animation[animCurrent].height == animation[animTarget].height)
1494 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);
1496 skeleton.joints[i].velocity = velocity / scale + facing * 5;
1497 change.x = (float)(Random() % 100) / 100;
1498 change.y = (float)(Random() % 100) / 100;
1499 change.z = (float)(Random() % 100) / 100;
1500 skeleton.joints[i].velocity += change;
1501 skeleton.joints[abs(Random() % skeleton.num_joints)].velocity -= change;
1503 change.x = (float)(Random() % 100) / 100;
1504 change.y = (float)(Random() % 100) / 100;
1505 change.z = (float)(Random() % 100) / 100;
1506 skeleton.joints[i].velchange += change;
1507 skeleton.joints[abs(Random() % skeleton.num_joints)].velchange -= change;
1510 if (checkcollision) {
1517 for (j = 0; j < skeleton.num_joints; j++) {
1518 average += skeleton.joints[j].position;
1522 coords += average * scale;
1523 for (j = 0; j < skeleton.num_joints; j++) {
1524 skeleton.joints[j].position -= average;
1527 whichpatchx = coords.x / (terrain.size / subdivision * terrain.scale);
1528 whichpatchz = coords.z / (terrain.size / subdivision * terrain.scale);
1529 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
1530 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
1531 i = terrain.patchobjects[whichpatchx][whichpatchz][l];
1534 if (SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.yaw[i], &objects.model[i]) != -1) {
1535 coords.x = lowpoint.x;
1536 coords.z = lowpoint.z;
1545 for (i = 0; i < skeleton.num_joints; i++) {
1546 velocity += skeleton.joints[i].velocity * scale;
1548 velocity /= skeleton.num_joints;
1551 if (Random() % 2 == 0) {
1552 if (weaponactive != -1 && animTarget != rabbitkickanim && num_weapons > 0) {
1553 weapons[weaponids[0]].owner = -1;
1554 weapons[weaponids[0]].hitsomething = 0;
1555 weapons[weaponids[0]].velocity = jointVel(righthand) * scale * -.3;
1556 weapons[weaponids[0]].velocity.x += .01;
1557 weapons[weaponids[0]].tipvelocity = jointVel(righthand) * scale;
1558 weapons[weaponids[0]].missed = 1;
1559 weapons[weaponids[0]].freetime = 0;
1560 weapons[weaponids[0]].firstfree = 1;
1561 weapons[weaponids[0]].physics = 1;
1564 weaponids[0] = weaponids[num_weapons];
1565 if (weaponstuck == num_weapons)
1569 for (i = 0; i < numplayers; i++) {
1570 Person::players[i]->wentforweapon = 0;
1575 animTarget = bounceidleanim;
1576 animCurrent = bounceidleanim;
1586 void Person::FootLand(int which, float opacity)
1588 static XYZ terrainlight;
1589 static XYZ footvel, footpoint;
1590 if (opacity >= 1 || skiddelay <= 0)
1594 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1596 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1597 //footpoint.y=coords.y;
1598 if (distsq(&footpoint, &viewer))
1599 Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity);
1600 } else if (environment == snowyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1601 footvel = velocity / 5;
1605 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1607 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1608 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1609 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1610 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1611 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity);
1612 if (opacity >= 1 || detail == 2)
1614 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1615 terrain.MakeDecal(footprintdecal, footpoint, .2, 1 * opacity, yaw);
1616 } else if (environment == grassyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1617 footvel = velocity / 5;
1621 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1623 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1624 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1625 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1626 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1627 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity);
1628 } else if (environment == desertenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1629 footvel = velocity / 5;
1633 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1635 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1636 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1637 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1638 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1639 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity);
1640 if (opacity >= 1 || detail == 2)
1642 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1643 terrain.MakeDecal(footprintdecal, footpoint, .2, .25 * opacity, yaw);
1644 } else if (isLanding() || animTarget == jumpupanim || isLandhard()) {
1645 footvel = velocity / 5;
1649 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1651 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1652 //footpoint.y=coords.y;
1653 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1654 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity);
1659 * make a puff effect at a body part (dust effect?)
1661 void Person::Puff(int whichlabel)
1663 static XYZ footvel, footpoint;
1666 footpoint = DoRotation(jointPos(whichlabel), 0, yaw, 0) * scale + coords;
1667 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .9, .3);
1671 * I think I added this in an attempt to clean up code
1673 void Person::setAnimation(int animation)
1675 animTarget = animation;
1684 void Person::DoAnimations()
1686 if (!skeleton.free) {
1688 static float oldtarget;
1690 if (isIdle() && animCurrent != getIdle())
1691 normalsupdatedelay = 0;
1693 if (animTarget == tempanim || animCurrent == tempanim) {
1694 animation[tempanim] = tempanimation;
1696 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
1702 vel[0] = velocity.x;
1703 vel[1] = velocity.y;
1704 vel[2] = velocity.z;
1707 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1708 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
1710 if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z))
1712 if (!crouchkeydown && velocity.y >= -15)
1715 if ((animCurrent == jumpupanim || animTarget == jumpdownanim)/*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) {
1720 targfacing = DoRotation(targfacing, 0, targetyaw, 0);
1722 if (normaldotproduct(targfacing, velocity) >= -.3)
1723 animTarget = flipanim;
1725 animTarget = backflipanim;
1726 crouchtogglekeydown = 1;
1734 if (animation[animTarget].attack != reversed)
1736 if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) {
1737 crouchtogglekeydown = 0;
1738 if (aitype == playercontrolled)
1741 if (!crouchtogglekeydown && animation[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain))
1744 crouchtogglekeydown = 1;
1748 if (animation[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) {
1750 normalsupdatedelay = 0;
1754 if (animTarget == rollanim && frameTarget == 3 && onfire) {
1756 emit_sound_at(fireendsound, coords);
1757 pause_sound(stream_firesound);
1761 if (animTarget == rabbittacklinganim && frameTarget == 1) {
1762 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->animTarget].attack==neutral&&victim->id!=0)Reverse();
1763 if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0)
1765 if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) {
1766 if (normaldotproduct(victim->facing, facing) > 0)
1767 victim->animTarget = rabbittackledbackanim;
1769 victim->animTarget = rabbittackledfrontanim;
1770 victim->frameTarget = 2;
1773 victim->targetyaw = yaw;
1774 if (victim->aitype == gethelptype)
1775 victim->DoDamage(victim->damagetolerance - victim->damage);
1776 //victim->DoDamage(30);
1777 if (creature == wolftype) {
1779 emit_sound_at(clawslicesound, victim->coords);
1781 victim->DoBloodBig(1 / victim->armorhead, 210);
1783 award_bonus(id, TackleBonus,
1784 victim->aitype == gethelptype ? 50 : 0);
1788 if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (animation[animTarget].label[frameTarget] || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) {
1789 if (weapons[weaponids[0]].getType() == knife) {
1790 if (weaponactive == -1)
1792 else if (weaponactive == 0)
1795 if (weaponactive == -1) {
1796 emit_sound_at(knifesheathesound, coords);
1798 if (weaponactive != -1) {
1799 emit_sound_at(knifedrawsound, coords, 128);
1802 drawtogglekeydown = 1;
1805 if (tutoriallevel != 1 || id == 0)
1806 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1809 if (terrain.getOpacity(coords.x, coords.z) < .2) {
1810 if (animation[animTarget].label[frameTarget] == 1)
1811 whichsound = footstepsound;
1813 whichsound = footstepsound2;
1814 if (animation[animTarget].label[frameTarget] == 1)
1816 if (animation[animTarget].label[frameTarget] == 2)
1818 if (animation[animTarget].label[frameTarget] == 3 && isRun()) {
1824 if (terrain.getOpacity(coords.x, coords.z) >= .2) {
1825 if (animation[animTarget].label[frameTarget] == 1)
1826 whichsound = footstepsound3;
1828 whichsound = footstepsound4;
1832 if (animation[animTarget].label[frameTarget] == 1)
1833 whichsound = footstepsound3;
1835 whichsound = footstepsound4;
1837 if (animation[animTarget].label[frameTarget] == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
1838 if (animation[animTarget].attack != neutral) {
1839 i = abs(Random() % 3);
1841 whichsound = lowwhooshsound;
1843 whichsound = midwhooshsound;
1845 whichsound = highwhooshsound;
1847 if (animation[animTarget].attack == neutral)
1848 whichsound = movewhooshsound;
1849 } else if (animation[animTarget].label[frameTarget] == 4)
1850 whichsound = knifeswishsound;
1851 if (animation[animTarget].label[frameTarget] == 8 && tutoriallevel != 1)
1852 whichsound = landsound2;
1854 emit_sound_at(whichsound, coords, 256.);
1857 if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
1858 envsound[numenvsounds] = coords;
1859 if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim)
1860 envsoundvol[numenvsounds] = 15;
1862 envsoundvol[numenvsounds] = 6;
1863 envsoundlife[numenvsounds] = .4;
1867 if (animation[animTarget].label[frameTarget] == 3) {
1869 emit_sound_at(whichsound, coords, 128.);
1874 if (tutoriallevel != 1 || id == 0)
1875 if (speechdelay <= 0)
1876 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
1877 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1878 int whichsound = -1;
1879 if (animation[animTarget].label[frameTarget] == 4 && aitype != playercontrolled) {
1880 if (animation[animTarget].attack != neutral) {
1881 i = abs(Random() % 4);
1882 if (creature == rabbittype) {
1883 if (i == 0) whichsound = rabbitattacksound;
1884 if (i == 1) whichsound = rabbitattack2sound;
1885 if (i == 2) whichsound = rabbitattack3sound;
1886 if (i == 3) whichsound = rabbitattack4sound;
1888 if (creature == wolftype) {
1889 if (i == 0) whichsound = barksound;
1890 if (i == 1) whichsound = bark2sound;
1891 if (i == 2) whichsound = bark3sound;
1892 if (i == 3) whichsound = barkgrowlsound;
1896 //if(animation[animTarget].attack==neutral)whichsound=movewhooshsound;
1898 //else if(animation[animTarget].label[frameTarget]==4)whichsound=knifeswishsound;
1899 //if(animation[animTarget].label[frameTarget]==8)whichsound=landsound2;
1901 if (whichsound != -1) {
1902 emit_sound_at(whichsound, coords);
1908 if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) {
1914 currentoffset = targetoffset;
1915 frameTarget = frameCurrent;
1916 animCurrent = animTarget;
1919 if (animTarget == removeknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1920 for (i = 0; i < weapons.size(); i++) {
1921 if (weapons[i].owner == -1)
1922 if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
1923 if (distsq(&coords, &weapons[i].position) >= 1) {
1924 if (weapons[i].getType() != staff) {
1925 emit_sound_at(knifedrawsound, coords, 128.);
1929 weapons[i].owner = id;
1930 if (num_weapons > 0) {
1931 weaponids[num_weapons] = weaponids[0];
1940 if (animTarget == crouchremoveknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1941 for (i = 0; i < weapons.size(); i++) {
1942 bool willwork = true;
1943 if (weapons[i].owner != -1)
1944 if (Person::players[weapons[i].owner]->weaponstuck != -1)
1945 if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == i)
1946 if (Person::players[weapons[i].owner]->num_weapons > 1)
1948 if ((weapons[i].owner == -1) || (hasvictim && weapons[i].owner == victim->id && victim->skeleton.free))
1949 if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) {
1950 if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
1951 bool fleshstuck = false;
1952 if (weapons[i].owner != -1)
1953 if (victim->weaponstuck != -1) {
1954 if (victim->weaponids[victim->weaponstuck] == i) {
1959 emit_sound_at(fleshstabremovesound, coords, 128.);
1961 if (weapons[i].getType() != staff) {
1962 emit_sound_at(knifedrawsound, coords, 128.);
1966 if (weapons[i].owner != -1) {
1968 victim = Person::players[weapons[i].owner];
1969 if (victim->num_weapons == 1)
1970 victim->num_weapons = 0;
1972 victim->num_weapons = 1;
1974 //victim->weaponactive=-1;
1975 victim->skeleton.longdead = 0;
1976 victim->skeleton.free = 1;
1977 victim->skeleton.broken = 0;
1979 for (int j = 0; j < victim->skeleton.num_joints; j++) {
1980 victim->skeleton.joints[j].velchange = 0;
1981 victim->skeleton.joints[j].locked = 0;
1987 Normalise(&relative);
1988 XYZ footvel, footpoint;
1990 footpoint = weapons[i].position;
1991 if (victim->weaponstuck != -1) {
1992 if (victim->weaponids[victim->weaponstuck] == i) {
1994 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
1995 weapons[i].bloody = 2;
1996 weapons[i].blooddrip = 5;
1997 victim->weaponstuck = -1;
2000 if (victim->num_weapons > 0) {
2001 if (victim->weaponstuck != 0 && victim->weaponstuck != -1)
2002 victim->weaponstuck = 0;
2003 if (victim->weaponids[0] == i)
2004 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
2007 victim->jointVel(abdomen) += relative * 6;
2008 victim->jointVel(neck) += relative * 6;
2009 victim->jointVel(rightshoulder) += relative * 6;
2010 victim->jointVel(leftshoulder) += relative * 6;
2012 weapons[i].owner = id;
2013 if (num_weapons > 0) {
2014 weaponids[num_weapons] = weaponids[0];
2023 if (animCurrent == drawleftanim && animation[animTarget].label[frameCurrent] == 5) {
2024 if (weaponactive == -1)
2026 else if (weaponactive == 0) {
2028 if (num_weapons == 2) {
2030 buffer = weaponids[0];
2031 weaponids[0] = weaponids[1];
2032 weaponids[1] = buffer;
2035 if (weaponactive == -1) {
2036 emit_sound_at(knifesheathesound, coords, 128.);
2038 if (weaponactive != -1) {
2039 emit_sound_at(knifedrawsound, coords, 128.);
2044 if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) {
2045 XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0);
2046 Normalise(&rotatetarget);
2047 targetyaw = -asin(0 - rotatetarget.x);
2048 targetyaw *= 360 / 6.28;
2049 if (rotatetarget.z < 0)
2050 targetyaw = 180 - targetyaw;
2052 if (animTarget == walljumprightkickanim)
2054 if (animTarget == walljumpleftkickanim)
2060 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0))
2063 if (distsq(&victim->coords, &/*Person::players[i]->*/coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1)
2068 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) {
2069 animTarget = rabbittackleanim;
2071 emit_sound_at(jumpsound, coords);
2079 targetloc = velocity;
2080 Normalise(&targetloc);
2081 targetloc += coords;
2082 for (i = 0; i < numplayers; i++) {
2084 if (distsq(&targetloc, &Person::players[i]->coords) < closestdist || closestdist == 0) {
2085 closestdist = distsq(&targetloc, &Person::players[i]->coords);
2089 if (closestid != -1)
2090 if (closestdist < 5 && !Person::players[closestid]->dead && animation[Person::players[closestid]->animTarget].height != lowheight && Person::players[closestid]->animTarget != backhandspringanim) {
2092 victim = Person::players[closestid];
2093 coords = victim->coords;
2094 animCurrent = rabbittacklinganim;
2095 animTarget = rabbittacklinganim;
2099 if (coords.z != victim->coords.z || coords.x != victim->coords.x) {
2100 rotatetarget = coords - victim->coords;
2101 Normalise(&rotatetarget);
2102 targetyaw = -asin(0 - rotatetarget.x);
2103 targetyaw *= 360 / 6.28;
2104 if (rotatetarget.z < 0)
2105 targetyaw = 180 - targetyaw;
2107 if (animTarget != rabbitrunninganim) {
2108 emit_sound_at(jumpsound, coords, 128.);
2114 float damagemult = 1 * power;
2115 if (creature == wolftype)
2116 damagemult = 2.5 * power;
2118 damagemult /= victim->damagetolerance / 200;
2120 //if(onfire)damagemult=3;
2121 if ((animation[animTarget].attack == normalattack || animTarget == walljumprightkickanim || animTarget == walljumpleftkickanim) && (!feint) && (victim->skeleton.free != 2 || animTarget == killanim || animTarget == dropkickanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == staffgroundsmashanim)) {
2122 if (animTarget == spinkickanim && animation[animTarget].label[frameCurrent] == 5) {
2123 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2127 if (Random() % 2 || creature == wolftype) {
2130 if (creature == wolftype)
2133 if (tutoriallevel != 1) {
2134 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2136 if (creature == wolftype) {
2137 emit_sound_at(clawslicesound, victim->coords, 128.);
2139 victim->DoBloodBig(2 / victim->armorhead, 175);
2143 relative = victim->coords - coords;
2145 Normalise(&relative);
2146 relative = DoRotation(relative, 0, -90, 0);
2147 for (i = 0; i < victim->skeleton.num_joints; i++) {
2148 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2150 victim->jointVel(head) += relative * damagemult * 200;
2153 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2159 if (animTarget == wolfslapanim && animation[animTarget].label[frameCurrent] == 5) {
2160 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2164 if (Random() % 2 || creature == wolftype) {
2166 if (creature == wolftype)
2169 emit_sound_at(whooshhitsound, victim->coords);
2170 if (creature == wolftype) {
2171 emit_sound_at(clawslicesound, victim->coords, 128.);
2173 victim->DoBloodBig(2, 175);
2177 relative = victim->coords - coords;
2179 Normalise(&relative);
2181 Normalise(&relative);
2182 relative = DoRotation(relative, 0, 90, 0);
2183 for (i = 0; i < victim->skeleton.num_joints; i++) {
2184 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2186 victim->jointVel(head) += relative * damagemult * 100;
2189 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2193 if (animTarget == walljumprightkickanim && animation[animTarget].label[frameCurrent] == 5) {
2194 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2200 if (tutoriallevel != 1) {
2201 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2203 if (creature == wolftype) {
2204 emit_sound_at(clawslicesound, victim->coords, 128.);
2206 victim->DoBloodBig(2 / victim->armorhead, 175);
2212 Normalise(&relative);
2213 relative = DoRotation(relative, 0, -90, 0);
2214 for (i = 0; i < victim->skeleton.num_joints; i++) {
2215 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2217 victim->jointVel(head) += relative * damagemult * 200;
2220 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2222 if (victim->damage > victim->damagetolerance)
2223 award_bonus(id, style);
2229 if (animTarget == walljumpleftkickanim && animation[animTarget].label[frameCurrent] == 5) {
2230 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2236 if (tutoriallevel != 1) {
2237 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2239 if (creature == wolftype) {
2240 emit_sound_at(clawslicesound, victim->coords, 128.);
2242 victim->DoBloodBig(2 / victim->armorhead, 175);
2248 Normalise(&relative);
2249 relative = DoRotation(relative, 0, 90, 0);
2250 for (i = 0; i < victim->skeleton.num_joints; i++) {
2251 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2253 victim->jointVel(head) += relative * damagemult * 200;
2256 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2258 if (victim->damage > victim->damagetolerance)
2259 award_bonus(id, style);
2265 if (animTarget == blockhighleftstrikeanim && animation[animTarget].label[frameCurrent] == 5) {
2266 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2274 emit_sound_at(whooshhitsound, victim->coords);
2277 relative = victim->coords - coords;
2279 Normalise(&relative);
2280 for (i = 0; i < victim->skeleton.num_joints; i++) {
2281 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
2283 victim->jointVel(head) += relative * damagemult * 100;
2286 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2290 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 8) {
2291 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) {
2295 emit_sound_at(whooshhitsound, victim->coords, 128.);
2297 victim->skeleton.longdead = 0;
2298 victim->skeleton.free = 1;
2299 victim->skeleton.broken = 0;
2300 victim->skeleton.spinny = 1;
2302 for (i = 0; i < victim->skeleton.num_joints; i++) {
2303 victim->skeleton.joints[i].velchange = 0;
2304 victim->skeleton.joints[i].delay = 0;
2305 victim->skeleton.joints[i].locked = 0;
2306 //victim->skeleton.joints[i].velocity=0;
2312 Normalise(&relative);
2313 for (i = 0; i < victim->skeleton.num_joints; i++) {
2314 victim->skeleton.joints[i].velocity.y = relative.y * 10;
2315 victim->skeleton.joints[i].position.y += relative.y * .3;
2316 victim->skeleton.joints[i].oldposition.y += relative.y * .3;
2317 victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
2319 victim->Puff(abdomen);
2320 victim->jointVel(abdomen).y = relative.y * 400;
2324 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 5) {
2325 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) {
2329 if (tutoriallevel != 1) {
2330 emit_sound_at(heavyimpactsound, coords, 128.);
2333 relative = victim->coords - coords;
2335 Normalise(&relative);
2336 for (i = 0; i < victim->skeleton.num_joints; i++) {
2337 victim->skeleton.joints[i].velocity += relative * damagemult * 90;
2339 victim->Puff(abdomen);
2340 if (victim->dead != 2 && victim->permanentdamage > victim->damagetolerance - 250 && autoslomo) {
2344 victim->DoDamage(damagemult * 500 / victim->protectionhigh);
2345 victim->jointVel(abdomen) += relative * damagemult * 300;
2349 if (animTarget == dropkickanim && animation[animTarget].label[frameCurrent] == 7) {
2350 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) {
2354 if (tutoriallevel != 1) {
2355 emit_sound_at(thudsound, coords);
2358 victim->skeleton.longdead = 0;
2359 victim->skeleton.free = 1;
2360 victim->skeleton.broken = 0;
2361 victim->skeleton.spinny = 1;
2363 for (i = 0; i < victim->skeleton.num_joints; i++) {
2364 victim->skeleton.joints[i].velchange = 0;
2365 //victim->skeleton.joints[i].delay=0;
2366 victim->skeleton.joints[i].locked = 0;
2369 relative = victim->coords - coords;
2370 Normalise(&relative);
2372 Normalise(&relative);
2373 for (i = 0; i < victim->skeleton.num_joints; i++) {
2374 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2379 victim->Puff(abdomen);
2380 victim->DoDamage(damagemult * 20 / victim->protectionhigh);
2381 victim->jointVel(abdomen) += relative * damagemult * 200;
2390 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 5) {
2391 //if(id==0)camerashake+=.4;
2394 if (!victim->skeleton.free)
2398 terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360);
2399 emit_sound_at(knifesheathesound, coords, 128.);
2402 if (victim && hasvictim) {
2403 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2405 XYZ where, startpoint, endpoint, movepoint, colpoint;
2406 float rotationpoint;
2408 if (weapons[weaponids[weaponactive]].getType() == knife) {
2409 where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4);
2410 where -= victim->coords;
2411 if (!victim->skeleton.free)
2412 where = DoRotation(where, 0, -victim->yaw, 0);
2415 startpoint.y += 100;
2419 if (weapons[weaponids[weaponactive]].getType() == sword) {
2420 where = weapons[weaponids[weaponactive]].position;
2421 where -= victim->coords;
2422 if (!victim->skeleton.free)
2423 where = DoRotation(where, 0, -victim->yaw, 0);
2425 where = weapons[weaponids[weaponactive]].tippoint;
2426 where -= victim->coords;
2427 if (!victim->skeleton.free)
2428 where = DoRotation(where, 0, -victim->yaw, 0);
2431 if (weapons[weaponids[weaponactive]].getType() == staff) {
2432 where = weapons[weaponids[weaponactive]].position;
2433 where -= victim->coords;
2434 if (!victim->skeleton.free)
2435 where = DoRotation(where, 0, -victim->yaw, 0);
2437 where = weapons[weaponids[weaponactive]].tippoint;
2438 where -= victim->coords;
2439 if (!victim->skeleton.free)
2440 where = DoRotation(where, 0, -victim->yaw, 0);
2445 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
2447 if (whichtri != -1) {
2448 if (victim->dead != 2) {
2449 victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2));
2451 award_bonus(id, FinishedBonus);
2454 weapons[weaponids[weaponactive]].bloody = 2;
2456 victim->skeleton.longdead = 0;
2457 victim->skeleton.free = 1;
2458 victim->skeleton.broken = 0;
2460 for (i = 0; i < victim->skeleton.num_joints; i++) {
2461 victim->skeleton.joints[i].velchange = 0;
2462 victim->skeleton.joints[i].locked = 0;
2463 //victim->skeleton.joints[i].velocity=0;
2465 emit_sound_at(fleshstabsound, coords, 128);
2468 if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) {
2469 weapons[weaponids[weaponactive]].blooddrip += 5;
2470 weapons[weaponids[weaponactive]].blooddripdelay = 0;
2472 if (whichtri == -1) {
2474 emit_sound_at(knifesheathesound, coords, 128.);
2480 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 6) {
2482 emit_sound_at(knifedrawsound, coords, 128);
2485 if (victim && hasvictim) {
2486 XYZ footvel, footpoint;
2488 emit_sound_at(fleshstabremovesound, coords, 128.);
2491 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2493 if (weapons[weaponids[weaponactive]].getType() == sword) {
2494 XYZ where, startpoint, endpoint, movepoint;
2495 float rotationpoint;
2498 where = weapons[weaponids[weaponactive]].position;
2499 where -= victim->coords;
2500 if (!victim->skeleton.free)
2501 where = DoRotation(where, 0, -victim->yaw, 0);
2503 where = weapons[weaponids[weaponactive]].tippoint;
2504 where -= victim->coords;
2505 if (!victim->skeleton.free)
2506 where = DoRotation(where, 0, -victim->yaw, 0);
2511 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2512 footpoint += victim->coords;
2514 if (whichtri == -1) {
2515 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2518 if (weapons[weaponids[weaponactive]].getType() == staff) {
2519 XYZ where, startpoint, endpoint, movepoint;
2520 float rotationpoint;
2523 where = weapons[weaponids[weaponactive]].position;
2524 where -= victim->coords;
2525 if (!victim->skeleton.free)
2526 where = DoRotation(where, 0, -victim->yaw, 0);
2528 where = weapons[weaponids[weaponactive]].tippoint;
2529 where -= victim->coords;
2530 if (!victim->skeleton.free)
2531 where = DoRotation(where, 0, -victim->yaw, 0);
2536 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2537 footpoint += victim->coords;
2539 if (whichtri == -1) {
2540 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2543 hasvictim = victim->DoBloodBigWhere(2, 220, footpoint);
2545 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2546 victim->skeleton.longdead = 0;
2547 victim->skeleton.free = 1;
2548 victim->skeleton.broken = 0;
2550 for (i = 0; i < victim->skeleton.num_joints; i++) {
2551 victim->skeleton.joints[i].velchange = 0;
2552 victim->skeleton.joints[i].locked = 0;
2553 //victim->skeleton.joints[i].velocity=0;
2559 Normalise(&relative);
2560 //victim->Puff(abdomen);
2562 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2564 if (victim->bloodloss < victim->damagetolerance) {
2565 victim->bloodloss += 1000;
2569 victim->jointVel(abdomen) += relative * damagemult * 20;
2573 if (!hasvictim && onterrain) {
2574 weapons[weaponids[weaponactive]].bloody = 0;
2575 weapons[weaponids[weaponactive]].blooddrip = 0;
2579 if (animTarget == upunchanim && animation[animTarget].label[frameCurrent] == 5) {
2580 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2588 if (tutoriallevel != 1) {
2589 emit_sound_at(heavyimpactsound, victim->coords, 128);
2594 relative = victim->coords - coords;
2596 Normalise(&relative);
2597 for (i = 0; i < victim->skeleton.num_joints; i++) {
2598 victim->skeleton.joints[i].velocity = relative * 30;
2600 victim->jointVel(head) += relative * damagemult * 150;
2602 victim->frameTarget = 0;
2603 victim->animTarget = staggerbackhardanim;
2604 victim->targetyaw = targetyaw + 180;
2606 victim->stunned = 1;
2609 victim->Puff(abdomen);
2610 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2617 if (animTarget == winduppunchanim && animation[animTarget].label[frameCurrent] == 5) {
2618 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) {
2622 if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height != lowheight) {
2623 if (tutoriallevel != 1) {
2624 emit_sound_at(thudsound, victim->coords);
2626 } else if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height == lowheight) {
2627 if (tutoriallevel != 1) {
2628 emit_sound_at(whooshhitsound, victim->coords);
2631 if (tutoriallevel != 1) {
2632 emit_sound_at(heavyimpactsound, victim->coords);
2636 if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || animation[victim->animTarget].height == lowheight)
2639 relative = victim->coords - coords;
2641 Normalise(&relative);
2643 Normalise(&relative);
2644 for (i = 0; i < victim->skeleton.num_joints; i++) {
2645 victim->skeleton.joints[i].velocity = relative * 5;
2647 victim->jointVel(abdomen) += relative * damagemult * 400;
2649 victim->frameTarget = 0;
2650 victim->animTarget = staggerbackhardanim;
2651 victim->targetyaw = targetyaw + 180;
2653 victim->stunned = 1;
2655 victim->Puff(abdomen);
2656 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2662 if (animTarget == blockhighleftanim && animation[animTarget].label[frameCurrent] == 5) {
2663 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2664 if (victim->id == 0)
2666 emit_sound_at(landsound2, victim->coords);
2672 if (animTarget == swordslashparryanim && animation[animTarget].label[frameCurrent] == 5) {
2673 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2674 if (victim->id == 0)
2677 if (weaponactive != -1) {
2678 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2679 if (weapons[victim->weaponids[0]].getType() == staff)
2680 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2681 if (weapons[weaponids[0]].getType() == staff)
2682 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2684 emit_sound_at(swordstaffsound, victim->coords);
2686 emit_sound_at(metalhitsound, victim->coords);
2694 if (animTarget == knifethrowanim && animation[animTarget].label[frameCurrent] == 5) {
2695 if (weaponactive != -1) {
2698 weapons[weaponids[0]].owner = -1;
2699 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);
2701 /*if(victim->animTarget==jumpupanim||victim->animTarget==jumpdownanim){
2702 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2704 weapons[weaponids[0]].velocity = aim * 50;
2705 weapons[weaponids[0]].tipvelocity = aim * 50;
2706 weapons[weaponids[0]].missed = 0;
2707 weapons[weaponids[0]].hitsomething = 0;
2708 weapons[weaponids[0]].freetime = 0;
2709 weapons[weaponids[0]].firstfree = 1;
2710 weapons[weaponids[0]].physics = 0;
2713 weaponids[0] = weaponids[num_weapons];
2719 if (animTarget == knifeslashstartanim && animation[animTarget].label[frameCurrent] == 5) {
2721 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 &&/*animation[victim->animTarget].height!=lowheight&&*/victim->animTarget != dodgebackanim && victim->animTarget != rollanim) {
2723 if (tutoriallevel != 1)
2724 victim->DoBloodBig(1.5 / victim->armorhigh, 225);
2726 award_bonus(id, Slicebonus);
2727 if (tutoriallevel != 1) {
2728 emit_sound_at(knifeslicesound, victim->coords);
2730 //victim->jointVel(abdomen)+=relative*damagemult*200;
2731 if (animation[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
2732 if (victim->id != 0 || difficulty == 2) {
2733 victim->frameTarget = 0;
2734 victim->animTarget = staggerbackhardanim;
2735 victim->targetyaw = targetyaw + 180;
2739 victim->lowreversaldelay = 0;
2740 victim->highreversaldelay = 0;
2741 if (aitype != playercontrolled)
2742 weaponmissdelay = .6;
2744 if (tutoriallevel != 1)
2745 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2746 weapons[weaponids[weaponactive]].bloody = 1;
2747 if (tutoriallevel != 1)
2748 weapons[weaponids[weaponactive]].blooddrip += 3;
2750 XYZ footvel, footpoint;
2752 if (skeleton.free) {
2753 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2755 if (!skeleton.free) {
2756 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2758 if (tutoriallevel != 1) {
2760 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .6, .3);
2761 footvel = DoRotation(facing, 0, 90, 0) * .8;
2763 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2764 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2765 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
2766 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
2768 if (tutoriallevel == 1) {
2769 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .6, .3);
2771 victim->DoDamage(damagemult * 0);
2774 if (animTarget == swordslashanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2775 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) {
2776 if (victim->weaponactive == -1 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) {
2777 award_bonus(id, Slashbonus);
2779 if (tutoriallevel != 1) {
2780 if (normaldotproduct(victim->facing, victim->coords - coords) < 0)
2781 victim->DoBloodBig(2 / victim->armorhigh, 190);
2783 victim->DoBloodBig(2 / victim->armorhigh, 185);
2784 victim->deathbleeding = 1;
2785 emit_sound_at(swordslicesound, victim->coords);
2787 //victim->jointVel(abdomen)+=relative*damagemult*200;
2788 if (tutoriallevel != 1) {
2789 victim->frameTarget = 0;
2790 victim->animTarget = staggerbackhardanim;
2791 victim->targetyaw = targetyaw + 180;
2795 if (tutoriallevel != 1) {
2796 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2797 weapons[weaponids[weaponactive]].bloody = 1;
2798 weapons[weaponids[weaponactive]].blooddrip += 3;
2800 float bloodlossamount;
2801 bloodlossamount = 200 + abs((float)(Random() % 40)) - 20;
2802 victim->bloodloss += bloodlossamount / victim->armorhigh;
2803 //victim->bloodloss+=100*(6.5-distsq(&coords,&victim->coords));
2804 victim->DoDamage(damagemult * 0);
2806 XYZ footvel, footpoint;
2808 if (skeleton.free) {
2809 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2811 if (!skeleton.free) {
2812 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2815 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
2816 footvel = DoRotation(facing, 0, 90, 0) * .8;
2818 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2819 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2820 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
2821 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
2824 if (victim->weaponactive != -1) {
2825 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2826 if (weapons[victim->weaponids[0]].getType() == staff)
2827 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2828 if (weapons[weaponids[0]].getType() == staff)
2829 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2831 emit_sound_at(swordstaffsound, victim->coords);
2833 emit_sound_at(metalhitsound, victim->coords);
2839 victim->Puff(righthand);
2841 victim->frameTarget = 0;
2842 victim->animTarget = staggerbackhighanim;
2843 victim->targetyaw = targetyaw + 180;
2845 weapons[victim->weaponids[0]].owner = -1;
2846 aim = DoRotation(facing, 0, 90, 0) * 21;
2848 weapons[victim->weaponids[0]].velocity = aim * -.2;
2849 weapons[victim->weaponids[0]].tipvelocity = aim;
2850 weapons[victim->weaponids[0]].missed = 1;
2851 weapons[weaponids[0]].hitsomething = 0;
2852 weapons[victim->weaponids[0]].freetime = 0;
2853 weapons[victim->weaponids[0]].firstfree = 1;
2854 weapons[victim->weaponids[0]].physics = 1;
2855 victim->num_weapons--;
2856 if (victim->num_weapons) {
2857 victim->weaponids[0] = victim->weaponids[num_weapons];
2858 if (victim->weaponstuck == victim->num_weapons)
2859 victim->weaponstuck = 0;
2861 victim->weaponactive = -1;
2862 for (i = 0; i < numplayers; i++) {
2863 Person::players[i]->wentforweapon = 0;
2870 if (animTarget == staffhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2871 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2872 if (tutoriallevel != 1) {
2873 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 250;
2877 if (Random() % 2 || creature == wolftype) {
2880 emit_sound_at(staffheadsound, victim->coords);
2884 relative = victim->coords - coords;
2886 Normalise(&relative);
2887 relative = DoRotation(relative, 0, 90, 0);
2889 Normalise(&relative);
2890 for (i = 0; i < victim->skeleton.num_joints; i++) {
2891 victim->skeleton.joints[i].velocity += relative * damagemult * 60;
2893 victim->jointVel(head) += relative * damagemult * 230;
2894 victim->jointVel(neck) += relative * damagemult * 230;
2897 if (tutoriallevel != 1) {
2898 victim->DoDamage(damagemult * 120 / victim->protectionhigh);
2900 award_bonus(id, solidhit, 30);
2905 if (animTarget == staffspinhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2906 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2907 if (tutoriallevel != 1) {
2908 weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250;
2912 if (Random() % 2 || creature == wolftype) {
2915 emit_sound_at(staffheadsound, victim->coords);
2919 relative = victim->coords - coords;
2921 Normalise(&relative);
2922 relative = DoRotation(relative, 0, -90, 0);
2923 for (i = 0; i < victim->skeleton.num_joints; i++) {
2924 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2926 victim->jointVel(head) += relative * damagemult * 220;
2927 victim->jointVel(neck) += relative * damagemult * 220;
2930 if (tutoriallevel != 1) {
2931 victim->DoDamage(damagemult * 350 / victim->protectionhead);
2933 award_bonus(id, solidhit, 60);
2938 if (animTarget == staffgroundsmashanim && animation[animTarget].label[frameCurrent] == 5) {
2939 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) {
2941 if (tutoriallevel != 1) {
2943 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500;
2946 if (Random() % 2 || creature == wolftype) {
2949 emit_sound_at(staffbodysound, victim->coords);
2951 victim->skeleton.longdead = 0;
2952 victim->skeleton.free = 1;
2953 victim->skeleton.broken = 0;
2955 for (i = 0; i < victim->skeleton.num_joints; i++) {
2956 victim->skeleton.joints[i].velchange = 0;
2957 victim->skeleton.joints[i].locked = 0;
2958 //victim->skeleton.joints[i].velocity=0;
2964 /*relative=victim->coords-coords;
2966 Normalise(&relative);
2967 relative=DoRotation(relative,0,90,0);*/
2969 Normalise(&relative);
2970 if (!victim->dead) {
2971 for (i = 0; i < victim->skeleton.num_joints; i++) {
2972 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
2975 victim->jointVel(abdomen) += relative * damagemult * 40;
2978 for (i = 0; i < victim->skeleton.num_joints; i++) {
2979 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
2982 //victim->jointVel(abdomen)+=relative*damagemult*20;
2984 victim->Puff(abdomen);
2985 if (tutoriallevel != 1) {
2986 victim->DoDamage(damagemult * 100 / victim->protectionhigh);
2988 if (!victim->dead) {
2989 award_bonus(id, solidhit, 40);
2995 if (animTarget == lowkickanim && animation[animTarget].label[frameCurrent] == 5) {
2996 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != highheight) {
3001 relative = victim->coords - coords;
3003 Normalise(&relative);
3007 if (animation[victim->animTarget].height == lowheight) {
3013 for (i = 0; i < victim->skeleton.num_joints; i++) {
3014 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3016 victim->jointVel(head) += relative * damagemult * 200;
3017 if (tutoriallevel != 1) {
3018 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3021 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3022 if (victim->howactive == typesleeping)
3023 victim->DoDamage(damagemult * 150 / victim->protectionhead);
3024 if (creature == wolftype) {
3025 emit_sound_at(clawslicesound, victim->coords, 128.);
3027 victim->DoBloodBig(2 / victim->armorhead, 175);
3030 if (victim->damage >= victim->damagetolerance)
3032 for (i = 0; i < victim->skeleton.num_joints; i++) {
3033 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3035 victim->jointVel(abdomen) += relative * damagemult * 200;
3036 victim->frameTarget = 0;
3037 victim->animTarget = staggerbackhighanim;
3038 victim->targetyaw = targetyaw + 180;
3040 if (tutoriallevel != 1) {
3041 emit_sound_at(landsound2, victim->coords, 128.);
3043 victim->Puff(abdomen);
3044 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3045 if (creature == wolftype) {
3046 emit_sound_at(clawslicesound, victim->coords, 128.);
3048 victim->DoBloodBig(2 / victim->armorhigh, 170);
3055 if (animTarget == sweepanim && animation[animTarget].label[frameCurrent] == 5) {
3056 if ((victim->animTarget != jumpupanim) &&
3057 (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) &&
3058 (victim != this->shared_from_this())) {
3062 if (tutoriallevel != 1) {
3063 emit_sound_at(landsound2, victim->coords, 128.);
3066 relative = victim->coords - coords;
3068 Normalise(&relative);
3070 if (animation[victim->animTarget].height == middleheight || animation[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
3073 for (i = 0; i < victim->skeleton.num_joints; i++) {
3074 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
3076 relative = DoRotation(relative, 0, -90, 0);
3078 for (i = 0; i < victim->skeleton.num_joints; i++) {
3079 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)
3080 victim->skeleton.joints[i].velocity = relative * 80;
3082 victim->Puff(rightankle);
3083 victim->Puff(leftankle);
3084 victim->DoDamage(damagemult * 40 / victim->protectionlow);
3086 if (victim->damage >= victim->damagetolerance)
3088 for (i = 0; i < victim->skeleton.num_joints; i++) {
3089 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3091 relative = DoRotation(relative, 0, -90, 0);
3092 for (i = 0; i < victim->skeleton.num_joints; i++) {
3093 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)
3094 victim->skeleton.joints[i].velocity += relative * damagemult * 80;
3096 victim->jointVel(abdomen) += relative * damagemult * 200;
3097 victim->frameTarget = 0;
3098 victim->animTarget = staggerbackhighanim;
3099 victim->targetyaw = targetyaw + 180;
3101 if (tutoriallevel != 1) {
3102 emit_sound_at(landsound2, victim->coords, 128.);
3104 victim->Puff(abdomen);
3105 victim->DoDamage(damagemult * 30 / victim->protectionlow);
3113 if (animation[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) {
3114 if (animTarget == spinkickreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3122 if (tutoriallevel != 1) {
3123 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3125 if (creature == wolftype) {
3126 emit_sound_at(clawslicesound, victim->coords, 128);
3128 victim->DoBloodBig(2 / victim->armorhigh, 170);
3132 relative = victim->coords - oldcoords;
3134 Normalise(&relative);
3135 //relative=DoRotation(relative,0,-90,0);
3136 for (i = 0; i < victim->skeleton.num_joints; i++) {
3137 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3139 victim->jointVel(abdomen) += relative * damagemult * 200;
3141 victim->Puff(abdomen);
3142 victim->DoDamage(damagemult * 150 / victim->protectionhigh);
3144 award_bonus(id, Reversal);
3147 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && animation[animTarget].label[frameCurrent] == 5) {
3148 if (victim->weaponactive != -1 && victim->num_weapons > 0) {
3149 if (weapons[victim->weaponids[victim->weaponactive]].owner == victim->id) {
3150 weapons[victim->weaponids[victim->weaponactive]].owner = id;
3152 if (num_weapons > 0) {
3153 weaponids[num_weapons] = weaponids[victim->weaponactive];
3156 weaponids[0] = victim->weaponids[victim->weaponactive];
3157 victim->num_weapons--;
3158 if (victim->num_weapons > 0) {
3159 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
3160 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
3162 victim->weaponactive = -1;
3167 if (animTarget == staffhitreversalanim && animation[animTarget].label[frameCurrent] == 5) {
3175 emit_sound_at(whooshhitsound, victim->coords, 128.);
3178 relative = victim->coords - oldcoords;
3180 Normalise(&relative);
3181 //relative=DoRotation(relative,0,-90,0);
3182 for (i = 0; i < victim->skeleton.num_joints; i++) {
3183 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3185 victim->jointVel(abdomen) += relative * damagemult * 200;
3188 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3191 if (animTarget == staffspinhitreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3200 award_bonus(id, staffreversebonus);
3202 if (tutoriallevel != 1) {
3203 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3206 award_bonus(id, staffreversebonus); // Huh, again?
3209 relative = victim->coords - oldcoords;
3211 Normalise(&relative);
3212 //relative=DoRotation(relative,0,-90,0);
3213 for (i = 0; i < victim->skeleton.num_joints; i++) {
3214 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3216 victim->jointVel(abdomen) += relative * damagemult * 200;
3219 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3222 if (animTarget == upunchreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3228 Normalise(&relative);
3231 for (i = 0; i < victim->skeleton.num_joints; i++) {
3232 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3234 victim->jointVel(lefthand) *= .1;
3235 victim->jointVel(leftwrist) *= .2;
3236 victim->jointVel(leftelbow) *= .5;
3237 victim->jointVel(leftshoulder) *= .7;
3238 victim->jointVel(righthand) *= .1;
3239 victim->jointVel(rightwrist) *= .2;
3240 victim->jointVel(rightelbow) *= .5;
3241 victim->jointVel(rightshoulder) *= .7;
3243 victim->Puff(abdomen);
3244 victim->DoDamage(damagemult * 90 / victim->protectionhigh);
3246 award_bonus(id, Reversal);
3250 if (weaponactive != -1 || creature == wolftype)
3252 if (creature == rabbittype && weaponactive != -1)
3253 if (weapons[weaponids[0]].getType() == staff)
3256 if (weaponactive != -1) {
3257 victim->DoBloodBig(2 / victim->armorhigh, 225);
3258 emit_sound_at(knifeslicesound, victim->coords);
3259 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3260 weapons[weaponids[weaponactive]].bloody = 1;
3261 weapons[weaponids[weaponactive]].blooddrip += 3;
3263 if (weaponactive == -1 && creature == wolftype) {
3265 emit_sound_at(clawslicesound, victim->coords, 128.);
3267 victim->DoBloodBig(2 / victim->armorhigh, 175);
3274 if (animTarget == swordslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3280 Normalise(&relative);
3283 for (i = 0; i < victim->skeleton.num_joints; i++) {
3284 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3286 victim->jointVel(lefthand) *= .1 - 1;
3287 victim->jointVel(leftwrist) *= .2 - 1;
3288 victim->jointVel(leftelbow) *= .5 - 1;
3289 victim->jointVel(leftshoulder) *= .7 - 1;
3290 victim->jointVel(righthand) *= .1 - 1;
3291 victim->jointVel(rightwrist) *= .2 - 1;
3292 victim->jointVel(rightelbow) *= .5 - 1;
3293 victim->jointVel(rightshoulder) *= .7 - 1;
3295 award_bonus(id, swordreversebonus);
3298 if (hasvictim && animTarget == knifeslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3306 if (tutoriallevel != 1) {
3307 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3311 relative = victim->coords - oldcoords;
3313 Normalise(&relative);
3314 relative = DoRotation(relative, 0, -90, 0);
3315 for (i = 0; i < victim->skeleton.num_joints; i++) {
3316 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3318 victim->jointVel(abdomen) += relative * damagemult * 200;
3320 victim->Puff(abdomen);
3321 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3323 award_bonus(id, Reversal);
3326 if (hasvictim && animTarget == sneakattackanim && animation[animTarget].label[frameCurrent] == 7) {
3329 victim->skeleton.spinny = 0;
3331 relative = facing * -1;
3333 Normalise(&relative);
3334 if (victim->id == 0)
3336 for (i = 0; i < victim->skeleton.num_joints; i++) {
3337 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3339 //victim->DoDamage(1000);
3340 victim->damage = victim->damagetolerance;
3341 victim->permanentdamage = victim->damagetolerance - 1;
3344 if (weaponactive != -1 || creature == wolftype)
3346 if (creature == rabbittype && weaponactive != -1)
3347 if (weapons[weaponids[0]].getType() == staff)
3350 if (weaponactive != -1) {
3351 victim->DoBloodBig(200, 225);
3352 emit_sound_at(knifeslicesound, victim->coords);
3354 weapons[weaponids[weaponactive]].bloody = 2;
3355 weapons[weaponids[weaponactive]].blooddrip += 5;
3358 if (creature == wolftype && weaponactive == -1) {
3359 emit_sound_at(clawslicesound, victim->coords, 128.);
3361 victim->DoBloodBig(2, 175);
3364 award_bonus(id, spinecrusher);
3367 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3368 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3370 if (animTarget == knifefollowanim)
3371 victim->DoBloodBig(200, 210);
3372 if (animTarget == knifesneakattackanim) {
3373 /*victim->DoBloodBig(200,195);
3378 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
3379 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck),0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3381 XYZ footvel, footpoint;
3383 footpoint = weapons[weaponids[0]].tippoint;
3385 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3386 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3387 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3388 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3389 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3390 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3391 victim->DoBloodBig(200, 195);
3392 award_bonus(id, tracheotomy);
3394 if (animTarget == knifefollowanim) {
3395 award_bonus(id, Stabbonus);
3396 XYZ footvel, footpoint;
3398 footpoint = weapons[weaponids[0]].tippoint;
3400 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3401 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3402 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3403 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3404 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3405 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3408 victim->bloodloss += 10000;
3409 victim->velocity = 0;
3410 emit_sound_at(fleshstabsound, victim->coords);
3412 weapons[weaponids[weaponactive]].bloody = 2;
3413 weapons[weaponids[weaponactive]].blooddrip += 5;
3417 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 6) {
3419 victim->velocity = 0;
3420 for (i = 0; i < victim->skeleton.num_joints; i++) {
3421 victim->skeleton.joints[i].velocity = 0;
3423 if (animTarget == knifefollowanim) {
3425 for (i = 0; i < victim->skeleton.num_joints; i++) {
3426 victim->skeleton.joints[i].velocity = 0;
3429 if (weaponactive != -1 && animation[victim->animTarget].attack != reversal) {
3430 emit_sound_at(fleshstabremovesound, victim->coords);
3432 weapons[weaponids[weaponactive]].bloody = 2;
3433 weapons[weaponids[weaponactive]].blooddrip += 5;
3435 XYZ footvel, footpoint;
3437 footpoint = weapons[weaponids[0]].tippoint;
3439 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3440 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3441 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3442 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3443 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3444 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3448 if (hasvictim && (animTarget == swordsneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3449 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3450 award_bonus(id, backstab);
3454 XYZ footvel, footpoint;
3456 footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2;
3458 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3459 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3460 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3461 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3462 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 5, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3463 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3464 victim->DoBloodBig(200, 180);
3465 victim->DoBloodBig(200, 215);
3466 victim->bloodloss += 10000;
3467 victim->velocity = 0;
3468 emit_sound_at(fleshstabsound, victim->coords);
3470 weapons[weaponids[weaponactive]].bloody = 2;
3471 weapons[weaponids[weaponactive]].blooddrip += 5;
3475 if (hasvictim && animTarget == swordsneakattackanim && animation[animTarget].label[frameCurrent] == 6) {
3477 victim->velocity = 0;
3478 for (i = 0; i < victim->skeleton.num_joints; i++) {
3479 victim->skeleton.joints[i].velocity = 0;
3481 if (weaponactive != -1) {
3482 emit_sound_at(fleshstabremovesound, victim->coords);
3484 weapons[weaponids[weaponactive]].bloody = 2;
3485 weapons[weaponids[weaponactive]].blooddrip += 5;
3487 XYZ footvel, footpoint;
3489 footpoint = weapons[weaponids[0]].tippoint;
3491 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3492 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3493 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3494 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3495 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3496 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3500 if (animTarget == sweepreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3508 if (weaponactive == -1) {
3509 if (tutoriallevel != 1) {
3510 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3515 if (weaponactive != -1 || creature == wolftype)
3517 if (creature == rabbittype && weaponactive != -1)
3518 if (weapons[weaponids[0]].getType() == staff)
3521 if (weaponactive != -1) {
3522 victim->DoBloodBig(2 / victim->armorhead, 225);
3523 emit_sound_at(knifeslicesound, victim->coords);
3524 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3525 weapons[weaponids[weaponactive]].bloody = 1;
3526 weapons[weaponids[weaponactive]].blooddrip += 3;
3528 if (weaponactive == -1 && creature == wolftype) {
3529 emit_sound_at(clawslicesound, victim->coords, 128.);
3531 victim->DoBloodBig(2 / victim->armorhead, 175);
3535 award_bonus(id, Reversal);
3540 //relative=victim->coords-oldcoords;
3541 relative = facing * -1;
3543 Normalise(&relative);
3544 relative = DoRotation(relative, 0, 90, 0);
3546 Normalise(&relative);
3547 for (i = 0; i < victim->skeleton.num_joints; i++) {
3548 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3550 victim->jointVel(head) += relative * damagemult * 200;
3551 if (victim->damage < victim->damagetolerance - 100)
3552 victim->velocity = relative * 200;
3553 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3554 victim->velocity = 0;
3557 if (animTarget == sweepreversalanim && ((animation[animTarget].label[frameCurrent] == 9 && victim->damage < victim->damagetolerance) || (animation[animTarget].label[frameCurrent] == 7 && victim->damage > victim->damagetolerance))) {
3561 //relative=victim->coords-oldcoords;
3562 relative = facing * -1;
3564 Normalise(&relative);
3565 relative = DoRotation(relative, 0, 90, 0);
3567 Normalise(&relative);
3568 for (i = 0; i < victim->skeleton.num_joints; i++) {
3569 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3571 victim->jointVel(head) += relative * damagemult * 200;
3574 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim))
3575 if (victim->damage > victim->damagetolerance && bonus != reverseko) {
3576 award_bonus(id, reverseko);
3582 if (frameTarget > animation[animCurrent].numframes - 1) {
3585 animTarget = getIdle();
3589 if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) {
3590 animTarget = rollanim;
3592 emit_sound_at(movewhooshsound, coords, 128.);
3594 if (animCurrent == staggerbackhighanim) {
3595 animTarget = getIdle();
3597 if (animCurrent == staggerbackhardanim) {
3598 animTarget = getIdle();
3600 if (animCurrent == removeknifeanim) {
3601 animTarget = getIdle();
3603 if (animCurrent == crouchremoveknifeanim) {
3604 animTarget = getCrouch();
3606 if (animCurrent == backhandspringanim) {
3607 animTarget = getIdle();
3609 if (animCurrent == dodgebackanim) {
3610 animTarget = getIdle();
3612 if (animCurrent == drawleftanim) {
3613 animTarget = getIdle();
3615 if (animCurrent == drawrightanim || animCurrent == crouchdrawrightanim) {
3616 animTarget = getIdle();
3617 if (animCurrent == crouchdrawrightanim) {
3618 animTarget = getCrouch();
3620 if (weaponactive == -1)
3622 else if (weaponactive == 0) {
3624 if (num_weapons == 2) {
3626 buffer = weaponids[0];
3627 weaponids[0] = weaponids[1];
3628 weaponids[1] = buffer;
3632 if (weaponactive == -1) {
3633 emit_sound_at(knifesheathesound, coords, 128.);
3635 if (weaponactive != -1) {
3636 emit_sound_at(knifedrawsound, coords, 128.);
3639 if (animCurrent == rollanim) {
3640 animTarget = getCrouch();
3645 if (animTarget == walljumprightkickanim) {
3648 if (animTarget == walljumpleftkickanim) {
3651 animTarget = jumpdownanim;
3653 if (animCurrent == climbanim) {
3654 animTarget = getCrouch();
3656 coords += facing * .1;
3657 if (!isnormal(coords.x))
3668 if (animTarget == rabbitkickreversalanim) {
3669 animTarget = getCrouch();
3672 if (animTarget == jumpreversalanim) {
3673 animTarget = getCrouch();
3676 if (animTarget == walljumprightanim || animTarget == walljumpbackanim || animTarget == walljumpfrontanim) {
3677 if (attackkeydown && animTarget != walljumpfrontanim) {
3679 float closestdist = -1;
3682 for (i = 0; i < numplayers; i++) {
3683 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3684 distance = distsq(&Person::players[i]->coords, &coords);
3685 if (closestdist == -1 || distance < closestdist) {
3686 closestdist = distance;
3691 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3692 victim = Person::players[closest];
3693 animTarget = walljumprightkickanim;
3695 XYZ rotatetarget = victim->coords - coords;
3696 Normalise(&rotatetarget);
3697 yaw = -asin(0 - rotatetarget.x);
3699 if (rotatetarget.z < 0)
3701 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3702 velocity = (victim->coords - coords) * 4;
3707 if (animTarget == walljumpbackanim) {
3708 animTarget = backflipanim;
3710 velocity = facing * -8;
3713 resume_stream(whooshsound);
3715 if (animTarget == walljumprightanim) {
3716 animTarget = rightflipanim;
3720 velocity = DoRotation(facing, 0, 30, 0) * -8;
3723 if (animTarget == walljumpfrontanim) {
3724 animTarget = frontflipanim;
3728 velocity = facing * 8;
3732 resume_stream(whooshsound);
3734 if (animTarget == walljumpleftanim) {
3735 if (attackkeydown) {
3737 float closestdist = -1;
3740 for (i = 0; i < numplayers; i++) {
3741 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3742 distance = distsq(&Person::players[i]->coords, &coords);
3743 if (closestdist == -1 || distance < closestdist) {
3744 closestdist = distance;
3749 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3750 victim = Person::players[closest];
3751 animTarget = walljumpleftkickanim;
3753 XYZ rotatetarget = victim->coords - coords;
3754 Normalise(&rotatetarget);
3755 yaw = -asin(0 - rotatetarget.x);
3757 if (rotatetarget.z < 0)
3759 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3760 velocity = (victim->coords - coords) * 4;
3765 if (animTarget != walljumpleftkickanim) {
3766 animTarget = leftflipanim;
3770 velocity = DoRotation(facing, 0, -30, 0) * -8;
3774 resume_stream(whooshsound);
3776 if (animTarget == sneakattackanim) {
3777 animCurrent = getCrouch();
3778 animTarget = getCrouch();
3785 transspeed = 1000000;
3786 targetheadyaw += 180;
3787 coords -= facing * .7;
3789 coords.y = terrain.getHeight(coords.x, coords.z);
3793 if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) {
3794 animTarget = getIdle();
3797 coords.y = terrain.getHeight(coords.x, coords.z);
3801 if (animCurrent == knifefollowanim) {
3802 animTarget = getIdle();
3805 if (animation[animTarget].attack == reversal && animCurrent != sneakattackanim && animCurrent != knifesneakattackanim && animCurrent != swordsneakattackanim && animCurrent != knifefollowanim) {
3806 float ycoords = oldcoords.y;
3807 animTarget = getStop();
3812 transspeed = 1000000;
3813 targetheadyaw += 180;
3814 if (!isnormal(coords.x))
3816 if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim)
3817 oldcoords = coords + facing * .5;
3818 else if (animCurrent == sweepreversalanim)
3819 oldcoords = coords + facing * 1.1;
3820 else if (animCurrent == upunchreversalanim) {
3821 oldcoords = coords + facing * 1.5;
3824 targetheadyaw += 180;
3827 } else if (animCurrent == knifeslashreversalanim) {
3828 oldcoords = coords + facing * .5;
3831 targetheadyaw += 90;
3834 } else if (animCurrent == staffspinhitreversalanim) {
3837 targetheadyaw += 180;
3842 oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z);
3844 oldcoords.y = ycoords;
3845 currentoffset = coords - oldcoords;
3851 if (animCurrent == knifesneakattackedanim || animCurrent == swordsneakattackedanim) {
3856 if (animation[animTarget].attack == reversed) {
3858 if (animTarget == sweepreversedanim)
3860 animTarget = backhandspringanim;
3862 emit_sound_at(landsound, coords, 128);
3864 if (animCurrent == upunchreversedanim || animCurrent == swordslashreversedanim) {
3865 animTarget = rollanim;
3868 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3869 coords.y = oldcoords.y;
3871 if (animCurrent == knifeslashreversedanim) {
3872 animTarget = rollanim;
3877 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3878 coords.y = oldcoords.y;
3882 animTarget = jumpdownanim;
3885 animTarget = getIdle();
3887 animTarget = getIdle();
3888 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
3889 animTarget = getIdle();
3891 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3892 coords.y = oldcoords.y;
3893 //coords+=DoRotation(animation[animCurrent].offset,0,yaw,0)*scale;
3894 targetoffset.y = coords.y;
3896 targetoffset.y = terrain.getHeight(coords.x, coords.z);
3897 currentoffset = DoRotation(animation[animCurrent].offset * -1, 0, yaw, 0) * scale;
3898 currentoffset.y -= (coords.y - targetoffset.y);
3899 coords.y = targetoffset.y;
3901 normalsupdatedelay = 0;
3903 if (animCurrent == upunchanim) {
3904 animTarget = getStop();
3905 normalsupdatedelay = 0;
3908 if (animCurrent == rabbitkickanim && animTarget != backflipanim) {
3912 if (num_weapons > 0)
3913 if (weapons[0].getType() == staff)
3919 rabbitkickragdoll = 1;
3921 if (animCurrent == rabbitkickreversedanim) {
3927 skeleton.spinny = 0;
3928 SolidHitBonus(!id); // FIXME: tricky id
3932 animTarget = rollanim;
3935 pause_sound(whooshsound);
3939 if (animCurrent == rabbittackledbackanim || animCurrent == rabbittackledfrontanim) {
3943 skeleton.spinny = 0;
3945 if (animCurrent == jumpreversedanim) {
3951 skeleton.spinny = 0;
3952 SolidHitBonus(!id); // FIXME: tricky id
3956 animTarget = rollanim;
3957 coords += facing * 2;
3959 pause_sound(whooshsound);
3964 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) {
3965 animTarget = getupfromfrontanim;
3967 } else if (animation[animCurrent].attack == normalattack) {
3968 animTarget = getIdle();
3971 if (animCurrent == blockhighleftanim && aitype != playercontrolled) {
3972 animTarget = blockhighleftstrikeanim;
3974 if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) {
3975 animTarget = getIdle();
3978 if (animCurrent == spinkickanim && victim->skeleton.free) {
3979 if (creature == rabbittype)
3980 animTarget = fightidleanim;
3985 if (isIdle() && !wasIdle())
3986 normalsupdatedelay = 0;
3988 if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) {
3989 animTarget = jumpdownanim;
3992 if (!skeleton.free) {
3994 if (!transspeed && animation[animTarget].attack != 2 && animation[animTarget].attack != 3) {
3995 if (!isRun() || !wasRun()) {
3996 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
3997 target += multiplier * animation[animTarget].speed[frameTarget] * speed * 2;
3998 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
3999 target += multiplier * animation[animCurrent].speed[frameCurrent] * speed * 2;
4001 if (isRun() && wasRun()) {
4003 tempspeed = velspeed;
4004 if (tempspeed < 10 * speedmult)
4005 tempspeed = 10 * speedmult;
4006 target += multiplier * animation[animTarget].speed[frameCurrent] * speed * 1.7 * tempspeed / (speed * 45 * scale);
4008 } else if (transspeed)
4009 target += multiplier * transspeed * speed * 2;
4011 if (!isRun() || !wasRun()) {
4012 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
4013 target += multiplier * animation[animTarget].speed[frameTarget] * 2;
4014 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
4015 target += multiplier * animation[animCurrent].speed[frameCurrent] * 2;
4019 if (animCurrent != animTarget)
4020 target = (target + oldtarget) / 2;
4023 frameCurrent = frameTarget;
4027 rot = targetrot * target;
4028 yaw += rot - oldrot;
4034 if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
4036 for (i = 0; i < skeleton.num_joints; i++) {
4037 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent];
4040 skeleton.FindForwards();
4042 for (i = 0; i < skeleton.num_muscles; i++) {
4043 if (skeleton.muscles[i].visible) {
4044 skeleton.FindRotationMuscle(i, animTarget);
4047 for (i = 0; i < skeleton.num_muscles; i++) {
4048 if (skeleton.muscles[i].visible) {
4049 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
4050 skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4051 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
4052 skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4053 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
4054 skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4059 for (i = 0; i < skeleton.num_joints; i++) {
4060 skeleton.joints[i].position = animation[animTarget].position[i][frameTarget];
4063 skeleton.FindForwards();
4065 for (i = 0; i < skeleton.num_muscles; i++) {
4066 if (skeleton.muscles[i].visible) {
4067 skeleton.FindRotationMuscle(i, animTarget);
4070 for (i = 0; i < skeleton.num_muscles; i++) {
4071 if (skeleton.muscles[i].visible) {
4072 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
4073 skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4074 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
4075 skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4076 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
4077 skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4078 if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) skeleton.muscles[i].newrotate3 -= 360;
4079 if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) skeleton.muscles[i].newrotate3 += 360;
4080 if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) skeleton.muscles[i].newrotate2 -= 360;
4081 if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) skeleton.muscles[i].newrotate2 += 360;
4082 if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) skeleton.muscles[i].newrotate1 -= 360;
4083 if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) skeleton.muscles[i].newrotate1 += 360;
4087 if (frameCurrent >= animation[animCurrent].numframes)
4088 frameCurrent = animation[animCurrent].numframes - 1;
4090 oldanimCurrent = animCurrent;
4091 oldanimTarget = animTarget;
4092 oldframeTarget = frameTarget;
4093 oldframeCurrent = frameCurrent;
4095 for (i = 0; i < skeleton.num_joints; i++) {
4096 skeleton.joints[i].velocity = (animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target) - skeleton.joints[i].position) / multiplier;
4097 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target);
4099 offset = currentoffset * (1 - target) + targetoffset * target;
4100 for (i = 0; i < skeleton.num_muscles; i++) {
4101 if (skeleton.muscles[i].visible) {
4102 skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * (target);
4103 skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * (target);
4104 skeleton.muscles[i].rotate3 = skeleton.muscles[i].oldrotate3 * (1 - target) + skeleton.muscles[i].newrotate3 * (target);
4109 if (isLanding() && landhard) {
4112 animTarget = getLandhard();
4119 //skeleton.DoConstraints();
4126 void Person::DoStuff()
4128 static XYZ terrainnormal;
4129 static XYZ flatfacing;
4130 static XYZ flatvelocity;
4131 static float flatvelspeed;
4135 static int bloodsize;
4136 static int startx, starty, endx, endy;
4137 static GLubyte color;
4138 static XYZ bloodvel;
4140 onfiredelay -= multiplier;
4141 if (onfiredelay < 0 && onfire) {
4142 if (Random() % 2 == 0) {
4148 crouchkeydowntime += multiplier;
4150 crouchkeydowntime = 0;
4151 jumpkeydowntime += multiplier;
4152 if (!jumpkeydown && skeleton.free)
4153 jumpkeydowntime = 0;
4155 if (hostile || damage > 0 || bloodloss > 0)
4158 if (isIdle() || isRun())
4161 if (num_weapons == 1 && weaponactive != -1)
4165 blooddimamount -= multiplier * .3;
4166 speechdelay -= multiplier;
4167 texupdatedelay -= multiplier;
4168 interestdelay -= multiplier;
4169 flamedelay -= multiplier;
4170 parriedrecently -= multiplier;
4172 victim = this->shared_from_this();
4177 speed = 1.1 * speedmult;
4179 speed = 1.0 * speedmult;
4181 rabbitkickragdoll = 0;
4185 if (id != 0 && (creature == rabbittype || difficulty != 2))
4187 if (id != 0 && creature == wolftype && difficulty == 2) {
4189 if (aitype != passivetype) {
4191 if (aitype == attacktypecutoff && (Person::players[0]->isIdle() || Person::players[0]->isCrouch() || Person::players[0]->skeleton.free || Person::players[0]->animTarget == getupfrombackanim || Person::players[0]->animTarget == getupfromfrontanim || Person::players[0]->animTarget == sneakanim) && distsq(&coords, &Person::players[0]->coords) < 16) {
4197 if (animTarget == wolfrunninganim && !superruntoggle) {
4198 animTarget = getRun();
4202 if (weaponactive == -1 && num_weapons > 0) {
4203 if (weapons[weaponids[0]].getType() == staff) {
4209 burnt += multiplier;
4210 /*if(aitype!=playercontrolled)*///deathbleeding=5;
4211 /*if(aitype!=playercontrolled)*/
4215 OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3);
4217 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
4223 vel[0] = velocity.x;
4224 vel[1] = velocity.y;
4225 vel[2] = velocity.z;
4228 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4229 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
4233 while (flamedelay < 0 && onfire) {
4235 howmany = abs(Random() % (skeleton.num_joints));
4237 flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4239 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4241 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4243 flatfacing = skeleton.joints[howmany].position * scale + coords;
4244 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
4247 while (flamedelay < 0 && !onfire && tutoriallevel == 1 && id != 0) {
4249 howmany = abs(Random() % (skeleton.num_joints));
4251 flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4253 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4255 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4257 flatfacing = skeleton.joints[howmany].position * scale + coords;
4258 Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
4262 bleeding -= multiplier * .3;
4263 if (bloodtoggle == 2) {
4264 skeleton.drawmodel.textureptr.bind();
4265 if (bleeding <= 0 && (detail != 2 || osx))
4270 if (neckspurtamount > 0) {
4271 neckspurtamount -= multiplier;
4272 neckspurtdelay -= multiplier * 3;
4273 neckspurtparticledelay -= multiplier * 3;
4274 if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
4277 if (!skeleton.free) {
4278 bloodvel.z = 5 * neckspurtamount;
4279 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4281 if (skeleton.free) {
4282 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
4285 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4287 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
4289 Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4291 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4292 neckspurtparticledelay = .05;
4294 if (neckspurtdelay < 0) {
4299 if (deathbleeding > 0 && dead != 2) {
4300 if (deathbleeding < 5)
4301 bleeddelay -= deathbleeding * multiplier / 4;
4303 bleeddelay -= 5 * multiplier / 4;
4304 if (bleeddelay < 0 && bloodtoggle) {
4310 bloodvel += DoRotation(jointVel(abdomen), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
4312 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
4314 Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4316 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
4319 bloodloss += deathbleeding * multiplier * 80;
4320 deathbleeding -= multiplier * 1.6;
4321 //if(id==0)deathbleeding-=multiplier*.2;
4322 if (deathbleeding < 0)
4324 if (bloodloss > damagetolerance && animation[animTarget].attack == neutral) {
4325 if (weaponactive != -1) {
4326 weapons[weaponids[0]].owner = -1;
4327 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4328 weapons[weaponids[0]].velocity.x += .01;
4329 weapons[weaponids[0]].tipvelocity = velocity * scale;
4330 weapons[weaponids[0]].missed = 1;
4331 weapons[weaponids[0]].hitsomething = 0;
4332 weapons[weaponids[0]].freetime = 0;
4333 weapons[weaponids[0]].firstfree = 1;
4334 weapons[weaponids[0]].physics = 1;
4337 weaponids[0] = weaponids[num_weapons];
4338 if (weaponstuck == num_weapons)
4342 for (i = 0; i < numplayers; i++) {
4343 Person::players[i]->wentforweapon = 0;
4355 if (!dead && creature == wolftype) {
4356 award_bonus(0, Wolfbonus);
4359 if (animTarget == knifefollowedanim && !skeleton.free) {
4360 for (i = 0; i < skeleton.num_joints; i++) {
4361 skeleton.joints[i].velocity = 0;
4362 skeleton.joints[i].velocity.y = -2;
4365 if (id != 0 && unconscioustime > .1) {
4373 if (texupdatedelay < 0 && bleeding > 0 && bloodtoggle == 2 && distsq(&viewer, &coords) < 9) {
4374 texupdatedelay = .12;
4376 bloodsize = 5 - realtexdetail;
4380 startx = bleedy; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4381 starty = bleedx; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4382 endx = startx + bloodsize;
4383 endy = starty + bloodsize;
4393 if (endx > skeleton.skinsize - 1) {
4394 endx = skeleton.skinsize - 1;
4397 if (endy > skeleton.skinsize - 1) {
4398 endy = skeleton.skinsize - 1;
4406 for (i = startx; i < endx; i++) {
4407 for (j = starty; j < endy; j++) {
4408 if (Random() % 2 == 0) {
4409 color = Random() % 85 + 170;
4410 if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2)
4411 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2;
4412 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0;
4413 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0;
4417 if (!osx && detail > 1) {
4418 skeleton.drawmodel.textureptr.bind();
4422 if (!skeleton.free) {
4423 bleedy -= 4 / realtexdetail;
4425 bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4427 bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4429 if (skeleton.free) {
4430 bleedx += 4 * direction / realtexdetail;
4432 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4434 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4438 if (abs(righthandmorphness - targetrighthandmorphness) < multiplier * 4) {
4439 righthandmorphness = targetrighthandmorphness;
4440 righthandmorphstart = righthandmorphend;
4441 } else if (righthandmorphness > targetrighthandmorphness) {
4442 righthandmorphness -= multiplier * 4;
4443 } else if (righthandmorphness < targetrighthandmorphness) {
4444 righthandmorphness += multiplier * 4;
4447 if (abs(lefthandmorphness - targetlefthandmorphness) < multiplier * 4) {
4448 lefthandmorphness = targetlefthandmorphness;
4449 lefthandmorphstart = lefthandmorphend;
4450 } else if (lefthandmorphness > targetlefthandmorphness) {
4451 lefthandmorphness -= multiplier * 4;
4452 } else if (lefthandmorphness < targetlefthandmorphness) {
4453 lefthandmorphness += multiplier * 4;
4456 if (creature == rabbittype || targettailmorphness == 5 || targettailmorphness == 0) {
4457 if (abs(tailmorphness - targettailmorphness) < multiplier * 10) {
4458 tailmorphness = targettailmorphness;
4459 tailmorphstart = tailmorphend;
4460 } else if (tailmorphness > targettailmorphness) {
4461 tailmorphness -= multiplier * 10;
4462 } else if (tailmorphness < targettailmorphness) {
4463 tailmorphness += multiplier * 10;
4467 if (creature == wolftype) {
4468 if (abs(tailmorphness - targettailmorphness) < multiplier * 4) {
4469 tailmorphness = targettailmorphness;
4470 tailmorphstart = tailmorphend;
4471 } else if (tailmorphness > targettailmorphness) {
4472 tailmorphness -= multiplier * 2;
4473 } else if (tailmorphness < targettailmorphness) {
4474 tailmorphness += multiplier * 2;
4478 if (headmorphend == 3 || headmorphstart == 3) {
4479 if (abs(headmorphness - targetheadmorphness) < multiplier * 7) {
4480 headmorphness = targetheadmorphness;
4481 headmorphstart = headmorphend;
4482 } else if (headmorphness > targetheadmorphness) {
4483 headmorphness -= multiplier * 7;
4484 } else if (headmorphness < targetheadmorphness) {
4485 headmorphness += multiplier * 7;
4487 } else if (headmorphend == 5 || headmorphstart == 5) {
4488 if (abs(headmorphness - targetheadmorphness) < multiplier * 10) {
4489 headmorphness = targetheadmorphness;
4490 headmorphstart = headmorphend;
4491 } else if (headmorphness > targetheadmorphness) {
4492 headmorphness -= multiplier * 10;
4493 } else if (headmorphness < targetheadmorphness) {
4494 headmorphness += multiplier * 10;
4497 if (abs(headmorphness - targetheadmorphness) < multiplier * 4) {
4498 headmorphness = targetheadmorphness;
4499 headmorphstart = headmorphend;
4500 } else if (headmorphness > targetheadmorphness) {
4501 headmorphness -= multiplier * 4;
4502 } else if (headmorphness < targetheadmorphness) {
4503 headmorphness += multiplier * 4;
4507 if (abs(chestmorphness - targetchestmorphness) < multiplier) {
4508 chestmorphness = targetchestmorphness;
4509 chestmorphstart = chestmorphend;
4510 } else if (chestmorphness > targetchestmorphness) {
4511 chestmorphness -= multiplier;
4512 } else if (chestmorphness < targetchestmorphness) {
4513 chestmorphness += multiplier;
4516 if (dead != 2 && howactive <= typesleeping) {
4517 if (chestmorphstart == 0 && chestmorphend == 0) {
4519 targetchestmorphness = 1;
4522 if (chestmorphstart != 0 && chestmorphend != 0) {
4524 targetchestmorphness = 1;
4526 if (environment == snowyenvironment) {
4530 footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
4532 footvel = skeleton.specialforward[0] * -1;
4534 footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
4536 footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
4537 if (animTarget == sleepanim)
4538 footvel = DoRotation(footvel, 0, 90, 0);
4539 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
4543 if (!dead && howactive < typesleeping) {
4544 blinkdelay -= multiplier * 2;
4545 if (headmorphstart == 0 && headmorphend == 0 && blinkdelay <= 0) {
4547 targetheadmorphness = 1;
4549 blinkdelay = (float)(abs(Random() % 40)) / 5;
4551 if (headmorphstart == 3 && headmorphend == 3) {
4553 targetheadmorphness = 1;
4558 twitchdelay -= multiplier * 1.5;
4559 if (animTarget != hurtidleanim) {
4560 if (headmorphstart == 0 && headmorphend == 0 && twitchdelay <= 0) {
4562 targetheadmorphness = 1;
4564 twitchdelay = (float)(abs(Random() % 40)) / 5;
4566 if (headmorphstart == 5 && headmorphend == 5) {
4568 targetheadmorphness = 1;
4572 if ((isIdle() || isCrouch()) && animTarget != hurtidleanim) {
4573 twitchdelay3 -= multiplier * 1;
4574 if (Random() % 2 == 0) {
4575 if (righthandmorphstart == 0 && righthandmorphend == 0 && twitchdelay3 <= 0) {
4576 righthandmorphness = 0;
4577 targetrighthandmorphness = 1;
4578 righthandmorphend = 1;
4579 if (Random() % 2 == 0)twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4581 if (righthandmorphstart == 1 && righthandmorphend == 1) {
4582 righthandmorphness = 0;
4583 targetrighthandmorphness = 1;
4584 righthandmorphend = 0;
4587 if (Random() % 2 == 0) {
4588 if (lefthandmorphstart == 0 && lefthandmorphend == 0 && twitchdelay3 <= 0) {
4589 lefthandmorphness = 0;
4590 targetlefthandmorphness = 1;
4591 lefthandmorphend = 1;
4592 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4594 if (lefthandmorphstart == 1 && lefthandmorphend == 1) {
4595 lefthandmorphness = 0;
4596 targetlefthandmorphness = 1;
4597 lefthandmorphend = 0;
4603 if (creature == rabbittype) {
4604 if (howactive < typesleeping)
4605 twitchdelay2 -= multiplier * 1.5;
4607 twitchdelay2 -= multiplier * 0.5;
4608 if (howactive <= typesleeping) {
4609 if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) {
4611 targettailmorphness = 1;
4613 twitchdelay2 = (float)(abs(Random() % 40)) / 5;
4615 if (tailmorphstart == 1 && tailmorphend == 1) {
4617 targettailmorphness = 1;
4620 if (tailmorphstart == 2 && tailmorphend == 2) {
4622 targettailmorphness = 1;
4629 if (creature == wolftype) {
4630 twitchdelay2 -= multiplier * 1.5;
4631 if (tailmorphend != 0)
4632 if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) {
4634 targettailmorphness = 1;
4638 if (tailmorphend != 5)
4639 if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) {
4641 targettailmorphness = 1;
4645 if (twitchdelay2 <= 0) {
4646 if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) {
4648 targettailmorphness = 1;
4651 if (tailmorphstart == 1 && tailmorphend == 1) {
4653 targettailmorphness = 1;
4656 if (tailmorphstart == 2 && tailmorphend == 2) {
4658 targettailmorphness = 1;
4661 if (tailmorphstart == 3 && tailmorphend == 3) {
4663 targettailmorphness = 1;
4666 if (tailmorphstart == 4 && tailmorphend == 4) {
4668 targettailmorphness = 1;
4675 unconscioustime = 0;
4677 if (dead == 1 || howactive == typesleeping) {
4678 unconscioustime += multiplier;
4679 //If unconscious, close eyes and mouth
4680 if (righthandmorphend != 0)
4681 righthandmorphness = 0;
4682 righthandmorphend = 0;
4683 targetrighthandmorphness = 1;
4685 if (lefthandmorphend != 0)
4686 lefthandmorphness = 0;
4687 lefthandmorphend = 0;
4688 targetlefthandmorphness = 1;
4690 if (headmorphend != 3 && headmorphend != 5)
4693 targetheadmorphness = 1;
4697 if (howactive > typesleeping) {
4700 if (bloodtoggle && !bled) {
4701 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4703 if (bloodtoggle && !bled)
4704 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4705 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4706 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4710 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4715 if (dead == 2 || howactive > typesleeping) {
4716 //If dead, open mouth and hands
4717 if (righthandmorphend != 0)
4718 righthandmorphness = 0;
4719 righthandmorphend = 0;
4720 targetrighthandmorphness = 1;
4722 if (lefthandmorphend != 0)
4723 lefthandmorphness = 0;
4724 lefthandmorphend = 0;
4725 targetlefthandmorphness = 1;
4727 if (headmorphend != 2)
4730 targetheadmorphness = 1;
4733 if (stunned > 0 && !dead && headmorphend != 2) {
4734 if (headmorphend != 4)
4737 targetheadmorphness = 1;
4740 if (damage > damagetolerance && !dead) {
4743 unconscioustime = 0;
4745 if (creature == wolftype) {
4746 award_bonus(0, Wolfbonus);
4751 if (weaponactive != -1) {
4752 weapons[weaponids[0]].owner = -1;
4753 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4754 weapons[weaponids[0]].velocity.x += .01;
4755 weapons[weaponids[0]].tipvelocity = velocity * scale;
4756 weapons[weaponids[0]].missed = 1;
4757 weapons[weaponids[0]].hitsomething = 0;
4758 weapons[weaponids[0]].freetime = 0;
4759 weapons[weaponids[0]].firstfree = 1;
4760 weapons[weaponids[0]].physics = 1;
4763 weaponids[0] = weaponids[num_weapons];
4764 if (weaponstuck == num_weapons)
4768 for (i = 0; i < numplayers; i++) {
4769 Person::players[i]->wentforweapon = 0;
4775 if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) {
4783 //if(dead)damage-=multiplier/4;
4785 damage -= multiplier * 13;
4786 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4788 permanentdamage -= multiplier * 4;
4789 if (isIdle() || isCrouch()) {
4791 permanentdamage -= multiplier * 4;
4792 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4796 if (permanentdamage < 0)
4797 permanentdamage = 0;
4798 if (superpermanentdamage < 0)
4799 superpermanentdamage = 0;
4800 if (permanentdamage < superpermanentdamage) {
4801 permanentdamage = superpermanentdamage;
4803 if (damage < permanentdamage) {
4804 damage = permanentdamage;
4806 if (dead == 1 && damage < damagetolerance) {
4810 for (i = 0; i < skeleton.num_joints; i++) {
4811 skeleton.joints[i].velocity = 0;
4814 if (permanentdamage > damagetolerance && dead != 2) {
4817 if (weaponactive != -1) {
4818 weapons[weaponids[0]].owner = -1;
4819 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4820 weapons[weaponids[0]].velocity.x += .01;
4821 weapons[weaponids[0]].tipvelocity = velocity * scale;
4822 weapons[weaponids[0]].missed = 1;
4823 weapons[weaponids[0]].hitsomething = 0;
4824 weapons[weaponids[0]].freetime = 0;
4825 weapons[weaponids[0]].firstfree = 1;
4826 weapons[weaponids[0]].physics = 1;
4829 weaponids[0] = weaponids[num_weapons];
4830 if (weaponstuck == num_weapons)
4834 for (i = 0; i < numplayers; i++) {
4835 Person::players[i]->wentforweapon = 0;
4841 if (!dead && creature == wolftype) {
4842 award_bonus(0, Wolfbonus);
4845 if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance)
4846 award_bonus(id, touchofdeath);
4847 if (id != 0 && unconscioustime > .1) {
4855 emit_sound_at(breaksound, coords);
4858 if (skeleton.free == 1) {
4860 pause_sound(whooshsound);
4863 //If knocked over, open hands and close mouth
4864 if (righthandmorphend != 0)
4865 righthandmorphness = 0;
4866 righthandmorphend = 0;
4867 targetrighthandmorphness = 1;
4869 if (lefthandmorphend != 0)
4870 lefthandmorphness = 0;
4871 lefthandmorphend = 0;
4872 targetlefthandmorphness = 1;
4874 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) {
4875 if (headmorphend != 0)
4878 targetheadmorphness = 1;
4882 skeleton.DoGravity(&scale);
4884 damageamount = skeleton.DoConstraints(&coords, &scale) * 5;
4885 if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1))
4886 award_bonus(id, deepimpact);
4887 DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3));
4891 for (j = 0; j < skeleton.num_joints; j++) {
4892 average += skeleton.joints[j].position;
4896 coords += average * scale;
4897 for (j = 0; j < skeleton.num_joints; j++) {
4898 skeleton.joints[j].position -= average;
4900 average /= multiplier;
4902 //velocity=jointVel(groin)*scale;
4904 for (i = 0; i < skeleton.num_joints; i++) {
4905 velocity += skeleton.joints[i].velocity * scale;
4907 velocity /= skeleton.num_joints;
4909 if (!isnormal(velocity.x) && velocity.x) {
4913 if (findLength(&average) < 10 && dead && skeleton.free) {
4914 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
4915 if (skeleton.longdead > 2000) {
4916 if (skeleton.longdead > 6000) {
4918 pause_sound(whooshsound);
4923 if (dead == 2 && bloodloss < damagetolerance) {
4925 headpoint = (jointPos(head) + jointPos(neck)) / 2 * scale + coords;
4927 if (bloodtoggle && !bled) {
4928 terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
4930 if (bloodtoggle && !bled)
4931 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4932 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4933 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4934 float size = .2 * 1.2;
4937 objects.model[j].MakeDecal(blooddecal, &point, &size, &opacity, &yaw);
4941 if (dead == 2 && bloodloss >= damagetolerance) {
4943 headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords;
4946 if (bloodtoggle && !bled) {
4947 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4949 if (bloodtoggle && !bled)
4950 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4951 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4952 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4956 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4963 if (!dead && crouchkeydown && skeleton.freetime > .5 && id == 0 && skeleton.free) {
4964 bool canrecover = 1;
4965 XYZ startpoint, endpoint, colpoint, colviewer, coltarget;
4966 startpoint = coords;
4969 if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1)
4971 if (velocity.y < -30)
4973 for (i = 0; i < objects.numobjects; i++) {
4974 if (objects.type[i] != treeleavestype && objects.type[i] != bushtype && objects.type[i] != firetype) {
4975 colviewer = startpoint;
4976 coltarget = endpoint;
4977 if (objects.model[i].LineCheck(&colviewer, &coltarget, &colpoint, &objects.position[i], &objects.yaw[i]) != -1)
4986 terrainnormal = jointPos(groin) - jointPos(abdomen);
4987 if (joint(groin).locked && joint(abdomen).locked) {
4988 terrainnormal = jointPos(groin) - jointPos(abdomen);
4989 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
4991 if (joint(abdomen).locked && joint(neck).locked) {
4992 terrainnormal = jointPos(abdomen) - jointPos(neck);
4993 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
4995 if (joint(groin).locked && joint(neck).locked) {
4996 terrainnormal = jointPos(groin) - jointPos(neck);
4997 middle = (jointPos(groin) + jointPos(neck)) / 2;
4999 Normalise(&terrainnormal);
5001 targetyaw = -asin(0 - terrainnormal.x);
5002 targetyaw *= 360 / 6.28;
5003 if (terrainnormal.z < 0)
5004 targetyaw = 180 - targetyaw;
5009 animTarget = flipanim;
5010 crouchtogglekeydown = 1;
5015 animCurrent = tempanim;
5018 //tilt2=targettilt2;
5020 //if(middle.y>0)targetoffset.y=middle.y+1;
5022 for (i = 0; i < skeleton.num_joints; i++) {
5023 tempanimation.position[i][0] = skeleton.joints[i].position;
5024 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
5029 if (findLength(&average) < 10 && !dead && skeleton.free) {
5030 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
5031 if (skeleton.longdead > (damage + 500) * 1.5) {
5033 pause_sound(whooshsound);
5039 terrainnormal = jointPos(groin) - jointPos(abdomen);
5040 if (joint(groin).locked && joint(abdomen).locked) {
5041 terrainnormal = jointPos(groin) - jointPos(abdomen);
5042 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
5044 if (joint(abdomen).locked && joint(neck).locked) {
5045 terrainnormal = jointPos(abdomen) - jointPos(neck);
5046 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
5048 if (joint(groin).locked && joint(neck).locked) {
5049 terrainnormal = jointPos(groin) - jointPos(neck);
5050 middle = (jointPos(groin) + jointPos(neck)) / 2;
5052 Normalise(&terrainnormal);
5054 targetyaw = -asin(0 - terrainnormal.x);
5055 targetyaw *= 360 / 6.28;
5056 if (terrainnormal.z < 0)
5057 targetyaw = 180 - targetyaw;
5060 targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1;
5063 if (skeleton.forward.y < 0) {
5064 animTarget = getupfrombackanim;
5068 if (skeleton.forward.y > -.3) {
5069 animTarget = getupfromfrontanim;
5077 if ((Random() % 8 == 0 && id != 0 && creature == rabbittype) || (Random() % 2 == 0 && id != 0 && creature == wolftype) || (id == 0 && crouchkeydown && (forwardkeydown || backkeydown || leftkeydown || rightkeydown))) {
5078 animTarget = rollanim;
5079 targetyaw = lookyaw;
5096 if ( !leftkeydown && !rightkeydown)
5103 if (abs(targettilt2) > 50)
5105 animCurrent = tempanim;
5108 tilt2 = targettilt2;
5110 if (middle.y > 0 && animTarget != rollanim)
5111 targetoffset.y = middle.y + 1;
5113 for (i = 0; i < skeleton.num_joints; i++) {
5114 tempanimation.position[i][0] = skeleton.joints[i].position;
5115 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
5122 if (num_weapons > 0)
5123 if (weapons[0].getType() == staff)
5125 if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) {
5126 if (velocity.y > -30) {
5128 tempvelocity = velocity;
5129 Normalise(&tempvelocity);
5130 targetyaw = -asin(0 - tempvelocity.x);
5131 targetyaw *= 360 / 6.28;
5133 targetyaw = 180 - targetyaw;
5137 if (dotproduct(&skeleton.forward, &tempvelocity) < 0) {
5138 animTarget = rollanim;
5141 animTarget = backhandspringanim;
5147 emit_sound_at(movewhooshsound, coords, 128.);
5149 animCurrent = animTarget;
5150 frameCurrent = frameTarget - 1;
5162 if (skeleton.freefall == 0)
5167 if (aitype != passivetype || skeleton.free == 1)
5168 if (findLengthfast(&velocity) > .1)
5169 for (i = 0; i < objects.numobjects; i++) {
5170 if (objects.type[i] == firetype)
5171 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) {
5173 if (!objects.onfire[i]) {
5174 emit_sound_at(firestartsound, objects.position[i]);
5176 objects.onfire[i] = 1;
5179 if (objects.onfire[i]) {
5184 if (objects.type[i] == bushtype)
5185 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) {
5187 if (!objects.onfire[i]) {
5188 emit_sound_at(firestartsound, objects.position[i]);
5190 objects.onfire[i] = 1;
5194 if (objects.onfire[i]) {
5198 if (objects.messedwith[i] <= 0) {
5202 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5205 envsound[numenvsounds] = coords;
5206 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5207 envsoundlife[numenvsounds] = .4;
5212 if (environment == grassyenvironment)
5213 howmany = findLength(&velocity) * 4;
5214 if (environment == snowyenvironment)
5215 howmany = findLength(&velocity) * 2;
5217 if (environment != desertenvironment)
5218 for (j = 0; j < howmany; j++) {
5219 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5220 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5221 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5224 pos.x += float(abs(Random() % 100) - 50) / 200;
5225 pos.y += float(abs(Random() % 100) - 50) / 200;
5226 pos.z += float(abs(Random() % 100) - 50) / 200;
5227 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);
5228 Sprite::setLastSpriteSpecial(1);
5230 howmany = findLength(&velocity) * 4;
5232 if (environment == snowyenvironment)
5233 for (j = 0; j < howmany; j++) {
5234 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5235 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5236 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5239 pos.x += float(abs(Random() % 100) - 50) / 200;
5240 pos.y += float(abs(Random() % 100) - 50) / 200;
5241 pos.z += float(abs(Random() % 100) - 50) / 200;
5242 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5243 Sprite::setLastSpriteSpecial(2);
5246 objects.rotx[i] += velocity.x * multiplier * 6;
5247 objects.roty[i] += velocity.z * multiplier * 6;
5248 objects.messedwith[i] = .5;
5251 if (objects.type[i] == treeleavestype && environment != desertenvironment) {
5252 if (objects.pitch[i] == 0)
5255 tempcoord = coords - objects.position[i];
5256 tempcoord = DoRotation(tempcoord, 0, -objects.yaw[i], 0);
5257 tempcoord = DoRotation(tempcoord, -objects.pitch[i], 0, 0);
5258 tempcoord += objects.position[i];
5260 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]) {
5261 if (objects.messedwith[i] <= 0) {
5265 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5268 envsound[numenvsounds] = coords;
5269 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5270 envsoundlife[numenvsounds] = .4;
5275 if (environment == grassyenvironment)
5276 howmany = findLength(&velocity) * 4;
5277 if (environment == snowyenvironment)
5278 howmany = findLength(&velocity) * 2;
5280 if (environment != desertenvironment)
5281 for (j = 0; j < howmany; j++) {
5282 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5283 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5284 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5286 pos += velocity * .1;
5288 pos.x += float(abs(Random() % 100) - 50) / 150;
5289 pos.y += float(abs(Random() % 100) - 50) / 150;
5290 pos.z += float(abs(Random() % 100) - 50) / 150;
5291 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);
5292 Sprite::setLastSpriteSpecial(1);
5294 howmany = findLength(&velocity) * 4;
5296 if (environment == snowyenvironment)
5297 for (j = 0; j < howmany; j++) {
5298 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5299 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5300 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5302 pos += velocity * .1;
5304 pos.x += float(abs(Random() % 100) - 50) / 150;
5305 pos.y += float(abs(Random() % 100) - 50) / 150;
5306 pos.z += float(abs(Random() % 100) - 50) / 150;
5307 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5308 Sprite::setLastSpriteSpecial(2);
5311 objects.messedwith[i] = .5;
5316 if (!skeleton.free) {
5319 if ((stunned > 0 || surprised > 0) && numplayers > 2 && aitype != passivetype)
5322 if (aitype != passivetype && victim->skeleton.free && !victim->dead)
5324 if (tutoriallevel == 1 && id != 0)
5326 if (play && aitype != playercontrolled) {
5327 int whichsound = -1;
5328 i = abs(Random() % 4);
5329 if (speechdelay <= 0) {
5330 if (creature == rabbittype) {
5332 whichsound = rabbitchitter;
5334 whichsound = rabbitchitter2;
5336 if (creature == wolftype) {
5338 whichsound = growlsound;
5340 whichsound = growl2sound;
5345 if (whichsound != -1) {
5346 emit_sound_at(whichsound, coords);
5350 if (animTarget == staggerbackhighanim)
5352 if (animTarget == staggerbackhardanim)
5354 staggerdelay -= multiplier;
5355 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
5357 if (velocity.y < -30 && animTarget == jumpdownanim)
5359 if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) {
5360 animTarget = getIdle();
5364 weaponmissdelay -= multiplier;
5365 highreversaldelay -= multiplier;
5366 lowreversaldelay -= multiplier;
5367 lastcollide -= multiplier;
5368 skiddelay -= multiplier;
5369 if (!isnormal(velocity.x) && velocity.x) {
5372 if (!isnormal(targettilt) && targettilt) {
5375 if (!isnormal(targettilt2) && targettilt2) {
5378 if (!isnormal(targetyaw) && targetyaw) {
5382 if (animTarget == bounceidleanim || animTarget == wolfidle || animTarget == walkanim || animTarget == drawrightanim || animTarget == crouchdrawrightanim || animTarget == drawleftanim || animTarget == fightidleanim || animTarget == fightsidestep || animTarget == hanganim || isCrouch() || animTarget == backhandspringanim) {
5383 //open hands and close mouth
5384 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5385 righthandmorphness = 0;
5386 righthandmorphend = 0;
5387 targetrighthandmorphness = 1;
5390 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5391 lefthandmorphness = 0;
5392 lefthandmorphend = 0;
5393 targetlefthandmorphness = 1;
5396 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5 && headmorphend != 0 && headmorphness == targetheadmorphness) {
5399 targetheadmorphness = 1;
5403 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) {
5404 //open hands and mouth
5405 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5406 righthandmorphness = 0;
5407 righthandmorphend = 0;
5408 targetrighthandmorphness = 1;
5411 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5412 lefthandmorphness = 0;
5413 lefthandmorphend = 0;
5414 targetlefthandmorphness = 1;
5417 if (headmorphend != 1 && headmorphness == targetheadmorphness) {
5420 targetheadmorphness = 1;
5424 if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim || animTarget == blockhighleftanim) {
5425 //close hands and mouth
5426 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5427 righthandmorphness = 0;
5428 righthandmorphend = 1;
5429 targetrighthandmorphness = 1;
5432 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5433 lefthandmorphness = 0;
5434 lefthandmorphend = 1;
5435 targetlefthandmorphness = 1;
5438 if (headmorphend != 0 && headmorphness == targetheadmorphness) {
5441 targetheadmorphness = 1;
5445 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) {
5446 //close hands and yell
5447 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5448 righthandmorphness = 0;
5449 righthandmorphend = 1;
5450 targetrighthandmorphness = 1;
5453 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5454 lefthandmorphness = 0;
5455 lefthandmorphend = 1;
5456 targetlefthandmorphness = 1;
5459 if (headmorphend != 2 && headmorphness == targetheadmorphness) {
5462 targetheadmorphness = 1;
5469 if ((victim != this->shared_from_this()) && !victim->dead && (victim->aitype != passivetype) &&
5470 (victim->aitype != searchtype) && (aitype != passivetype) &&
5471 (aitype != searchtype) && (victim->id < numplayers) && (aitype != passivetype)) {
5472 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
5476 if (!dead && animTarget != hurtidleanim)
5477 if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) {
5478 if (headmorphend != 4 || headmorphness == targetheadmorphness) {
5481 targetheadmorphness = 1;
5485 if (weaponactive != -1) {
5486 if (weapons[weaponids[weaponactive]].getType() != staff) {
5487 righthandmorphstart = 1;
5488 righthandmorphend = 1;
5490 if (weapons[weaponids[weaponactive]].getType() == staff) {
5491 righthandmorphstart = 2;
5492 righthandmorphend = 2;
5494 targetrighthandmorphness = 1;
5497 terrainnormal = terrain.getNormal(coords.x, coords.z);
5499 if (animation[animTarget].attack != reversal) {
5500 if (!isnormal(coords.x))
5508 flatfacing = DoRotation(flatfacing, 0, yaw, 0);
5509 facing = flatfacing;
5510 ReflectVector(&facing, terrainnormal);
5513 if (isRun() || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) {
5515 targettilt2 = -facing.y * 20;
5520 if (!isRun() && !animation[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim)
5522 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5523 flatvelocity = velocity;
5525 flatvelspeed = findLength(&flatvelocity);
5526 targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity);
5527 targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity);
5532 if (targettilt > 25)
5534 if (targettilt < -25)
5538 if (targettilt2 > 45)
5540 if (targettilt2 < -45)
5542 if (abs(tilt2 - targettilt2) < multiplier * 400)
5543 tilt2 = targettilt2;
5544 else if (tilt2 > targettilt2) {
5545 tilt2 -= multiplier * 400;
5546 } else if (tilt2 < targettilt2) {
5547 tilt2 += multiplier * 400;
5549 if (!animation[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) {
5556 if (!isnormal(targettilt) && targettilt) {
5559 if (!isnormal(targettilt2) && targettilt2) {
5564 //if(!creature==wolftype||animTarget==rabbitkickanim)
5565 if (animTarget == rabbittackleanim) {
5566 velocity += facing * multiplier * speed * 700 * scale;
5567 velspeed = findLength(&velocity);
5568 if (velspeed > speed * 65 * scale) {
5569 velocity /= velspeed;
5570 velspeed = speed * 65 * scale;
5571 velocity *= velspeed;
5573 velocity.y += gravity * multiplier * 20;
5574 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5575 velspeed = findLength(&velocity);
5576 velocity = flatfacing * velspeed;
5578 if (animTarget != rabbitrunninganim && animTarget != wolfrunninganim) {
5579 if (isRun() || animTarget == rabbitkickanim) {
5580 velocity += facing * multiplier * speed * 700 * scale;
5581 velspeed = findLength(&velocity);
5582 if (velspeed > speed * 45 * scale) {
5583 velocity /= velspeed;
5584 velspeed = speed * 45 * scale;
5585 velocity *= velspeed;
5587 velocity.y += gravity * multiplier * 20;
5588 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5589 velspeed = findLength(&velocity);
5590 if (velspeed < speed * 30 * scale)
5591 velspeed = speed * 30 * scale;
5592 velocity = flatfacing * velspeed;
5594 } else if (isRun()) {
5595 velocity += facing * multiplier * speed * 700 * scale;
5596 velspeed = findLength(&velocity);
5597 if (creature == rabbittype) {
5598 if (velspeed > speed * 55 * scale) {
5599 velocity /= velspeed;
5600 velspeed = speed * 55 * scale;
5601 velocity *= velspeed;
5604 if (creature == wolftype) {
5605 if (velspeed > speed * 75 * scale) {
5606 velocity /= velspeed;
5607 velspeed = speed * 75 * scale;
5608 velocity *= velspeed;
5611 velocity.y += gravity * multiplier * 20;
5612 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5613 velspeed = findLength(&velocity);
5614 velocity = flatfacing * velspeed;
5617 if (animTarget == rollanim && animation[animTarget].label[frameTarget] != 6) {
5618 velocity += facing * multiplier * speed * 700 * scale;
5619 velspeed = findLength(&velocity);
5620 if (velspeed > speed * 45 * scale) {
5621 velocity /= velspeed;
5622 velspeed = speed * 45 * scale;
5623 velocity *= velspeed;
5625 velocity.y += gravity * multiplier * 20;
5626 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5627 velspeed = findLength(&velocity);
5628 velocity = flatfacing * velspeed;
5632 /*if(animCurrent==rollanim&&(isCrouch()||isIdle())){
5633 velocity+=facing*multiplier*speed*700*scale;
5634 velspeed=findLength(&velocity);
5635 if(velspeed>speed*25*scale){
5637 velspeed=speed*25*scale;
5640 velocity.y+=gravity*multiplier*20;
5641 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5642 velspeed=findLength(&velocity);
5643 velocity=flatfacing*velspeed;
5646 if (animTarget == sneakanim || animTarget == walkanim) {
5647 velocity += facing * multiplier * speed * 700 * scale;
5648 velspeed = findLength(&velocity);
5649 if (velspeed > speed * 12 * scale) {
5650 velocity /= velspeed;
5651 velspeed = speed * 12 * scale;
5652 velocity *= velspeed;
5654 velocity.y += gravity * multiplier * 20;
5655 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5656 velspeed = findLength(&velocity);
5657 velocity = flatfacing * velspeed;
5660 if ((animTarget == fightidleanim || animTarget == knifefightidleanim) && (animCurrent == bounceidleanim || animCurrent == hurtidleanim)) {
5661 velocity += facing * multiplier * speed * 700 * scale;
5662 velspeed = findLength(&velocity);
5663 if (velspeed > speed * 2 * scale) {
5664 velocity /= velspeed;
5665 velspeed = speed * 2 * scale;
5666 velocity *= velspeed;
5668 velocity.y += gravity * multiplier * 20;
5669 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5670 velspeed = findLength(&velocity);
5671 velocity = flatfacing * velspeed;
5675 if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) {
5676 velocity -= facing * multiplier * speed * 700 * scale;
5677 velspeed = findLength(&velocity);
5678 if (velspeed > speed * 2 * scale) {
5679 velocity /= velspeed;
5680 velspeed = speed * 2 * scale;
5681 velocity *= velspeed;
5683 velocity.y += gravity * multiplier * 20;
5684 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5685 velspeed = findLength(&velocity);
5686 velocity = flatfacing * velspeed * -1;
5689 if (animTarget == fightsidestep) {
5690 velocity += DoRotation(facing * multiplier * speed * 700 * scale, 0, -90, 0);
5691 velspeed = findLength(&velocity);
5692 if (velspeed > speed * 12 * scale) {
5693 velocity /= velspeed;
5694 velspeed = speed * 12 * scale;
5695 velocity *= velspeed;
5697 velocity.y += gravity * multiplier * 20;
5698 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5699 velspeed = findLength(&velocity);
5700 velocity = DoRotation(flatfacing * velspeed, 0, -90, 0);
5703 if (animTarget == staggerbackhighanim) {
5704 coords -= facing * multiplier * speed * 16 * scale;
5707 if (animTarget == staggerbackhardanim && animation[staggerbackhardanim].label[frameTarget] != 6) {
5708 coords -= facing * multiplier * speed * 20 * scale;
5712 if (animTarget == backhandspringanim) {
5713 //coords-=facing*multiplier*50*scale;
5714 velocity += facing * multiplier * speed * 700 * scale * -1;
5715 velspeed = findLength(&velocity);
5716 if (velspeed > speed * 50 * scale) {
5717 velocity /= velspeed;
5718 velspeed = speed * 50 * scale;
5719 velocity *= velspeed;
5721 velocity.y += gravity * multiplier * 20;
5722 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5723 velspeed = findLength(&velocity);
5724 velocity = flatfacing * velspeed * -1;
5726 if (animTarget == dodgebackanim) {
5727 //coords-=facing*multiplier*50*scale;
5728 velocity += facing * multiplier * speed * 700 * scale * -1;
5729 velspeed = findLength(&velocity);
5730 if (velspeed > speed * 60 * scale) {
5731 velocity /= velspeed;
5732 velspeed = speed * 60 * scale;
5733 velocity *= velspeed;
5735 velocity.y += gravity * multiplier * 20;
5736 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5737 velspeed = findLength(&velocity);
5738 velocity = flatfacing * velspeed * -1;
5741 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5742 velspeed = findLength(&velocity);
5746 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5747 velocity.y += gravity * multiplier;
5750 if (animTarget != climbanim && animTarget != hanganim && !isWallJump())
5751 coords += velocity * multiplier;
5753 if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
5754 if (isFlip() && animation[animTarget].label[frameTarget] == 7)
5757 if (animTarget == jumpupanim) {
5759 animTarget = getIdle();
5766 pause_sound(whooshsound);
5767 OPENAL_SetVolume(channels[whooshsound], 0);
5770 if (animTarget == jumpdownanim || isFlip()) {
5771 if (isFlip())jumppower = -4;
5772 animTarget = getLanding();
5773 emit_sound_at(landsound, coords, 128.);
5776 envsound[numenvsounds] = coords;
5777 envsoundvol[numenvsounds] = 16;
5778 envsoundlife[numenvsounds] = .4;
5784 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump())
5785 coords.y += gravity * multiplier * 2;
5786 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) {
5787 coords.y = terrain.getHeight(coords.x, coords.z);
5792 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)) {
5793 velspeed = findLength(&velocity);
5795 if (velspeed < multiplier * 300 * scale) {
5798 velocity -= velocity / velspeed * multiplier * 300 * scale;
5799 if (velspeed > 5 && (isLanding() || isLandhard())) {
5800 skiddingdelay += multiplier;
5801 if (skiddelay <= 0) {
5811 velspeed = findLength(&velocity);
5813 if (velspeed < multiplier * 600 * scale) {
5816 velocity -= velocity / velspeed * multiplier * 600 * scale;
5818 if (velspeed > 5 && (isLanding() || isLandhard())) {
5819 skiddingdelay += multiplier;
5820 if (skiddelay <= 0) {
5829 if (skiddingdelay < 0)
5830 skiddingdelay += multiplier;
5831 if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) {
5833 if (!onterrain || environment == grassyenvironment) {
5834 emit_sound_at(skidsound, coords, 128 * velspeed / 10);
5836 emit_sound_at(snowskidsound, coords, 128 * velspeed / 10);
5840 if (animation[animTarget].attack == normalattack && animTarget != rabbitkickanim && !victim->skeleton.free) {
5841 terrainnormal = victim->coords - coords;
5842 Normalise(&terrainnormal);
5843 targetyaw = -asin(0 - terrainnormal.x);
5844 targetyaw *= 360 / 6.28;
5845 if (terrainnormal.z < 0)
5846 targetyaw = 180 - targetyaw;
5847 targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70;
5850 if (animation[animTarget].attack == reversal && animTarget != rabbittacklinganim) {
5851 targetyaw = victim->targetyaw;
5853 if (animTarget == rabbittacklinganim) {
5854 coords = victim->coords;
5857 skeleton.oldfree = skeleton.free;
5861 midterrain.x = terrain.size * terrain.scale / 2;
5862 midterrain.z = terrain.size * terrain.scale / 2;
5863 if (distsqflat(&coords, &midterrain) > (terrain.size * terrain.scale / 2 - viewdistance) * (terrain.size * terrain.scale / 2 - viewdistance)) {
5865 tempposit = coords - midterrain;
5867 Normalise(&tempposit);
5868 tempposit *= (terrain.size * terrain.scale / 2 - viewdistance);
5869 coords.x = tempposit.x + midterrain.x;
5870 coords.z = tempposit.z + midterrain.z;
5876 * inverse kinematics helper function
5878 void IKHelper(Person *p, float interp)
5880 XYZ point, newpoint, change, change2;
5881 float heightleft, heightright;
5883 // TODO: implement localToWorld and worldToLocal
5884 // but keep in mind it won't be the same math if player is ragdolled or something
5885 // - localToWorldStanding / worldToLocalStanding (or crouching or...?)
5886 // then comb through code for places where to use it
5888 // point = localToWorld(jointPos(leftfoot))
5889 point = DoRotation(p->jointPos(leftfoot), 0, p->yaw, 0) * p->scale + p->coords;
5890 // adjust height of foot
5891 heightleft = terrain.getHeight(point.x, point.z) + .04;
5892 point.y = heightleft;
5893 change = p->jointPos(leftankle) - p->jointPos(leftfoot);
5894 change2 = p->jointPos(leftknee) - p->jointPos(leftfoot);
5895 // jointPos(leftfoot) = interpolate(worldToLocal(point), jointPos(leftfoot), interp)
5896 p->jointPos(leftfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(leftfoot) * (1 - interp);
5897 // move ankle along with foot
5898 p->jointPos(leftankle) = p->jointPos(leftfoot) + change;
5899 // average knee pos between old and new pos
5900 p->jointPos(leftknee) = (p->jointPos(leftfoot) + change2) / 2 + (p->jointPos(leftknee)) / 2;
5902 // do same as above for right leg
5903 point = DoRotation(p->jointPos(rightfoot), 0, p->yaw, 0) * p->scale + p->coords;
5904 heightright = terrain.getHeight(point.x, point.z) + .04;
5905 point.y = heightright;
5906 change = p->jointPos(rightankle) - p->jointPos(rightfoot);
5907 change2 = p->jointPos(rightknee) - p->jointPos(rightfoot);
5908 p->jointPos(rightfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(rightfoot) * (1 - interp);
5909 p->jointPos(rightankle) = p->jointPos(rightfoot) + change;
5910 p->jointPos(rightknee) = (p->jointPos(rightfoot) + change2) / 2 + (p->jointPos(rightknee)) / 2;
5912 // fix up skeleton now that we've moved body parts?
5913 p->skeleton.DoConstraints(&p->coords, &p->scale);
5920 int Person::DrawSkeleton()
5922 int oldplayerdetail;
5923 if ((frustum.SphereInFrustum(coords.x, coords.y + scale * 3, coords.z, scale * 8) && distsq(&viewer, &coords) < viewdistance * viewdistance) || skeleton.free == 3) {
5924 if (onterrain && (isIdle() || isCrouch() || wasIdle() || wasCrouch()) && !skeleton.free) {
5934 glAlphaFunc(GL_GREATER, 0.0001);
5936 float terrainheight;
5940 if (!isnormal(tilt))
5942 if (!isnormal(tilt2))
5944 oldplayerdetail = playerdetail;
5946 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) {
5949 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 128 && detail == 1) {
5952 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) {
5957 if (playerdetail != oldplayerdetail) {
5959 normalsupdatedelay = 0;
5961 static float updatedelaychange;
5962 static float morphness;
5963 static float framemult;
5965 skeleton.FindForwards();
5966 if (howactive == typesittingwall) {
5967 skeleton.specialforward[1] = 0;
5968 skeleton.specialforward[1].z = 1;
5974 static int weaponattachmuscle;
5975 static int weaponrotatemuscle;
5976 static XYZ weaponpoint;
5977 static int start, endthing;
5978 if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
5979 if (!isSleeping() && !isSitting()) {
5980 // TODO: give these meaningful names
5981 const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard()
5982 || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim);
5983 const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard()
5984 || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim);
5986 if (onterrain && (cond1 && cond2) && !skeleton.free) {
5988 if (creature == wolftype)
5992 if (onterrain && (cond1 && !cond2) && !skeleton.free) {
5993 IKHelper(this, target);
5994 if (creature == wolftype)
5995 IKHelper(this, target);
5998 if (onterrain && (!cond1 && cond2) && !skeleton.free) {
5999 IKHelper(this, 1 - target);
6000 if (creature == wolftype)
6001 IKHelper(this, 1 - target);
6005 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()))
6008 targetheadyaw = -targetyaw;
6009 targetheadpitch = 0;
6010 if (animation[animTarget].attack == 3)
6011 targetheadyaw += 180;
6013 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6014 skeleton.drawmodel.vertex[i] = 0;
6015 skeleton.drawmodel.vertex[i].y = 999;
6017 for (i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
6018 skeleton.drawmodellow.vertex[i] = 0;
6019 skeleton.drawmodellow.vertex[i].y = 999;
6021 for (i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
6022 skeleton.drawmodelclothes.vertex[i] = 0;
6023 skeleton.drawmodelclothes.vertex[i].y = 999;
6025 for (i = 0; i < skeleton.num_muscles; i++) {
6026 // convenience renames
6027 const int p1 = skeleton.muscles[i].parent1->label;
6028 const int p2 = skeleton.muscles[i].parent2->label;
6030 if ((skeleton.muscles[i].numvertices > 0 && playerdetail) || (skeleton.muscles[i].numverticeslow > 0 && !playerdetail)) {
6035 if (p1 == righthand || p2 == righthand) {
6036 morphness = righthandmorphness;
6037 start = righthandmorphstart;
6038 endthing = righthandmorphend;
6040 if (p1 == lefthand || p2 == lefthand) {
6041 morphness = lefthandmorphness;
6042 start = lefthandmorphstart;
6043 endthing = lefthandmorphend;
6045 if (p1 == head || p2 == head) {
6046 morphness = headmorphness;
6047 start = headmorphstart;
6048 endthing = headmorphend;
6050 if ((p1 == neck && p2 == abdomen) || (p2 == neck && p1 == abdomen)) {
6051 morphness = chestmorphness;
6052 start = chestmorphstart;
6053 endthing = chestmorphend;
6055 if ((p1 == groin && p2 == abdomen) || (p2 == groin && p1 == abdomen)) {
6056 morphness = tailmorphness;
6057 start = tailmorphstart;
6058 endthing = tailmorphend;
6061 skeleton.FindRotationMuscle(i, animTarget);
6062 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6063 glMatrixMode(GL_MODELVIEW);
6067 glRotatef(tilt2, 1, 0, 0);
6069 glRotatef(tilt, 0, 0, 1);
6072 glTranslatef(mid.x, mid.y, mid.z);
6074 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6075 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6077 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6078 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6080 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6081 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6083 if (playerdetail || skeleton.free == 3) {
6084 for (j = 0; j < skeleton.muscles[i].numvertices; j++) {
6085 XYZ &v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
6086 XYZ &v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
6087 glMatrixMode(GL_MODELVIEW);
6089 if (p1 == abdomen || p2 == abdomen)
6090 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionbody.x,
6091 (v0.y * (1 - morphness) + v1.y * morphness) * proportionbody.y,
6092 (v0.z * (1 - morphness) + v1.z * morphness) * proportionbody.z);
6093 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6094 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionarms.x,
6095 (v0.y * (1 - morphness) + v1.y * morphness) * proportionarms.y,
6096 (v0.z * (1 - morphness) + v1.z * morphness) * proportionarms.z);
6097 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6098 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionlegs.x,
6099 (v0.y * (1 - morphness) + v1.y * morphness) * proportionlegs.y,
6100 (v0.z * (1 - morphness) + v1.z * morphness) * proportionlegs.z);
6101 if (p1 == head || p2 == head)
6102 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionhead.x,
6103 (v0.y * (1 - morphness) + v1.y * morphness) * proportionhead.y,
6104 (v0.z * (1 - morphness) + v1.z * morphness) * proportionhead.z);
6105 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6106 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
6107 //if(!isnormal(scale))test=1;
6108 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale;
6109 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale;
6110 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z = M[14] * scale;
6115 if (!playerdetail || skeleton.free == 3) {
6116 for (j = 0; j < skeleton.muscles[i].numverticeslow; j++) {
6117 XYZ &v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
6118 glMatrixMode(GL_MODELVIEW);
6120 if (p1 == abdomen || p2 == abdomen)
6121 glTranslatef(v0.x * proportionbody.x,
6122 v0.y * proportionbody.y,
6123 v0.z * proportionbody.z);
6124 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6125 glTranslatef(v0.x * proportionarms.x,
6126 v0.y * proportionarms.y,
6127 v0.z * proportionarms.z);
6128 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6129 glTranslatef(v0.x * proportionlegs.x,
6130 v0.y * proportionlegs.y,
6131 v0.z * proportionlegs.z);
6132 if (p1 == head || p2 == head)
6133 glTranslatef(v0.x * proportionhead.x,
6134 v0.y * proportionhead.y,
6135 v0.z * proportionhead.z);
6137 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6138 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
6139 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y = M[13] * scale;
6140 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z = M[14] * scale;
6146 if (skeleton.clothes && skeleton.muscles[i].numverticesclothes > 0) {
6147 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6149 glMatrixMode(GL_MODELVIEW);
6153 glRotatef(tilt2, 1, 0, 0);
6155 glRotatef(tilt, 0, 0, 1);
6156 glTranslatef(mid.x, mid.y, mid.z);
6157 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6158 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6160 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6161 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6163 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6164 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6166 for (j = 0; j < skeleton.muscles[i].numverticesclothes; j++) {
6167 XYZ &v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
6168 glMatrixMode(GL_MODELVIEW);
6170 if (p1 == abdomen || p2 == abdomen)
6171 glTranslatef(v0.x * proportionbody.x,
6172 v0.y * proportionbody.y,
6173 v0.z * proportionbody.z);
6174 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6175 glTranslatef(v0.x * proportionarms.x,
6176 v0.y * proportionarms.y,
6177 v0.z * proportionarms.z);
6178 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6179 glTranslatef(v0.x * proportionlegs.x,
6180 v0.y * proportionlegs.y,
6181 v0.z * proportionlegs.z);
6182 if (p1 == head || p2 == head)
6183 glTranslatef(v0.x * proportionhead.x,
6184 v0.y * proportionhead.y,
6185 v0.z * proportionhead.z);
6186 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6187 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
6188 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
6189 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z = M[14] * scale;
6194 updatedelay = 1 + (float)(Random() % 100) / 1000;
6196 if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) {
6197 normalsupdatedelay = 1;
6198 if (playerdetail || skeleton.free == 3)
6199 skeleton.drawmodel.CalculateNormals(0);
6200 if (!playerdetail || skeleton.free == 3)
6201 skeleton.drawmodellow.CalculateNormals(0);
6202 if (skeleton.clothes)
6203 skeleton.drawmodelclothes.CalculateNormals(0);
6205 if (playerdetail || skeleton.free == 3)
6206 skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
6207 if (!playerdetail || skeleton.free == 3)
6208 skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
6209 if (skeleton.clothes) {
6210 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6215 updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1);
6216 if (updatedelaychange > -realmultiplier * 30)
6217 updatedelaychange = -realmultiplier * 30;
6218 if (updatedelaychange > -framemult * 4)
6219 updatedelaychange = -framemult * 4;
6220 if (skeleton.free == 1)
6221 updatedelaychange *= 6;
6223 updatedelaychange *= 8;
6224 updatedelay += updatedelaychange;
6226 glMatrixMode(GL_MODELVIEW);
6229 glTranslatef(coords.x, coords.y - .02, coords.z);
6231 glTranslatef(coords.x, coords.y - .02, coords.z);
6233 glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
6235 glRotatef(yaw, 0, 1, 0);
6238 glColor4f(.4, 1, .4, 1);
6239 glDisable(GL_LIGHTING);
6240 glDisable(GL_TEXTURE_2D);
6243 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6244 XYZ &v0 = skeleton.drawmodel.vertex[i];
6245 glVertex3f(v0.x, v0.y, v0.z);
6251 for (i = 0; i < skeleton.drawmodel.TriangleNum; i++) {
6252 XYZ &v0 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]];
6253 XYZ &v1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]];
6254 XYZ &v2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]];
6255 glVertex3f(v0.x, v0.y, v0.z);
6256 glVertex3f(v1.x, v1.y, v1.z);
6257 glVertex3f(v1.x, v1.y, v1.z);
6258 glVertex3f(v2.x, v2.y, v2.z);
6259 glVertex3f(v2.x, v2.y, v2.z);
6260 glVertex3f(v0.x, v0.y, v0.z);
6266 terrainlight = terrain.getLighting(coords.x, coords.z);
6267 distance = distsq(&viewer, &coords);
6268 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
6272 terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1;
6273 if (terrainheight < 1)
6275 if (terrainheight > 1.7)
6276 terrainheight = 1.7;
6279 glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance);
6280 glDisable(GL_BLEND);
6281 glAlphaFunc(GL_GREATER, 0.0001);
6282 glEnable(GL_TEXTURE_2D);
6284 glDisable(GL_TEXTURE_2D);
6285 glColor4f(.7, .35, 0, .5);
6287 glEnable(GL_LIGHTING);
6290 if (tutoriallevel && id != 0) {
6291 //glDisable(GL_TEXTURE_2D);
6292 glColor4f(.7, .7, .7, 0.6);
6294 glEnable(GL_LIGHTING);
6296 if (canattack && cananger)
6297 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6298 glDisable(GL_TEXTURE_2D);
6299 glColor4f(1, 0, 0, 0.8);
6301 glMatrixMode(GL_TEXTURE);
6303 glTranslatef(0, -smoketex, 0);
6304 glTranslatef(-smoketex, 0, 0);
6308 if ((tutoriallevel && id != 0))
6309 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6311 skeleton.drawmodel.draw();
6314 if (!playerdetail) {
6315 if ((tutoriallevel && id != 0))
6316 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6318 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6321 if (!(animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed))
6322 if (tutoriallevel && id != 0) {
6324 glMatrixMode(GL_MODELVIEW);
6325 glEnable(GL_TEXTURE_2D);
6326 glColor4f(.7, .7, .7, 0.6);
6328 glEnable(GL_LIGHTING);
6330 if (canattack && cananger)
6331 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6332 glDisable(GL_TEXTURE_2D);
6333 glColor4f(1, 0, 0, 0.8);
6335 glMatrixMode(GL_TEXTURE);
6337 glTranslatef(0, -smoketex * .6, 0);
6338 glTranslatef(smoketex * .6, 0, 0);
6341 if ((tutoriallevel && id != 0))
6342 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6344 skeleton.drawmodel.draw();
6347 if (!playerdetail) {
6348 if ((tutoriallevel && id != 0))
6349 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6351 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6356 if (tutoriallevel && id != 0) {
6358 glMatrixMode(GL_MODELVIEW);
6359 glEnable(GL_TEXTURE_2D);
6361 if (skeleton.clothes) {
6365 skeleton.drawmodelclothes.draw();
6367 skeleton.drawmodelclothes.drawimmediate();
6373 if (num_weapons > 0) {
6374 for (k = 0; k < num_weapons; k++) {
6376 if (weaponactive == k) {
6377 if (weapons[i].getType() != staff) {
6378 for (j = 0; j < skeleton.num_muscles; j++) {
6379 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6380 weaponattachmuscle = j;
6383 for (j = 0; j < skeleton.num_muscles; j++) {
6384 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) {
6385 weaponrotatemuscle = j;
6388 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6389 if (creature == wolftype)
6390 weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3);
6392 if (weapons[i].getType() == staff) {
6393 for (j = 0; j < skeleton.num_muscles; j++) {
6394 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6395 weaponattachmuscle = j;
6398 for (j = 0; j < skeleton.num_muscles; j++) {
6399 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) {
6400 weaponrotatemuscle = j;
6403 //weaponpoint=jointPos(rightwrist);
6404 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6405 //weaponpoint+=skeleton.specialforward[1]*.1+(jointPos(rightwrist)-jointPos(rightelbow));
6406 XYZ tempnormthing, vec1, vec2;
6407 vec1 = (jointPos(rightwrist) - jointPos(rightelbow));
6408 vec2 = (jointPos(rightwrist) - jointPos(rightshoulder));
6409 CrossProduct(&vec1, &vec2, &tempnormthing);
6410 Normalise(&tempnormthing);
6411 if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim)
6412 weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow));
6415 if (weaponactive != k && weaponstuck != k) {
6416 if (weapons[i].getType() == knife)
6417 weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35;
6418 if (weapons[i].getType() == sword)
6419 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6420 if (weapons[i].getType() == staff)
6421 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6422 for (j = 0; j < skeleton.num_muscles; j++) {
6423 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) {
6424 weaponrotatemuscle = j;
6428 if (weaponstuck == k) {
6429 if (weaponstuckwhere == 0)
6430 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8;
6432 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
6433 for (j = 0; j < skeleton.num_muscles; j++) {
6434 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) {
6435 weaponrotatemuscle = j;
6439 if (skeleton.free) {
6440 weapons[i].position = weaponpoint * scale + coords;
6441 weapons[i].bigrotation = 0;
6442 weapons[i].bigtilt = 0;
6443 weapons[i].bigtilt2 = 0;
6445 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;
6446 weapons[i].bigrotation = yaw;
6447 weapons[i].bigtilt = tilt;
6448 weapons[i].bigtilt2 = tilt2;
6450 weapons[i].rotation1 = skeleton.muscles[weaponrotatemuscle].lastrotate1;
6451 weapons[i].rotation2 = skeleton.muscles[weaponrotatemuscle].lastrotate2;
6452 weapons[i].rotation3 = skeleton.muscles[weaponrotatemuscle].lastrotate3;
6453 if (weaponactive == k) {
6454 if (weapons[i].getType() == knife) {
6455 weapons[i].smallrotation = 180;
6456 weapons[i].smallrotation2 = 0;
6457 if (isCrouch() || wasCrouch()) {
6458 weapons[i].smallrotation2 = 20;
6460 if (animTarget == hurtidleanim) {
6461 weapons[i].smallrotation2 = 50;
6463 if ((animCurrent == crouchstabanim && animTarget == crouchstabanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
6464 XYZ temppoint1, temppoint2, tempforward;
6467 temppoint1 = jointPos(righthand);
6468 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6469 distance = findDistance(&temppoint1, &temppoint2);
6470 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6471 weapons[i].rotation2 *= 360 / 6.28;
6474 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6475 weapons[i].rotation1 *= 360 / 6.28;
6476 weapons[i].rotation3 = 0;
6477 weapons[i].smallrotation = -90;
6478 weapons[i].smallrotation2 = 0;
6479 if (temppoint1.x > temppoint2.x)
6480 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6482 if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) {
6483 XYZ temppoint1, temppoint2, tempforward;
6486 temppoint1 = jointPos(righthand);
6487 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6488 distance = findDistance(&temppoint1, &temppoint2);
6489 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6490 weapons[i].rotation2 *= 360 / 6.28;
6493 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6494 weapons[i].rotation1 *= 360 / 6.28;
6495 weapons[i].rotation3 = 0;
6496 weapons[i].smallrotation = 90;
6497 weapons[i].smallrotation2 = 0;
6498 if (temppoint1.x > temppoint2.x)
6499 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6501 if (animTarget == knifethrowanim) {
6502 weapons[i].smallrotation = 90;
6503 //weapons[i].smallrotation2=-90;
6504 weapons[i].smallrotation2 = 0;
6505 weapons[i].rotation1 = 0;
6506 weapons[i].rotation2 = 0;
6507 weapons[i].rotation3 = 0;
6509 if (animTarget == knifesneakattackanim && frameTarget < 5) {
6510 weapons[i].smallrotation = -90;
6511 weapons[i].rotation1 = 0;
6512 weapons[i].rotation2 = 0;
6513 weapons[i].rotation3 = 0;
6516 if (weapons[i].getType() == sword) {
6517 weapons[i].smallrotation = 0;
6518 weapons[i].smallrotation2 = 0;
6519 if (animTarget == knifethrowanim) {
6520 weapons[i].smallrotation = -90;
6521 weapons[i].smallrotation2 = 0;
6522 weapons[i].rotation1 = 0;
6523 weapons[i].rotation2 = 0;
6524 weapons[i].rotation3 = 0;
6526 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)) {
6527 XYZ temppoint1, temppoint2, tempforward;
6530 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6531 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6532 distance = findDistance(&temppoint1, &temppoint2);
6533 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6534 weapons[i].rotation2 *= 360 / 6.28;
6537 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6538 weapons[i].rotation1 *= 360 / 6.28;
6539 weapons[i].rotation3 = 0;
6540 weapons[i].smallrotation = 90;
6541 weapons[i].smallrotation2 = 0;
6542 if (temppoint1.x > temppoint2.x)
6543 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6546 if (weapons[i].getType() == staff) {
6547 weapons[i].smallrotation = 100;
6548 weapons[i].smallrotation2 = 0;
6549 if ((animTarget == staffhitanim && animCurrent == staffhitanim) || (animTarget == staffhitreversedanim && animCurrent == staffhitreversedanim) || (animTarget == staffspinhitreversedanim && animCurrent == staffspinhitreversedanim) || (animTarget == staffgroundsmashanim && animCurrent == staffgroundsmashanim) || (animTarget == staffspinhitanim && animCurrent == staffspinhitanim)) {
6550 XYZ temppoint1, temppoint2, tempforward;
6553 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6554 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6555 distance = findDistance(&temppoint1, &temppoint2);
6556 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6557 weapons[i].rotation2 *= 360 / 6.28;
6560 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6561 weapons[i].rotation1 *= 360 / 6.28;
6562 weapons[i].rotation3 = 0;
6563 weapons[i].smallrotation = 90;
6564 weapons[i].smallrotation2 = 0;
6565 if (temppoint1.x > temppoint2.x)
6566 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6570 if (weaponactive != k && weaponstuck != k) {
6571 if (weapons[i].getType() == knife) {
6572 weapons[i].smallrotation = -70;
6573 weapons[i].smallrotation2 = 10;
6575 if (weapons[i].getType() == sword) {
6576 weapons[i].smallrotation = -100;
6577 weapons[i].smallrotation2 = -8;
6579 if (weapons[i].getType() == staff) {
6580 weapons[i].smallrotation = -100;
6581 weapons[i].smallrotation2 = -8;
6584 if (weaponstuck == k) {
6585 if (weaponstuckwhere == 0)
6586 weapons[i].smallrotation = 180;
6588 weapons[i].smallrotation = 0;
6589 weapons[i].smallrotation2 = 10;
6598 if (animation[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isFlip() || isWallJump())
6600 if (animCurrent != animTarget)
6602 //if(id==0)calcrot=1;
6603 if (skeleton.free == 2)
6612 int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6615 static float distance;
6616 static float olddistance;
6617 static int intersecting;
6618 static int firstintersecting;
6621 static XYZ start, end;
6622 static float slopethreshold = -.4;
6624 firstintersecting = -1;
6628 if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius)
6631 *p1 = DoRotation(*p1, 0, -*rotate, 0);
6632 for (i = 0; i < 4; i++) {
6633 for (j = 0; j < model->TriangleNum; j++) {
6634 if (model->facenormals[j].y <= slopethreshold) {
6636 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)));
6637 if (distance < radius) {
6638 point = *p1 - model->facenormals[j] * distance;
6639 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]]))
6642 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6643 &model->vertex[model->Triangles[j].vertex[1]],
6646 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6647 &model->vertex[model->Triangles[j].vertex[2]],
6650 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6651 &model->vertex[model->Triangles[j].vertex[2]],
6654 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6658 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)) {
6659 p1->y = point.y + radius;
6660 if ((animTarget == jumpdownanim || isFlip())) {
6661 if (isFlip() && (frameTarget < 5 || animation[animTarget].label[frameTarget] == 7 || animation[animTarget].label[frameTarget] == 4))
6664 if (animTarget == jumpupanim) {
6666 animTarget = getIdle();
6673 pause_sound(whooshsound);
6674 OPENAL_SetVolume(channels[whooshsound], 0);
6677 if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) {
6680 animTarget = getLanding();
6681 emit_sound_at(landsound, coords, 128.);
6684 envsound[numenvsounds] = coords;
6685 envsoundvol[numenvsounds] = 16;
6686 envsoundlife[numenvsounds] = .4;
6694 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6695 olddistance = distance;
6696 firstintersecting = j;
6701 for (j = 0; j < model->TriangleNum; j++) {
6702 if (model->facenormals[j].y > slopethreshold) {
6705 start.y -= radius / 4;
6706 XYZ &v0 = model->vertex[model->Triangles[j].vertex[0]];
6707 XYZ &v1 = model->vertex[model->Triangles[j].vertex[1]];
6708 XYZ &v2 = model->vertex[model->Triangles[j].vertex[2]];
6709 distance = abs((model->facenormals[j].x * start.x)
6710 + (model->facenormals[j].y * start.y)
6711 + (model->facenormals[j].z * start.z)
6712 - ((model->facenormals[j].x * v0.x)
6713 + (model->facenormals[j].y * v0.y)
6714 + (model->facenormals[j].z * v0.z)));
6715 if (distance < radius * .5) {
6716 point = start - model->facenormals[j] * distance;
6717 if (PointInTriangle( &point, model->facenormals[j], &v0, &v1, &v2))
6720 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
6722 intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6724 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6726 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6727 if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
6729 velocity -= DoRotation(model->facenormals[j], 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->facenormals[j], 0, *rotate, 0))); //(distance-radius*.5)/multiplier;
6730 if (findLengthfast(&start) < findLengthfast(&velocity))
6733 *p1 += model->facenormals[j] * (distance - radius * .5);
6736 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6737 olddistance = distance;
6738 firstintersecting = j;
6745 *p = DoRotation(*p, 0, *rotate, 0);
6748 *p1 = DoRotation(*p1, 0, *rotate, 0);
6750 return firstintersecting;