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 std::vector<std::shared_ptr<Person>> Person::players(1, std::shared_ptr<Person>(new Person()));
91 * GameTick/doPlayerCollisions
93 void Person::CheckKick()
96 && (animTarget == rabbitkickanim
98 && victim != this->shared_from_this()
100 && animCurrent == rabbitkickanim)
101 && distsq(&coords, &victim->coords) < 1.2
102 && !victim->skeleton.free))
105 if (animation[victim->animTarget].height != lowheight) {
106 float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
107 XYZ relative = velocity;
109 Normalise(&relative);
113 if (tutoriallevel != 1)
114 emit_sound_at(heavyimpactsound, victim->coords);
116 for (int i = 0; i < victim->skeleton.num_joints; i++) {
117 victim->skeleton.joints[i].velocity += relative * 120 * damagemult;
120 victim->DoDamage(100 * damagemult / victim->protectionhigh);
126 animTarget = backflipanim;
128 velocity = facing * -10;
132 resume_stream(whooshsound);
134 award_bonus(id, cannon);
135 } else if (victim->isCrouch()) {
136 animTarget = rabbitkickreversedanim;
137 animCurrent = rabbitkickreversedanim;
138 victim->animCurrent = rabbitkickreversalanim;
139 victim->animTarget = rabbitkickreversalanim;
145 victim->oldcoords = victim->coords;
146 coords = victim->coords;
147 victim->targetyaw = targetyaw;
148 victim->victim = this->shared_from_this();
155 * GameTick/doPlayerCollisions - spread fire between players
156 * GameTick/doDebugKeys - press f to ignite
157 * Person::DoStuff - spread fire from lit campfires and bushes
159 void Person::CatchFire()
161 XYZ flatfacing, flatvelocity;
163 for (int i = 0; i < 10; i++) {
164 howmany = abs(Random() % (skeleton.num_joints));
166 flatvelocity = velocity;
168 flatvelocity = skeleton.joints[howmany].velocity;
170 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
172 flatfacing = skeleton.joints[howmany].position * scale + coords;
173 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
178 emit_sound_at(firestartsound, coords);
180 emit_stream_at(stream_firesound, coords);
188 * idle animation for this creature (depending on status)
190 int Person::getIdle()
192 if (indialogue != -1 && howactive == typeactive && creature == rabbittype)
194 if (hasvictim && (victim != this->shared_from_this())/*||(id==0&&attackkeydown)*/)
195 if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype &&
196 victim->aitype != searchtype && aitype != passivetype && aitype != searchtype &&
197 victim->id < Person::players.size())) {
198 if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) {
199 if (creature == rabbittype)
200 return fightidleanim;
201 if (creature == wolftype)
204 if (aitype == playercontrolled && stunned <= 0 && weaponactive != -1) {
205 if (weapons[weaponids[weaponactive]].getType() == knife)
206 return knifefightidleanim;
207 if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1)
208 return swordfightidlebothanim;
209 if (weapons[weaponids[weaponactive]].getType() == sword)
210 return swordfightidleanim;
211 if (weapons[weaponids[weaponactive]].getType() == staff)
212 return swordfightidleanim;
214 if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause)
215 return fightsidestep;
217 if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype)
219 if (howactive == typesitting) return sitanim;
220 if (howactive == typesittingwall) return sitwallanim;
221 if (howactive == typesleeping) return sleepanim;
222 if (howactive == typedead1) return dead1anim;
223 if (howactive == typedead2) return dead2anim;
224 if (howactive == typedead3) return dead3anim;
225 if (howactive == typedead4) return dead4anim;
226 if (creature == rabbittype) return bounceidleanim;
227 if (creature == wolftype) return wolfidle;
232 * crouch animation for this creature
234 int Person::getCrouch()
236 if (creature == rabbittype)
238 if (creature == wolftype)
239 return wolfcrouchanim;
244 * running animation for this creature (can be upright or all fours)
248 if (creature == rabbittype && (!superruntoggle || weaponactive != -1))
250 if (creature == wolftype && (!superruntoggle))
253 if (creature == rabbittype && (superruntoggle && weaponactive == -1))
254 return rabbitrunninganim;
255 if (creature == wolftype && (superruntoggle))
256 return wolfrunninganim;
262 int Person::getStop()
264 if (creature == rabbittype)
266 if (creature == wolftype)
273 int Person::getLanding()
275 if (creature == rabbittype)
277 if (creature == wolftype)
284 int Person::getLandhard()
286 if (creature == rabbittype)
288 if (creature == wolftype)
289 return wolflandhardanim;
296 * Person::DoAnimations
299 SolidHitBonus(int playerid)
301 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
302 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
304 award_bonus(playerid, solidhit);
308 * spawns blood effects
310 void Person::DoBlood(float howmuch, int which)
312 // FIXME: should abstract out inputs
313 static int bleedxint, bleedyint;
315 //if(howmuch&&id==0)blooddimamount=1;
316 if (bloodtoggle && tutoriallevel != 1) {
317 if (bleeding <= 0 && spurt) {
319 for (int i = 0; i < 3; i++) {
320 // emit blood particles
322 if (!skeleton.free) {
324 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
327 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
330 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
332 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
334 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
335 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
337 if (!skeleton.free) {
338 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
339 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
342 if (Random() % 2 == 0) // 50% chance
343 for (int i = 0; i < 3; i++) {
344 if (Random() % 2 != 0) {
345 // emit teeth particles
348 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
349 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
352 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
353 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
357 Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
359 Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
361 Sprite::setLastSpriteSpecial(3); // sets it to teeth
366 // FIXME: manipulating attributes
367 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
370 if (creature == rabbittype)
371 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) {
372 bleedxint = abs(Random() % 512);
373 bleedyint = abs(Random() % 512);
375 if (creature == wolftype)
376 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) {
377 bleedxint = abs(Random() % 512);
378 bleedyint = abs(Random() % 512);
382 bleedy /= realtexdetail;
383 bleedx /= realtexdetail;
384 direction = abs(Random() % 2) * 2 - 1;
393 * spawns big blood effects and ???
394 * modifies character's skin texture
396 void Person::DoBloodBig(float howmuch, int which)
398 static int bleedxint, bleedyint, i, j;
400 if (howmuch && id == 0)
403 if (tutoriallevel != 1 || id == 0)
404 if (aitype != playercontrolled && howmuch > 0) {
408 // FIXME: seems to be spawning sounds by manipulating attributes... MESSY!
409 if (creature == wolftype) {
410 int i = abs(Random() % 2);
412 whichsound = snarlsound;
414 whichsound = snarl2sound;
415 envsound[numenvsounds] = coords;
416 envsoundvol[numenvsounds] = 16;
417 envsoundlife[numenvsounds] = .4;
420 if (creature == rabbittype) {
421 int i = abs(Random() % 2);
423 whichsound = rabbitpainsound;
424 if (i == 1 && howmuch >= 2)
425 whichsound = rabbitpain1sound;
426 envsound[numenvsounds] = coords;
427 envsoundvol[numenvsounds] = 16;
428 envsoundlife[numenvsounds] = .4;
430 //if(i==2)whichsound=rabbitpain2sound;
433 if (whichsound != -1)
434 emit_sound_at(whichsound, coords);
437 if (id == 0 && howmuch > 0) {
438 // FIXME: manipulating attributes
446 if (bloodtoggle && decals && tutoriallevel != 1) {
447 if (bleeding <= 0 && spurt) {
449 for (int i = 0; i < 3; i++) {
450 // emit blood particles
451 // FIXME: copypaste from above
453 if (!skeleton.free) {
455 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
458 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
461 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
463 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
465 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
466 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
468 if (!skeleton.free) {
469 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
470 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
475 // weird texture manipulation code follows.
476 // looks like this is painting blood onto the character's skin texture
477 // FIXME: surely there's a better way
479 int offsetx = 0, offsety = 0;
481 offsety = Random() % 40;
482 offsetx = abs(Random() % 60);
484 if (which == 190 || which == 185) {
485 offsety = Random() % 40;
486 offsetx = abs(Random() % 100) - 20;
489 offsety = Random() % 10;
490 offsetx = Random() % 10;
493 offsety = Random() % 20;
494 offsetx = Random() % 20;
496 if (which == 220 || which == 215) {
506 if (creature == rabbittype)
507 for (i = 0; i < 512; i++) {
508 for (j = 0; j < 512; j++) {
509 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
510 if (i < startx) startx = i;
511 if (j < starty) starty = j;
512 if (i > endx) endx = i;
513 if (j > endy) endy = j;
517 if (creature == wolftype)
518 for (i = 0; i < 512; i++) {
519 for (j = 0; j < 512; j++) {
520 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
521 if (i < startx) startx = i;
522 if (j < starty) starty = j;
523 if (i > endx) endx = i;
524 if (j > endy) endy = j;
534 if (startx < 0) startx = 0;
535 if (starty < 0) starty = 0;
536 if (endx > 512 - 1) endx = 512 - 1;
537 if (endy > 512 - 1) endy = 512 - 1;
538 if (endx < startx) endx = startx;
539 if (endy < starty) endy = starty;
541 startx /= realtexdetail;
542 starty /= realtexdetail;
543 endx /= realtexdetail;
544 endy /= realtexdetail;
546 int texdetailint = realtexdetail;
548 if (creature == rabbittype)
549 for (i = startx; i < endx; i++) {
550 for (j = starty; j < endy; j++) {
551 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) {
552 color = Random() % 85 + 170;
553 where = i * skeleton.skinsize * 3 + j * 3;
554 if (skeleton.skinText[where + 0] > color / 2)
555 skeleton.skinText[where + 0] = color / 2;
556 skeleton.skinText[where + 1] = 0;
557 skeleton.skinText[where + 2] = 0;
561 if (creature == wolftype)
562 for (i = startx; i < endx; i++) {
563 for (j = starty; j < endy; j++) {
564 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) {
565 color = Random() % 85 + 170;
566 where = i * skeleton.skinsize * 3 + j * 3;
567 if (skeleton.skinText[where + 0] > color / 2)
568 skeleton.skinText[where + 0] = color / 2;
569 skeleton.skinText[where + 1] = 0;
570 skeleton.skinText[where + 2] = 0;
574 skeleton.drawmodel.textureptr.bind();
579 if (creature == rabbittype)
580 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) {
581 bleedxint = abs(Random() % 512);
582 bleedyint = abs(Random() % 512);
584 if (creature == wolftype)
585 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) {
586 bleedxint = abs(Random() % 512);
587 bleedyint = abs(Random() % 512);
589 bleedy = bleedxint + offsetx;
590 bleedx = bleedyint + offsety;
591 bleedy /= realtexdetail;
592 bleedx /= realtexdetail;
597 if (bleedx > skeleton.skinsize - 1)
598 bleedx = skeleton.skinsize - 1;
599 if (bleedy > skeleton.skinsize - 1)
600 bleedy = skeleton.skinsize - 1;
601 direction = abs(Random() % 2) * 2 - 1;
604 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
605 deathbleeding += bleeding;
606 bloodloss += bleeding * 3;
608 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
609 if (abs(Random() % 2) == 0) {
610 aitype = gethelptype;
613 aitype = attacktypecutoff;
621 * similar to DoBloodBig
623 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
627 static XYZ startpoint, endpoint, colpoint, movepoint;
628 static float rotationpoint;
630 static XYZ p1, p2, p3, p0;
634 float coordsx, coordsy;
637 if (bloodtoggle && decals && tutoriallevel != 1) {
640 where = DoRotation(where, 0, -yaw, 0);
648 // ray testing for a tri in the character model
649 whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
650 if (whichtri != -1) {
651 // low level geometry math
653 p1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
654 p2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
655 p3 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
657 CrossProduct(p2-p1,p3-p1,&N);
658 CrossProduct(p0-p1,p3-p1,&temp);
659 s = dotproduct(&temp,&N)/findLength(&N);
660 CrossProduct(p2-p1,p1-p0,&temp);
661 t = dotproduct(&temp,&N)/findLength(&N);
664 bary.x = distsq(&p0, &p1);
665 bary.y = distsq(&p0, &p2);
666 bary.z = distsq(&p0, &p3);
668 total = bary.x + bary.y + bary.z;
677 total = bary.x + bary.y + bary.z;
683 gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0];
684 gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1];
685 gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2];
686 gyy.x = skeleton.drawmodel.Triangles[whichtri].gy[0];
687 gyy.y = skeleton.drawmodel.Triangles[whichtri].gy[1];
688 gyy.z = skeleton.drawmodel.Triangles[whichtri].gy[2];
689 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;
690 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;
692 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
693 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
695 if (bleeding <= 0 && spurt) {
697 for (int i = 0; i < 3; i++) {
698 // emit blood particles
699 // FIXME: more copypaste code
701 if (!skeleton.free) {
703 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
706 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
709 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
711 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
713 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
714 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
716 if (!skeleton.free) {
717 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
718 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
723 // texture manipulation follows
725 int offsetx = 0, offsety = 0;
728 offsetx=abs(Random()%120);
730 if(which==220||which==215){
732 offsetx=abs(Random()%80);
735 offsetx = (1 + coordsy) * 512 - 291;
736 offsety = coordsx * 512 - 437;
743 if (creature == rabbittype)
744 for (i = 0; i < 512; i++) {
745 for (j = 0; j < 512; j++) {
746 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
747 if (i < startx) startx = i;
748 if (j < starty) starty = j;
749 if (i > endx) endx = i;
750 if (j > endy) endy = j;
754 if (creature == wolftype)
755 for (i = 0; i < 512; i++) {
756 for (j = 0; j < 512; j++) {
757 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
758 if (i < startx) startx = i;
759 if (j < starty) starty = j;
760 if (i > endx) endx = i;
761 if (j > endy) endy = j;
770 if (startx < 0) startx = 0;
771 if (starty < 0) starty = 0;
772 if (endx > 512 - 1) endx = 512 - 1;
773 if (endy > 512 - 1) endy = 512 - 1;
774 if (endx < startx) endx = startx;
775 if (endy < starty) endy = starty;
777 startx /= realtexdetail;
778 starty /= realtexdetail;
779 endx /= realtexdetail;
780 endy /= realtexdetail;
782 int texdetailint = realtexdetail;
784 if (creature == rabbittype)
785 for (i = startx; i < endx; i++) {
786 for (j = starty; j < endy; j++) {
787 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) {
788 color = Random() % 85 + 170;
789 where = i * skeleton.skinsize * 3 + j * 3;
790 if (skeleton.skinText[where + 0] > color / 2)
791 skeleton.skinText[where + 0] = color / 2;
792 skeleton.skinText[where + 1] = 0;
793 skeleton.skinText[where + 2] = 0;
794 } 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) {
795 color = Random() % 85 + 170;
796 where = i * skeleton.skinsize * 3 + j * 3;
797 if (skeleton.skinText[where + 0] > color / 2)
798 skeleton.skinText[where + 0] = color / 2;
799 skeleton.skinText[where + 1] = 0;
800 skeleton.skinText[where + 2] = 0;
804 if (creature == wolftype)
805 for (i = startx; i < endx; i++) {
806 for (j = starty; j < endy; j++) {
807 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) {
808 color = Random() % 85 + 170;
809 where = i * skeleton.skinsize * 3 + j * 3;
810 if (skeleton.skinText[where + 0] > color / 2)
811 skeleton.skinText[where + 0] = color / 2;
812 skeleton.skinText[where + 1] = 0;
813 skeleton.skinText[where + 2] = 0;
814 } 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) {
815 color = Random() % 85 + 170;
816 where = i * skeleton.skinsize * 3 + j * 3;
817 if (skeleton.skinText[where + 0] > color / 2)
818 skeleton.skinText[where + 0] = color / 2;
819 skeleton.skinText[where + 1] = 0;
820 skeleton.skinText[where + 2] = 0;
824 skeleton.drawmodel.textureptr.bind();
827 bleedy = (1 + coordsy) * 512;
828 bleedx = coordsx * 512;
829 bleedy /= realtexdetail;
830 bleedx /= realtexdetail;
835 if (bleedx > skeleton.skinsize - 1)
836 bleedx = skeleton.skinsize - 1;
837 if (bleedy > skeleton.skinsize - 1)
838 bleedy = skeleton.skinsize - 1;
839 direction = abs(Random() % 2) * 2 - 1;
844 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
845 deathbleeding += bleeding;
846 bloodloss += bleeding * 3;
848 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
849 if (abs(Random() % 2) == 0) {
850 aitype = gethelptype;
853 aitype = attacktypecutoff;
864 * guessing this performs a reversal
866 void Person::Reverse()
868 if (!((victim->aitype == playercontrolled
870 || staggerdelay <= 0)
871 && victim->animTarget != jumpupanim
872 && victim->animTarget != jumpdownanim
873 && (tutoriallevel != 1 || cananger)
877 if (normaldotproduct (victim->facing, victim->coords - coords) > 0
878 && (victim->id != 0 || difficulty >= 2)
879 && (creature != wolftype || victim->creature == wolftype))
882 if (animTarget == sweepanim) {
883 animTarget = sweepreversedanim;
884 animCurrent = sweepreversedanim;
885 victim->animCurrent = sweepreversalanim;
886 victim->animTarget = sweepreversalanim;
888 if (animTarget == spinkickanim) {
889 animTarget = spinkickreversedanim;
890 animCurrent = spinkickreversedanim;
891 victim->animCurrent = spinkickreversalanim;
892 victim->animTarget = spinkickreversalanim;
894 if (animTarget == upunchanim || animTarget == rabbittacklinganim) {
895 if (animTarget == rabbittacklinganim) {
898 victim->frameCurrent = 6;
899 victim->frameTarget = 7;
901 animTarget = upunchreversedanim;
902 animCurrent = upunchreversedanim;
903 victim->animCurrent = upunchreversalanim;
904 victim->animTarget = upunchreversalanim;
906 if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
907 if (victim->weaponactive != -1) {
908 victim->throwtogglekeydown = 1;
909 weapons[victim->weaponids[0]].owner = -1;
910 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
911 if (weapons[victim->weaponids[0]].velocity.x == 0)
912 weapons[victim->weaponids[0]].velocity.x = .1;
913 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
914 weapons[victim->weaponids[0]].missed = 1;
915 weapons[victim->weaponids[0]].freetime = 0;
916 weapons[victim->weaponids[0]].firstfree = 1;
917 weapons[victim->weaponids[0]].physics = 1;
918 victim->num_weapons--;
919 if (victim->num_weapons) {
920 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
921 if (victim->weaponstuck == victim->num_weapons)
922 victim->weaponstuck = 0;
925 victim->weaponactive = -1;
926 for (unsigned j = 0; j < Person::players.size(); j++) {
927 Person::players[j]->wentforweapon = 0;
931 animTarget = staffhitreversedanim;
932 animCurrent = staffhitreversedanim;
933 victim->animCurrent = staffhitreversalanim;
934 victim->animTarget = staffhitreversalanim;
936 if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
937 if (victim->weaponactive != -1) {
938 victim->throwtogglekeydown = 1;
939 weapons[victim->weaponids[0]].owner = -1;
940 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
941 if (weapons[victim->weaponids[0]].velocity.x == 0)
942 weapons[victim->weaponids[0]].velocity.x = .1;
943 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
944 weapons[victim->weaponids[0]].missed = 1;
945 weapons[victim->weaponids[0]].freetime = 0;
946 weapons[victim->weaponids[0]].firstfree = 1;
947 weapons[victim->weaponids[0]].physics = 1;
948 victim->num_weapons--;
949 if (victim->num_weapons) {
950 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
951 if (victim->weaponstuck == victim->num_weapons)
952 victim->weaponstuck = 0;
955 victim->weaponactive = -1;
956 for (unsigned j = 0; j < Person::players.size(); j++) {
957 Person::players[j]->wentforweapon = 0;
960 animTarget = staffspinhitreversedanim;
961 animCurrent = staffspinhitreversedanim;
962 victim->animCurrent = staffspinhitreversalanim;
963 victim->animTarget = staffspinhitreversalanim;
965 if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
966 if (victim->weaponactive != -1) {
967 victim->throwtogglekeydown = 1;
968 weapons[victim->weaponids[0]].owner = -1;
969 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
970 if (weapons[victim->weaponids[0]].velocity.x == 0)
971 weapons[victim->weaponids[0]].velocity.x = .1;
972 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
973 weapons[victim->weaponids[0]].missed = 1;
974 weapons[victim->weaponids[0]].freetime = 0;
975 weapons[victim->weaponids[0]].firstfree = 1;
976 weapons[victim->weaponids[0]].physics = 1;
977 victim->num_weapons--;
978 if (victim->num_weapons) {
979 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
980 if (victim->weaponstuck == victim->num_weapons)
981 victim->weaponstuck = 0;
984 victim->weaponactive = -1;
985 for (unsigned j = 0; j < Person::players.size(); j++) {
986 Person::players[j]->wentforweapon = 0;
989 animTarget = swordslashreversedanim;
990 animCurrent = swordslashreversedanim;
991 victim->animCurrent = swordslashreversalanim;
992 victim->animTarget = swordslashreversalanim;
994 if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
995 if (victim->weaponactive != -1) {
996 victim->throwtogglekeydown = 1;
997 weapons[victim->weaponids[0]].owner = -1;
998 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
999 if (weapons[victim->weaponids[0]].velocity.x == 0)
1000 weapons[victim->weaponids[0]].velocity.x = .1;
1001 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
1002 weapons[victim->weaponids[0]].missed = 1;
1003 weapons[victim->weaponids[0]].freetime = 0;
1004 weapons[victim->weaponids[0]].firstfree = 1;
1005 weapons[victim->weaponids[0]].physics = 1;
1006 victim->num_weapons--;
1007 if (victim->num_weapons) {
1008 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1009 if (victim->weaponstuck == victim->num_weapons)
1010 victim->weaponstuck = 0;
1013 victim->weaponactive = -1;
1014 for (unsigned j = 0; j < Person::players.size(); j++) {
1015 Person::players[j]->wentforweapon = 0;
1018 animTarget = knifeslashreversedanim;
1019 animCurrent = knifeslashreversedanim;
1020 victim->animCurrent = knifeslashreversalanim;
1021 victim->animTarget = knifeslashreversalanim;
1023 if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim && animTarget != swordslashanim) {
1024 victim->targettilt2 = targettilt2;
1025 victim->frameCurrent = frameCurrent;
1026 victim->frameTarget = frameTarget;
1027 victim->target = target;
1028 victim->velocity = 0;
1029 victim->oldcoords = victim->coords;
1030 victim->coords = coords;
1031 victim->targetyaw = targetyaw;
1032 victim->yaw = targetyaw;
1033 victim->victim = this->shared_from_this();
1035 if (animTarget == winduppunchanim) {
1036 animTarget = winduppunchblockedanim;
1037 victim->animTarget = blockhighleftanim;
1038 victim->frameTarget = 1;
1039 victim->target = .5;
1040 victim->victim = this->shared_from_this();
1041 victim->targetyaw = targetyaw + 180;
1043 if (animTarget == wolfslapanim) {
1044 animTarget = winduppunchblockedanim;
1045 victim->animTarget = blockhighleftanim;
1046 victim->frameTarget = 1;
1047 victim->target = .5;
1048 victim->victim = this->shared_from_this();
1049 victim->targetyaw = targetyaw + 180;
1051 if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) {
1052 animTarget = swordslashparriedanim;
1053 parriedrecently = .4;
1054 victim->parriedrecently = 0;
1055 victim->animTarget = swordslashparryanim;
1056 victim->frameTarget = 1;
1057 victim->target = .5;
1058 victim->victim = this->shared_from_this();
1059 victim->targetyaw = targetyaw + 180;
1061 if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
1062 if (victim->weaponactive != -1) {
1063 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1064 if (weapons[victim->weaponids[0]].getType() == staff)
1065 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1066 if (weapons[weaponids[0]].getType() == staff)
1067 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1068 emit_sound_at(swordstaffsound, victim->coords);
1070 emit_sound_at(metalhitsound, victim->coords);
1074 victim->Puff(righthand);
1076 victim->frameTarget = 0;
1077 victim->animTarget = staggerbackhighanim;
1078 victim->targetyaw = targetyaw + 180;
1080 weapons[victim->weaponids[0]].owner = -1;
1081 aim = DoRotation(facing, 0, 90, 0) * 21;
1083 weapons[victim->weaponids[0]].velocity = aim * -.2;
1084 weapons[victim->weaponids[0]].tipvelocity = aim;
1085 weapons[victim->weaponids[0]].missed = 1;
1086 weapons[victim->weaponids[0]].hitsomething = 0;
1087 weapons[victim->weaponids[0]].freetime = 0;
1088 weapons[victim->weaponids[0]].firstfree = 1;
1089 weapons[victim->weaponids[0]].physics = 1;
1090 victim->num_weapons--;
1091 if (victim->num_weapons) {
1092 victim->weaponids[0] = victim->weaponids[num_weapons];
1093 if (victim->weaponstuck == victim->num_weapons)
1094 victim->weaponstuck = 0;
1096 victim->weaponactive = -1;
1097 for (unsigned i = 0; i < Person::players.size(); i++) {
1098 Person::players[i]->wentforweapon = 0;
1102 if (abs(Random() % 20) == 0) {
1103 if (weaponactive != -1) {
1104 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1105 if (weapons[victim->weaponids[0]].getType() == staff)
1106 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1107 if (weapons[weaponids[0]].getType() == staff)
1108 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1110 emit_sound_at(swordstaffsound, coords);
1112 emit_sound_at(metalhitsound, coords);
1120 animTarget = staggerbackhighanim;
1121 targetyaw = targetyaw + 180;
1123 weapons[weaponids[0]].owner = -1;
1124 aim = DoRotation(facing, 0, 90, 0) * 21;
1126 weapons[weaponids[0]].velocity = aim * -.2;
1127 weapons[weaponids[0]].tipvelocity = aim;
1128 weapons[weaponids[0]].hitsomething = 0;
1129 weapons[weaponids[0]].missed = 1;
1130 weapons[weaponids[0]].freetime = 0;
1131 weapons[weaponids[0]].firstfree = 1;
1132 weapons[weaponids[0]].physics = 1;
1135 weaponids[0] = weaponids[num_weapons];
1136 if (weaponstuck == num_weapons)
1140 for (unsigned i = 0; i < Person::players.size(); i++) {
1141 Person::players[i]->wentforweapon = 0;
1148 if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) {
1149 if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) {
1150 victim->animTarget = dodgebackanim;
1151 victim->frameTarget = 0;
1155 rotatetarget = coords - victim->coords;
1156 Normalise(&rotatetarget);
1157 victim->targetyaw = -asin(0 - rotatetarget.x);
1158 victim->targetyaw *= 360 / 6.28;
1159 if (rotatetarget.z < 0)
1160 victim->targetyaw = 180 - victim->targetyaw;
1162 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1164 victim->lastattack3 = victim->lastattack2;
1165 victim->lastattack2 = victim->lastattack;
1166 victim->lastattack = victim->animTarget;
1168 victim->animTarget = sweepanim;
1169 victim->frameTarget = 0;
1173 rotatetarget = coords - victim->coords;
1174 Normalise(&rotatetarget);
1175 victim->targetyaw = -asin(0 - rotatetarget.x);
1176 victim->targetyaw *= 360 / 6.28;
1177 if (rotatetarget.z < 0)
1178 victim->targetyaw = 180 - victim->targetyaw;
1180 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1182 victim->lastattack3 = victim->lastattack2;
1183 victim->lastattack2 = victim->lastattack;
1184 victim->lastattack = victim->animTarget;
1189 victim->velocity = 0;
1191 if (aitype != playercontrolled)
1193 if (aitype != playercontrolled && Random() % 3 == 0 && escapednum < 2 && difficulty == 2)
1195 if (aitype != playercontrolled && Random() % 5 == 0 && escapednum < 2 && difficulty == 1)
1197 if (aitype != playercontrolled && Random() % 10 == 0 && escapednum < 2 && difficulty == 0)
1200 if (victim->id == 0 && animation[victim->animTarget].attack == reversal)
1207 void Person::DoDamage(float howmuch)
1209 // subtract health (temporary?)
1210 if (tutoriallevel != 1)
1211 damage += howmuch / power;
1214 damagedealt += howmuch / power;
1216 damagetaken += howmuch / power;
1219 if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo))
1222 if (tutoriallevel != 1)
1223 permanentdamage += howmuch / 2 / power;
1224 if (tutoriallevel != 1)
1225 superpermanentdamage += howmuch / 4 / power;
1227 if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2)
1229 if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt)
1233 camerashake += howmuch / 100;
1234 if (id == 0 && ((howmuch > 50 && damage > damagetolerance / 2)))
1235 blackout = damage / damagetolerance;
1240 if (aitype == passivetype && damage < damagetolerance && ((tutoriallevel != 1 || cananger) && hostile))
1241 aitype = attacktypecutoff;
1242 if (tutoriallevel != 1 && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
1243 if (abs(Random() % 2) == 0) {
1244 aitype = gethelptype;
1247 aitype = attacktypecutoff;
1251 if (howmuch > damagetolerance * 50 && skeleton.free != 2) {
1254 for (int i = 0; i < skeleton.num_joints; i++) {
1256 flatvelocity2 = velocity;
1258 flatvelocity2 = skeleton.joints[i].velocity;
1260 flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
1262 flatfacing2 = skeleton.joints[i].position * scale + coords;
1263 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1264 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1265 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1266 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1267 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1268 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1271 emit_sound_at(splattersound, coords);
1280 if (!dead && creature == wolftype) {
1281 award_bonus(0, Wolfbonus);
1288 if (tutoriallevel != 1 || id == 0)
1289 if (speechdelay <= 0 && !dead && aitype != playercontrolled) {
1290 int whichsound = -1;
1292 if (creature == wolftype) {
1293 int i = abs(Random() % 2);
1295 whichsound = snarlsound;
1297 whichsound = snarl2sound;
1298 envsound[numenvsounds] = coords;
1299 envsoundvol[numenvsounds] = 16;
1300 envsoundlife[numenvsounds] = .4;
1303 if (creature == rabbittype) {
1304 int i = abs(Random() % 2);
1306 whichsound = rabbitpainsound;
1307 if (i == 1 && damage > damagetolerance)
1308 whichsound = rabbitpain1sound;
1309 envsound[numenvsounds] = coords;
1310 envsoundvol[numenvsounds] = 16;
1311 envsoundlife[numenvsounds] = .4;
1313 //if(i==2)whichsound=rabbitpain2sound;
1316 if (whichsound != -1) {
1317 emit_sound_at(whichsound, coords);
1322 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1323 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1327 * calculate/animate head facing direction?
1329 void Person::DoHead()
1331 static XYZ rotatearound;
1333 static float lookspeed = 500;
1335 if (!freeze && !winfreeze) {
1338 targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100;
1339 targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100;
1341 while (targetheadyaw > 180)targetheadyaw -= 360;
1342 while (targetheadyaw < -180)targetheadyaw += 360;
1344 if (targetheadyaw > 160)
1345 targetheadpitch = targetheadpitch * -1;
1346 if (targetheadyaw < -160)
1347 targetheadpitch = targetheadpitch * -1;
1348 if (targetheadyaw > 160)
1349 targetheadyaw = targetheadyaw - 180;
1350 if (targetheadyaw < -160)
1351 targetheadyaw = targetheadyaw + 180;
1353 if (targetheadpitch > 120)
1354 targetheadpitch = 120;
1355 if (targetheadpitch < -120)
1356 targetheadpitch = -120;
1357 if (targetheadyaw > 120)
1358 targetheadyaw = 120;
1359 if (targetheadyaw < -120)
1360 targetheadyaw = -120;
1363 targetheadpitch = 0;
1365 if (targetheadyaw > 80)
1367 if (targetheadyaw < -80)
1368 targetheadyaw = -80;
1369 if (targetheadpitch > 50)
1370 targetheadpitch = 50;
1371 if (targetheadpitch < -50)
1372 targetheadpitch = -50;
1375 if (abs(headyaw - targetheadyaw) < multiplier * lookspeed)
1376 headyaw = targetheadyaw;
1377 else if (headyaw > targetheadyaw) {
1378 headyaw -= multiplier * lookspeed;
1379 } else if (headyaw < targetheadyaw) {
1380 headyaw += multiplier * lookspeed;
1383 if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2)
1384 headpitch = targetheadpitch;
1385 else if (headpitch > targetheadpitch) {
1386 headpitch -= multiplier * lookspeed / 2;
1387 } else if (headpitch < targetheadpitch) {
1388 headpitch += multiplier * lookspeed / 2;
1391 rotatearound = jointPos(neck);
1392 jointPos(head) = rotatearound + DoRotation(jointPos(head) - rotatearound, headpitch, 0, 0);
1396 if (animTarget != bounceidleanim && animTarget != fightidleanim && animTarget != wolfidle && animTarget != knifefightidleanim && animTarget != drawrightanim && animTarget != drawleftanim && animTarget != walkanim) {
1397 facing = DoRotation(facing, headpitch * .4, 0, 0);
1398 facing = DoRotation(facing, 0, headyaw * .4, 0);
1401 if (animTarget == bounceidleanim || animTarget == fightidleanim || animTarget == wolfidle || animTarget == knifefightidleanim || animTarget == drawrightanim || animTarget == drawleftanim) {
1402 facing = DoRotation(facing, headpitch * .8, 0, 0);
1403 facing = DoRotation(facing, 0, headyaw * .8, 0);
1406 if (animTarget == walkanim) {
1407 facing = DoRotation(facing, headpitch * .6, 0, 0);
1408 facing = DoRotation(facing, 0, headyaw * .6, 0);
1411 skeleton.specialforward[0] = facing;
1412 //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1413 for (int 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 (int 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 (int 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 (int 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 (int 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 (unsigned i = 0; i < Person::players.size(); 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) {
1687 static float oldtarget;
1689 if (isIdle() && animCurrent != getIdle())
1690 normalsupdatedelay = 0;
1692 if (animTarget == tempanim || animCurrent == tempanim) {
1693 animation[tempanim] = tempanimation;
1695 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
1701 vel[0] = velocity.x;
1702 vel[1] = velocity.y;
1703 vel[2] = velocity.z;
1706 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1707 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
1709 if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z))
1711 if (!crouchkeydown && velocity.y >= -15)
1714 if ((animCurrent == jumpupanim || animTarget == jumpdownanim)/*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) {
1719 targfacing = DoRotation(targfacing, 0, targetyaw, 0);
1721 if (normaldotproduct(targfacing, velocity) >= -.3)
1722 animTarget = flipanim;
1724 animTarget = backflipanim;
1725 crouchtogglekeydown = 1;
1733 if (animation[animTarget].attack != reversed)
1735 if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) {
1736 crouchtogglekeydown = 0;
1737 if (aitype == playercontrolled)
1740 if (!crouchtogglekeydown && animation[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain))
1743 crouchtogglekeydown = 1;
1747 if (animation[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) {
1749 normalsupdatedelay = 0;
1753 if (animTarget == rollanim && frameTarget == 3 && onfire) {
1755 emit_sound_at(fireendsound, coords);
1756 pause_sound(stream_firesound);
1760 if (animTarget == rabbittacklinganim && frameTarget == 1) {
1761 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->animTarget].attack==neutral&&victim->id!=0)Reverse();
1762 if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0)
1764 if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) {
1765 if (normaldotproduct(victim->facing, facing) > 0)
1766 victim->animTarget = rabbittackledbackanim;
1768 victim->animTarget = rabbittackledfrontanim;
1769 victim->frameTarget = 2;
1772 victim->targetyaw = yaw;
1773 if (victim->aitype == gethelptype)
1774 victim->DoDamage(victim->damagetolerance - victim->damage);
1775 //victim->DoDamage(30);
1776 if (creature == wolftype) {
1778 emit_sound_at(clawslicesound, victim->coords);
1780 victim->DoBloodBig(1 / victim->armorhead, 210);
1782 award_bonus(id, TackleBonus,
1783 victim->aitype == gethelptype ? 50 : 0);
1787 if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (animation[animTarget].label[frameTarget] || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) {
1788 if (weapons[weaponids[0]].getType() == knife) {
1789 if (weaponactive == -1)
1791 else if (weaponactive == 0)
1794 if (weaponactive == -1) {
1795 emit_sound_at(knifesheathesound, coords);
1797 if (weaponactive != -1) {
1798 emit_sound_at(knifedrawsound, coords, 128);
1801 drawtogglekeydown = 1;
1804 if (tutoriallevel != 1 || id == 0)
1805 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1808 if (terrain.getOpacity(coords.x, coords.z) < .2) {
1809 if (animation[animTarget].label[frameTarget] == 1)
1810 whichsound = footstepsound;
1812 whichsound = footstepsound2;
1813 if (animation[animTarget].label[frameTarget] == 1)
1815 if (animation[animTarget].label[frameTarget] == 2)
1817 if (animation[animTarget].label[frameTarget] == 3 && isRun()) {
1823 if (terrain.getOpacity(coords.x, coords.z) >= .2) {
1824 if (animation[animTarget].label[frameTarget] == 1)
1825 whichsound = footstepsound3;
1827 whichsound = footstepsound4;
1831 if (animation[animTarget].label[frameTarget] == 1)
1832 whichsound = footstepsound3;
1834 whichsound = footstepsound4;
1836 if (animation[animTarget].label[frameTarget] == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
1837 if (animation[animTarget].attack != neutral) {
1838 unsigned r = abs(Random() % 3);
1840 whichsound = lowwhooshsound;
1842 whichsound = midwhooshsound;
1844 whichsound = highwhooshsound;
1846 if (animation[animTarget].attack == neutral)
1847 whichsound = movewhooshsound;
1848 } else if (animation[animTarget].label[frameTarget] == 4)
1849 whichsound = knifeswishsound;
1850 if (animation[animTarget].label[frameTarget] == 8 && tutoriallevel != 1)
1851 whichsound = landsound2;
1853 emit_sound_at(whichsound, coords, 256.);
1856 if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
1857 envsound[numenvsounds] = coords;
1858 if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim)
1859 envsoundvol[numenvsounds] = 15;
1861 envsoundvol[numenvsounds] = 6;
1862 envsoundlife[numenvsounds] = .4;
1866 if (animation[animTarget].label[frameTarget] == 3) {
1868 emit_sound_at(whichsound, coords, 128.);
1873 if (tutoriallevel != 1 || id == 0)
1874 if (speechdelay <= 0)
1875 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
1876 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1877 int whichsound = -1;
1878 if (animation[animTarget].label[frameTarget] == 4 && aitype != playercontrolled) {
1879 if (animation[animTarget].attack != neutral) {
1880 unsigned r = abs(Random() % 4);
1881 if (creature == rabbittype) {
1882 if (r == 0) whichsound = rabbitattacksound;
1883 if (r == 1) whichsound = rabbitattack2sound;
1884 if (r == 2) whichsound = rabbitattack3sound;
1885 if (r == 3) whichsound = rabbitattack4sound;
1887 if (creature == wolftype) {
1888 if (r == 0) whichsound = barksound;
1889 if (r == 1) whichsound = bark2sound;
1890 if (r == 2) whichsound = bark3sound;
1891 if (r == 3) whichsound = barkgrowlsound;
1895 //if(animation[animTarget].attack==neutral)whichsound=movewhooshsound;
1897 //else if(animation[animTarget].label[frameTarget]==4)whichsound=knifeswishsound;
1898 //if(animation[animTarget].label[frameTarget]==8)whichsound=landsound2;
1900 if (whichsound != -1) {
1901 emit_sound_at(whichsound, coords);
1907 if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) {
1913 currentoffset = targetoffset;
1914 frameTarget = frameCurrent;
1915 animCurrent = animTarget;
1918 if (animTarget == removeknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1919 for (unsigned i = 0; i < weapons.size(); i++) {
1920 if (weapons[i].owner == -1)
1921 if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
1922 if (distsq(&coords, &weapons[i].position) >= 1) {
1923 if (weapons[i].getType() != staff) {
1924 emit_sound_at(knifedrawsound, coords, 128.);
1928 weapons[i].owner = id;
1929 if (num_weapons > 0) {
1930 weaponids[num_weapons] = weaponids[0];
1939 if (animTarget == crouchremoveknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1940 for (unsigned i = 0; i < weapons.size(); i++) {
1941 bool willwork = true;
1942 if (weapons[i].owner != -1)
1943 if (Person::players[weapons[i].owner]->weaponstuck != -1)
1944 if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == int(i))
1945 if (Person::players[weapons[i].owner]->num_weapons > 1)
1947 if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free))
1948 if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) {
1949 if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
1950 bool fleshstuck = false;
1951 if (weapons[i].owner != -1)
1952 if (victim->weaponstuck != -1) {
1953 if (victim->weaponids[victim->weaponstuck] == int(i)) {
1958 emit_sound_at(fleshstabremovesound, coords, 128.);
1960 if (weapons[i].getType() != staff) {
1961 emit_sound_at(knifedrawsound, coords, 128.);
1965 if (weapons[i].owner != -1) {
1967 victim = Person::players[weapons[i].owner];
1968 if (victim->num_weapons == 1)
1969 victim->num_weapons = 0;
1971 victim->num_weapons = 1;
1973 //victim->weaponactive=-1;
1974 victim->skeleton.longdead = 0;
1975 victim->skeleton.free = 1;
1976 victim->skeleton.broken = 0;
1978 for (int j = 0; j < victim->skeleton.num_joints; j++) {
1979 victim->skeleton.joints[j].velchange = 0;
1980 victim->skeleton.joints[j].locked = 0;
1986 Normalise(&relative);
1987 XYZ footvel, footpoint;
1989 footpoint = weapons[i].position;
1990 if (victim->weaponstuck != -1) {
1991 if (victim->weaponids[victim->weaponstuck] == int(i)) {
1993 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
1994 weapons[i].bloody = 2;
1995 weapons[i].blooddrip = 5;
1996 victim->weaponstuck = -1;
1999 if (victim->num_weapons > 0) {
2000 if (victim->weaponstuck != 0 && victim->weaponstuck != -1)
2001 victim->weaponstuck = 0;
2002 if (victim->weaponids[0] == int(i))
2003 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
2006 victim->jointVel(abdomen) += relative * 6;
2007 victim->jointVel(neck) += relative * 6;
2008 victim->jointVel(rightshoulder) += relative * 6;
2009 victim->jointVel(leftshoulder) += relative * 6;
2011 weapons[i].owner = id;
2012 if (num_weapons > 0) {
2013 weaponids[num_weapons] = weaponids[0];
2022 if (animCurrent == drawleftanim && animation[animTarget].label[frameCurrent] == 5) {
2023 if (weaponactive == -1)
2025 else if (weaponactive == 0) {
2027 if (num_weapons == 2) {
2029 buffer = weaponids[0];
2030 weaponids[0] = weaponids[1];
2031 weaponids[1] = buffer;
2034 if (weaponactive == -1) {
2035 emit_sound_at(knifesheathesound, coords, 128.);
2037 if (weaponactive != -1) {
2038 emit_sound_at(knifedrawsound, coords, 128.);
2043 if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) {
2044 XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0);
2045 Normalise(&rotatetarget);
2046 targetyaw = -asin(0 - rotatetarget.x);
2047 targetyaw *= 360 / 6.28;
2048 if (rotatetarget.z < 0)
2049 targetyaw = 180 - targetyaw;
2051 if (animTarget == walljumprightkickanim)
2053 if (animTarget == walljumpleftkickanim)
2059 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0))
2062 if (distsq(&victim->coords, &/*Person::players[i]->*/coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1)
2067 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) {
2068 animTarget = rabbittackleanim;
2070 emit_sound_at(jumpsound, coords);
2078 targetloc = velocity;
2079 Normalise(&targetloc);
2080 targetloc += coords;
2081 for (unsigned i = 0; i < Person::players.size(); i++) {
2083 if (distsq(&targetloc, &Person::players[i]->coords) < closestdist || closestdist == 0) {
2084 closestdist = distsq(&targetloc, &Person::players[i]->coords);
2088 if (closestid != -1)
2089 if (closestdist < 5 && !Person::players[closestid]->dead && animation[Person::players[closestid]->animTarget].height != lowheight && Person::players[closestid]->animTarget != backhandspringanim) {
2091 victim = Person::players[closestid];
2092 coords = victim->coords;
2093 animCurrent = rabbittacklinganim;
2094 animTarget = rabbittacklinganim;
2098 if (coords.z != victim->coords.z || coords.x != victim->coords.x) {
2099 rotatetarget = coords - victim->coords;
2100 Normalise(&rotatetarget);
2101 targetyaw = -asin(0 - rotatetarget.x);
2102 targetyaw *= 360 / 6.28;
2103 if (rotatetarget.z < 0)
2104 targetyaw = 180 - targetyaw;
2106 if (animTarget != rabbitrunninganim) {
2107 emit_sound_at(jumpsound, coords, 128.);
2113 float damagemult = 1 * power;
2114 if (creature == wolftype)
2115 damagemult = 2.5 * power;
2117 damagemult /= victim->damagetolerance / 200;
2119 //if(onfire)damagemult=3;
2120 if ((animation[animTarget].attack == normalattack || animTarget == walljumprightkickanim || animTarget == walljumpleftkickanim) && (!feint) && (victim->skeleton.free != 2 || animTarget == killanim || animTarget == dropkickanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == staffgroundsmashanim)) {
2121 if (animTarget == spinkickanim && animation[animTarget].label[frameCurrent] == 5) {
2122 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2126 if (Random() % 2 || creature == wolftype) {
2129 if (creature == wolftype)
2132 if (tutoriallevel != 1) {
2133 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2135 if (creature == wolftype) {
2136 emit_sound_at(clawslicesound, victim->coords, 128.);
2138 victim->DoBloodBig(2 / victim->armorhead, 175);
2142 relative = victim->coords - coords;
2144 Normalise(&relative);
2145 relative = DoRotation(relative, 0, -90, 0);
2146 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2147 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2149 victim->jointVel(head) += relative * damagemult * 200;
2152 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2158 if (animTarget == wolfslapanim && animation[animTarget].label[frameCurrent] == 5) {
2159 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2163 if (Random() % 2 || creature == wolftype) {
2165 if (creature == wolftype)
2168 emit_sound_at(whooshhitsound, victim->coords);
2169 if (creature == wolftype) {
2170 emit_sound_at(clawslicesound, victim->coords, 128.);
2172 victim->DoBloodBig(2, 175);
2176 relative = victim->coords - coords;
2178 Normalise(&relative);
2180 Normalise(&relative);
2181 relative = DoRotation(relative, 0, 90, 0);
2182 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2183 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2185 victim->jointVel(head) += relative * damagemult * 100;
2188 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2192 if (animTarget == walljumprightkickanim && animation[animTarget].label[frameCurrent] == 5) {
2193 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2199 if (tutoriallevel != 1) {
2200 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2202 if (creature == wolftype) {
2203 emit_sound_at(clawslicesound, victim->coords, 128.);
2205 victim->DoBloodBig(2 / victim->armorhead, 175);
2211 Normalise(&relative);
2212 relative = DoRotation(relative, 0, -90, 0);
2213 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2214 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2216 victim->jointVel(head) += relative * damagemult * 200;
2219 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2221 if (victim->damage > victim->damagetolerance)
2222 award_bonus(id, style);
2228 if (animTarget == walljumpleftkickanim && animation[animTarget].label[frameCurrent] == 5) {
2229 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2235 if (tutoriallevel != 1) {
2236 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2238 if (creature == wolftype) {
2239 emit_sound_at(clawslicesound, victim->coords, 128.);
2241 victim->DoBloodBig(2 / victim->armorhead, 175);
2247 Normalise(&relative);
2248 relative = DoRotation(relative, 0, 90, 0);
2249 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2250 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2252 victim->jointVel(head) += relative * damagemult * 200;
2255 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2257 if (victim->damage > victim->damagetolerance)
2258 award_bonus(id, style);
2264 if (animTarget == blockhighleftstrikeanim && animation[animTarget].label[frameCurrent] == 5) {
2265 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2273 emit_sound_at(whooshhitsound, victim->coords);
2276 relative = victim->coords - coords;
2278 Normalise(&relative);
2279 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2280 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
2282 victim->jointVel(head) += relative * damagemult * 100;
2285 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2289 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 8) {
2290 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) {
2294 emit_sound_at(whooshhitsound, victim->coords, 128.);
2296 victim->skeleton.longdead = 0;
2297 victim->skeleton.free = 1;
2298 victim->skeleton.broken = 0;
2299 victim->skeleton.spinny = 1;
2301 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2302 victim->skeleton.joints[i].velchange = 0;
2303 victim->skeleton.joints[i].delay = 0;
2304 victim->skeleton.joints[i].locked = 0;
2305 //victim->skeleton.joints[i].velocity=0;
2311 Normalise(&relative);
2312 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2313 victim->skeleton.joints[i].velocity.y = relative.y * 10;
2314 victim->skeleton.joints[i].position.y += relative.y * .3;
2315 victim->skeleton.joints[i].oldposition.y += relative.y * .3;
2316 victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
2318 victim->Puff(abdomen);
2319 victim->jointVel(abdomen).y = relative.y * 400;
2323 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 5) {
2324 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) {
2328 if (tutoriallevel != 1) {
2329 emit_sound_at(heavyimpactsound, coords, 128.);
2332 relative = victim->coords - coords;
2334 Normalise(&relative);
2335 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2336 victim->skeleton.joints[i].velocity += relative * damagemult * 90;
2338 victim->Puff(abdomen);
2339 if (victim->dead != 2 && victim->permanentdamage > victim->damagetolerance - 250 && autoslomo) {
2343 victim->DoDamage(damagemult * 500 / victim->protectionhigh);
2344 victim->jointVel(abdomen) += relative * damagemult * 300;
2348 if (animTarget == dropkickanim && animation[animTarget].label[frameCurrent] == 7) {
2349 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) {
2353 if (tutoriallevel != 1) {
2354 emit_sound_at(thudsound, coords);
2357 victim->skeleton.longdead = 0;
2358 victim->skeleton.free = 1;
2359 victim->skeleton.broken = 0;
2360 victim->skeleton.spinny = 1;
2362 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2363 victim->skeleton.joints[i].velchange = 0;
2364 //victim->skeleton.joints[i].delay=0;
2365 victim->skeleton.joints[i].locked = 0;
2368 relative = victim->coords - coords;
2369 Normalise(&relative);
2371 Normalise(&relative);
2372 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2373 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2378 victim->Puff(abdomen);
2379 victim->DoDamage(damagemult * 20 / victim->protectionhigh);
2380 victim->jointVel(abdomen) += relative * damagemult * 200;
2389 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 5) {
2390 //if(id==0)camerashake+=.4;
2393 if (!victim->skeleton.free)
2397 terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360);
2398 emit_sound_at(knifesheathesound, coords, 128.);
2401 if (victim && hasvictim) {
2402 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2404 XYZ where, startpoint, endpoint, movepoint, colpoint;
2405 float rotationpoint;
2407 if (weapons[weaponids[weaponactive]].getType() == knife) {
2408 where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4);
2409 where -= victim->coords;
2410 if (!victim->skeleton.free)
2411 where = DoRotation(where, 0, -victim->yaw, 0);
2414 startpoint.y += 100;
2418 if (weapons[weaponids[weaponactive]].getType() == sword) {
2419 where = weapons[weaponids[weaponactive]].position;
2420 where -= victim->coords;
2421 if (!victim->skeleton.free)
2422 where = DoRotation(where, 0, -victim->yaw, 0);
2424 where = weapons[weaponids[weaponactive]].tippoint;
2425 where -= victim->coords;
2426 if (!victim->skeleton.free)
2427 where = DoRotation(where, 0, -victim->yaw, 0);
2430 if (weapons[weaponids[weaponactive]].getType() == staff) {
2431 where = weapons[weaponids[weaponactive]].position;
2432 where -= victim->coords;
2433 if (!victim->skeleton.free)
2434 where = DoRotation(where, 0, -victim->yaw, 0);
2436 where = weapons[weaponids[weaponactive]].tippoint;
2437 where -= victim->coords;
2438 if (!victim->skeleton.free)
2439 where = DoRotation(where, 0, -victim->yaw, 0);
2444 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
2446 if (whichtri != -1) {
2447 if (victim->dead != 2) {
2448 victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2));
2450 award_bonus(id, FinishedBonus);
2453 weapons[weaponids[weaponactive]].bloody = 2;
2455 victim->skeleton.longdead = 0;
2456 victim->skeleton.free = 1;
2457 victim->skeleton.broken = 0;
2459 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2460 victim->skeleton.joints[i].velchange = 0;
2461 victim->skeleton.joints[i].locked = 0;
2462 //victim->skeleton.joints[i].velocity=0;
2464 emit_sound_at(fleshstabsound, coords, 128);
2467 if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) {
2468 weapons[weaponids[weaponactive]].blooddrip += 5;
2469 weapons[weaponids[weaponactive]].blooddripdelay = 0;
2471 if (whichtri == -1) {
2473 emit_sound_at(knifesheathesound, coords, 128.);
2479 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 6) {
2481 emit_sound_at(knifedrawsound, coords, 128);
2484 if (victim && hasvictim) {
2485 XYZ footvel, footpoint;
2487 emit_sound_at(fleshstabremovesound, coords, 128.);
2490 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2492 if (weapons[weaponids[weaponactive]].getType() == sword) {
2493 XYZ where, startpoint, endpoint, movepoint;
2494 float rotationpoint;
2497 where = weapons[weaponids[weaponactive]].position;
2498 where -= victim->coords;
2499 if (!victim->skeleton.free)
2500 where = DoRotation(where, 0, -victim->yaw, 0);
2502 where = weapons[weaponids[weaponactive]].tippoint;
2503 where -= victim->coords;
2504 if (!victim->skeleton.free)
2505 where = DoRotation(where, 0, -victim->yaw, 0);
2510 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2511 footpoint += victim->coords;
2513 if (whichtri == -1) {
2514 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2517 if (weapons[weaponids[weaponactive]].getType() == staff) {
2518 XYZ where, startpoint, endpoint, movepoint;
2519 float rotationpoint;
2522 where = weapons[weaponids[weaponactive]].position;
2523 where -= victim->coords;
2524 if (!victim->skeleton.free)
2525 where = DoRotation(where, 0, -victim->yaw, 0);
2527 where = weapons[weaponids[weaponactive]].tippoint;
2528 where -= victim->coords;
2529 if (!victim->skeleton.free)
2530 where = DoRotation(where, 0, -victim->yaw, 0);
2535 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2536 footpoint += victim->coords;
2538 if (whichtri == -1) {
2539 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2542 hasvictim = victim->DoBloodBigWhere(2, 220, footpoint);
2544 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2545 victim->skeleton.longdead = 0;
2546 victim->skeleton.free = 1;
2547 victim->skeleton.broken = 0;
2549 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2550 victim->skeleton.joints[i].velchange = 0;
2551 victim->skeleton.joints[i].locked = 0;
2552 //victim->skeleton.joints[i].velocity=0;
2558 Normalise(&relative);
2559 //victim->Puff(abdomen);
2561 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2563 if (victim->bloodloss < victim->damagetolerance) {
2564 victim->bloodloss += 1000;
2568 victim->jointVel(abdomen) += relative * damagemult * 20;
2572 if (!hasvictim && onterrain) {
2573 weapons[weaponids[weaponactive]].bloody = 0;
2574 weapons[weaponids[weaponactive]].blooddrip = 0;
2578 if (animTarget == upunchanim && animation[animTarget].label[frameCurrent] == 5) {
2579 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2587 if (tutoriallevel != 1) {
2588 emit_sound_at(heavyimpactsound, victim->coords, 128);
2593 relative = victim->coords - coords;
2595 Normalise(&relative);
2596 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2597 victim->skeleton.joints[i].velocity = relative * 30;
2599 victim->jointVel(head) += relative * damagemult * 150;
2601 victim->frameTarget = 0;
2602 victim->animTarget = staggerbackhardanim;
2603 victim->targetyaw = targetyaw + 180;
2605 victim->stunned = 1;
2608 victim->Puff(abdomen);
2609 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2616 if (animTarget == winduppunchanim && animation[animTarget].label[frameCurrent] == 5) {
2617 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) {
2621 if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height != lowheight) {
2622 if (tutoriallevel != 1) {
2623 emit_sound_at(thudsound, victim->coords);
2625 } else if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height == lowheight) {
2626 if (tutoriallevel != 1) {
2627 emit_sound_at(whooshhitsound, victim->coords);
2630 if (tutoriallevel != 1) {
2631 emit_sound_at(heavyimpactsound, victim->coords);
2635 if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || animation[victim->animTarget].height == lowheight)
2638 relative = victim->coords - coords;
2640 Normalise(&relative);
2642 Normalise(&relative);
2643 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2644 victim->skeleton.joints[i].velocity = relative * 5;
2646 victim->jointVel(abdomen) += relative * damagemult * 400;
2648 victim->frameTarget = 0;
2649 victim->animTarget = staggerbackhardanim;
2650 victim->targetyaw = targetyaw + 180;
2652 victim->stunned = 1;
2654 victim->Puff(abdomen);
2655 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2661 if (animTarget == blockhighleftanim && animation[animTarget].label[frameCurrent] == 5) {
2662 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2663 if (victim->id == 0)
2665 emit_sound_at(landsound2, victim->coords);
2671 if (animTarget == swordslashparryanim && animation[animTarget].label[frameCurrent] == 5) {
2672 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2673 if (victim->id == 0)
2676 if (weaponactive != -1) {
2677 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2678 if (weapons[victim->weaponids[0]].getType() == staff)
2679 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2680 if (weapons[weaponids[0]].getType() == staff)
2681 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2683 emit_sound_at(swordstaffsound, victim->coords);
2685 emit_sound_at(metalhitsound, victim->coords);
2693 if (animTarget == knifethrowanim && animation[animTarget].label[frameCurrent] == 5) {
2694 if (weaponactive != -1) {
2697 weapons[weaponids[0]].owner = -1;
2698 aim = victim->coords + DoRotation(victim->jointPos(abdomen), 0, victim->yaw, 0) * victim->scale + victim->velocity * findDistance(&victim->coords, &coords) / 50 - (coords + DoRotation(jointPos(righthand), 0, yaw, 0) * scale);
2700 /*if(victim->animTarget==jumpupanim||victim->animTarget==jumpdownanim){
2701 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2703 weapons[weaponids[0]].velocity = aim * 50;
2704 weapons[weaponids[0]].tipvelocity = aim * 50;
2705 weapons[weaponids[0]].missed = 0;
2706 weapons[weaponids[0]].hitsomething = 0;
2707 weapons[weaponids[0]].freetime = 0;
2708 weapons[weaponids[0]].firstfree = 1;
2709 weapons[weaponids[0]].physics = 0;
2712 weaponids[0] = weaponids[num_weapons];
2718 if (animTarget == knifeslashstartanim && animation[animTarget].label[frameCurrent] == 5) {
2720 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 &&/*animation[victim->animTarget].height!=lowheight&&*/victim->animTarget != dodgebackanim && victim->animTarget != rollanim) {
2722 if (tutoriallevel != 1)
2723 victim->DoBloodBig(1.5 / victim->armorhigh, 225);
2725 award_bonus(id, Slicebonus);
2726 if (tutoriallevel != 1) {
2727 emit_sound_at(knifeslicesound, victim->coords);
2729 //victim->jointVel(abdomen)+=relative*damagemult*200;
2730 if (animation[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
2731 if (victim->id != 0 || difficulty == 2) {
2732 victim->frameTarget = 0;
2733 victim->animTarget = staggerbackhardanim;
2734 victim->targetyaw = targetyaw + 180;
2738 victim->lowreversaldelay = 0;
2739 victim->highreversaldelay = 0;
2740 if (aitype != playercontrolled)
2741 weaponmissdelay = .6;
2743 if (tutoriallevel != 1)
2744 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2745 weapons[weaponids[weaponactive]].bloody = 1;
2746 if (tutoriallevel != 1)
2747 weapons[weaponids[weaponactive]].blooddrip += 3;
2749 XYZ footvel, footpoint;
2751 if (skeleton.free) {
2752 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2754 if (!skeleton.free) {
2755 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2757 if (tutoriallevel != 1) {
2759 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .6, .3);
2760 footvel = DoRotation(facing, 0, 90, 0) * .8;
2762 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2763 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2764 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
2765 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
2767 if (tutoriallevel == 1) {
2768 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .6, .3);
2770 victim->DoDamage(damagemult * 0);
2773 if (animTarget == swordslashanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2774 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) {
2775 if (victim->weaponactive == -1 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) {
2776 award_bonus(id, Slashbonus);
2778 if (tutoriallevel != 1) {
2779 if (normaldotproduct(victim->facing, victim->coords - coords) < 0)
2780 victim->DoBloodBig(2 / victim->armorhigh, 190);
2782 victim->DoBloodBig(2 / victim->armorhigh, 185);
2783 victim->deathbleeding = 1;
2784 emit_sound_at(swordslicesound, victim->coords);
2786 //victim->jointVel(abdomen)+=relative*damagemult*200;
2787 if (tutoriallevel != 1) {
2788 victim->frameTarget = 0;
2789 victim->animTarget = staggerbackhardanim;
2790 victim->targetyaw = targetyaw + 180;
2794 if (tutoriallevel != 1) {
2795 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2796 weapons[weaponids[weaponactive]].bloody = 1;
2797 weapons[weaponids[weaponactive]].blooddrip += 3;
2799 float bloodlossamount;
2800 bloodlossamount = 200 + abs((float)(Random() % 40)) - 20;
2801 victim->bloodloss += bloodlossamount / victim->armorhigh;
2802 //victim->bloodloss+=100*(6.5-distsq(&coords,&victim->coords));
2803 victim->DoDamage(damagemult * 0);
2805 XYZ footvel, footpoint;
2807 if (skeleton.free) {
2808 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2810 if (!skeleton.free) {
2811 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2814 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
2815 footvel = DoRotation(facing, 0, 90, 0) * .8;
2817 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2818 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2819 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
2820 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
2823 if (victim->weaponactive != -1) {
2824 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2825 if (weapons[victim->weaponids[0]].getType() == staff)
2826 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2827 if (weapons[weaponids[0]].getType() == staff)
2828 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2830 emit_sound_at(swordstaffsound, victim->coords);
2832 emit_sound_at(metalhitsound, victim->coords);
2838 victim->Puff(righthand);
2840 victim->frameTarget = 0;
2841 victim->animTarget = staggerbackhighanim;
2842 victim->targetyaw = targetyaw + 180;
2844 weapons[victim->weaponids[0]].owner = -1;
2845 aim = DoRotation(facing, 0, 90, 0) * 21;
2847 weapons[victim->weaponids[0]].velocity = aim * -.2;
2848 weapons[victim->weaponids[0]].tipvelocity = aim;
2849 weapons[victim->weaponids[0]].missed = 1;
2850 weapons[weaponids[0]].hitsomething = 0;
2851 weapons[victim->weaponids[0]].freetime = 0;
2852 weapons[victim->weaponids[0]].firstfree = 1;
2853 weapons[victim->weaponids[0]].physics = 1;
2854 victim->num_weapons--;
2855 if (victim->num_weapons) {
2856 victim->weaponids[0] = victim->weaponids[num_weapons];
2857 if (victim->weaponstuck == victim->num_weapons)
2858 victim->weaponstuck = 0;
2860 victim->weaponactive = -1;
2861 for (unsigned i = 0; i < Person::players.size(); i++) {
2862 Person::players[i]->wentforweapon = 0;
2869 if (animTarget == staffhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2870 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2871 if (tutoriallevel != 1) {
2872 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 250;
2876 if (Random() % 2 || creature == wolftype) {
2879 emit_sound_at(staffheadsound, victim->coords);
2883 relative = victim->coords - coords;
2885 Normalise(&relative);
2886 relative = DoRotation(relative, 0, 90, 0);
2888 Normalise(&relative);
2889 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2890 victim->skeleton.joints[i].velocity += relative * damagemult * 60;
2892 victim->jointVel(head) += relative * damagemult * 230;
2893 victim->jointVel(neck) += relative * damagemult * 230;
2896 if (tutoriallevel != 1) {
2897 victim->DoDamage(damagemult * 120 / victim->protectionhigh);
2899 award_bonus(id, solidhit, 30);
2904 if (animTarget == staffspinhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2905 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2906 if (tutoriallevel != 1) {
2907 weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250;
2911 if (Random() % 2 || creature == wolftype) {
2914 emit_sound_at(staffheadsound, victim->coords);
2918 relative = victim->coords - coords;
2920 Normalise(&relative);
2921 relative = DoRotation(relative, 0, -90, 0);
2922 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2923 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2925 victim->jointVel(head) += relative * damagemult * 220;
2926 victim->jointVel(neck) += relative * damagemult * 220;
2929 if (tutoriallevel != 1) {
2930 victim->DoDamage(damagemult * 350 / victim->protectionhead);
2932 award_bonus(id, solidhit, 60);
2937 if (animTarget == staffgroundsmashanim && animation[animTarget].label[frameCurrent] == 5) {
2938 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) {
2940 if (tutoriallevel != 1) {
2942 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500;
2945 if (Random() % 2 || creature == wolftype) {
2948 emit_sound_at(staffbodysound, victim->coords);
2950 victim->skeleton.longdead = 0;
2951 victim->skeleton.free = 1;
2952 victim->skeleton.broken = 0;
2954 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2955 victim->skeleton.joints[i].velchange = 0;
2956 victim->skeleton.joints[i].locked = 0;
2957 //victim->skeleton.joints[i].velocity=0;
2963 /*relative=victim->coords-coords;
2965 Normalise(&relative);
2966 relative=DoRotation(relative,0,90,0);*/
2968 Normalise(&relative);
2969 if (!victim->dead) {
2970 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2971 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
2974 victim->jointVel(abdomen) += relative * damagemult * 40;
2977 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2978 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
2981 //victim->jointVel(abdomen)+=relative*damagemult*20;
2983 victim->Puff(abdomen);
2984 if (tutoriallevel != 1) {
2985 victim->DoDamage(damagemult * 100 / victim->protectionhigh);
2987 if (!victim->dead) {
2988 award_bonus(id, solidhit, 40);
2994 if (animTarget == lowkickanim && animation[animTarget].label[frameCurrent] == 5) {
2995 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != highheight) {
3000 relative = victim->coords - coords;
3002 Normalise(&relative);
3006 if (animation[victim->animTarget].height == lowheight) {
3012 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3013 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3015 victim->jointVel(head) += relative * damagemult * 200;
3016 if (tutoriallevel != 1) {
3017 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3020 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3021 if (victim->howactive == typesleeping)
3022 victim->DoDamage(damagemult * 150 / victim->protectionhead);
3023 if (creature == wolftype) {
3024 emit_sound_at(clawslicesound, victim->coords, 128.);
3026 victim->DoBloodBig(2 / victim->armorhead, 175);
3029 if (victim->damage >= victim->damagetolerance)
3031 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3032 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3034 victim->jointVel(abdomen) += relative * damagemult * 200;
3035 victim->frameTarget = 0;
3036 victim->animTarget = staggerbackhighanim;
3037 victim->targetyaw = targetyaw + 180;
3039 if (tutoriallevel != 1) {
3040 emit_sound_at(landsound2, victim->coords, 128.);
3042 victim->Puff(abdomen);
3043 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3044 if (creature == wolftype) {
3045 emit_sound_at(clawslicesound, victim->coords, 128.);
3047 victim->DoBloodBig(2 / victim->armorhigh, 170);
3054 if (animTarget == sweepanim && animation[animTarget].label[frameCurrent] == 5) {
3055 if ((victim->animTarget != jumpupanim) &&
3056 (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) &&
3057 (victim != this->shared_from_this())) {
3061 if (tutoriallevel != 1) {
3062 emit_sound_at(landsound2, victim->coords, 128.);
3065 relative = victim->coords - coords;
3067 Normalise(&relative);
3069 if (animation[victim->animTarget].height == middleheight || animation[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
3072 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3073 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
3075 relative = DoRotation(relative, 0, -90, 0);
3077 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3078 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)
3079 victim->skeleton.joints[i].velocity = relative * 80;
3081 victim->Puff(rightankle);
3082 victim->Puff(leftankle);
3083 victim->DoDamage(damagemult * 40 / victim->protectionlow);
3085 if (victim->damage >= victim->damagetolerance)
3087 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3088 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3090 relative = DoRotation(relative, 0, -90, 0);
3091 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3092 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)
3093 victim->skeleton.joints[i].velocity += relative * damagemult * 80;
3095 victim->jointVel(abdomen) += relative * damagemult * 200;
3096 victim->frameTarget = 0;
3097 victim->animTarget = staggerbackhighanim;
3098 victim->targetyaw = targetyaw + 180;
3100 if (tutoriallevel != 1) {
3101 emit_sound_at(landsound2, victim->coords, 128.);
3103 victim->Puff(abdomen);
3104 victim->DoDamage(damagemult * 30 / victim->protectionlow);
3112 if (animation[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) {
3113 if (animTarget == spinkickreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3121 if (tutoriallevel != 1) {
3122 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3124 if (creature == wolftype) {
3125 emit_sound_at(clawslicesound, victim->coords, 128);
3127 victim->DoBloodBig(2 / victim->armorhigh, 170);
3131 relative = victim->coords - oldcoords;
3133 Normalise(&relative);
3134 //relative=DoRotation(relative,0,-90,0);
3135 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3136 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3138 victim->jointVel(abdomen) += relative * damagemult * 200;
3140 victim->Puff(abdomen);
3141 victim->DoDamage(damagemult * 150 / victim->protectionhigh);
3143 award_bonus(id, Reversal);
3146 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && animation[animTarget].label[frameCurrent] == 5) {
3147 if (victim->weaponactive != -1 && victim->num_weapons > 0) {
3148 if (weapons[victim->weaponids[victim->weaponactive]].owner == int(victim->id)) {
3149 weapons[victim->weaponids[victim->weaponactive]].owner = id;
3151 if (num_weapons > 0) {
3152 weaponids[num_weapons] = weaponids[victim->weaponactive];
3155 weaponids[0] = victim->weaponids[victim->weaponactive];
3156 victim->num_weapons--;
3157 if (victim->num_weapons > 0) {
3158 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
3159 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
3161 victim->weaponactive = -1;
3166 if (animTarget == staffhitreversalanim && animation[animTarget].label[frameCurrent] == 5) {
3174 emit_sound_at(whooshhitsound, victim->coords, 128.);
3177 relative = victim->coords - oldcoords;
3179 Normalise(&relative);
3180 //relative=DoRotation(relative,0,-90,0);
3181 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3182 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3184 victim->jointVel(abdomen) += relative * damagemult * 200;
3187 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3190 if (animTarget == staffspinhitreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3199 award_bonus(id, staffreversebonus);
3201 if (tutoriallevel != 1) {
3202 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3205 award_bonus(id, staffreversebonus); // Huh, again?
3208 relative = victim->coords - oldcoords;
3210 Normalise(&relative);
3211 //relative=DoRotation(relative,0,-90,0);
3212 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3213 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3215 victim->jointVel(abdomen) += relative * damagemult * 200;
3218 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3221 if (animTarget == upunchreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3227 Normalise(&relative);
3230 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3231 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3233 victim->jointVel(lefthand) *= .1;
3234 victim->jointVel(leftwrist) *= .2;
3235 victim->jointVel(leftelbow) *= .5;
3236 victim->jointVel(leftshoulder) *= .7;
3237 victim->jointVel(righthand) *= .1;
3238 victim->jointVel(rightwrist) *= .2;
3239 victim->jointVel(rightelbow) *= .5;
3240 victim->jointVel(rightshoulder) *= .7;
3242 victim->Puff(abdomen);
3243 victim->DoDamage(damagemult * 90 / victim->protectionhigh);
3245 award_bonus(id, Reversal);
3249 if (weaponactive != -1 || creature == wolftype)
3251 if (creature == rabbittype && weaponactive != -1)
3252 if (weapons[weaponids[0]].getType() == staff)
3255 if (weaponactive != -1) {
3256 victim->DoBloodBig(2 / victim->armorhigh, 225);
3257 emit_sound_at(knifeslicesound, victim->coords);
3258 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3259 weapons[weaponids[weaponactive]].bloody = 1;
3260 weapons[weaponids[weaponactive]].blooddrip += 3;
3262 if (weaponactive == -1 && creature == wolftype) {
3264 emit_sound_at(clawslicesound, victim->coords, 128.);
3266 victim->DoBloodBig(2 / victim->armorhigh, 175);
3273 if (animTarget == swordslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3279 Normalise(&relative);
3282 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3283 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3285 victim->jointVel(lefthand) *= .1 - 1;
3286 victim->jointVel(leftwrist) *= .2 - 1;
3287 victim->jointVel(leftelbow) *= .5 - 1;
3288 victim->jointVel(leftshoulder) *= .7 - 1;
3289 victim->jointVel(righthand) *= .1 - 1;
3290 victim->jointVel(rightwrist) *= .2 - 1;
3291 victim->jointVel(rightelbow) *= .5 - 1;
3292 victim->jointVel(rightshoulder) *= .7 - 1;
3294 award_bonus(id, swordreversebonus);
3297 if (hasvictim && animTarget == knifeslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3305 if (tutoriallevel != 1) {
3306 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3310 relative = victim->coords - oldcoords;
3312 Normalise(&relative);
3313 relative = DoRotation(relative, 0, -90, 0);
3314 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3315 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3317 victim->jointVel(abdomen) += relative * damagemult * 200;
3319 victim->Puff(abdomen);
3320 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3322 award_bonus(id, Reversal);
3325 if (hasvictim && animTarget == sneakattackanim && animation[animTarget].label[frameCurrent] == 7) {
3328 victim->skeleton.spinny = 0;
3330 relative = facing * -1;
3332 Normalise(&relative);
3333 if (victim->id == 0)
3335 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3336 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3338 //victim->DoDamage(1000);
3339 victim->damage = victim->damagetolerance;
3340 victim->permanentdamage = victim->damagetolerance - 1;
3343 if (weaponactive != -1 || creature == wolftype)
3345 if (creature == rabbittype && weaponactive != -1)
3346 if (weapons[weaponids[0]].getType() == staff)
3349 if (weaponactive != -1) {
3350 victim->DoBloodBig(200, 225);
3351 emit_sound_at(knifeslicesound, victim->coords);
3353 weapons[weaponids[weaponactive]].bloody = 2;
3354 weapons[weaponids[weaponactive]].blooddrip += 5;
3357 if (creature == wolftype && weaponactive == -1) {
3358 emit_sound_at(clawslicesound, victim->coords, 128.);
3360 victim->DoBloodBig(2, 175);
3363 award_bonus(id, spinecrusher);
3366 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3367 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3369 if (animTarget == knifefollowanim)
3370 victim->DoBloodBig(200, 210);
3371 if (animTarget == knifesneakattackanim) {
3372 /*victim->DoBloodBig(200,195);
3377 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
3378 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck),0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3380 XYZ footvel, footpoint;
3382 footpoint = weapons[weaponids[0]].tippoint;
3384 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3385 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3386 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3387 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3388 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3389 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3390 victim->DoBloodBig(200, 195);
3391 award_bonus(id, tracheotomy);
3393 if (animTarget == knifefollowanim) {
3394 award_bonus(id, Stabbonus);
3395 XYZ footvel, footpoint;
3397 footpoint = weapons[weaponids[0]].tippoint;
3399 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3400 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3401 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3402 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3403 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3404 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3407 victim->bloodloss += 10000;
3408 victim->velocity = 0;
3409 emit_sound_at(fleshstabsound, victim->coords);
3411 weapons[weaponids[weaponactive]].bloody = 2;
3412 weapons[weaponids[weaponactive]].blooddrip += 5;
3416 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 6) {
3418 victim->velocity = 0;
3419 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3420 victim->skeleton.joints[i].velocity = 0;
3422 if (animTarget == knifefollowanim) {
3424 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3425 victim->skeleton.joints[i].velocity = 0;
3428 if (weaponactive != -1 && animation[victim->animTarget].attack != reversal) {
3429 emit_sound_at(fleshstabremovesound, victim->coords);
3431 weapons[weaponids[weaponactive]].bloody = 2;
3432 weapons[weaponids[weaponactive]].blooddrip += 5;
3434 XYZ footvel, footpoint;
3436 footpoint = weapons[weaponids[0]].tippoint;
3438 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3439 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3440 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3441 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3442 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3443 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3447 if (hasvictim && (animTarget == swordsneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3448 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3449 award_bonus(id, backstab);
3453 XYZ footvel, footpoint;
3455 footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2;
3457 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3458 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3459 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3460 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3461 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 5, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3462 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3463 victim->DoBloodBig(200, 180);
3464 victim->DoBloodBig(200, 215);
3465 victim->bloodloss += 10000;
3466 victim->velocity = 0;
3467 emit_sound_at(fleshstabsound, victim->coords);
3469 weapons[weaponids[weaponactive]].bloody = 2;
3470 weapons[weaponids[weaponactive]].blooddrip += 5;
3474 if (hasvictim && animTarget == swordsneakattackanim && animation[animTarget].label[frameCurrent] == 6) {
3476 victim->velocity = 0;
3477 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3478 victim->skeleton.joints[i].velocity = 0;
3480 if (weaponactive != -1) {
3481 emit_sound_at(fleshstabremovesound, victim->coords);
3483 weapons[weaponids[weaponactive]].bloody = 2;
3484 weapons[weaponids[weaponactive]].blooddrip += 5;
3486 XYZ footvel, footpoint;
3488 footpoint = weapons[weaponids[0]].tippoint;
3490 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3491 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3492 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3493 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3494 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3495 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3499 if (animTarget == sweepreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3507 if (weaponactive == -1) {
3508 if (tutoriallevel != 1) {
3509 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3514 if (weaponactive != -1 || creature == wolftype)
3516 if (creature == rabbittype && weaponactive != -1)
3517 if (weapons[weaponids[0]].getType() == staff)
3520 if (weaponactive != -1) {
3521 victim->DoBloodBig(2 / victim->armorhead, 225);
3522 emit_sound_at(knifeslicesound, victim->coords);
3523 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3524 weapons[weaponids[weaponactive]].bloody = 1;
3525 weapons[weaponids[weaponactive]].blooddrip += 3;
3527 if (weaponactive == -1 && creature == wolftype) {
3528 emit_sound_at(clawslicesound, victim->coords, 128.);
3530 victim->DoBloodBig(2 / victim->armorhead, 175);
3534 award_bonus(id, Reversal);
3539 //relative=victim->coords-oldcoords;
3540 relative = facing * -1;
3542 Normalise(&relative);
3543 relative = DoRotation(relative, 0, 90, 0);
3545 Normalise(&relative);
3546 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3547 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3549 victim->jointVel(head) += relative * damagemult * 200;
3550 if (victim->damage < victim->damagetolerance - 100)
3551 victim->velocity = relative * 200;
3552 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3553 victim->velocity = 0;
3556 if (animTarget == sweepreversalanim && ((animation[animTarget].label[frameCurrent] == 9 && victim->damage < victim->damagetolerance) || (animation[animTarget].label[frameCurrent] == 7 && victim->damage > victim->damagetolerance))) {
3560 //relative=victim->coords-oldcoords;
3561 relative = facing * -1;
3563 Normalise(&relative);
3564 relative = DoRotation(relative, 0, 90, 0);
3566 Normalise(&relative);
3567 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3568 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3570 victim->jointVel(head) += relative * damagemult * 200;
3573 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim))
3574 if (victim->damage > victim->damagetolerance && bonus != reverseko) {
3575 award_bonus(id, reverseko);
3581 if (frameTarget > animation[animCurrent].numframes - 1) {
3584 animTarget = getIdle();
3588 if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) {
3589 animTarget = rollanim;
3591 emit_sound_at(movewhooshsound, coords, 128.);
3593 if (animCurrent == staggerbackhighanim) {
3594 animTarget = getIdle();
3596 if (animCurrent == staggerbackhardanim) {
3597 animTarget = getIdle();
3599 if (animCurrent == removeknifeanim) {
3600 animTarget = getIdle();
3602 if (animCurrent == crouchremoveknifeanim) {
3603 animTarget = getCrouch();
3605 if (animCurrent == backhandspringanim) {
3606 animTarget = getIdle();
3608 if (animCurrent == dodgebackanim) {
3609 animTarget = getIdle();
3611 if (animCurrent == drawleftanim) {
3612 animTarget = getIdle();
3614 if (animCurrent == drawrightanim || animCurrent == crouchdrawrightanim) {
3615 animTarget = getIdle();
3616 if (animCurrent == crouchdrawrightanim) {
3617 animTarget = getCrouch();
3619 if (weaponactive == -1)
3621 else if (weaponactive == 0) {
3623 if (num_weapons == 2) {
3625 buffer = weaponids[0];
3626 weaponids[0] = weaponids[1];
3627 weaponids[1] = buffer;
3631 if (weaponactive == -1) {
3632 emit_sound_at(knifesheathesound, coords, 128.);
3634 if (weaponactive != -1) {
3635 emit_sound_at(knifedrawsound, coords, 128.);
3638 if (animCurrent == rollanim) {
3639 animTarget = getCrouch();
3644 if (animTarget == walljumprightkickanim) {
3647 if (animTarget == walljumpleftkickanim) {
3650 animTarget = jumpdownanim;
3652 if (animCurrent == climbanim) {
3653 animTarget = getCrouch();
3655 coords += facing * .1;
3656 if (!isnormal(coords.x))
3667 if (animTarget == rabbitkickreversalanim) {
3668 animTarget = getCrouch();
3671 if (animTarget == jumpreversalanim) {
3672 animTarget = getCrouch();
3675 if (animTarget == walljumprightanim || animTarget == walljumpbackanim || animTarget == walljumpfrontanim) {
3676 if (attackkeydown && animTarget != walljumpfrontanim) {
3678 float closestdist = -1;
3680 if (Person::players.size() > 1)
3681 for (unsigned i = 0; i < Person::players.size(); i++) {
3682 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3683 distance = distsq(&Person::players[i]->coords, &coords);
3684 if (closestdist == -1 || distance < closestdist) {
3685 closestdist = distance;
3690 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3691 victim = Person::players[closest];
3692 animTarget = walljumprightkickanim;
3694 XYZ rotatetarget = victim->coords - coords;
3695 Normalise(&rotatetarget);
3696 yaw = -asin(0 - rotatetarget.x);
3698 if (rotatetarget.z < 0)
3700 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3701 velocity = (victim->coords - coords) * 4;
3706 if (animTarget == walljumpbackanim) {
3707 animTarget = backflipanim;
3709 velocity = facing * -8;
3712 resume_stream(whooshsound);
3714 if (animTarget == walljumprightanim) {
3715 animTarget = rightflipanim;
3719 velocity = DoRotation(facing, 0, 30, 0) * -8;
3722 if (animTarget == walljumpfrontanim) {
3723 animTarget = frontflipanim;
3727 velocity = facing * 8;
3731 resume_stream(whooshsound);
3733 if (animTarget == walljumpleftanim) {
3734 if (attackkeydown) {
3736 float closestdist = -1;
3738 if (Person::players.size() > 1)
3739 for (unsigned i = 0; i < Person::players.size(); i++) {
3740 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3741 distance = distsq(&Person::players[i]->coords, &coords);
3742 if (closestdist == -1 || distance < closestdist) {
3743 closestdist = distance;
3748 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3749 victim = Person::players[closest];
3750 animTarget = walljumpleftkickanim;
3752 XYZ rotatetarget = victim->coords - coords;
3753 Normalise(&rotatetarget);
3754 yaw = -asin(0 - rotatetarget.x);
3756 if (rotatetarget.z < 0)
3758 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3759 velocity = (victim->coords - coords) * 4;
3764 if (animTarget != walljumpleftkickanim) {
3765 animTarget = leftflipanim;
3769 velocity = DoRotation(facing, 0, -30, 0) * -8;
3773 resume_stream(whooshsound);
3775 if (animTarget == sneakattackanim) {
3776 animCurrent = getCrouch();
3777 animTarget = getCrouch();
3784 transspeed = 1000000;
3785 targetheadyaw += 180;
3786 coords -= facing * .7;
3788 coords.y = terrain.getHeight(coords.x, coords.z);
3792 if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) {
3793 animTarget = getIdle();
3796 coords.y = terrain.getHeight(coords.x, coords.z);
3800 if (animCurrent == knifefollowanim) {
3801 animTarget = getIdle();
3804 if (animation[animTarget].attack == reversal && animCurrent != sneakattackanim && animCurrent != knifesneakattackanim && animCurrent != swordsneakattackanim && animCurrent != knifefollowanim) {
3805 float ycoords = oldcoords.y;
3806 animTarget = getStop();
3811 transspeed = 1000000;
3812 targetheadyaw += 180;
3813 if (!isnormal(coords.x))
3815 if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim)
3816 oldcoords = coords + facing * .5;
3817 else if (animCurrent == sweepreversalanim)
3818 oldcoords = coords + facing * 1.1;
3819 else if (animCurrent == upunchreversalanim) {
3820 oldcoords = coords + facing * 1.5;
3823 targetheadyaw += 180;
3826 } else if (animCurrent == knifeslashreversalanim) {
3827 oldcoords = coords + facing * .5;
3830 targetheadyaw += 90;
3833 } else if (animCurrent == staffspinhitreversalanim) {
3836 targetheadyaw += 180;
3841 oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z);
3843 oldcoords.y = ycoords;
3844 currentoffset = coords - oldcoords;
3850 if (animCurrent == knifesneakattackedanim || animCurrent == swordsneakattackedanim) {
3855 if (animation[animTarget].attack == reversed) {
3857 if (animTarget == sweepreversedanim)
3859 animTarget = backhandspringanim;
3861 emit_sound_at(landsound, coords, 128);
3863 if (animCurrent == upunchreversedanim || animCurrent == swordslashreversedanim) {
3864 animTarget = rollanim;
3867 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3868 coords.y = oldcoords.y;
3870 if (animCurrent == knifeslashreversedanim) {
3871 animTarget = rollanim;
3876 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3877 coords.y = oldcoords.y;
3881 animTarget = jumpdownanim;
3884 animTarget = getIdle();
3886 animTarget = getIdle();
3887 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
3888 animTarget = getIdle();
3890 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3891 coords.y = oldcoords.y;
3892 //coords+=DoRotation(animation[animCurrent].offset,0,yaw,0)*scale;
3893 targetoffset.y = coords.y;
3895 targetoffset.y = terrain.getHeight(coords.x, coords.z);
3896 currentoffset = DoRotation(animation[animCurrent].offset * -1, 0, yaw, 0) * scale;
3897 currentoffset.y -= (coords.y - targetoffset.y);
3898 coords.y = targetoffset.y;
3900 normalsupdatedelay = 0;
3902 if (animCurrent == upunchanim) {
3903 animTarget = getStop();
3904 normalsupdatedelay = 0;
3907 if (animCurrent == rabbitkickanim && animTarget != backflipanim) {
3911 if (num_weapons > 0)
3912 if (weapons[0].getType() == staff)
3918 rabbitkickragdoll = 1;
3920 if (animCurrent == rabbitkickreversedanim) {
3926 skeleton.spinny = 0;
3927 SolidHitBonus(!id); // FIXME: tricky id
3931 animTarget = rollanim;
3934 pause_sound(whooshsound);
3938 if (animCurrent == rabbittackledbackanim || animCurrent == rabbittackledfrontanim) {
3942 skeleton.spinny = 0;
3944 if (animCurrent == jumpreversedanim) {
3950 skeleton.spinny = 0;
3951 SolidHitBonus(!id); // FIXME: tricky id
3955 animTarget = rollanim;
3956 coords += facing * 2;
3958 pause_sound(whooshsound);
3963 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) {
3964 animTarget = getupfromfrontanim;
3966 } else if (animation[animCurrent].attack == normalattack) {
3967 animTarget = getIdle();
3970 if (animCurrent == blockhighleftanim && aitype != playercontrolled) {
3971 animTarget = blockhighleftstrikeanim;
3973 if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) {
3974 animTarget = getIdle();
3977 if (animCurrent == spinkickanim && victim->skeleton.free) {
3978 if (creature == rabbittype)
3979 animTarget = fightidleanim;
3984 if (isIdle() && !wasIdle())
3985 normalsupdatedelay = 0;
3987 if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) {
3988 animTarget = jumpdownanim;
3991 if (!skeleton.free) {
3993 if (!transspeed && animation[animTarget].attack != 2 && animation[animTarget].attack != 3) {
3994 if (!isRun() || !wasRun()) {
3995 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
3996 target += multiplier * animation[animTarget].speed[frameTarget] * speed * 2;
3997 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
3998 target += multiplier * animation[animCurrent].speed[frameCurrent] * speed * 2;
4000 if (isRun() && wasRun()) {
4002 tempspeed = velspeed;
4003 if (tempspeed < 10 * speedmult)
4004 tempspeed = 10 * speedmult;
4005 target += multiplier * animation[animTarget].speed[frameCurrent] * speed * 1.7 * tempspeed / (speed * 45 * scale);
4007 } else if (transspeed)
4008 target += multiplier * transspeed * speed * 2;
4010 if (!isRun() || !wasRun()) {
4011 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
4012 target += multiplier * animation[animTarget].speed[frameTarget] * 2;
4013 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
4014 target += multiplier * animation[animCurrent].speed[frameCurrent] * 2;
4018 if (animCurrent != animTarget)
4019 target = (target + oldtarget) / 2;
4022 frameCurrent = frameTarget;
4026 rot = targetrot * target;
4027 yaw += rot - oldrot;
4033 if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
4035 for (int i = 0; i < skeleton.num_joints; i++) {
4036 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent];
4039 skeleton.FindForwards();
4041 for (int i = 0; i < skeleton.num_muscles; i++) {
4042 if (skeleton.muscles[i].visible) {
4043 skeleton.FindRotationMuscle(i, animTarget);
4046 for (int i = 0; i < skeleton.num_muscles; i++) {
4047 if (skeleton.muscles[i].visible) {
4048 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
4049 skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4050 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
4051 skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4052 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
4053 skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4058 for (int i = 0; i < skeleton.num_joints; i++) {
4059 skeleton.joints[i].position = animation[animTarget].position[i][frameTarget];
4062 skeleton.FindForwards();
4064 for (int i = 0; i < skeleton.num_muscles; i++) {
4065 if (skeleton.muscles[i].visible) {
4066 skeleton.FindRotationMuscle(i, animTarget);
4069 for (int i = 0; i < skeleton.num_muscles; i++) {
4070 if (skeleton.muscles[i].visible) {
4071 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
4072 skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4073 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
4074 skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4075 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
4076 skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4077 if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) skeleton.muscles[i].newrotate3 -= 360;
4078 if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) skeleton.muscles[i].newrotate3 += 360;
4079 if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) skeleton.muscles[i].newrotate2 -= 360;
4080 if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) skeleton.muscles[i].newrotate2 += 360;
4081 if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) skeleton.muscles[i].newrotate1 -= 360;
4082 if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) skeleton.muscles[i].newrotate1 += 360;
4086 if (frameCurrent >= animation[animCurrent].numframes)
4087 frameCurrent = animation[animCurrent].numframes - 1;
4089 oldanimCurrent = animCurrent;
4090 oldanimTarget = animTarget;
4091 oldframeTarget = frameTarget;
4092 oldframeCurrent = frameCurrent;
4094 for (int i = 0; i < skeleton.num_joints; i++) {
4095 skeleton.joints[i].velocity = (animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target) - skeleton.joints[i].position) / multiplier;
4096 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target);
4098 offset = currentoffset * (1 - target) + targetoffset * target;
4099 for (int i = 0; i < skeleton.num_muscles; i++) {
4100 if (skeleton.muscles[i].visible) {
4101 skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * (target);
4102 skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * (target);
4103 skeleton.muscles[i].rotate3 = skeleton.muscles[i].oldrotate3 * (1 - target) + skeleton.muscles[i].newrotate3 * (target);
4108 if (isLanding() && landhard) {
4111 animTarget = getLandhard();
4118 //skeleton.DoConstraints();
4125 void Person::DoStuff()
4127 static XYZ terrainnormal;
4128 static XYZ flatfacing;
4129 static XYZ flatvelocity;
4130 static float flatvelspeed;
4134 static int bloodsize;
4135 static int startx, starty, endx, endy;
4136 static GLubyte color;
4137 static XYZ bloodvel;
4139 onfiredelay -= multiplier;
4140 if (onfiredelay < 0 && onfire) {
4141 if (Random() % 2 == 0) {
4147 crouchkeydowntime += multiplier;
4149 crouchkeydowntime = 0;
4150 jumpkeydowntime += multiplier;
4151 if (!jumpkeydown && skeleton.free)
4152 jumpkeydowntime = 0;
4154 if (hostile || damage > 0 || bloodloss > 0)
4157 if (isIdle() || isRun())
4160 if (num_weapons == 1 && weaponactive != -1)
4164 blooddimamount -= multiplier * .3;
4165 speechdelay -= multiplier;
4166 texupdatedelay -= multiplier;
4167 interestdelay -= multiplier;
4168 flamedelay -= multiplier;
4169 parriedrecently -= multiplier;
4171 victim = this->shared_from_this();
4176 speed = 1.1 * speedmult;
4178 speed = 1.0 * speedmult;
4180 rabbitkickragdoll = 0;
4184 if (id != 0 && (creature == rabbittype || difficulty != 2))
4186 if (id != 0 && creature == wolftype && difficulty == 2) {
4188 if (aitype != passivetype) {
4190 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) {
4196 if (animTarget == wolfrunninganim && !superruntoggle) {
4197 animTarget = getRun();
4201 if (weaponactive == -1 && num_weapons > 0) {
4202 if (weapons[weaponids[0]].getType() == staff) {
4208 burnt += multiplier;
4209 /*if(aitype!=playercontrolled)*///deathbleeding=5;
4210 /*if(aitype!=playercontrolled)*/
4214 OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3);
4216 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
4222 vel[0] = velocity.x;
4223 vel[1] = velocity.y;
4224 vel[2] = velocity.z;
4227 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4228 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
4232 while (flamedelay < 0 && onfire) {
4234 howmany = abs(Random() % (skeleton.num_joints));
4236 flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4238 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4240 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4242 flatfacing = skeleton.joints[howmany].position * scale + coords;
4243 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
4246 while (flamedelay < 0 && !onfire && tutoriallevel == 1 && id != 0) {
4248 howmany = abs(Random() % (skeleton.num_joints));
4250 flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4252 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4254 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4256 flatfacing = skeleton.joints[howmany].position * scale + coords;
4257 Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
4261 bleeding -= multiplier * .3;
4262 if (bloodtoggle == 2) {
4263 skeleton.drawmodel.textureptr.bind();
4264 if (bleeding <= 0 && (detail != 2 || osx))
4269 if (neckspurtamount > 0) {
4270 neckspurtamount -= multiplier;
4271 neckspurtdelay -= multiplier * 3;
4272 neckspurtparticledelay -= multiplier * 3;
4273 if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
4276 if (!skeleton.free) {
4277 bloodvel.z = 5 * neckspurtamount;
4278 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4280 if (skeleton.free) {
4281 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
4284 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4286 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
4288 Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4290 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4291 neckspurtparticledelay = .05;
4293 if (neckspurtdelay < 0) {
4298 if (deathbleeding > 0 && dead != 2) {
4299 if (deathbleeding < 5)
4300 bleeddelay -= deathbleeding * multiplier / 4;
4302 bleeddelay -= 5 * multiplier / 4;
4303 if (bleeddelay < 0 && bloodtoggle) {
4309 bloodvel += DoRotation(jointVel(abdomen), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
4311 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
4313 Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4315 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
4318 bloodloss += deathbleeding * multiplier * 80;
4319 deathbleeding -= multiplier * 1.6;
4320 //if(id==0)deathbleeding-=multiplier*.2;
4321 if (deathbleeding < 0)
4323 if (bloodloss > damagetolerance && animation[animTarget].attack == neutral) {
4324 if (weaponactive != -1) {
4325 weapons[weaponids[0]].owner = -1;
4326 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4327 weapons[weaponids[0]].velocity.x += .01;
4328 weapons[weaponids[0]].tipvelocity = velocity * scale;
4329 weapons[weaponids[0]].missed = 1;
4330 weapons[weaponids[0]].hitsomething = 0;
4331 weapons[weaponids[0]].freetime = 0;
4332 weapons[weaponids[0]].firstfree = 1;
4333 weapons[weaponids[0]].physics = 1;
4336 weaponids[0] = weaponids[num_weapons];
4337 if (weaponstuck == num_weapons)
4341 for (unsigned i = 0; i < Person::players.size(); i++) {
4342 Person::players[i]->wentforweapon = 0;
4354 if (!dead && creature == wolftype) {
4355 award_bonus(0, Wolfbonus);
4358 if (animTarget == knifefollowedanim && !skeleton.free) {
4359 for (int i = 0; i < skeleton.num_joints; i++) {
4360 skeleton.joints[i].velocity = 0;
4361 skeleton.joints[i].velocity.y = -2;
4364 if (id != 0 && unconscioustime > .1) {
4372 if (texupdatedelay < 0 && bleeding > 0 && bloodtoggle == 2 && distsq(&viewer, &coords) < 9) {
4373 texupdatedelay = .12;
4375 bloodsize = 5 - realtexdetail;
4379 startx = bleedy; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4380 starty = bleedx; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4381 endx = startx + bloodsize;
4382 endy = starty + bloodsize;
4392 if (endx > skeleton.skinsize - 1) {
4393 endx = skeleton.skinsize - 1;
4396 if (endy > skeleton.skinsize - 1) {
4397 endy = skeleton.skinsize - 1;
4405 for (i = startx; i < endx; i++) {
4406 for (j = starty; j < endy; j++) {
4407 if (Random() % 2 == 0) {
4408 color = Random() % 85 + 170;
4409 if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2)
4410 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2;
4411 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0;
4412 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0;
4416 if (!osx && detail > 1) {
4417 skeleton.drawmodel.textureptr.bind();
4421 if (!skeleton.free) {
4422 bleedy -= 4 / realtexdetail;
4424 bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4426 bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4428 if (skeleton.free) {
4429 bleedx += 4 * direction / realtexdetail;
4431 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4433 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4437 if (abs(righthandmorphness - targetrighthandmorphness) < multiplier * 4) {
4438 righthandmorphness = targetrighthandmorphness;
4439 righthandmorphstart = righthandmorphend;
4440 } else if (righthandmorphness > targetrighthandmorphness) {
4441 righthandmorphness -= multiplier * 4;
4442 } else if (righthandmorphness < targetrighthandmorphness) {
4443 righthandmorphness += multiplier * 4;
4446 if (abs(lefthandmorphness - targetlefthandmorphness) < multiplier * 4) {
4447 lefthandmorphness = targetlefthandmorphness;
4448 lefthandmorphstart = lefthandmorphend;
4449 } else if (lefthandmorphness > targetlefthandmorphness) {
4450 lefthandmorphness -= multiplier * 4;
4451 } else if (lefthandmorphness < targetlefthandmorphness) {
4452 lefthandmorphness += multiplier * 4;
4455 if (creature == rabbittype || targettailmorphness == 5 || targettailmorphness == 0) {
4456 if (abs(tailmorphness - targettailmorphness) < multiplier * 10) {
4457 tailmorphness = targettailmorphness;
4458 tailmorphstart = tailmorphend;
4459 } else if (tailmorphness > targettailmorphness) {
4460 tailmorphness -= multiplier * 10;
4461 } else if (tailmorphness < targettailmorphness) {
4462 tailmorphness += multiplier * 10;
4466 if (creature == wolftype) {
4467 if (abs(tailmorphness - targettailmorphness) < multiplier * 4) {
4468 tailmorphness = targettailmorphness;
4469 tailmorphstart = tailmorphend;
4470 } else if (tailmorphness > targettailmorphness) {
4471 tailmorphness -= multiplier * 2;
4472 } else if (tailmorphness < targettailmorphness) {
4473 tailmorphness += multiplier * 2;
4477 if (headmorphend == 3 || headmorphstart == 3) {
4478 if (abs(headmorphness - targetheadmorphness) < multiplier * 7) {
4479 headmorphness = targetheadmorphness;
4480 headmorphstart = headmorphend;
4481 } else if (headmorphness > targetheadmorphness) {
4482 headmorphness -= multiplier * 7;
4483 } else if (headmorphness < targetheadmorphness) {
4484 headmorphness += multiplier * 7;
4486 } else if (headmorphend == 5 || headmorphstart == 5) {
4487 if (abs(headmorphness - targetheadmorphness) < multiplier * 10) {
4488 headmorphness = targetheadmorphness;
4489 headmorphstart = headmorphend;
4490 } else if (headmorphness > targetheadmorphness) {
4491 headmorphness -= multiplier * 10;
4492 } else if (headmorphness < targetheadmorphness) {
4493 headmorphness += multiplier * 10;
4496 if (abs(headmorphness - targetheadmorphness) < multiplier * 4) {
4497 headmorphness = targetheadmorphness;
4498 headmorphstart = headmorphend;
4499 } else if (headmorphness > targetheadmorphness) {
4500 headmorphness -= multiplier * 4;
4501 } else if (headmorphness < targetheadmorphness) {
4502 headmorphness += multiplier * 4;
4506 if (abs(chestmorphness - targetchestmorphness) < multiplier) {
4507 chestmorphness = targetchestmorphness;
4508 chestmorphstart = chestmorphend;
4509 } else if (chestmorphness > targetchestmorphness) {
4510 chestmorphness -= multiplier;
4511 } else if (chestmorphness < targetchestmorphness) {
4512 chestmorphness += multiplier;
4515 if (dead != 2 && howactive <= typesleeping) {
4516 if (chestmorphstart == 0 && chestmorphend == 0) {
4518 targetchestmorphness = 1;
4521 if (chestmorphstart != 0 && chestmorphend != 0) {
4523 targetchestmorphness = 1;
4525 if (environment == snowyenvironment) {
4529 footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
4531 footvel = skeleton.specialforward[0] * -1;
4533 footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
4535 footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
4536 if (animTarget == sleepanim)
4537 footvel = DoRotation(footvel, 0, 90, 0);
4538 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
4542 if (!dead && howactive < typesleeping) {
4543 blinkdelay -= multiplier * 2;
4544 if (headmorphstart == 0 && headmorphend == 0 && blinkdelay <= 0) {
4546 targetheadmorphness = 1;
4548 blinkdelay = (float)(abs(Random() % 40)) / 5;
4550 if (headmorphstart == 3 && headmorphend == 3) {
4552 targetheadmorphness = 1;
4557 twitchdelay -= multiplier * 1.5;
4558 if (animTarget != hurtidleanim) {
4559 if (headmorphstart == 0 && headmorphend == 0 && twitchdelay <= 0) {
4561 targetheadmorphness = 1;
4563 twitchdelay = (float)(abs(Random() % 40)) / 5;
4565 if (headmorphstart == 5 && headmorphend == 5) {
4567 targetheadmorphness = 1;
4571 if ((isIdle() || isCrouch()) && animTarget != hurtidleanim) {
4572 twitchdelay3 -= multiplier * 1;
4573 if (Random() % 2 == 0) {
4574 if (righthandmorphstart == 0 && righthandmorphend == 0 && twitchdelay3 <= 0) {
4575 righthandmorphness = 0;
4576 targetrighthandmorphness = 1;
4577 righthandmorphend = 1;
4578 if (Random() % 2 == 0)twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4580 if (righthandmorphstart == 1 && righthandmorphend == 1) {
4581 righthandmorphness = 0;
4582 targetrighthandmorphness = 1;
4583 righthandmorphend = 0;
4586 if (Random() % 2 == 0) {
4587 if (lefthandmorphstart == 0 && lefthandmorphend == 0 && twitchdelay3 <= 0) {
4588 lefthandmorphness = 0;
4589 targetlefthandmorphness = 1;
4590 lefthandmorphend = 1;
4591 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4593 if (lefthandmorphstart == 1 && lefthandmorphend == 1) {
4594 lefthandmorphness = 0;
4595 targetlefthandmorphness = 1;
4596 lefthandmorphend = 0;
4602 if (creature == rabbittype) {
4603 if (howactive < typesleeping)
4604 twitchdelay2 -= multiplier * 1.5;
4606 twitchdelay2 -= multiplier * 0.5;
4607 if (howactive <= typesleeping) {
4608 if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) {
4610 targettailmorphness = 1;
4612 twitchdelay2 = (float)(abs(Random() % 40)) / 5;
4614 if (tailmorphstart == 1 && tailmorphend == 1) {
4616 targettailmorphness = 1;
4619 if (tailmorphstart == 2 && tailmorphend == 2) {
4621 targettailmorphness = 1;
4628 if (creature == wolftype) {
4629 twitchdelay2 -= multiplier * 1.5;
4630 if (tailmorphend != 0)
4631 if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) {
4633 targettailmorphness = 1;
4637 if (tailmorphend != 5)
4638 if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) {
4640 targettailmorphness = 1;
4644 if (twitchdelay2 <= 0) {
4645 if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) {
4647 targettailmorphness = 1;
4650 if (tailmorphstart == 1 && tailmorphend == 1) {
4652 targettailmorphness = 1;
4655 if (tailmorphstart == 2 && tailmorphend == 2) {
4657 targettailmorphness = 1;
4660 if (tailmorphstart == 3 && tailmorphend == 3) {
4662 targettailmorphness = 1;
4665 if (tailmorphstart == 4 && tailmorphend == 4) {
4667 targettailmorphness = 1;
4674 unconscioustime = 0;
4676 if (dead == 1 || howactive == typesleeping) {
4677 unconscioustime += multiplier;
4678 //If unconscious, close eyes and mouth
4679 if (righthandmorphend != 0)
4680 righthandmorphness = 0;
4681 righthandmorphend = 0;
4682 targetrighthandmorphness = 1;
4684 if (lefthandmorphend != 0)
4685 lefthandmorphness = 0;
4686 lefthandmorphend = 0;
4687 targetlefthandmorphness = 1;
4689 if (headmorphend != 3 && headmorphend != 5)
4692 targetheadmorphness = 1;
4696 if (howactive > typesleeping) {
4699 if (bloodtoggle && !bled) {
4700 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4702 if (bloodtoggle && !bled)
4703 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4704 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4705 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4709 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4714 if (dead == 2 || howactive > typesleeping) {
4715 //If dead, open mouth and hands
4716 if (righthandmorphend != 0)
4717 righthandmorphness = 0;
4718 righthandmorphend = 0;
4719 targetrighthandmorphness = 1;
4721 if (lefthandmorphend != 0)
4722 lefthandmorphness = 0;
4723 lefthandmorphend = 0;
4724 targetlefthandmorphness = 1;
4726 if (headmorphend != 2)
4729 targetheadmorphness = 1;
4732 if (stunned > 0 && !dead && headmorphend != 2) {
4733 if (headmorphend != 4)
4736 targetheadmorphness = 1;
4739 if (damage > damagetolerance && !dead) {
4742 unconscioustime = 0;
4744 if (creature == wolftype) {
4745 award_bonus(0, Wolfbonus);
4750 if (weaponactive != -1) {
4751 weapons[weaponids[0]].owner = -1;
4752 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4753 weapons[weaponids[0]].velocity.x += .01;
4754 weapons[weaponids[0]].tipvelocity = velocity * scale;
4755 weapons[weaponids[0]].missed = 1;
4756 weapons[weaponids[0]].hitsomething = 0;
4757 weapons[weaponids[0]].freetime = 0;
4758 weapons[weaponids[0]].firstfree = 1;
4759 weapons[weaponids[0]].physics = 1;
4762 weaponids[0] = weaponids[num_weapons];
4763 if (weaponstuck == num_weapons)
4767 for (unsigned i = 0; i < Person::players.size(); i++) {
4768 Person::players[i]->wentforweapon = 0;
4774 if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) {
4782 //if(dead)damage-=multiplier/4;
4784 damage -= multiplier * 13;
4785 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4787 permanentdamage -= multiplier * 4;
4788 if (isIdle() || isCrouch()) {
4790 permanentdamage -= multiplier * 4;
4791 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4795 if (permanentdamage < 0)
4796 permanentdamage = 0;
4797 if (superpermanentdamage < 0)
4798 superpermanentdamage = 0;
4799 if (permanentdamage < superpermanentdamage) {
4800 permanentdamage = superpermanentdamage;
4802 if (damage < permanentdamage) {
4803 damage = permanentdamage;
4805 if (dead == 1 && damage < damagetolerance) {
4809 for (int i = 0; i < skeleton.num_joints; i++) {
4810 skeleton.joints[i].velocity = 0;
4813 if (permanentdamage > damagetolerance && dead != 2) {
4816 if (weaponactive != -1) {
4817 weapons[weaponids[0]].owner = -1;
4818 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4819 weapons[weaponids[0]].velocity.x += .01;
4820 weapons[weaponids[0]].tipvelocity = velocity * scale;
4821 weapons[weaponids[0]].missed = 1;
4822 weapons[weaponids[0]].hitsomething = 0;
4823 weapons[weaponids[0]].freetime = 0;
4824 weapons[weaponids[0]].firstfree = 1;
4825 weapons[weaponids[0]].physics = 1;
4828 weaponids[0] = weaponids[num_weapons];
4829 if (weaponstuck == num_weapons)
4833 for (unsigned i = 0; i < Person::players.size(); i++) {
4834 Person::players[i]->wentforweapon = 0;
4840 if (!dead && creature == wolftype) {
4841 award_bonus(0, Wolfbonus);
4844 if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance)
4845 award_bonus(id, touchofdeath);
4846 if (id != 0 && unconscioustime > .1) {
4854 emit_sound_at(breaksound, coords);
4857 if (skeleton.free == 1) {
4859 pause_sound(whooshsound);
4862 //If knocked over, open hands and close mouth
4863 if (righthandmorphend != 0)
4864 righthandmorphness = 0;
4865 righthandmorphend = 0;
4866 targetrighthandmorphness = 1;
4868 if (lefthandmorphend != 0)
4869 lefthandmorphness = 0;
4870 lefthandmorphend = 0;
4871 targetlefthandmorphness = 1;
4873 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) {
4874 if (headmorphend != 0)
4877 targetheadmorphness = 1;
4881 skeleton.DoGravity(&scale);
4883 damageamount = skeleton.DoConstraints(&coords, &scale) * 5;
4884 if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1))
4885 award_bonus(id, deepimpact);
4886 DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3));
4890 for (j = 0; j < skeleton.num_joints; j++) {
4891 average += skeleton.joints[j].position;
4895 coords += average * scale;
4896 for (j = 0; j < skeleton.num_joints; j++) {
4897 skeleton.joints[j].position -= average;
4899 average /= multiplier;
4901 //velocity=jointVel(groin)*scale;
4903 for (int i = 0; i < skeleton.num_joints; i++) {
4904 velocity += skeleton.joints[i].velocity * scale;
4906 velocity /= skeleton.num_joints;
4908 if (!isnormal(velocity.x) && velocity.x) {
4912 if (findLength(&average) < 10 && dead && skeleton.free) {
4913 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
4914 if (skeleton.longdead > 2000) {
4915 if (skeleton.longdead > 6000) {
4917 pause_sound(whooshsound);
4922 if (dead == 2 && bloodloss < damagetolerance) {
4924 headpoint = (jointPos(head) + jointPos(neck)) / 2 * scale + coords;
4926 if (bloodtoggle && !bled) {
4927 terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
4929 if (bloodtoggle && !bled)
4930 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4931 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4932 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4933 float size = .2 * 1.2;
4936 objects.model[j].MakeDecal(blooddecal, &point, &size, &opacity, &yaw);
4940 if (dead == 2 && bloodloss >= damagetolerance) {
4942 headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords;
4945 if (bloodtoggle && !bled) {
4946 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4948 if (bloodtoggle && !bled)
4949 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4950 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4951 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4955 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4962 if (!dead && crouchkeydown && skeleton.freetime > .5 && id == 0 && skeleton.free) {
4963 bool canrecover = 1;
4964 XYZ startpoint, endpoint, colpoint, colviewer, coltarget;
4965 startpoint = coords;
4968 if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1)
4970 if (velocity.y < -30)
4972 for (i = 0; i < objects.numobjects; i++) {
4973 if (objects.type[i] != treeleavestype && objects.type[i] != bushtype && objects.type[i] != firetype) {
4974 colviewer = startpoint;
4975 coltarget = endpoint;
4976 if (objects.model[i].LineCheck(&colviewer, &coltarget, &colpoint, &objects.position[i], &objects.yaw[i]) != -1)
4985 terrainnormal = jointPos(groin) - jointPos(abdomen);
4986 if (joint(groin).locked && joint(abdomen).locked) {
4987 terrainnormal = jointPos(groin) - jointPos(abdomen);
4988 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
4990 if (joint(abdomen).locked && joint(neck).locked) {
4991 terrainnormal = jointPos(abdomen) - jointPos(neck);
4992 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
4994 if (joint(groin).locked && joint(neck).locked) {
4995 terrainnormal = jointPos(groin) - jointPos(neck);
4996 middle = (jointPos(groin) + jointPos(neck)) / 2;
4998 Normalise(&terrainnormal);
5000 targetyaw = -asin(0 - terrainnormal.x);
5001 targetyaw *= 360 / 6.28;
5002 if (terrainnormal.z < 0)
5003 targetyaw = 180 - targetyaw;
5008 animTarget = flipanim;
5009 crouchtogglekeydown = 1;
5014 animCurrent = tempanim;
5017 //tilt2=targettilt2;
5019 //if(middle.y>0)targetoffset.y=middle.y+1;
5021 for (int i = 0; i < skeleton.num_joints; i++) {
5022 tempanimation.position[i][0] = skeleton.joints[i].position;
5023 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
5028 if (findLength(&average) < 10 && !dead && skeleton.free) {
5029 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
5030 if (skeleton.longdead > (damage + 500) * 1.5) {
5032 pause_sound(whooshsound);
5038 terrainnormal = jointPos(groin) - jointPos(abdomen);
5039 if (joint(groin).locked && joint(abdomen).locked) {
5040 terrainnormal = jointPos(groin) - jointPos(abdomen);
5041 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
5043 if (joint(abdomen).locked && joint(neck).locked) {
5044 terrainnormal = jointPos(abdomen) - jointPos(neck);
5045 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
5047 if (joint(groin).locked && joint(neck).locked) {
5048 terrainnormal = jointPos(groin) - jointPos(neck);
5049 middle = (jointPos(groin) + jointPos(neck)) / 2;
5051 Normalise(&terrainnormal);
5053 targetyaw = -asin(0 - terrainnormal.x);
5054 targetyaw *= 360 / 6.28;
5055 if (terrainnormal.z < 0)
5056 targetyaw = 180 - targetyaw;
5059 targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1;
5062 if (skeleton.forward.y < 0) {
5063 animTarget = getupfrombackanim;
5067 if (skeleton.forward.y > -.3) {
5068 animTarget = getupfromfrontanim;
5076 if ((Random() % 8 == 0 && id != 0 && creature == rabbittype) || (Random() % 2 == 0 && id != 0 && creature == wolftype) || (id == 0 && crouchkeydown && (forwardkeydown || backkeydown || leftkeydown || rightkeydown))) {
5077 animTarget = rollanim;
5078 targetyaw = lookyaw;
5095 if ( !leftkeydown && !rightkeydown)
5102 if (abs(targettilt2) > 50)
5104 animCurrent = tempanim;
5107 tilt2 = targettilt2;
5109 if (middle.y > 0 && animTarget != rollanim)
5110 targetoffset.y = middle.y + 1;
5112 for (int i = 0; i < skeleton.num_joints; i++) {
5113 tempanimation.position[i][0] = skeleton.joints[i].position;
5114 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
5121 if (num_weapons > 0)
5122 if (weapons[0].getType() == staff)
5124 if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) {
5125 if (velocity.y > -30) {
5127 tempvelocity = velocity;
5128 Normalise(&tempvelocity);
5129 targetyaw = -asin(0 - tempvelocity.x);
5130 targetyaw *= 360 / 6.28;
5132 targetyaw = 180 - targetyaw;
5136 if (dotproduct(&skeleton.forward, &tempvelocity) < 0) {
5137 animTarget = rollanim;
5140 animTarget = backhandspringanim;
5146 emit_sound_at(movewhooshsound, coords, 128.);
5148 animCurrent = animTarget;
5149 frameCurrent = frameTarget - 1;
5161 if (skeleton.freefall == 0)
5166 if (aitype != passivetype || skeleton.free == 1)
5167 if (findLengthfast(&velocity) > .1)
5168 for (i = 0; i < objects.numobjects; i++) {
5169 if (objects.type[i] == firetype)
5170 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) {
5172 if (!objects.onfire[i]) {
5173 emit_sound_at(firestartsound, objects.position[i]);
5175 objects.onfire[i] = 1;
5178 if (objects.onfire[i]) {
5183 if (objects.type[i] == bushtype)
5184 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) {
5186 if (!objects.onfire[i]) {
5187 emit_sound_at(firestartsound, objects.position[i]);
5189 objects.onfire[i] = 1;
5193 if (objects.onfire[i]) {
5197 if (objects.messedwith[i] <= 0) {
5201 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5204 envsound[numenvsounds] = coords;
5205 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5206 envsoundlife[numenvsounds] = .4;
5211 if (environment == grassyenvironment)
5212 howmany = findLength(&velocity) * 4;
5213 if (environment == snowyenvironment)
5214 howmany = findLength(&velocity) * 2;
5216 if (environment != desertenvironment)
5217 for (j = 0; j < howmany; j++) {
5218 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5219 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5220 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5223 pos.x += float(abs(Random() % 100) - 50) / 200;
5224 pos.y += float(abs(Random() % 100) - 50) / 200;
5225 pos.z += float(abs(Random() % 100) - 50) / 200;
5226 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);
5227 Sprite::setLastSpriteSpecial(1);
5229 howmany = findLength(&velocity) * 4;
5231 if (environment == snowyenvironment)
5232 for (j = 0; j < howmany; j++) {
5233 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5234 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5235 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5238 pos.x += float(abs(Random() % 100) - 50) / 200;
5239 pos.y += float(abs(Random() % 100) - 50) / 200;
5240 pos.z += float(abs(Random() % 100) - 50) / 200;
5241 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5242 Sprite::setLastSpriteSpecial(2);
5245 objects.rotx[i] += velocity.x * multiplier * 6;
5246 objects.roty[i] += velocity.z * multiplier * 6;
5247 objects.messedwith[i] = .5;
5250 if (objects.type[i] == treeleavestype && environment != desertenvironment) {
5251 if (objects.pitch[i] == 0)
5254 tempcoord = coords - objects.position[i];
5255 tempcoord = DoRotation(tempcoord, 0, -objects.yaw[i], 0);
5256 tempcoord = DoRotation(tempcoord, -objects.pitch[i], 0, 0);
5257 tempcoord += objects.position[i];
5259 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]) {
5260 if (objects.messedwith[i] <= 0) {
5264 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5267 envsound[numenvsounds] = coords;
5268 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5269 envsoundlife[numenvsounds] = .4;
5274 if (environment == grassyenvironment)
5275 howmany = findLength(&velocity) * 4;
5276 if (environment == snowyenvironment)
5277 howmany = findLength(&velocity) * 2;
5279 if (environment != desertenvironment)
5280 for (j = 0; j < howmany; j++) {
5281 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5282 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5283 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5285 pos += velocity * .1;
5287 pos.x += float(abs(Random() % 100) - 50) / 150;
5288 pos.y += float(abs(Random() % 100) - 50) / 150;
5289 pos.z += float(abs(Random() % 100) - 50) / 150;
5290 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);
5291 Sprite::setLastSpriteSpecial(1);
5293 howmany = findLength(&velocity) * 4;
5295 if (environment == snowyenvironment)
5296 for (j = 0; j < howmany; j++) {
5297 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5298 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5299 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5301 pos += velocity * .1;
5303 pos.x += float(abs(Random() % 100) - 50) / 150;
5304 pos.y += float(abs(Random() % 100) - 50) / 150;
5305 pos.z += float(abs(Random() % 100) - 50) / 150;
5306 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5307 Sprite::setLastSpriteSpecial(2);
5310 objects.messedwith[i] = .5;
5315 if (!skeleton.free) {
5318 if ((stunned > 0 || surprised > 0) && Person::players.size() > 2 && aitype != passivetype)
5321 if (aitype != passivetype && victim->skeleton.free && !victim->dead)
5323 if (tutoriallevel == 1 && id != 0)
5325 if (play && aitype != playercontrolled) {
5326 int whichsound = -1;
5327 i = abs(Random() % 4);
5328 if (speechdelay <= 0) {
5329 if (creature == rabbittype) {
5331 whichsound = rabbitchitter;
5333 whichsound = rabbitchitter2;
5335 if (creature == wolftype) {
5337 whichsound = growlsound;
5339 whichsound = growl2sound;
5344 if (whichsound != -1) {
5345 emit_sound_at(whichsound, coords);
5349 if (animTarget == staggerbackhighanim)
5351 if (animTarget == staggerbackhardanim)
5353 staggerdelay -= multiplier;
5354 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
5356 if (velocity.y < -30 && animTarget == jumpdownanim)
5358 if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) {
5359 animTarget = getIdle();
5363 weaponmissdelay -= multiplier;
5364 highreversaldelay -= multiplier;
5365 lowreversaldelay -= multiplier;
5366 lastcollide -= multiplier;
5367 skiddelay -= multiplier;
5368 if (!isnormal(velocity.x) && velocity.x) {
5371 if (!isnormal(targettilt) && targettilt) {
5374 if (!isnormal(targettilt2) && targettilt2) {
5377 if (!isnormal(targetyaw) && targetyaw) {
5381 if (animTarget == bounceidleanim || animTarget == wolfidle || animTarget == walkanim || animTarget == drawrightanim || animTarget == crouchdrawrightanim || animTarget == drawleftanim || animTarget == fightidleanim || animTarget == fightsidestep || animTarget == hanganim || isCrouch() || animTarget == backhandspringanim) {
5382 //open hands and close mouth
5383 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5384 righthandmorphness = 0;
5385 righthandmorphend = 0;
5386 targetrighthandmorphness = 1;
5389 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5390 lefthandmorphness = 0;
5391 lefthandmorphend = 0;
5392 targetlefthandmorphness = 1;
5395 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5 && headmorphend != 0 && headmorphness == targetheadmorphness) {
5398 targetheadmorphness = 1;
5402 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) {
5403 //open hands and mouth
5404 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5405 righthandmorphness = 0;
5406 righthandmorphend = 0;
5407 targetrighthandmorphness = 1;
5410 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5411 lefthandmorphness = 0;
5412 lefthandmorphend = 0;
5413 targetlefthandmorphness = 1;
5416 if (headmorphend != 1 && headmorphness == targetheadmorphness) {
5419 targetheadmorphness = 1;
5423 if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim || animTarget == blockhighleftanim) {
5424 //close hands and mouth
5425 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5426 righthandmorphness = 0;
5427 righthandmorphend = 1;
5428 targetrighthandmorphness = 1;
5431 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5432 lefthandmorphness = 0;
5433 lefthandmorphend = 1;
5434 targetlefthandmorphness = 1;
5437 if (headmorphend != 0 && headmorphness == targetheadmorphness) {
5440 targetheadmorphness = 1;
5444 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) {
5445 //close hands and yell
5446 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5447 righthandmorphness = 0;
5448 righthandmorphend = 1;
5449 targetrighthandmorphness = 1;
5452 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5453 lefthandmorphness = 0;
5454 lefthandmorphend = 1;
5455 targetlefthandmorphness = 1;
5458 if (headmorphend != 2 && headmorphness == targetheadmorphness) {
5461 targetheadmorphness = 1;
5468 if ((victim != this->shared_from_this()) && !victim->dead && (victim->aitype != passivetype) &&
5469 (victim->aitype != searchtype) && (aitype != passivetype) &&
5470 (aitype != searchtype) && (victim->id < Person::players.size()) && (aitype != passivetype)) {
5471 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
5475 if (!dead && animTarget != hurtidleanim)
5476 if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) {
5477 if (headmorphend != 4 || headmorphness == targetheadmorphness) {
5480 targetheadmorphness = 1;
5484 if (weaponactive != -1) {
5485 if (weapons[weaponids[weaponactive]].getType() != staff) {
5486 righthandmorphstart = 1;
5487 righthandmorphend = 1;
5489 if (weapons[weaponids[weaponactive]].getType() == staff) {
5490 righthandmorphstart = 2;
5491 righthandmorphend = 2;
5493 targetrighthandmorphness = 1;
5496 terrainnormal = terrain.getNormal(coords.x, coords.z);
5498 if (animation[animTarget].attack != reversal) {
5499 if (!isnormal(coords.x))
5507 flatfacing = DoRotation(flatfacing, 0, yaw, 0);
5508 facing = flatfacing;
5509 ReflectVector(&facing, terrainnormal);
5512 if (isRun() || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) {
5514 targettilt2 = -facing.y * 20;
5519 if (!isRun() && !animation[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim)
5521 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5522 flatvelocity = velocity;
5524 flatvelspeed = findLength(&flatvelocity);
5525 targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity);
5526 targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity);
5531 if (targettilt > 25)
5533 if (targettilt < -25)
5537 if (targettilt2 > 45)
5539 if (targettilt2 < -45)
5541 if (abs(tilt2 - targettilt2) < multiplier * 400)
5542 tilt2 = targettilt2;
5543 else if (tilt2 > targettilt2) {
5544 tilt2 -= multiplier * 400;
5545 } else if (tilt2 < targettilt2) {
5546 tilt2 += multiplier * 400;
5548 if (!animation[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) {
5555 if (!isnormal(targettilt) && targettilt) {
5558 if (!isnormal(targettilt2) && targettilt2) {
5563 //if(!creature==wolftype||animTarget==rabbitkickanim)
5564 if (animTarget == rabbittackleanim) {
5565 velocity += facing * multiplier * speed * 700 * scale;
5566 velspeed = findLength(&velocity);
5567 if (velspeed > speed * 65 * scale) {
5568 velocity /= velspeed;
5569 velspeed = speed * 65 * scale;
5570 velocity *= velspeed;
5572 velocity.y += gravity * multiplier * 20;
5573 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5574 velspeed = findLength(&velocity);
5575 velocity = flatfacing * velspeed;
5577 if (animTarget != rabbitrunninganim && animTarget != wolfrunninganim) {
5578 if (isRun() || animTarget == rabbitkickanim) {
5579 velocity += facing * multiplier * speed * 700 * scale;
5580 velspeed = findLength(&velocity);
5581 if (velspeed > speed * 45 * scale) {
5582 velocity /= velspeed;
5583 velspeed = speed * 45 * scale;
5584 velocity *= velspeed;
5586 velocity.y += gravity * multiplier * 20;
5587 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5588 velspeed = findLength(&velocity);
5589 if (velspeed < speed * 30 * scale)
5590 velspeed = speed * 30 * scale;
5591 velocity = flatfacing * velspeed;
5593 } else if (isRun()) {
5594 velocity += facing * multiplier * speed * 700 * scale;
5595 velspeed = findLength(&velocity);
5596 if (creature == rabbittype) {
5597 if (velspeed > speed * 55 * scale) {
5598 velocity /= velspeed;
5599 velspeed = speed * 55 * scale;
5600 velocity *= velspeed;
5603 if (creature == wolftype) {
5604 if (velspeed > speed * 75 * scale) {
5605 velocity /= velspeed;
5606 velspeed = speed * 75 * scale;
5607 velocity *= velspeed;
5610 velocity.y += gravity * multiplier * 20;
5611 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5612 velspeed = findLength(&velocity);
5613 velocity = flatfacing * velspeed;
5616 if (animTarget == rollanim && animation[animTarget].label[frameTarget] != 6) {
5617 velocity += facing * multiplier * speed * 700 * scale;
5618 velspeed = findLength(&velocity);
5619 if (velspeed > speed * 45 * scale) {
5620 velocity /= velspeed;
5621 velspeed = speed * 45 * scale;
5622 velocity *= velspeed;
5624 velocity.y += gravity * multiplier * 20;
5625 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5626 velspeed = findLength(&velocity);
5627 velocity = flatfacing * velspeed;
5631 /*if(animCurrent==rollanim&&(isCrouch()||isIdle())){
5632 velocity+=facing*multiplier*speed*700*scale;
5633 velspeed=findLength(&velocity);
5634 if(velspeed>speed*25*scale){
5636 velspeed=speed*25*scale;
5639 velocity.y+=gravity*multiplier*20;
5640 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5641 velspeed=findLength(&velocity);
5642 velocity=flatfacing*velspeed;
5645 if (animTarget == sneakanim || animTarget == walkanim) {
5646 velocity += facing * multiplier * speed * 700 * scale;
5647 velspeed = findLength(&velocity);
5648 if (velspeed > speed * 12 * scale) {
5649 velocity /= velspeed;
5650 velspeed = speed * 12 * scale;
5651 velocity *= velspeed;
5653 velocity.y += gravity * multiplier * 20;
5654 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5655 velspeed = findLength(&velocity);
5656 velocity = flatfacing * velspeed;
5659 if ((animTarget == fightidleanim || animTarget == knifefightidleanim) && (animCurrent == bounceidleanim || animCurrent == hurtidleanim)) {
5660 velocity += facing * multiplier * speed * 700 * scale;
5661 velspeed = findLength(&velocity);
5662 if (velspeed > speed * 2 * scale) {
5663 velocity /= velspeed;
5664 velspeed = speed * 2 * scale;
5665 velocity *= velspeed;
5667 velocity.y += gravity * multiplier * 20;
5668 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5669 velspeed = findLength(&velocity);
5670 velocity = flatfacing * velspeed;
5674 if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) {
5675 velocity -= facing * multiplier * speed * 700 * scale;
5676 velspeed = findLength(&velocity);
5677 if (velspeed > speed * 2 * scale) {
5678 velocity /= velspeed;
5679 velspeed = speed * 2 * scale;
5680 velocity *= velspeed;
5682 velocity.y += gravity * multiplier * 20;
5683 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5684 velspeed = findLength(&velocity);
5685 velocity = flatfacing * velspeed * -1;
5688 if (animTarget == fightsidestep) {
5689 velocity += DoRotation(facing * multiplier * speed * 700 * scale, 0, -90, 0);
5690 velspeed = findLength(&velocity);
5691 if (velspeed > speed * 12 * scale) {
5692 velocity /= velspeed;
5693 velspeed = speed * 12 * scale;
5694 velocity *= velspeed;
5696 velocity.y += gravity * multiplier * 20;
5697 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5698 velspeed = findLength(&velocity);
5699 velocity = DoRotation(flatfacing * velspeed, 0, -90, 0);
5702 if (animTarget == staggerbackhighanim) {
5703 coords -= facing * multiplier * speed * 16 * scale;
5706 if (animTarget == staggerbackhardanim && animation[staggerbackhardanim].label[frameTarget] != 6) {
5707 coords -= facing * multiplier * speed * 20 * scale;
5711 if (animTarget == backhandspringanim) {
5712 //coords-=facing*multiplier*50*scale;
5713 velocity += facing * multiplier * speed * 700 * scale * -1;
5714 velspeed = findLength(&velocity);
5715 if (velspeed > speed * 50 * scale) {
5716 velocity /= velspeed;
5717 velspeed = speed * 50 * scale;
5718 velocity *= velspeed;
5720 velocity.y += gravity * multiplier * 20;
5721 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5722 velspeed = findLength(&velocity);
5723 velocity = flatfacing * velspeed * -1;
5725 if (animTarget == dodgebackanim) {
5726 //coords-=facing*multiplier*50*scale;
5727 velocity += facing * multiplier * speed * 700 * scale * -1;
5728 velspeed = findLength(&velocity);
5729 if (velspeed > speed * 60 * scale) {
5730 velocity /= velspeed;
5731 velspeed = speed * 60 * scale;
5732 velocity *= velspeed;
5734 velocity.y += gravity * multiplier * 20;
5735 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5736 velspeed = findLength(&velocity);
5737 velocity = flatfacing * velspeed * -1;
5740 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5741 velspeed = findLength(&velocity);
5745 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5746 velocity.y += gravity * multiplier;
5749 if (animTarget != climbanim && animTarget != hanganim && !isWallJump())
5750 coords += velocity * multiplier;
5752 if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
5753 if (isFlip() && animation[animTarget].label[frameTarget] == 7)
5756 if (animTarget == jumpupanim) {
5758 animTarget = getIdle();
5765 pause_sound(whooshsound);
5766 OPENAL_SetVolume(channels[whooshsound], 0);
5769 if (animTarget == jumpdownanim || isFlip()) {
5770 if (isFlip())jumppower = -4;
5771 animTarget = getLanding();
5772 emit_sound_at(landsound, coords, 128.);
5775 envsound[numenvsounds] = coords;
5776 envsoundvol[numenvsounds] = 16;
5777 envsoundlife[numenvsounds] = .4;
5783 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump())
5784 coords.y += gravity * multiplier * 2;
5785 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) {
5786 coords.y = terrain.getHeight(coords.x, coords.z);
5791 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)) {
5792 velspeed = findLength(&velocity);
5794 if (velspeed < multiplier * 300 * scale) {
5797 velocity -= velocity / velspeed * multiplier * 300 * scale;
5798 if (velspeed > 5 && (isLanding() || isLandhard())) {
5799 skiddingdelay += multiplier;
5800 if (skiddelay <= 0) {
5810 velspeed = findLength(&velocity);
5812 if (velspeed < multiplier * 600 * scale) {
5815 velocity -= velocity / velspeed * multiplier * 600 * scale;
5817 if (velspeed > 5 && (isLanding() || isLandhard())) {
5818 skiddingdelay += multiplier;
5819 if (skiddelay <= 0) {
5828 if (skiddingdelay < 0)
5829 skiddingdelay += multiplier;
5830 if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) {
5832 if (!onterrain || environment == grassyenvironment) {
5833 emit_sound_at(skidsound, coords, 128 * velspeed / 10);
5835 emit_sound_at(snowskidsound, coords, 128 * velspeed / 10);
5839 if (animation[animTarget].attack == normalattack && animTarget != rabbitkickanim && !victim->skeleton.free) {
5840 terrainnormal = victim->coords - coords;
5841 Normalise(&terrainnormal);
5842 targetyaw = -asin(0 - terrainnormal.x);
5843 targetyaw *= 360 / 6.28;
5844 if (terrainnormal.z < 0)
5845 targetyaw = 180 - targetyaw;
5846 targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70;
5849 if (animation[animTarget].attack == reversal && animTarget != rabbittacklinganim) {
5850 targetyaw = victim->targetyaw;
5852 if (animTarget == rabbittacklinganim) {
5853 coords = victim->coords;
5856 skeleton.oldfree = skeleton.free;
5860 midterrain.x = terrain.size * terrain.scale / 2;
5861 midterrain.z = terrain.size * terrain.scale / 2;
5862 if (distsqflat(&coords, &midterrain) > (terrain.size * terrain.scale / 2 - viewdistance) * (terrain.size * terrain.scale / 2 - viewdistance)) {
5864 tempposit = coords - midterrain;
5866 Normalise(&tempposit);
5867 tempposit *= (terrain.size * terrain.scale / 2 - viewdistance);
5868 coords.x = tempposit.x + midterrain.x;
5869 coords.z = tempposit.z + midterrain.z;
5875 * inverse kinematics helper function
5877 void IKHelper(Person *p, float interp)
5879 XYZ point, newpoint, change, change2;
5880 float heightleft, heightright;
5882 // TODO: implement localToWorld and worldToLocal
5883 // but keep in mind it won't be the same math if player is ragdolled or something
5884 // - localToWorldStanding / worldToLocalStanding (or crouching or...?)
5885 // then comb through code for places where to use it
5887 // point = localToWorld(jointPos(leftfoot))
5888 point = DoRotation(p->jointPos(leftfoot), 0, p->yaw, 0) * p->scale + p->coords;
5889 // adjust height of foot
5890 heightleft = terrain.getHeight(point.x, point.z) + .04;
5891 point.y = heightleft;
5892 change = p->jointPos(leftankle) - p->jointPos(leftfoot);
5893 change2 = p->jointPos(leftknee) - p->jointPos(leftfoot);
5894 // jointPos(leftfoot) = interpolate(worldToLocal(point), jointPos(leftfoot), interp)
5895 p->jointPos(leftfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(leftfoot) * (1 - interp);
5896 // move ankle along with foot
5897 p->jointPos(leftankle) = p->jointPos(leftfoot) + change;
5898 // average knee pos between old and new pos
5899 p->jointPos(leftknee) = (p->jointPos(leftfoot) + change2) / 2 + (p->jointPos(leftknee)) / 2;
5901 // do same as above for right leg
5902 point = DoRotation(p->jointPos(rightfoot), 0, p->yaw, 0) * p->scale + p->coords;
5903 heightright = terrain.getHeight(point.x, point.z) + .04;
5904 point.y = heightright;
5905 change = p->jointPos(rightankle) - p->jointPos(rightfoot);
5906 change2 = p->jointPos(rightknee) - p->jointPos(rightfoot);
5907 p->jointPos(rightfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(rightfoot) * (1 - interp);
5908 p->jointPos(rightankle) = p->jointPos(rightfoot) + change;
5909 p->jointPos(rightknee) = (p->jointPos(rightfoot) + change2) / 2 + (p->jointPos(rightknee)) / 2;
5911 // fix up skeleton now that we've moved body parts?
5912 p->skeleton.DoConstraints(&p->coords, &p->scale);
5919 int Person::DrawSkeleton()
5921 int oldplayerdetail;
5922 if ((frustum.SphereInFrustum(coords.x, coords.y + scale * 3, coords.z, scale * 8) && distsq(&viewer, &coords) < viewdistance * viewdistance) || skeleton.free == 3) {
5923 if (onterrain && (isIdle() || isCrouch() || wasIdle() || wasCrouch()) && !skeleton.free) {
5933 glAlphaFunc(GL_GREATER, 0.0001);
5935 float terrainheight;
5939 if (!isnormal(tilt))
5941 if (!isnormal(tilt2))
5943 oldplayerdetail = playerdetail;
5945 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) {
5948 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 128 && detail == 1) {
5951 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) {
5956 if (playerdetail != oldplayerdetail) {
5958 normalsupdatedelay = 0;
5960 static float updatedelaychange;
5961 static float morphness;
5962 static float framemult;
5964 skeleton.FindForwards();
5965 if (howactive == typesittingwall) {
5966 skeleton.specialforward[1] = 0;
5967 skeleton.specialforward[1].z = 1;
5973 static int weaponattachmuscle;
5974 static int weaponrotatemuscle;
5975 static XYZ weaponpoint;
5976 static int start, endthing;
5977 if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
5978 if (!isSleeping() && !isSitting()) {
5979 // TODO: give these meaningful names
5980 const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard()
5981 || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim);
5982 const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard()
5983 || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim);
5985 if (onterrain && (cond1 && cond2) && !skeleton.free) {
5987 if (creature == wolftype)
5991 if (onterrain && (cond1 && !cond2) && !skeleton.free) {
5992 IKHelper(this, target);
5993 if (creature == wolftype)
5994 IKHelper(this, target);
5997 if (onterrain && (!cond1 && cond2) && !skeleton.free) {
5998 IKHelper(this, 1 - target);
5999 if (creature == wolftype)
6000 IKHelper(this, 1 - target);
6004 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()))
6007 targetheadyaw = -targetyaw;
6008 targetheadpitch = 0;
6009 if (animation[animTarget].attack == 3)
6010 targetheadyaw += 180;
6012 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6013 skeleton.drawmodel.vertex[i] = 0;
6014 skeleton.drawmodel.vertex[i].y = 999;
6016 for (i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
6017 skeleton.drawmodellow.vertex[i] = 0;
6018 skeleton.drawmodellow.vertex[i].y = 999;
6020 for (i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
6021 skeleton.drawmodelclothes.vertex[i] = 0;
6022 skeleton.drawmodelclothes.vertex[i].y = 999;
6024 for (int i = 0; i < skeleton.num_muscles; i++) {
6025 // convenience renames
6026 const int p1 = skeleton.muscles[i].parent1->label;
6027 const int p2 = skeleton.muscles[i].parent2->label;
6029 if ((skeleton.muscles[i].numvertices > 0 && playerdetail) || (skeleton.muscles[i].numverticeslow > 0 && !playerdetail)) {
6034 if (p1 == righthand || p2 == righthand) {
6035 morphness = righthandmorphness;
6036 start = righthandmorphstart;
6037 endthing = righthandmorphend;
6039 if (p1 == lefthand || p2 == lefthand) {
6040 morphness = lefthandmorphness;
6041 start = lefthandmorphstart;
6042 endthing = lefthandmorphend;
6044 if (p1 == head || p2 == head) {
6045 morphness = headmorphness;
6046 start = headmorphstart;
6047 endthing = headmorphend;
6049 if ((p1 == neck && p2 == abdomen) || (p2 == neck && p1 == abdomen)) {
6050 morphness = chestmorphness;
6051 start = chestmorphstart;
6052 endthing = chestmorphend;
6054 if ((p1 == groin && p2 == abdomen) || (p2 == groin && p1 == abdomen)) {
6055 morphness = tailmorphness;
6056 start = tailmorphstart;
6057 endthing = tailmorphend;
6060 skeleton.FindRotationMuscle(i, animTarget);
6061 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6062 glMatrixMode(GL_MODELVIEW);
6066 glRotatef(tilt2, 1, 0, 0);
6068 glRotatef(tilt, 0, 0, 1);
6071 glTranslatef(mid.x, mid.y, mid.z);
6073 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6074 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6076 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6077 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6079 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6080 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6082 if (playerdetail || skeleton.free == 3) {
6083 for (j = 0; j < skeleton.muscles[i].numvertices; j++) {
6084 XYZ &v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
6085 XYZ &v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
6086 glMatrixMode(GL_MODELVIEW);
6088 if (p1 == abdomen || p2 == abdomen)
6089 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionbody.x,
6090 (v0.y * (1 - morphness) + v1.y * morphness) * proportionbody.y,
6091 (v0.z * (1 - morphness) + v1.z * morphness) * proportionbody.z);
6092 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6093 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionarms.x,
6094 (v0.y * (1 - morphness) + v1.y * morphness) * proportionarms.y,
6095 (v0.z * (1 - morphness) + v1.z * morphness) * proportionarms.z);
6096 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6097 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionlegs.x,
6098 (v0.y * (1 - morphness) + v1.y * morphness) * proportionlegs.y,
6099 (v0.z * (1 - morphness) + v1.z * morphness) * proportionlegs.z);
6100 if (p1 == head || p2 == head)
6101 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionhead.x,
6102 (v0.y * (1 - morphness) + v1.y * morphness) * proportionhead.y,
6103 (v0.z * (1 - morphness) + v1.z * morphness) * proportionhead.z);
6104 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6105 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
6106 //if(!isnormal(scale))test=1;
6107 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale;
6108 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale;
6109 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z = M[14] * scale;
6114 if (!playerdetail || skeleton.free == 3) {
6115 for (j = 0; j < skeleton.muscles[i].numverticeslow; j++) {
6116 XYZ &v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
6117 glMatrixMode(GL_MODELVIEW);
6119 if (p1 == abdomen || p2 == abdomen)
6120 glTranslatef(v0.x * proportionbody.x,
6121 v0.y * proportionbody.y,
6122 v0.z * proportionbody.z);
6123 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6124 glTranslatef(v0.x * proportionarms.x,
6125 v0.y * proportionarms.y,
6126 v0.z * proportionarms.z);
6127 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6128 glTranslatef(v0.x * proportionlegs.x,
6129 v0.y * proportionlegs.y,
6130 v0.z * proportionlegs.z);
6131 if (p1 == head || p2 == head)
6132 glTranslatef(v0.x * proportionhead.x,
6133 v0.y * proportionhead.y,
6134 v0.z * proportionhead.z);
6136 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6137 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
6138 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y = M[13] * scale;
6139 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z = M[14] * scale;
6145 if (skeleton.clothes && skeleton.muscles[i].numverticesclothes > 0) {
6146 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6148 glMatrixMode(GL_MODELVIEW);
6152 glRotatef(tilt2, 1, 0, 0);
6154 glRotatef(tilt, 0, 0, 1);
6155 glTranslatef(mid.x, mid.y, mid.z);
6156 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6157 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6159 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6160 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6162 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6163 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6165 for (j = 0; j < skeleton.muscles[i].numverticesclothes; j++) {
6166 XYZ &v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
6167 glMatrixMode(GL_MODELVIEW);
6169 if (p1 == abdomen || p2 == abdomen)
6170 glTranslatef(v0.x * proportionbody.x,
6171 v0.y * proportionbody.y,
6172 v0.z * proportionbody.z);
6173 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6174 glTranslatef(v0.x * proportionarms.x,
6175 v0.y * proportionarms.y,
6176 v0.z * proportionarms.z);
6177 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6178 glTranslatef(v0.x * proportionlegs.x,
6179 v0.y * proportionlegs.y,
6180 v0.z * proportionlegs.z);
6181 if (p1 == head || p2 == head)
6182 glTranslatef(v0.x * proportionhead.x,
6183 v0.y * proportionhead.y,
6184 v0.z * proportionhead.z);
6185 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6186 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
6187 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
6188 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z = M[14] * scale;
6193 updatedelay = 1 + (float)(Random() % 100) / 1000;
6195 if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) {
6196 normalsupdatedelay = 1;
6197 if (playerdetail || skeleton.free == 3)
6198 skeleton.drawmodel.CalculateNormals(0);
6199 if (!playerdetail || skeleton.free == 3)
6200 skeleton.drawmodellow.CalculateNormals(0);
6201 if (skeleton.clothes)
6202 skeleton.drawmodelclothes.CalculateNormals(0);
6204 if (playerdetail || skeleton.free == 3)
6205 skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
6206 if (!playerdetail || skeleton.free == 3)
6207 skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
6208 if (skeleton.clothes) {
6209 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6214 updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1);
6215 if (updatedelaychange > -realmultiplier * 30)
6216 updatedelaychange = -realmultiplier * 30;
6217 if (updatedelaychange > -framemult * 4)
6218 updatedelaychange = -framemult * 4;
6219 if (skeleton.free == 1)
6220 updatedelaychange *= 6;
6222 updatedelaychange *= 8;
6223 updatedelay += updatedelaychange;
6225 glMatrixMode(GL_MODELVIEW);
6228 glTranslatef(coords.x, coords.y - .02, coords.z);
6230 glTranslatef(coords.x, coords.y - .02, coords.z);
6232 glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
6234 glRotatef(yaw, 0, 1, 0);
6237 glColor4f(.4, 1, .4, 1);
6238 glDisable(GL_LIGHTING);
6239 glDisable(GL_TEXTURE_2D);
6242 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6243 XYZ &v0 = skeleton.drawmodel.vertex[i];
6244 glVertex3f(v0.x, v0.y, v0.z);
6250 for (i = 0; i < skeleton.drawmodel.TriangleNum; i++) {
6251 XYZ &v0 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]];
6252 XYZ &v1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]];
6253 XYZ &v2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]];
6254 glVertex3f(v0.x, v0.y, v0.z);
6255 glVertex3f(v1.x, v1.y, v1.z);
6256 glVertex3f(v1.x, v1.y, v1.z);
6257 glVertex3f(v2.x, v2.y, v2.z);
6258 glVertex3f(v2.x, v2.y, v2.z);
6259 glVertex3f(v0.x, v0.y, v0.z);
6265 terrainlight = terrain.getLighting(coords.x, coords.z);
6266 distance = distsq(&viewer, &coords);
6267 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
6271 terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1;
6272 if (terrainheight < 1)
6274 if (terrainheight > 1.7)
6275 terrainheight = 1.7;
6278 glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance);
6279 glDisable(GL_BLEND);
6280 glAlphaFunc(GL_GREATER, 0.0001);
6281 glEnable(GL_TEXTURE_2D);
6283 glDisable(GL_TEXTURE_2D);
6284 glColor4f(.7, .35, 0, .5);
6286 glEnable(GL_LIGHTING);
6289 if (tutoriallevel && id != 0) {
6290 //glDisable(GL_TEXTURE_2D);
6291 glColor4f(.7, .7, .7, 0.6);
6293 glEnable(GL_LIGHTING);
6295 if (canattack && cananger)
6296 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6297 glDisable(GL_TEXTURE_2D);
6298 glColor4f(1, 0, 0, 0.8);
6300 glMatrixMode(GL_TEXTURE);
6302 glTranslatef(0, -smoketex, 0);
6303 glTranslatef(-smoketex, 0, 0);
6307 if ((tutoriallevel && id != 0))
6308 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6310 skeleton.drawmodel.draw();
6313 if (!playerdetail) {
6314 if ((tutoriallevel && id != 0))
6315 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6317 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6320 if (!(animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed))
6321 if (tutoriallevel && id != 0) {
6323 glMatrixMode(GL_MODELVIEW);
6324 glEnable(GL_TEXTURE_2D);
6325 glColor4f(.7, .7, .7, 0.6);
6327 glEnable(GL_LIGHTING);
6329 if (canattack && cananger)
6330 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6331 glDisable(GL_TEXTURE_2D);
6332 glColor4f(1, 0, 0, 0.8);
6334 glMatrixMode(GL_TEXTURE);
6336 glTranslatef(0, -smoketex * .6, 0);
6337 glTranslatef(smoketex * .6, 0, 0);
6340 if ((tutoriallevel && id != 0))
6341 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6343 skeleton.drawmodel.draw();
6346 if (!playerdetail) {
6347 if ((tutoriallevel && id != 0))
6348 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6350 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6355 if (tutoriallevel && id != 0) {
6357 glMatrixMode(GL_MODELVIEW);
6358 glEnable(GL_TEXTURE_2D);
6360 if (skeleton.clothes) {
6364 skeleton.drawmodelclothes.draw();
6366 skeleton.drawmodelclothes.drawimmediate();
6372 if (num_weapons > 0) {
6373 for (k = 0; k < num_weapons; k++) {
6375 if (weaponactive == k) {
6376 if (weapons[i].getType() != staff) {
6377 for (j = 0; j < skeleton.num_muscles; j++) {
6378 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6379 weaponattachmuscle = j;
6382 for (j = 0; j < skeleton.num_muscles; j++) {
6383 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) {
6384 weaponrotatemuscle = j;
6387 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6388 if (creature == wolftype)
6389 weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3);
6391 if (weapons[i].getType() == staff) {
6392 for (j = 0; j < skeleton.num_muscles; j++) {
6393 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6394 weaponattachmuscle = j;
6397 for (j = 0; j < skeleton.num_muscles; j++) {
6398 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) {
6399 weaponrotatemuscle = j;
6402 //weaponpoint=jointPos(rightwrist);
6403 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6404 //weaponpoint+=skeleton.specialforward[1]*.1+(jointPos(rightwrist)-jointPos(rightelbow));
6405 XYZ tempnormthing, vec1, vec2;
6406 vec1 = (jointPos(rightwrist) - jointPos(rightelbow));
6407 vec2 = (jointPos(rightwrist) - jointPos(rightshoulder));
6408 CrossProduct(&vec1, &vec2, &tempnormthing);
6409 Normalise(&tempnormthing);
6410 if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim)
6411 weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow));
6414 if (weaponactive != k && weaponstuck != k) {
6415 if (weapons[i].getType() == knife)
6416 weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35;
6417 if (weapons[i].getType() == sword)
6418 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6419 if (weapons[i].getType() == staff)
6420 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6421 for (j = 0; j < skeleton.num_muscles; j++) {
6422 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) {
6423 weaponrotatemuscle = j;
6427 if (weaponstuck == k) {
6428 if (weaponstuckwhere == 0)
6429 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8;
6431 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
6432 for (j = 0; j < skeleton.num_muscles; j++) {
6433 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) {
6434 weaponrotatemuscle = j;
6438 if (skeleton.free) {
6439 weapons[i].position = weaponpoint * scale + coords;
6440 weapons[i].bigrotation = 0;
6441 weapons[i].bigtilt = 0;
6442 weapons[i].bigtilt2 = 0;
6444 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;
6445 weapons[i].bigrotation = yaw;
6446 weapons[i].bigtilt = tilt;
6447 weapons[i].bigtilt2 = tilt2;
6449 weapons[i].rotation1 = skeleton.muscles[weaponrotatemuscle].lastrotate1;
6450 weapons[i].rotation2 = skeleton.muscles[weaponrotatemuscle].lastrotate2;
6451 weapons[i].rotation3 = skeleton.muscles[weaponrotatemuscle].lastrotate3;
6452 if (weaponactive == k) {
6453 if (weapons[i].getType() == knife) {
6454 weapons[i].smallrotation = 180;
6455 weapons[i].smallrotation2 = 0;
6456 if (isCrouch() || wasCrouch()) {
6457 weapons[i].smallrotation2 = 20;
6459 if (animTarget == hurtidleanim) {
6460 weapons[i].smallrotation2 = 50;
6462 if ((animCurrent == crouchstabanim && animTarget == crouchstabanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
6463 XYZ temppoint1, temppoint2, tempforward;
6466 temppoint1 = jointPos(righthand);
6467 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6468 distance = findDistance(&temppoint1, &temppoint2);
6469 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6470 weapons[i].rotation2 *= 360 / 6.28;
6473 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6474 weapons[i].rotation1 *= 360 / 6.28;
6475 weapons[i].rotation3 = 0;
6476 weapons[i].smallrotation = -90;
6477 weapons[i].smallrotation2 = 0;
6478 if (temppoint1.x > temppoint2.x)
6479 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6481 if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) {
6482 XYZ temppoint1, temppoint2, tempforward;
6485 temppoint1 = jointPos(righthand);
6486 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6487 distance = findDistance(&temppoint1, &temppoint2);
6488 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6489 weapons[i].rotation2 *= 360 / 6.28;
6492 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6493 weapons[i].rotation1 *= 360 / 6.28;
6494 weapons[i].rotation3 = 0;
6495 weapons[i].smallrotation = 90;
6496 weapons[i].smallrotation2 = 0;
6497 if (temppoint1.x > temppoint2.x)
6498 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6500 if (animTarget == knifethrowanim) {
6501 weapons[i].smallrotation = 90;
6502 //weapons[i].smallrotation2=-90;
6503 weapons[i].smallrotation2 = 0;
6504 weapons[i].rotation1 = 0;
6505 weapons[i].rotation2 = 0;
6506 weapons[i].rotation3 = 0;
6508 if (animTarget == knifesneakattackanim && frameTarget < 5) {
6509 weapons[i].smallrotation = -90;
6510 weapons[i].rotation1 = 0;
6511 weapons[i].rotation2 = 0;
6512 weapons[i].rotation3 = 0;
6515 if (weapons[i].getType() == sword) {
6516 weapons[i].smallrotation = 0;
6517 weapons[i].smallrotation2 = 0;
6518 if (animTarget == knifethrowanim) {
6519 weapons[i].smallrotation = -90;
6520 weapons[i].smallrotation2 = 0;
6521 weapons[i].rotation1 = 0;
6522 weapons[i].rotation2 = 0;
6523 weapons[i].rotation3 = 0;
6525 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)) {
6526 XYZ temppoint1, temppoint2, tempforward;
6529 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6530 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6531 distance = findDistance(&temppoint1, &temppoint2);
6532 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6533 weapons[i].rotation2 *= 360 / 6.28;
6536 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6537 weapons[i].rotation1 *= 360 / 6.28;
6538 weapons[i].rotation3 = 0;
6539 weapons[i].smallrotation = 90;
6540 weapons[i].smallrotation2 = 0;
6541 if (temppoint1.x > temppoint2.x)
6542 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6545 if (weapons[i].getType() == staff) {
6546 weapons[i].smallrotation = 100;
6547 weapons[i].smallrotation2 = 0;
6548 if ((animTarget == staffhitanim && animCurrent == staffhitanim) || (animTarget == staffhitreversedanim && animCurrent == staffhitreversedanim) || (animTarget == staffspinhitreversedanim && animCurrent == staffspinhitreversedanim) || (animTarget == staffgroundsmashanim && animCurrent == staffgroundsmashanim) || (animTarget == staffspinhitanim && animCurrent == staffspinhitanim)) {
6549 XYZ temppoint1, temppoint2, tempforward;
6552 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6553 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6554 distance = findDistance(&temppoint1, &temppoint2);
6555 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6556 weapons[i].rotation2 *= 360 / 6.28;
6559 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6560 weapons[i].rotation1 *= 360 / 6.28;
6561 weapons[i].rotation3 = 0;
6562 weapons[i].smallrotation = 90;
6563 weapons[i].smallrotation2 = 0;
6564 if (temppoint1.x > temppoint2.x)
6565 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6569 if (weaponactive != k && weaponstuck != k) {
6570 if (weapons[i].getType() == knife) {
6571 weapons[i].smallrotation = -70;
6572 weapons[i].smallrotation2 = 10;
6574 if (weapons[i].getType() == sword) {
6575 weapons[i].smallrotation = -100;
6576 weapons[i].smallrotation2 = -8;
6578 if (weapons[i].getType() == staff) {
6579 weapons[i].smallrotation = -100;
6580 weapons[i].smallrotation2 = -8;
6583 if (weaponstuck == k) {
6584 if (weaponstuckwhere == 0)
6585 weapons[i].smallrotation = 180;
6587 weapons[i].smallrotation = 0;
6588 weapons[i].smallrotation2 = 10;
6597 if (animation[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isFlip() || isWallJump())
6599 if (animCurrent != animTarget)
6601 //if(id==0)calcrot=1;
6602 if (skeleton.free == 2)
6611 int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6614 static float distance;
6615 static float olddistance;
6616 static int intersecting;
6617 static int firstintersecting;
6620 static XYZ start, end;
6621 static float slopethreshold = -.4;
6623 firstintersecting = -1;
6627 if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius)
6630 *p1 = DoRotation(*p1, 0, -*rotate, 0);
6631 for (i = 0; i < 4; i++) {
6632 for (j = 0; j < model->TriangleNum; j++) {
6633 if (model->facenormals[j].y <= slopethreshold) {
6635 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)));
6636 if (distance < radius) {
6637 point = *p1 - model->facenormals[j] * distance;
6638 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]]))
6641 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6642 &model->vertex[model->Triangles[j].vertex[1]],
6645 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6646 &model->vertex[model->Triangles[j].vertex[2]],
6649 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6650 &model->vertex[model->Triangles[j].vertex[2]],
6653 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6657 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)) {
6658 p1->y = point.y + radius;
6659 if ((animTarget == jumpdownanim || isFlip())) {
6660 if (isFlip() && (frameTarget < 5 || animation[animTarget].label[frameTarget] == 7 || animation[animTarget].label[frameTarget] == 4))
6663 if (animTarget == jumpupanim) {
6665 animTarget = getIdle();
6672 pause_sound(whooshsound);
6673 OPENAL_SetVolume(channels[whooshsound], 0);
6676 if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) {
6679 animTarget = getLanding();
6680 emit_sound_at(landsound, coords, 128.);
6683 envsound[numenvsounds] = coords;
6684 envsoundvol[numenvsounds] = 16;
6685 envsoundlife[numenvsounds] = .4;
6693 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6694 olddistance = distance;
6695 firstintersecting = j;
6700 for (j = 0; j < model->TriangleNum; j++) {
6701 if (model->facenormals[j].y > slopethreshold) {
6704 start.y -= radius / 4;
6705 XYZ &v0 = model->vertex[model->Triangles[j].vertex[0]];
6706 XYZ &v1 = model->vertex[model->Triangles[j].vertex[1]];
6707 XYZ &v2 = model->vertex[model->Triangles[j].vertex[2]];
6708 distance = abs((model->facenormals[j].x * start.x)
6709 + (model->facenormals[j].y * start.y)
6710 + (model->facenormals[j].z * start.z)
6711 - ((model->facenormals[j].x * v0.x)
6712 + (model->facenormals[j].y * v0.y)
6713 + (model->facenormals[j].z * v0.z)));
6714 if (distance < radius * .5) {
6715 point = start - model->facenormals[j] * distance;
6716 if (PointInTriangle( &point, model->facenormals[j], &v0, &v1, &v2))
6719 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
6721 intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6723 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6725 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6726 if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
6728 velocity -= DoRotation(model->facenormals[j], 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->facenormals[j], 0, *rotate, 0))); //(distance-radius*.5)/multiplier;
6729 if (findLengthfast(&start) < findLengthfast(&velocity))
6732 *p1 += model->facenormals[j] * (distance - radius * .5);
6735 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6736 olddistance = distance;
6737 firstintersecting = j;
6744 *p = DoRotation(*p, 0, *rotate, 0);
6747 *p1 = DoRotation(*p1, 0, *rotate, 0);
6749 return firstintersecting;