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 modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 Lugaru 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. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
20 /**> HEADER FILES <**/
22 #include "openal_wrapper.h"
23 #include "Animation.h"
28 extern float multiplier;
29 extern Terrain terrain;
31 extern int environment;
33 extern FRUSTUM frustum;
35 extern float realmultiplier;
37 extern float slomodelay;
38 extern bool cellophane;
39 extern float texdetail;
40 extern float realtexdetail;
41 extern GLubyte bloodText[512 * 512 * 3];
42 extern GLubyte wolfbloodText[512 * 512 * 3];
43 extern int bloodtoggle;
44 extern Objects objects;
46 extern bool autoslomo;
47 extern float camerashake;
49 extern float viewdistance;
50 extern float blackout;
51 extern int difficulty;
53 extern float fadestart;
55 extern bool winfreeze;
56 extern float flashamount, flashr, flashg, flashb;
57 extern int flashdelay;
58 extern bool showpoints;
59 extern bool immediate;
61 extern bool tilt2weird;
62 extern bool tiltweird;
64 extern bool proportionweird;
65 extern bool vertexweird[6];
66 extern XYZ envsound[30];
67 extern float envsoundvol[30];
68 extern float envsoundlife[30];
69 extern int numenvsounds;
70 extern int tutoriallevel;
71 extern float smoketex;
72 extern int tutorialstage;
73 extern bool reversaltrain;
74 extern bool canattack;
76 extern float damagedealt;
78 extern float hostiletime;
80 extern int indialogue;
82 extern bool gamestarted;
84 std::vector<std::shared_ptr<Person>> Person::players(1, std::shared_ptr<Person>(new Person()));
89 * GameTick/doPlayerCollisions
91 void Person::CheckKick()
94 && (animTarget == rabbitkickanim
96 && victim != this->shared_from_this()
98 && animCurrent == rabbitkickanim)
99 && distsq(&coords, &victim->coords) < 1.2
100 && !victim->skeleton.free))
103 if (animation[victim->animTarget].height != lowheight) {
104 float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
105 XYZ relative = velocity;
107 Normalise(&relative);
111 if (tutoriallevel != 1)
112 emit_sound_at(heavyimpactsound, victim->coords);
114 for (int i = 0; i < victim->skeleton.num_joints; i++) {
115 victim->skeleton.joints[i].velocity += relative * 120 * damagemult;
118 victim->DoDamage(100 * damagemult / victim->protectionhigh);
124 animTarget = backflipanim;
126 velocity = facing * -10;
130 resume_stream(whooshsound);
132 award_bonus(id, cannon);
133 } else if (victim->isCrouch()) {
134 animTarget = rabbitkickreversedanim;
135 animCurrent = rabbitkickreversedanim;
136 victim->animCurrent = rabbitkickreversalanim;
137 victim->animTarget = rabbitkickreversalanim;
143 victim->oldcoords = victim->coords;
144 coords = victim->coords;
145 victim->targetyaw = targetyaw;
146 victim->victim = this->shared_from_this();
153 * GameTick/doPlayerCollisions - spread fire between players
154 * GameTick/doDebugKeys - press f to ignite
155 * Person::DoStuff - spread fire from lit campfires and bushes
157 void Person::CatchFire()
159 XYZ flatfacing, flatvelocity;
161 for (int i = 0; i < 10; i++) {
162 howmany = abs(Random() % (skeleton.num_joints));
164 flatvelocity = velocity;
166 flatvelocity = skeleton.joints[howmany].velocity;
168 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
170 flatfacing = skeleton.joints[howmany].position * scale + coords;
171 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
176 emit_sound_at(firestartsound, coords);
178 emit_stream_at(stream_firesound, coords);
186 * idle animation for this creature (depending on status)
188 int Person::getIdle()
190 if (indialogue != -1 && howactive == typeactive && creature == rabbittype)
192 if (hasvictim && (victim != this->shared_from_this())/*||(id==0&&attackkeydown)*/)
193 if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype &&
194 victim->aitype != searchtype && aitype != passivetype && aitype != searchtype &&
195 victim->id < Person::players.size())) {
196 if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) {
197 if (creature == rabbittype)
198 return fightidleanim;
199 if (creature == wolftype)
202 if (aitype == playercontrolled && stunned <= 0 && weaponactive != -1) {
203 if (weapons[weaponids[weaponactive]].getType() == knife)
204 return knifefightidleanim;
205 if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1)
206 return swordfightidlebothanim;
207 if (weapons[weaponids[weaponactive]].getType() == sword)
208 return swordfightidleanim;
209 if (weapons[weaponids[weaponactive]].getType() == staff)
210 return swordfightidleanim;
212 if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause)
213 return fightsidestep;
215 if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype)
217 if (howactive == typesitting) return sitanim;
218 if (howactive == typesittingwall) return sitwallanim;
219 if (howactive == typesleeping) return sleepanim;
220 if (howactive == typedead1) return dead1anim;
221 if (howactive == typedead2) return dead2anim;
222 if (howactive == typedead3) return dead3anim;
223 if (howactive == typedead4) return dead4anim;
224 if (creature == rabbittype) return bounceidleanim;
225 if (creature == wolftype) return wolfidle;
230 * crouch animation for this creature
232 int Person::getCrouch()
234 if (creature == rabbittype)
236 if (creature == wolftype)
237 return wolfcrouchanim;
242 * running animation for this creature (can be upright or all fours)
246 if (creature == rabbittype && (!superruntoggle || weaponactive != -1))
248 if (creature == wolftype && (!superruntoggle))
251 if (creature == rabbittype && (superruntoggle && weaponactive == -1))
252 return rabbitrunninganim;
253 if (creature == wolftype && (superruntoggle))
254 return wolfrunninganim;
260 int Person::getStop()
262 if (creature == rabbittype)
264 if (creature == wolftype)
271 int Person::getLanding()
273 if (creature == rabbittype)
275 if (creature == wolftype)
282 int Person::getLandhard()
284 if (creature == rabbittype)
286 if (creature == wolftype)
287 return wolflandhardanim;
294 * Person::DoAnimations
297 SolidHitBonus(int playerid)
299 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
300 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
302 award_bonus(playerid, solidhit);
306 * spawns blood effects
308 void Person::DoBlood(float howmuch, int which)
310 // FIXME: should abstract out inputs
311 static int bleedxint, bleedyint;
313 //if(howmuch&&id==0)blooddimamount=1;
314 if (bloodtoggle && tutoriallevel != 1) {
315 if (bleeding <= 0 && spurt) {
317 for (int i = 0; i < 3; i++) {
318 // emit blood particles
320 if (!skeleton.free) {
322 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
325 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
328 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
330 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
332 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
333 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
335 if (!skeleton.free) {
336 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
337 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
340 if (Random() % 2 == 0) // 50% chance
341 for (int i = 0; i < 3; i++) {
342 if (Random() % 2 != 0) {
343 // emit teeth particles
346 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
347 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
350 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
351 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
355 Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
357 Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
359 Sprite::setLastSpriteSpecial(3); // sets it to teeth
364 // FIXME: manipulating attributes
365 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
368 if (creature == rabbittype)
369 while (bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
370 bleedxint = abs(Random() % 512);
371 bleedyint = abs(Random() % 512);
373 if (creature == wolftype)
374 while (wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
375 bleedxint = abs(Random() % 512);
376 bleedyint = abs(Random() % 512);
380 bleedy /= realtexdetail;
381 bleedx /= realtexdetail;
382 direction = abs(Random() % 2) * 2 - 1;
391 * spawns big blood effects and ???
392 * modifies character's skin texture
394 void Person::DoBloodBig(float howmuch, int which)
396 static int bleedxint, bleedyint, i, j;
398 if (howmuch && id == 0)
401 if (tutoriallevel != 1 || id == 0)
402 if (aitype != playercontrolled && howmuch > 0) {
406 // FIXME: seems to be spawning sounds by manipulating attributes... MESSY!
407 if (creature == wolftype) {
408 int i = abs(Random() % 2);
410 whichsound = snarlsound;
412 whichsound = snarl2sound;
413 envsound[numenvsounds] = coords;
414 envsoundvol[numenvsounds] = 16;
415 envsoundlife[numenvsounds] = .4;
418 if (creature == rabbittype) {
419 int i = abs(Random() % 2);
421 whichsound = rabbitpainsound;
422 if (i == 1 && howmuch >= 2)
423 whichsound = rabbitpain1sound;
424 envsound[numenvsounds] = coords;
425 envsoundvol[numenvsounds] = 16;
426 envsoundlife[numenvsounds] = .4;
428 //if(i==2)whichsound=rabbitpain2sound;
431 if (whichsound != -1)
432 emit_sound_at(whichsound, coords);
435 if (id == 0 && howmuch > 0) {
436 // FIXME: manipulating attributes
444 if (bloodtoggle && decals && tutoriallevel != 1) {
445 if (bleeding <= 0 && spurt) {
447 for (int i = 0; i < 3; i++) {
448 // emit blood particles
449 // FIXME: copypaste from above
451 if (!skeleton.free) {
453 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
456 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
459 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
461 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
463 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
464 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
466 if (!skeleton.free) {
467 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
468 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
473 // weird texture manipulation code follows.
474 // looks like this is painting blood onto the character's skin texture
475 // FIXME: surely there's a better way
477 int offsetx = 0, offsety = 0;
479 offsety = Random() % 40;
480 offsetx = abs(Random() % 60);
482 if (which == 190 || which == 185) {
483 offsety = Random() % 40;
484 offsetx = abs(Random() % 100) - 20;
487 offsety = Random() % 10;
488 offsetx = Random() % 10;
491 offsety = Random() % 20;
492 offsetx = Random() % 20;
494 if (which == 220 || which == 215) {
504 if (creature == rabbittype)
505 for (i = 0; i < 512; i++) {
506 for (j = 0; j < 512; j++) {
507 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
508 if (i < startx) startx = i;
509 if (j < starty) starty = j;
510 if (i > endx) endx = i;
511 if (j > endy) endy = j;
515 if (creature == wolftype)
516 for (i = 0; i < 512; i++) {
517 for (j = 0; j < 512; j++) {
518 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
519 if (i < startx) startx = i;
520 if (j < starty) starty = j;
521 if (i > endx) endx = i;
522 if (j > endy) endy = j;
532 if (startx < 0) startx = 0;
533 if (starty < 0) starty = 0;
534 if (endx > 512 - 1) endx = 512 - 1;
535 if (endy > 512 - 1) endy = 512 - 1;
536 if (endx < startx) endx = startx;
537 if (endy < starty) endy = starty;
539 startx /= realtexdetail;
540 starty /= realtexdetail;
541 endx /= realtexdetail;
542 endy /= realtexdetail;
544 int texdetailint = realtexdetail;
546 if (creature == rabbittype)
547 for (i = startx; i < endx; i++) {
548 for (j = starty; j < endy; j++) {
549 if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
550 color = Random() % 85 + 170;
551 where = i * skeleton.skinsize * 3 + j * 3;
552 if (skeleton.skinText[where + 0] > color / 2)
553 skeleton.skinText[where + 0] = color / 2;
554 skeleton.skinText[where + 1] = 0;
555 skeleton.skinText[where + 2] = 0;
559 if (creature == wolftype)
560 for (i = startx; i < endx; i++) {
561 for (j = starty; j < endy; j++) {
562 if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
563 color = Random() % 85 + 170;
564 where = i * skeleton.skinsize * 3 + j * 3;
565 if (skeleton.skinText[where + 0] > color / 2)
566 skeleton.skinText[where + 0] = color / 2;
567 skeleton.skinText[where + 1] = 0;
568 skeleton.skinText[where + 2] = 0;
572 skeleton.drawmodel.textureptr.bind();
577 if (creature == rabbittype)
578 while (bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || bloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
579 bleedxint = abs(Random() % 512);
580 bleedyint = abs(Random() % 512);
582 if (creature == wolftype)
583 while (wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] > which + 4 || wolfbloodText[bleedxint * 512 * 3 + bleedyint * 3 + 0] < which - 4 || bleedxint < 10 || bleedyint < 10 || bleedxint > 500 || bleedyint > 500) {
584 bleedxint = abs(Random() % 512);
585 bleedyint = abs(Random() % 512);
587 bleedy = bleedxint + offsetx;
588 bleedx = bleedyint + offsety;
589 bleedy /= realtexdetail;
590 bleedx /= realtexdetail;
595 if (bleedx > skeleton.skinsize - 1)
596 bleedx = skeleton.skinsize - 1;
597 if (bleedy > skeleton.skinsize - 1)
598 bleedy = skeleton.skinsize - 1;
599 direction = abs(Random() % 2) * 2 - 1;
602 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
603 deathbleeding += bleeding;
604 bloodloss += bleeding * 3;
606 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
607 if (abs(Random() % 2) == 0) {
608 aitype = gethelptype;
611 aitype = attacktypecutoff;
619 * similar to DoBloodBig
621 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
625 static XYZ startpoint, endpoint, colpoint, movepoint;
626 static float rotationpoint;
628 static XYZ p1, p2, p3, p0;
632 float coordsx, coordsy;
635 if (bloodtoggle && decals && tutoriallevel != 1) {
638 where = DoRotation(where, 0, -yaw, 0);
646 // ray testing for a tri in the character model
647 whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
648 if (whichtri != -1) {
649 // low level geometry math
651 p1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
652 p2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
653 p3 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
655 CrossProduct(p2-p1,p3-p1,&N);
656 CrossProduct(p0-p1,p3-p1,&temp);
657 s = dotproduct(&temp,&N)/findLength(&N);
658 CrossProduct(p2-p1,p1-p0,&temp);
659 t = dotproduct(&temp,&N)/findLength(&N);
662 bary.x = distsq(&p0, &p1);
663 bary.y = distsq(&p0, &p2);
664 bary.z = distsq(&p0, &p3);
666 total = bary.x + bary.y + bary.z;
675 total = bary.x + bary.y + bary.z;
681 gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0];
682 gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1];
683 gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2];
684 gyy.x = skeleton.drawmodel.Triangles[whichtri].gy[0];
685 gyy.y = skeleton.drawmodel.Triangles[whichtri].gy[1];
686 gyy.z = skeleton.drawmodel.Triangles[whichtri].gy[2];
687 coordsx = skeleton.drawmodel.Triangles[whichtri].gx[0] * bary.x + skeleton.drawmodel.Triangles[whichtri].gx[1] * bary.y + skeleton.drawmodel.Triangles[whichtri].gx[2] * bary.z;
688 coordsy = skeleton.drawmodel.Triangles[whichtri].gy[0] * bary.x + skeleton.drawmodel.Triangles[whichtri].gy[1] * bary.y + skeleton.drawmodel.Triangles[whichtri].gy[2] * bary.z;
690 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
691 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
693 if (bleeding <= 0 && spurt) {
695 for (int i = 0; i < 3; i++) {
696 // emit blood particles
697 // FIXME: more copypaste code
699 if (!skeleton.free) {
701 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
704 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
707 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
709 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
711 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
712 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
714 if (!skeleton.free) {
715 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
716 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
721 // texture manipulation follows
723 int offsetx = 0, offsety = 0;
726 offsetx=abs(Random()%120);
728 if(which==220||which==215){
730 offsetx=abs(Random()%80);
733 offsetx = (1 + coordsy) * 512 - 291;
734 offsety = coordsx * 512 - 437;
741 if (creature == rabbittype)
742 for (i = 0; i < 512; i++) {
743 for (j = 0; j < 512; j++) {
744 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
745 if (i < startx) startx = i;
746 if (j < starty) starty = j;
747 if (i > endx) endx = i;
748 if (j > endy) endy = j;
752 if (creature == wolftype)
753 for (i = 0; i < 512; i++) {
754 for (j = 0; j < 512; j++) {
755 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
756 if (i < startx) startx = i;
757 if (j < starty) starty = j;
758 if (i > endx) endx = i;
759 if (j > endy) endy = j;
768 if (startx < 0) startx = 0;
769 if (starty < 0) starty = 0;
770 if (endx > 512 - 1) endx = 512 - 1;
771 if (endy > 512 - 1) endy = 512 - 1;
772 if (endx < startx) endx = startx;
773 if (endy < starty) endy = starty;
775 startx /= realtexdetail;
776 starty /= realtexdetail;
777 endx /= realtexdetail;
778 endy /= realtexdetail;
780 int texdetailint = realtexdetail;
782 if (creature == rabbittype)
783 for (i = startx; i < endx; i++) {
784 for (j = starty; j < endy; j++) {
785 if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
786 color = Random() % 85 + 170;
787 where = i * skeleton.skinsize * 3 + j * 3;
788 if (skeleton.skinText[where + 0] > color / 2)
789 skeleton.skinText[where + 0] = color / 2;
790 skeleton.skinText[where + 1] = 0;
791 skeleton.skinText[where + 2] = 0;
792 } else if (bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= 160 + 4 && bloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= 160 - 4) {
793 color = Random() % 85 + 170;
794 where = i * skeleton.skinsize * 3 + j * 3;
795 if (skeleton.skinText[where + 0] > color / 2)
796 skeleton.skinText[where + 0] = color / 2;
797 skeleton.skinText[where + 1] = 0;
798 skeleton.skinText[where + 2] = 0;
802 if (creature == wolftype)
803 for (i = startx; i < endx; i++) {
804 for (j = starty; j < endy; j++) {
805 if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= which + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= which - 4) {
806 color = Random() % 85 + 170;
807 where = i * skeleton.skinsize * 3 + j * 3;
808 if (skeleton.skinText[where + 0] > color / 2)
809 skeleton.skinText[where + 0] = color / 2;
810 skeleton.skinText[where + 1] = 0;
811 skeleton.skinText[where + 2] = 0;
812 } else if (wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] <= 160 + 4 && wolfbloodText[(i * texdetailint - offsetx) * 512 * 3 + (j * texdetailint - offsety) * 3 + 0] >= 160 - 4) {
813 color = Random() % 85 + 170;
814 where = i * skeleton.skinsize * 3 + j * 3;
815 if (skeleton.skinText[where + 0] > color / 2)
816 skeleton.skinText[where + 0] = color / 2;
817 skeleton.skinText[where + 1] = 0;
818 skeleton.skinText[where + 2] = 0;
822 skeleton.drawmodel.textureptr.bind();
825 bleedy = (1 + coordsy) * 512;
826 bleedx = coordsx * 512;
827 bleedy /= realtexdetail;
828 bleedx /= realtexdetail;
833 if (bleedx > skeleton.skinsize - 1)
834 bleedx = skeleton.skinsize - 1;
835 if (bleedy > skeleton.skinsize - 1)
836 bleedy = skeleton.skinsize - 1;
837 direction = abs(Random() % 2) * 2 - 1;
842 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
843 deathbleeding += bleeding;
844 bloodloss += bleeding * 3;
846 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
847 if (abs(Random() % 2) == 0) {
848 aitype = gethelptype;
851 aitype = attacktypecutoff;
862 * guessing this performs a reversal
864 void Person::Reverse()
866 if (!((victim->aitype == playercontrolled
868 || staggerdelay <= 0)
869 && victim->animTarget != jumpupanim
870 && victim->animTarget != jumpdownanim
871 && (tutoriallevel != 1 || cananger)
875 if (normaldotproduct (victim->facing, victim->coords - coords) > 0
876 && (victim->id != 0 || difficulty >= 2)
877 && (creature != wolftype || victim->creature == wolftype))
880 if (animTarget == sweepanim) {
881 animTarget = sweepreversedanim;
882 animCurrent = sweepreversedanim;
883 victim->animCurrent = sweepreversalanim;
884 victim->animTarget = sweepreversalanim;
886 if (animTarget == spinkickanim) {
887 animTarget = spinkickreversedanim;
888 animCurrent = spinkickreversedanim;
889 victim->animCurrent = spinkickreversalanim;
890 victim->animTarget = spinkickreversalanim;
892 if (animTarget == upunchanim || animTarget == rabbittacklinganim) {
893 if (animTarget == rabbittacklinganim) {
896 victim->frameCurrent = 6;
897 victim->frameTarget = 7;
899 animTarget = upunchreversedanim;
900 animCurrent = upunchreversedanim;
901 victim->animCurrent = upunchreversalanim;
902 victim->animTarget = upunchreversalanim;
904 if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
905 if (victim->weaponactive != -1) {
906 victim->throwtogglekeydown = 1;
907 weapons[victim->weaponids[0]].owner = -1;
908 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
909 if (weapons[victim->weaponids[0]].velocity.x == 0)
910 weapons[victim->weaponids[0]].velocity.x = .1;
911 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
912 weapons[victim->weaponids[0]].missed = 1;
913 weapons[victim->weaponids[0]].freetime = 0;
914 weapons[victim->weaponids[0]].firstfree = 1;
915 weapons[victim->weaponids[0]].physics = 1;
916 victim->num_weapons--;
917 if (victim->num_weapons) {
918 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
919 if (victim->weaponstuck == victim->num_weapons)
920 victim->weaponstuck = 0;
923 victim->weaponactive = -1;
924 for (unsigned j = 0; j < Person::players.size(); j++) {
925 Person::players[j]->wentforweapon = 0;
929 animTarget = staffhitreversedanim;
930 animCurrent = staffhitreversedanim;
931 victim->animCurrent = staffhitreversalanim;
932 victim->animTarget = staffhitreversalanim;
934 if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
935 if (victim->weaponactive != -1) {
936 victim->throwtogglekeydown = 1;
937 weapons[victim->weaponids[0]].owner = -1;
938 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
939 if (weapons[victim->weaponids[0]].velocity.x == 0)
940 weapons[victim->weaponids[0]].velocity.x = .1;
941 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
942 weapons[victim->weaponids[0]].missed = 1;
943 weapons[victim->weaponids[0]].freetime = 0;
944 weapons[victim->weaponids[0]].firstfree = 1;
945 weapons[victim->weaponids[0]].physics = 1;
946 victim->num_weapons--;
947 if (victim->num_weapons) {
948 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
949 if (victim->weaponstuck == victim->num_weapons)
950 victim->weaponstuck = 0;
953 victim->weaponactive = -1;
954 for (unsigned j = 0; j < Person::players.size(); j++) {
955 Person::players[j]->wentforweapon = 0;
958 animTarget = staffspinhitreversedanim;
959 animCurrent = staffspinhitreversedanim;
960 victim->animCurrent = staffspinhitreversalanim;
961 victim->animTarget = staffspinhitreversalanim;
963 if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
964 if (victim->weaponactive != -1) {
965 victim->throwtogglekeydown = 1;
966 weapons[victim->weaponids[0]].owner = -1;
967 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
968 if (weapons[victim->weaponids[0]].velocity.x == 0)
969 weapons[victim->weaponids[0]].velocity.x = .1;
970 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
971 weapons[victim->weaponids[0]].missed = 1;
972 weapons[victim->weaponids[0]].freetime = 0;
973 weapons[victim->weaponids[0]].firstfree = 1;
974 weapons[victim->weaponids[0]].physics = 1;
975 victim->num_weapons--;
976 if (victim->num_weapons) {
977 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
978 if (victim->weaponstuck == victim->num_weapons)
979 victim->weaponstuck = 0;
982 victim->weaponactive = -1;
983 for (unsigned j = 0; j < Person::players.size(); j++) {
984 Person::players[j]->wentforweapon = 0;
987 animTarget = swordslashreversedanim;
988 animCurrent = swordslashreversedanim;
989 victim->animCurrent = swordslashreversalanim;
990 victim->animTarget = swordslashreversalanim;
992 if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
993 if (victim->weaponactive != -1) {
994 victim->throwtogglekeydown = 1;
995 weapons[victim->weaponids[0]].owner = -1;
996 weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
997 if (weapons[victim->weaponids[0]].velocity.x == 0)
998 weapons[victim->weaponids[0]].velocity.x = .1;
999 weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
1000 weapons[victim->weaponids[0]].missed = 1;
1001 weapons[victim->weaponids[0]].freetime = 0;
1002 weapons[victim->weaponids[0]].firstfree = 1;
1003 weapons[victim->weaponids[0]].physics = 1;
1004 victim->num_weapons--;
1005 if (victim->num_weapons) {
1006 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1007 if (victim->weaponstuck == victim->num_weapons)
1008 victim->weaponstuck = 0;
1011 victim->weaponactive = -1;
1012 for (unsigned j = 0; j < Person::players.size(); j++) {
1013 Person::players[j]->wentforweapon = 0;
1016 animTarget = knifeslashreversedanim;
1017 animCurrent = knifeslashreversedanim;
1018 victim->animCurrent = knifeslashreversalanim;
1019 victim->animTarget = knifeslashreversalanim;
1021 if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim) {
1022 victim->targettilt2 = targettilt2;
1023 victim->frameCurrent = frameCurrent;
1024 victim->frameTarget = frameTarget;
1025 victim->target = target;
1026 victim->velocity = 0;
1027 victim->oldcoords = victim->coords;
1028 victim->coords = coords;
1029 victim->targetyaw = targetyaw;
1030 victim->yaw = targetyaw;
1031 victim->victim = this->shared_from_this();
1033 if (animTarget == winduppunchanim) {
1034 animTarget = winduppunchblockedanim;
1035 victim->animTarget = blockhighleftanim;
1036 victim->frameTarget = 1;
1037 victim->target = .5;
1038 victim->victim = this->shared_from_this();
1039 victim->targetyaw = targetyaw + 180;
1041 if (animTarget == wolfslapanim) {
1042 animTarget = winduppunchblockedanim;
1043 victim->animTarget = blockhighleftanim;
1044 victim->frameTarget = 1;
1045 victim->target = .5;
1046 victim->victim = this->shared_from_this();
1047 victim->targetyaw = targetyaw + 180;
1049 if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) {
1050 animTarget = swordslashparriedanim;
1051 parriedrecently = .4;
1052 victim->parriedrecently = 0;
1053 victim->animTarget = swordslashparryanim;
1054 victim->frameTarget = 1;
1055 victim->target = .5;
1056 victim->victim = this->shared_from_this();
1057 victim->targetyaw = targetyaw + 180;
1059 if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
1060 if (victim->weaponactive != -1) {
1061 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1062 if (weapons[victim->weaponids[0]].getType() == staff)
1063 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1064 if (weapons[weaponids[0]].getType() == staff)
1065 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1066 emit_sound_at(swordstaffsound, victim->coords);
1068 emit_sound_at(metalhitsound, victim->coords);
1072 victim->Puff(righthand);
1074 victim->frameTarget = 0;
1075 victim->animTarget = staggerbackhighanim;
1076 victim->targetyaw = targetyaw + 180;
1078 weapons[victim->weaponids[0]].owner = -1;
1079 aim = DoRotation(facing, 0, 90, 0) * 21;
1081 weapons[victim->weaponids[0]].velocity = aim * -.2;
1082 weapons[victim->weaponids[0]].tipvelocity = aim;
1083 weapons[victim->weaponids[0]].missed = 1;
1084 weapons[victim->weaponids[0]].hitsomething = 0;
1085 weapons[victim->weaponids[0]].freetime = 0;
1086 weapons[victim->weaponids[0]].firstfree = 1;
1087 weapons[victim->weaponids[0]].physics = 1;
1088 victim->num_weapons--;
1089 if (victim->num_weapons) {
1090 victim->weaponids[0] = victim->weaponids[num_weapons];
1091 if (victim->weaponstuck == victim->num_weapons)
1092 victim->weaponstuck = 0;
1094 victim->weaponactive = -1;
1095 for (unsigned i = 0; i < Person::players.size(); i++) {
1096 Person::players[i]->wentforweapon = 0;
1100 if (abs(Random() % 20) == 0) {
1101 if (weaponactive != -1) {
1102 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1103 if (weapons[victim->weaponids[0]].getType() == staff)
1104 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1105 if (weapons[weaponids[0]].getType() == staff)
1106 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1108 emit_sound_at(swordstaffsound, coords);
1110 emit_sound_at(metalhitsound, coords);
1118 animTarget = staggerbackhighanim;
1119 targetyaw = targetyaw + 180;
1121 weapons[weaponids[0]].owner = -1;
1122 aim = DoRotation(facing, 0, 90, 0) * 21;
1124 weapons[weaponids[0]].velocity = aim * -.2;
1125 weapons[weaponids[0]].tipvelocity = aim;
1126 weapons[weaponids[0]].hitsomething = 0;
1127 weapons[weaponids[0]].missed = 1;
1128 weapons[weaponids[0]].freetime = 0;
1129 weapons[weaponids[0]].firstfree = 1;
1130 weapons[weaponids[0]].physics = 1;
1133 weaponids[0] = weaponids[num_weapons];
1134 if (weaponstuck == num_weapons)
1138 for (unsigned i = 0; i < Person::players.size(); i++) {
1139 Person::players[i]->wentforweapon = 0;
1146 if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) {
1147 if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) {
1148 victim->animTarget = dodgebackanim;
1149 victim->frameTarget = 0;
1153 rotatetarget = coords - victim->coords;
1154 Normalise(&rotatetarget);
1155 victim->targetyaw = -asin(0 - rotatetarget.x);
1156 victim->targetyaw *= 360 / 6.28;
1157 if (rotatetarget.z < 0)
1158 victim->targetyaw = 180 - victim->targetyaw;
1160 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1162 victim->lastattack3 = victim->lastattack2;
1163 victim->lastattack2 = victim->lastattack;
1164 victim->lastattack = victim->animTarget;
1166 victim->animTarget = sweepanim;
1167 victim->frameTarget = 0;
1171 rotatetarget = coords - victim->coords;
1172 Normalise(&rotatetarget);
1173 victim->targetyaw = -asin(0 - rotatetarget.x);
1174 victim->targetyaw *= 360 / 6.28;
1175 if (rotatetarget.z < 0)
1176 victim->targetyaw = 180 - victim->targetyaw;
1178 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1180 victim->lastattack3 = victim->lastattack2;
1181 victim->lastattack2 = victim->lastattack;
1182 victim->lastattack = victim->animTarget;
1187 victim->velocity = 0;
1189 if (aitype != playercontrolled)
1191 if (aitype != playercontrolled && Random() % 3 == 0 && escapednum < 2 && difficulty == 2)
1193 if (aitype != playercontrolled && Random() % 5 == 0 && escapednum < 2 && difficulty == 1)
1195 if (aitype != playercontrolled && Random() % 10 == 0 && escapednum < 2 && difficulty == 0)
1198 if (victim->id == 0 && animation[victim->animTarget].attack == reversal)
1205 void Person::DoDamage(float howmuch)
1207 // subtract health (temporary?)
1208 if (tutoriallevel != 1)
1209 damage += howmuch / power;
1212 damagedealt += howmuch / power;
1214 damagetaken += howmuch / power;
1217 if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo))
1220 if (tutoriallevel != 1)
1221 permanentdamage += howmuch / 2 / power;
1222 if (tutoriallevel != 1)
1223 superpermanentdamage += howmuch / 4 / power;
1225 if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2)
1227 if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt)
1231 camerashake += howmuch / 100;
1232 if (id == 0 && ((howmuch > 50 && damage > damagetolerance / 2)))
1233 blackout = damage / damagetolerance;
1238 if (aitype == passivetype && damage < damagetolerance && ((tutoriallevel != 1 || cananger) && hostile))
1239 aitype = attacktypecutoff;
1240 if (tutoriallevel != 1 && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
1241 if (abs(Random() % 2) == 0) {
1242 aitype = gethelptype;
1245 aitype = attacktypecutoff;
1249 if (howmuch > damagetolerance * 50 && skeleton.free != 2) {
1252 for (int i = 0; i < skeleton.num_joints; i++) {
1254 flatvelocity2 = velocity;
1256 flatvelocity2 = skeleton.joints[i].velocity;
1258 flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
1260 flatfacing2 = skeleton.joints[i].position * scale + coords;
1261 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1262 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1263 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1264 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1265 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1266 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1269 emit_sound_at(splattersound, coords);
1278 if (!dead && creature == wolftype) {
1279 award_bonus(0, Wolfbonus);
1286 if (tutoriallevel != 1 || id == 0)
1287 if (speechdelay <= 0 && !dead && aitype != playercontrolled) {
1288 int whichsound = -1;
1290 if (creature == wolftype) {
1291 int i = abs(Random() % 2);
1293 whichsound = snarlsound;
1295 whichsound = snarl2sound;
1296 envsound[numenvsounds] = coords;
1297 envsoundvol[numenvsounds] = 16;
1298 envsoundlife[numenvsounds] = .4;
1301 if (creature == rabbittype) {
1302 int i = abs(Random() % 2);
1304 whichsound = rabbitpainsound;
1305 if (i == 1 && damage > damagetolerance)
1306 whichsound = rabbitpain1sound;
1307 envsound[numenvsounds] = coords;
1308 envsoundvol[numenvsounds] = 16;
1309 envsoundlife[numenvsounds] = .4;
1311 //if(i==2)whichsound=rabbitpain2sound;
1314 if (whichsound != -1) {
1315 emit_sound_at(whichsound, coords);
1320 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1321 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1325 * calculate/animate head facing direction?
1327 void Person::DoHead()
1329 static XYZ rotatearound;
1331 static float lookspeed = 500;
1333 if (!freeze && !winfreeze) {
1336 targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100;
1337 targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100;
1339 while (targetheadyaw > 180)targetheadyaw -= 360;
1340 while (targetheadyaw < -180)targetheadyaw += 360;
1342 if (targetheadyaw > 160)
1343 targetheadpitch = targetheadpitch * -1;
1344 if (targetheadyaw < -160)
1345 targetheadpitch = targetheadpitch * -1;
1346 if (targetheadyaw > 160)
1347 targetheadyaw = targetheadyaw - 180;
1348 if (targetheadyaw < -160)
1349 targetheadyaw = targetheadyaw + 180;
1351 if (targetheadpitch > 120)
1352 targetheadpitch = 120;
1353 if (targetheadpitch < -120)
1354 targetheadpitch = -120;
1355 if (targetheadyaw > 120)
1356 targetheadyaw = 120;
1357 if (targetheadyaw < -120)
1358 targetheadyaw = -120;
1361 targetheadpitch = 0;
1363 if (targetheadyaw > 80)
1365 if (targetheadyaw < -80)
1366 targetheadyaw = -80;
1367 if (targetheadpitch > 50)
1368 targetheadpitch = 50;
1369 if (targetheadpitch < -50)
1370 targetheadpitch = -50;
1373 if (abs(headyaw - targetheadyaw) < multiplier * lookspeed)
1374 headyaw = targetheadyaw;
1375 else if (headyaw > targetheadyaw) {
1376 headyaw -= multiplier * lookspeed;
1377 } else if (headyaw < targetheadyaw) {
1378 headyaw += multiplier * lookspeed;
1381 if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2)
1382 headpitch = targetheadpitch;
1383 else if (headpitch > targetheadpitch) {
1384 headpitch -= multiplier * lookspeed / 2;
1385 } else if (headpitch < targetheadpitch) {
1386 headpitch += multiplier * lookspeed / 2;
1389 rotatearound = jointPos(neck);
1390 jointPos(head) = rotatearound + DoRotation(jointPos(head) - rotatearound, headpitch, 0, 0);
1394 if (animTarget != bounceidleanim && animTarget != fightidleanim && animTarget != wolfidle && animTarget != knifefightidleanim && animTarget != drawrightanim && animTarget != drawleftanim && animTarget != walkanim) {
1395 facing = DoRotation(facing, headpitch * .4, 0, 0);
1396 facing = DoRotation(facing, 0, headyaw * .4, 0);
1399 if (animTarget == bounceidleanim || animTarget == fightidleanim || animTarget == wolfidle || animTarget == knifefightidleanim || animTarget == drawrightanim || animTarget == drawleftanim) {
1400 facing = DoRotation(facing, headpitch * .8, 0, 0);
1401 facing = DoRotation(facing, 0, headyaw * .8, 0);
1404 if (animTarget == walkanim) {
1405 facing = DoRotation(facing, headpitch * .6, 0, 0);
1406 facing = DoRotation(facing, 0, headyaw * .6, 0);
1409 skeleton.specialforward[0] = facing;
1410 //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1411 for (int i = 0; i < skeleton.num_muscles; i++) {
1412 if (skeleton.muscles[i].visible && (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)) {
1413 skeleton.FindRotationMuscle(i, animTarget);
1420 * ragdolls character?
1422 void Person::RagDoll(bool checkcollision)
1427 if (!skeleton.free) {
1430 if (id == 0 && isFlip())
1437 facing = DoRotation(facing, 0, yaw, 0);
1439 skeleton.freetime = 0;
1441 skeleton.longdead = 0;
1444 skeleton.broken = 0;
1445 skeleton.spinny = 1;
1447 skeleton.freefall = 1;
1449 if (!isnormal(velocity.x)) velocity.x = 0;
1450 if (!isnormal(velocity.y)) velocity.y = 0;
1451 if (!isnormal(velocity.z)) velocity.z = 0;
1452 if (!isnormal(yaw)) yaw = 0;
1453 if (!isnormal(coords.x)) coords = 0;
1454 if (!isnormal(tilt)) tilt = 0;
1455 if (!isnormal(tilt2)) tilt2 = 0;
1457 for (int i = 0; i < skeleton.num_joints; i++) {
1458 skeleton.joints[i].delay = 0;
1459 skeleton.joints[i].locked = 0;
1460 skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1461 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0);
1462 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = coords;
1463 skeleton.joints[i].position.y += .1;
1464 skeleton.joints[i].oldposition = skeleton.joints[i].position;
1465 skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords;
1468 for (int i = 0; i < skeleton.num_joints; i++) {
1469 skeleton.joints[i].velocity = 0;
1470 skeleton.joints[i].velchange = 0;
1472 skeleton.DoConstraints(&coords, &scale);
1473 if (animation[animCurrent].height == lowheight || animation[animTarget].height == lowheight) {
1474 skeleton.DoConstraints(&coords, &scale);
1475 skeleton.DoConstraints(&coords, &scale);
1476 skeleton.DoConstraints(&coords, &scale);
1477 skeleton.DoConstraints(&coords, &scale);
1480 speed = animation[animTarget].speed[frameTarget] * 2;
1481 if (animation[animCurrent].speed[frameCurrent] > animation[animTarget].speed[frameTarget]) {
1482 speed = animation[animCurrent].speed[frameCurrent] * 2;
1485 speed = transspeed * 2;
1489 for (int i = 0; i < skeleton.num_joints; i++) {
1490 if ((animation[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && animation[animCurrent].height == animation[animTarget].height)
1491 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);
1493 skeleton.joints[i].velocity = velocity / scale + facing * 5;
1494 change.x = (float)(Random() % 100) / 100;
1495 change.y = (float)(Random() % 100) / 100;
1496 change.z = (float)(Random() % 100) / 100;
1497 skeleton.joints[i].velocity += change;
1498 skeleton.joints[abs(Random() % skeleton.num_joints)].velocity -= change;
1500 change.x = (float)(Random() % 100) / 100;
1501 change.y = (float)(Random() % 100) / 100;
1502 change.z = (float)(Random() % 100) / 100;
1503 skeleton.joints[i].velchange += change;
1504 skeleton.joints[abs(Random() % skeleton.num_joints)].velchange -= change;
1507 if (checkcollision) {
1514 for (j = 0; j < skeleton.num_joints; j++) {
1515 average += skeleton.joints[j].position;
1519 coords += average * scale;
1520 for (j = 0; j < skeleton.num_joints; j++) {
1521 skeleton.joints[j].position -= average;
1524 whichpatchx = coords.x / (terrain.size / subdivision * terrain.scale);
1525 whichpatchz = coords.z / (terrain.size / subdivision * terrain.scale);
1526 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
1527 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
1528 i = terrain.patchobjects[whichpatchx][whichpatchz][l];
1531 if (SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.yaw[i], &objects.model[i]) != -1) {
1532 coords.x = lowpoint.x;
1533 coords.z = lowpoint.z;
1542 for (int i = 0; i < skeleton.num_joints; i++) {
1543 velocity += skeleton.joints[i].velocity * scale;
1545 velocity /= skeleton.num_joints;
1548 if (Random() % 2 == 0) {
1549 if (weaponactive != -1 && animTarget != rabbitkickanim && num_weapons > 0) {
1550 weapons[weaponids[0]].owner = -1;
1551 weapons[weaponids[0]].hitsomething = 0;
1552 weapons[weaponids[0]].velocity = jointVel(righthand) * scale * -.3;
1553 weapons[weaponids[0]].velocity.x += .01;
1554 weapons[weaponids[0]].tipvelocity = jointVel(righthand) * scale;
1555 weapons[weaponids[0]].missed = 1;
1556 weapons[weaponids[0]].freetime = 0;
1557 weapons[weaponids[0]].firstfree = 1;
1558 weapons[weaponids[0]].physics = 1;
1561 weaponids[0] = weaponids[num_weapons];
1562 if (weaponstuck == num_weapons)
1566 for (unsigned i = 0; i < Person::players.size(); i++) {
1567 Person::players[i]->wentforweapon = 0;
1572 animTarget = bounceidleanim;
1573 animCurrent = bounceidleanim;
1583 void Person::FootLand(int which, float opacity)
1585 static XYZ terrainlight;
1586 static XYZ footvel, footpoint;
1587 if (opacity >= 1 || skiddelay <= 0)
1591 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1593 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1594 //footpoint.y=coords.y;
1595 if (distsq(&footpoint, &viewer))
1596 Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity);
1597 } else if (environment == snowyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1598 footvel = velocity / 5;
1602 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1604 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1605 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1606 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1607 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1608 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity);
1609 if (opacity >= 1 || detail == 2)
1611 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1612 terrain.MakeDecal(footprintdecal, footpoint, .2, 1 * opacity, yaw);
1613 } else if (environment == grassyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1614 footvel = velocity / 5;
1618 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1620 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1621 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1622 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1623 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1624 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity);
1625 } else if (environment == desertenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1626 footvel = velocity / 5;
1630 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1632 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1633 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1634 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1635 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1636 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity);
1637 if (opacity >= 1 || detail == 2)
1639 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1640 terrain.MakeDecal(footprintdecal, footpoint, .2, .25 * opacity, yaw);
1641 } else if (isLanding() || animTarget == jumpupanim || isLandhard()) {
1642 footvel = velocity / 5;
1646 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1648 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1649 //footpoint.y=coords.y;
1650 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1651 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity);
1656 * make a puff effect at a body part (dust effect?)
1658 void Person::Puff(int whichlabel)
1660 static XYZ footvel, footpoint;
1663 footpoint = DoRotation(jointPos(whichlabel), 0, yaw, 0) * scale + coords;
1664 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .9, .3);
1668 * I think I added this in an attempt to clean up code
1670 void Person::setAnimation(int animation)
1672 animTarget = animation;
1681 void Person::DoAnimations()
1683 if (!skeleton.free) {
1684 static float oldtarget;
1686 if (isIdle() && animCurrent != getIdle())
1687 normalsupdatedelay = 0;
1689 if (animTarget == tempanim || animCurrent == tempanim) {
1690 animation[tempanim] = tempanimation;
1692 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
1698 vel[0] = velocity.x;
1699 vel[1] = velocity.y;
1700 vel[2] = velocity.z;
1703 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1704 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
1706 if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z))
1708 if (!crouchkeydown && velocity.y >= -15)
1711 if ((animCurrent == jumpupanim || animTarget == jumpdownanim)/*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) {
1716 targfacing = DoRotation(targfacing, 0, targetyaw, 0);
1718 if (normaldotproduct(targfacing, velocity) >= -.3)
1719 animTarget = flipanim;
1721 animTarget = backflipanim;
1722 crouchtogglekeydown = 1;
1730 if (animation[animTarget].attack != reversed)
1732 if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) {
1733 crouchtogglekeydown = 0;
1734 if (aitype == playercontrolled)
1737 if (!crouchtogglekeydown && animation[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain))
1740 crouchtogglekeydown = 1;
1744 if (animation[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) {
1746 normalsupdatedelay = 0;
1750 if (animTarget == rollanim && frameTarget == 3 && onfire) {
1752 emit_sound_at(fireendsound, coords);
1753 pause_sound(stream_firesound);
1757 if (animTarget == rabbittacklinganim && frameTarget == 1) {
1758 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->animTarget].attack==neutral&&victim->id!=0)Reverse();
1759 if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0)
1761 if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) {
1762 if (normaldotproduct(victim->facing, facing) > 0)
1763 victim->animTarget = rabbittackledbackanim;
1765 victim->animTarget = rabbittackledfrontanim;
1766 victim->frameTarget = 2;
1769 victim->targetyaw = yaw;
1770 if (victim->aitype == gethelptype)
1771 victim->DoDamage(victim->damagetolerance - victim->damage);
1772 //victim->DoDamage(30);
1773 if (creature == wolftype) {
1775 emit_sound_at(clawslicesound, victim->coords);
1777 victim->DoBloodBig(1 / victim->armorhead, 210);
1779 award_bonus(id, TackleBonus,
1780 victim->aitype == gethelptype ? 50 : 0);
1784 if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (animation[animTarget].label[frameTarget] || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) {
1785 if (weapons[weaponids[0]].getType() == knife) {
1786 if (weaponactive == -1)
1788 else if (weaponactive == 0)
1791 if (weaponactive == -1) {
1792 emit_sound_at(knifesheathesound, coords);
1794 if (weaponactive != -1) {
1795 emit_sound_at(knifedrawsound, coords, 128);
1798 drawtogglekeydown = 1;
1801 if (tutoriallevel != 1 || id == 0)
1802 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1805 if (terrain.getOpacity(coords.x, coords.z) < .2) {
1806 if (animation[animTarget].label[frameTarget] == 1)
1807 whichsound = footstepsound;
1809 whichsound = footstepsound2;
1810 if (animation[animTarget].label[frameTarget] == 1)
1812 if (animation[animTarget].label[frameTarget] == 2)
1814 if (animation[animTarget].label[frameTarget] == 3 && isRun()) {
1820 if (terrain.getOpacity(coords.x, coords.z) >= .2) {
1821 if (animation[animTarget].label[frameTarget] == 1)
1822 whichsound = footstepsound3;
1824 whichsound = footstepsound4;
1828 if (animation[animTarget].label[frameTarget] == 1)
1829 whichsound = footstepsound3;
1831 whichsound = footstepsound4;
1833 if (animation[animTarget].label[frameTarget] == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
1834 if (animation[animTarget].attack != neutral) {
1835 unsigned r = abs(Random() % 3);
1837 whichsound = lowwhooshsound;
1839 whichsound = midwhooshsound;
1841 whichsound = highwhooshsound;
1843 if (animation[animTarget].attack == neutral)
1844 whichsound = movewhooshsound;
1845 } else if (animation[animTarget].label[frameTarget] == 4)
1846 whichsound = knifeswishsound;
1847 if (animation[animTarget].label[frameTarget] == 8 && tutoriallevel != 1)
1848 whichsound = landsound2;
1850 emit_sound_at(whichsound, coords, 256.);
1853 if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
1854 envsound[numenvsounds] = coords;
1855 if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim)
1856 envsoundvol[numenvsounds] = 15;
1858 envsoundvol[numenvsounds] = 6;
1859 envsoundlife[numenvsounds] = .4;
1863 if (animation[animTarget].label[frameTarget] == 3) {
1865 emit_sound_at(whichsound, coords, 128.);
1870 if (tutoriallevel != 1 || id == 0)
1871 if (speechdelay <= 0)
1872 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
1873 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1874 int whichsound = -1;
1875 if (animation[animTarget].label[frameTarget] == 4 && aitype != playercontrolled) {
1876 if (animation[animTarget].attack != neutral) {
1877 unsigned r = abs(Random() % 4);
1878 if (creature == rabbittype) {
1879 if (r == 0) whichsound = rabbitattacksound;
1880 if (r == 1) whichsound = rabbitattack2sound;
1881 if (r == 2) whichsound = rabbitattack3sound;
1882 if (r == 3) whichsound = rabbitattack4sound;
1884 if (creature == wolftype) {
1885 if (r == 0) whichsound = barksound;
1886 if (r == 1) whichsound = bark2sound;
1887 if (r == 2) whichsound = bark3sound;
1888 if (r == 3) whichsound = barkgrowlsound;
1892 //if(animation[animTarget].attack==neutral)whichsound=movewhooshsound;
1894 //else if(animation[animTarget].label[frameTarget]==4)whichsound=knifeswishsound;
1895 //if(animation[animTarget].label[frameTarget]==8)whichsound=landsound2;
1897 if (whichsound != -1) {
1898 emit_sound_at(whichsound, coords);
1904 if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) {
1910 currentoffset = targetoffset;
1911 frameTarget = frameCurrent;
1912 animCurrent = animTarget;
1915 if (animTarget == removeknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1916 for (unsigned i = 0; i < weapons.size(); i++) {
1917 if (weapons[i].owner == -1)
1918 if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
1919 if (distsq(&coords, &weapons[i].position) >= 1) {
1920 if (weapons[i].getType() != staff) {
1921 emit_sound_at(knifedrawsound, coords, 128.);
1925 weapons[i].owner = id;
1926 if (num_weapons > 0) {
1927 weaponids[num_weapons] = weaponids[0];
1936 if (animTarget == crouchremoveknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1937 for (unsigned i = 0; i < weapons.size(); i++) {
1938 bool willwork = true;
1939 if (weapons[i].owner != -1)
1940 if (Person::players[weapons[i].owner]->weaponstuck != -1)
1941 if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == int(i))
1942 if (Person::players[weapons[i].owner]->num_weapons > 1)
1944 if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free))
1945 if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) {
1946 if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
1947 bool fleshstuck = false;
1948 if (weapons[i].owner != -1)
1949 if (victim->weaponstuck != -1) {
1950 if (victim->weaponids[victim->weaponstuck] == int(i)) {
1955 emit_sound_at(fleshstabremovesound, coords, 128.);
1957 if (weapons[i].getType() != staff) {
1958 emit_sound_at(knifedrawsound, coords, 128.);
1962 if (weapons[i].owner != -1) {
1964 victim = Person::players[weapons[i].owner];
1965 if (victim->num_weapons == 1)
1966 victim->num_weapons = 0;
1968 victim->num_weapons = 1;
1970 //victim->weaponactive=-1;
1971 victim->skeleton.longdead = 0;
1972 victim->skeleton.free = 1;
1973 victim->skeleton.broken = 0;
1975 for (int j = 0; j < victim->skeleton.num_joints; j++) {
1976 victim->skeleton.joints[j].velchange = 0;
1977 victim->skeleton.joints[j].locked = 0;
1983 Normalise(&relative);
1984 XYZ footvel, footpoint;
1986 footpoint = weapons[i].position;
1987 if (victim->weaponstuck != -1) {
1988 if (victim->weaponids[victim->weaponstuck] == int(i)) {
1990 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
1991 weapons[i].bloody = 2;
1992 weapons[i].blooddrip = 5;
1993 victim->weaponstuck = -1;
1996 if (victim->num_weapons > 0) {
1997 if (victim->weaponstuck != 0 && victim->weaponstuck != -1)
1998 victim->weaponstuck = 0;
1999 if (victim->weaponids[0] == int(i))
2000 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
2003 victim->jointVel(abdomen) += relative * 6;
2004 victim->jointVel(neck) += relative * 6;
2005 victim->jointVel(rightshoulder) += relative * 6;
2006 victim->jointVel(leftshoulder) += relative * 6;
2008 weapons[i].owner = id;
2009 if (num_weapons > 0) {
2010 weaponids[num_weapons] = weaponids[0];
2019 if (animCurrent == drawleftanim && animation[animTarget].label[frameCurrent] == 5) {
2020 if (weaponactive == -1)
2022 else if (weaponactive == 0) {
2024 if (num_weapons == 2) {
2026 buffer = weaponids[0];
2027 weaponids[0] = weaponids[1];
2028 weaponids[1] = buffer;
2031 if (weaponactive == -1) {
2032 emit_sound_at(knifesheathesound, coords, 128.);
2034 if (weaponactive != -1) {
2035 emit_sound_at(knifedrawsound, coords, 128.);
2040 if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) {
2041 XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0);
2042 Normalise(&rotatetarget);
2043 targetyaw = -asin(0 - rotatetarget.x);
2044 targetyaw *= 360 / 6.28;
2045 if (rotatetarget.z < 0)
2046 targetyaw = 180 - targetyaw;
2048 if (animTarget == walljumprightkickanim)
2050 if (animTarget == walljumpleftkickanim)
2056 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0))
2059 if (distsq(&victim->coords, &/*Person::players[i]->*/coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1)
2064 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) {
2065 animTarget = rabbittackleanim;
2067 emit_sound_at(jumpsound, coords);
2075 targetloc = velocity;
2076 Normalise(&targetloc);
2077 targetloc += coords;
2078 for (unsigned i = 0; i < Person::players.size(); i++) {
2080 if (distsq(&targetloc, &Person::players[i]->coords) < closestdist || closestdist == 0) {
2081 closestdist = distsq(&targetloc, &Person::players[i]->coords);
2085 if (closestid != -1)
2086 if (closestdist < 5 && !Person::players[closestid]->dead && animation[Person::players[closestid]->animTarget].height != lowheight && Person::players[closestid]->animTarget != backhandspringanim) {
2088 victim = Person::players[closestid];
2089 coords = victim->coords;
2090 animCurrent = rabbittacklinganim;
2091 animTarget = rabbittacklinganim;
2095 if (coords.z != victim->coords.z || coords.x != victim->coords.x) {
2096 rotatetarget = coords - victim->coords;
2097 Normalise(&rotatetarget);
2098 targetyaw = -asin(0 - rotatetarget.x);
2099 targetyaw *= 360 / 6.28;
2100 if (rotatetarget.z < 0)
2101 targetyaw = 180 - targetyaw;
2103 if (animTarget != rabbitrunninganim) {
2104 emit_sound_at(jumpsound, coords, 128.);
2110 float damagemult = 1 * power;
2111 if (creature == wolftype)
2112 damagemult = 2.5 * power;
2114 damagemult /= victim->damagetolerance / 200;
2116 //if(onfire)damagemult=3;
2117 if ((animation[animTarget].attack == normalattack || animTarget == walljumprightkickanim || animTarget == walljumpleftkickanim) && (!feint) && (victim->skeleton.free != 2 || animTarget == killanim || animTarget == dropkickanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == staffgroundsmashanim)) {
2118 if (animTarget == spinkickanim && animation[animTarget].label[frameCurrent] == 5) {
2119 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2123 if (Random() % 2 || creature == wolftype) {
2126 if (creature == wolftype)
2129 if (tutoriallevel != 1) {
2130 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2132 if (creature == wolftype) {
2133 emit_sound_at(clawslicesound, victim->coords, 128.);
2135 victim->DoBloodBig(2 / victim->armorhead, 175);
2139 relative = victim->coords - coords;
2141 Normalise(&relative);
2142 relative = DoRotation(relative, 0, -90, 0);
2143 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2144 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2146 victim->jointVel(head) += relative * damagemult * 200;
2149 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2155 if (animTarget == wolfslapanim && animation[animTarget].label[frameCurrent] == 5) {
2156 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2160 if (Random() % 2 || creature == wolftype) {
2162 if (creature == wolftype)
2165 emit_sound_at(whooshhitsound, victim->coords);
2166 if (creature == wolftype) {
2167 emit_sound_at(clawslicesound, victim->coords, 128.);
2169 victim->DoBloodBig(2, 175);
2173 relative = victim->coords - coords;
2175 Normalise(&relative);
2177 Normalise(&relative);
2178 relative = DoRotation(relative, 0, 90, 0);
2179 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2180 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2182 victim->jointVel(head) += relative * damagemult * 100;
2185 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2189 if (animTarget == walljumprightkickanim && animation[animTarget].label[frameCurrent] == 5) {
2190 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2196 if (tutoriallevel != 1) {
2197 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2199 if (creature == wolftype) {
2200 emit_sound_at(clawslicesound, victim->coords, 128.);
2202 victim->DoBloodBig(2 / victim->armorhead, 175);
2208 Normalise(&relative);
2209 relative = DoRotation(relative, 0, -90, 0);
2210 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2211 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2213 victim->jointVel(head) += relative * damagemult * 200;
2216 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2218 if (victim->damage > victim->damagetolerance)
2219 award_bonus(id, style);
2225 if (animTarget == walljumpleftkickanim && animation[animTarget].label[frameCurrent] == 5) {
2226 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2232 if (tutoriallevel != 1) {
2233 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2235 if (creature == wolftype) {
2236 emit_sound_at(clawslicesound, victim->coords, 128.);
2238 victim->DoBloodBig(2 / victim->armorhead, 175);
2244 Normalise(&relative);
2245 relative = DoRotation(relative, 0, 90, 0);
2246 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2247 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2249 victim->jointVel(head) += relative * damagemult * 200;
2252 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2254 if (victim->damage > victim->damagetolerance)
2255 award_bonus(id, style);
2261 if (animTarget == blockhighleftstrikeanim && animation[animTarget].label[frameCurrent] == 5) {
2262 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2270 emit_sound_at(whooshhitsound, victim->coords);
2273 relative = victim->coords - coords;
2275 Normalise(&relative);
2276 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2277 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
2279 victim->jointVel(head) += relative * damagemult * 100;
2282 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2286 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 8) {
2287 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) {
2291 emit_sound_at(whooshhitsound, victim->coords, 128.);
2293 victim->skeleton.longdead = 0;
2294 victim->skeleton.free = 1;
2295 victim->skeleton.broken = 0;
2296 victim->skeleton.spinny = 1;
2298 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2299 victim->skeleton.joints[i].velchange = 0;
2300 victim->skeleton.joints[i].delay = 0;
2301 victim->skeleton.joints[i].locked = 0;
2302 //victim->skeleton.joints[i].velocity=0;
2308 Normalise(&relative);
2309 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2310 victim->skeleton.joints[i].velocity.y = relative.y * 10;
2311 victim->skeleton.joints[i].position.y += relative.y * .3;
2312 victim->skeleton.joints[i].oldposition.y += relative.y * .3;
2313 victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
2315 victim->Puff(abdomen);
2316 victim->jointVel(abdomen).y = relative.y * 400;
2320 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 5) {
2321 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) {
2325 if (tutoriallevel != 1) {
2326 emit_sound_at(heavyimpactsound, coords, 128.);
2329 relative = victim->coords - coords;
2331 Normalise(&relative);
2332 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2333 victim->skeleton.joints[i].velocity += relative * damagemult * 90;
2335 victim->Puff(abdomen);
2336 if (victim->dead != 2 && victim->permanentdamage > victim->damagetolerance - 250 && autoslomo) {
2340 victim->DoDamage(damagemult * 500 / victim->protectionhigh);
2341 victim->jointVel(abdomen) += relative * damagemult * 300;
2345 if (animTarget == dropkickanim && animation[animTarget].label[frameCurrent] == 7) {
2346 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) {
2350 if (tutoriallevel != 1) {
2351 emit_sound_at(thudsound, coords);
2354 victim->skeleton.longdead = 0;
2355 victim->skeleton.free = 1;
2356 victim->skeleton.broken = 0;
2357 victim->skeleton.spinny = 1;
2359 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2360 victim->skeleton.joints[i].velchange = 0;
2361 //victim->skeleton.joints[i].delay=0;
2362 victim->skeleton.joints[i].locked = 0;
2365 relative = victim->coords - coords;
2366 Normalise(&relative);
2368 Normalise(&relative);
2369 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2370 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2375 victim->Puff(abdomen);
2376 victim->DoDamage(damagemult * 20 / victim->protectionhigh);
2377 victim->jointVel(abdomen) += relative * damagemult * 200;
2386 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 5) {
2387 //if(id==0)camerashake+=.4;
2390 if (!victim->skeleton.free)
2394 terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360);
2395 emit_sound_at(knifesheathesound, coords, 128.);
2398 if (victim && hasvictim) {
2399 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2401 XYZ where, startpoint, endpoint, movepoint, colpoint;
2402 float rotationpoint;
2404 if (weapons[weaponids[weaponactive]].getType() == knife) {
2405 where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4);
2406 where -= victim->coords;
2407 if (!victim->skeleton.free)
2408 where = DoRotation(where, 0, -victim->yaw, 0);
2411 startpoint.y += 100;
2415 if (weapons[weaponids[weaponactive]].getType() == sword) {
2416 where = weapons[weaponids[weaponactive]].position;
2417 where -= victim->coords;
2418 if (!victim->skeleton.free)
2419 where = DoRotation(where, 0, -victim->yaw, 0);
2421 where = weapons[weaponids[weaponactive]].tippoint;
2422 where -= victim->coords;
2423 if (!victim->skeleton.free)
2424 where = DoRotation(where, 0, -victim->yaw, 0);
2427 if (weapons[weaponids[weaponactive]].getType() == staff) {
2428 where = weapons[weaponids[weaponactive]].position;
2429 where -= victim->coords;
2430 if (!victim->skeleton.free)
2431 where = DoRotation(where, 0, -victim->yaw, 0);
2433 where = weapons[weaponids[weaponactive]].tippoint;
2434 where -= victim->coords;
2435 if (!victim->skeleton.free)
2436 where = DoRotation(where, 0, -victim->yaw, 0);
2441 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
2443 if (whichtri != -1) {
2444 if (victim->dead != 2) {
2445 victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2));
2447 award_bonus(id, FinishedBonus);
2450 weapons[weaponids[weaponactive]].bloody = 2;
2452 victim->skeleton.longdead = 0;
2453 victim->skeleton.free = 1;
2454 victim->skeleton.broken = 0;
2456 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2457 victim->skeleton.joints[i].velchange = 0;
2458 victim->skeleton.joints[i].locked = 0;
2459 //victim->skeleton.joints[i].velocity=0;
2461 emit_sound_at(fleshstabsound, coords, 128);
2464 if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) {
2465 weapons[weaponids[weaponactive]].blooddrip += 5;
2466 weapons[weaponids[weaponactive]].blooddripdelay = 0;
2468 if (whichtri == -1) {
2470 emit_sound_at(knifesheathesound, coords, 128.);
2476 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 6) {
2478 emit_sound_at(knifedrawsound, coords, 128);
2481 if (victim && hasvictim) {
2482 XYZ footvel, footpoint;
2484 emit_sound_at(fleshstabremovesound, coords, 128.);
2487 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2489 if (weapons[weaponids[weaponactive]].getType() == sword) {
2490 XYZ where, startpoint, endpoint, movepoint;
2491 float rotationpoint;
2494 where = weapons[weaponids[weaponactive]].position;
2495 where -= victim->coords;
2496 if (!victim->skeleton.free)
2497 where = DoRotation(where, 0, -victim->yaw, 0);
2499 where = weapons[weaponids[weaponactive]].tippoint;
2500 where -= victim->coords;
2501 if (!victim->skeleton.free)
2502 where = DoRotation(where, 0, -victim->yaw, 0);
2507 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2508 footpoint += victim->coords;
2510 if (whichtri == -1) {
2511 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2514 if (weapons[weaponids[weaponactive]].getType() == staff) {
2515 XYZ where, startpoint, endpoint, movepoint;
2516 float rotationpoint;
2519 where = weapons[weaponids[weaponactive]].position;
2520 where -= victim->coords;
2521 if (!victim->skeleton.free)
2522 where = DoRotation(where, 0, -victim->yaw, 0);
2524 where = weapons[weaponids[weaponactive]].tippoint;
2525 where -= victim->coords;
2526 if (!victim->skeleton.free)
2527 where = DoRotation(where, 0, -victim->yaw, 0);
2532 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2533 footpoint += victim->coords;
2535 if (whichtri == -1) {
2536 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2539 hasvictim = victim->DoBloodBigWhere(2, 220, footpoint);
2541 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2542 victim->skeleton.longdead = 0;
2543 victim->skeleton.free = 1;
2544 victim->skeleton.broken = 0;
2546 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2547 victim->skeleton.joints[i].velchange = 0;
2548 victim->skeleton.joints[i].locked = 0;
2549 //victim->skeleton.joints[i].velocity=0;
2555 Normalise(&relative);
2556 //victim->Puff(abdomen);
2558 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2560 if (victim->bloodloss < victim->damagetolerance) {
2561 victim->bloodloss += 1000;
2565 victim->jointVel(abdomen) += relative * damagemult * 20;
2569 if (!hasvictim && onterrain) {
2570 weapons[weaponids[weaponactive]].bloody = 0;
2571 weapons[weaponids[weaponactive]].blooddrip = 0;
2575 if (animTarget == upunchanim && animation[animTarget].label[frameCurrent] == 5) {
2576 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2584 if (tutoriallevel != 1) {
2585 emit_sound_at(heavyimpactsound, victim->coords, 128);
2590 relative = victim->coords - coords;
2592 Normalise(&relative);
2593 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2594 victim->skeleton.joints[i].velocity = relative * 30;
2596 victim->jointVel(head) += relative * damagemult * 150;
2598 victim->frameTarget = 0;
2599 victim->animTarget = staggerbackhardanim;
2600 victim->targetyaw = targetyaw + 180;
2602 victim->stunned = 1;
2605 victim->Puff(abdomen);
2606 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2613 if (animTarget == winduppunchanim && animation[animTarget].label[frameCurrent] == 5) {
2614 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) {
2618 if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height != lowheight) {
2619 if (tutoriallevel != 1) {
2620 emit_sound_at(thudsound, victim->coords);
2622 } else if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height == lowheight) {
2623 if (tutoriallevel != 1) {
2624 emit_sound_at(whooshhitsound, victim->coords);
2627 if (tutoriallevel != 1) {
2628 emit_sound_at(heavyimpactsound, victim->coords);
2632 if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || animation[victim->animTarget].height == lowheight)
2635 relative = victim->coords - coords;
2637 Normalise(&relative);
2639 Normalise(&relative);
2640 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2641 victim->skeleton.joints[i].velocity = relative * 5;
2643 victim->jointVel(abdomen) += relative * damagemult * 400;
2645 victim->frameTarget = 0;
2646 victim->animTarget = staggerbackhardanim;
2647 victim->targetyaw = targetyaw + 180;
2649 victim->stunned = 1;
2651 victim->Puff(abdomen);
2652 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2658 if (animTarget == blockhighleftanim && animation[animTarget].label[frameCurrent] == 5) {
2659 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2660 if (victim->id == 0)
2662 emit_sound_at(landsound2, victim->coords);
2668 if (animTarget == swordslashparryanim && animation[animTarget].label[frameCurrent] == 5) {
2669 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2670 if (victim->id == 0)
2673 if (weaponactive != -1) {
2674 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2675 if (weapons[victim->weaponids[0]].getType() == staff)
2676 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2677 if (weapons[weaponids[0]].getType() == staff)
2678 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2680 emit_sound_at(swordstaffsound, victim->coords);
2682 emit_sound_at(metalhitsound, victim->coords);
2690 if (animTarget == knifethrowanim && animation[animTarget].label[frameCurrent] == 5) {
2691 if (weaponactive != -1) {
2694 weapons[weaponids[0]].owner = -1;
2695 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);
2697 /*if(victim->animTarget==jumpupanim||victim->animTarget==jumpdownanim){
2698 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2700 weapons[weaponids[0]].velocity = aim * 50;
2701 weapons[weaponids[0]].tipvelocity = aim * 50;
2702 weapons[weaponids[0]].missed = 0;
2703 weapons[weaponids[0]].hitsomething = 0;
2704 weapons[weaponids[0]].freetime = 0;
2705 weapons[weaponids[0]].firstfree = 1;
2706 weapons[weaponids[0]].physics = 0;
2709 weaponids[0] = weaponids[num_weapons];
2715 if (animTarget == knifeslashstartanim && animation[animTarget].label[frameCurrent] == 5) {
2717 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 &&/*animation[victim->animTarget].height!=lowheight&&*/victim->animTarget != dodgebackanim && victim->animTarget != rollanim) {
2719 if (tutoriallevel != 1)
2720 victim->DoBloodBig(1.5 / victim->armorhigh, 225);
2722 award_bonus(id, Slicebonus);
2723 if (tutoriallevel != 1) {
2724 emit_sound_at(knifeslicesound, victim->coords);
2726 //victim->jointVel(abdomen)+=relative*damagemult*200;
2727 if (animation[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
2728 if (victim->id != 0 || difficulty == 2) {
2729 victim->frameTarget = 0;
2730 victim->animTarget = staggerbackhardanim;
2731 victim->targetyaw = targetyaw + 180;
2735 victim->lowreversaldelay = 0;
2736 victim->highreversaldelay = 0;
2737 if (aitype != playercontrolled)
2738 weaponmissdelay = .6;
2740 if (tutoriallevel != 1)
2741 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2742 weapons[weaponids[weaponactive]].bloody = 1;
2743 if (tutoriallevel != 1)
2744 weapons[weaponids[weaponactive]].blooddrip += 3;
2746 XYZ footvel, footpoint;
2748 if (skeleton.free) {
2749 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2751 if (!skeleton.free) {
2752 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2754 if (tutoriallevel != 1) {
2756 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .6, .3);
2757 footvel = DoRotation(facing, 0, 90, 0) * .8;
2759 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2760 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2761 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
2762 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
2764 if (tutoriallevel == 1) {
2765 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .6, .3);
2767 victim->DoDamage(damagemult * 0);
2770 if (animTarget == swordslashanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2771 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) {
2772 if (victim->weaponactive == -1 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) {
2773 award_bonus(id, Slashbonus);
2775 if (tutoriallevel != 1) {
2776 if (normaldotproduct(victim->facing, victim->coords - coords) < 0)
2777 victim->DoBloodBig(2 / victim->armorhigh, 190);
2779 victim->DoBloodBig(2 / victim->armorhigh, 185);
2780 victim->deathbleeding = 1;
2781 emit_sound_at(swordslicesound, victim->coords);
2783 //victim->jointVel(abdomen)+=relative*damagemult*200;
2784 if (tutoriallevel != 1) {
2785 victim->frameTarget = 0;
2786 victim->animTarget = staggerbackhardanim;
2787 victim->targetyaw = targetyaw + 180;
2791 if (tutoriallevel != 1) {
2792 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2793 weapons[weaponids[weaponactive]].bloody = 1;
2794 weapons[weaponids[weaponactive]].blooddrip += 3;
2796 float bloodlossamount;
2797 bloodlossamount = 200 + abs((float)(Random() % 40)) - 20;
2798 victim->bloodloss += bloodlossamount / victim->armorhigh;
2799 //victim->bloodloss+=100*(6.5-distsq(&coords,&victim->coords));
2800 victim->DoDamage(damagemult * 0);
2802 XYZ footvel, footpoint;
2804 if (skeleton.free) {
2805 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2807 if (!skeleton.free) {
2808 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2811 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
2812 footvel = DoRotation(facing, 0, 90, 0) * .8;
2814 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2815 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2816 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
2817 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
2820 if (victim->weaponactive != -1) {
2821 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2822 if (weapons[victim->weaponids[0]].getType() == staff)
2823 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2824 if (weapons[weaponids[0]].getType() == staff)
2825 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2827 emit_sound_at(swordstaffsound, victim->coords);
2829 emit_sound_at(metalhitsound, victim->coords);
2835 victim->Puff(righthand);
2837 victim->frameTarget = 0;
2838 victim->animTarget = staggerbackhighanim;
2839 victim->targetyaw = targetyaw + 180;
2841 weapons[victim->weaponids[0]].owner = -1;
2842 aim = DoRotation(facing, 0, 90, 0) * 21;
2844 weapons[victim->weaponids[0]].velocity = aim * -.2;
2845 weapons[victim->weaponids[0]].tipvelocity = aim;
2846 weapons[victim->weaponids[0]].missed = 1;
2847 weapons[weaponids[0]].hitsomething = 0;
2848 weapons[victim->weaponids[0]].freetime = 0;
2849 weapons[victim->weaponids[0]].firstfree = 1;
2850 weapons[victim->weaponids[0]].physics = 1;
2851 victim->num_weapons--;
2852 if (victim->num_weapons) {
2853 victim->weaponids[0] = victim->weaponids[num_weapons];
2854 if (victim->weaponstuck == victim->num_weapons)
2855 victim->weaponstuck = 0;
2857 victim->weaponactive = -1;
2858 for (unsigned i = 0; i < Person::players.size(); i++) {
2859 Person::players[i]->wentforweapon = 0;
2866 if (animTarget == staffhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2867 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2868 if (tutoriallevel != 1) {
2869 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 250;
2873 if (Random() % 2 || creature == wolftype) {
2876 emit_sound_at(staffheadsound, victim->coords);
2880 relative = victim->coords - coords;
2882 Normalise(&relative);
2883 relative = DoRotation(relative, 0, 90, 0);
2885 Normalise(&relative);
2886 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2887 victim->skeleton.joints[i].velocity += relative * damagemult * 60;
2889 victim->jointVel(head) += relative * damagemult * 230;
2890 victim->jointVel(neck) += relative * damagemult * 230;
2893 if (tutoriallevel != 1) {
2894 victim->DoDamage(damagemult * 120 / victim->protectionhigh);
2896 award_bonus(id, solidhit, 30);
2901 if (animTarget == staffspinhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2902 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2903 if (tutoriallevel != 1) {
2904 weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250;
2908 if (Random() % 2 || creature == wolftype) {
2911 emit_sound_at(staffheadsound, victim->coords);
2915 relative = victim->coords - coords;
2917 Normalise(&relative);
2918 relative = DoRotation(relative, 0, -90, 0);
2919 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2920 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2922 victim->jointVel(head) += relative * damagemult * 220;
2923 victim->jointVel(neck) += relative * damagemult * 220;
2926 if (tutoriallevel != 1) {
2927 victim->DoDamage(damagemult * 350 / victim->protectionhead);
2929 award_bonus(id, solidhit, 60);
2934 if (animTarget == staffgroundsmashanim && animation[animTarget].label[frameCurrent] == 5) {
2935 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) {
2937 if (tutoriallevel != 1) {
2939 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500;
2942 if (Random() % 2 || creature == wolftype) {
2945 emit_sound_at(staffbodysound, victim->coords);
2947 victim->skeleton.longdead = 0;
2948 victim->skeleton.free = 1;
2949 victim->skeleton.broken = 0;
2951 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2952 victim->skeleton.joints[i].velchange = 0;
2953 victim->skeleton.joints[i].locked = 0;
2954 //victim->skeleton.joints[i].velocity=0;
2960 /*relative=victim->coords-coords;
2962 Normalise(&relative);
2963 relative=DoRotation(relative,0,90,0);*/
2965 Normalise(&relative);
2966 if (!victim->dead) {
2967 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2968 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
2971 victim->jointVel(abdomen) += relative * damagemult * 40;
2974 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2975 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
2978 //victim->jointVel(abdomen)+=relative*damagemult*20;
2980 victim->Puff(abdomen);
2981 if (tutoriallevel != 1) {
2982 victim->DoDamage(damagemult * 100 / victim->protectionhigh);
2984 if (!victim->dead) {
2985 award_bonus(id, solidhit, 40);
2991 if (animTarget == lowkickanim && animation[animTarget].label[frameCurrent] == 5) {
2992 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != highheight) {
2997 relative = victim->coords - coords;
2999 Normalise(&relative);
3003 if (animation[victim->animTarget].height == lowheight) {
3009 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3010 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3012 victim->jointVel(head) += relative * damagemult * 200;
3013 if (tutoriallevel != 1) {
3014 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3017 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3018 if (victim->howactive == typesleeping)
3019 victim->DoDamage(damagemult * 150 / victim->protectionhead);
3020 if (creature == wolftype) {
3021 emit_sound_at(clawslicesound, victim->coords, 128.);
3023 victim->DoBloodBig(2 / victim->armorhead, 175);
3026 if (victim->damage >= victim->damagetolerance)
3028 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3029 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3031 victim->jointVel(abdomen) += relative * damagemult * 200;
3032 victim->frameTarget = 0;
3033 victim->animTarget = staggerbackhighanim;
3034 victim->targetyaw = targetyaw + 180;
3036 if (tutoriallevel != 1) {
3037 emit_sound_at(landsound2, victim->coords, 128.);
3039 victim->Puff(abdomen);
3040 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3041 if (creature == wolftype) {
3042 emit_sound_at(clawslicesound, victim->coords, 128.);
3044 victim->DoBloodBig(2 / victim->armorhigh, 170);
3051 if (animTarget == sweepanim && animation[animTarget].label[frameCurrent] == 5) {
3052 if ((victim->animTarget != jumpupanim) &&
3053 (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) &&
3054 (victim != this->shared_from_this())) {
3058 if (tutoriallevel != 1) {
3059 emit_sound_at(landsound2, victim->coords, 128.);
3062 relative = victim->coords - coords;
3064 Normalise(&relative);
3066 if (animation[victim->animTarget].height == middleheight || animation[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
3069 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3070 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
3072 relative = DoRotation(relative, 0, -90, 0);
3074 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3075 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)
3076 victim->skeleton.joints[i].velocity = relative * 80;
3078 victim->Puff(rightankle);
3079 victim->Puff(leftankle);
3080 victim->DoDamage(damagemult * 40 / victim->protectionlow);
3082 if (victim->damage >= victim->damagetolerance)
3084 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3085 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
3087 relative = DoRotation(relative, 0, -90, 0);
3088 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3089 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)
3090 victim->skeleton.joints[i].velocity += relative * damagemult * 80;
3092 victim->jointVel(abdomen) += relative * damagemult * 200;
3093 victim->frameTarget = 0;
3094 victim->animTarget = staggerbackhighanim;
3095 victim->targetyaw = targetyaw + 180;
3097 if (tutoriallevel != 1) {
3098 emit_sound_at(landsound2, victim->coords, 128.);
3100 victim->Puff(abdomen);
3101 victim->DoDamage(damagemult * 30 / victim->protectionlow);
3109 if (animation[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) {
3110 if (animTarget == spinkickreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3118 if (tutoriallevel != 1) {
3119 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3121 if (creature == wolftype) {
3122 emit_sound_at(clawslicesound, victim->coords, 128);
3124 victim->DoBloodBig(2 / victim->armorhigh, 170);
3128 relative = victim->coords - oldcoords;
3130 Normalise(&relative);
3131 //relative=DoRotation(relative,0,-90,0);
3132 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3133 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3135 victim->jointVel(abdomen) += relative * damagemult * 200;
3137 victim->Puff(abdomen);
3138 victim->DoDamage(damagemult * 150 / victim->protectionhigh);
3140 award_bonus(id, Reversal);
3143 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && animation[animTarget].label[frameCurrent] == 5) {
3144 if (victim->weaponactive != -1 && victim->num_weapons > 0) {
3145 if (weapons[victim->weaponids[victim->weaponactive]].owner == int(victim->id)) {
3146 weapons[victim->weaponids[victim->weaponactive]].owner = id;
3148 if (num_weapons > 0) {
3149 weaponids[num_weapons] = weaponids[victim->weaponactive];
3152 weaponids[0] = victim->weaponids[victim->weaponactive];
3153 victim->num_weapons--;
3154 if (victim->num_weapons > 0) {
3155 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
3156 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
3158 victim->weaponactive = -1;
3163 if (animTarget == staffhitreversalanim && animation[animTarget].label[frameCurrent] == 5) {
3171 emit_sound_at(whooshhitsound, victim->coords, 128.);
3174 relative = victim->coords - oldcoords;
3176 Normalise(&relative);
3177 //relative=DoRotation(relative,0,-90,0);
3178 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3179 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3181 victim->jointVel(abdomen) += relative * damagemult * 200;
3184 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3187 if (animTarget == staffspinhitreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3196 award_bonus(id, staffreversebonus);
3198 if (tutoriallevel != 1) {
3199 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3202 award_bonus(id, staffreversebonus); // Huh, again?
3205 relative = victim->coords - oldcoords;
3207 Normalise(&relative);
3208 //relative=DoRotation(relative,0,-90,0);
3209 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3210 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3212 victim->jointVel(abdomen) += relative * damagemult * 200;
3215 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3218 if (animTarget == upunchreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3224 Normalise(&relative);
3227 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3228 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3230 victim->jointVel(lefthand) *= .1;
3231 victim->jointVel(leftwrist) *= .2;
3232 victim->jointVel(leftelbow) *= .5;
3233 victim->jointVel(leftshoulder) *= .7;
3234 victim->jointVel(righthand) *= .1;
3235 victim->jointVel(rightwrist) *= .2;
3236 victim->jointVel(rightelbow) *= .5;
3237 victim->jointVel(rightshoulder) *= .7;
3239 victim->Puff(abdomen);
3240 victim->DoDamage(damagemult * 90 / victim->protectionhigh);
3242 award_bonus(id, Reversal);
3246 if (weaponactive != -1 || creature == wolftype)
3248 if (creature == rabbittype && weaponactive != -1)
3249 if (weapons[weaponids[0]].getType() == staff)
3252 if (weaponactive != -1) {
3253 victim->DoBloodBig(2 / victim->armorhigh, 225);
3254 emit_sound_at(knifeslicesound, victim->coords);
3255 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3256 weapons[weaponids[weaponactive]].bloody = 1;
3257 weapons[weaponids[weaponactive]].blooddrip += 3;
3259 if (weaponactive == -1 && creature == wolftype) {
3261 emit_sound_at(clawslicesound, victim->coords, 128.);
3263 victim->DoBloodBig(2 / victim->armorhigh, 175);
3270 if (animTarget == swordslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3276 Normalise(&relative);
3279 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3280 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3282 victim->jointVel(lefthand) *= .1 - 1;
3283 victim->jointVel(leftwrist) *= .2 - 1;
3284 victim->jointVel(leftelbow) *= .5 - 1;
3285 victim->jointVel(leftshoulder) *= .7 - 1;
3286 victim->jointVel(righthand) *= .1 - 1;
3287 victim->jointVel(rightwrist) *= .2 - 1;
3288 victim->jointVel(rightelbow) *= .5 - 1;
3289 victim->jointVel(rightshoulder) *= .7 - 1;
3291 award_bonus(id, swordreversebonus);
3294 if (hasvictim && animTarget == knifeslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3302 if (tutoriallevel != 1) {
3303 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3307 relative = victim->coords - oldcoords;
3309 Normalise(&relative);
3310 relative = DoRotation(relative, 0, -90, 0);
3311 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3312 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3314 victim->jointVel(abdomen) += relative * damagemult * 200;
3316 victim->Puff(abdomen);
3317 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3319 award_bonus(id, Reversal);
3322 if (hasvictim && animTarget == sneakattackanim && animation[animTarget].label[frameCurrent] == 7) {
3325 victim->skeleton.spinny = 0;
3327 relative = facing * -1;
3329 Normalise(&relative);
3330 if (victim->id == 0)
3332 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3333 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3335 //victim->DoDamage(1000);
3336 victim->damage = victim->damagetolerance;
3337 victim->permanentdamage = victim->damagetolerance - 1;
3340 if (weaponactive != -1 || creature == wolftype)
3342 if (creature == rabbittype && weaponactive != -1)
3343 if (weapons[weaponids[0]].getType() == staff)
3346 if (weaponactive != -1) {
3347 victim->DoBloodBig(200, 225);
3348 emit_sound_at(knifeslicesound, victim->coords);
3350 weapons[weaponids[weaponactive]].bloody = 2;
3351 weapons[weaponids[weaponactive]].blooddrip += 5;
3354 if (creature == wolftype && weaponactive == -1) {
3355 emit_sound_at(clawslicesound, victim->coords, 128.);
3357 victim->DoBloodBig(2, 175);
3360 award_bonus(id, spinecrusher);
3363 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3364 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3366 if (animTarget == knifefollowanim)
3367 victim->DoBloodBig(200, 210);
3368 if (animTarget == knifesneakattackanim) {
3369 /*victim->DoBloodBig(200,195);
3374 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
3375 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck),0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3377 XYZ footvel, footpoint;
3379 footpoint = weapons[weaponids[0]].tippoint;
3381 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3382 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3383 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3384 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3385 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3386 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3387 victim->DoBloodBig(200, 195);
3388 award_bonus(id, tracheotomy);
3390 if (animTarget == knifefollowanim) {
3391 award_bonus(id, Stabbonus);
3392 XYZ footvel, footpoint;
3394 footpoint = weapons[weaponids[0]].tippoint;
3396 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3397 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3398 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3399 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3400 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3401 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3404 victim->bloodloss += 10000;
3405 victim->velocity = 0;
3406 emit_sound_at(fleshstabsound, victim->coords);
3408 weapons[weaponids[weaponactive]].bloody = 2;
3409 weapons[weaponids[weaponactive]].blooddrip += 5;
3413 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 6) {
3415 victim->velocity = 0;
3416 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3417 victim->skeleton.joints[i].velocity = 0;
3419 if (animTarget == knifefollowanim) {
3421 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3422 victim->skeleton.joints[i].velocity = 0;
3425 if (weaponactive != -1 && animation[victim->animTarget].attack != reversal) {
3426 emit_sound_at(fleshstabremovesound, victim->coords);
3428 weapons[weaponids[weaponactive]].bloody = 2;
3429 weapons[weaponids[weaponactive]].blooddrip += 5;
3431 XYZ footvel, footpoint;
3433 footpoint = weapons[weaponids[0]].tippoint;
3435 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3436 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3437 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3438 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3439 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3440 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3444 if (hasvictim && (animTarget == swordsneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3445 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3446 award_bonus(id, backstab);
3450 XYZ footvel, footpoint;
3452 footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2;
3454 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3455 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3456 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3457 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3458 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 5, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3459 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3460 victim->DoBloodBig(200, 180);
3461 victim->DoBloodBig(200, 215);
3462 victim->bloodloss += 10000;
3463 victim->velocity = 0;
3464 emit_sound_at(fleshstabsound, victim->coords);
3466 weapons[weaponids[weaponactive]].bloody = 2;
3467 weapons[weaponids[weaponactive]].blooddrip += 5;
3471 if (hasvictim && animTarget == swordsneakattackanim && animation[animTarget].label[frameCurrent] == 6) {
3473 victim->velocity = 0;
3474 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3475 victim->skeleton.joints[i].velocity = 0;
3477 if (weaponactive != -1) {
3478 emit_sound_at(fleshstabremovesound, victim->coords);
3480 weapons[weaponids[weaponactive]].bloody = 2;
3481 weapons[weaponids[weaponactive]].blooddrip += 5;
3483 XYZ footvel, footpoint;
3485 footpoint = weapons[weaponids[0]].tippoint;
3487 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3488 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3489 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3490 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3491 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3492 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3496 if (animTarget == sweepreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3504 if (weaponactive == -1) {
3505 if (tutoriallevel != 1) {
3506 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3511 if (weaponactive != -1 || creature == wolftype)
3513 if (creature == rabbittype && weaponactive != -1)
3514 if (weapons[weaponids[0]].getType() == staff)
3517 if (weaponactive != -1) {
3518 victim->DoBloodBig(2 / victim->armorhead, 225);
3519 emit_sound_at(knifeslicesound, victim->coords);
3520 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3521 weapons[weaponids[weaponactive]].bloody = 1;
3522 weapons[weaponids[weaponactive]].blooddrip += 3;
3524 if (weaponactive == -1 && creature == wolftype) {
3525 emit_sound_at(clawslicesound, victim->coords, 128.);
3527 victim->DoBloodBig(2 / victim->armorhead, 175);
3531 award_bonus(id, Reversal);
3536 //relative=victim->coords-oldcoords;
3537 relative = facing * -1;
3539 Normalise(&relative);
3540 relative = DoRotation(relative, 0, 90, 0);
3542 Normalise(&relative);
3543 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3544 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3546 victim->jointVel(head) += relative * damagemult * 200;
3547 if (victim->damage < victim->damagetolerance - 100)
3548 victim->velocity = relative * 200;
3549 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3550 victim->velocity = 0;
3553 if (animTarget == sweepreversalanim && ((animation[animTarget].label[frameCurrent] == 9 && victim->damage < victim->damagetolerance) || (animation[animTarget].label[frameCurrent] == 7 && victim->damage > victim->damagetolerance))) {
3557 //relative=victim->coords-oldcoords;
3558 relative = facing * -1;
3560 Normalise(&relative);
3561 relative = DoRotation(relative, 0, 90, 0);
3563 Normalise(&relative);
3564 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3565 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3567 victim->jointVel(head) += relative * damagemult * 200;
3570 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim))
3571 if (victim->damage > victim->damagetolerance && bonus != reverseko) {
3572 award_bonus(id, reverseko);
3578 if (frameTarget > animation[animCurrent].numframes - 1) {
3581 animTarget = getIdle();
3585 if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) {
3586 animTarget = rollanim;
3588 emit_sound_at(movewhooshsound, coords, 128.);
3590 if (animCurrent == staggerbackhighanim) {
3591 animTarget = getIdle();
3593 if (animCurrent == staggerbackhardanim) {
3594 animTarget = getIdle();
3596 if (animCurrent == removeknifeanim) {
3597 animTarget = getIdle();
3599 if (animCurrent == crouchremoveknifeanim) {
3600 animTarget = getCrouch();
3602 if (animCurrent == backhandspringanim) {
3603 animTarget = getIdle();
3605 if (animCurrent == dodgebackanim) {
3606 animTarget = getIdle();
3608 if (animCurrent == drawleftanim) {
3609 animTarget = getIdle();
3611 if (animCurrent == drawrightanim || animCurrent == crouchdrawrightanim) {
3612 animTarget = getIdle();
3613 if (animCurrent == crouchdrawrightanim) {
3614 animTarget = getCrouch();
3616 if (weaponactive == -1)
3618 else if (weaponactive == 0) {
3620 if (num_weapons == 2) {
3622 buffer = weaponids[0];
3623 weaponids[0] = weaponids[1];
3624 weaponids[1] = buffer;
3628 if (weaponactive == -1) {
3629 emit_sound_at(knifesheathesound, coords, 128.);
3631 if (weaponactive != -1) {
3632 emit_sound_at(knifedrawsound, coords, 128.);
3635 if (animCurrent == rollanim) {
3636 animTarget = getCrouch();
3641 if (animTarget == walljumprightkickanim) {
3644 if (animTarget == walljumpleftkickanim) {
3647 animTarget = jumpdownanim;
3649 if (animCurrent == climbanim) {
3650 animTarget = getCrouch();
3652 coords += facing * .1;
3653 if (!isnormal(coords.x))
3664 if (animTarget == rabbitkickreversalanim) {
3665 animTarget = getCrouch();
3668 if (animTarget == jumpreversalanim) {
3669 animTarget = getCrouch();
3672 if (animTarget == walljumprightanim || animTarget == walljumpbackanim || animTarget == walljumpfrontanim) {
3673 if (attackkeydown && animTarget != walljumpfrontanim) {
3675 float closestdist = -1;
3677 if (Person::players.size() > 1)
3678 for (unsigned i = 0; i < Person::players.size(); i++) {
3679 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3680 distance = distsq(&Person::players[i]->coords, &coords);
3681 if (closestdist == -1 || distance < closestdist) {
3682 closestdist = distance;
3687 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3688 victim = Person::players[closest];
3689 animTarget = walljumprightkickanim;
3691 XYZ rotatetarget = victim->coords - coords;
3692 Normalise(&rotatetarget);
3693 yaw = -asin(0 - rotatetarget.x);
3695 if (rotatetarget.z < 0)
3697 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3698 velocity = (victim->coords - coords) * 4;
3703 if (animTarget == walljumpbackanim) {
3704 animTarget = backflipanim;
3706 velocity = facing * -8;
3709 resume_stream(whooshsound);
3711 if (animTarget == walljumprightanim) {
3712 animTarget = rightflipanim;
3716 velocity = DoRotation(facing, 0, 30, 0) * -8;
3719 if (animTarget == walljumpfrontanim) {
3720 animTarget = frontflipanim;
3724 velocity = facing * 8;
3728 resume_stream(whooshsound);
3730 if (animTarget == walljumpleftanim) {
3731 if (attackkeydown) {
3733 float closestdist = -1;
3735 if (Person::players.size() > 1)
3736 for (unsigned i = 0; i < Person::players.size(); i++) {
3737 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3738 distance = distsq(&Person::players[i]->coords, &coords);
3739 if (closestdist == -1 || distance < closestdist) {
3740 closestdist = distance;
3745 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3746 victim = Person::players[closest];
3747 animTarget = walljumpleftkickanim;
3749 XYZ rotatetarget = victim->coords - coords;
3750 Normalise(&rotatetarget);
3751 yaw = -asin(0 - rotatetarget.x);
3753 if (rotatetarget.z < 0)
3755 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3756 velocity = (victim->coords - coords) * 4;
3761 if (animTarget != walljumpleftkickanim) {
3762 animTarget = leftflipanim;
3766 velocity = DoRotation(facing, 0, -30, 0) * -8;
3770 resume_stream(whooshsound);
3772 if (animTarget == sneakattackanim) {
3773 animCurrent = getCrouch();
3774 animTarget = getCrouch();
3781 transspeed = 1000000;
3782 targetheadyaw += 180;
3783 coords -= facing * .7;
3785 coords.y = terrain.getHeight(coords.x, coords.z);
3789 if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) {
3790 animTarget = getIdle();
3793 coords.y = terrain.getHeight(coords.x, coords.z);
3797 if (animCurrent == knifefollowanim) {
3798 animTarget = getIdle();
3801 if (animation[animTarget].attack == reversal && animCurrent != sneakattackanim && animCurrent != knifesneakattackanim && animCurrent != swordsneakattackanim && animCurrent != knifefollowanim) {
3802 float ycoords = oldcoords.y;
3803 animTarget = getStop();
3808 transspeed = 1000000;
3809 targetheadyaw += 180;
3810 if (!isnormal(coords.x))
3812 if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim)
3813 oldcoords = coords + facing * .5;
3814 else if (animCurrent == sweepreversalanim)
3815 oldcoords = coords + facing * 1.1;
3816 else if (animCurrent == upunchreversalanim) {
3817 oldcoords = coords + facing * 1.5;
3820 targetheadyaw += 180;
3823 } else if (animCurrent == knifeslashreversalanim) {
3824 oldcoords = coords + facing * .5;
3827 targetheadyaw += 90;
3830 } else if (animCurrent == staffspinhitreversalanim) {
3833 targetheadyaw += 180;
3838 oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z);
3840 oldcoords.y = ycoords;
3841 currentoffset = coords - oldcoords;
3847 if (animCurrent == knifesneakattackedanim || animCurrent == swordsneakattackedanim) {
3852 if (animation[animTarget].attack == reversed) {
3854 if (animTarget == sweepreversedanim)
3856 animTarget = backhandspringanim;
3858 emit_sound_at(landsound, coords, 128);
3860 if (animCurrent == upunchreversedanim || animCurrent == swordslashreversedanim) {
3861 animTarget = rollanim;
3864 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3865 coords.y = oldcoords.y;
3867 if (animCurrent == knifeslashreversedanim) {
3868 animTarget = rollanim;
3873 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3874 coords.y = oldcoords.y;
3878 animTarget = jumpdownanim;
3881 animTarget = getIdle();
3883 animTarget = getIdle();
3884 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
3885 animTarget = getIdle();
3887 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3888 coords.y = oldcoords.y;
3889 //coords+=DoRotation(animation[animCurrent].offset,0,yaw,0)*scale;
3890 targetoffset.y = coords.y;
3892 targetoffset.y = terrain.getHeight(coords.x, coords.z);
3893 currentoffset = DoRotation(animation[animCurrent].offset * -1, 0, yaw, 0) * scale;
3894 currentoffset.y -= (coords.y - targetoffset.y);
3895 coords.y = targetoffset.y;
3897 normalsupdatedelay = 0;
3899 if (animCurrent == upunchanim) {
3900 animTarget = getStop();
3901 normalsupdatedelay = 0;
3904 if (animCurrent == rabbitkickanim && animTarget != backflipanim) {
3908 if (num_weapons > 0)
3909 if (weapons[0].getType() == staff)
3915 rabbitkickragdoll = 1;
3917 if (animCurrent == rabbitkickreversedanim) {
3923 skeleton.spinny = 0;
3924 SolidHitBonus(!id); // FIXME: tricky id
3928 animTarget = rollanim;
3931 pause_sound(whooshsound);
3935 if (animCurrent == rabbittackledbackanim || animCurrent == rabbittackledfrontanim) {
3939 skeleton.spinny = 0;
3941 if (animCurrent == jumpreversedanim) {
3947 skeleton.spinny = 0;
3948 SolidHitBonus(!id); // FIXME: tricky id
3952 animTarget = rollanim;
3953 coords += facing * 2;
3955 pause_sound(whooshsound);
3960 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) {
3961 animTarget = getupfromfrontanim;
3963 } else if (animation[animCurrent].attack == normalattack) {
3964 animTarget = getIdle();
3967 if (animCurrent == blockhighleftanim && aitype != playercontrolled) {
3968 animTarget = blockhighleftstrikeanim;
3970 if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) {
3971 animTarget = getIdle();
3974 if (animCurrent == spinkickanim && victim->skeleton.free) {
3975 if (creature == rabbittype)
3976 animTarget = fightidleanim;
3981 if (isIdle() && !wasIdle())
3982 normalsupdatedelay = 0;
3984 if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) {
3985 animTarget = jumpdownanim;
3988 if (!skeleton.free) {
3990 if (!transspeed && animation[animTarget].attack != 2 && animation[animTarget].attack != 3) {
3991 if (!isRun() || !wasRun()) {
3992 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
3993 target += multiplier * animation[animTarget].speed[frameTarget] * speed * 2;
3994 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
3995 target += multiplier * animation[animCurrent].speed[frameCurrent] * speed * 2;
3997 if (isRun() && wasRun()) {
3999 tempspeed = velspeed;
4000 if (tempspeed < 10 * speedmult)
4001 tempspeed = 10 * speedmult;
4002 target += multiplier * animation[animTarget].speed[frameCurrent] * speed * 1.7 * tempspeed / (speed * 45 * scale);
4004 } else if (transspeed)
4005 target += multiplier * transspeed * speed * 2;
4007 if (!isRun() || !wasRun()) {
4008 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
4009 target += multiplier * animation[animTarget].speed[frameTarget] * 2;
4010 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
4011 target += multiplier * animation[animCurrent].speed[frameCurrent] * 2;
4015 if (animCurrent != animTarget)
4016 target = (target + oldtarget) / 2;
4019 frameCurrent = frameTarget;
4023 rot = targetrot * target;
4024 yaw += rot - oldrot;
4030 if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
4032 for (int i = 0; i < skeleton.num_joints; i++) {
4033 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent];
4036 skeleton.FindForwards();
4038 for (int i = 0; i < skeleton.num_muscles; i++) {
4039 if (skeleton.muscles[i].visible) {
4040 skeleton.FindRotationMuscle(i, animTarget);
4043 for (int i = 0; i < skeleton.num_muscles; i++) {
4044 if (skeleton.muscles[i].visible) {
4045 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
4046 skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4047 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
4048 skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4049 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
4050 skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4055 for (int i = 0; i < skeleton.num_joints; i++) {
4056 skeleton.joints[i].position = animation[animTarget].position[i][frameTarget];
4059 skeleton.FindForwards();
4061 for (int i = 0; i < skeleton.num_muscles; i++) {
4062 if (skeleton.muscles[i].visible) {
4063 skeleton.FindRotationMuscle(i, animTarget);
4066 for (int i = 0; i < skeleton.num_muscles; i++) {
4067 if (skeleton.muscles[i].visible) {
4068 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
4069 skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
4070 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
4071 skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
4072 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
4073 skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
4074 if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) skeleton.muscles[i].newrotate3 -= 360;
4075 if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) skeleton.muscles[i].newrotate3 += 360;
4076 if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) skeleton.muscles[i].newrotate2 -= 360;
4077 if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) skeleton.muscles[i].newrotate2 += 360;
4078 if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) skeleton.muscles[i].newrotate1 -= 360;
4079 if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) skeleton.muscles[i].newrotate1 += 360;
4083 if (frameCurrent >= animation[animCurrent].numframes)
4084 frameCurrent = animation[animCurrent].numframes - 1;
4086 oldanimCurrent = animCurrent;
4087 oldanimTarget = animTarget;
4088 oldframeTarget = frameTarget;
4089 oldframeCurrent = frameCurrent;
4091 for (int i = 0; i < skeleton.num_joints; i++) {
4092 skeleton.joints[i].velocity = (animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target) - skeleton.joints[i].position) / multiplier;
4093 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target);
4095 offset = currentoffset * (1 - target) + targetoffset * target;
4096 for (int i = 0; i < skeleton.num_muscles; i++) {
4097 if (skeleton.muscles[i].visible) {
4098 skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * (target);
4099 skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * (target);
4100 skeleton.muscles[i].rotate3 = skeleton.muscles[i].oldrotate3 * (1 - target) + skeleton.muscles[i].newrotate3 * (target);
4105 if (isLanding() && landhard) {
4108 animTarget = getLandhard();
4115 //skeleton.DoConstraints();
4122 void Person::DoStuff()
4124 static XYZ terrainnormal;
4125 static XYZ flatfacing;
4126 static XYZ flatvelocity;
4127 static float flatvelspeed;
4131 static int bloodsize;
4132 static int startx, starty, endx, endy;
4133 static GLubyte color;
4134 static XYZ bloodvel;
4136 onfiredelay -= multiplier;
4137 if (onfiredelay < 0 && onfire) {
4138 if (Random() % 2 == 0) {
4144 crouchkeydowntime += multiplier;
4146 crouchkeydowntime = 0;
4147 jumpkeydowntime += multiplier;
4148 if (!jumpkeydown && skeleton.free)
4149 jumpkeydowntime = 0;
4151 if (hostile || damage > 0 || bloodloss > 0)
4154 if (isIdle() || isRun())
4157 if (num_weapons == 1 && weaponactive != -1)
4161 blooddimamount -= multiplier * .3;
4162 speechdelay -= multiplier;
4163 texupdatedelay -= multiplier;
4164 interestdelay -= multiplier;
4165 flamedelay -= multiplier;
4166 parriedrecently -= multiplier;
4168 victim = this->shared_from_this();
4173 speed = 1.1 * speedmult;
4175 speed = 1.0 * speedmult;
4177 rabbitkickragdoll = 0;
4181 if (id != 0 && (creature == rabbittype || difficulty != 2))
4183 if (id != 0 && creature == wolftype && difficulty == 2) {
4185 if (aitype != passivetype) {
4187 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) {
4193 if (animTarget == wolfrunninganim && !superruntoggle) {
4194 animTarget = getRun();
4198 if (weaponactive == -1 && num_weapons > 0) {
4199 if (weapons[weaponids[0]].getType() == staff) {
4205 burnt += multiplier;
4206 /*if(aitype!=playercontrolled)*///deathbleeding=5;
4207 /*if(aitype!=playercontrolled)*/
4211 OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3);
4213 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
4219 vel[0] = velocity.x;
4220 vel[1] = velocity.y;
4221 vel[2] = velocity.z;
4224 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4225 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
4229 while (flamedelay < 0 && onfire) {
4231 howmany = abs(Random() % (skeleton.num_joints));
4233 flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4235 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4237 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4239 flatfacing = skeleton.joints[howmany].position * scale + coords;
4240 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
4243 while (flamedelay < 0 && !onfire && tutoriallevel == 1 && id != 0) {
4245 howmany = abs(Random() % (skeleton.num_joints));
4247 flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4249 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4251 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4253 flatfacing = skeleton.joints[howmany].position * scale + coords;
4254 Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
4258 bleeding -= multiplier * .3;
4259 if (bloodtoggle == 2) {
4260 skeleton.drawmodel.textureptr.bind();
4261 if (bleeding <= 0 && (detail != 2 || osx))
4266 if (neckspurtamount > 0) {
4267 neckspurtamount -= multiplier;
4268 neckspurtdelay -= multiplier * 3;
4269 neckspurtparticledelay -= multiplier * 3;
4270 if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
4273 if (!skeleton.free) {
4274 bloodvel.z = 5 * neckspurtamount;
4275 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4277 if (skeleton.free) {
4278 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
4281 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4283 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
4285 Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4287 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4288 neckspurtparticledelay = .05;
4290 if (neckspurtdelay < 0) {
4295 if (deathbleeding > 0 && dead != 2) {
4296 if (deathbleeding < 5)
4297 bleeddelay -= deathbleeding * multiplier / 4;
4299 bleeddelay -= 5 * multiplier / 4;
4300 if (bleeddelay < 0 && bloodtoggle) {
4306 bloodvel += DoRotation(jointVel(abdomen), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
4308 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
4310 Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4312 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
4315 bloodloss += deathbleeding * multiplier * 80;
4316 deathbleeding -= multiplier * 1.6;
4317 //if(id==0)deathbleeding-=multiplier*.2;
4318 if (deathbleeding < 0)
4320 if (bloodloss > damagetolerance && animation[animTarget].attack == neutral) {
4321 if (weaponactive != -1) {
4322 weapons[weaponids[0]].owner = -1;
4323 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4324 weapons[weaponids[0]].velocity.x += .01;
4325 weapons[weaponids[0]].tipvelocity = velocity * scale;
4326 weapons[weaponids[0]].missed = 1;
4327 weapons[weaponids[0]].hitsomething = 0;
4328 weapons[weaponids[0]].freetime = 0;
4329 weapons[weaponids[0]].firstfree = 1;
4330 weapons[weaponids[0]].physics = 1;
4333 weaponids[0] = weaponids[num_weapons];
4334 if (weaponstuck == num_weapons)
4338 for (unsigned i = 0; i < Person::players.size(); i++) {
4339 Person::players[i]->wentforweapon = 0;
4351 if (!dead && creature == wolftype) {
4352 award_bonus(0, Wolfbonus);
4355 if (animTarget == knifefollowedanim && !skeleton.free) {
4356 for (int i = 0; i < skeleton.num_joints; i++) {
4357 skeleton.joints[i].velocity = 0;
4358 skeleton.joints[i].velocity.y = -2;
4361 if (id != 0 && unconscioustime > .1) {
4369 if (texupdatedelay < 0 && bleeding > 0 && bloodtoggle == 2 && distsq(&viewer, &coords) < 9) {
4370 texupdatedelay = .12;
4372 bloodsize = 5 - realtexdetail;
4376 startx = bleedy; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4377 starty = bleedx; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4378 endx = startx + bloodsize;
4379 endy = starty + bloodsize;
4389 if (endx > skeleton.skinsize - 1) {
4390 endx = skeleton.skinsize - 1;
4393 if (endy > skeleton.skinsize - 1) {
4394 endy = skeleton.skinsize - 1;
4402 for (i = startx; i < endx; i++) {
4403 for (j = starty; j < endy; j++) {
4404 if (Random() % 2 == 0) {
4405 color = Random() % 85 + 170;
4406 if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2)
4407 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2;
4408 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0;
4409 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0;
4413 if (!osx && detail > 1) {
4414 skeleton.drawmodel.textureptr.bind();
4418 if (!skeleton.free) {
4419 bleedy -= 4 / realtexdetail;
4421 bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4423 bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4425 if (skeleton.free) {
4426 bleedx += 4 * direction / realtexdetail;
4428 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4430 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4434 if (abs(righthandmorphness - targetrighthandmorphness) < multiplier * 4) {
4435 righthandmorphness = targetrighthandmorphness;
4436 righthandmorphstart = righthandmorphend;
4437 } else if (righthandmorphness > targetrighthandmorphness) {
4438 righthandmorphness -= multiplier * 4;
4439 } else if (righthandmorphness < targetrighthandmorphness) {
4440 righthandmorphness += multiplier * 4;
4443 if (abs(lefthandmorphness - targetlefthandmorphness) < multiplier * 4) {
4444 lefthandmorphness = targetlefthandmorphness;
4445 lefthandmorphstart = lefthandmorphend;
4446 } else if (lefthandmorphness > targetlefthandmorphness) {
4447 lefthandmorphness -= multiplier * 4;
4448 } else if (lefthandmorphness < targetlefthandmorphness) {
4449 lefthandmorphness += multiplier * 4;
4452 if (creature == rabbittype || targettailmorphness == 5 || targettailmorphness == 0) {
4453 if (abs(tailmorphness - targettailmorphness) < multiplier * 10) {
4454 tailmorphness = targettailmorphness;
4455 tailmorphstart = tailmorphend;
4456 } else if (tailmorphness > targettailmorphness) {
4457 tailmorphness -= multiplier * 10;
4458 } else if (tailmorphness < targettailmorphness) {
4459 tailmorphness += multiplier * 10;
4463 if (creature == wolftype) {
4464 if (abs(tailmorphness - targettailmorphness) < multiplier * 4) {
4465 tailmorphness = targettailmorphness;
4466 tailmorphstart = tailmorphend;
4467 } else if (tailmorphness > targettailmorphness) {
4468 tailmorphness -= multiplier * 2;
4469 } else if (tailmorphness < targettailmorphness) {
4470 tailmorphness += multiplier * 2;
4474 if (headmorphend == 3 || headmorphstart == 3) {
4475 if (abs(headmorphness - targetheadmorphness) < multiplier * 7) {
4476 headmorphness = targetheadmorphness;
4477 headmorphstart = headmorphend;
4478 } else if (headmorphness > targetheadmorphness) {
4479 headmorphness -= multiplier * 7;
4480 } else if (headmorphness < targetheadmorphness) {
4481 headmorphness += multiplier * 7;
4483 } else if (headmorphend == 5 || headmorphstart == 5) {
4484 if (abs(headmorphness - targetheadmorphness) < multiplier * 10) {
4485 headmorphness = targetheadmorphness;
4486 headmorphstart = headmorphend;
4487 } else if (headmorphness > targetheadmorphness) {
4488 headmorphness -= multiplier * 10;
4489 } else if (headmorphness < targetheadmorphness) {
4490 headmorphness += multiplier * 10;
4493 if (abs(headmorphness - targetheadmorphness) < multiplier * 4) {
4494 headmorphness = targetheadmorphness;
4495 headmorphstart = headmorphend;
4496 } else if (headmorphness > targetheadmorphness) {
4497 headmorphness -= multiplier * 4;
4498 } else if (headmorphness < targetheadmorphness) {
4499 headmorphness += multiplier * 4;
4503 if (abs(chestmorphness - targetchestmorphness) < multiplier) {
4504 chestmorphness = targetchestmorphness;
4505 chestmorphstart = chestmorphend;
4506 } else if (chestmorphness > targetchestmorphness) {
4507 chestmorphness -= multiplier;
4508 } else if (chestmorphness < targetchestmorphness) {
4509 chestmorphness += multiplier;
4512 if (dead != 2 && howactive <= typesleeping) {
4513 if (chestmorphstart == 0 && chestmorphend == 0) {
4515 targetchestmorphness = 1;
4518 if (chestmorphstart != 0 && chestmorphend != 0) {
4520 targetchestmorphness = 1;
4522 if (environment == snowyenvironment) {
4526 footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
4528 footvel = skeleton.specialforward[0] * -1;
4530 footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
4532 footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
4533 if (animTarget == sleepanim)
4534 footvel = DoRotation(footvel, 0, 90, 0);
4535 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
4539 if (!dead && howactive < typesleeping) {
4540 blinkdelay -= multiplier * 2;
4541 if (headmorphstart == 0 && headmorphend == 0 && blinkdelay <= 0) {
4543 targetheadmorphness = 1;
4545 blinkdelay = (float)(abs(Random() % 40)) / 5;
4547 if (headmorphstart == 3 && headmorphend == 3) {
4549 targetheadmorphness = 1;
4554 twitchdelay -= multiplier * 1.5;
4555 if (animTarget != hurtidleanim) {
4556 if (headmorphstart == 0 && headmorphend == 0 && twitchdelay <= 0) {
4558 targetheadmorphness = 1;
4560 twitchdelay = (float)(abs(Random() % 40)) / 5;
4562 if (headmorphstart == 5 && headmorphend == 5) {
4564 targetheadmorphness = 1;
4568 if ((isIdle() || isCrouch()) && animTarget != hurtidleanim) {
4569 twitchdelay3 -= multiplier * 1;
4570 if (Random() % 2 == 0) {
4571 if (righthandmorphstart == 0 && righthandmorphend == 0 && twitchdelay3 <= 0) {
4572 righthandmorphness = 0;
4573 targetrighthandmorphness = 1;
4574 righthandmorphend = 1;
4575 if (Random() % 2 == 0)twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4577 if (righthandmorphstart == 1 && righthandmorphend == 1) {
4578 righthandmorphness = 0;
4579 targetrighthandmorphness = 1;
4580 righthandmorphend = 0;
4583 if (Random() % 2 == 0) {
4584 if (lefthandmorphstart == 0 && lefthandmorphend == 0 && twitchdelay3 <= 0) {
4585 lefthandmorphness = 0;
4586 targetlefthandmorphness = 1;
4587 lefthandmorphend = 1;
4588 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4590 if (lefthandmorphstart == 1 && lefthandmorphend == 1) {
4591 lefthandmorphness = 0;
4592 targetlefthandmorphness = 1;
4593 lefthandmorphend = 0;
4599 if (creature == rabbittype) {
4600 if (howactive < typesleeping)
4601 twitchdelay2 -= multiplier * 1.5;
4603 twitchdelay2 -= multiplier * 0.5;
4604 if (howactive <= typesleeping) {
4605 if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) {
4607 targettailmorphness = 1;
4609 twitchdelay2 = (float)(abs(Random() % 40)) / 5;
4611 if (tailmorphstart == 1 && tailmorphend == 1) {
4613 targettailmorphness = 1;
4616 if (tailmorphstart == 2 && tailmorphend == 2) {
4618 targettailmorphness = 1;
4625 if (creature == wolftype) {
4626 twitchdelay2 -= multiplier * 1.5;
4627 if (tailmorphend != 0)
4628 if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) {
4630 targettailmorphness = 1;
4634 if (tailmorphend != 5)
4635 if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) {
4637 targettailmorphness = 1;
4641 if (twitchdelay2 <= 0) {
4642 if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) {
4644 targettailmorphness = 1;
4647 if (tailmorphstart == 1 && tailmorphend == 1) {
4649 targettailmorphness = 1;
4652 if (tailmorphstart == 2 && tailmorphend == 2) {
4654 targettailmorphness = 1;
4657 if (tailmorphstart == 3 && tailmorphend == 3) {
4659 targettailmorphness = 1;
4662 if (tailmorphstart == 4 && tailmorphend == 4) {
4664 targettailmorphness = 1;
4671 unconscioustime = 0;
4673 if (dead == 1 || howactive == typesleeping) {
4674 unconscioustime += multiplier;
4675 //If unconscious, close eyes and mouth
4676 if (righthandmorphend != 0)
4677 righthandmorphness = 0;
4678 righthandmorphend = 0;
4679 targetrighthandmorphness = 1;
4681 if (lefthandmorphend != 0)
4682 lefthandmorphness = 0;
4683 lefthandmorphend = 0;
4684 targetlefthandmorphness = 1;
4686 if (headmorphend != 3 && headmorphend != 5)
4689 targetheadmorphness = 1;
4693 if (howactive > typesleeping) {
4696 if (bloodtoggle && !bled) {
4697 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4699 if (bloodtoggle && !bled)
4700 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4701 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4702 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4706 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4711 if (dead == 2 || howactive > typesleeping) {
4712 //If dead, open mouth and hands
4713 if (righthandmorphend != 0)
4714 righthandmorphness = 0;
4715 righthandmorphend = 0;
4716 targetrighthandmorphness = 1;
4718 if (lefthandmorphend != 0)
4719 lefthandmorphness = 0;
4720 lefthandmorphend = 0;
4721 targetlefthandmorphness = 1;
4723 if (headmorphend != 2)
4726 targetheadmorphness = 1;
4729 if (stunned > 0 && !dead && headmorphend != 2) {
4730 if (headmorphend != 4)
4733 targetheadmorphness = 1;
4736 if (damage > damagetolerance && !dead) {
4739 unconscioustime = 0;
4741 if (creature == wolftype) {
4742 award_bonus(0, Wolfbonus);
4747 if (weaponactive != -1) {
4748 weapons[weaponids[0]].owner = -1;
4749 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4750 weapons[weaponids[0]].velocity.x += .01;
4751 weapons[weaponids[0]].tipvelocity = velocity * scale;
4752 weapons[weaponids[0]].missed = 1;
4753 weapons[weaponids[0]].hitsomething = 0;
4754 weapons[weaponids[0]].freetime = 0;
4755 weapons[weaponids[0]].firstfree = 1;
4756 weapons[weaponids[0]].physics = 1;
4759 weaponids[0] = weaponids[num_weapons];
4760 if (weaponstuck == num_weapons)
4764 for (unsigned i = 0; i < Person::players.size(); i++) {
4765 Person::players[i]->wentforweapon = 0;
4771 if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) {
4779 //if(dead)damage-=multiplier/4;
4781 damage -= multiplier * 13;
4782 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4784 permanentdamage -= multiplier * 4;
4785 if (isIdle() || isCrouch()) {
4787 permanentdamage -= multiplier * 4;
4788 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4792 if (permanentdamage < 0)
4793 permanentdamage = 0;
4794 if (superpermanentdamage < 0)
4795 superpermanentdamage = 0;
4796 if (permanentdamage < superpermanentdamage) {
4797 permanentdamage = superpermanentdamage;
4799 if (damage < permanentdamage) {
4800 damage = permanentdamage;
4802 if (dead == 1 && damage < damagetolerance) {
4806 for (int i = 0; i < skeleton.num_joints; i++) {
4807 skeleton.joints[i].velocity = 0;
4810 if (permanentdamage > damagetolerance && dead != 2) {
4813 if (weaponactive != -1) {
4814 weapons[weaponids[0]].owner = -1;
4815 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4816 weapons[weaponids[0]].velocity.x += .01;
4817 weapons[weaponids[0]].tipvelocity = velocity * scale;
4818 weapons[weaponids[0]].missed = 1;
4819 weapons[weaponids[0]].hitsomething = 0;
4820 weapons[weaponids[0]].freetime = 0;
4821 weapons[weaponids[0]].firstfree = 1;
4822 weapons[weaponids[0]].physics = 1;
4825 weaponids[0] = weaponids[num_weapons];
4826 if (weaponstuck == num_weapons)
4830 for (unsigned i = 0; i < Person::players.size(); i++) {
4831 Person::players[i]->wentforweapon = 0;
4837 if (!dead && creature == wolftype) {
4838 award_bonus(0, Wolfbonus);
4841 if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance)
4842 award_bonus(id, touchofdeath);
4843 if (id != 0 && unconscioustime > .1) {
4851 emit_sound_at(breaksound, coords);
4854 if (skeleton.free == 1) {
4856 pause_sound(whooshsound);
4859 //If knocked over, open hands and close mouth
4860 if (righthandmorphend != 0)
4861 righthandmorphness = 0;
4862 righthandmorphend = 0;
4863 targetrighthandmorphness = 1;
4865 if (lefthandmorphend != 0)
4866 lefthandmorphness = 0;
4867 lefthandmorphend = 0;
4868 targetlefthandmorphness = 1;
4870 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) {
4871 if (headmorphend != 0)
4874 targetheadmorphness = 1;
4878 skeleton.DoGravity(&scale);
4880 damageamount = skeleton.DoConstraints(&coords, &scale) * 5;
4881 if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1))
4882 award_bonus(id, deepimpact);
4883 DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3));
4887 for (j = 0; j < skeleton.num_joints; j++) {
4888 average += skeleton.joints[j].position;
4892 coords += average * scale;
4893 for (j = 0; j < skeleton.num_joints; j++) {
4894 skeleton.joints[j].position -= average;
4896 average /= multiplier;
4898 //velocity=jointVel(groin)*scale;
4900 for (int i = 0; i < skeleton.num_joints; i++) {
4901 velocity += skeleton.joints[i].velocity * scale;
4903 velocity /= skeleton.num_joints;
4905 if (!isnormal(velocity.x) && velocity.x) {
4909 if (findLength(&average) < 10 && dead && skeleton.free) {
4910 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
4911 if (skeleton.longdead > 2000) {
4912 if (skeleton.longdead > 6000) {
4914 pause_sound(whooshsound);
4919 if (dead == 2 && bloodloss < damagetolerance) {
4921 headpoint = (jointPos(head) + jointPos(neck)) / 2 * scale + coords;
4923 if (bloodtoggle && !bled) {
4924 terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
4926 if (bloodtoggle && !bled)
4927 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4928 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4929 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4930 float size = .2 * 1.2;
4933 objects.model[j].MakeDecal(blooddecal, &point, &size, &opacity, &yaw);
4937 if (dead == 2 && bloodloss >= damagetolerance) {
4939 headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords;
4942 if (bloodtoggle && !bled) {
4943 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4945 if (bloodtoggle && !bled)
4946 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4947 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4948 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4952 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4959 if (!dead && crouchkeydown && skeleton.freetime > .5 && id == 0 && skeleton.free) {
4960 bool canrecover = 1;
4961 XYZ startpoint, endpoint, colpoint, colviewer, coltarget;
4962 startpoint = coords;
4965 if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1)
4967 if (velocity.y < -30)
4969 for (i = 0; i < objects.numobjects; i++) {
4970 if (objects.type[i] != treeleavestype && objects.type[i] != bushtype && objects.type[i] != firetype) {
4971 colviewer = startpoint;
4972 coltarget = endpoint;
4973 if (objects.model[i].LineCheck(&colviewer, &coltarget, &colpoint, &objects.position[i], &objects.yaw[i]) != -1)
4982 terrainnormal = jointPos(groin) - jointPos(abdomen);
4983 if (joint(groin).locked && joint(abdomen).locked) {
4984 terrainnormal = jointPos(groin) - jointPos(abdomen);
4985 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
4987 if (joint(abdomen).locked && joint(neck).locked) {
4988 terrainnormal = jointPos(abdomen) - jointPos(neck);
4989 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
4991 if (joint(groin).locked && joint(neck).locked) {
4992 terrainnormal = jointPos(groin) - jointPos(neck);
4993 middle = (jointPos(groin) + jointPos(neck)) / 2;
4995 Normalise(&terrainnormal);
4997 targetyaw = -asin(0 - terrainnormal.x);
4998 targetyaw *= 360 / 6.28;
4999 if (terrainnormal.z < 0)
5000 targetyaw = 180 - targetyaw;
5005 animTarget = flipanim;
5006 crouchtogglekeydown = 1;
5011 animCurrent = tempanim;
5014 //tilt2=targettilt2;
5016 //if(middle.y>0)targetoffset.y=middle.y+1;
5018 for (int i = 0; i < skeleton.num_joints; i++) {
5019 tempanimation.position[i][0] = skeleton.joints[i].position;
5020 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
5025 if (findLength(&average) < 10 && !dead && skeleton.free) {
5026 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
5027 if (skeleton.longdead > (damage + 500) * 1.5) {
5029 pause_sound(whooshsound);
5035 terrainnormal = jointPos(groin) - jointPos(abdomen);
5036 if (joint(groin).locked && joint(abdomen).locked) {
5037 terrainnormal = jointPos(groin) - jointPos(abdomen);
5038 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
5040 if (joint(abdomen).locked && joint(neck).locked) {
5041 terrainnormal = jointPos(abdomen) - jointPos(neck);
5042 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
5044 if (joint(groin).locked && joint(neck).locked) {
5045 terrainnormal = jointPos(groin) - jointPos(neck);
5046 middle = (jointPos(groin) + jointPos(neck)) / 2;
5048 Normalise(&terrainnormal);
5050 targetyaw = -asin(0 - terrainnormal.x);
5051 targetyaw *= 360 / 6.28;
5052 if (terrainnormal.z < 0)
5053 targetyaw = 180 - targetyaw;
5056 targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1;
5059 if (skeleton.forward.y < 0) {
5060 animTarget = getupfrombackanim;
5064 if (skeleton.forward.y > -.3) {
5065 animTarget = getupfromfrontanim;
5073 if ((Random() % 8 == 0 && id != 0 && creature == rabbittype) || (Random() % 2 == 0 && id != 0 && creature == wolftype) || (id == 0 && crouchkeydown && (forwardkeydown || backkeydown || leftkeydown || rightkeydown))) {
5074 animTarget = rollanim;
5075 targetyaw = lookyaw;
5092 if ( !leftkeydown && !rightkeydown)
5099 if (abs(targettilt2) > 50)
5101 animCurrent = tempanim;
5104 tilt2 = targettilt2;
5106 if (middle.y > 0 && animTarget != rollanim)
5107 targetoffset.y = middle.y + 1;
5109 for (int i = 0; i < skeleton.num_joints; i++) {
5110 tempanimation.position[i][0] = skeleton.joints[i].position;
5111 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
5118 if (num_weapons > 0)
5119 if (weapons[0].getType() == staff)
5121 if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) {
5122 if (velocity.y > -30) {
5124 tempvelocity = velocity;
5125 Normalise(&tempvelocity);
5126 targetyaw = -asin(0 - tempvelocity.x);
5127 targetyaw *= 360 / 6.28;
5129 targetyaw = 180 - targetyaw;
5133 if (dotproduct(&skeleton.forward, &tempvelocity) < 0) {
5134 animTarget = rollanim;
5137 animTarget = backhandspringanim;
5143 emit_sound_at(movewhooshsound, coords, 128.);
5145 animCurrent = animTarget;
5146 frameCurrent = frameTarget - 1;
5158 if (skeleton.freefall == 0)
5163 if (aitype != passivetype || skeleton.free == 1)
5164 if (findLengthfast(&velocity) > .1)
5165 for (i = 0; i < objects.numobjects; i++) {
5166 if (objects.type[i] == firetype)
5167 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) {
5169 if (!objects.onfire[i]) {
5170 emit_sound_at(firestartsound, objects.position[i]);
5172 objects.onfire[i] = 1;
5175 if (objects.onfire[i]) {
5180 if (objects.type[i] == bushtype)
5181 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) {
5183 if (!objects.onfire[i]) {
5184 emit_sound_at(firestartsound, objects.position[i]);
5186 objects.onfire[i] = 1;
5190 if (objects.onfire[i]) {
5194 if (objects.messedwith[i] <= 0) {
5198 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5201 envsound[numenvsounds] = coords;
5202 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5203 envsoundlife[numenvsounds] = .4;
5208 if (environment == grassyenvironment)
5209 howmany = findLength(&velocity) * 4;
5210 if (environment == snowyenvironment)
5211 howmany = findLength(&velocity) * 2;
5213 if (environment != desertenvironment)
5214 for (j = 0; j < howmany; j++) {
5215 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5216 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5217 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5220 pos.x += float(abs(Random() % 100) - 50) / 200;
5221 pos.y += float(abs(Random() % 100) - 50) / 200;
5222 pos.z += float(abs(Random() % 100) - 50) / 200;
5223 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);
5224 Sprite::setLastSpriteSpecial(1);
5226 howmany = findLength(&velocity) * 4;
5228 if (environment == snowyenvironment)
5229 for (j = 0; j < howmany; j++) {
5230 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5231 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5232 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5235 pos.x += float(abs(Random() % 100) - 50) / 200;
5236 pos.y += float(abs(Random() % 100) - 50) / 200;
5237 pos.z += float(abs(Random() % 100) - 50) / 200;
5238 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5239 Sprite::setLastSpriteSpecial(2);
5242 objects.rotx[i] += velocity.x * multiplier * 6;
5243 objects.roty[i] += velocity.z * multiplier * 6;
5244 objects.messedwith[i] = .5;
5247 if (objects.type[i] == treeleavestype && environment != desertenvironment) {
5248 if (objects.pitch[i] == 0)
5251 tempcoord = coords - objects.position[i];
5252 tempcoord = DoRotation(tempcoord, 0, -objects.yaw[i], 0);
5253 tempcoord = DoRotation(tempcoord, -objects.pitch[i], 0, 0);
5254 tempcoord += objects.position[i];
5256 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]) {
5257 if (objects.messedwith[i] <= 0) {
5261 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5264 envsound[numenvsounds] = coords;
5265 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5266 envsoundlife[numenvsounds] = .4;
5271 if (environment == grassyenvironment)
5272 howmany = findLength(&velocity) * 4;
5273 if (environment == snowyenvironment)
5274 howmany = findLength(&velocity) * 2;
5276 if (environment != desertenvironment)
5277 for (j = 0; j < howmany; j++) {
5278 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5279 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5280 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5282 pos += velocity * .1;
5284 pos.x += float(abs(Random() % 100) - 50) / 150;
5285 pos.y += float(abs(Random() % 100) - 50) / 150;
5286 pos.z += float(abs(Random() % 100) - 50) / 150;
5287 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);
5288 Sprite::setLastSpriteSpecial(1);
5290 howmany = findLength(&velocity) * 4;
5292 if (environment == snowyenvironment)
5293 for (j = 0; j < howmany; j++) {
5294 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5295 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5296 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5298 pos += velocity * .1;
5300 pos.x += float(abs(Random() % 100) - 50) / 150;
5301 pos.y += float(abs(Random() % 100) - 50) / 150;
5302 pos.z += float(abs(Random() % 100) - 50) / 150;
5303 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5304 Sprite::setLastSpriteSpecial(2);
5307 objects.messedwith[i] = .5;
5312 if (!skeleton.free) {
5315 if ((stunned > 0 || surprised > 0) && Person::players.size() > 2 && aitype != passivetype)
5318 if (aitype != passivetype && victim->skeleton.free && !victim->dead)
5320 if (tutoriallevel == 1 && id != 0)
5322 if (play && aitype != playercontrolled) {
5323 int whichsound = -1;
5324 i = abs(Random() % 4);
5325 if (speechdelay <= 0) {
5326 if (creature == rabbittype) {
5328 whichsound = rabbitchitter;
5330 whichsound = rabbitchitter2;
5332 if (creature == wolftype) {
5334 whichsound = growlsound;
5336 whichsound = growl2sound;
5341 if (whichsound != -1) {
5342 emit_sound_at(whichsound, coords);
5346 if (animTarget == staggerbackhighanim)
5348 if (animTarget == staggerbackhardanim)
5350 staggerdelay -= multiplier;
5351 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
5353 if (velocity.y < -30 && animTarget == jumpdownanim)
5355 if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) {
5356 animTarget = getIdle();
5360 weaponmissdelay -= multiplier;
5361 highreversaldelay -= multiplier;
5362 lowreversaldelay -= multiplier;
5363 lastcollide -= multiplier;
5364 skiddelay -= multiplier;
5365 if (!isnormal(velocity.x) && velocity.x) {
5368 if (!isnormal(targettilt) && targettilt) {
5371 if (!isnormal(targettilt2) && targettilt2) {
5374 if (!isnormal(targetyaw) && targetyaw) {
5378 if (animTarget == bounceidleanim || animTarget == wolfidle || animTarget == walkanim || animTarget == drawrightanim || animTarget == crouchdrawrightanim || animTarget == drawleftanim || animTarget == fightidleanim || animTarget == fightsidestep || animTarget == hanganim || isCrouch() || animTarget == backhandspringanim) {
5379 //open hands and close mouth
5380 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5381 righthandmorphness = 0;
5382 righthandmorphend = 0;
5383 targetrighthandmorphness = 1;
5386 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5387 lefthandmorphness = 0;
5388 lefthandmorphend = 0;
5389 targetlefthandmorphness = 1;
5392 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5 && headmorphend != 0 && headmorphness == targetheadmorphness) {
5395 targetheadmorphness = 1;
5399 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) {
5400 //open hands and mouth
5401 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5402 righthandmorphness = 0;
5403 righthandmorphend = 0;
5404 targetrighthandmorphness = 1;
5407 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5408 lefthandmorphness = 0;
5409 lefthandmorphend = 0;
5410 targetlefthandmorphness = 1;
5413 if (headmorphend != 1 && headmorphness == targetheadmorphness) {
5416 targetheadmorphness = 1;
5420 if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim) {
5421 //close hands and mouth
5422 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5423 righthandmorphness = 0;
5424 righthandmorphend = 1;
5425 targetrighthandmorphness = 1;
5428 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5429 lefthandmorphness = 0;
5430 lefthandmorphend = 1;
5431 targetlefthandmorphness = 1;
5434 if (headmorphend != 0 && headmorphness == targetheadmorphness) {
5437 targetheadmorphness = 1;
5441 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) {
5442 //close hands and yell
5443 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5444 righthandmorphness = 0;
5445 righthandmorphend = 1;
5446 targetrighthandmorphness = 1;
5449 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5450 lefthandmorphness = 0;
5451 lefthandmorphend = 1;
5452 targetlefthandmorphness = 1;
5455 if (headmorphend != 2 && headmorphness == targetheadmorphness) {
5458 targetheadmorphness = 1;
5465 if ((victim != this->shared_from_this()) && !victim->dead && (victim->aitype != passivetype) &&
5466 (victim->aitype != searchtype) && (aitype != passivetype) &&
5467 (aitype != searchtype) && (victim->id < Person::players.size()) && (aitype != passivetype)) {
5468 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
5472 if (!dead && animTarget != hurtidleanim)
5473 if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) {
5474 if (headmorphend != 4 || headmorphness == targetheadmorphness) {
5477 targetheadmorphness = 1;
5481 if (weaponactive != -1) {
5482 if (weapons[weaponids[weaponactive]].getType() != staff) {
5483 righthandmorphstart = 1;
5484 righthandmorphend = 1;
5486 if (weapons[weaponids[weaponactive]].getType() == staff) {
5487 righthandmorphstart = 2;
5488 righthandmorphend = 2;
5490 targetrighthandmorphness = 1;
5493 terrainnormal = terrain.getNormal(coords.x, coords.z);
5495 if (animation[animTarget].attack != reversal) {
5496 if (!isnormal(coords.x))
5504 flatfacing = DoRotation(flatfacing, 0, yaw, 0);
5505 facing = flatfacing;
5506 ReflectVector(&facing, terrainnormal);
5509 if (isRun() || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) {
5511 targettilt2 = -facing.y * 20;
5516 if (!isRun() && !animation[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim)
5518 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5519 flatvelocity = velocity;
5521 flatvelspeed = findLength(&flatvelocity);
5522 targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity);
5523 targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity);
5528 if (targettilt > 25)
5530 if (targettilt < -25)
5534 if (targettilt2 > 45)
5536 if (targettilt2 < -45)
5538 if (abs(tilt2 - targettilt2) < multiplier * 400)
5539 tilt2 = targettilt2;
5540 else if (tilt2 > targettilt2) {
5541 tilt2 -= multiplier * 400;
5542 } else if (tilt2 < targettilt2) {
5543 tilt2 += multiplier * 400;
5545 if (!animation[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) {
5552 if (!isnormal(targettilt) && targettilt) {
5555 if (!isnormal(targettilt2) && targettilt2) {
5560 //if(!creature==wolftype||animTarget==rabbitkickanim)
5561 if (animTarget == rabbittackleanim) {
5562 velocity += facing * multiplier * speed * 700 * scale;
5563 velspeed = findLength(&velocity);
5564 if (velspeed > speed * 65 * scale) {
5565 velocity /= velspeed;
5566 velspeed = speed * 65 * scale;
5567 velocity *= velspeed;
5569 velocity.y += gravity * multiplier * 20;
5570 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5571 velspeed = findLength(&velocity);
5572 velocity = flatfacing * velspeed;
5574 if (animTarget != rabbitrunninganim && animTarget != wolfrunninganim) {
5575 if (isRun() || animTarget == rabbitkickanim) {
5576 velocity += facing * multiplier * speed * 700 * scale;
5577 velspeed = findLength(&velocity);
5578 if (velspeed > speed * 45 * scale) {
5579 velocity /= velspeed;
5580 velspeed = speed * 45 * scale;
5581 velocity *= velspeed;
5583 velocity.y += gravity * multiplier * 20;
5584 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5585 velspeed = findLength(&velocity);
5586 if (velspeed < speed * 30 * scale)
5587 velspeed = speed * 30 * scale;
5588 velocity = flatfacing * velspeed;
5590 } else if (isRun()) {
5591 velocity += facing * multiplier * speed * 700 * scale;
5592 velspeed = findLength(&velocity);
5593 if (creature == rabbittype) {
5594 if (velspeed > speed * 55 * scale) {
5595 velocity /= velspeed;
5596 velspeed = speed * 55 * scale;
5597 velocity *= velspeed;
5600 if (creature == wolftype) {
5601 if (velspeed > speed * 75 * scale) {
5602 velocity /= velspeed;
5603 velspeed = speed * 75 * scale;
5604 velocity *= velspeed;
5607 velocity.y += gravity * multiplier * 20;
5608 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5609 velspeed = findLength(&velocity);
5610 velocity = flatfacing * velspeed;
5613 if (animTarget == rollanim && animation[animTarget].label[frameTarget] != 6) {
5614 velocity += facing * multiplier * speed * 700 * scale;
5615 velspeed = findLength(&velocity);
5616 if (velspeed > speed * 45 * scale) {
5617 velocity /= velspeed;
5618 velspeed = speed * 45 * scale;
5619 velocity *= velspeed;
5621 velocity.y += gravity * multiplier * 20;
5622 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5623 velspeed = findLength(&velocity);
5624 velocity = flatfacing * velspeed;
5628 /*if(animCurrent==rollanim&&(isCrouch()||isIdle())){
5629 velocity+=facing*multiplier*speed*700*scale;
5630 velspeed=findLength(&velocity);
5631 if(velspeed>speed*25*scale){
5633 velspeed=speed*25*scale;
5636 velocity.y+=gravity*multiplier*20;
5637 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5638 velspeed=findLength(&velocity);
5639 velocity=flatfacing*velspeed;
5642 if (animTarget == sneakanim || animTarget == walkanim) {
5643 velocity += facing * multiplier * speed * 700 * scale;
5644 velspeed = findLength(&velocity);
5645 if (velspeed > speed * 12 * scale) {
5646 velocity /= velspeed;
5647 velspeed = speed * 12 * scale;
5648 velocity *= velspeed;
5650 velocity.y += gravity * multiplier * 20;
5651 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5652 velspeed = findLength(&velocity);
5653 velocity = flatfacing * velspeed;
5656 if ((animTarget == fightidleanim || animTarget == knifefightidleanim) && (animCurrent == bounceidleanim || animCurrent == hurtidleanim)) {
5657 velocity += facing * multiplier * speed * 700 * scale;
5658 velspeed = findLength(&velocity);
5659 if (velspeed > speed * 2 * scale) {
5660 velocity /= velspeed;
5661 velspeed = speed * 2 * scale;
5662 velocity *= velspeed;
5664 velocity.y += gravity * multiplier * 20;
5665 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5666 velspeed = findLength(&velocity);
5667 velocity = flatfacing * velspeed;
5671 if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) {
5672 velocity -= facing * multiplier * speed * 700 * scale;
5673 velspeed = findLength(&velocity);
5674 if (velspeed > speed * 2 * scale) {
5675 velocity /= velspeed;
5676 velspeed = speed * 2 * scale;
5677 velocity *= velspeed;
5679 velocity.y += gravity * multiplier * 20;
5680 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5681 velspeed = findLength(&velocity);
5682 velocity = flatfacing * velspeed * -1;
5685 if (animTarget == fightsidestep) {
5686 velocity += DoRotation(facing * multiplier * speed * 700 * scale, 0, -90, 0);
5687 velspeed = findLength(&velocity);
5688 if (velspeed > speed * 12 * scale) {
5689 velocity /= velspeed;
5690 velspeed = speed * 12 * scale;
5691 velocity *= velspeed;
5693 velocity.y += gravity * multiplier * 20;
5694 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5695 velspeed = findLength(&velocity);
5696 velocity = DoRotation(flatfacing * velspeed, 0, -90, 0);
5699 if (animTarget == staggerbackhighanim) {
5700 coords -= facing * multiplier * speed * 16 * scale;
5703 if (animTarget == staggerbackhardanim && animation[staggerbackhardanim].label[frameTarget] != 6) {
5704 coords -= facing * multiplier * speed * 20 * scale;
5708 if (animTarget == backhandspringanim) {
5709 //coords-=facing*multiplier*50*scale;
5710 velocity += facing * multiplier * speed * 700 * scale * -1;
5711 velspeed = findLength(&velocity);
5712 if (velspeed > speed * 50 * scale) {
5713 velocity /= velspeed;
5714 velspeed = speed * 50 * scale;
5715 velocity *= velspeed;
5717 velocity.y += gravity * multiplier * 20;
5718 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5719 velspeed = findLength(&velocity);
5720 velocity = flatfacing * velspeed * -1;
5722 if (animTarget == dodgebackanim) {
5723 //coords-=facing*multiplier*50*scale;
5724 velocity += facing * multiplier * speed * 700 * scale * -1;
5725 velspeed = findLength(&velocity);
5726 if (velspeed > speed * 60 * scale) {
5727 velocity /= velspeed;
5728 velspeed = speed * 60 * scale;
5729 velocity *= velspeed;
5731 velocity.y += gravity * multiplier * 20;
5732 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5733 velspeed = findLength(&velocity);
5734 velocity = flatfacing * velspeed * -1;
5737 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5738 velspeed = findLength(&velocity);
5742 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5743 velocity.y += gravity * multiplier;
5746 if (animTarget != climbanim && animTarget != hanganim && !isWallJump())
5747 coords += velocity * multiplier;
5749 if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
5750 if (isFlip() && animation[animTarget].label[frameTarget] == 7)
5753 if (animTarget == jumpupanim) {
5755 animTarget = getIdle();
5762 pause_sound(whooshsound);
5763 OPENAL_SetVolume(channels[whooshsound], 0);
5766 if (animTarget == jumpdownanim || isFlip()) {
5767 if (isFlip())jumppower = -4;
5768 animTarget = getLanding();
5769 emit_sound_at(landsound, coords, 128.);
5772 envsound[numenvsounds] = coords;
5773 envsoundvol[numenvsounds] = 16;
5774 envsoundlife[numenvsounds] = .4;
5780 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump())
5781 coords.y += gravity * multiplier * 2;
5782 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) {
5783 coords.y = terrain.getHeight(coords.x, coords.z);
5788 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)) {
5789 velspeed = findLength(&velocity);
5791 if (velspeed < multiplier * 300 * scale) {
5794 velocity -= velocity / velspeed * multiplier * 300 * scale;
5795 if (velspeed > 5 && (isLanding() || isLandhard())) {
5796 skiddingdelay += multiplier;
5797 if (skiddelay <= 0) {
5807 velspeed = findLength(&velocity);
5809 if (velspeed < multiplier * 600 * scale) {
5812 velocity -= velocity / velspeed * multiplier * 600 * scale;
5814 if (velspeed > 5 && (isLanding() || isLandhard())) {
5815 skiddingdelay += multiplier;
5816 if (skiddelay <= 0) {
5825 if (skiddingdelay < 0)
5826 skiddingdelay += multiplier;
5827 if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) {
5829 if (!onterrain || environment == grassyenvironment) {
5830 emit_sound_at(skidsound, coords, 128 * velspeed / 10);
5832 emit_sound_at(snowskidsound, coords, 128 * velspeed / 10);
5836 if (animation[animTarget].attack == normalattack && animTarget != rabbitkickanim && !victim->skeleton.free) {
5837 terrainnormal = victim->coords - coords;
5838 Normalise(&terrainnormal);
5839 targetyaw = -asin(0 - terrainnormal.x);
5840 targetyaw *= 360 / 6.28;
5841 if (terrainnormal.z < 0)
5842 targetyaw = 180 - targetyaw;
5843 targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70;
5846 if (animation[animTarget].attack == reversal && animTarget != rabbittacklinganim) {
5847 targetyaw = victim->targetyaw;
5849 if (animTarget == rabbittacklinganim) {
5850 coords = victim->coords;
5853 skeleton.oldfree = skeleton.free;
5857 midterrain.x = terrain.size * terrain.scale / 2;
5858 midterrain.z = terrain.size * terrain.scale / 2;
5859 if (distsqflat(&coords, &midterrain) > (terrain.size * terrain.scale / 2 - viewdistance) * (terrain.size * terrain.scale / 2 - viewdistance)) {
5861 tempposit = coords - midterrain;
5863 Normalise(&tempposit);
5864 tempposit *= (terrain.size * terrain.scale / 2 - viewdistance);
5865 coords.x = tempposit.x + midterrain.x;
5866 coords.z = tempposit.z + midterrain.z;
5872 * inverse kinematics helper function
5874 void IKHelper(Person *p, float interp)
5876 XYZ point, newpoint, change, change2;
5877 float heightleft, heightright;
5879 // TODO: implement localToWorld and worldToLocal
5880 // but keep in mind it won't be the same math if player is ragdolled or something
5881 // - localToWorldStanding / worldToLocalStanding (or crouching or...?)
5882 // then comb through code for places where to use it
5884 // point = localToWorld(jointPos(leftfoot))
5885 point = DoRotation(p->jointPos(leftfoot), 0, p->yaw, 0) * p->scale + p->coords;
5886 // adjust height of foot
5887 heightleft = terrain.getHeight(point.x, point.z) + .04;
5888 point.y = heightleft;
5889 change = p->jointPos(leftankle) - p->jointPos(leftfoot);
5890 change2 = p->jointPos(leftknee) - p->jointPos(leftfoot);
5891 // jointPos(leftfoot) = interpolate(worldToLocal(point), jointPos(leftfoot), interp)
5892 p->jointPos(leftfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(leftfoot) * (1 - interp);
5893 // move ankle along with foot
5894 p->jointPos(leftankle) = p->jointPos(leftfoot) + change;
5895 // average knee pos between old and new pos
5896 p->jointPos(leftknee) = (p->jointPos(leftfoot) + change2) / 2 + (p->jointPos(leftknee)) / 2;
5898 // do same as above for right leg
5899 point = DoRotation(p->jointPos(rightfoot), 0, p->yaw, 0) * p->scale + p->coords;
5900 heightright = terrain.getHeight(point.x, point.z) + .04;
5901 point.y = heightright;
5902 change = p->jointPos(rightankle) - p->jointPos(rightfoot);
5903 change2 = p->jointPos(rightknee) - p->jointPos(rightfoot);
5904 p->jointPos(rightfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(rightfoot) * (1 - interp);
5905 p->jointPos(rightankle) = p->jointPos(rightfoot) + change;
5906 p->jointPos(rightknee) = (p->jointPos(rightfoot) + change2) / 2 + (p->jointPos(rightknee)) / 2;
5908 // fix up skeleton now that we've moved body parts?
5909 p->skeleton.DoConstraints(&p->coords, &p->scale);
5916 int Person::DrawSkeleton()
5918 int oldplayerdetail;
5919 if ((frustum.SphereInFrustum(coords.x, coords.y + scale * 3, coords.z, scale * 8) && distsq(&viewer, &coords) < viewdistance * viewdistance) || skeleton.free == 3) {
5920 if (onterrain && (isIdle() || isCrouch() || wasIdle() || wasCrouch()) && !skeleton.free) {
5930 glAlphaFunc(GL_GREATER, 0.0001);
5932 float terrainheight;
5936 if (!isnormal(tilt))
5938 if (!isnormal(tilt2))
5940 oldplayerdetail = playerdetail;
5942 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) {
5945 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 128 && detail == 1) {
5948 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) {
5953 if (playerdetail != oldplayerdetail) {
5955 normalsupdatedelay = 0;
5957 static float updatedelaychange;
5958 static float morphness;
5959 static float framemult;
5961 skeleton.FindForwards();
5962 if (howactive == typesittingwall) {
5963 skeleton.specialforward[1] = 0;
5964 skeleton.specialforward[1].z = 1;
5970 static int weaponattachmuscle;
5971 static int weaponrotatemuscle;
5972 static XYZ weaponpoint;
5973 static int start, endthing;
5974 if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
5975 if (!isSleeping() && !isSitting()) {
5976 // TODO: give these meaningful names
5977 const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard()
5978 || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim);
5979 const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard()
5980 || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim);
5982 if (onterrain && (cond1 && cond2) && !skeleton.free) {
5984 if (creature == wolftype)
5988 if (onterrain && (cond1 && !cond2) && !skeleton.free) {
5989 IKHelper(this, target);
5990 if (creature == wolftype)
5991 IKHelper(this, target);
5994 if (onterrain && (!cond1 && cond2) && !skeleton.free) {
5995 IKHelper(this, 1 - target);
5996 if (creature == wolftype)
5997 IKHelper(this, 1 - target);
6001 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()))
6004 targetheadyaw = -targetyaw;
6005 targetheadpitch = 0;
6006 if (animation[animTarget].attack == 3)
6007 targetheadyaw += 180;
6009 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6010 skeleton.drawmodel.vertex[i] = 0;
6011 skeleton.drawmodel.vertex[i].y = 999;
6013 for (i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
6014 skeleton.drawmodellow.vertex[i] = 0;
6015 skeleton.drawmodellow.vertex[i].y = 999;
6017 for (i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
6018 skeleton.drawmodelclothes.vertex[i] = 0;
6019 skeleton.drawmodelclothes.vertex[i].y = 999;
6021 for (int i = 0; i < skeleton.num_muscles; i++) {
6022 // convenience renames
6023 const int p1 = skeleton.muscles[i].parent1->label;
6024 const int p2 = skeleton.muscles[i].parent2->label;
6026 if ((skeleton.muscles[i].numvertices > 0 && playerdetail) || (skeleton.muscles[i].numverticeslow > 0 && !playerdetail)) {
6031 if (p1 == righthand || p2 == righthand) {
6032 morphness = righthandmorphness;
6033 start = righthandmorphstart;
6034 endthing = righthandmorphend;
6036 if (p1 == lefthand || p2 == lefthand) {
6037 morphness = lefthandmorphness;
6038 start = lefthandmorphstart;
6039 endthing = lefthandmorphend;
6041 if (p1 == head || p2 == head) {
6042 morphness = headmorphness;
6043 start = headmorphstart;
6044 endthing = headmorphend;
6046 if ((p1 == neck && p2 == abdomen) || (p2 == neck && p1 == abdomen)) {
6047 morphness = chestmorphness;
6048 start = chestmorphstart;
6049 endthing = chestmorphend;
6051 if ((p1 == groin && p2 == abdomen) || (p2 == groin && p1 == abdomen)) {
6052 morphness = tailmorphness;
6053 start = tailmorphstart;
6054 endthing = tailmorphend;
6057 skeleton.FindRotationMuscle(i, animTarget);
6058 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6059 glMatrixMode(GL_MODELVIEW);
6063 glRotatef(tilt2, 1, 0, 0);
6065 glRotatef(tilt, 0, 0, 1);
6068 glTranslatef(mid.x, mid.y, mid.z);
6070 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6071 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6073 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6074 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6076 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6077 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6079 if (playerdetail || skeleton.free == 3) {
6080 for (j = 0; j < skeleton.muscles[i].numvertices; j++) {
6081 XYZ &v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
6082 XYZ &v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
6083 glMatrixMode(GL_MODELVIEW);
6085 if (p1 == abdomen || p2 == abdomen)
6086 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionbody.x,
6087 (v0.y * (1 - morphness) + v1.y * morphness) * proportionbody.y,
6088 (v0.z * (1 - morphness) + v1.z * morphness) * proportionbody.z);
6089 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6090 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionarms.x,
6091 (v0.y * (1 - morphness) + v1.y * morphness) * proportionarms.y,
6092 (v0.z * (1 - morphness) + v1.z * morphness) * proportionarms.z);
6093 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6094 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionlegs.x,
6095 (v0.y * (1 - morphness) + v1.y * morphness) * proportionlegs.y,
6096 (v0.z * (1 - morphness) + v1.z * morphness) * proportionlegs.z);
6097 if (p1 == head || p2 == head)
6098 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionhead.x,
6099 (v0.y * (1 - morphness) + v1.y * morphness) * proportionhead.y,
6100 (v0.z * (1 - morphness) + v1.z * morphness) * proportionhead.z);
6101 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6102 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
6103 //if(!isnormal(scale))test=1;
6104 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale;
6105 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale;
6106 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z = M[14] * scale;
6111 if (!playerdetail || skeleton.free == 3) {
6112 for (j = 0; j < skeleton.muscles[i].numverticeslow; j++) {
6113 XYZ &v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
6114 glMatrixMode(GL_MODELVIEW);
6116 if (p1 == abdomen || p2 == abdomen)
6117 glTranslatef(v0.x * proportionbody.x,
6118 v0.y * proportionbody.y,
6119 v0.z * proportionbody.z);
6120 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6121 glTranslatef(v0.x * proportionarms.x,
6122 v0.y * proportionarms.y,
6123 v0.z * proportionarms.z);
6124 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6125 glTranslatef(v0.x * proportionlegs.x,
6126 v0.y * proportionlegs.y,
6127 v0.z * proportionlegs.z);
6128 if (p1 == head || p2 == head)
6129 glTranslatef(v0.x * proportionhead.x,
6130 v0.y * proportionhead.y,
6131 v0.z * proportionhead.z);
6133 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6134 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
6135 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y = M[13] * scale;
6136 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z = M[14] * scale;
6142 if (skeleton.clothes && skeleton.muscles[i].numverticesclothes > 0) {
6143 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6145 glMatrixMode(GL_MODELVIEW);
6149 glRotatef(tilt2, 1, 0, 0);
6151 glRotatef(tilt, 0, 0, 1);
6152 glTranslatef(mid.x, mid.y, mid.z);
6153 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6154 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6156 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6157 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6159 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6160 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6162 for (j = 0; j < skeleton.muscles[i].numverticesclothes; j++) {
6163 XYZ &v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
6164 glMatrixMode(GL_MODELVIEW);
6166 if (p1 == abdomen || p2 == abdomen)
6167 glTranslatef(v0.x * proportionbody.x,
6168 v0.y * proportionbody.y,
6169 v0.z * proportionbody.z);
6170 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
6171 glTranslatef(v0.x * proportionarms.x,
6172 v0.y * proportionarms.y,
6173 v0.z * proportionarms.z);
6174 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
6175 glTranslatef(v0.x * proportionlegs.x,
6176 v0.y * proportionlegs.y,
6177 v0.z * proportionlegs.z);
6178 if (p1 == head || p2 == head)
6179 glTranslatef(v0.x * proportionhead.x,
6180 v0.y * proportionhead.y,
6181 v0.z * proportionhead.z);
6182 glGetFloatv(GL_MODELVIEW_MATRIX, M);
6183 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
6184 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
6185 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z = M[14] * scale;
6190 updatedelay = 1 + (float)(Random() % 100) / 1000;
6192 if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) {
6193 normalsupdatedelay = 1;
6194 if (playerdetail || skeleton.free == 3)
6195 skeleton.drawmodel.CalculateNormals(0);
6196 if (!playerdetail || skeleton.free == 3)
6197 skeleton.drawmodellow.CalculateNormals(0);
6198 if (skeleton.clothes)
6199 skeleton.drawmodelclothes.CalculateNormals(0);
6201 if (playerdetail || skeleton.free == 3)
6202 skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
6203 if (!playerdetail || skeleton.free == 3)
6204 skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
6205 if (skeleton.clothes) {
6206 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6211 updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1);
6212 if (updatedelaychange > -realmultiplier * 30)
6213 updatedelaychange = -realmultiplier * 30;
6214 if (updatedelaychange > -framemult * 4)
6215 updatedelaychange = -framemult * 4;
6216 if (skeleton.free == 1)
6217 updatedelaychange *= 6;
6219 updatedelaychange *= 8;
6220 updatedelay += updatedelaychange;
6222 glMatrixMode(GL_MODELVIEW);
6225 glTranslatef(coords.x, coords.y - .02, coords.z);
6227 glTranslatef(coords.x, coords.y - .02, coords.z);
6229 glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
6231 glRotatef(yaw, 0, 1, 0);
6234 glColor4f(.4, 1, .4, 1);
6235 glDisable(GL_LIGHTING);
6236 glDisable(GL_TEXTURE_2D);
6239 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6240 XYZ &v0 = skeleton.drawmodel.vertex[i];
6241 glVertex3f(v0.x, v0.y, v0.z);
6247 for (i = 0; i < skeleton.drawmodel.TriangleNum; i++) {
6248 XYZ &v0 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]];
6249 XYZ &v1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]];
6250 XYZ &v2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]];
6251 glVertex3f(v0.x, v0.y, v0.z);
6252 glVertex3f(v1.x, v1.y, v1.z);
6253 glVertex3f(v1.x, v1.y, v1.z);
6254 glVertex3f(v2.x, v2.y, v2.z);
6255 glVertex3f(v2.x, v2.y, v2.z);
6256 glVertex3f(v0.x, v0.y, v0.z);
6262 terrainlight = terrain.getLighting(coords.x, coords.z);
6263 distance = distsq(&viewer, &coords);
6264 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
6268 terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1;
6269 if (terrainheight < 1)
6271 if (terrainheight > 1.7)
6272 terrainheight = 1.7;
6275 glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance);
6276 glDisable(GL_BLEND);
6277 glAlphaFunc(GL_GREATER, 0.0001);
6278 glEnable(GL_TEXTURE_2D);
6280 glDisable(GL_TEXTURE_2D);
6281 glColor4f(.7, .35, 0, .5);
6283 glEnable(GL_LIGHTING);
6286 if (tutoriallevel && id != 0) {
6287 //glDisable(GL_TEXTURE_2D);
6288 glColor4f(.7, .7, .7, 0.6);
6290 glEnable(GL_LIGHTING);
6292 if (canattack && cananger)
6293 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6294 glDisable(GL_TEXTURE_2D);
6295 glColor4f(1, 0, 0, 0.8);
6297 glMatrixMode(GL_TEXTURE);
6299 glTranslatef(0, -smoketex, 0);
6300 glTranslatef(-smoketex, 0, 0);
6304 if ((tutoriallevel && id != 0))
6305 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6307 skeleton.drawmodel.draw();
6310 if (!playerdetail) {
6311 if ((tutoriallevel && id != 0))
6312 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6314 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6317 if (!(animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed))
6318 if (tutoriallevel && id != 0) {
6320 glMatrixMode(GL_MODELVIEW);
6321 glEnable(GL_TEXTURE_2D);
6322 glColor4f(.7, .7, .7, 0.6);
6324 glEnable(GL_LIGHTING);
6326 if (canattack && cananger)
6327 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6328 glDisable(GL_TEXTURE_2D);
6329 glColor4f(1, 0, 0, 0.8);
6331 glMatrixMode(GL_TEXTURE);
6333 glTranslatef(0, -smoketex * .6, 0);
6334 glTranslatef(smoketex * .6, 0, 0);
6337 if ((tutoriallevel && id != 0))
6338 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6340 skeleton.drawmodel.draw();
6343 if (!playerdetail) {
6344 if ((tutoriallevel && id != 0))
6345 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6347 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6352 if (tutoriallevel && id != 0) {
6354 glMatrixMode(GL_MODELVIEW);
6355 glEnable(GL_TEXTURE_2D);
6357 if (skeleton.clothes) {
6361 skeleton.drawmodelclothes.draw();
6363 skeleton.drawmodelclothes.drawimmediate();
6369 if (num_weapons > 0) {
6370 for (k = 0; k < num_weapons; k++) {
6372 if (weaponactive == k) {
6373 if (weapons[i].getType() != staff) {
6374 for (j = 0; j < skeleton.num_muscles; j++) {
6375 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6376 weaponattachmuscle = j;
6379 for (j = 0; j < skeleton.num_muscles; j++) {
6380 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) {
6381 weaponrotatemuscle = j;
6384 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6385 if (creature == wolftype)
6386 weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3);
6388 if (weapons[i].getType() == staff) {
6389 for (j = 0; j < skeleton.num_muscles; j++) {
6390 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6391 weaponattachmuscle = j;
6394 for (j = 0; j < skeleton.num_muscles; j++) {
6395 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) {
6396 weaponrotatemuscle = j;
6399 //weaponpoint=jointPos(rightwrist);
6400 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6401 //weaponpoint+=skeleton.specialforward[1]*.1+(jointPos(rightwrist)-jointPos(rightelbow));
6402 XYZ tempnormthing, vec1, vec2;
6403 vec1 = (jointPos(rightwrist) - jointPos(rightelbow));
6404 vec2 = (jointPos(rightwrist) - jointPos(rightshoulder));
6405 CrossProduct(&vec1, &vec2, &tempnormthing);
6406 Normalise(&tempnormthing);
6407 if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim)
6408 weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow));
6411 if (weaponactive != k && weaponstuck != k) {
6412 if (weapons[i].getType() == knife)
6413 weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35;
6414 if (weapons[i].getType() == sword)
6415 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6416 if (weapons[i].getType() == staff)
6417 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6418 for (j = 0; j < skeleton.num_muscles; j++) {
6419 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) {
6420 weaponrotatemuscle = j;
6424 if (weaponstuck == k) {
6425 if (weaponstuckwhere == 0)
6426 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8;
6428 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
6429 for (j = 0; j < skeleton.num_muscles; j++) {
6430 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) {
6431 weaponrotatemuscle = j;
6435 if (skeleton.free) {
6436 weapons[i].position = weaponpoint * scale + coords;
6437 weapons[i].bigrotation = 0;
6438 weapons[i].bigtilt = 0;
6439 weapons[i].bigtilt2 = 0;
6441 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;
6442 weapons[i].bigrotation = yaw;
6443 weapons[i].bigtilt = tilt;
6444 weapons[i].bigtilt2 = tilt2;
6446 weapons[i].rotation1 = skeleton.muscles[weaponrotatemuscle].lastrotate1;
6447 weapons[i].rotation2 = skeleton.muscles[weaponrotatemuscle].lastrotate2;
6448 weapons[i].rotation3 = skeleton.muscles[weaponrotatemuscle].lastrotate3;
6449 if (weaponactive == k) {
6450 if (weapons[i].getType() == knife) {
6451 weapons[i].smallrotation = 180;
6452 weapons[i].smallrotation2 = 0;
6453 if (isCrouch() || wasCrouch()) {
6454 weapons[i].smallrotation2 = 20;
6456 if (animTarget == hurtidleanim) {
6457 weapons[i].smallrotation2 = 50;
6459 if ((animCurrent == crouchstabanim && animTarget == crouchstabanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
6460 XYZ temppoint1, temppoint2, tempforward;
6463 temppoint1 = jointPos(righthand);
6464 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6465 distance = findDistance(&temppoint1, &temppoint2);
6466 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6467 weapons[i].rotation2 *= 360 / 6.28;
6470 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6471 weapons[i].rotation1 *= 360 / 6.28;
6472 weapons[i].rotation3 = 0;
6473 weapons[i].smallrotation = -90;
6474 weapons[i].smallrotation2 = 0;
6475 if (temppoint1.x > temppoint2.x)
6476 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6478 if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) {
6479 XYZ temppoint1, temppoint2, tempforward;
6482 temppoint1 = jointPos(righthand);
6483 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6484 distance = findDistance(&temppoint1, &temppoint2);
6485 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6486 weapons[i].rotation2 *= 360 / 6.28;
6489 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6490 weapons[i].rotation1 *= 360 / 6.28;
6491 weapons[i].rotation3 = 0;
6492 weapons[i].smallrotation = 90;
6493 weapons[i].smallrotation2 = 0;
6494 if (temppoint1.x > temppoint2.x)
6495 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6497 if (animTarget == knifethrowanim) {
6498 weapons[i].smallrotation = 90;
6499 //weapons[i].smallrotation2=-90;
6500 weapons[i].smallrotation2 = 0;
6501 weapons[i].rotation1 = 0;
6502 weapons[i].rotation2 = 0;
6503 weapons[i].rotation3 = 0;
6505 if (animTarget == knifesneakattackanim && frameTarget < 5) {
6506 weapons[i].smallrotation = -90;
6507 weapons[i].rotation1 = 0;
6508 weapons[i].rotation2 = 0;
6509 weapons[i].rotation3 = 0;
6512 if (weapons[i].getType() == sword) {
6513 weapons[i].smallrotation = 0;
6514 weapons[i].smallrotation2 = 0;
6515 if (animTarget == knifethrowanim) {
6516 weapons[i].smallrotation = -90;
6517 weapons[i].smallrotation2 = 0;
6518 weapons[i].rotation1 = 0;
6519 weapons[i].rotation2 = 0;
6520 weapons[i].rotation3 = 0;
6522 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)) {
6523 XYZ temppoint1, temppoint2, tempforward;
6526 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6527 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6528 distance = findDistance(&temppoint1, &temppoint2);
6529 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6530 weapons[i].rotation2 *= 360 / 6.28;
6533 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6534 weapons[i].rotation1 *= 360 / 6.28;
6535 weapons[i].rotation3 = 0;
6536 weapons[i].smallrotation = 90;
6537 weapons[i].smallrotation2 = 0;
6538 if (temppoint1.x > temppoint2.x)
6539 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6542 if (weapons[i].getType() == staff) {
6543 weapons[i].smallrotation = 100;
6544 weapons[i].smallrotation2 = 0;
6545 if ((animTarget == staffhitanim && animCurrent == staffhitanim) || (animTarget == staffhitreversedanim && animCurrent == staffhitreversedanim) || (animTarget == staffspinhitreversedanim && animCurrent == staffspinhitreversedanim) || (animTarget == staffgroundsmashanim && animCurrent == staffgroundsmashanim) || (animTarget == staffspinhitanim && animCurrent == staffspinhitanim)) {
6546 XYZ temppoint1, temppoint2, tempforward;
6549 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6550 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6551 distance = findDistance(&temppoint1, &temppoint2);
6552 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6553 weapons[i].rotation2 *= 360 / 6.28;
6556 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6557 weapons[i].rotation1 *= 360 / 6.28;
6558 weapons[i].rotation3 = 0;
6559 weapons[i].smallrotation = 90;
6560 weapons[i].smallrotation2 = 0;
6561 if (temppoint1.x > temppoint2.x)
6562 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6566 if (weaponactive != k && weaponstuck != k) {
6567 if (weapons[i].getType() == knife) {
6568 weapons[i].smallrotation = -70;
6569 weapons[i].smallrotation2 = 10;
6571 if (weapons[i].getType() == sword) {
6572 weapons[i].smallrotation = -100;
6573 weapons[i].smallrotation2 = -8;
6575 if (weapons[i].getType() == staff) {
6576 weapons[i].smallrotation = -100;
6577 weapons[i].smallrotation2 = -8;
6580 if (weaponstuck == k) {
6581 if (weaponstuckwhere == 0)
6582 weapons[i].smallrotation = 180;
6584 weapons[i].smallrotation = 0;
6585 weapons[i].smallrotation2 = 10;
6594 if (animation[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isFlip() || isWallJump())
6596 if (animCurrent != animTarget)
6598 //if(id==0)calcrot=1;
6599 if (skeleton.free == 2)
6608 int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6611 static float distance;
6612 static float olddistance;
6613 static int intersecting;
6614 static int firstintersecting;
6617 static XYZ start, end;
6618 static float slopethreshold = -.4;
6620 firstintersecting = -1;
6624 if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius)
6627 *p1 = DoRotation(*p1, 0, -*rotate, 0);
6628 for (i = 0; i < 4; i++) {
6629 for (j = 0; j < model->TriangleNum; j++) {
6630 if (model->facenormals[j].y <= slopethreshold) {
6632 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)));
6633 if (distance < radius) {
6634 point = *p1 - model->facenormals[j] * distance;
6635 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]]))
6638 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6639 &model->vertex[model->Triangles[j].vertex[1]],
6642 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6643 &model->vertex[model->Triangles[j].vertex[2]],
6646 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6647 &model->vertex[model->Triangles[j].vertex[2]],
6650 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6654 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)) {
6655 p1->y = point.y + radius;
6656 if ((animTarget == jumpdownanim || isFlip())) {
6657 if (isFlip() && (frameTarget < 5 || animation[animTarget].label[frameTarget] == 7 || animation[animTarget].label[frameTarget] == 4))
6660 if (animTarget == jumpupanim) {
6662 animTarget = getIdle();
6669 pause_sound(whooshsound);
6670 OPENAL_SetVolume(channels[whooshsound], 0);
6673 if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) {
6676 animTarget = getLanding();
6677 emit_sound_at(landsound, coords, 128.);
6680 envsound[numenvsounds] = coords;
6681 envsoundvol[numenvsounds] = 16;
6682 envsoundlife[numenvsounds] = .4;
6690 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6691 olddistance = distance;
6692 firstintersecting = j;
6697 for (j = 0; j < model->TriangleNum; j++) {
6698 if (model->facenormals[j].y > slopethreshold) {
6701 start.y -= radius / 4;
6702 XYZ &v0 = model->vertex[model->Triangles[j].vertex[0]];
6703 XYZ &v1 = model->vertex[model->Triangles[j].vertex[1]];
6704 XYZ &v2 = model->vertex[model->Triangles[j].vertex[2]];
6705 distance = abs((model->facenormals[j].x * start.x)
6706 + (model->facenormals[j].y * start.y)
6707 + (model->facenormals[j].z * start.z)
6708 - ((model->facenormals[j].x * v0.x)
6709 + (model->facenormals[j].y * v0.y)
6710 + (model->facenormals[j].z * v0.z)));
6711 if (distance < radius * .5) {
6712 point = start - model->facenormals[j] * distance;
6713 if (PointInTriangle( &point, model->facenormals[j], &v0, &v1, &v2))
6716 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
6718 intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6720 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6722 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6723 if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
6725 velocity -= DoRotation(model->facenormals[j], 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->facenormals[j], 0, *rotate, 0))); //(distance-radius*.5)/multiplier;
6726 if (findLengthfast(&start) < findLengthfast(&velocity))
6729 *p1 += model->facenormals[j] * (distance - radius * .5);
6732 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6733 olddistance = distance;
6734 firstintersecting = j;
6741 *p = DoRotation(*p, 0, *rotate, 0);
6744 *p1 = DoRotation(*p1, 0, *rotate, 0);
6746 return firstintersecting;