2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 /**> HEADER FILES <**/
23 #include "openal_wrapper.h"
24 #include "Animation.h"
29 extern float multiplier;
30 extern Terrain terrain;
32 extern int environment;
34 extern FRUSTUM frustum;
36 extern float realmultiplier;
38 extern float slomodelay;
39 extern bool cellophane;
40 extern float texdetail;
41 extern float realtexdetail;
42 extern GLubyte bloodText[512 * 512 * 3];
43 extern GLubyte wolfbloodText[512 * 512 * 3];
44 extern int bloodtoggle;
45 extern Objects objects;
46 extern bool autoslomo;
47 extern float camerashake;
49 extern float viewdistance;
50 extern float blackout;
51 extern int difficulty;
53 extern float fadestart;
55 extern bool winfreeze;
56 extern float flashamount, flashr, flashg, flashb;
57 extern int flashdelay;
58 extern bool showpoints;
59 extern bool immediate;
61 extern bool tilt2weird;
62 extern bool tiltweird;
64 extern bool proportionweird;
65 extern bool vertexweird[6];
66 extern XYZ envsound[30];
67 extern float envsoundvol[30];
68 extern float envsoundlife[30];
69 extern int numenvsounds;
70 extern int tutoriallevel;
71 extern float smoketex;
72 extern int tutorialstage;
73 extern bool reversaltrain;
74 extern bool canattack;
76 extern float damagedealt;
78 extern float hostiletime;
80 extern int indialogue;
82 extern bool gamestarted;
84 std::vector<std::shared_ptr<Person>> Person::players(1, std::shared_ptr<Person>(new Person()));
89 * GameTick/doPlayerCollisions
91 void Person::CheckKick()
94 && (animTarget == rabbitkickanim
96 && victim != this->shared_from_this()
98 && animCurrent == rabbitkickanim)
99 && distsq(&coords, &victim->coords) < 1.2
100 && !victim->skeleton.free))
103 if (animation[victim->animTarget].height != lowheight) {
104 float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
105 XYZ relative = velocity;
107 Normalise(&relative);
111 if (tutoriallevel != 1)
112 emit_sound_at(heavyimpactsound, victim->coords);
114 for (int i = 0; i < victim->skeleton.num_joints; i++) {
115 victim->skeleton.joints[i].velocity += relative * 120 * damagemult;
118 victim->DoDamage(100 * damagemult / victim->protectionhigh);
124 animTarget = backflipanim;
126 velocity = facing * -10;
130 resume_stream(whooshsound);
132 award_bonus(id, cannon);
133 } else if (victim->isCrouch()) {
134 animTarget = rabbitkickreversedanim;
135 animCurrent = rabbitkickreversedanim;
136 victim->animCurrent = rabbitkickreversalanim;
137 victim->animTarget = rabbitkickreversalanim;
143 victim->oldcoords = victim->coords;
144 coords = victim->coords;
145 victim->targetyaw = targetyaw;
146 victim->victim = this->shared_from_this();
153 * GameTick/doPlayerCollisions - spread fire between players
154 * GameTick/doDebugKeys - press f to ignite
155 * Person::DoStuff - spread fire from lit campfires and bushes
157 void Person::CatchFire()
159 XYZ flatfacing, flatvelocity;
161 for (int i = 0; i < 10; i++) {
162 howmany = abs(Random() % (skeleton.num_joints));
164 flatvelocity = skeleton.joints[howmany].velocity;
165 flatfacing = skeleton.joints[howmany].position * scale + coords;
167 flatvelocity = velocity;
168 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
170 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
175 emit_sound_at(firestartsound, coords);
177 emit_stream_at(stream_firesound, coords);
185 * idle animation for this creature (depending on status)
187 int Person::getIdle()
189 if (indialogue != -1 && howactive == typeactive && creature == rabbittype)
191 if (hasvictim && (victim != this->shared_from_this())/*||(id==0&&attackkeydown)*/)
192 if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype &&
193 victim->aitype != searchtype && aitype != passivetype && aitype != searchtype &&
194 victim->id < Person::players.size())) {
195 if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) {
196 if (creature == rabbittype)
197 return fightidleanim;
198 if (creature == wolftype)
201 if (aitype == playercontrolled && stunned <= 0 && weaponactive != -1) {
202 if (weapons[weaponids[weaponactive]].getType() == knife)
203 return knifefightidleanim;
204 if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1)
205 return swordfightidlebothanim;
206 if (weapons[weaponids[weaponactive]].getType() == sword)
207 return swordfightidleanim;
208 if (weapons[weaponids[weaponactive]].getType() == staff)
209 return swordfightidleanim;
211 if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause)
212 return fightsidestep;
214 if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype)
216 if (howactive == typesitting) return sitanim;
217 if (howactive == typesittingwall) return sitwallanim;
218 if (howactive == typesleeping) return sleepanim;
219 if (howactive == typedead1) return dead1anim;
220 if (howactive == typedead2) return dead2anim;
221 if (howactive == typedead3) return dead3anim;
222 if (howactive == typedead4) return dead4anim;
223 if (creature == rabbittype) return bounceidleanim;
224 if (creature == wolftype) return wolfidle;
229 * crouch animation for this creature
231 int Person::getCrouch()
233 if (creature == rabbittype)
235 if (creature == wolftype)
236 return wolfcrouchanim;
241 * running animation for this creature (can be upright or all fours)
245 if (creature == rabbittype && (!superruntoggle || weaponactive != -1))
247 if (creature == wolftype && (!superruntoggle))
250 if (creature == rabbittype && (superruntoggle && weaponactive == -1))
251 return rabbitrunninganim;
252 if (creature == wolftype && (superruntoggle))
253 return wolfrunninganim;
259 int Person::getStop()
261 if (creature == rabbittype)
263 if (creature == wolftype)
270 int Person::getLanding()
272 if (creature == rabbittype)
274 if (creature == wolftype)
281 int Person::getLandhard()
283 if (creature == rabbittype)
285 if (creature == wolftype)
286 return wolflandhardanim;
293 * Person::DoAnimations
296 SolidHitBonus(int playerid)
298 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
299 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
301 award_bonus(playerid, solidhit);
305 * spawns blood effects
307 void Person::DoBlood(float howmuch, int which)
309 // FIXME: should abstract out inputs
310 static int bleedxint, bleedyint;
312 if (bloodtoggle && tutoriallevel != 1) {
313 if (bleeding <= 0 && spurt) {
315 for (int i = 0; i < 3; i++) {
316 // emit blood particles
319 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
320 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
321 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
322 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
325 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
326 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
327 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
328 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
331 if (Random() % 2 == 0) // 50% chance
332 for (int i = 0; i < 3; i++) {
333 if (Random() % 2 != 0) {
334 // emit teeth particles
337 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
338 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
341 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
342 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
346 Sprite::MakeSprite(splintersprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
348 Sprite::MakeSprite(splintersprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
350 Sprite::setLastSpriteSpecial(3); // sets it to teeth
355 // FIXME: manipulating attributes
356 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
359 if (creature == rabbittype)
360 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) {
361 bleedxint = abs(Random() % 512);
362 bleedyint = abs(Random() % 512);
364 if (creature == wolftype)
365 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) {
366 bleedxint = abs(Random() % 512);
367 bleedyint = abs(Random() % 512);
371 bleedy /= realtexdetail;
372 bleedx /= realtexdetail;
373 direction = abs(Random() % 2) * 2 - 1;
382 * spawns big blood effects and ???
383 * modifies character's skin texture
385 void Person::DoBloodBig(float howmuch, int which)
387 static int bleedxint, bleedyint, i, j;
389 if (howmuch && id == 0)
392 if (tutoriallevel != 1 || id == 0)
393 if (aitype != playercontrolled && howmuch > 0) {
397 // FIXME: seems to be spawning sounds by manipulating attributes... MESSY!
398 if (creature == wolftype) {
399 int i = abs(Random() % 2);
401 whichsound = snarlsound;
403 whichsound = snarl2sound;
404 envsound[numenvsounds] = coords;
405 envsoundvol[numenvsounds] = 16;
406 envsoundlife[numenvsounds] = .4;
409 if (creature == rabbittype) {
410 int i = abs(Random() % 2);
412 whichsound = rabbitpainsound;
413 if (i == 1 && howmuch >= 2)
414 whichsound = rabbitpain1sound;
415 envsound[numenvsounds] = coords;
416 envsoundvol[numenvsounds] = 16;
417 envsoundlife[numenvsounds] = .4;
421 if (whichsound != -1)
422 emit_sound_at(whichsound, coords);
425 if (id == 0 && howmuch > 0) {
426 // FIXME: manipulating attributes
434 if (bloodtoggle && decals && tutoriallevel != 1) {
435 if (bleeding <= 0 && spurt) {
437 for (int i = 0; i < 3; i++) {
438 // emit blood particles
439 // FIXME: copypaste from above
442 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
443 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
444 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
445 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
448 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
449 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
450 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
451 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
456 // weird texture manipulation code follows.
457 // looks like this is painting blood onto the character's skin texture
458 // FIXME: surely there's a better way
460 int offsetx = 0, offsety = 0;
462 offsety = Random() % 40;
463 offsetx = abs(Random() % 60);
465 if (which == 190 || which == 185) {
466 offsety = Random() % 40;
467 offsetx = abs(Random() % 100) - 20;
470 offsety = Random() % 10;
471 offsetx = Random() % 10;
474 offsety = Random() % 20;
475 offsetx = Random() % 20;
477 if (which == 220 || which == 215) {
487 if (creature == rabbittype)
488 for (i = 0; i < 512; i++) {
489 for (j = 0; j < 512; j++) {
490 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
491 if (i < startx) startx = i;
492 if (j < starty) starty = j;
493 if (i > endx) endx = i;
494 if (j > endy) endy = j;
498 if (creature == wolftype)
499 for (i = 0; i < 512; i++) {
500 for (j = 0; j < 512; j++) {
501 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
502 if (i < startx) startx = i;
503 if (j < starty) starty = j;
504 if (i > endx) endx = i;
505 if (j > endy) endy = j;
515 if (startx < 0) startx = 0;
516 if (starty < 0) starty = 0;
517 if (endx > 512 - 1) endx = 512 - 1;
518 if (endy > 512 - 1) endy = 512 - 1;
519 if (endx < startx) endx = startx;
520 if (endy < starty) endy = starty;
522 startx /= realtexdetail;
523 starty /= realtexdetail;
524 endx /= realtexdetail;
525 endy /= realtexdetail;
527 int texdetailint = realtexdetail;
529 if (creature == rabbittype)
530 for (i = startx; i < endx; i++) {
531 for (j = starty; j < endy; j++) {
532 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) {
533 color = Random() % 85 + 170;
534 where = i * skeleton.skinsize * 3 + j * 3;
535 if (skeleton.skinText[where + 0] > color / 2)
536 skeleton.skinText[where + 0] = color / 2;
537 skeleton.skinText[where + 1] = 0;
538 skeleton.skinText[where + 2] = 0;
542 if (creature == wolftype)
543 for (i = startx; i < endx; i++) {
544 for (j = starty; j < endy; j++) {
545 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) {
546 color = Random() % 85 + 170;
547 where = i * skeleton.skinsize * 3 + j * 3;
548 if (skeleton.skinText[where + 0] > color / 2)
549 skeleton.skinText[where + 0] = color / 2;
550 skeleton.skinText[where + 1] = 0;
551 skeleton.skinText[where + 2] = 0;
555 skeleton.drawmodel.textureptr.bind();
560 if (creature == rabbittype)
561 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) {
562 bleedxint = abs(Random() % 512);
563 bleedyint = abs(Random() % 512);
565 if (creature == wolftype)
566 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) {
567 bleedxint = abs(Random() % 512);
568 bleedyint = abs(Random() % 512);
570 bleedy = bleedxint + offsetx;
571 bleedx = bleedyint + offsety;
572 bleedy /= realtexdetail;
573 bleedx /= realtexdetail;
578 if (bleedx > skeleton.skinsize - 1)
579 bleedx = skeleton.skinsize - 1;
580 if (bleedy > skeleton.skinsize - 1)
581 bleedy = skeleton.skinsize - 1;
582 direction = abs(Random() % 2) * 2 - 1;
585 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
586 deathbleeding += bleeding;
587 bloodloss += bleeding * 3;
589 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
590 if (abs(Random() % 2) == 0) {
591 aitype = gethelptype;
594 aitype = attacktypecutoff;
602 * similar to DoBloodBig
604 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
608 static XYZ startpoint, endpoint, colpoint, movepoint;
609 static float rotationpoint;
611 static XYZ p1, p2, p3, p0;
614 float coordsx, coordsy;
617 if (bloodtoggle && decals && tutoriallevel != 1) {
620 where = DoRotation(where, 0, -yaw, 0);
628 // ray testing for a tri in the character model
629 whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
630 if (whichtri != -1) {
631 // low level geometry math
633 p1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
634 p2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
635 p3 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
637 CrossProduct(p2-p1,p3-p1,&N);
638 CrossProduct(p0-p1,p3-p1,&temp);
639 s = dotproduct(&temp,&N)/findLength(&N);
640 CrossProduct(p2-p1,p1-p0,&temp);
641 t = dotproduct(&temp,&N)/findLength(&N);
644 bary.x = distsq(&p0, &p1);
645 bary.y = distsq(&p0, &p2);
646 bary.z = distsq(&p0, &p3);
648 total = bary.x + bary.y + bary.z;
657 total = bary.x + bary.y + bary.z;
663 gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0];
664 gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1];
665 gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2];
666 gyy.x = skeleton.drawmodel.Triangles[whichtri].gy[0];
667 gyy.y = skeleton.drawmodel.Triangles[whichtri].gy[1];
668 gyy.z = skeleton.drawmodel.Triangles[whichtri].gy[2];
669 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;
670 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;
672 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
673 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
675 if (bleeding <= 0 && spurt) {
677 for (int i = 0; i < 3; i++) {
678 // emit blood particles
679 // FIXME: more copypaste code
682 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
683 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
684 Sprite::MakeSprite(bloodsprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
685 Sprite::MakeSprite(bloodflamesprite, jointPos(head) * scale + coords, bloodvel, 1, 1, 1, .3, 1);
688 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
689 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
690 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
691 Sprite::MakeSprite(bloodflamesprite, DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
696 // texture manipulation follows
698 int offsetx = 0, offsety = 0;
699 offsetx = (1 + coordsy) * 512 - 291;
700 offsety = coordsx * 512 - 437;
707 if (creature == rabbittype)
708 for (i = 0; i < 512; i++) {
709 for (j = 0; j < 512; j++) {
710 if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
711 if (i < startx) startx = i;
712 if (j < starty) starty = j;
713 if (i > endx) endx = i;
714 if (j > endy) endy = j;
718 if (creature == wolftype)
719 for (i = 0; i < 512; i++) {
720 for (j = 0; j < 512; j++) {
721 if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
722 if (i < startx) startx = i;
723 if (j < starty) starty = j;
724 if (i > endx) endx = i;
725 if (j > endy) endy = j;
734 if (startx < 0) startx = 0;
735 if (starty < 0) starty = 0;
736 if (endx > 512 - 1) endx = 512 - 1;
737 if (endy > 512 - 1) endy = 512 - 1;
738 if (endx < startx) endx = startx;
739 if (endy < starty) endy = starty;
741 startx /= realtexdetail;
742 starty /= realtexdetail;
743 endx /= realtexdetail;
744 endy /= realtexdetail;
746 int texdetailint = realtexdetail;
748 if (creature == rabbittype)
749 for (i = startx; i < endx; i++) {
750 for (j = starty; j < endy; j++) {
751 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) {
752 color = Random() % 85 + 170;
753 where = i * skeleton.skinsize * 3 + j * 3;
754 if (skeleton.skinText[where + 0] > color / 2)
755 skeleton.skinText[where + 0] = color / 2;
756 skeleton.skinText[where + 1] = 0;
757 skeleton.skinText[where + 2] = 0;
758 } 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) {
759 color = Random() % 85 + 170;
760 where = i * skeleton.skinsize * 3 + j * 3;
761 if (skeleton.skinText[where + 0] > color / 2)
762 skeleton.skinText[where + 0] = color / 2;
763 skeleton.skinText[where + 1] = 0;
764 skeleton.skinText[where + 2] = 0;
768 if (creature == wolftype)
769 for (i = startx; i < endx; i++) {
770 for (j = starty; j < endy; j++) {
771 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) {
772 color = Random() % 85 + 170;
773 where = i * skeleton.skinsize * 3 + j * 3;
774 if (skeleton.skinText[where + 0] > color / 2)
775 skeleton.skinText[where + 0] = color / 2;
776 skeleton.skinText[where + 1] = 0;
777 skeleton.skinText[where + 2] = 0;
778 } 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) {
779 color = Random() % 85 + 170;
780 where = i * skeleton.skinsize * 3 + j * 3;
781 if (skeleton.skinText[where + 0] > color / 2)
782 skeleton.skinText[where + 0] = color / 2;
783 skeleton.skinText[where + 1] = 0;
784 skeleton.skinText[where + 2] = 0;
788 skeleton.drawmodel.textureptr.bind();
791 bleedy = (1 + coordsy) * 512;
792 bleedx = coordsx * 512;
793 bleedy /= realtexdetail;
794 bleedx /= realtexdetail;
799 if (bleedx > skeleton.skinsize - 1)
800 bleedx = skeleton.skinsize - 1;
801 if (bleedy > skeleton.skinsize - 1)
802 bleedy = skeleton.skinsize - 1;
803 direction = abs(Random() % 2) * 2 - 1;
808 bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
809 deathbleeding += bleeding;
810 bloodloss += bleeding * 3;
812 if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
813 if (abs(Random() % 2) == 0) {
814 aitype = gethelptype;
817 aitype = attacktypecutoff;
828 * guessing this performs a reversal
830 void Person::Reverse()
832 if (!((victim->aitype == playercontrolled
834 || staggerdelay <= 0)
835 && victim->animTarget != jumpupanim
836 && victim->animTarget != jumpdownanim
837 && (tutoriallevel != 1 || cananger)
841 if (normaldotproduct (victim->facing, victim->coords - coords) > 0
842 && (victim->id != 0 || difficulty >= 2)
843 && (creature != wolftype || victim->creature == wolftype))
846 if (animTarget == sweepanim) {
847 animTarget = sweepreversedanim;
848 animCurrent = sweepreversedanim;
849 victim->animCurrent = sweepreversalanim;
850 victim->animTarget = sweepreversalanim;
852 if (animTarget == spinkickanim) {
853 animTarget = spinkickreversedanim;
854 animCurrent = spinkickreversedanim;
855 victim->animCurrent = spinkickreversalanim;
856 victim->animTarget = spinkickreversalanim;
858 if (animTarget == upunchanim || animTarget == rabbittacklinganim) {
859 if (animTarget == rabbittacklinganim) {
862 victim->frameCurrent = 6;
863 victim->frameTarget = 7;
865 animTarget = upunchreversedanim;
866 animCurrent = upunchreversedanim;
867 victim->animCurrent = upunchreversalanim;
868 victim->animTarget = upunchreversalanim;
870 if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
871 if (victim->weaponactive != -1) {
872 victim->throwtogglekeydown = 1;
873 XYZ tempVelocity = victim->velocity * .2;
874 if (tempVelocity.x == 0)
876 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
877 victim->num_weapons--;
878 if (victim->num_weapons) {
879 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
880 if (victim->weaponstuck == victim->num_weapons)
881 victim->weaponstuck = 0;
884 victim->weaponactive = -1;
885 for (unsigned j = 0; j < Person::players.size(); j++) {
886 Person::players[j]->wentforweapon = 0;
890 animTarget = staffhitreversedanim;
891 animCurrent = staffhitreversedanim;
892 victim->animCurrent = staffhitreversalanim;
893 victim->animTarget = staffhitreversalanim;
895 if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
896 if (victim->weaponactive != -1) {
897 victim->throwtogglekeydown = 1;
898 XYZ tempVelocity = victim->velocity * .2;
899 if (tempVelocity.x == 0)
901 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
902 victim->num_weapons--;
903 if (victim->num_weapons) {
904 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
905 if (victim->weaponstuck == victim->num_weapons)
906 victim->weaponstuck = 0;
909 victim->weaponactive = -1;
910 for (unsigned j = 0; j < Person::players.size(); j++) {
911 Person::players[j]->wentforweapon = 0;
914 animTarget = staffspinhitreversedanim;
915 animCurrent = staffspinhitreversedanim;
916 victim->animCurrent = staffspinhitreversalanim;
917 victim->animTarget = staffspinhitreversalanim;
919 if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
920 if (victim->weaponactive != -1) {
921 victim->throwtogglekeydown = 1;
922 XYZ tempVelocity = victim->velocity * .2;
923 if (tempVelocity.x == 0)
925 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
926 victim->num_weapons--;
927 if (victim->num_weapons) {
928 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
929 if (victim->weaponstuck == victim->num_weapons)
930 victim->weaponstuck = 0;
933 victim->weaponactive = -1;
934 for (unsigned j = 0; j < Person::players.size(); j++) {
935 Person::players[j]->wentforweapon = 0;
938 animTarget = swordslashreversedanim;
939 animCurrent = swordslashreversedanim;
940 victim->animCurrent = swordslashreversalanim;
941 victim->animTarget = swordslashreversalanim;
943 if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
944 if (victim->weaponactive != -1) {
945 victim->throwtogglekeydown = 1;
946 XYZ tempVelocity = victim->velocity * .2;
947 if (tempVelocity.x == 0)
949 weapons[victim->weaponids[0]].drop(tempVelocity, tempVelocity, false);
950 victim->num_weapons--;
951 if (victim->num_weapons) {
952 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
953 if (victim->weaponstuck == victim->num_weapons)
954 victim->weaponstuck = 0;
957 victim->weaponactive = -1;
958 for (unsigned j = 0; j < Person::players.size(); j++) {
959 Person::players[j]->wentforweapon = 0;
962 animTarget = knifeslashreversedanim;
963 animCurrent = knifeslashreversedanim;
964 victim->animCurrent = knifeslashreversalanim;
965 victim->animTarget = knifeslashreversalanim;
967 if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim) {
968 victim->targettilt2 = targettilt2;
969 victim->frameCurrent = frameCurrent;
970 victim->frameTarget = frameTarget;
971 victim->target = target;
972 victim->velocity = 0;
973 victim->oldcoords = victim->coords;
974 victim->coords = coords;
975 victim->targetyaw = targetyaw;
976 victim->yaw = targetyaw;
977 victim->victim = this->shared_from_this();
979 if (animTarget == winduppunchanim) {
980 animTarget = winduppunchblockedanim;
981 victim->animTarget = blockhighleftanim;
982 victim->frameTarget = 1;
984 victim->victim = this->shared_from_this();
985 victim->targetyaw = targetyaw + 180;
987 if (animTarget == wolfslapanim) {
988 animTarget = winduppunchblockedanim;
989 victim->animTarget = blockhighleftanim;
990 victim->frameTarget = 1;
992 victim->victim = this->shared_from_this();
993 victim->targetyaw = targetyaw + 180;
995 if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) {
996 animTarget = swordslashparriedanim;
997 parriedrecently = .4;
998 victim->parriedrecently = 0;
999 victim->animTarget = swordslashparryanim;
1000 victim->frameTarget = 1;
1001 victim->target = .5;
1002 victim->victim = this->shared_from_this();
1003 victim->targetyaw = targetyaw + 180;
1005 if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
1006 if (victim->weaponactive != -1) {
1007 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1008 if (weapons[victim->weaponids[0]].getType() == staff)
1009 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1010 if (weapons[weaponids[0]].getType() == staff)
1011 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1012 emit_sound_at(swordstaffsound, victim->coords);
1014 emit_sound_at(metalhitsound, victim->coords);
1018 victim->Puff(righthand);
1020 victim->frameTarget = 0;
1021 victim->animTarget = staggerbackhighanim;
1022 victim->targetyaw = targetyaw + 180;
1024 aim = DoRotation(facing, 0, 90, 0) * 21;
1026 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
1027 victim->num_weapons--;
1028 if (victim->num_weapons) {
1029 victim->weaponids[0] = victim->weaponids[num_weapons];
1030 if (victim->weaponstuck == victim->num_weapons)
1031 victim->weaponstuck = 0;
1033 victim->weaponactive = -1;
1034 for (unsigned i = 0; i < Person::players.size(); i++) {
1035 Person::players[i]->wentforweapon = 0;
1039 if (abs(Random() % 20) == 0) {
1040 if (weaponactive != -1) {
1041 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1042 if (weapons[victim->weaponids[0]].getType() == staff)
1043 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1044 if (weapons[weaponids[0]].getType() == staff)
1045 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1047 emit_sound_at(swordstaffsound, coords);
1049 emit_sound_at(metalhitsound, coords);
1057 animTarget = staggerbackhighanim;
1058 targetyaw = targetyaw + 180;
1060 aim = DoRotation(facing, 0, 90, 0) * 21;
1062 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
1065 weaponids[0] = weaponids[num_weapons];
1066 if (weaponstuck == num_weapons)
1070 for (unsigned i = 0; i < Person::players.size(); i++) {
1071 Person::players[i]->wentforweapon = 0;
1078 if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) {
1079 if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) {
1080 victim->animTarget = dodgebackanim;
1081 victim->frameTarget = 0;
1085 rotatetarget = coords - victim->coords;
1086 Normalise(&rotatetarget);
1087 victim->targetyaw = -asin(0 - rotatetarget.x);
1088 victim->targetyaw *= 360 / 6.28;
1089 if (rotatetarget.z < 0)
1090 victim->targetyaw = 180 - victim->targetyaw;
1092 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1094 victim->lastattack3 = victim->lastattack2;
1095 victim->lastattack2 = victim->lastattack;
1096 victim->lastattack = victim->animTarget;
1098 victim->animTarget = sweepanim;
1099 victim->frameTarget = 0;
1103 rotatetarget = coords - victim->coords;
1104 Normalise(&rotatetarget);
1105 victim->targetyaw = -asin(0 - rotatetarget.x);
1106 victim->targetyaw *= 360 / 6.28;
1107 if (rotatetarget.z < 0)
1108 victim->targetyaw = 180 - victim->targetyaw;
1110 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1112 victim->lastattack3 = victim->lastattack2;
1113 victim->lastattack2 = victim->lastattack;
1114 victim->lastattack = victim->animTarget;
1119 victim->velocity = 0;
1121 if (aitype != playercontrolled)
1123 if (aitype != playercontrolled && Random() % 3 == 0 && escapednum < 2 && difficulty == 2)
1125 if (aitype != playercontrolled && Random() % 5 == 0 && escapednum < 2 && difficulty == 1)
1127 if (aitype != playercontrolled && Random() % 10 == 0 && escapednum < 2 && difficulty == 0)
1130 if (victim->id == 0 && animation[victim->animTarget].attack == reversal)
1137 void Person::DoDamage(float howmuch)
1139 // subtract health (temporary?)
1140 if (tutoriallevel != 1)
1141 damage += howmuch / power;
1144 damagedealt += howmuch / power;
1146 damagetaken += howmuch / power;
1149 if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo))
1152 if (tutoriallevel != 1)
1153 permanentdamage += howmuch / 2 / power;
1154 if (tutoriallevel != 1)
1155 superpermanentdamage += howmuch / 4 / power;
1157 if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2)
1159 if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt)
1163 camerashake += howmuch / 100;
1164 if (id == 0 && ((howmuch > 50 && damage > damagetolerance / 2)))
1165 blackout = damage / damagetolerance;
1170 if (aitype == passivetype && damage < damagetolerance && ((tutoriallevel != 1 || cananger) && hostile))
1171 aitype = attacktypecutoff;
1172 if (tutoriallevel != 1 && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
1173 if (abs(Random() % 2) == 0) {
1174 aitype = gethelptype;
1177 aitype = attacktypecutoff;
1181 if (howmuch > damagetolerance * 50 && skeleton.free != 2) {
1184 for (int i = 0; i < skeleton.num_joints; i++) {
1185 if (skeleton.free) {
1186 flatvelocity2 = skeleton.joints[i].velocity;
1187 flatfacing2 = skeleton.joints[i].position * scale + coords;
1189 flatvelocity2 = velocity;
1190 flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
1192 flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1193 flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1194 flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1195 Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1196 Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1197 Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1200 emit_sound_at(splattersound, coords);
1205 if (!dead && creature == wolftype) {
1206 award_bonus(0, Wolfbonus);
1213 if (tutoriallevel != 1 || id == 0)
1214 if (speechdelay <= 0 && !dead && aitype != playercontrolled) {
1215 int whichsound = -1;
1217 if (creature == wolftype) {
1218 int i = abs(Random() % 2);
1220 whichsound = snarlsound;
1222 whichsound = snarl2sound;
1223 envsound[numenvsounds] = coords;
1224 envsoundvol[numenvsounds] = 16;
1225 envsoundlife[numenvsounds] = .4;
1228 if (creature == rabbittype) {
1229 int i = abs(Random() % 2);
1231 whichsound = rabbitpainsound;
1232 if (i == 1 && damage > damagetolerance)
1233 whichsound = rabbitpain1sound;
1234 envsound[numenvsounds] = coords;
1235 envsoundvol[numenvsounds] = 16;
1236 envsoundlife[numenvsounds] = .4;
1240 if (whichsound != -1) {
1241 emit_sound_at(whichsound, coords);
1248 * calculate/animate head facing direction?
1250 void Person::DoHead()
1252 static XYZ rotatearound;
1254 static float lookspeed = 500;
1256 if (!freeze && !winfreeze) {
1259 targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100;
1260 targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100;
1262 while (targetheadyaw > 180)targetheadyaw -= 360;
1263 while (targetheadyaw < -180)targetheadyaw += 360;
1265 if (targetheadyaw > 160)
1266 targetheadpitch = targetheadpitch * -1;
1267 if (targetheadyaw < -160)
1268 targetheadpitch = targetheadpitch * -1;
1269 if (targetheadyaw > 160)
1270 targetheadyaw = targetheadyaw - 180;
1271 if (targetheadyaw < -160)
1272 targetheadyaw = targetheadyaw + 180;
1274 if (targetheadpitch > 120)
1275 targetheadpitch = 120;
1276 if (targetheadpitch < -120)
1277 targetheadpitch = -120;
1278 if (targetheadyaw > 120)
1279 targetheadyaw = 120;
1280 if (targetheadyaw < -120)
1281 targetheadyaw = -120;
1284 targetheadpitch = 0;
1286 if (targetheadyaw > 80)
1288 if (targetheadyaw < -80)
1289 targetheadyaw = -80;
1290 if (targetheadpitch > 50)
1291 targetheadpitch = 50;
1292 if (targetheadpitch < -50)
1293 targetheadpitch = -50;
1296 if (abs(headyaw - targetheadyaw) < multiplier * lookspeed)
1297 headyaw = targetheadyaw;
1298 else if (headyaw > targetheadyaw) {
1299 headyaw -= multiplier * lookspeed;
1300 } else if (headyaw < targetheadyaw) {
1301 headyaw += multiplier * lookspeed;
1304 if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2)
1305 headpitch = targetheadpitch;
1306 else if (headpitch > targetheadpitch) {
1307 headpitch -= multiplier * lookspeed / 2;
1308 } else if (headpitch < targetheadpitch) {
1309 headpitch += multiplier * lookspeed / 2;
1312 rotatearound = jointPos(neck);
1313 jointPos(head) = rotatearound + DoRotation(jointPos(head) - rotatearound, headpitch, 0, 0);
1317 if (animTarget != bounceidleanim && animTarget != fightidleanim && animTarget != wolfidle && animTarget != knifefightidleanim && animTarget != drawrightanim && animTarget != drawleftanim && animTarget != walkanim) {
1318 facing = DoRotation(facing, headpitch * .4, 0, 0);
1319 facing = DoRotation(facing, 0, headyaw * .4, 0);
1322 if (animTarget == bounceidleanim || animTarget == fightidleanim || animTarget == wolfidle || animTarget == knifefightidleanim || animTarget == drawrightanim || animTarget == drawleftanim) {
1323 facing = DoRotation(facing, headpitch * .8, 0, 0);
1324 facing = DoRotation(facing, 0, headyaw * .8, 0);
1327 if (animTarget == walkanim) {
1328 facing = DoRotation(facing, headpitch * .6, 0, 0);
1329 facing = DoRotation(facing, 0, headyaw * .6, 0);
1332 skeleton.specialforward[0] = facing;
1333 //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1334 for (int i = 0; i < skeleton.num_muscles; i++) {
1335 if (skeleton.muscles[i].visible && (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)) {
1336 skeleton.FindRotationMuscle(i, animTarget);
1343 * ragdolls character?
1345 void Person::RagDoll(bool checkcollision)
1350 if (!skeleton.free) {
1353 if (id == 0 && isFlip())
1360 facing = DoRotation(facing, 0, yaw, 0);
1362 skeleton.freetime = 0;
1364 skeleton.longdead = 0;
1367 skeleton.broken = 0;
1368 skeleton.spinny = 1;
1370 skeleton.freefall = 1;
1372 if (!isnormal(velocity.x)) velocity.x = 0;
1373 if (!isnormal(velocity.y)) velocity.y = 0;
1374 if (!isnormal(velocity.z)) velocity.z = 0;
1375 if (!isnormal(yaw)) yaw = 0;
1376 if (!isnormal(coords.x)) coords = 0;
1377 if (!isnormal(tilt)) tilt = 0;
1378 if (!isnormal(tilt2)) tilt2 = 0;
1380 for (int i = 0; i < skeleton.num_joints; i++) {
1381 skeleton.joints[i].delay = 0;
1382 skeleton.joints[i].locked = 0;
1383 skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1384 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0);
1385 if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = coords;
1386 skeleton.joints[i].position.y += .1;
1387 skeleton.joints[i].oldposition = skeleton.joints[i].position;
1388 skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords;
1391 for (int i = 0; i < skeleton.num_joints; i++) {
1392 skeleton.joints[i].velocity = 0;
1393 skeleton.joints[i].velchange = 0;
1395 skeleton.DoConstraints(&coords, &scale);
1396 if (animation[animCurrent].height == lowheight || animation[animTarget].height == lowheight) {
1397 skeleton.DoConstraints(&coords, &scale);
1398 skeleton.DoConstraints(&coords, &scale);
1399 skeleton.DoConstraints(&coords, &scale);
1400 skeleton.DoConstraints(&coords, &scale);
1403 speed = animation[animTarget].speed[frameTarget] * 2;
1404 if (animation[animCurrent].speed[frameCurrent] > animation[animTarget].speed[frameTarget]) {
1405 speed = animation[animCurrent].speed[frameCurrent] * 2;
1408 speed = transspeed * 2;
1412 for (int i = 0; i < skeleton.num_joints; i++) {
1413 if ((animation[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && animation[animCurrent].height == animation[animTarget].height)
1414 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);
1416 skeleton.joints[i].velocity = velocity / scale + facing * 5;
1417 change.x = (float)(Random() % 100) / 100;
1418 change.y = (float)(Random() % 100) / 100;
1419 change.z = (float)(Random() % 100) / 100;
1420 skeleton.joints[i].velocity += change;
1421 skeleton.joints[abs(Random() % skeleton.num_joints)].velocity -= change;
1423 change.x = (float)(Random() % 100) / 100;
1424 change.y = (float)(Random() % 100) / 100;
1425 change.z = (float)(Random() % 100) / 100;
1426 skeleton.joints[i].velchange += change;
1427 skeleton.joints[abs(Random() % skeleton.num_joints)].velchange -= change;
1430 if (checkcollision) {
1437 for (j = 0; j < skeleton.num_joints; j++) {
1438 average += skeleton.joints[j].position;
1442 coords += average * scale;
1443 for (j = 0; j < skeleton.num_joints; j++) {
1444 skeleton.joints[j].position -= average;
1447 whichpatchx = coords.x / (terrain.size / subdivision * terrain.scale);
1448 whichpatchz = coords.z / (terrain.size / subdivision * terrain.scale);
1449 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
1450 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
1451 i = terrain.patchobjects[whichpatchx][whichpatchz][l];
1454 if (SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.yaw[i], &objects.model[i]) != -1) {
1455 coords.x = lowpoint.x;
1456 coords.z = lowpoint.z;
1465 for (int i = 0; i < skeleton.num_joints; i++) {
1466 velocity += skeleton.joints[i].velocity * scale;
1468 velocity /= skeleton.num_joints;
1471 if (Random() % 2 == 0) {
1472 if (weaponactive != -1 && animTarget != rabbitkickanim && num_weapons > 0) {
1473 weapons[weaponids[0]].drop(jointVel(righthand) * scale * -.3, jointVel(righthand) * scale);
1474 weapons[weaponids[0]].velocity.x += .01;
1477 weaponids[0] = weaponids[num_weapons];
1478 if (weaponstuck == num_weapons)
1482 for (unsigned i = 0; i < Person::players.size(); i++) {
1483 Person::players[i]->wentforweapon = 0;
1488 animTarget = bounceidleanim;
1489 animCurrent = bounceidleanim;
1499 void Person::FootLand(int which, float opacity)
1501 static XYZ terrainlight;
1502 static XYZ footvel, footpoint;
1503 if (opacity >= 1 || skiddelay <= 0)
1507 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1509 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1510 //footpoint.y=coords.y;
1511 if (distsq(&footpoint, &viewer))
1512 Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity);
1513 } else if (environment == snowyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1514 footvel = velocity / 5;
1518 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1520 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1521 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1522 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1523 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1524 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity);
1525 if (opacity >= 1 || detail == 2)
1527 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1528 terrain.MakeDecal(footprintdecal, footpoint, .2, 1 * opacity, yaw);
1529 } else if (environment == grassyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1530 footvel = velocity / 5;
1534 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1536 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1537 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1538 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1539 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1540 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity);
1541 } else if (environment == desertenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1542 footvel = velocity / 5;
1546 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1548 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1549 footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1550 terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1551 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1552 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity);
1553 if (opacity >= 1 || detail == 2)
1555 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1556 terrain.MakeDecal(footprintdecal, footpoint, .2, .25 * opacity, yaw);
1557 } else if (isLanding() || animTarget == jumpupanim || isLandhard()) {
1558 footvel = velocity / 5;
1562 footpoint = DoRotation(jointPos(leftfoot), 0, yaw, 0) * scale + coords;
1564 footpoint = DoRotation(jointPos(rightfoot), 0, yaw, 0) * scale + coords;
1565 //footpoint.y=coords.y;
1566 if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1567 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity);
1572 * make a puff effect at a body part (dust effect?)
1574 void Person::Puff(int whichlabel)
1576 static XYZ footvel, footpoint;
1579 footpoint = DoRotation(jointPos(whichlabel), 0, yaw, 0) * scale + coords;
1580 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .9, .3);
1584 * I think I added this in an attempt to clean up code
1586 void Person::setAnimation(int animation)
1588 animTarget = animation;
1597 void Person::DoAnimations()
1599 if (!skeleton.free) {
1600 static float oldtarget;
1602 if (isIdle() && animCurrent != getIdle())
1603 normalsupdatedelay = 0;
1605 if (animTarget == tempanim || animCurrent == tempanim) {
1606 animation[tempanim] = tempanimation;
1608 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
1614 vel[0] = velocity.x;
1615 vel[1] = velocity.y;
1616 vel[2] = velocity.z;
1619 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1620 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
1622 if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z))
1624 if (!crouchkeydown && velocity.y >= -15)
1627 if ((animCurrent == jumpupanim || animTarget == jumpdownanim)/*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) {
1632 targfacing = DoRotation(targfacing, 0, targetyaw, 0);
1634 if (normaldotproduct(targfacing, velocity) >= -.3)
1635 animTarget = flipanim;
1637 animTarget = backflipanim;
1638 crouchtogglekeydown = 1;
1646 if (animation[animTarget].attack != reversed)
1648 if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) {
1649 crouchtogglekeydown = 0;
1650 if (aitype == playercontrolled)
1653 if (!crouchtogglekeydown && animation[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain))
1656 crouchtogglekeydown = 1;
1660 if (animation[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) {
1662 normalsupdatedelay = 0;
1666 if (animTarget == rollanim && frameTarget == 3 && onfire) {
1668 emit_sound_at(fireendsound, coords);
1669 pause_sound(stream_firesound);
1673 if (animTarget == rabbittacklinganim && frameTarget == 1) {
1674 if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0)
1676 if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) {
1677 if (normaldotproduct(victim->facing, facing) > 0)
1678 victim->animTarget = rabbittackledbackanim;
1680 victim->animTarget = rabbittackledfrontanim;
1681 victim->frameTarget = 2;
1684 victim->targetyaw = yaw;
1685 if (victim->aitype == gethelptype)
1686 victim->DoDamage(victim->damagetolerance - victim->damage);
1687 //victim->DoDamage(30);
1688 if (creature == wolftype) {
1690 emit_sound_at(clawslicesound, victim->coords);
1692 victim->DoBloodBig(1 / victim->armorhead, 210);
1694 award_bonus(id, TackleBonus,
1695 victim->aitype == gethelptype ? 50 : 0);
1699 if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (animation[animTarget].label[frameTarget] || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) {
1700 if (weapons[weaponids[0]].getType() == knife) {
1701 if (weaponactive == -1)
1703 else if (weaponactive == 0)
1706 if (weaponactive == -1) {
1707 emit_sound_at(knifesheathesound, coords);
1709 if (weaponactive != -1) {
1710 emit_sound_at(knifedrawsound, coords, 128);
1713 drawtogglekeydown = 1;
1716 if (tutoriallevel != 1 || id == 0)
1717 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1720 if (terrain.getOpacity(coords.x, coords.z) < .2) {
1721 if (animation[animTarget].label[frameTarget] == 1)
1722 whichsound = footstepsound;
1724 whichsound = footstepsound2;
1725 if (animation[animTarget].label[frameTarget] == 1)
1727 if (animation[animTarget].label[frameTarget] == 2)
1729 if (animation[animTarget].label[frameTarget] == 3 && isRun()) {
1735 if (terrain.getOpacity(coords.x, coords.z) >= .2) {
1736 if (animation[animTarget].label[frameTarget] == 1)
1737 whichsound = footstepsound3;
1739 whichsound = footstepsound4;
1743 if (animation[animTarget].label[frameTarget] == 1)
1744 whichsound = footstepsound3;
1746 whichsound = footstepsound4;
1748 if (animation[animTarget].label[frameTarget] == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
1749 if (animation[animTarget].attack != neutral) {
1750 unsigned r = abs(Random() % 3);
1752 whichsound = lowwhooshsound;
1754 whichsound = midwhooshsound;
1756 whichsound = highwhooshsound;
1758 if (animation[animTarget].attack == neutral)
1759 whichsound = movewhooshsound;
1760 } else if (animation[animTarget].label[frameTarget] == 4)
1761 whichsound = knifeswishsound;
1762 if (animation[animTarget].label[frameTarget] == 8 && tutoriallevel != 1)
1763 whichsound = landsound2;
1765 emit_sound_at(whichsound, coords, 256.);
1768 if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
1769 envsound[numenvsounds] = coords;
1770 if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim)
1771 envsoundvol[numenvsounds] = 15;
1773 envsoundvol[numenvsounds] = 6;
1774 envsoundlife[numenvsounds] = .4;
1778 if (animation[animTarget].label[frameTarget] == 3) {
1780 emit_sound_at(whichsound, coords, 128.);
1785 if (tutoriallevel != 1 || id == 0)
1786 if (speechdelay <= 0)
1787 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
1788 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1789 int whichsound = -1;
1790 if (animation[animTarget].label[frameTarget] == 4 && aitype != playercontrolled) {
1791 if (animation[animTarget].attack != neutral) {
1792 unsigned r = abs(Random() % 4);
1793 if (creature == rabbittype) {
1794 if (r == 0) whichsound = rabbitattacksound;
1795 if (r == 1) whichsound = rabbitattack2sound;
1796 if (r == 2) whichsound = rabbitattack3sound;
1797 if (r == 3) whichsound = rabbitattack4sound;
1799 if (creature == wolftype) {
1800 if (r == 0) whichsound = barksound;
1801 if (r == 1) whichsound = bark2sound;
1802 if (r == 2) whichsound = bark3sound;
1803 if (r == 3) whichsound = barkgrowlsound;
1809 if (whichsound != -1) {
1810 emit_sound_at(whichsound, coords);
1816 if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) {
1822 currentoffset = targetoffset;
1823 frameTarget = frameCurrent;
1824 animCurrent = animTarget;
1827 if (animTarget == removeknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1828 for (unsigned i = 0; i < weapons.size(); i++) {
1829 if (weapons[i].owner == -1)
1830 if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
1831 if (distsq(&coords, &weapons[i].position) >= 1) {
1832 if (weapons[i].getType() != staff) {
1833 emit_sound_at(knifedrawsound, coords, 128.);
1842 if (animTarget == crouchremoveknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1843 for (unsigned i = 0; i < weapons.size(); i++) {
1844 bool willwork = true;
1845 if (weapons[i].owner != -1)
1846 if (Person::players[weapons[i].owner]->weaponstuck != -1)
1847 if (Person::players[weapons[i].owner]->weaponids[Person::players[weapons[i].owner]->weaponstuck] == int(i))
1848 if (Person::players[weapons[i].owner]->num_weapons > 1)
1850 if ((weapons[i].owner == -1) || (hasvictim && (weapons[i].owner == int(victim->id)) && victim->skeleton.free))
1851 if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) {
1852 if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
1853 bool fleshstuck = false;
1854 if (weapons[i].owner != -1)
1855 if (victim->weaponstuck != -1) {
1856 if (victim->weaponids[victim->weaponstuck] == int(i)) {
1861 emit_sound_at(fleshstabremovesound, coords, 128.);
1863 if (weapons[i].getType() != staff) {
1864 emit_sound_at(knifedrawsound, coords, 128.);
1867 if (weapons[i].owner != -1) {
1868 victim = Person::players[weapons[i].owner];
1869 if (victim->num_weapons == 1)
1870 victim->num_weapons = 0;
1872 victim->num_weapons = 1;
1874 //victim->weaponactive=-1;
1875 victim->skeleton.longdead = 0;
1876 victim->skeleton.free = 1;
1877 victim->skeleton.broken = 0;
1879 for (int j = 0; j < victim->skeleton.num_joints; j++) {
1880 victim->skeleton.joints[j].velchange = 0;
1881 victim->skeleton.joints[j].locked = 0;
1887 Normalise(&relative);
1888 XYZ footvel, footpoint;
1890 footpoint = weapons[i].position;
1891 if (victim->weaponstuck != -1) {
1892 if (victim->weaponids[victim->weaponstuck] == int(i)) {
1894 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
1895 weapons[i].bloody = 2;
1896 weapons[i].blooddrip = 5;
1897 victim->weaponstuck = -1;
1900 if (victim->num_weapons > 0) {
1901 if (victim->weaponstuck != 0 && victim->weaponstuck != -1)
1902 victim->weaponstuck = 0;
1903 if (victim->weaponids[0] == int(i))
1904 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1907 victim->jointVel(abdomen) += relative * 6;
1908 victim->jointVel(neck) += relative * 6;
1909 victim->jointVel(rightshoulder) += relative * 6;
1910 victim->jointVel(leftshoulder) += relative * 6;
1918 if (animCurrent == drawleftanim && animation[animTarget].label[frameCurrent] == 5) {
1919 if (weaponactive == -1)
1921 else if (weaponactive == 0) {
1923 if (num_weapons == 2) {
1925 buffer = weaponids[0];
1926 weaponids[0] = weaponids[1];
1927 weaponids[1] = buffer;
1930 if (weaponactive == -1) {
1931 emit_sound_at(knifesheathesound, coords, 128.);
1933 if (weaponactive != -1) {
1934 emit_sound_at(knifedrawsound, coords, 128.);
1939 if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) {
1940 XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0);
1941 Normalise(&rotatetarget);
1942 targetyaw = -asin(0 - rotatetarget.x);
1943 targetyaw *= 360 / 6.28;
1944 if (rotatetarget.z < 0)
1945 targetyaw = 180 - targetyaw;
1947 if (animTarget == walljumprightkickanim)
1949 if (animTarget == walljumpleftkickanim)
1955 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0))
1958 if (distsq(&victim->coords, &/*Person::players[i]->*/coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1)
1963 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) {
1964 animTarget = rabbittackleanim;
1966 emit_sound_at(jumpsound, coords);
1974 targetloc = velocity;
1975 Normalise(&targetloc);
1976 targetloc += coords;
1977 for (unsigned i = 0; i < Person::players.size(); i++) {
1979 if (distsq(&targetloc, &Person::players[i]->coords) < closestdist || closestdist == 0) {
1980 closestdist = distsq(&targetloc, &Person::players[i]->coords);
1984 if (closestid != -1)
1985 if (closestdist < 5 && !Person::players[closestid]->dead && animation[Person::players[closestid]->animTarget].height != lowheight && Person::players[closestid]->animTarget != backhandspringanim) {
1987 victim = Person::players[closestid];
1988 coords = victim->coords;
1989 animCurrent = rabbittacklinganim;
1990 animTarget = rabbittacklinganim;
1994 if (coords.z != victim->coords.z || coords.x != victim->coords.x) {
1995 rotatetarget = coords - victim->coords;
1996 Normalise(&rotatetarget);
1997 targetyaw = -asin(0 - rotatetarget.x);
1998 targetyaw *= 360 / 6.28;
1999 if (rotatetarget.z < 0)
2000 targetyaw = 180 - targetyaw;
2002 if (animTarget != rabbitrunninganim) {
2003 emit_sound_at(jumpsound, coords, 128.);
2009 float damagemult = 1 * power;
2010 if (creature == wolftype)
2011 damagemult = 2.5 * power;
2013 damagemult /= victim->damagetolerance / 200;
2015 if ((animation[animTarget].attack == normalattack || animTarget == walljumprightkickanim || animTarget == walljumpleftkickanim) && (!feint) && (victim->skeleton.free != 2 || animTarget == killanim || animTarget == dropkickanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == staffgroundsmashanim)) {
2016 if (animTarget == spinkickanim && animation[animTarget].label[frameCurrent] == 5) {
2017 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2021 if (Random() % 2 || creature == wolftype) {
2024 if (creature == wolftype)
2027 if (tutoriallevel != 1) {
2028 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2030 if (creature == wolftype) {
2031 emit_sound_at(clawslicesound, victim->coords, 128.);
2033 victim->DoBloodBig(2 / victim->armorhead, 175);
2037 relative = victim->coords - coords;
2039 Normalise(&relative);
2040 relative = DoRotation(relative, 0, -90, 0);
2041 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2042 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2044 victim->jointVel(head) += relative * damagemult * 200;
2047 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2053 if (animTarget == wolfslapanim && animation[animTarget].label[frameCurrent] == 5) {
2054 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2058 if (Random() % 2 || creature == wolftype) {
2060 if (creature == wolftype)
2063 emit_sound_at(whooshhitsound, victim->coords);
2064 if (creature == wolftype) {
2065 emit_sound_at(clawslicesound, victim->coords, 128.);
2067 victim->DoBloodBig(2, 175);
2071 relative = victim->coords - coords;
2073 Normalise(&relative);
2075 Normalise(&relative);
2076 relative = DoRotation(relative, 0, 90, 0);
2077 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2078 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2080 victim->jointVel(head) += relative * damagemult * 100;
2083 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2087 if (animTarget == walljumprightkickanim && animation[animTarget].label[frameCurrent] == 5) {
2088 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2094 if (tutoriallevel != 1) {
2095 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2097 if (creature == wolftype) {
2098 emit_sound_at(clawslicesound, victim->coords, 128.);
2100 victim->DoBloodBig(2 / victim->armorhead, 175);
2106 Normalise(&relative);
2107 relative = DoRotation(relative, 0, -90, 0);
2108 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2109 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2111 victim->jointVel(head) += relative * damagemult * 200;
2114 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2116 if (victim->damage > victim->damagetolerance)
2117 award_bonus(id, style);
2123 if (animTarget == walljumpleftkickanim && animation[animTarget].label[frameCurrent] == 5) {
2124 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2130 if (tutoriallevel != 1) {
2131 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2133 if (creature == wolftype) {
2134 emit_sound_at(clawslicesound, victim->coords, 128.);
2136 victim->DoBloodBig(2 / victim->armorhead, 175);
2142 Normalise(&relative);
2143 relative = DoRotation(relative, 0, 90, 0);
2144 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2145 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2147 victim->jointVel(head) += relative * damagemult * 200;
2150 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2152 if (victim->damage > victim->damagetolerance)
2153 award_bonus(id, style);
2159 if (animTarget == blockhighleftstrikeanim && animation[animTarget].label[frameCurrent] == 5) {
2160 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2168 emit_sound_at(whooshhitsound, victim->coords);
2171 relative = victim->coords - coords;
2173 Normalise(&relative);
2174 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2175 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
2177 victim->jointVel(head) += relative * damagemult * 100;
2180 victim->DoDamage(damagemult * 50 / victim->protectionhead);
2184 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 8) {
2185 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) {
2189 emit_sound_at(whooshhitsound, victim->coords, 128.);
2191 victim->skeleton.longdead = 0;
2192 victim->skeleton.free = 1;
2193 victim->skeleton.broken = 0;
2194 victim->skeleton.spinny = 1;
2196 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2197 victim->skeleton.joints[i].velchange = 0;
2198 victim->skeleton.joints[i].delay = 0;
2199 victim->skeleton.joints[i].locked = 0;
2200 //victim->skeleton.joints[i].velocity=0;
2206 Normalise(&relative);
2207 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2208 victim->skeleton.joints[i].velocity.y = relative.y * 10;
2209 victim->skeleton.joints[i].position.y += relative.y * .3;
2210 victim->skeleton.joints[i].oldposition.y += relative.y * .3;
2211 victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
2213 victim->Puff(abdomen);
2214 victim->jointVel(abdomen).y = relative.y * 400;
2218 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 5) {
2219 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) {
2223 if (tutoriallevel != 1) {
2224 emit_sound_at(heavyimpactsound, coords, 128.);
2227 relative = victim->coords - coords;
2229 Normalise(&relative);
2230 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2231 victim->skeleton.joints[i].velocity += relative * damagemult * 90;
2233 victim->Puff(abdomen);
2234 if (victim->dead != 2 && victim->permanentdamage > victim->damagetolerance - 250 && autoslomo) {
2238 victim->DoDamage(damagemult * 500 / victim->protectionhigh);
2239 victim->jointVel(abdomen) += relative * damagemult * 300;
2243 if (animTarget == dropkickanim && animation[animTarget].label[frameCurrent] == 7) {
2244 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) {
2248 if (tutoriallevel != 1) {
2249 emit_sound_at(thudsound, coords);
2252 victim->skeleton.longdead = 0;
2253 victim->skeleton.free = 1;
2254 victim->skeleton.broken = 0;
2255 victim->skeleton.spinny = 1;
2257 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2258 victim->skeleton.joints[i].velchange = 0;
2259 //victim->skeleton.joints[i].delay=0;
2260 victim->skeleton.joints[i].locked = 0;
2263 relative = victim->coords - coords;
2264 Normalise(&relative);
2266 Normalise(&relative);
2267 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2268 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2273 victim->Puff(abdomen);
2274 victim->DoDamage(damagemult * 20 / victim->protectionhigh);
2275 victim->jointVel(abdomen) += relative * damagemult * 200;
2284 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 5) {
2287 if (!victim->skeleton.free)
2291 terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360);
2292 emit_sound_at(knifesheathesound, coords, 128.);
2295 if (victim && hasvictim) {
2296 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2298 XYZ where, startpoint, endpoint, movepoint, colpoint;
2299 float rotationpoint;
2301 if (weapons[weaponids[weaponactive]].getType() == knife) {
2302 where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4);
2303 where -= victim->coords;
2304 if (!victim->skeleton.free)
2305 where = DoRotation(where, 0, -victim->yaw, 0);
2308 startpoint.y += 100;
2312 if (weapons[weaponids[weaponactive]].getType() == sword) {
2313 where = weapons[weaponids[weaponactive]].position;
2314 where -= victim->coords;
2315 if (!victim->skeleton.free)
2316 where = DoRotation(where, 0, -victim->yaw, 0);
2318 where = weapons[weaponids[weaponactive]].tippoint;
2319 where -= victim->coords;
2320 if (!victim->skeleton.free)
2321 where = DoRotation(where, 0, -victim->yaw, 0);
2324 if (weapons[weaponids[weaponactive]].getType() == staff) {
2325 where = weapons[weaponids[weaponactive]].position;
2326 where -= victim->coords;
2327 if (!victim->skeleton.free)
2328 where = DoRotation(where, 0, -victim->yaw, 0);
2330 where = weapons[weaponids[weaponactive]].tippoint;
2331 where -= victim->coords;
2332 if (!victim->skeleton.free)
2333 where = DoRotation(where, 0, -victim->yaw, 0);
2338 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
2340 if (whichtri != -1) {
2341 if (victim->dead != 2) {
2342 victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2));
2344 award_bonus(id, FinishedBonus);
2347 weapons[weaponids[weaponactive]].bloody = 2;
2349 victim->skeleton.longdead = 0;
2350 victim->skeleton.free = 1;
2351 victim->skeleton.broken = 0;
2353 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2354 victim->skeleton.joints[i].velchange = 0;
2355 victim->skeleton.joints[i].locked = 0;
2356 //victim->skeleton.joints[i].velocity=0;
2358 emit_sound_at(fleshstabsound, coords, 128);
2361 if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) {
2362 weapons[weaponids[weaponactive]].blooddrip += 5;
2363 weapons[weaponids[weaponactive]].blooddripdelay = 0;
2365 if (whichtri == -1) {
2367 emit_sound_at(knifesheathesound, coords, 128.);
2373 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 6) {
2375 emit_sound_at(knifedrawsound, coords, 128);
2378 if (victim && hasvictim) {
2379 XYZ footvel, footpoint;
2381 emit_sound_at(fleshstabremovesound, coords, 128.);
2384 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2386 if (weapons[weaponids[weaponactive]].getType() == sword) {
2387 XYZ where, startpoint, endpoint, movepoint;
2388 float rotationpoint;
2391 where = weapons[weaponids[weaponactive]].position;
2392 where -= victim->coords;
2393 if (!victim->skeleton.free)
2394 where = DoRotation(where, 0, -victim->yaw, 0);
2396 where = weapons[weaponids[weaponactive]].tippoint;
2397 where -= victim->coords;
2398 if (!victim->skeleton.free)
2399 where = DoRotation(where, 0, -victim->yaw, 0);
2404 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2405 footpoint += victim->coords;
2407 if (whichtri == -1) {
2408 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2411 if (weapons[weaponids[weaponactive]].getType() == staff) {
2412 XYZ where, startpoint, endpoint, movepoint;
2413 float rotationpoint;
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);
2429 whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2430 footpoint += victim->coords;
2432 if (whichtri == -1) {
2433 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2436 hasvictim = victim->DoBloodBigWhere(2, 220, footpoint);
2438 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2439 victim->skeleton.longdead = 0;
2440 victim->skeleton.free = 1;
2441 victim->skeleton.broken = 0;
2443 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2444 victim->skeleton.joints[i].velchange = 0;
2445 victim->skeleton.joints[i].locked = 0;
2446 //victim->skeleton.joints[i].velocity=0;
2452 Normalise(&relative);
2453 //victim->Puff(abdomen);
2455 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2457 if (victim->bloodloss < victim->damagetolerance) {
2458 victim->bloodloss += 1000;
2462 victim->jointVel(abdomen) += relative * damagemult * 20;
2466 if (!hasvictim && onterrain) {
2467 weapons[weaponids[weaponactive]].bloody = 0;
2468 weapons[weaponids[weaponactive]].blooddrip = 0;
2472 if (animTarget == upunchanim && animation[animTarget].label[frameCurrent] == 5) {
2473 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2481 if (tutoriallevel != 1) {
2482 emit_sound_at(heavyimpactsound, victim->coords, 128);
2487 relative = victim->coords - coords;
2489 Normalise(&relative);
2490 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2491 victim->skeleton.joints[i].velocity = relative * 30;
2493 victim->jointVel(head) += relative * damagemult * 150;
2495 victim->frameTarget = 0;
2496 victim->animTarget = staggerbackhardanim;
2497 victim->targetyaw = targetyaw + 180;
2499 victim->stunned = 1;
2502 victim->Puff(abdomen);
2503 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2510 if (animTarget == winduppunchanim && animation[animTarget].label[frameCurrent] == 5) {
2511 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) {
2515 if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height != lowheight) {
2516 if (tutoriallevel != 1) {
2517 emit_sound_at(thudsound, victim->coords);
2519 } else if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height == lowheight) {
2520 if (tutoriallevel != 1) {
2521 emit_sound_at(whooshhitsound, victim->coords);
2524 if (tutoriallevel != 1) {
2525 emit_sound_at(heavyimpactsound, victim->coords);
2529 if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || animation[victim->animTarget].height == lowheight)
2532 relative = victim->coords - coords;
2534 Normalise(&relative);
2536 Normalise(&relative);
2537 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2538 victim->skeleton.joints[i].velocity = relative * 5;
2540 victim->jointVel(abdomen) += relative * damagemult * 400;
2542 victim->frameTarget = 0;
2543 victim->animTarget = staggerbackhardanim;
2544 victim->targetyaw = targetyaw + 180;
2546 victim->stunned = 1;
2548 victim->Puff(abdomen);
2549 victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2555 if (animTarget == blockhighleftanim && animation[animTarget].label[frameCurrent] == 5) {
2556 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2557 if (victim->id == 0)
2559 emit_sound_at(landsound2, victim->coords);
2565 if (animTarget == swordslashparryanim && animation[animTarget].label[frameCurrent] == 5) {
2566 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2567 if (victim->id == 0)
2570 if (weaponactive != -1) {
2571 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2572 if (weapons[victim->weaponids[0]].getType() == staff)
2573 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2574 if (weapons[weaponids[0]].getType() == staff)
2575 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2577 emit_sound_at(swordstaffsound, victim->coords);
2579 emit_sound_at(metalhitsound, victim->coords);
2587 if (animTarget == knifethrowanim && animation[animTarget].label[frameCurrent] == 5) {
2588 if (weaponactive != -1) {
2591 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);
2593 weapons[weaponids[0]].thrown(aim * 50);
2596 weaponids[0] = weaponids[num_weapons];
2602 if (animTarget == knifeslashstartanim && animation[animTarget].label[frameCurrent] == 5) {
2604 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 &&/*animation[victim->animTarget].height!=lowheight&&*/victim->animTarget != dodgebackanim && victim->animTarget != rollanim) {
2606 if (tutoriallevel != 1)
2607 victim->DoBloodBig(1.5 / victim->armorhigh, 225);
2609 award_bonus(id, Slicebonus);
2610 if (tutoriallevel != 1) {
2611 emit_sound_at(knifeslicesound, victim->coords);
2613 //victim->jointVel(abdomen)+=relative*damagemult*200;
2614 if (animation[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
2615 if (victim->id != 0 || difficulty == 2) {
2616 victim->frameTarget = 0;
2617 victim->animTarget = staggerbackhardanim;
2618 victim->targetyaw = targetyaw + 180;
2622 victim->lowreversaldelay = 0;
2623 victim->highreversaldelay = 0;
2624 if (aitype != playercontrolled)
2625 weaponmissdelay = .6;
2627 if (tutoriallevel != 1)
2628 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2629 weapons[weaponids[weaponactive]].bloody = 1;
2630 if (tutoriallevel != 1)
2631 weapons[weaponids[weaponactive]].blooddrip += 3;
2633 XYZ footvel, footpoint;
2635 if (skeleton.free) {
2636 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2638 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2640 if (tutoriallevel != 1) {
2642 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .6, .3);
2643 footvel = DoRotation(facing, 0, 90, 0) * .8;
2645 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2646 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2647 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
2648 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
2650 if (tutoriallevel == 1) {
2651 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .6, .3);
2653 victim->DoDamage(damagemult * 0);
2656 if (animTarget == swordslashanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2657 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) {
2658 if (victim->weaponactive == -1 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) {
2659 award_bonus(id, Slashbonus);
2661 if (tutoriallevel != 1) {
2662 if (normaldotproduct(victim->facing, victim->coords - coords) < 0)
2663 victim->DoBloodBig(2 / victim->armorhigh, 190);
2665 victim->DoBloodBig(2 / victim->armorhigh, 185);
2666 victim->deathbleeding = 1;
2667 emit_sound_at(swordslicesound, victim->coords);
2669 //victim->jointVel(abdomen)+=relative*damagemult*200;
2670 if (tutoriallevel != 1) {
2671 victim->frameTarget = 0;
2672 victim->animTarget = staggerbackhardanim;
2673 victim->targetyaw = targetyaw + 180;
2677 if (tutoriallevel != 1) {
2678 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2679 weapons[weaponids[weaponactive]].bloody = 1;
2680 weapons[weaponids[weaponactive]].blooddrip += 3;
2682 float bloodlossamount;
2683 bloodlossamount = 200 + abs((float)(Random() % 40)) - 20;
2684 victim->bloodloss += bloodlossamount / victim->armorhigh;
2685 //victim->bloodloss+=100*(6.5-distsq(&coords,&victim->coords));
2686 victim->DoDamage(damagemult * 0);
2688 XYZ footvel, footpoint;
2690 if (skeleton.free) {
2691 footpoint = (victim->jointPos(abdomen) + victim->jointPos(neck)) / 2 * victim->scale + victim->coords;
2693 footpoint = DoRotation((victim->jointPos(abdomen) + victim->jointPos(neck)) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2696 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
2697 footvel = DoRotation(facing, 0, 90, 0) * .8;
2699 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2700 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2701 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
2702 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
2705 if (victim->weaponactive != -1) {
2706 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2707 if (weapons[victim->weaponids[0]].getType() == staff)
2708 weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2709 if (weapons[weaponids[0]].getType() == staff)
2710 weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2712 emit_sound_at(swordstaffsound, victim->coords);
2714 emit_sound_at(metalhitsound, victim->coords);
2720 victim->Puff(righthand);
2722 victim->frameTarget = 0;
2723 victim->animTarget = staggerbackhighanim;
2724 victim->targetyaw = targetyaw + 180;
2726 aim = DoRotation(facing, 0, 90, 0) * 21;
2728 weapons[victim->weaponids[0]].drop(aim * -.2, aim);
2729 victim->num_weapons--;
2730 if (victim->num_weapons) {
2731 victim->weaponids[0] = victim->weaponids[num_weapons];
2732 if (victim->weaponstuck == victim->num_weapons)
2733 victim->weaponstuck = 0;
2735 victim->weaponactive = -1;
2736 for (unsigned i = 0; i < Person::players.size(); i++) {
2737 Person::players[i]->wentforweapon = 0;
2744 if (animTarget == staffhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2745 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2746 if (tutoriallevel != 1) {
2747 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 250;
2751 if (Random() % 2 || creature == wolftype) {
2754 emit_sound_at(staffheadsound, victim->coords);
2758 relative = victim->coords - coords;
2760 Normalise(&relative);
2761 relative = DoRotation(relative, 0, 90, 0);
2763 Normalise(&relative);
2764 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2765 victim->skeleton.joints[i].velocity += relative * damagemult * 60;
2767 victim->jointVel(head) += relative * damagemult * 230;
2768 victim->jointVel(neck) += relative * damagemult * 230;
2771 if (tutoriallevel != 1) {
2772 victim->DoDamage(damagemult * 120 / victim->protectionhigh);
2774 award_bonus(id, solidhit, 30);
2779 if (animTarget == staffspinhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2780 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2781 if (tutoriallevel != 1) {
2782 weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250;
2786 if (Random() % 2 || creature == wolftype) {
2789 emit_sound_at(staffheadsound, victim->coords);
2793 relative = victim->coords - coords;
2795 Normalise(&relative);
2796 relative = DoRotation(relative, 0, -90, 0);
2797 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2798 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2800 victim->jointVel(head) += relative * damagemult * 220;
2801 victim->jointVel(neck) += relative * damagemult * 220;
2804 if (tutoriallevel != 1) {
2805 victim->DoDamage(damagemult * 350 / victim->protectionhead);
2807 award_bonus(id, solidhit, 60);
2812 if (animTarget == staffgroundsmashanim && animation[animTarget].label[frameCurrent] == 5) {
2813 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) {
2815 if (tutoriallevel != 1) {
2817 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500;
2820 if (Random() % 2 || creature == wolftype) {
2823 emit_sound_at(staffbodysound, victim->coords);
2825 victim->skeleton.longdead = 0;
2826 victim->skeleton.free = 1;
2827 victim->skeleton.broken = 0;
2829 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2830 victim->skeleton.joints[i].velchange = 0;
2831 victim->skeleton.joints[i].locked = 0;
2832 //victim->skeleton.joints[i].velocity=0;
2838 /*relative=victim->coords-coords;
2840 Normalise(&relative);
2841 relative=DoRotation(relative,0,90,0);*/
2843 Normalise(&relative);
2844 if (!victim->dead) {
2845 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2846 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
2849 victim->jointVel(abdomen) += relative * damagemult * 40;
2852 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2853 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
2856 //victim->jointVel(abdomen)+=relative*damagemult*20;
2858 victim->Puff(abdomen);
2859 if (tutoriallevel != 1) {
2860 victim->DoDamage(damagemult * 100 / victim->protectionhigh);
2862 if (!victim->dead) {
2863 award_bonus(id, solidhit, 40);
2869 if (animTarget == lowkickanim && animation[animTarget].label[frameCurrent] == 5) {
2870 if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != highheight) {
2875 relative = victim->coords - coords;
2877 Normalise(&relative);
2881 if (animation[victim->animTarget].height == lowheight) {
2887 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2888 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2890 victim->jointVel(head) += relative * damagemult * 200;
2891 if (tutoriallevel != 1) {
2892 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2895 victim->DoDamage(damagemult * 100 / victim->protectionhead);
2896 if (victim->howactive == typesleeping)
2897 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2898 if (creature == wolftype) {
2899 emit_sound_at(clawslicesound, victim->coords, 128.);
2901 victim->DoBloodBig(2 / victim->armorhead, 175);
2904 if (victim->damage >= victim->damagetolerance)
2906 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2907 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
2909 victim->jointVel(abdomen) += relative * damagemult * 200;
2910 victim->frameTarget = 0;
2911 victim->animTarget = staggerbackhighanim;
2912 victim->targetyaw = targetyaw + 180;
2914 if (tutoriallevel != 1) {
2915 emit_sound_at(landsound2, victim->coords, 128.);
2917 victim->Puff(abdomen);
2918 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
2919 if (creature == wolftype) {
2920 emit_sound_at(clawslicesound, victim->coords, 128.);
2922 victim->DoBloodBig(2 / victim->armorhigh, 170);
2929 if (animTarget == sweepanim && animation[animTarget].label[frameCurrent] == 5) {
2930 if ((victim->animTarget != jumpupanim) &&
2931 (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) &&
2932 (victim != this->shared_from_this())) {
2936 if (tutoriallevel != 1) {
2937 emit_sound_at(landsound2, victim->coords, 128.);
2940 relative = victim->coords - coords;
2942 Normalise(&relative);
2944 if (animation[victim->animTarget].height == middleheight || animation[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
2947 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2948 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
2950 relative = DoRotation(relative, 0, -90, 0);
2952 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2953 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)
2954 victim->skeleton.joints[i].velocity = relative * 80;
2956 victim->Puff(rightankle);
2957 victim->Puff(leftankle);
2958 victim->DoDamage(damagemult * 40 / victim->protectionlow);
2960 if (victim->damage >= victim->damagetolerance)
2962 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2963 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
2965 relative = DoRotation(relative, 0, -90, 0);
2966 for (int i = 0; i < victim->skeleton.num_joints; i++) {
2967 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)
2968 victim->skeleton.joints[i].velocity += relative * damagemult * 80;
2970 victim->jointVel(abdomen) += relative * damagemult * 200;
2971 victim->frameTarget = 0;
2972 victim->animTarget = staggerbackhighanim;
2973 victim->targetyaw = targetyaw + 180;
2975 if (tutoriallevel != 1) {
2976 emit_sound_at(landsound2, victim->coords, 128.);
2978 victim->Puff(abdomen);
2979 victim->DoDamage(damagemult * 30 / victim->protectionlow);
2987 if (animation[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) {
2988 if (animTarget == spinkickreversalanim && animation[animTarget].label[frameCurrent] == 7) {
2996 if (tutoriallevel != 1) {
2997 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2999 if (creature == wolftype) {
3000 emit_sound_at(clawslicesound, victim->coords, 128);
3002 victim->DoBloodBig(2 / victim->armorhigh, 170);
3006 relative = victim->coords - oldcoords;
3008 Normalise(&relative);
3009 //relative=DoRotation(relative,0,-90,0);
3010 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3011 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3013 victim->jointVel(abdomen) += relative * damagemult * 200;
3015 victim->Puff(abdomen);
3016 victim->DoDamage(damagemult * 150 / victim->protectionhigh);
3018 award_bonus(id, Reversal);
3021 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && animation[animTarget].label[frameCurrent] == 5) {
3022 if (victim->weaponactive != -1 && victim->num_weapons > 0) {
3023 if (weapons[victim->weaponids[victim->weaponactive]].owner == int(victim->id)) {
3024 takeWeapon(victim->weaponids[victim->weaponactive]);
3025 victim->num_weapons--;
3026 if (victim->num_weapons > 0) {
3027 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
3029 victim->weaponactive = -1;
3034 if (animTarget == staffhitreversalanim && animation[animTarget].label[frameCurrent] == 5) {
3042 emit_sound_at(whooshhitsound, victim->coords, 128.);
3045 relative = victim->coords - oldcoords;
3047 Normalise(&relative);
3048 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3049 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3051 victim->jointVel(abdomen) += relative * damagemult * 200;
3053 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3056 if (animTarget == staffspinhitreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3065 award_bonus(id, staffreversebonus);
3067 if (tutoriallevel != 1) {
3068 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3071 award_bonus(id, staffreversebonus); // Huh, again?
3074 relative = victim->coords - oldcoords;
3076 Normalise(&relative);
3077 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3078 victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3080 victim->jointVel(abdomen) += relative * damagemult * 200;
3082 victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3085 if (animTarget == upunchreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3091 Normalise(&relative);
3093 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3094 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3096 victim->jointVel(lefthand) *= .1;
3097 victim->jointVel(leftwrist) *= .2;
3098 victim->jointVel(leftelbow) *= .5;
3099 victim->jointVel(leftshoulder) *= .7;
3100 victim->jointVel(righthand) *= .1;
3101 victim->jointVel(rightwrist) *= .2;
3102 victim->jointVel(rightelbow) *= .5;
3103 victim->jointVel(rightshoulder) *= .7;
3105 victim->Puff(abdomen);
3106 victim->DoDamage(damagemult * 90 / victim->protectionhigh);
3108 award_bonus(id, Reversal);
3112 if (weaponactive != -1 || creature == wolftype)
3114 if (creature == rabbittype && weaponactive != -1)
3115 if (weapons[weaponids[0]].getType() == staff)
3118 if (weaponactive != -1) {
3119 victim->DoBloodBig(2 / victim->armorhigh, 225);
3120 emit_sound_at(knifeslicesound, victim->coords);
3121 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3122 weapons[weaponids[weaponactive]].bloody = 1;
3123 weapons[weaponids[weaponactive]].blooddrip += 3;
3125 if (weaponactive == -1 && creature == wolftype) {
3127 emit_sound_at(clawslicesound, victim->coords, 128.);
3129 victim->DoBloodBig(2 / victim->armorhigh, 175);
3136 if (animTarget == swordslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3142 Normalise(&relative);
3144 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3145 victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3147 victim->jointVel(lefthand) *= .1 - 1;
3148 victim->jointVel(leftwrist) *= .2 - 1;
3149 victim->jointVel(leftelbow) *= .5 - 1;
3150 victim->jointVel(leftshoulder) *= .7 - 1;
3151 victim->jointVel(righthand) *= .1 - 1;
3152 victim->jointVel(rightwrist) *= .2 - 1;
3153 victim->jointVel(rightelbow) *= .5 - 1;
3154 victim->jointVel(rightshoulder) *= .7 - 1;
3156 award_bonus(id, swordreversebonus);
3159 if (hasvictim && animTarget == knifeslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3167 if (tutoriallevel != 1) {
3168 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3172 relative = victim->coords - oldcoords;
3174 Normalise(&relative);
3175 relative = DoRotation(relative, 0, -90, 0);
3176 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3177 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3179 victim->jointVel(abdomen) += relative * damagemult * 200;
3180 victim->Puff(abdomen);
3181 victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3183 award_bonus(id, Reversal);
3186 if (hasvictim && animTarget == sneakattackanim && animation[animTarget].label[frameCurrent] == 7) {
3189 victim->skeleton.spinny = 0;
3191 relative = facing * -1;
3193 Normalise(&relative);
3194 if (victim->id == 0)
3196 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3197 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3199 victim->damage = victim->damagetolerance;
3200 victim->permanentdamage = victim->damagetolerance - 1;
3203 if (weaponactive != -1 || creature == wolftype)
3205 if (creature == rabbittype && weaponactive != -1)
3206 if (weapons[weaponids[0]].getType() == staff)
3209 if (weaponactive != -1) {
3210 victim->DoBloodBig(200, 225);
3211 emit_sound_at(knifeslicesound, victim->coords);
3213 weapons[weaponids[weaponactive]].bloody = 2;
3214 weapons[weaponids[weaponactive]].blooddrip += 5;
3217 if (creature == wolftype && weaponactive == -1) {
3218 emit_sound_at(clawslicesound, victim->coords, 128.);
3220 victim->DoBloodBig(2, 175);
3223 award_bonus(id, spinecrusher);
3226 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3227 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3229 if (animTarget == knifefollowanim)
3230 victim->DoBloodBig(200, 210);
3231 if (animTarget == knifesneakattackanim) {
3232 XYZ footvel, footpoint;
3234 footpoint = weapons[weaponids[0]].tippoint;
3236 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3237 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3238 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3239 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3240 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3241 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3242 victim->DoBloodBig(200, 195);
3243 award_bonus(id, tracheotomy);
3245 if (animTarget == knifefollowanim) {
3246 award_bonus(id, Stabbonus);
3247 XYZ footvel, footpoint;
3249 footpoint = weapons[weaponids[0]].tippoint;
3251 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3252 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3253 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3254 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3255 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3256 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3259 victim->bloodloss += 10000;
3260 victim->velocity = 0;
3261 emit_sound_at(fleshstabsound, victim->coords);
3263 weapons[weaponids[weaponactive]].bloody = 2;
3264 weapons[weaponids[weaponactive]].blooddrip += 5;
3268 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 6) {
3270 victim->velocity = 0;
3271 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3272 victim->skeleton.joints[i].velocity = 0;
3274 if (animTarget == knifefollowanim) {
3276 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3277 victim->skeleton.joints[i].velocity = 0;
3280 if (weaponactive != -1 && animation[victim->animTarget].attack != reversal) {
3281 emit_sound_at(fleshstabremovesound, victim->coords);
3283 weapons[weaponids[weaponactive]].bloody = 2;
3284 weapons[weaponids[weaponactive]].blooddrip += 5;
3286 XYZ footvel, footpoint;
3288 footpoint = weapons[weaponids[0]].tippoint;
3290 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3291 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3292 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3293 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3294 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3295 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3299 if (hasvictim && (animTarget == swordsneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3300 if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3301 award_bonus(id, backstab);
3305 XYZ footvel, footpoint;
3307 footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2;
3309 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3310 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3311 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3312 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3313 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 5, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3314 Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3315 victim->DoBloodBig(200, 180);
3316 victim->DoBloodBig(200, 215);
3317 victim->bloodloss += 10000;
3318 victim->velocity = 0;
3319 emit_sound_at(fleshstabsound, victim->coords);
3321 weapons[weaponids[weaponactive]].bloody = 2;
3322 weapons[weaponids[weaponactive]].blooddrip += 5;
3326 if (hasvictim && animTarget == swordsneakattackanim && animation[animTarget].label[frameCurrent] == 6) {
3328 victim->velocity = 0;
3329 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3330 victim->skeleton.joints[i].velocity = 0;
3332 if (weaponactive != -1) {
3333 emit_sound_at(fleshstabremovesound, victim->coords);
3335 weapons[weaponids[weaponactive]].bloody = 2;
3336 weapons[weaponids[weaponactive]].blooddrip += 5;
3338 XYZ footvel, footpoint;
3340 footpoint = weapons[weaponids[0]].tippoint;
3342 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3343 footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3344 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3345 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3346 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3347 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3351 if (animTarget == sweepreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3359 if (weaponactive == -1) {
3360 if (tutoriallevel != 1) {
3361 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3366 if (weaponactive != -1 || creature == wolftype)
3368 if (creature == rabbittype && weaponactive != -1)
3369 if (weapons[weaponids[0]].getType() == staff)
3372 if (weaponactive != -1) {
3373 victim->DoBloodBig(2 / victim->armorhead, 225);
3374 emit_sound_at(knifeslicesound, victim->coords);
3375 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3376 weapons[weaponids[weaponactive]].bloody = 1;
3377 weapons[weaponids[weaponactive]].blooddrip += 3;
3379 if (weaponactive == -1 && creature == wolftype) {
3380 emit_sound_at(clawslicesound, victim->coords, 128.);
3382 victim->DoBloodBig(2 / victim->armorhead, 175);
3386 award_bonus(id, Reversal);
3391 relative = facing * -1;
3393 Normalise(&relative);
3394 relative = DoRotation(relative, 0, 90, 0);
3396 Normalise(&relative);
3397 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3398 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3400 victim->jointVel(head) += relative * damagemult * 200;
3401 if (victim->damage < victim->damagetolerance - 100)
3402 victim->velocity = relative * 200;
3403 victim->DoDamage(damagemult * 100 / victim->protectionhead);
3404 victim->velocity = 0;
3407 if (animTarget == sweepreversalanim && ((animation[animTarget].label[frameCurrent] == 9 && victim->damage < victim->damagetolerance) || (animation[animTarget].label[frameCurrent] == 7 && victim->damage > victim->damagetolerance))) {
3411 relative = facing * -1;
3413 Normalise(&relative);
3414 relative = DoRotation(relative, 0, 90, 0);
3416 Normalise(&relative);
3417 for (int i = 0; i < victim->skeleton.num_joints; i++) {
3418 victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3420 victim->jointVel(head) += relative * damagemult * 200;
3423 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim))
3424 if (victim->damage > victim->damagetolerance && bonus != reverseko) {
3425 award_bonus(id, reverseko);
3431 if (frameTarget > animation[animCurrent].numframes - 1) {
3434 animTarget = getIdle();
3438 if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) {
3439 animTarget = rollanim;
3441 emit_sound_at(movewhooshsound, coords, 128.);
3443 if (animCurrent == staggerbackhighanim) {
3444 animTarget = getIdle();
3446 if (animCurrent == staggerbackhardanim) {
3447 animTarget = getIdle();
3449 if (animCurrent == removeknifeanim) {
3450 animTarget = getIdle();
3452 if (animCurrent == crouchremoveknifeanim) {
3453 animTarget = getCrouch();
3455 if (animCurrent == backhandspringanim) {
3456 animTarget = getIdle();
3458 if (animCurrent == dodgebackanim) {
3459 animTarget = getIdle();
3461 if (animCurrent == drawleftanim) {
3462 animTarget = getIdle();
3464 if (animCurrent == drawrightanim || animCurrent == crouchdrawrightanim) {
3465 animTarget = getIdle();
3466 if (animCurrent == crouchdrawrightanim) {
3467 animTarget = getCrouch();
3469 if (weaponactive == -1)
3471 else if (weaponactive == 0) {
3473 if (num_weapons == 2) {
3475 buffer = weaponids[0];
3476 weaponids[0] = weaponids[1];
3477 weaponids[1] = buffer;
3481 if (weaponactive == -1) {
3482 emit_sound_at(knifesheathesound, coords, 128.);
3484 if (weaponactive != -1) {
3485 emit_sound_at(knifedrawsound, coords, 128.);
3488 if (animCurrent == rollanim) {
3489 animTarget = getCrouch();
3494 if (animTarget == walljumprightkickanim) {
3497 if (animTarget == walljumpleftkickanim) {
3500 animTarget = jumpdownanim;
3502 if (animCurrent == climbanim) {
3503 animTarget = getCrouch();
3505 coords += facing * .1;
3506 if (!isnormal(coords.x))
3517 if (animTarget == rabbitkickreversalanim) {
3518 animTarget = getCrouch();
3521 if (animTarget == jumpreversalanim) {
3522 animTarget = getCrouch();
3525 if (animTarget == walljumprightanim || animTarget == walljumpbackanim || animTarget == walljumpfrontanim) {
3526 if (attackkeydown && animTarget != walljumpfrontanim) {
3528 float closestdist = -1;
3530 if (Person::players.size() > 1)
3531 for (unsigned i = 0; i < Person::players.size(); i++) {
3532 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3533 distance = distsq(&Person::players[i]->coords, &coords);
3534 if (closestdist == -1 || distance < closestdist) {
3535 closestdist = distance;
3540 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3541 victim = Person::players[closest];
3542 animTarget = walljumprightkickanim;
3544 XYZ rotatetarget = victim->coords - coords;
3545 Normalise(&rotatetarget);
3546 yaw = -asin(0 - rotatetarget.x);
3548 if (rotatetarget.z < 0)
3550 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3551 velocity = (victim->coords - coords) * 4;
3556 if (animTarget == walljumpbackanim) {
3557 animTarget = backflipanim;
3559 velocity = facing * -8;
3562 resume_stream(whooshsound);
3564 if (animTarget == walljumprightanim) {
3565 animTarget = rightflipanim;
3569 velocity = DoRotation(facing, 0, 30, 0) * -8;
3572 if (animTarget == walljumpfrontanim) {
3573 animTarget = frontflipanim;
3577 velocity = facing * 8;
3581 resume_stream(whooshsound);
3583 if (animTarget == walljumpleftanim) {
3584 if (attackkeydown) {
3586 float closestdist = -1;
3588 if (Person::players.size() > 1)
3589 for (unsigned i = 0; i < Person::players.size(); i++) {
3590 if (id != i && Person::players[i]->coords.y < coords.y && !Person::players[i]->skeleton.free) {
3591 distance = distsq(&Person::players[i]->coords, &coords);
3592 if (closestdist == -1 || distance < closestdist) {
3593 closestdist = distance;
3598 if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3599 victim = Person::players[closest];
3600 animTarget = walljumpleftkickanim;
3602 XYZ rotatetarget = victim->coords - coords;
3603 Normalise(&rotatetarget);
3604 yaw = -asin(0 - rotatetarget.x);
3606 if (rotatetarget.z < 0)
3608 targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3609 velocity = (victim->coords - coords) * 4;
3614 if (animTarget != walljumpleftkickanim) {
3615 animTarget = leftflipanim;
3619 velocity = DoRotation(facing, 0, -30, 0) * -8;
3623 resume_stream(whooshsound);
3625 if (animTarget == sneakattackanim) {
3626 animCurrent = getCrouch();
3627 animTarget = getCrouch();
3634 transspeed = 1000000;
3635 targetheadyaw += 180;
3636 coords -= facing * .7;
3638 coords.y = terrain.getHeight(coords.x, coords.z);
3642 if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) {
3643 animTarget = getIdle();
3646 coords.y = terrain.getHeight(coords.x, coords.z);
3650 if (animCurrent == knifefollowanim) {
3651 animTarget = getIdle();
3654 if (animation[animTarget].attack == reversal && animCurrent != sneakattackanim && animCurrent != knifesneakattackanim && animCurrent != swordsneakattackanim && animCurrent != knifefollowanim) {
3655 float ycoords = oldcoords.y;
3656 animTarget = getStop();
3661 transspeed = 1000000;
3662 targetheadyaw += 180;
3663 if (!isnormal(coords.x))
3665 if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim)
3666 oldcoords = coords + facing * .5;
3667 else if (animCurrent == sweepreversalanim)
3668 oldcoords = coords + facing * 1.1;
3669 else if (animCurrent == upunchreversalanim) {
3670 oldcoords = coords + facing * 1.5;
3673 targetheadyaw += 180;
3676 } else if (animCurrent == knifeslashreversalanim) {
3677 oldcoords = coords + facing * .5;
3680 targetheadyaw += 90;
3683 } else if (animCurrent == staffspinhitreversalanim) {
3686 targetheadyaw += 180;
3691 oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z);
3693 oldcoords.y = ycoords;
3694 currentoffset = coords - oldcoords;
3700 if (animCurrent == knifesneakattackedanim || animCurrent == swordsneakattackedanim) {
3705 if (animation[animTarget].attack == reversed) {
3707 if (animTarget == sweepreversedanim)
3709 animTarget = backhandspringanim;
3711 emit_sound_at(landsound, coords, 128);
3713 if (animCurrent == upunchreversedanim || animCurrent == swordslashreversedanim) {
3714 animTarget = rollanim;
3717 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3718 coords.y = oldcoords.y;
3720 if (animCurrent == knifeslashreversedanim) {
3721 animTarget = rollanim;
3726 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3727 coords.y = oldcoords.y;
3731 animTarget = jumpdownanim;
3734 animTarget = getIdle();
3736 animTarget = getIdle();
3737 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
3738 animTarget = getIdle();
3740 coords += (DoRotation(jointPos(leftfoot), 0, yaw, 0) + DoRotation(jointPos(rightfoot), 0, yaw, 0)) / 2 * scale;
3741 coords.y = oldcoords.y;
3742 //coords+=DoRotation(animation[animCurrent].offset,0,yaw,0)*scale;
3743 targetoffset.y = coords.y;
3745 targetoffset.y = terrain.getHeight(coords.x, coords.z);
3746 currentoffset = DoRotation(animation[animCurrent].offset * -1, 0, yaw, 0) * scale;
3747 currentoffset.y -= (coords.y - targetoffset.y);
3748 coords.y = targetoffset.y;
3750 normalsupdatedelay = 0;
3752 if (animCurrent == upunchanim) {
3753 animTarget = getStop();
3754 normalsupdatedelay = 0;
3757 if (animCurrent == rabbitkickanim && animTarget != backflipanim) {
3761 if (num_weapons > 0)
3762 if (weapons[0].getType() == staff)
3768 rabbitkickragdoll = 1;
3770 if (animCurrent == rabbitkickreversedanim) {
3776 skeleton.spinny = 0;
3777 SolidHitBonus(!id); // FIXME: tricky id
3781 animTarget = rollanim;
3784 pause_sound(whooshsound);
3788 if (animCurrent == rabbittackledbackanim || animCurrent == rabbittackledfrontanim) {
3792 skeleton.spinny = 0;
3794 if (animCurrent == jumpreversedanim) {
3800 skeleton.spinny = 0;
3801 SolidHitBonus(!id); // FIXME: tricky id
3805 animTarget = rollanim;
3806 coords += facing * 2;
3808 pause_sound(whooshsound);
3813 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) {
3814 animTarget = getupfromfrontanim;
3816 } else if (animation[animCurrent].attack == normalattack) {
3817 animTarget = getIdle();
3820 if (animCurrent == blockhighleftanim && aitype != playercontrolled) {
3821 animTarget = blockhighleftstrikeanim;
3823 if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) {
3824 animTarget = getIdle();
3827 if (animCurrent == spinkickanim && victim->skeleton.free) {
3828 if (creature == rabbittype)
3829 animTarget = fightidleanim;
3834 if (isIdle() && !wasIdle())
3835 normalsupdatedelay = 0;
3837 if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) {
3838 animTarget = jumpdownanim;
3841 if (!skeleton.free) {
3843 if (!transspeed && animation[animTarget].attack != 2 && animation[animTarget].attack != 3) {
3844 if (!isRun() || !wasRun()) {
3845 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
3846 target += multiplier * animation[animTarget].speed[frameTarget] * speed * 2;
3847 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
3848 target += multiplier * animation[animCurrent].speed[frameCurrent] * speed * 2;
3850 if (isRun() && wasRun()) {
3852 tempspeed = velspeed;
3853 if (tempspeed < 10 * speedmult)
3854 tempspeed = 10 * speedmult;
3855 target += multiplier * animation[animTarget].speed[frameCurrent] * speed * 1.7 * tempspeed / (speed * 45 * scale);
3857 } else if (transspeed)
3858 target += multiplier * transspeed * speed * 2;
3860 if (!isRun() || !wasRun()) {
3861 if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
3862 target += multiplier * animation[animTarget].speed[frameTarget] * 2;
3863 if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
3864 target += multiplier * animation[animCurrent].speed[frameCurrent] * 2;
3868 if (animCurrent != animTarget)
3869 target = (target + oldtarget) / 2;
3872 frameCurrent = frameTarget;
3876 rot = targetrot * target;
3877 yaw += rot - oldrot;
3883 if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
3885 for (int i = 0; i < skeleton.num_joints; i++) {
3886 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent];
3889 skeleton.FindForwards();
3891 for (int i = 0; i < skeleton.num_muscles; i++) {
3892 if (skeleton.muscles[i].visible) {
3893 skeleton.FindRotationMuscle(i, animTarget);
3896 for (int i = 0; i < skeleton.num_muscles; i++) {
3897 if (skeleton.muscles[i].visible) {
3898 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
3899 skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
3900 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
3901 skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
3902 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
3903 skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
3908 for (int i = 0; i < skeleton.num_joints; i++) {
3909 skeleton.joints[i].position = animation[animTarget].position[i][frameTarget];
3912 skeleton.FindForwards();
3914 for (int i = 0; i < skeleton.num_muscles; i++) {
3915 if (skeleton.muscles[i].visible) {
3916 skeleton.FindRotationMuscle(i, animTarget);
3919 for (int i = 0; i < skeleton.num_muscles; i++) {
3920 if (skeleton.muscles[i].visible) {
3921 if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
3922 skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
3923 if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
3924 skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
3925 if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
3926 skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
3927 if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) skeleton.muscles[i].newrotate3 -= 360;
3928 if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) skeleton.muscles[i].newrotate3 += 360;
3929 if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) skeleton.muscles[i].newrotate2 -= 360;
3930 if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) skeleton.muscles[i].newrotate2 += 360;
3931 if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) skeleton.muscles[i].newrotate1 -= 360;
3932 if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) skeleton.muscles[i].newrotate1 += 360;
3936 if (frameCurrent >= animation[animCurrent].numframes)
3937 frameCurrent = animation[animCurrent].numframes - 1;
3939 oldanimCurrent = animCurrent;
3940 oldanimTarget = animTarget;
3941 oldframeTarget = frameTarget;
3942 oldframeCurrent = frameCurrent;
3944 for (int i = 0; i < skeleton.num_joints; i++) {
3945 skeleton.joints[i].velocity = (animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target) - skeleton.joints[i].position) / multiplier;
3946 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target);
3948 offset = currentoffset * (1 - target) + targetoffset * target;
3949 for (int i = 0; i < skeleton.num_muscles; i++) {
3950 if (skeleton.muscles[i].visible) {
3951 skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * (target);
3952 skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * (target);
3953 skeleton.muscles[i].rotate3 = skeleton.muscles[i].oldrotate3 * (1 - target) + skeleton.muscles[i].newrotate3 * (target);
3958 if (isLanding() && landhard) {
3961 animTarget = getLandhard();
3974 void Person::DoStuff()
3976 static XYZ terrainnormal;
3977 static XYZ flatfacing;
3978 static XYZ flatvelocity;
3979 static float flatvelspeed;
3983 static int bloodsize;
3984 static int startx, starty, endx, endy;
3985 static GLubyte color;
3986 static XYZ bloodvel;
3988 onfiredelay -= multiplier;
3989 if (onfiredelay < 0 && onfire) {
3990 if (Random() % 2 == 0) {
3996 crouchkeydowntime += multiplier;
3998 crouchkeydowntime = 0;
3999 jumpkeydowntime += multiplier;
4000 if (!jumpkeydown && skeleton.free)
4001 jumpkeydowntime = 0;
4003 if (hostile || damage > 0 || bloodloss > 0)
4006 if (isIdle() || isRun())
4009 if (num_weapons == 1 && weaponactive != -1)
4013 blooddimamount -= multiplier * .3;
4014 speechdelay -= multiplier;
4015 texupdatedelay -= multiplier;
4016 interestdelay -= multiplier;
4017 flamedelay -= multiplier;
4018 parriedrecently -= multiplier;
4020 victim = this->shared_from_this();
4025 speed = 1.1 * speedmult;
4027 speed = 1.0 * speedmult;
4029 rabbitkickragdoll = 0;
4033 if (id != 0 && (creature == rabbittype || difficulty != 2))
4035 if (id != 0 && creature == wolftype && difficulty == 2) {
4037 if (aitype != passivetype) {
4039 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) {
4045 if (animTarget == wolfrunninganim && !superruntoggle) {
4046 animTarget = getRun();
4050 if (weaponactive == -1 && num_weapons > 0) {
4051 if (weapons[weaponids[0]].getType() == staff) {
4057 burnt += multiplier;
4061 OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3);
4063 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
4069 vel[0] = velocity.x;
4070 vel[1] = velocity.y;
4071 vel[2] = velocity.z;
4074 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4075 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
4079 while (flamedelay < 0 && onfire) {
4081 howmany = abs(Random() % (skeleton.num_joints));
4082 if (skeleton.free) {
4083 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4084 flatfacing = skeleton.joints[howmany].position * scale + coords;
4086 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4087 flatvelocity = (coords - oldcoords) / multiplier / 2;
4089 Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
4092 while (flamedelay < 0 && !onfire && tutoriallevel == 1 && id != 0) {
4094 howmany = abs(Random() % (skeleton.num_joints));
4095 if (skeleton.free) {
4096 flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4097 flatfacing = skeleton.joints[howmany].position * scale + coords;
4099 flatvelocity = (coords - oldcoords) / multiplier / 2;
4100 flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4102 Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
4106 bleeding -= multiplier * .3;
4107 if (bloodtoggle == 2) {
4108 skeleton.drawmodel.textureptr.bind();
4109 if ((bleeding <= 0) && (detail != 2))
4114 if (neckspurtamount > 0) {
4115 neckspurtamount -= multiplier;
4116 neckspurtdelay -= multiplier * 3;
4117 neckspurtparticledelay -= multiplier * 3;
4118 if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
4121 if (skeleton.free) {
4122 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
4123 bloodvel += DoRotation(jointVel(head), ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4124 Sprite::MakeSprite(bloodsprite, (jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4126 bloodvel.z = 5 * neckspurtamount;
4127 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4128 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
4129 Sprite::MakeSprite(bloodsprite, DoRotation(jointPos(neck) + (jointPos(neck) - jointPos(head)) / 5, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4131 neckspurtparticledelay = .05;
4133 if (neckspurtdelay < 0) {
4138 if (deathbleeding > 0 && dead != 2) {
4139 if (deathbleeding < 5)
4140 bleeddelay -= deathbleeding * multiplier / 4;
4142 bleeddelay -= 5 * multiplier / 4;
4143 if (bleeddelay < 0 && bloodtoggle) {
4148 if (skeleton.free) {
4149 bloodvel += DoRotation(jointVel(abdomen), ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
4150 Sprite::MakeSprite(bloodsprite, jointPos(abdomen) * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4152 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
4153 Sprite::MakeSprite(bloodsprite, DoRotation((jointPos(abdomen) + jointPos(abdomen)) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
4157 bloodloss += deathbleeding * multiplier * 80;
4158 deathbleeding -= multiplier * 1.6;
4159 if (deathbleeding < 0)
4161 if (bloodloss > damagetolerance && animation[animTarget].attack == neutral) {
4162 if (weaponactive != -1) {
4163 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
4164 weapons[weaponids[0]].velocity.x += .01;
4167 weaponids[0] = weaponids[num_weapons];
4168 if (weaponstuck == num_weapons)
4172 for (unsigned i = 0; i < Person::players.size(); i++) {
4173 Person::players[i]->wentforweapon = 0;
4185 if (!dead && creature == wolftype) {
4186 award_bonus(0, Wolfbonus);
4189 if (animTarget == knifefollowedanim && !skeleton.free) {
4190 for (int i = 0; i < skeleton.num_joints; i++) {
4191 skeleton.joints[i].velocity = 0;
4192 skeleton.joints[i].velocity.y = -2;
4195 if (id != 0 && unconscioustime > .1) {
4203 if (texupdatedelay < 0 && bleeding > 0 && bloodtoggle == 2 && distsq(&viewer, &coords) < 9) {
4204 texupdatedelay = .12;
4206 bloodsize = 5 - realtexdetail;
4210 startx = bleedy; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4211 starty = bleedx; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4212 endx = startx + bloodsize;
4213 endy = starty + bloodsize;
4223 if (endx > skeleton.skinsize - 1) {
4224 endx = skeleton.skinsize - 1;
4227 if (endy > skeleton.skinsize - 1) {
4228 endy = skeleton.skinsize - 1;
4236 for (i = startx; i < endx; i++) {
4237 for (j = starty; j < endy; j++) {
4238 if (Random() % 2 == 0) {
4239 color = Random() % 85 + 170;
4240 if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2)
4241 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2;
4242 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0;
4243 skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0;
4248 skeleton.drawmodel.textureptr.bind();
4252 if (skeleton.free) {
4253 bleedx += 4 * direction / realtexdetail;
4255 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4257 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4259 bleedy -= 4 / realtexdetail;
4261 bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4263 bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4267 if (abs(righthandmorphness - targetrighthandmorphness) < multiplier * 4) {
4268 righthandmorphness = targetrighthandmorphness;
4269 righthandmorphstart = righthandmorphend;
4270 } else if (righthandmorphness > targetrighthandmorphness) {
4271 righthandmorphness -= multiplier * 4;
4272 } else if (righthandmorphness < targetrighthandmorphness) {
4273 righthandmorphness += multiplier * 4;
4276 if (abs(lefthandmorphness - targetlefthandmorphness) < multiplier * 4) {
4277 lefthandmorphness = targetlefthandmorphness;
4278 lefthandmorphstart = lefthandmorphend;
4279 } else if (lefthandmorphness > targetlefthandmorphness) {
4280 lefthandmorphness -= multiplier * 4;
4281 } else if (lefthandmorphness < targetlefthandmorphness) {
4282 lefthandmorphness += multiplier * 4;
4285 if (creature == rabbittype || targettailmorphness == 5 || targettailmorphness == 0) {
4286 if (abs(tailmorphness - targettailmorphness) < multiplier * 10) {
4287 tailmorphness = targettailmorphness;
4288 tailmorphstart = tailmorphend;
4289 } else if (tailmorphness > targettailmorphness) {
4290 tailmorphness -= multiplier * 10;
4291 } else if (tailmorphness < targettailmorphness) {
4292 tailmorphness += multiplier * 10;
4296 if (creature == wolftype) {
4297 if (abs(tailmorphness - targettailmorphness) < multiplier * 4) {
4298 tailmorphness = targettailmorphness;
4299 tailmorphstart = tailmorphend;
4300 } else if (tailmorphness > targettailmorphness) {
4301 tailmorphness -= multiplier * 2;
4302 } else if (tailmorphness < targettailmorphness) {
4303 tailmorphness += multiplier * 2;
4307 if (headmorphend == 3 || headmorphstart == 3) {
4308 if (abs(headmorphness - targetheadmorphness) < multiplier * 7) {
4309 headmorphness = targetheadmorphness;
4310 headmorphstart = headmorphend;
4311 } else if (headmorphness > targetheadmorphness) {
4312 headmorphness -= multiplier * 7;
4313 } else if (headmorphness < targetheadmorphness) {
4314 headmorphness += multiplier * 7;
4316 } else if (headmorphend == 5 || headmorphstart == 5) {
4317 if (abs(headmorphness - targetheadmorphness) < multiplier * 10) {
4318 headmorphness = targetheadmorphness;
4319 headmorphstart = headmorphend;
4320 } else if (headmorphness > targetheadmorphness) {
4321 headmorphness -= multiplier * 10;
4322 } else if (headmorphness < targetheadmorphness) {
4323 headmorphness += multiplier * 10;
4326 if (abs(headmorphness - targetheadmorphness) < multiplier * 4) {
4327 headmorphness = targetheadmorphness;
4328 headmorphstart = headmorphend;
4329 } else if (headmorphness > targetheadmorphness) {
4330 headmorphness -= multiplier * 4;
4331 } else if (headmorphness < targetheadmorphness) {
4332 headmorphness += multiplier * 4;
4336 if (abs(chestmorphness - targetchestmorphness) < multiplier) {
4337 chestmorphness = targetchestmorphness;
4338 chestmorphstart = chestmorphend;
4339 } else if (chestmorphness > targetchestmorphness) {
4340 chestmorphness -= multiplier;
4341 } else if (chestmorphness < targetchestmorphness) {
4342 chestmorphness += multiplier;
4345 if (dead != 2 && howactive <= typesleeping) {
4346 if (chestmorphstart == 0 && chestmorphend == 0) {
4348 targetchestmorphness = 1;
4351 if (chestmorphstart != 0 && chestmorphend != 0) {
4353 targetchestmorphness = 1;
4355 if (environment == snowyenvironment) {
4358 if (skeleton.free) {
4359 footvel = skeleton.specialforward[0] * -1;
4360 footpoint = ((jointPos(head) + jointPos(neck)) / 2) * scale + coords;
4362 footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
4363 footpoint = DoRotation((jointPos(head) + jointPos(neck)) / 2, 0, yaw, 0) * scale + coords;
4365 if (animTarget == sleepanim)
4366 footvel = DoRotation(footvel, 0, 90, 0);
4367 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
4371 if (!dead && howactive < typesleeping) {
4372 blinkdelay -= multiplier * 2;
4373 if (headmorphstart == 0 && headmorphend == 0 && blinkdelay <= 0) {
4375 targetheadmorphness = 1;
4377 blinkdelay = (float)(abs(Random() % 40)) / 5;
4379 if (headmorphstart == 3 && headmorphend == 3) {
4381 targetheadmorphness = 1;
4386 twitchdelay -= multiplier * 1.5;
4387 if (animTarget != hurtidleanim) {
4388 if (headmorphstart == 0 && headmorphend == 0 && twitchdelay <= 0) {
4390 targetheadmorphness = 1;
4392 twitchdelay = (float)(abs(Random() % 40)) / 5;
4394 if (headmorphstart == 5 && headmorphend == 5) {
4396 targetheadmorphness = 1;
4400 if ((isIdle() || isCrouch()) && animTarget != hurtidleanim) {
4401 twitchdelay3 -= multiplier * 1;
4402 if (Random() % 2 == 0) {
4403 if (righthandmorphstart == 0 && righthandmorphend == 0 && twitchdelay3 <= 0) {
4404 righthandmorphness = 0;
4405 targetrighthandmorphness = 1;
4406 righthandmorphend = 1;
4407 if (Random() % 2 == 0)twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4409 if (righthandmorphstart == 1 && righthandmorphend == 1) {
4410 righthandmorphness = 0;
4411 targetrighthandmorphness = 1;
4412 righthandmorphend = 0;
4415 if (Random() % 2 == 0) {
4416 if (lefthandmorphstart == 0 && lefthandmorphend == 0 && twitchdelay3 <= 0) {
4417 lefthandmorphness = 0;
4418 targetlefthandmorphness = 1;
4419 lefthandmorphend = 1;
4420 twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4422 if (lefthandmorphstart == 1 && lefthandmorphend == 1) {
4423 lefthandmorphness = 0;
4424 targetlefthandmorphness = 1;
4425 lefthandmorphend = 0;
4431 if (creature == rabbittype) {
4432 if (howactive < typesleeping)
4433 twitchdelay2 -= multiplier * 1.5;
4435 twitchdelay2 -= multiplier * 0.5;
4436 if (howactive <= typesleeping) {
4437 if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) {
4439 targettailmorphness = 1;
4441 twitchdelay2 = (float)(abs(Random() % 40)) / 5;
4443 if (tailmorphstart == 1 && tailmorphend == 1) {
4445 targettailmorphness = 1;
4448 if (tailmorphstart == 2 && tailmorphend == 2) {
4450 targettailmorphness = 1;
4457 if (creature == wolftype) {
4458 twitchdelay2 -= multiplier * 1.5;
4459 if (tailmorphend != 0)
4460 if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) {
4462 targettailmorphness = 1;
4466 if (tailmorphend != 5)
4467 if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) {
4469 targettailmorphness = 1;
4473 if (twitchdelay2 <= 0) {
4474 if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) {
4476 targettailmorphness = 1;
4479 if (tailmorphstart == 1 && tailmorphend == 1) {
4481 targettailmorphness = 1;
4484 if (tailmorphstart == 2 && tailmorphend == 2) {
4486 targettailmorphness = 1;
4489 if (tailmorphstart == 3 && tailmorphend == 3) {
4491 targettailmorphness = 1;
4494 if (tailmorphstart == 4 && tailmorphend == 4) {
4496 targettailmorphness = 1;
4503 unconscioustime = 0;
4505 if (dead == 1 || howactive == typesleeping) {
4506 unconscioustime += multiplier;
4507 //If unconscious, close eyes and mouth
4508 if (righthandmorphend != 0)
4509 righthandmorphness = 0;
4510 righthandmorphend = 0;
4511 targetrighthandmorphness = 1;
4513 if (lefthandmorphend != 0)
4514 lefthandmorphness = 0;
4515 lefthandmorphend = 0;
4516 targetlefthandmorphness = 1;
4518 if (headmorphend != 3 && headmorphend != 5)
4521 targetheadmorphness = 1;
4525 if (howactive > typesleeping) {
4528 if (bloodtoggle && !bled) {
4529 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4531 if (bloodtoggle && !bled)
4532 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4533 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4534 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4538 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4543 if (dead == 2 || howactive > typesleeping) {
4544 //If dead, open mouth and hands
4545 if (righthandmorphend != 0)
4546 righthandmorphness = 0;
4547 righthandmorphend = 0;
4548 targetrighthandmorphness = 1;
4550 if (lefthandmorphend != 0)
4551 lefthandmorphness = 0;
4552 lefthandmorphend = 0;
4553 targetlefthandmorphness = 1;
4555 if (headmorphend != 2)
4558 targetheadmorphness = 1;
4561 if (stunned > 0 && !dead && headmorphend != 2) {
4562 if (headmorphend != 4)
4565 targetheadmorphness = 1;
4568 if (damage > damagetolerance && !dead) {
4571 unconscioustime = 0;
4573 if (creature == wolftype) {
4574 award_bonus(0, Wolfbonus);
4579 if (weaponactive != -1) {
4580 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
4581 weapons[weaponids[0]].velocity.x += .01;
4584 weaponids[0] = weaponids[num_weapons];
4585 if (weaponstuck == num_weapons)
4589 for (unsigned i = 0; i < Person::players.size(); i++) {
4590 Person::players[i]->wentforweapon = 0;
4596 if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) {
4605 damage -= multiplier * 13;
4607 permanentdamage -= multiplier * 4;
4608 if (isIdle() || isCrouch()) {
4610 permanentdamage -= multiplier * 4;
4614 if (permanentdamage < 0)
4615 permanentdamage = 0;
4616 if (superpermanentdamage < 0)
4617 superpermanentdamage = 0;
4618 if (permanentdamage < superpermanentdamage) {
4619 permanentdamage = superpermanentdamage;
4621 if (damage < permanentdamage) {
4622 damage = permanentdamage;
4624 if (dead == 1 && damage < damagetolerance) {
4628 for (int i = 0; i < skeleton.num_joints; i++) {
4629 skeleton.joints[i].velocity = 0;
4632 if (permanentdamage > damagetolerance && dead != 2) {
4635 if (weaponactive != -1) {
4636 weapons[weaponids[0]].drop(velocity * scale * -.3, velocity * scale);
4637 weapons[weaponids[0]].velocity.x += .01;
4640 weaponids[0] = weaponids[num_weapons];
4641 if (weaponstuck == num_weapons)
4645 for (unsigned i = 0; i < Person::players.size(); i++) {
4646 Person::players[i]->wentforweapon = 0;
4652 if (!dead && creature == wolftype) {
4653 award_bonus(0, Wolfbonus);
4656 if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance)
4657 award_bonus(id, touchofdeath);
4658 if (id != 0 && unconscioustime > .1) {
4666 emit_sound_at(breaksound, coords);
4669 if (skeleton.free == 1) {
4671 pause_sound(whooshsound);
4674 //If knocked over, open hands and close mouth
4675 if (righthandmorphend != 0)
4676 righthandmorphness = 0;
4677 righthandmorphend = 0;
4678 targetrighthandmorphness = 1;
4680 if (lefthandmorphend != 0)
4681 lefthandmorphness = 0;
4682 lefthandmorphend = 0;
4683 targetlefthandmorphness = 1;
4685 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) {
4686 if (headmorphend != 0)
4689 targetheadmorphness = 1;
4693 skeleton.DoGravity(&scale);
4695 damageamount = skeleton.DoConstraints(&coords, &scale) * 5;
4696 if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1))
4697 award_bonus(id, deepimpact);
4698 DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3));
4702 for (j = 0; j < skeleton.num_joints; j++) {
4703 average += skeleton.joints[j].position;
4707 coords += average * scale;
4708 for (j = 0; j < skeleton.num_joints; j++) {
4709 skeleton.joints[j].position -= average;
4711 average /= multiplier;
4714 for (int i = 0; i < skeleton.num_joints; i++) {
4715 velocity += skeleton.joints[i].velocity * scale;
4717 velocity /= skeleton.num_joints;
4719 if (!isnormal(velocity.x) && velocity.x) {
4723 if (findLength(&average) < 10 && dead && skeleton.free) {
4724 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
4725 if (skeleton.longdead > 2000) {
4726 if (skeleton.longdead > 6000) {
4728 pause_sound(whooshsound);
4733 if (dead == 2 && bloodloss < damagetolerance) {
4735 headpoint = (jointPos(head) + jointPos(neck)) / 2 * scale + coords;
4737 if (bloodtoggle && !bled) {
4738 terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
4740 if (bloodtoggle && !bled)
4741 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4742 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4743 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4744 float size = .2 * 1.2;
4747 objects.model[j].MakeDecal(blooddecal, &point, &size, &opacity, &yaw);
4751 if (dead == 2 && bloodloss >= damagetolerance) {
4753 headpoint = (jointPos(abdomen) + jointPos(neck)) / 2 * scale + coords;
4756 if (bloodtoggle && !bled) {
4757 terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4759 if (bloodtoggle && !bled)
4760 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4761 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4762 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4766 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4773 if (!dead && crouchkeydown && skeleton.freetime > .5 && id == 0 && skeleton.free) {
4774 bool canrecover = 1;
4775 XYZ startpoint, endpoint, colpoint, colviewer, coltarget;
4776 startpoint = coords;
4779 if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1)
4781 if (velocity.y < -30)
4783 for (i = 0; i < objects.numobjects; i++) {
4784 if (objects.type[i] != treeleavestype && objects.type[i] != bushtype && objects.type[i] != firetype) {
4785 colviewer = startpoint;
4786 coltarget = endpoint;
4787 if (objects.model[i].LineCheck(&colviewer, &coltarget, &colpoint, &objects.position[i], &objects.yaw[i]) != -1)
4796 terrainnormal = jointPos(groin) - jointPos(abdomen);
4797 if (joint(groin).locked && joint(abdomen).locked) {
4798 terrainnormal = jointPos(groin) - jointPos(abdomen);
4799 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
4801 if (joint(abdomen).locked && joint(neck).locked) {
4802 terrainnormal = jointPos(abdomen) - jointPos(neck);
4803 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
4805 if (joint(groin).locked && joint(neck).locked) {
4806 terrainnormal = jointPos(groin) - jointPos(neck);
4807 middle = (jointPos(groin) + jointPos(neck)) / 2;
4809 Normalise(&terrainnormal);
4811 targetyaw = -asin(0 - terrainnormal.x);
4812 targetyaw *= 360 / 6.28;
4813 if (terrainnormal.z < 0)
4814 targetyaw = 180 - targetyaw;
4818 animTarget = flipanim;
4819 crouchtogglekeydown = 1;
4824 animCurrent = tempanim;
4828 for (int i = 0; i < skeleton.num_joints; i++) {
4829 tempanimation.position[i][0] = skeleton.joints[i].position;
4830 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
4835 if (findLength(&average) < 10 && !dead && skeleton.free) {
4836 skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
4837 if (skeleton.longdead > (damage + 500) * 1.5) {
4839 pause_sound(whooshsound);
4845 terrainnormal = jointPos(groin) - jointPos(abdomen);
4846 if (joint(groin).locked && joint(abdomen).locked) {
4847 terrainnormal = jointPos(groin) - jointPos(abdomen);
4848 middle = (jointPos(groin) + jointPos(abdomen)) / 2;
4850 if (joint(abdomen).locked && joint(neck).locked) {
4851 terrainnormal = jointPos(abdomen) - jointPos(neck);
4852 middle = (jointPos(neck) + jointPos(abdomen)) / 2;
4854 if (joint(groin).locked && joint(neck).locked) {
4855 terrainnormal = jointPos(groin) - jointPos(neck);
4856 middle = (jointPos(groin) + jointPos(neck)) / 2;
4858 Normalise(&terrainnormal);
4860 targetyaw = -asin(0 - terrainnormal.x);
4861 targetyaw *= 360 / 6.28;
4862 if (terrainnormal.z < 0)
4863 targetyaw = 180 - targetyaw;
4866 targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1;
4869 if (skeleton.forward.y < 0) {
4870 animTarget = getupfrombackanim;
4874 if (skeleton.forward.y > -.3) {
4875 animTarget = getupfromfrontanim;
4883 if ((Random() % 8 == 0 && id != 0 && creature == rabbittype) || (Random() % 2 == 0 && id != 0 && creature == wolftype) || (id == 0 && crouchkeydown && (forwardkeydown || backkeydown || leftkeydown || rightkeydown))) {
4884 animTarget = rollanim;
4885 targetyaw = lookyaw;
4902 if ( !leftkeydown && !rightkeydown)
4909 if (abs(targettilt2) > 50)
4911 animCurrent = tempanim;
4914 tilt2 = targettilt2;
4916 if (middle.y > 0 && animTarget != rollanim)
4917 targetoffset.y = middle.y + 1;
4919 for (int i = 0; i < skeleton.num_joints; i++) {
4920 tempanimation.position[i][0] = skeleton.joints[i].position;
4921 tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
4928 if (num_weapons > 0)
4929 if (weapons[0].getType() == staff)
4931 if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) {
4932 if (velocity.y > -30) {
4934 tempvelocity = velocity;
4935 Normalise(&tempvelocity);
4936 targetyaw = -asin(0 - tempvelocity.x);
4937 targetyaw *= 360 / 6.28;
4939 targetyaw = 180 - targetyaw;
4943 if (dotproduct(&skeleton.forward, &tempvelocity) < 0) {
4944 animTarget = rollanim;
4947 animTarget = backhandspringanim;
4953 emit_sound_at(movewhooshsound, coords, 128.);
4955 animCurrent = animTarget;
4956 frameCurrent = frameTarget - 1;
4968 if (skeleton.freefall == 0)
4973 if (aitype != passivetype || skeleton.free == 1)
4974 if (findLengthfast(&velocity) > .1)
4975 for (i = 0; i < objects.numobjects; i++) {
4976 if (objects.type[i] == firetype)
4977 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) {
4979 if (!objects.onfire[i]) {
4980 emit_sound_at(firestartsound, objects.position[i]);
4982 objects.onfire[i] = 1;
4985 if (objects.onfire[i]) {
4990 if (objects.type[i] == bushtype)
4991 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) {
4993 if (!objects.onfire[i]) {
4994 emit_sound_at(firestartsound, objects.position[i]);
4996 objects.onfire[i] = 1;
5000 if (objects.onfire[i]) {
5004 if (objects.messedwith[i] <= 0) {
5008 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5011 envsound[numenvsounds] = coords;
5012 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5013 envsoundlife[numenvsounds] = .4;
5018 if (environment == grassyenvironment)
5019 howmany = findLength(&velocity) * 4;
5020 if (environment == snowyenvironment)
5021 howmany = findLength(&velocity) * 2;
5023 if (environment != desertenvironment)
5024 for (j = 0; j < howmany; j++) {
5025 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5026 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5027 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5030 pos.x += float(abs(Random() % 100) - 50) / 200;
5031 pos.y += float(abs(Random() % 100) - 50) / 200;
5032 pos.z += float(abs(Random() % 100) - 50) / 200;
5033 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);
5034 Sprite::setLastSpriteSpecial(1);
5036 howmany = findLength(&velocity) * 4;
5038 if (environment == snowyenvironment)
5039 for (j = 0; j < howmany; j++) {
5040 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5041 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5042 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5045 pos.x += float(abs(Random() % 100) - 50) / 200;
5046 pos.y += float(abs(Random() % 100) - 50) / 200;
5047 pos.z += float(abs(Random() % 100) - 50) / 200;
5048 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5049 Sprite::setLastSpriteSpecial(2);
5052 objects.rotx[i] += velocity.x * multiplier * 6;
5053 objects.roty[i] += velocity.z * multiplier * 6;
5054 objects.messedwith[i] = .5;
5057 if (objects.type[i] == treeleavestype && environment != desertenvironment) {
5058 if (objects.pitch[i] == 0)
5061 tempcoord = coords - objects.position[i];
5062 tempcoord = DoRotation(tempcoord, 0, -objects.yaw[i], 0);
5063 tempcoord = DoRotation(tempcoord, -objects.pitch[i], 0, 0);
5064 tempcoord += objects.position[i];
5066 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]) {
5067 if (objects.messedwith[i] <= 0) {
5071 emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5074 envsound[numenvsounds] = coords;
5075 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5076 envsoundlife[numenvsounds] = .4;
5081 if (environment == grassyenvironment)
5082 howmany = findLength(&velocity) * 4;
5083 if (environment == snowyenvironment)
5084 howmany = findLength(&velocity) * 2;
5086 if (environment != desertenvironment)
5087 for (j = 0; j < howmany; j++) {
5088 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5089 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5090 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5092 pos += velocity * .1;
5094 pos.x += float(abs(Random() % 100) - 50) / 150;
5095 pos.y += float(abs(Random() % 100) - 50) / 150;
5096 pos.z += float(abs(Random() % 100) - 50) / 150;
5097 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);
5098 Sprite::setLastSpriteSpecial(1);
5100 howmany = findLength(&velocity) * 4;
5102 if (environment == snowyenvironment)
5103 for (j = 0; j < howmany; j++) {
5104 tempvel.x = float(abs(Random() % 100) - 50) / 20;
5105 tempvel.y = float(abs(Random() % 100) - 50) / 20;
5106 tempvel.z = float(abs(Random() % 100) - 50) / 20;
5108 pos += velocity * .1;
5110 pos.x += float(abs(Random() % 100) - 50) / 150;
5111 pos.y += float(abs(Random() % 100) - 50) / 150;
5112 pos.z += float(abs(Random() % 100) - 50) / 150;
5113 Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5114 Sprite::setLastSpriteSpecial(2);
5117 objects.messedwith[i] = .5;
5122 if (!skeleton.free) {
5125 if ((stunned > 0 || surprised > 0) && Person::players.size() > 2 && aitype != passivetype)
5128 if (aitype != passivetype && victim->skeleton.free && !victim->dead)
5130 if (tutoriallevel == 1 && id != 0)
5132 if (play && aitype != playercontrolled) {
5133 int whichsound = -1;
5134 i = abs(Random() % 4);
5135 if (speechdelay <= 0) {
5136 if (creature == rabbittype) {
5138 whichsound = rabbitchitter;
5140 whichsound = rabbitchitter2;
5142 if (creature == wolftype) {
5144 whichsound = growlsound;
5146 whichsound = growl2sound;
5151 if (whichsound != -1) {
5152 emit_sound_at(whichsound, coords);
5156 if (animTarget == staggerbackhighanim)
5158 if (animTarget == staggerbackhardanim)
5160 staggerdelay -= multiplier;
5161 if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
5163 if (velocity.y < -30 && animTarget == jumpdownanim)
5165 if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) {
5166 animTarget = getIdle();
5170 weaponmissdelay -= multiplier;
5171 highreversaldelay -= multiplier;
5172 lowreversaldelay -= multiplier;
5173 lastcollide -= multiplier;
5174 skiddelay -= multiplier;
5175 if (!isnormal(velocity.x) && velocity.x) {
5178 if (!isnormal(targettilt) && targettilt) {
5181 if (!isnormal(targettilt2) && targettilt2) {
5184 if (!isnormal(targetyaw) && targetyaw) {
5188 if (animTarget == bounceidleanim || animTarget == wolfidle || animTarget == walkanim || animTarget == drawrightanim || animTarget == crouchdrawrightanim || animTarget == drawleftanim || animTarget == fightidleanim || animTarget == fightsidestep || animTarget == hanganim || isCrouch() || animTarget == backhandspringanim) {
5189 //open hands and close mouth
5190 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5191 righthandmorphness = 0;
5192 righthandmorphend = 0;
5193 targetrighthandmorphness = 1;
5196 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5197 lefthandmorphness = 0;
5198 lefthandmorphend = 0;
5199 targetlefthandmorphness = 1;
5202 if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5 && headmorphend != 0 && headmorphness == targetheadmorphness) {
5205 targetheadmorphness = 1;
5209 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) {
5210 //open hands and mouth
5211 if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5212 righthandmorphness = 0;
5213 righthandmorphend = 0;
5214 targetrighthandmorphness = 1;
5217 if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5218 lefthandmorphness = 0;
5219 lefthandmorphend = 0;
5220 targetlefthandmorphness = 1;
5223 if (headmorphend != 1 && headmorphness == targetheadmorphness) {
5226 targetheadmorphness = 1;
5230 if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim) {
5231 //close hands and mouth
5232 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5233 righthandmorphness = 0;
5234 righthandmorphend = 1;
5235 targetrighthandmorphness = 1;
5238 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5239 lefthandmorphness = 0;
5240 lefthandmorphend = 1;
5241 targetlefthandmorphness = 1;
5244 if (headmorphend != 0 && headmorphness == targetheadmorphness) {
5247 targetheadmorphness = 1;
5251 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) {
5252 //close hands and yell
5253 if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5254 righthandmorphness = 0;
5255 righthandmorphend = 1;
5256 targetrighthandmorphness = 1;
5259 if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5260 lefthandmorphness = 0;
5261 lefthandmorphend = 1;
5262 targetlefthandmorphness = 1;
5265 if (headmorphend != 2 && headmorphness == targetheadmorphness) {
5268 targetheadmorphness = 1;
5275 if ((victim != this->shared_from_this()) && !victim->dead && (victim->aitype != passivetype) &&
5276 (victim->aitype != searchtype) && (aitype != passivetype) &&
5277 (aitype != searchtype) && (victim->id < Person::players.size())) {
5278 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
5282 if (!dead && animTarget != hurtidleanim)
5283 if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) {
5284 if (headmorphend != 4 || headmorphness == targetheadmorphness) {
5287 targetheadmorphness = 1;
5291 if (weaponactive != -1) {
5292 if (weapons[weaponids[weaponactive]].getType() != staff) {
5293 righthandmorphstart = 1;
5294 righthandmorphend = 1;
5296 if (weapons[weaponids[weaponactive]].getType() == staff) {
5297 righthandmorphstart = 2;
5298 righthandmorphend = 2;
5300 targetrighthandmorphness = 1;
5303 terrainnormal = terrain.getNormal(coords.x, coords.z);
5305 if (animation[animTarget].attack != reversal) {
5306 if (!isnormal(coords.x))
5314 flatfacing = DoRotation(flatfacing, 0, yaw, 0);
5315 facing = flatfacing;
5316 ReflectVector(&facing, terrainnormal);
5319 if (isRun() || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) {
5321 targettilt2 = -facing.y * 20;
5326 if (!isRun() && !animation[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim)
5328 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5329 flatvelocity = velocity;
5331 flatvelspeed = findLength(&flatvelocity);
5332 targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity);
5333 targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity);
5338 if (targettilt > 25)
5340 if (targettilt < -25)
5344 if (targettilt2 > 45)
5346 if (targettilt2 < -45)
5348 if (abs(tilt2 - targettilt2) < multiplier * 400)
5349 tilt2 = targettilt2;
5350 else if (tilt2 > targettilt2) {
5351 tilt2 -= multiplier * 400;
5352 } else if (tilt2 < targettilt2) {
5353 tilt2 += multiplier * 400;
5355 if (!animation[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) {
5362 if (!isnormal(targettilt) && targettilt) {
5365 if (!isnormal(targettilt2) && targettilt2) {
5370 if (animTarget == rabbittackleanim) {
5371 velocity += facing * multiplier * speed * 700 * scale;
5372 velspeed = findLength(&velocity);
5373 if (velspeed > speed * 65 * scale) {
5374 velocity /= velspeed;
5375 velspeed = speed * 65 * scale;
5376 velocity *= velspeed;
5378 velocity.y += gravity * multiplier * 20;
5379 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5380 velspeed = findLength(&velocity);
5381 velocity = flatfacing * velspeed;
5383 if (animTarget != rabbitrunninganim && animTarget != wolfrunninganim) {
5384 if (isRun() || animTarget == rabbitkickanim) {
5385 velocity += facing * multiplier * speed * 700 * scale;
5386 velspeed = findLength(&velocity);
5387 if (velspeed > speed * 45 * scale) {
5388 velocity /= velspeed;
5389 velspeed = speed * 45 * scale;
5390 velocity *= velspeed;
5392 velocity.y += gravity * multiplier * 20;
5393 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5394 velspeed = findLength(&velocity);
5395 if (velspeed < speed * 30 * scale)
5396 velspeed = speed * 30 * scale;
5397 velocity = flatfacing * velspeed;
5399 } else if (isRun()) {
5400 velocity += facing * multiplier * speed * 700 * scale;
5401 velspeed = findLength(&velocity);
5402 if (creature == rabbittype) {
5403 if (velspeed > speed * 55 * scale) {
5404 velocity /= velspeed;
5405 velspeed = speed * 55 * scale;
5406 velocity *= velspeed;
5409 if (creature == wolftype) {
5410 if (velspeed > speed * 75 * scale) {
5411 velocity /= velspeed;
5412 velspeed = speed * 75 * scale;
5413 velocity *= velspeed;
5416 velocity.y += gravity * multiplier * 20;
5417 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5418 velspeed = findLength(&velocity);
5419 velocity = flatfacing * velspeed;
5422 if (animTarget == rollanim && animation[animTarget].label[frameTarget] != 6) {
5423 velocity += facing * multiplier * speed * 700 * scale;
5424 velspeed = findLength(&velocity);
5425 if (velspeed > speed * 45 * scale) {
5426 velocity /= velspeed;
5427 velspeed = speed * 45 * scale;
5428 velocity *= velspeed;
5430 velocity.y += gravity * multiplier * 20;
5431 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5432 velspeed = findLength(&velocity);
5433 velocity = flatfacing * velspeed;
5436 if (animTarget == sneakanim || animTarget == walkanim) {
5437 velocity += facing * multiplier * speed * 700 * scale;
5438 velspeed = findLength(&velocity);
5439 if (velspeed > speed * 12 * scale) {
5440 velocity /= velspeed;
5441 velspeed = speed * 12 * scale;
5442 velocity *= velspeed;
5444 velocity.y += gravity * multiplier * 20;
5445 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5446 velspeed = findLength(&velocity);
5447 velocity = flatfacing * velspeed;
5450 if ((animTarget == fightidleanim || animTarget == knifefightidleanim) && (animCurrent == bounceidleanim || animCurrent == hurtidleanim)) {
5451 velocity += facing * multiplier * speed * 700 * scale;
5452 velspeed = findLength(&velocity);
5453 if (velspeed > speed * 2 * scale) {
5454 velocity /= velspeed;
5455 velspeed = speed * 2 * scale;
5456 velocity *= velspeed;
5458 velocity.y += gravity * multiplier * 20;
5459 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5460 velspeed = findLength(&velocity);
5461 velocity = flatfacing * velspeed;
5465 if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) {
5466 velocity -= facing * multiplier * speed * 700 * scale;
5467 velspeed = findLength(&velocity);
5468 if (velspeed > speed * 2 * scale) {
5469 velocity /= velspeed;
5470 velspeed = speed * 2 * scale;
5471 velocity *= velspeed;
5473 velocity.y += gravity * multiplier * 20;
5474 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5475 velspeed = findLength(&velocity);
5476 velocity = flatfacing * velspeed * -1;
5479 if (animTarget == fightsidestep) {
5480 velocity += DoRotation(facing * multiplier * speed * 700 * scale, 0, -90, 0);
5481 velspeed = findLength(&velocity);
5482 if (velspeed > speed * 12 * scale) {
5483 velocity /= velspeed;
5484 velspeed = speed * 12 * scale;
5485 velocity *= velspeed;
5487 velocity.y += gravity * multiplier * 20;
5488 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5489 velspeed = findLength(&velocity);
5490 velocity = DoRotation(flatfacing * velspeed, 0, -90, 0);
5493 if (animTarget == staggerbackhighanim) {
5494 coords -= facing * multiplier * speed * 16 * scale;
5497 if (animTarget == staggerbackhardanim && animation[staggerbackhardanim].label[frameTarget] != 6) {
5498 coords -= facing * multiplier * speed * 20 * scale;
5502 if (animTarget == backhandspringanim) {
5503 //coords-=facing*multiplier*50*scale;
5504 velocity += facing * multiplier * speed * 700 * scale * -1;
5505 velspeed = findLength(&velocity);
5506 if (velspeed > speed * 50 * scale) {
5507 velocity /= velspeed;
5508 velspeed = speed * 50 * scale;
5509 velocity *= velspeed;
5511 velocity.y += gravity * multiplier * 20;
5512 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5513 velspeed = findLength(&velocity);
5514 velocity = flatfacing * velspeed * -1;
5516 if (animTarget == dodgebackanim) {
5517 //coords-=facing*multiplier*50*scale;
5518 velocity += facing * multiplier * speed * 700 * scale * -1;
5519 velspeed = findLength(&velocity);
5520 if (velspeed > speed * 60 * scale) {
5521 velocity /= velspeed;
5522 velspeed = speed * 60 * scale;
5523 velocity *= velspeed;
5525 velocity.y += gravity * multiplier * 20;
5526 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5527 velspeed = findLength(&velocity);
5528 velocity = flatfacing * velspeed * -1;
5531 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5532 velspeed = findLength(&velocity);
5536 if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5537 velocity.y += gravity * multiplier;
5540 if (animTarget != climbanim && animTarget != hanganim && !isWallJump())
5541 coords += velocity * multiplier;
5543 if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
5544 if (isFlip() && animation[animTarget].label[frameTarget] == 7)
5547 if (animTarget == jumpupanim) {
5549 animTarget = getIdle();
5556 pause_sound(whooshsound);
5557 OPENAL_SetVolume(channels[whooshsound], 0);
5560 if (animTarget == jumpdownanim || isFlip()) {
5561 if (isFlip())jumppower = -4;
5562 animTarget = getLanding();
5563 emit_sound_at(landsound, coords, 128.);
5566 envsound[numenvsounds] = coords;
5567 envsoundvol[numenvsounds] = 16;
5568 envsoundlife[numenvsounds] = .4;
5574 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump())
5575 coords.y += gravity * multiplier * 2;
5576 if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) {
5577 coords.y = terrain.getHeight(coords.x, coords.z);
5582 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)) {
5583 velspeed = findLength(&velocity);
5585 if (velspeed < multiplier * 300 * scale) {
5588 velocity -= velocity / velspeed * multiplier * 300 * scale;
5589 if (velspeed > 5 && (isLanding() || isLandhard())) {
5590 skiddingdelay += multiplier;
5591 if (skiddelay <= 0) {
5601 velspeed = findLength(&velocity);
5603 if (velspeed < multiplier * 600 * scale) {
5606 velocity -= velocity / velspeed * multiplier * 600 * scale;
5608 if (velspeed > 5 && (isLanding() || isLandhard())) {
5609 skiddingdelay += multiplier;
5610 if (skiddelay <= 0) {
5619 if (skiddingdelay < 0)
5620 skiddingdelay += multiplier;
5621 if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) {
5623 if (!onterrain || environment == grassyenvironment) {
5624 emit_sound_at(skidsound, coords, 128 * velspeed / 10);
5626 emit_sound_at(snowskidsound, coords, 128 * velspeed / 10);
5630 if (animation[animTarget].attack == normalattack && animTarget != rabbitkickanim && !victim->skeleton.free) {
5631 terrainnormal = victim->coords - coords;
5632 Normalise(&terrainnormal);
5633 targetyaw = -asin(0 - terrainnormal.x);
5634 targetyaw *= 360 / 6.28;
5635 if (terrainnormal.z < 0)
5636 targetyaw = 180 - targetyaw;
5637 targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70;
5640 if (animation[animTarget].attack == reversal && animTarget != rabbittacklinganim) {
5641 targetyaw = victim->targetyaw;
5643 if (animTarget == rabbittacklinganim) {
5644 coords = victim->coords;
5647 skeleton.oldfree = skeleton.free;
5651 midterrain.x = terrain.size * terrain.scale / 2;
5652 midterrain.z = terrain.size * terrain.scale / 2;
5653 if (distsqflat(&coords, &midterrain) > (terrain.size * terrain.scale / 2 - viewdistance) * (terrain.size * terrain.scale / 2 - viewdistance)) {
5655 tempposit = coords - midterrain;
5657 Normalise(&tempposit);
5658 tempposit *= (terrain.size * terrain.scale / 2 - viewdistance);
5659 coords.x = tempposit.x + midterrain.x;
5660 coords.z = tempposit.z + midterrain.z;
5666 * inverse kinematics helper function
5668 void IKHelper(Person *p, float interp)
5670 XYZ point, change, change2;
5671 float heightleft, heightright;
5673 // TODO: implement localToWorld and worldToLocal
5674 // but keep in mind it won't be the same math if player is ragdolled or something
5675 // - localToWorldStanding / worldToLocalStanding (or crouching or...?)
5676 // then comb through code for places where to use it
5678 // point = localToWorld(jointPos(leftfoot))
5679 point = DoRotation(p->jointPos(leftfoot), 0, p->yaw, 0) * p->scale + p->coords;
5680 // adjust height of foot
5681 heightleft = terrain.getHeight(point.x, point.z) + .04;
5682 point.y = heightleft;
5683 change = p->jointPos(leftankle) - p->jointPos(leftfoot);
5684 change2 = p->jointPos(leftknee) - p->jointPos(leftfoot);
5685 // jointPos(leftfoot) = interpolate(worldToLocal(point), jointPos(leftfoot), interp)
5686 p->jointPos(leftfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(leftfoot) * (1 - interp);
5687 // move ankle along with foot
5688 p->jointPos(leftankle) = p->jointPos(leftfoot) + change;
5689 // average knee pos between old and new pos
5690 p->jointPos(leftknee) = (p->jointPos(leftfoot) + change2) / 2 + (p->jointPos(leftknee)) / 2;
5692 // do same as above for right leg
5693 point = DoRotation(p->jointPos(rightfoot), 0, p->yaw, 0) * p->scale + p->coords;
5694 heightright = terrain.getHeight(point.x, point.z) + .04;
5695 point.y = heightright;
5696 change = p->jointPos(rightankle) - p->jointPos(rightfoot);
5697 change2 = p->jointPos(rightknee) - p->jointPos(rightfoot);
5698 p->jointPos(rightfoot) = DoRotation((point - p->coords) / p->scale, 0, -p->yaw, 0) * interp + p->jointPos(rightfoot) * (1 - interp);
5699 p->jointPos(rightankle) = p->jointPos(rightfoot) + change;
5700 p->jointPos(rightknee) = (p->jointPos(rightfoot) + change2) / 2 + (p->jointPos(rightknee)) / 2;
5702 // fix up skeleton now that we've moved body parts?
5703 p->skeleton.DoConstraints(&p->coords, &p->scale);
5710 int Person::DrawSkeleton()
5712 int oldplayerdetail;
5713 if ((frustum.SphereInFrustum(coords.x, coords.y + scale * 3, coords.z, scale * 8) && distsq(&viewer, &coords) < viewdistance * viewdistance) || skeleton.free == 3) {
5714 if (onterrain && (isIdle() || isCrouch() || wasIdle() || wasCrouch()) && !skeleton.free) {
5724 glAlphaFunc(GL_GREATER, 0.0001);
5726 float terrainheight;
5730 if (!isnormal(tilt))
5732 if (!isnormal(tilt2))
5734 oldplayerdetail = playerdetail;
5736 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) {
5739 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 128 && detail == 1) {
5742 if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) {
5747 if (playerdetail != oldplayerdetail) {
5749 normalsupdatedelay = 0;
5751 static float updatedelaychange;
5752 static float morphness;
5753 static float framemult;
5755 skeleton.FindForwards();
5756 if (howactive == typesittingwall) {
5757 skeleton.specialforward[1] = 0;
5758 skeleton.specialforward[1].z = 1;
5764 static int weaponattachmuscle;
5765 static int weaponrotatemuscle;
5766 static XYZ weaponpoint;
5767 static int start, endthing;
5768 if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
5769 if (!isSleeping() && !isSitting()) {
5770 // TODO: give these meaningful names
5771 const bool cond1 = (isIdle() || isCrouch() || isLanding() || isLandhard()
5772 || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim);
5773 const bool cond2 = (wasIdle() || wasCrouch() || wasLanding() || wasLandhard()
5774 || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim);
5776 if (onterrain && (cond1 && cond2) && !skeleton.free) {
5778 if (creature == wolftype)
5782 if (onterrain && (cond1 && !cond2) && !skeleton.free) {
5783 IKHelper(this, target);
5784 if (creature == wolftype)
5785 IKHelper(this, target);
5788 if (onterrain && (!cond1 && cond2) && !skeleton.free) {
5789 IKHelper(this, 1 - target);
5790 if (creature == wolftype)
5791 IKHelper(this, 1 - target);
5795 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()))
5798 targetheadyaw = -targetyaw;
5799 targetheadpitch = 0;
5800 if (animation[animTarget].attack == 3)
5801 targetheadyaw += 180;
5803 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
5804 skeleton.drawmodel.vertex[i] = 0;
5805 skeleton.drawmodel.vertex[i].y = 999;
5807 for (i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
5808 skeleton.drawmodellow.vertex[i] = 0;
5809 skeleton.drawmodellow.vertex[i].y = 999;
5811 for (i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
5812 skeleton.drawmodelclothes.vertex[i] = 0;
5813 skeleton.drawmodelclothes.vertex[i].y = 999;
5815 for (int i = 0; i < skeleton.num_muscles; i++) {
5816 // convenience renames
5817 const int p1 = skeleton.muscles[i].parent1->label;
5818 const int p2 = skeleton.muscles[i].parent2->label;
5820 if ((skeleton.muscles[i].numvertices > 0 && playerdetail) || (skeleton.muscles[i].numverticeslow > 0 && !playerdetail)) {
5825 if (p1 == righthand || p2 == righthand) {
5826 morphness = righthandmorphness;
5827 start = righthandmorphstart;
5828 endthing = righthandmorphend;
5830 if (p1 == lefthand || p2 == lefthand) {
5831 morphness = lefthandmorphness;
5832 start = lefthandmorphstart;
5833 endthing = lefthandmorphend;
5835 if (p1 == head || p2 == head) {
5836 morphness = headmorphness;
5837 start = headmorphstart;
5838 endthing = headmorphend;
5840 if ((p1 == neck && p2 == abdomen) || (p2 == neck && p1 == abdomen)) {
5841 morphness = chestmorphness;
5842 start = chestmorphstart;
5843 endthing = chestmorphend;
5845 if ((p1 == groin && p2 == abdomen) || (p2 == groin && p1 == abdomen)) {
5846 morphness = tailmorphness;
5847 start = tailmorphstart;
5848 endthing = tailmorphend;
5851 skeleton.FindRotationMuscle(i, animTarget);
5852 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
5853 glMatrixMode(GL_MODELVIEW);
5857 glRotatef(tilt2, 1, 0, 0);
5859 glRotatef(tilt, 0, 0, 1);
5862 glTranslatef(mid.x, mid.y, mid.z);
5864 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
5865 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
5867 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
5868 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
5870 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
5871 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
5873 if (playerdetail || skeleton.free == 3) {
5874 for (j = 0; j < skeleton.muscles[i].numvertices; j++) {
5875 XYZ &v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
5876 XYZ &v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
5877 glMatrixMode(GL_MODELVIEW);
5879 if (p1 == abdomen || p2 == abdomen)
5880 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionbody.x,
5881 (v0.y * (1 - morphness) + v1.y * morphness) * proportionbody.y,
5882 (v0.z * (1 - morphness) + v1.z * morphness) * proportionbody.z);
5883 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
5884 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionarms.x,
5885 (v0.y * (1 - morphness) + v1.y * morphness) * proportionarms.y,
5886 (v0.z * (1 - morphness) + v1.z * morphness) * proportionarms.z);
5887 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
5888 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionlegs.x,
5889 (v0.y * (1 - morphness) + v1.y * morphness) * proportionlegs.y,
5890 (v0.z * (1 - morphness) + v1.z * morphness) * proportionlegs.z);
5891 if (p1 == head || p2 == head)
5892 glTranslatef((v0.x * (1 - morphness) + v1.x * morphness) * proportionhead.x,
5893 (v0.y * (1 - morphness) + v1.y * morphness) * proportionhead.y,
5894 (v0.z * (1 - morphness) + v1.z * morphness) * proportionhead.z);
5895 glGetFloatv(GL_MODELVIEW_MATRIX, M);
5896 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale;
5897 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale;
5898 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z = M[14] * scale;
5902 if (!playerdetail || skeleton.free == 3) {
5903 for (j = 0; j < skeleton.muscles[i].numverticeslow; j++) {
5904 XYZ &v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
5905 glMatrixMode(GL_MODELVIEW);
5907 if (p1 == abdomen || p2 == abdomen)
5908 glTranslatef(v0.x * proportionbody.x,
5909 v0.y * proportionbody.y,
5910 v0.z * proportionbody.z);
5911 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
5912 glTranslatef(v0.x * proportionarms.x,
5913 v0.y * proportionarms.y,
5914 v0.z * proportionarms.z);
5915 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
5916 glTranslatef(v0.x * proportionlegs.x,
5917 v0.y * proportionlegs.y,
5918 v0.z * proportionlegs.z);
5919 if (p1 == head || p2 == head)
5920 glTranslatef(v0.x * proportionhead.x,
5921 v0.y * proportionhead.y,
5922 v0.z * proportionhead.z);
5924 glGetFloatv(GL_MODELVIEW_MATRIX, M);
5925 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
5926 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y = M[13] * scale;
5927 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z = M[14] * scale;
5933 if (skeleton.clothes && skeleton.muscles[i].numverticesclothes > 0) {
5934 mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
5936 glMatrixMode(GL_MODELVIEW);
5940 glRotatef(tilt2, 1, 0, 0);
5942 glRotatef(tilt, 0, 0, 1);
5943 glTranslatef(mid.x, mid.y, mid.z);
5944 skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
5945 glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
5947 skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
5948 glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
5950 skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
5951 glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
5953 for (j = 0; j < skeleton.muscles[i].numverticesclothes; j++) {
5954 XYZ &v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
5955 glMatrixMode(GL_MODELVIEW);
5957 if (p1 == abdomen || p2 == abdomen)
5958 glTranslatef(v0.x * proportionbody.x,
5959 v0.y * proportionbody.y,
5960 v0.z * proportionbody.z);
5961 if (p1 == lefthand || p1 == righthand || p1 == leftwrist || p1 == rightwrist || p1 == leftelbow || p1 == rightelbow || p2 == leftelbow || p2 == rightelbow)
5962 glTranslatef(v0.x * proportionarms.x,
5963 v0.y * proportionarms.y,
5964 v0.z * proportionarms.z);
5965 if (p1 == leftfoot || p1 == rightfoot || p1 == leftankle || p1 == rightankle || p1 == leftknee || p1 == rightknee || p2 == leftknee || p2 == rightknee)
5966 glTranslatef(v0.x * proportionlegs.x,
5967 v0.y * proportionlegs.y,
5968 v0.z * proportionlegs.z);
5969 if (p1 == head || p2 == head)
5970 glTranslatef(v0.x * proportionhead.x,
5971 v0.y * proportionhead.y,
5972 v0.z * proportionhead.z);
5973 glGetFloatv(GL_MODELVIEW_MATRIX, M);
5974 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
5975 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
5976 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z = M[14] * scale;
5981 updatedelay = 1 + (float)(Random() % 100) / 1000;
5983 if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) {
5984 normalsupdatedelay = 1;
5985 if (playerdetail || skeleton.free == 3)
5986 skeleton.drawmodel.CalculateNormals(0);
5987 if (!playerdetail || skeleton.free == 3)
5988 skeleton.drawmodellow.CalculateNormals(0);
5989 if (skeleton.clothes)
5990 skeleton.drawmodelclothes.CalculateNormals(0);
5992 if (playerdetail || skeleton.free == 3)
5993 skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
5994 if (!playerdetail || skeleton.free == 3)
5995 skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
5996 if (skeleton.clothes) {
5997 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6002 updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1);
6003 if (updatedelaychange > -realmultiplier * 30)
6004 updatedelaychange = -realmultiplier * 30;
6005 if (updatedelaychange > -framemult * 4)
6006 updatedelaychange = -framemult * 4;
6007 if (skeleton.free == 1)
6008 updatedelaychange *= 6;
6010 updatedelaychange *= 8;
6011 updatedelay += updatedelaychange;
6013 glMatrixMode(GL_MODELVIEW);
6015 glTranslatef(coords.x, coords.y - .02, coords.z);
6016 if (!skeleton.free) {
6017 glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
6018 glRotatef(yaw, 0, 1, 0);
6022 glColor4f(.4, 1, .4, 1);
6023 glDisable(GL_LIGHTING);
6024 glDisable(GL_TEXTURE_2D);
6027 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6028 XYZ &v0 = skeleton.drawmodel.vertex[i];
6029 glVertex3f(v0.x, v0.y, v0.z);
6035 for (i = 0; i < skeleton.drawmodel.TriangleNum; i++) {
6036 XYZ &v0 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]];
6037 XYZ &v1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]];
6038 XYZ &v2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]];
6039 glVertex3f(v0.x, v0.y, v0.z);
6040 glVertex3f(v1.x, v1.y, v1.z);
6041 glVertex3f(v1.x, v1.y, v1.z);
6042 glVertex3f(v2.x, v2.y, v2.z);
6043 glVertex3f(v2.x, v2.y, v2.z);
6044 glVertex3f(v0.x, v0.y, v0.z);
6050 terrainlight = terrain.getLighting(coords.x, coords.z);
6051 distance = distsq(&viewer, &coords);
6052 distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
6056 terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1;
6057 if (terrainheight < 1)
6059 if (terrainheight > 1.7)
6060 terrainheight = 1.7;
6063 glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance);
6064 glDisable(GL_BLEND);
6065 glAlphaFunc(GL_GREATER, 0.0001);
6066 glEnable(GL_TEXTURE_2D);
6068 glDisable(GL_TEXTURE_2D);
6069 glColor4f(.7, .35, 0, .5);
6071 glEnable(GL_LIGHTING);
6074 if (tutoriallevel && id != 0) {
6075 glColor4f(.7, .7, .7, 0.6);
6077 glEnable(GL_LIGHTING);
6079 if (canattack && cananger)
6080 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6081 glDisable(GL_TEXTURE_2D);
6082 glColor4f(1, 0, 0, 0.8);
6084 glMatrixMode(GL_TEXTURE);
6086 glTranslatef(0, -smoketex, 0);
6087 glTranslatef(-smoketex, 0, 0);
6091 if ((tutoriallevel && id != 0))
6092 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6094 skeleton.drawmodel.draw();
6097 if (!playerdetail) {
6098 if ((tutoriallevel && id != 0))
6099 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6101 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6104 if (!(animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed))
6105 if (tutoriallevel && id != 0) {
6107 glMatrixMode(GL_MODELVIEW);
6108 glEnable(GL_TEXTURE_2D);
6109 glColor4f(.7, .7, .7, 0.6);
6111 glEnable(GL_LIGHTING);
6113 if (canattack && cananger)
6114 if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6115 glDisable(GL_TEXTURE_2D);
6116 glColor4f(1, 0, 0, 0.8);
6118 glMatrixMode(GL_TEXTURE);
6120 glTranslatef(0, -smoketex * .6, 0);
6121 glTranslatef(smoketex * .6, 0, 0);
6124 if ((tutoriallevel && id != 0))
6125 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6127 skeleton.drawmodel.draw();
6130 if (!playerdetail) {
6131 if ((tutoriallevel && id != 0))
6132 skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6134 skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6139 if (tutoriallevel && id != 0) {
6141 glMatrixMode(GL_MODELVIEW);
6142 glEnable(GL_TEXTURE_2D);
6144 if (skeleton.clothes) {
6148 skeleton.drawmodelclothes.draw();
6150 skeleton.drawmodelclothes.drawimmediate();
6156 if (num_weapons > 0) {
6157 for (k = 0; k < num_weapons; k++) {
6159 if (weaponactive == k) {
6160 if (weapons[i].getType() != staff) {
6161 for (j = 0; j < skeleton.num_muscles; j++) {
6162 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6163 weaponattachmuscle = j;
6166 for (j = 0; j < skeleton.num_muscles; j++) {
6167 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) {
6168 weaponrotatemuscle = j;
6171 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6172 if (creature == wolftype)
6173 weaponpoint = (jointPos(rightwrist) * .7 + jointPos(righthand) * .3);
6175 if (weapons[i].getType() == staff) {
6176 for (j = 0; j < skeleton.num_muscles; j++) {
6177 if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6178 weaponattachmuscle = j;
6181 for (j = 0; j < skeleton.num_muscles; j++) {
6182 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) {
6183 weaponrotatemuscle = j;
6186 //weaponpoint=jointPos(rightwrist);
6187 weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6188 //weaponpoint+=skeleton.specialforward[1]*.1+(jointPos(rightwrist)-jointPos(rightelbow));
6189 XYZ tempnormthing, vec1, vec2;
6190 vec1 = (jointPos(rightwrist) - jointPos(rightelbow));
6191 vec2 = (jointPos(rightwrist) - jointPos(rightshoulder));
6192 CrossProduct(&vec1, &vec2, &tempnormthing);
6193 Normalise(&tempnormthing);
6194 if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim)
6195 weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (jointPos(rightwrist) - jointPos(rightelbow));
6198 if (weaponactive != k && weaponstuck != k) {
6199 if (weapons[i].getType() == knife)
6200 weaponpoint = jointPos(abdomen) + (jointPos(righthip) - jointPos(lefthip)) * .1 + (jointPos(rightshoulder) - jointPos(leftshoulder)) * .35;
6201 if (weapons[i].getType() == sword)
6202 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6203 if (weapons[i].getType() == staff)
6204 weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
6205 for (j = 0; j < skeleton.num_muscles; j++) {
6206 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) {
6207 weaponrotatemuscle = j;
6211 if (weaponstuck == k) {
6212 if (weaponstuckwhere == 0)
6213 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 - skeleton.forward * .8;
6215 weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
6216 for (j = 0; j < skeleton.num_muscles; j++) {
6217 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) {
6218 weaponrotatemuscle = j;
6222 if (skeleton.free) {
6223 weapons[i].position = weaponpoint * scale + coords;
6224 weapons[i].bigrotation = 0;
6225 weapons[i].bigtilt = 0;
6226 weapons[i].bigtilt2 = 0;
6228 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;
6229 weapons[i].bigrotation = yaw;
6230 weapons[i].bigtilt = tilt;
6231 weapons[i].bigtilt2 = tilt2;
6233 weapons[i].rotation1 = skeleton.muscles[weaponrotatemuscle].lastrotate1;
6234 weapons[i].rotation2 = skeleton.muscles[weaponrotatemuscle].lastrotate2;
6235 weapons[i].rotation3 = skeleton.muscles[weaponrotatemuscle].lastrotate3;
6236 if (weaponactive == k) {
6237 if (weapons[i].getType() == knife) {
6238 weapons[i].smallrotation = 180;
6239 weapons[i].smallrotation2 = 0;
6240 if (isCrouch() || wasCrouch()) {
6241 weapons[i].smallrotation2 = 20;
6243 if (animTarget == hurtidleanim) {
6244 weapons[i].smallrotation2 = 50;
6246 if ((animCurrent == crouchstabanim && animTarget == crouchstabanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
6247 XYZ temppoint1, temppoint2;
6250 temppoint1 = jointPos(righthand);
6251 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6252 distance = findDistance(&temppoint1, &temppoint2);
6253 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6254 weapons[i].rotation2 *= 360 / 6.28;
6257 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6258 weapons[i].rotation1 *= 360 / 6.28;
6259 weapons[i].rotation3 = 0;
6260 weapons[i].smallrotation = -90;
6261 weapons[i].smallrotation2 = 0;
6262 if (temppoint1.x > temppoint2.x)
6263 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6265 if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) {
6266 XYZ temppoint1, temppoint2;
6269 temppoint1 = jointPos(righthand);
6270 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6271 distance = findDistance(&temppoint1, &temppoint2);
6272 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6273 weapons[i].rotation2 *= 360 / 6.28;
6276 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6277 weapons[i].rotation1 *= 360 / 6.28;
6278 weapons[i].rotation3 = 0;
6279 weapons[i].smallrotation = 90;
6280 weapons[i].smallrotation2 = 0;
6281 if (temppoint1.x > temppoint2.x)
6282 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6284 if (animTarget == knifethrowanim) {
6285 weapons[i].smallrotation = 90;
6286 //weapons[i].smallrotation2=-90;
6287 weapons[i].smallrotation2 = 0;
6288 weapons[i].rotation1 = 0;
6289 weapons[i].rotation2 = 0;
6290 weapons[i].rotation3 = 0;
6292 if (animTarget == knifesneakattackanim && frameTarget < 5) {
6293 weapons[i].smallrotation = -90;
6294 weapons[i].rotation1 = 0;
6295 weapons[i].rotation2 = 0;
6296 weapons[i].rotation3 = 0;
6299 if (weapons[i].getType() == sword) {
6300 weapons[i].smallrotation = 0;
6301 weapons[i].smallrotation2 = 0;
6302 if (animTarget == knifethrowanim) {
6303 weapons[i].smallrotation = -90;
6304 weapons[i].smallrotation2 = 0;
6305 weapons[i].rotation1 = 0;
6306 weapons[i].rotation2 = 0;
6307 weapons[i].rotation3 = 0;
6309 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)) {
6310 XYZ temppoint1, temppoint2;
6313 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6314 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6315 distance = findDistance(&temppoint1, &temppoint2);
6316 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6317 weapons[i].rotation2 *= 360 / 6.28;
6320 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6321 weapons[i].rotation1 *= 360 / 6.28;
6322 weapons[i].rotation3 = 0;
6323 weapons[i].smallrotation = 90;
6324 weapons[i].smallrotation2 = 0;
6325 if (temppoint1.x > temppoint2.x)
6326 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6329 if (weapons[i].getType() == staff) {
6330 weapons[i].smallrotation = 100;
6331 weapons[i].smallrotation2 = 0;
6332 if ((animTarget == staffhitanim && animCurrent == staffhitanim) || (animTarget == staffhitreversedanim && animCurrent == staffhitreversedanim) || (animTarget == staffspinhitreversedanim && animCurrent == staffspinhitreversedanim) || (animTarget == staffgroundsmashanim && animCurrent == staffgroundsmashanim) || (animTarget == staffspinhitanim && animCurrent == staffspinhitanim)) {
6333 XYZ temppoint1, temppoint2;
6336 temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //jointPos(righthand);
6337 temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6338 distance = findDistance(&temppoint1, &temppoint2);
6339 weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6340 weapons[i].rotation2 *= 360 / 6.28;
6343 weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6344 weapons[i].rotation1 *= 360 / 6.28;
6345 weapons[i].rotation3 = 0;
6346 weapons[i].smallrotation = 90;
6347 weapons[i].smallrotation2 = 0;
6348 if (temppoint1.x > temppoint2.x)
6349 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6353 if (weaponactive != k && weaponstuck != k) {
6354 if (weapons[i].getType() == knife) {
6355 weapons[i].smallrotation = -70;
6356 weapons[i].smallrotation2 = 10;
6358 if (weapons[i].getType() == sword) {
6359 weapons[i].smallrotation = -100;
6360 weapons[i].smallrotation2 = -8;
6362 if (weapons[i].getType() == staff) {
6363 weapons[i].smallrotation = -100;
6364 weapons[i].smallrotation2 = -8;
6367 if (weaponstuck == k) {
6368 if (weaponstuckwhere == 0)
6369 weapons[i].smallrotation = 180;
6371 weapons[i].smallrotation = 0;
6372 weapons[i].smallrotation2 = 10;
6381 if (animation[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isWallJump())
6383 if (animCurrent != animTarget)
6385 if (skeleton.free == 2)
6394 int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6397 static float distance;
6398 static float olddistance;
6399 static int intersecting;
6400 static int firstintersecting;
6403 static XYZ start, end;
6404 static float slopethreshold = -.4;
6406 firstintersecting = -1;
6410 if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius)
6413 *p1 = DoRotation(*p1, 0, -*rotate, 0);
6414 for (i = 0; i < 4; i++) {
6415 for (j = 0; j < model->TriangleNum; j++) {
6416 if (model->facenormals[j].y <= slopethreshold) {
6418 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)));
6419 if (distance < radius) {
6420 point = *p1 - model->facenormals[j] * distance;
6421 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]]))
6424 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6425 &model->vertex[model->Triangles[j].vertex[1]],
6428 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6429 &model->vertex[model->Triangles[j].vertex[2]],
6432 intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6433 &model->vertex[model->Triangles[j].vertex[2]],
6436 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6440 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)) {
6441 p1->y = point.y + radius;
6442 if ((animTarget == jumpdownanim || isFlip())) {
6443 if (isFlip() && (frameTarget < 5 || animation[animTarget].label[frameTarget] == 7 || animation[animTarget].label[frameTarget] == 4))
6446 if (animTarget == jumpupanim) {
6448 animTarget = getIdle();
6455 pause_sound(whooshsound);
6456 OPENAL_SetVolume(channels[whooshsound], 0);
6459 if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) {
6462 animTarget = getLanding();
6463 emit_sound_at(landsound, coords, 128.);
6466 envsound[numenvsounds] = coords;
6467 envsoundvol[numenvsounds] = 16;
6468 envsoundlife[numenvsounds] = .4;
6476 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6477 olddistance = distance;
6478 firstintersecting = j;
6483 for (j = 0; j < model->TriangleNum; j++) {
6484 if (model->facenormals[j].y > slopethreshold) {
6487 start.y -= radius / 4;
6488 XYZ &v0 = model->vertex[model->Triangles[j].vertex[0]];
6489 XYZ &v1 = model->vertex[model->Triangles[j].vertex[1]];
6490 XYZ &v2 = model->vertex[model->Triangles[j].vertex[2]];
6491 distance = abs((model->facenormals[j].x * start.x)
6492 + (model->facenormals[j].y * start.y)
6493 + (model->facenormals[j].z * start.z)
6494 - ((model->facenormals[j].x * v0.x)
6495 + (model->facenormals[j].y * v0.y)
6496 + (model->facenormals[j].z * v0.z)));
6497 if (distance < radius * .5) {
6498 point = start - model->facenormals[j] * distance;
6499 if (PointInTriangle( &point, model->facenormals[j], &v0, &v1, &v2))
6502 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, p1->x, p1->y, p1->z, radius / 2);
6504 intersecting = sphere_line_intersection(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6506 intersecting = sphere_line_intersection(v0.x, v0.y, v0.z, v2.x, v2.y, v2.z, p1->x, p1->y, p1->z, radius / 2);
6508 if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6509 if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
6511 velocity -= DoRotation(model->facenormals[j], 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->facenormals[j], 0, *rotate, 0))); //(distance-radius*.5)/multiplier;
6512 if (findLengthfast(&start) < findLengthfast(&velocity))
6515 *p1 += model->facenormals[j] * (distance - radius * .5);
6518 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6519 olddistance = distance;
6520 firstintersecting = j;
6527 *p = DoRotation(*p, 0, *rotate, 0);
6530 *p1 = DoRotation(*p1, 0, *rotate, 0);
6532 return firstintersecting;
6535 void Person::takeWeapon(int weaponId)
6538 weapons[weaponId].owner = id;
6539 if (num_weapons > 0) {
6540 weaponids[num_weapons] = weaponids[0];
6543 weaponids[0] = weaponId;