]> git.jsancho.org Git - lugaru.git/blob - Source/Person.cpp
b1e9f0aa2e396c883afbcdf092e4647d14bccbbc
[lugaru.git] / Source / Person.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 /**> HEADER FILES <**/
23 #include "Person.h"
24 #include "openal_wrapper.h"
25 #include "Animation.h"
26 #include "Sounds.h"
27 #include "Awards.h"
28 #include "Game.h"
29
30 extern float multiplier;
31 extern Terrain terrain;
32 extern float gravity;
33 extern int environment;
34 extern int detail;
35 extern FRUSTUM frustum;
36 extern XYZ viewer;
37 extern float realmultiplier;
38 extern int slomo;
39 extern float slomodelay;
40 extern bool cellophane;
41 extern float texdetail;
42 extern float realtexdetail;
43 extern GLubyte bloodText[512 * 512 * 3];
44 extern GLubyte wolfbloodText[512 * 512 * 3];
45 extern int bloodtoggle;
46 extern Objects objects;
47 extern bool osx;
48 extern bool autoslomo;
49 extern float camerashake;
50 extern float woozy;
51 extern float viewdistance;
52 extern float blackout;
53 extern int difficulty;
54 extern bool decals;
55 extern float fadestart;
56 extern bool freeze;
57 extern bool winfreeze;
58 extern float flashamount, flashr, flashg, flashb;
59 extern int flashdelay;
60 extern bool showpoints;
61 extern bool immediate;
62 extern int test;
63 extern bool tilt2weird;
64 extern bool tiltweird;
65 extern bool midweird;
66 extern bool proportionweird;
67 extern bool vertexweird[6];
68 extern XYZ envsound[30];
69 extern float envsoundvol[30];
70 extern float envsoundlife[30];
71 extern int numenvsounds;
72 extern int tutoriallevel;
73 extern float smoketex;
74 extern int tutorialstage;
75 extern bool reversaltrain;
76 extern bool canattack;
77 extern bool cananger;
78 extern float damagedealt;
79 extern int hostile;
80 extern float hostiletime;
81
82 extern int indialogue;
83
84 extern bool gamestarted;
85
86 Person player[maxplayers];
87
88 void Person::CheckKick()
89 {
90     if (!(hasvictim
91             && (animTarget == rabbitkickanim
92                 && victim
93                 && victim != this
94                 && frameCurrent >= 2
95                 && animCurrent == rabbitkickanim)
96             && (distsq(&coords, &victim->coords) < 1.2)
97             && (!victim->skeleton.free)))
98         return;
99
100     if (animation[victim->animTarget].height != lowheight) {
101         float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
102         XYZ relative = velocity;
103         relative.y = 0;
104         Normalise(&relative);
105
106         victim->spurt = 1;
107         DoBlood(.2, 250);
108         if (tutoriallevel != 1)
109             emit_sound_at(heavyimpactsound, victim->coords);
110         victim->RagDoll(0);
111         for (int i = 0; i < victim->skeleton.num_joints; i++) {
112             victim->skeleton.joints[i].velocity += relative * 120 * damagemult;
113         }
114         victim->Puff(neck);
115         victim->DoDamage(100 * damagemult / victim->protectionhigh);
116         if (id == 0)
117             camerashake += .4;
118
119         target = 0;
120         frameCurrent = 3;
121         animTarget = backflipanim;
122         frameTarget = 4;
123         velocity = facing * -10;
124         velocity.y = 5;
125         skeleton.free = 0;
126         if (id == 0)
127             resume_stream(whooshsound);
128
129         award_bonus(id, cannon);
130     } else if (victim->isCrouch()) {
131         animTarget = rabbitkickreversedanim;
132         animCurrent = rabbitkickreversedanim;
133         victim->animCurrent = rabbitkickreversalanim;
134         victim->animTarget = rabbitkickreversalanim;
135         targettilt2 = 0;
136         frameCurrent = 0;
137         frameTarget = 1;
138         target = 0;
139         velocity = 0;
140         victim->oldcoords = victim->coords;
141         coords = victim->coords;
142         victim->targetyaw = targetyaw;
143         victim->victim = this;
144     }
145 }
146
147 void Person::CatchFire()
148 {
149     XYZ flatfacing, flatvelocity;
150     int howmany;
151     for (int i = 0; i < 10; i++) {
152         howmany = abs(Random() % (skeleton.num_joints));
153         if (!skeleton.free)
154             flatvelocity = velocity;
155         if (skeleton.free)
156             flatvelocity = skeleton.joints[howmany].velocity;
157         if (!skeleton.free)
158             flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
159         if (skeleton.free)
160             flatfacing = skeleton.joints[howmany].position * scale + coords;
161         Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, 2, 1);
162     }
163
164     onfiredelay = 0.5;
165
166     emit_sound_at(firestartsound, coords);
167
168     emit_stream_at(stream_firesound, coords);
169
170     flamedelay = 0;
171
172     onfire = 1;
173 }
174
175 int Person::getIdle()
176 {
177     if (indialogue != -1 && howactive == typeactive && creature == rabbittype)
178         return talkidleanim;
179     if (hasvictim && victim != this/*||(id==0&&attackkeydown)*/)
180         if (/*(id==0&&attackkeydown)||*/(!victim->dead && victim->aitype != passivetype && victim->aitype != searchtype && aitype != passivetype && aitype != searchtype && victim->id < numplayers)) {
181             if ((aitype == playercontrolled && stunned <= 0 && weaponactive == -1) || pause) {
182                 if (creature == rabbittype)
183                     return fightidleanim;
184                 if (creature == wolftype)
185                     return wolfidle;
186             }
187             if (aitype == playercontrolled && stunned <= 0 && weaponactive != -1) {
188                 if (weapons[weaponids[weaponactive]].getType() == knife)
189                     return knifefightidleanim;
190                 if (weapons[weaponids[weaponactive]].getType() == sword && victim->weaponactive != -1)
191                     return swordfightidlebothanim;
192                 if (weapons[weaponids[weaponactive]].getType() == sword)
193                     return swordfightidleanim;
194                 if (weapons[weaponids[weaponactive]].getType() == staff)
195                     return swordfightidleanim;
196             }
197             if (aitype != playercontrolled && stunned <= 0 && creature != wolftype && !pause)
198                 return fightsidestep;
199         }
200     if ((damage > permanentdamage || damage > damagetolerance * .8 || deathbleeding > 0) && creature != wolftype)
201         return hurtidleanim;
202     if (howactive == typesitting) return sitanim;
203     if (howactive == typesittingwall) return sitwallanim;
204     if (howactive == typesleeping) return sleepanim;
205     if (howactive == typedead1) return dead1anim;
206     if (howactive == typedead2) return dead2anim;
207     if (howactive == typedead3) return dead3anim;
208     if (howactive == typedead4) return dead4anim;
209     if (creature == rabbittype) return bounceidleanim;
210     if (creature == wolftype) return wolfidle;
211     return 0;
212 }
213
214 int Person::getCrouch()
215 {
216     if (creature == rabbittype)
217         return crouchanim;
218     if (creature == wolftype)
219         return wolfcrouchanim;
220     return 0;
221 }
222
223 int Person::getRun()
224 {
225     if (creature == rabbittype && (!superruntoggle || weaponactive != -1))
226         return runanim;
227     if (creature == wolftype && (!superruntoggle))
228         return wolfrunanim;
229
230     if (creature == rabbittype && (superruntoggle && weaponactive == -1))
231         return rabbitrunninganim;
232     if (creature == wolftype && (superruntoggle))
233         return wolfrunninganim;
234     return 0;
235 }
236
237 int Person::getStop()
238 {
239     if (creature == rabbittype)
240         return stopanim;
241     if (creature == wolftype)
242         return wolfstopanim;
243     return 0;
244 }
245
246 int Person::getLanding()
247 {
248     if (creature == rabbittype)
249         return landanim;
250     if (creature == wolftype)
251         return wolflandanim;
252     return 0;
253 }
254
255 int Person::getLandhard()
256 {
257     if (creature == rabbittype)
258         return landhardanim;
259     if (creature == wolftype)
260         return wolflandhardanim;
261     return 0;
262 }
263
264 static void
265 SolidHitBonus(int playerid)
266 {
267     if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
268         award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
269     else
270         award_bonus(playerid, solidhit);
271 }
272
273 void Person::DoBlood(float howmuch, int which)
274 {
275     static int bleedxint, bleedyint;
276     static XYZ bloodvel;
277     //if(howmuch&&id==0)blooddimamount=1;
278     if (bloodtoggle && tutoriallevel != 1) {
279         if (bleeding <= 0 && spurt) {
280             spurt = 0;
281             for (int i = 0; i < 3; i++) {
282                 bloodvel = 0;
283                 if (!skeleton.free) {
284                     bloodvel.z = 10;
285                     bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
286                 }
287                 if (skeleton.free) {
288                     bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
289                 }
290                 if (skeleton.free)
291                     bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
292                 if (!skeleton.free)
293                     bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
294                 if (skeleton.free) {
295                     Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .05, 1);
296                     Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .3, 1);
297                 }
298                 if (!skeleton.free) {
299                     Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
300                     Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
301                 }
302             }
303             if (Random() % 2 == 0)
304                 for (int i = 0; i < 3; i++) {
305                     if (Random() % 2 != 0) {
306                         bloodvel = 0;
307                         if (skeleton.free) {
308                             bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
309                             bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
310                         } else {
311                             bloodvel.z = 10;
312                             bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
313                             bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
314                         }
315                         bloodvel *= .2;
316                         if (skeleton.free) {
317                             Sprite::MakeSprite(splintersprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .05, 1);
318                         } else {
319                             Sprite::MakeSprite(splintersprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
320                         }
321                         Sprite::setLastSpriteSpecial(3);
322                     }
323                 }
324         }
325         if (decals) {
326             bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
327             bleedxint = 0;
328             bleedyint = 0;
329             if (creature == rabbittype)
330                 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) {
331                     bleedxint = abs(Random() % 512);
332                     bleedyint = abs(Random() % 512);
333                 }
334             if (creature == wolftype)
335                 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) {
336                     bleedxint = abs(Random() % 512);
337                     bleedyint = abs(Random() % 512);
338                 }
339             bleedy = bleedxint;
340             bleedx = bleedyint;
341             bleedy /= realtexdetail;
342             bleedx /= realtexdetail;
343             direction = abs(Random() % 2) * 2 - 1;
344         }
345
346     }
347     if (bleeding > 2)
348         bleeding = 2;
349 }
350
351 void Person::DoBloodBig(float howmuch, int which)
352 {
353     static int bleedxint, bleedyint, i, j;
354     static XYZ bloodvel;
355     if (howmuch && id == 0)
356         blooddimamount = 1;
357
358     if (tutoriallevel != 1 || id == 0)
359         if (aitype != playercontrolled && howmuch > 0) {
360             int whichsound = -1;
361
362             if (creature == wolftype) {
363                 int i = abs(Random() % 2);
364                 if (i == 0)
365                     whichsound = snarlsound;
366                 if (i == 1)
367                     whichsound = snarl2sound;
368                 envsound[numenvsounds] = coords;
369                 envsoundvol[numenvsounds] = 16;
370                 envsoundlife[numenvsounds] = .4;
371                 numenvsounds++;
372             }
373             if (creature == rabbittype) {
374                 int i = abs(Random() % 2);
375                 if (i == 0)
376                     whichsound = rabbitpainsound;
377                 if (i == 1 && howmuch >= 2)
378                     whichsound = rabbitpain1sound;
379                 envsound[numenvsounds] = coords;
380                 envsoundvol[numenvsounds] = 16;
381                 envsoundlife[numenvsounds] = .4;
382                 numenvsounds++;
383                 //if(i==2)whichsound=rabbitpain2sound;
384             }
385
386             if (whichsound != -1)
387                 emit_sound_at(whichsound, coords);
388         }
389
390     if (id == 0 && howmuch > 0) {
391         flashamount = .5;
392         flashr = 1;
393         flashg = 0;
394         flashb = 0;
395         flashdelay = 0;
396     }
397
398     if (bloodtoggle && decals && tutoriallevel != 1) {
399         if (bleeding <= 0 && spurt) {
400             spurt = 0;
401             for (int i = 0; i < 3; i++) {
402                 bloodvel = 0;
403                 if (!skeleton.free) {
404                     bloodvel.z = 10;
405                     bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
406                 }
407                 if (skeleton.free) {
408                     bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
409                 }
410                 if (skeleton.free)
411                     bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
412                 if (!skeleton.free)
413                     bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
414                 if (skeleton.free) {
415                     Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .05, 1);
416                     Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .3, 1);
417                 }
418                 if (!skeleton.free) {
419                     Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
420                     Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
421                 }
422             }
423         }
424         int offsetx = 0, offsety = 0;
425         if (which == 225) {
426             offsety = Random() % 40;
427             offsetx = abs(Random() % 60);
428         }
429         if (which == 190 || which == 185) {
430             offsety = Random() % 40;
431             offsetx = abs(Random() % 100) - 20;
432         }
433         if (which == 175) {
434             offsety = Random() % 10;
435             offsetx = Random() % 10;
436         }
437         if (which == 170) {
438             offsety = Random() % 20;
439             offsetx = Random() % 20;
440         }
441         if (which == 220 || which == 215) {
442             offsetx = 20;
443         }
444
445
446         int startx = 512;
447         int starty = 512;
448         int endx = 0;
449         int endy = 0;
450         GLubyte color;
451         if (creature == rabbittype)
452             for (i = 0; i < 512; i++) {
453                 for (j = 0; j < 512; j++) {
454                     if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
455                         if (i < startx) startx = i;
456                         if (j < starty) starty = j;
457                         if (i > endx) endx = i;
458                         if (j > endy) endy = j;
459                     }
460                 }
461             }
462         if (creature == wolftype)
463             for (i = 0; i < 512; i++) {
464                 for (j = 0; j < 512; j++) {
465                     if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
466                         if (i < startx) startx = i;
467                         if (j < starty) starty = j;
468                         if (i > endx) endx = i;
469                         if (j > endy) endy = j;
470                     }
471                 }
472             }
473
474         startx += offsetx;
475         endx += offsetx;
476         starty += offsety;
477         endy += offsety;
478
479         if (startx < 0) startx = 0;
480         if (starty < 0) starty = 0;
481         if (endx > 512 - 1) endx = 512 - 1;
482         if (endy > 512 - 1) endy = 512 - 1;
483         if (endx < startx) endx = startx;
484         if (endy < starty) endy = starty;
485
486         startx /= realtexdetail;
487         starty /= realtexdetail;
488         endx /= realtexdetail;
489         endy /= realtexdetail;
490
491         int texdetailint = realtexdetail;
492         int where;
493         if (creature == rabbittype)
494             for (i = startx; i < endx; i++) {
495                 for (j = starty; j < endy; j++) {
496                     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) {
497                         color = Random() % 85 + 170;
498                         where = i * skeleton.skinsize * 3 + j * 3;
499                         if (skeleton.skinText[where + 0] > color / 2)
500                             skeleton.skinText[where + 0] = color / 2;
501                         skeleton.skinText[where + 1] = 0;
502                         skeleton.skinText[where + 2] = 0;
503                     }
504                 }
505             }
506         if (creature == wolftype)
507             for (i = startx; i < endx; i++) {
508                 for (j = starty; j < endy; j++) {
509                     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) {
510                         color = Random() % 85 + 170;
511                         where = i * skeleton.skinsize * 3 + j * 3;
512                         if (skeleton.skinText[where + 0] > color / 2)
513                             skeleton.skinText[where + 0] = color / 2;
514                         skeleton.skinText[where + 1] = 0;
515                         skeleton.skinText[where + 2] = 0;
516                     }
517                 }
518             }
519         skeleton.drawmodel.textureptr.bind();
520         DoMipmaps();
521
522         bleedxint = 0;
523         bleedyint = 0;
524         if (creature == rabbittype)
525             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) {
526                 bleedxint = abs(Random() % 512);
527                 bleedyint = abs(Random() % 512);
528             }
529         if (creature == wolftype)
530             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) {
531                 bleedxint = abs(Random() % 512);
532                 bleedyint = abs(Random() % 512);
533             }
534         bleedy = bleedxint + offsetx;
535         bleedx = bleedyint + offsety;
536         bleedy /= realtexdetail;
537         bleedx /= realtexdetail;
538         if (bleedx < 0)
539             bleedx = 0;
540         if (bleedy < 0)
541             bleedy = 0;
542         if (bleedx > skeleton.skinsize - 1)
543             bleedx = skeleton.skinsize - 1;
544         if (bleedy > skeleton.skinsize - 1)
545             bleedy = skeleton.skinsize - 1;
546         direction = abs(Random() % 2) * 2 - 1;
547
548     }
549     bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
550     deathbleeding += bleeding;
551     bloodloss += bleeding * 3;
552
553     if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
554         if (abs(Random() % 2) == 0) {
555             aitype = gethelptype;
556             lastseentime = 12;
557         } else
558             aitype = attacktypecutoff;
559         ally = 0;
560     }
561     if (bleeding > 2)
562         bleeding = 2;
563 }
564
565 bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
566 {
567     static int i, j;
568     static XYZ bloodvel;
569     static XYZ startpoint, endpoint, colpoint, movepoint;
570     static float rotationpoint;
571     static int whichtri;
572     static XYZ p1, p2, p3, p0;
573     static XYZ N, temp;
574     XYZ bary;
575     XYZ gxx, gyy;
576     float coordsx, coordsy;
577     float total;
578
579     if (bloodtoggle && decals && tutoriallevel != 1) {
580         where -= coords;
581         if (!skeleton.free)
582             where = DoRotation(where, 0, -yaw, 0);
583         //where=scale;
584         startpoint = where;
585         startpoint.y += 100;
586         endpoint = where;
587         endpoint.y -= 100;
588         movepoint = 0;
589         rotationpoint = 0;
590         whichtri = skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
591         if (whichtri != -1) {
592             p0 = colpoint;
593             p1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
594             p2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
595             p3 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
596             /*
597             CrossProduct(p2-p1,p3-p1,&N);
598             CrossProduct(p0-p1,p3-p1,&temp);
599             s =  dotproduct(&temp,&N)/findLength(&N);
600             CrossProduct(p2-p1,p1-p0,&temp);
601             t = dotproduct(&temp,&N)/findLength(&N);
602             r = 1 - (s + t);*/
603
604             bary.x = distsq(&p0, &p1);
605             bary.y = distsq(&p0, &p2);
606             bary.z = distsq(&p0, &p3);
607
608             total = bary.x + bary.y + bary.z;
609             bary.x /= total;
610             bary.y /= total;
611             bary.z /= total;
612
613             bary.x = 1 - bary.x;
614             bary.y = 1 - bary.y;
615             bary.z = 1 - bary.z;
616
617             total = bary.x + bary.y + bary.z;
618             bary.x /= total;
619             bary.y /= total;
620             bary.z /= total;
621
622
623             gxx.x = skeleton.drawmodel.Triangles[whichtri].gx[0];
624             gxx.y = skeleton.drawmodel.Triangles[whichtri].gx[1];
625             gxx.z = skeleton.drawmodel.Triangles[whichtri].gx[2];
626             gyy.x = skeleton.drawmodel.Triangles[whichtri].gy[0];
627             gyy.y = skeleton.drawmodel.Triangles[whichtri].gy[1];
628             gyy.z = skeleton.drawmodel.Triangles[whichtri].gy[2];
629             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;
630             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;
631
632             //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
633             //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
634
635             if (bleeding <= 0 && spurt) {
636                 spurt = 0;
637                 for (int i = 0; i < 3; i++) {
638                     bloodvel = 0;
639                     if (!skeleton.free) {
640                         bloodvel.z = 10;
641                         bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
642                     }
643                     if (skeleton.free) {
644                         bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0);
645                     }
646                     if (skeleton.free)
647                         bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
648                     if (!skeleton.free)
649                         bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
650                     if (skeleton.free) {
651                         Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .05, 1);
652                         Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position * scale + coords, bloodvel, 1, 1, 1, .3, 1);
653                     }
654                     if (!skeleton.free) {
655                         Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
656                         Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .3, 1);
657                     }
658                 }
659             }
660             int offsetx = 0, offsety = 0;
661             /*if(which==225){
662             offsety=Random()%40;
663             offsetx=abs(Random()%120);
664             }
665             if(which==220||which==215){
666             offsety=Random()%20;
667             offsetx=abs(Random()%80);
668             }*/
669             //which=220;
670             offsetx = (1 + coordsy) * 512 - 291;
671             offsety = coordsx * 512 - 437;
672
673             int startx = 512;
674             int starty = 512;
675             int endx = 0;
676             int endy = 0;
677             GLubyte color;
678             if (creature == rabbittype)
679                 for (i = 0; i < 512; i++) {
680                     for (j = 0; j < 512; j++) {
681                         if (bloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && bloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
682                             if (i < startx) startx = i;
683                             if (j < starty) starty = j;
684                             if (i > endx) endx = i;
685                             if (j > endy) endy = j;
686                         }
687                     }
688                 }
689             if (creature == wolftype)
690                 for (i = 0; i < 512; i++) {
691                     for (j = 0; j < 512; j++) {
692                         if (wolfbloodText[i * 512 * 3 + j * 3 + 0] <= which + 4 && wolfbloodText[i * 512 * 3 + j * 3 + 0] >= which - 4) {
693                             if (i < startx) startx = i;
694                             if (j < starty) starty = j;
695                             if (i > endx) endx = i;
696                             if (j > endy) endy = j;
697                         }
698                     }
699                 }
700             startx += offsetx;
701             endx += offsetx;
702             starty += offsety;
703             endy += offsety;
704
705             if (startx < 0) startx = 0;
706             if (starty < 0) starty = 0;
707             if (endx > 512 - 1) endx = 512 - 1;
708             if (endy > 512 - 1) endy = 512 - 1;
709             if (endx < startx) endx = startx;
710             if (endy < starty) endy = starty;
711
712             startx /= realtexdetail;
713             starty /= realtexdetail;
714             endx /= realtexdetail;
715             endy /= realtexdetail;
716
717             int texdetailint = realtexdetail;
718             int where;
719             if (creature == rabbittype)
720                 for (i = startx; i < endx; i++) {
721                     for (j = starty; j < endy; j++) {
722                         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) {
723                             color = Random() % 85 + 170;
724                             where = i * skeleton.skinsize * 3 + j * 3;
725                             if (skeleton.skinText[where + 0] > color / 2)
726                                 skeleton.skinText[where + 0] = color / 2;
727                             skeleton.skinText[where + 1] = 0;
728                             skeleton.skinText[where + 2] = 0;
729                         } 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) {
730                             color = Random() % 85 + 170;
731                             where = i * skeleton.skinsize * 3 + j * 3;
732                             if (skeleton.skinText[where + 0] > color / 2)
733                                 skeleton.skinText[where + 0] = color / 2;
734                             skeleton.skinText[where + 1] = 0;
735                             skeleton.skinText[where + 2] = 0;
736                         }
737                     }
738                 }
739             if (creature == wolftype)
740                 for (i = startx; i < endx; i++) {
741                     for (j = starty; j < endy; j++) {
742                         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) {
743                             color = Random() % 85 + 170;
744                             where = i * skeleton.skinsize * 3 + j * 3;
745                             if (skeleton.skinText[where + 0] > color / 2)
746                                 skeleton.skinText[where + 0] = color / 2;
747                             skeleton.skinText[where + 1] = 0;
748                             skeleton.skinText[where + 2] = 0;
749                         } 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) {
750                             color = Random() % 85 + 170;
751                             where = i * skeleton.skinsize * 3 + j * 3;
752                             if (skeleton.skinText[where + 0] > color / 2)
753                                 skeleton.skinText[where + 0] = color / 2;
754                             skeleton.skinText[where + 1] = 0;
755                             skeleton.skinText[where + 2] = 0;
756                         }
757                     }
758                 }
759             skeleton.drawmodel.textureptr.bind();
760             DoMipmaps();
761
762             bleedy = (1 + coordsy) * 512;
763             bleedx = coordsx * 512;
764             bleedy /= realtexdetail;
765             bleedx /= realtexdetail;
766             if (bleedx < 0)
767                 bleedx = 0;
768             if (bleedy < 0)
769                 bleedy = 0;
770             if (bleedx > skeleton.skinsize - 1)
771                 bleedx = skeleton.skinsize - 1;
772             if (bleedy > skeleton.skinsize - 1)
773                 bleedy = skeleton.skinsize - 1;
774             direction = abs(Random() % 2) * 2 - 1;
775         }
776         if (whichtri == -1)
777             return 0;
778     }
779     bleeding = howmuch + (float)abs(Random() % 100) / 200 - .25;
780     deathbleeding += bleeding;
781     bloodloss += bleeding * 3;
782
783     if (tutoriallevel != 1 && aitype != playercontrolled && bloodloss > damagetolerance * 2 / 3 && bloodloss < damagetolerance && creature == rabbittype) {
784         if (abs(Random() % 2) == 0) {
785             aitype = gethelptype;
786             lastseentime = 12;
787         } else
788             aitype = attacktypecutoff;
789         ally = 0;
790     }
791     if (bleeding > 2)
792         bleeding = 2;
793     return 1;
794 }
795
796
797
798 void Person::Reverse()
799 {
800     if (!((victim->aitype == playercontrolled
801             || hostiletime > 1
802             || staggerdelay <= 0)
803             && victim->animTarget != jumpupanim
804             && victim->animTarget != jumpdownanim
805             && (tutoriallevel != 1 || cananger)
806             && hostile))
807         return;
808
809     if (normaldotproduct (victim->facing, victim->coords - coords) > 0
810             && (victim->id != 0 || difficulty >= 2)
811             && (creature != wolftype || victim->creature == wolftype))
812         return;
813
814     if (animTarget == sweepanim) {
815         animTarget = sweepreversedanim;
816         animCurrent = sweepreversedanim;
817         victim->animCurrent = sweepreversalanim;
818         victim->animTarget = sweepreversalanim;
819     }
820     if (animTarget == spinkickanim) {
821         animTarget = spinkickreversedanim;
822         animCurrent = spinkickreversedanim;
823         victim->animCurrent = spinkickreversalanim;
824         victim->animTarget = spinkickreversalanim;
825     }
826     if (animTarget == upunchanim || animTarget == rabbittacklinganim) {
827         if (animTarget == rabbittacklinganim) {
828             frameCurrent = 6;
829             frameTarget = 7;
830             victim->frameCurrent = 6;
831             victim->frameTarget = 7;
832         }
833         animTarget = upunchreversedanim;
834         animCurrent = upunchreversedanim;
835         victim->animCurrent = upunchreversalanim;
836         victim->animTarget = upunchreversalanim;
837     }
838     if (animTarget == staffhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
839         if (victim->weaponactive != -1) {
840             victim->throwtogglekeydown = 1;
841             weapons[victim->weaponids[0]].owner = -1;
842             weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
843             if (weapons[victim->weaponids[0]].velocity.x == 0)
844                 weapons[victim->weaponids[0]].velocity.x = .1;
845             weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
846             weapons[victim->weaponids[0]].missed = 1;
847             weapons[victim->weaponids[0]].freetime = 0;
848             weapons[victim->weaponids[0]].firstfree = 1;
849             weapons[victim->weaponids[0]].physics = 1;
850             victim->num_weapons--;
851             if (victim->num_weapons) {
852                 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
853                 if (victim->weaponstuck == victim->num_weapons)
854                     victim->weaponstuck = 0;
855             }
856
857             victim->weaponactive = -1;
858             for (int j = 0; j < numplayers; j++) {
859                 player[j].wentforweapon = 0;
860             }
861         }
862
863         animTarget = staffhitreversedanim;
864         animCurrent = staffhitreversedanim;
865         victim->animCurrent = staffhitreversalanim;
866         victim->animTarget = staffhitreversalanim;
867     }
868     if (animTarget == staffspinhitanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 2 == 0)) {
869         if (victim->weaponactive != -1) {
870             victim->throwtogglekeydown = 1;
871             weapons[victim->weaponids[0]].owner = -1;
872             weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
873             if (weapons[victim->weaponids[0]].velocity.x == 0)
874                 weapons[victim->weaponids[0]].velocity.x = .1;
875             weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
876             weapons[victim->weaponids[0]].missed = 1;
877             weapons[victim->weaponids[0]].freetime = 0;
878             weapons[victim->weaponids[0]].firstfree = 1;
879             weapons[victim->weaponids[0]].physics = 1;
880             victim->num_weapons--;
881             if (victim->num_weapons) {
882                 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
883                 if (victim->weaponstuck == victim->num_weapons)
884                     victim->weaponstuck = 0;
885             }
886
887             victim->weaponactive = -1;
888             for (int j = 0; j < numplayers; j++) {
889                 player[j].wentforweapon = 0;
890             }
891         }
892         animTarget = staffspinhitreversedanim;
893         animCurrent = staffspinhitreversedanim;
894         victim->animCurrent = staffspinhitreversalanim;
895         victim->animTarget = staffspinhitreversalanim;
896     }
897     if (animTarget == swordslashanim && distsq(&victim->coords, &coords) < 2 && ((victim->id == 0 && victim->crouchkeydown) || Random() % 4 == 0)) {
898         if (victim->weaponactive != -1) {
899             victim->throwtogglekeydown = 1;
900             weapons[victim->weaponids[0]].owner = -1;
901             weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
902             if (weapons[victim->weaponids[0]].velocity.x == 0)
903                 weapons[victim->weaponids[0]].velocity.x = .1;
904             weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
905             weapons[victim->weaponids[0]].missed = 1;
906             weapons[victim->weaponids[0]].freetime = 0;
907             weapons[victim->weaponids[0]].firstfree = 1;
908             weapons[victim->weaponids[0]].physics = 1;
909             victim->num_weapons--;
910             if (victim->num_weapons) {
911                 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
912                 if (victim->weaponstuck == victim->num_weapons)
913                     victim->weaponstuck = 0;
914             }
915
916             victim->weaponactive = -1;
917             for (int j = 0; j < numplayers; j++) {
918                 player[j].wentforweapon = 0;
919             }
920         }
921         animTarget = swordslashreversedanim;
922         animCurrent = swordslashreversedanim;
923         victim->animCurrent = swordslashreversalanim;
924         victim->animTarget = swordslashreversalanim;
925     }
926     if (animTarget == knifeslashstartanim && distsq(&victim->coords, &coords) < 2 && (victim->id == 0 || Random() % 4 == 0)) {
927         if (victim->weaponactive != -1) {
928             victim->throwtogglekeydown = 1;
929             weapons[victim->weaponids[0]].owner = -1;
930             weapons[victim->weaponids[0]].velocity = victim->velocity * .2;
931             if (weapons[victim->weaponids[0]].velocity.x == 0)
932                 weapons[victim->weaponids[0]].velocity.x = .1;
933             weapons[victim->weaponids[0]].tipvelocity = weapons[victim->weaponids[0]].velocity;
934             weapons[victim->weaponids[0]].missed = 1;
935             weapons[victim->weaponids[0]].freetime = 0;
936             weapons[victim->weaponids[0]].firstfree = 1;
937             weapons[victim->weaponids[0]].physics = 1;
938             victim->num_weapons--;
939             if (victim->num_weapons) {
940                 victim->weaponids[0] = victim->weaponids[victim->num_weapons];
941                 if (victim->weaponstuck == victim->num_weapons)
942                     victim->weaponstuck = 0;
943             }
944
945             victim->weaponactive = -1;
946             for (int j = 0; j < numplayers; j++) {
947                 player[j].wentforweapon = 0;
948             }
949         }
950         animTarget = knifeslashreversedanim;
951         animCurrent = knifeslashreversedanim;
952         victim->animCurrent = knifeslashreversalanim;
953         victim->animTarget = knifeslashreversalanim;
954     }
955     if (animTarget != knifeslashstartanim && animTarget != staffhitanim && animTarget != staffspinhitanim && animTarget != winduppunchanim && animTarget != wolfslapanim && animTarget != swordslashanim && animTarget != swordslashanim) {
956         victim->targettilt2 = targettilt2;
957         victim->frameCurrent = frameCurrent;
958         victim->frameTarget = frameTarget;
959         victim->target = target;
960         victim->velocity = 0;
961         victim->oldcoords = victim->coords;
962         victim->coords = coords;
963         victim->targetyaw = targetyaw;
964         victim->yaw = targetyaw;
965         victim->victim = this;
966     }
967     if (animTarget == winduppunchanim) {
968         animTarget = winduppunchblockedanim;
969         victim->animTarget = blockhighleftanim;
970         victim->frameTarget = 1;
971         victim->target = .5;
972         victim->victim = this;
973         victim->targetyaw = targetyaw + 180;
974     }
975     if (animTarget == wolfslapanim) {
976         animTarget = winduppunchblockedanim;
977         victim->animTarget = blockhighleftanim;
978         victim->frameTarget = 1;
979         victim->target = .5;
980         victim->victim = this;
981         victim->targetyaw = targetyaw + 180;
982     }
983     if ((animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) && victim->weaponactive != -1) {
984         animTarget = swordslashparriedanim;
985         parriedrecently = .4;
986         victim->parriedrecently = 0;
987         victim->animTarget = swordslashparryanim;
988         victim->frameTarget = 1;
989         victim->target = .5;
990         victim->victim = this;
991         victim->targetyaw = targetyaw + 180;
992
993         if (abs(Random() % 20) == 0 || weapons[victim->weaponids[victim->weaponactive]].getType() == knife) {
994             if (victim->weaponactive != -1) {
995                 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
996                     if (weapons[victim->weaponids[0]].getType() == staff)
997                         weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
998                     if (weapons[weaponids[0]].getType() == staff)
999                         weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1000                     emit_sound_at(swordstaffsound, victim->coords);
1001                 } else {
1002                     emit_sound_at(metalhitsound, victim->coords);
1003                 }
1004             }
1005             XYZ aim;
1006             victim->Puff(righthand);
1007             victim->target = 0;
1008             victim->frameTarget = 0;
1009             victim->animTarget = staggerbackhighanim;
1010             victim->targetyaw = targetyaw + 180;
1011             victim->target = 0;
1012             weapons[victim->weaponids[0]].owner = -1;
1013             aim = DoRotation(facing, 0, 90, 0) * 21;
1014             aim.y += 7;
1015             weapons[victim->weaponids[0]].velocity = aim * -.2;
1016             weapons[victim->weaponids[0]].tipvelocity = aim;
1017             weapons[victim->weaponids[0]].missed = 1;
1018             weapons[victim->weaponids[0]].hitsomething = 0;
1019             weapons[victim->weaponids[0]].freetime = 0;
1020             weapons[victim->weaponids[0]].firstfree = 1;
1021             weapons[victim->weaponids[0]].physics = 1;
1022             victim->num_weapons--;
1023             if (victim->num_weapons) {
1024                 victim->weaponids[0] = victim->weaponids[num_weapons];
1025                 if (victim->weaponstuck == victim->num_weapons)
1026                     victim->weaponstuck = 0;
1027             }
1028             victim->weaponactive = -1;
1029             for (int i = 0; i < numplayers; i++) {
1030                 player[i].wentforweapon = 0;
1031             }
1032         }
1033
1034         if (abs(Random() % 20) == 0) {
1035             if (weaponactive != -1) {
1036                 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
1037                     if (weapons[victim->weaponids[0]].getType() == staff)
1038                         weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1039                     if (weapons[weaponids[0]].getType() == staff)
1040                         weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
1041
1042                     emit_sound_at(swordstaffsound, coords);
1043                 } else {
1044                     emit_sound_at(metalhitsound, coords);
1045                 }
1046             }
1047
1048             XYZ aim;
1049             Puff(righthand);
1050             target = 0;
1051             frameTarget = 0;
1052             animTarget = staggerbackhighanim;
1053             targetyaw = targetyaw + 180;
1054             target = 0;
1055             weapons[weaponids[0]].owner = -1;
1056             aim = DoRotation(facing, 0, 90, 0) * 21;
1057             aim.y += 7;
1058             weapons[weaponids[0]].velocity = aim * -.2;
1059             weapons[weaponids[0]].tipvelocity = aim;
1060             weapons[weaponids[0]].hitsomething = 0;
1061             weapons[weaponids[0]].missed = 1;
1062             weapons[weaponids[0]].freetime = 0;
1063             weapons[weaponids[0]].firstfree = 1;
1064             weapons[weaponids[0]].physics = 1;
1065             num_weapons--;
1066             if (num_weapons) {
1067                 weaponids[0] = weaponids[num_weapons];
1068                 if (weaponstuck == num_weapons)
1069                     weaponstuck = 0;
1070             }
1071             weaponactive = -1;
1072             for (int i = 0; i < numplayers; i++) {
1073                 player[i].wentforweapon = 0;
1074             }
1075
1076
1077         }
1078     }
1079     if (hasvictim)
1080         if (animTarget == knifeslashstartanim || animTarget == swordslashanim || animTarget == staffhitanim || animTarget == staffspinhitanim) {
1081             if ((animTarget != staffhitanim && animTarget != staffspinhitanim) || distsq(&coords, &victim->coords) > .2) {
1082                 victim->animTarget = dodgebackanim;
1083                 victim->frameTarget = 0;
1084                 victim->target = 0;
1085
1086                 XYZ rotatetarget;
1087                 rotatetarget = coords - victim->coords;
1088                 Normalise(&rotatetarget);
1089                 victim->targetyaw = -asin(0 - rotatetarget.x);
1090                 victim->targetyaw *= 360 / 6.28;
1091                 if (rotatetarget.z < 0)
1092                     victim->targetyaw = 180 - victim->targetyaw;
1093
1094                 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1095
1096                 victim->lastattack3 = victim->lastattack2;
1097                 victim->lastattack2 = victim->lastattack;
1098                 victim->lastattack = victim->animTarget;
1099             } else {
1100                 victim->animTarget = sweepanim;
1101                 victim->frameTarget = 0;
1102                 victim->target = 0;
1103
1104                 XYZ rotatetarget;
1105                 rotatetarget = coords - victim->coords;
1106                 Normalise(&rotatetarget);
1107                 victim->targetyaw = -asin(0 - rotatetarget.x);
1108                 victim->targetyaw *= 360 / 6.28;
1109                 if (rotatetarget.z < 0)
1110                     victim->targetyaw = 180 - victim->targetyaw;
1111
1112                 victim->targettilt2 = -asin(rotatetarget.y) * 360 / 6.28; //*-70;
1113
1114                 victim->lastattack3 = victim->lastattack2;
1115                 victim->lastattack2 = victim->lastattack;
1116                 victim->lastattack = victim->animTarget;
1117             }
1118         }
1119
1120     velocity = 0;
1121     victim->velocity = 0;
1122
1123     if (aitype != playercontrolled)
1124         feint = 0;
1125     if (aitype != playercontrolled && Random() % 3 == 0 && escapednum < 2 && difficulty == 2)
1126         feint = 1;
1127     if (aitype != playercontrolled && Random() % 5 == 0 && escapednum < 2 && difficulty == 1)
1128         feint = 1;
1129     if (aitype != playercontrolled && Random() % 10 == 0 && escapednum < 2 && difficulty == 0)
1130         feint = 1;
1131
1132     if (victim->id == 0 && animation[victim->animTarget].attack == reversal)
1133         numreversals++;
1134 }
1135
1136 void Person::DoDamage(float howmuch)
1137 {
1138     if (tutoriallevel != 1)
1139         damage += howmuch / power;
1140     if (id != 0)
1141         damagedealt += howmuch / power;
1142     if (id == 0)
1143         damagetaken += howmuch / power;
1144
1145     if (id == 0 && (bonus == solidhit || bonus == twoxcombo || bonus == threexcombo || bonus == fourxcombo || bonus == megacombo))
1146         bonus = 0;
1147     if (tutoriallevel != 1)
1148         permanentdamage += howmuch / 2 / power;
1149     if (tutoriallevel != 1)
1150         superpermanentdamage += howmuch / 4 / power;
1151     if (permanentdamage > damagetolerance / 2 && permanentdamage - howmuch < damagetolerance / 2 && Random() % 2)
1152         DoBlood(1, 255);
1153     if ((permanentdamage > damagetolerance * .8 && Random() % 2 && !deathbleeding) || spurt)
1154         DoBlood(1, 255);
1155     spurt = 0;
1156     if (id == 0)
1157         camerashake += howmuch / 100;
1158     if (id == 0 && ((howmuch > 50 && damage > damagetolerance / 2)))
1159         blackout = damage / damagetolerance;
1160     if (blackout > 1)
1161         blackout = 1;
1162
1163     if (aitype == passivetype && damage < damagetolerance && ((tutoriallevel != 1 || cananger) && hostile))
1164         aitype = attacktypecutoff;
1165     if (tutoriallevel != 1 && aitype != playercontrolled && damage < damagetolerance && damage > damagetolerance * 2 / 3 && creature == rabbittype) {
1166         if (abs(Random() % 2) == 0) {
1167             aitype = gethelptype;
1168             lastseentime = 12;
1169         } else
1170             aitype = attacktypecutoff;
1171         ally = 0;
1172     }
1173
1174     if (howmuch > damagetolerance * 50 && skeleton.free != 2) {
1175         XYZ flatvelocity2;
1176         XYZ flatfacing2;
1177         for (int i = 0; i < skeleton.num_joints; i++) {
1178             if (!skeleton.free)
1179                 flatvelocity2 = velocity;
1180             if (skeleton.free)
1181                 flatvelocity2 = skeleton.joints[i].velocity;
1182             if (!skeleton.free)
1183                 flatfacing2 = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
1184             if (skeleton.free)
1185                 flatfacing2 = skeleton.joints[i].position * scale + coords;
1186             flatvelocity2.x += (float)(abs(Random() % 100) - 50) / 10;
1187             flatvelocity2.y += (float)(abs(Random() % 100) - 50) / 10;
1188             flatvelocity2.z += (float)(abs(Random() % 100) - 50) / 10;
1189             Sprite::MakeSprite(bloodflamesprite, flatfacing2, flatvelocity2, 1, 1, 1, 3, 1);
1190             Sprite::MakeSprite(bloodsprite, flatfacing2, flatvelocity2, 1, 1, 1, .4, 1);
1191             Sprite::MakeSprite(cloudsprite, flatfacing2, flatvelocity2 * 0, .6, 0, 0, 1, .5);
1192         }
1193
1194         emit_sound_at(splattersound, coords);
1195
1196         skeleton.free = 2;
1197         DoDamage(10000);
1198         RagDoll(0);
1199         /*if(autoslomo){
1200         slomo=1;
1201         slomodelay=.2;
1202         }*/
1203         if (!dead && creature == wolftype) {
1204             award_bonus(0, Wolfbonus);
1205         }
1206         dead = 2;
1207         coords = 20;
1208     }
1209
1210     if (tutoriallevel != 1 || id == 0)
1211         if (speechdelay <= 0 && !dead && aitype != playercontrolled) {
1212             int whichsound = -1;
1213
1214             if (creature == wolftype) {
1215                 int i = abs(Random() % 2);
1216                 if (i == 0)
1217                     whichsound = snarlsound;
1218                 if (i == 1)
1219                     whichsound = snarl2sound;
1220                 envsound[numenvsounds] = coords;
1221                 envsoundvol[numenvsounds] = 16;
1222                 envsoundlife[numenvsounds] = .4;
1223                 numenvsounds++;
1224             }
1225             if (creature == rabbittype) {
1226                 int i = abs(Random() % 2);
1227                 if (i == 0)
1228                     whichsound = rabbitpainsound;
1229                 if (i == 1 && damage > damagetolerance)
1230                     whichsound = rabbitpain1sound;
1231                 envsound[numenvsounds] = coords;
1232                 envsoundvol[numenvsounds] = 16;
1233                 envsoundlife[numenvsounds] = .4;
1234                 numenvsounds++;
1235                 //if(i==2)whichsound=rabbitpain2sound;
1236             }
1237
1238             if (whichsound != -1) {
1239                 emit_sound_at(whichsound, coords);
1240             }
1241         }
1242     speechdelay = .3;
1243
1244     //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1245     //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1246 }
1247
1248 void Person::DoHead()
1249 {
1250     static XYZ rotatearound;
1251     static XYZ facing;
1252     static float lookspeed = 500;
1253
1254     if (!freeze && !winfreeze) {
1255
1256         //head facing
1257         targetheadyaw = (float)((int)((0 - yaw - targetheadyaw + 180) * 100) % 36000) / 100;
1258         targetheadpitch = (float)((int)(targetheadpitch * 100) % 36000) / 100;
1259
1260         while (targetheadyaw > 180)targetheadyaw -= 360;
1261         while (targetheadyaw < -180)targetheadyaw += 360;
1262
1263         if (targetheadyaw > 160)
1264             targetheadpitch = targetheadpitch * -1;
1265         if (targetheadyaw < -160)
1266             targetheadpitch = targetheadpitch * -1;
1267         if (targetheadyaw > 160)
1268             targetheadyaw = targetheadyaw - 180;
1269         if (targetheadyaw < -160)
1270             targetheadyaw = targetheadyaw + 180;
1271
1272         if (targetheadpitch > 120)
1273             targetheadpitch = 120;
1274         if (targetheadpitch < -120)
1275             targetheadpitch = -120;
1276         if (targetheadyaw > 120)
1277             targetheadyaw = 120;
1278         if (targetheadyaw < -120)
1279             targetheadyaw = -120;
1280
1281         if (!isIdle())
1282             targetheadpitch = 0;
1283         if (isIdle()) {
1284             if (targetheadyaw > 80)
1285                 targetheadyaw = 80;
1286             if (targetheadyaw < -80)
1287                 targetheadyaw = -80;
1288             if (targetheadpitch > 50)
1289                 targetheadpitch = 50;
1290             if (targetheadpitch < -50)
1291                 targetheadpitch = -50;
1292         }
1293
1294         if (abs(headyaw - targetheadyaw) < multiplier * lookspeed)
1295             headyaw = targetheadyaw;
1296         else if (headyaw > targetheadyaw) {
1297             headyaw -= multiplier * lookspeed;
1298         } else if (headyaw < targetheadyaw) {
1299             headyaw += multiplier * lookspeed;
1300         }
1301
1302         if (abs(headpitch - targetheadpitch) < multiplier * lookspeed / 2)
1303             headpitch = targetheadpitch;
1304         else if (headpitch > targetheadpitch) {
1305             headpitch -= multiplier * lookspeed / 2;
1306         } else if (headpitch < targetheadpitch) {
1307             headpitch += multiplier * lookspeed / 2;
1308         }
1309
1310         rotatearound = skeleton.joints[skeleton.jointlabels[neck]].position;
1311         skeleton.joints[skeleton.jointlabels[head]].position = rotatearound + DoRotation(skeleton.joints[skeleton.jointlabels[head]].position - rotatearound, headpitch, 0, 0);
1312
1313         facing = 0;
1314         facing.z = -1;
1315         if (animTarget != bounceidleanim && animTarget != fightidleanim && animTarget != wolfidle && animTarget != knifefightidleanim && animTarget != drawrightanim && animTarget != drawleftanim && animTarget != walkanim) {
1316             facing = DoRotation(facing, headpitch * .4, 0, 0);
1317             facing = DoRotation(facing, 0, headyaw * .4, 0);
1318         }
1319
1320         if (animTarget == bounceidleanim || animTarget == fightidleanim || animTarget == wolfidle || animTarget == knifefightidleanim || animTarget == drawrightanim || animTarget == drawleftanim) {
1321             facing = DoRotation(facing, headpitch * .8, 0, 0);
1322             facing = DoRotation(facing, 0, headyaw * .8, 0);
1323         }
1324
1325         if (animTarget == walkanim) {
1326             facing = DoRotation(facing, headpitch * .6, 0, 0);
1327             facing = DoRotation(facing, 0, headyaw * .6, 0);
1328         }
1329
1330         skeleton.specialforward[0] = facing;
1331         //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1332         static int i;
1333         for (i = 0; i < skeleton.num_muscles; i++) {
1334             if (skeleton.muscles[i].visible && (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)) {
1335                 skeleton.FindRotationMuscle(i, animTarget);
1336             }
1337         }
1338     }
1339 }
1340
1341 void Person::RagDoll(bool checkcollision)
1342 {
1343     static XYZ change;
1344     static int l, i, j;
1345     static float speed;
1346     if (!skeleton.free) {
1347         if (id == 0)
1348             numfalls++;
1349         if (id == 0 && isFlip())
1350             numflipfail++;
1351
1352         escapednum = 0;
1353
1354         facing = 0;
1355         facing.z = 1;
1356         facing = DoRotation(facing, 0, yaw, 0);
1357
1358         skeleton.freetime = 0;
1359
1360         skeleton.longdead = 0;
1361
1362         skeleton.free = 1;
1363         skeleton.broken = 0;
1364         skeleton.spinny = 1;
1365         freefall = 1;
1366         skeleton.freefall = 1;
1367
1368         if (!isnormal(velocity.x)) velocity.x = 0;
1369         if (!isnormal(velocity.y)) velocity.y = 0;
1370         if (!isnormal(velocity.z)) velocity.z = 0;
1371         if (!isnormal(yaw)) yaw = 0;
1372         if (!isnormal(coords.x)) coords = 0;
1373         if (!isnormal(tilt)) tilt = 0;
1374         if (!isnormal(tilt2)) tilt2 = 0;
1375
1376         for (i = 0; i < skeleton.num_joints; i++) {
1377             skeleton.joints[i].delay = 0;
1378             skeleton.joints[i].locked = 0;
1379             skeleton.joints[i].position = DoRotation(DoRotation(DoRotation(skeleton.joints[i].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0);
1380             if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = DoRotation(skeleton.joints[i].position, 0, yaw, 0);
1381             if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = skeleton.joints[i].position;
1382             if (!isnormal(skeleton.joints[i].position.x)) skeleton.joints[i].position = coords;
1383             skeleton.joints[i].position.y += .1;
1384             skeleton.joints[i].oldposition = skeleton.joints[i].position;
1385             skeleton.joints[i].realoldposition = skeleton.joints[i].position * scale + coords;
1386         }
1387
1388         for (i = 0; i < skeleton.num_joints; i++) {
1389             skeleton.joints[i].velocity = 0;
1390             skeleton.joints[i].velchange = 0;
1391         }
1392         skeleton.DoConstraints(&coords, &scale);
1393         if (animation[animCurrent].height == lowheight || animation[animTarget].height == lowheight) {
1394             skeleton.DoConstraints(&coords, &scale);
1395             skeleton.DoConstraints(&coords, &scale);
1396             skeleton.DoConstraints(&coords, &scale);
1397             skeleton.DoConstraints(&coords, &scale);
1398         }
1399
1400         speed = animation[animTarget].speed[frameTarget] * 2;
1401         if (animation[animCurrent].speed[frameCurrent] > animation[animTarget].speed[frameTarget]) {
1402             speed = animation[animCurrent].speed[frameCurrent] * 2;
1403         }
1404         if (transspeed)
1405             speed = transspeed * 2;
1406
1407         speed *= speedmult;
1408
1409         for (i = 0; i < skeleton.num_joints; i++) {
1410             if ((animation[animCurrent].attack != reversed || animCurrent == swordslashreversedanim) && animCurrent != rabbitkickanim && !isLanding() && !wasLanding() && animation[animCurrent].height == animation[animTarget].height)
1411                 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);
1412             else
1413                 skeleton.joints[i].velocity = velocity / scale + facing * 5;
1414             change.x = (float)(Random() % 100) / 100;
1415             change.y = (float)(Random() % 100) / 100;
1416             change.z = (float)(Random() % 100) / 100;
1417             skeleton.joints[i].velocity += change;
1418             skeleton.joints[abs(Random() % skeleton.num_joints)].velocity -= change;
1419
1420             change.x = (float)(Random() % 100) / 100;
1421             change.y = (float)(Random() % 100) / 100;
1422             change.z = (float)(Random() % 100) / 100;
1423             skeleton.joints[i].velchange += change;
1424             skeleton.joints[abs(Random() % skeleton.num_joints)].velchange -= change;
1425         }
1426
1427         if (checkcollision) {
1428             XYZ average;
1429             XYZ lowpoint;
1430             XYZ colpoint;
1431             int howmany;
1432             average = 0;
1433             howmany = 0;
1434             for (j = 0; j < skeleton.num_joints; j++) {
1435                 average += skeleton.joints[j].position;
1436                 howmany++;
1437             }
1438             average /= howmany;
1439             coords += average * scale;
1440             for (j = 0; j < skeleton.num_joints; j++) {
1441                 skeleton.joints[j].position -= average;
1442             }
1443
1444             whichpatchx = coords.x / (terrain.size / subdivision * terrain.scale);
1445             whichpatchz = coords.z / (terrain.size / subdivision * terrain.scale);
1446             if (terrain.patchobjectnum[whichpatchx][whichpatchz])
1447                 for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
1448                     i = terrain.patchobjects[whichpatchx][whichpatchz][l];
1449                     lowpoint = coords;
1450                     lowpoint.y += 1;
1451                     if (SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.yaw[i], &objects.model[i]) != -1) {
1452                         coords.x = lowpoint.x;
1453                         coords.z = lowpoint.z;
1454                     }
1455                 }
1456         }
1457
1458         yaw = 0;
1459         updatedelay = 0;
1460
1461         velocity = 0;
1462         for (i = 0; i < skeleton.num_joints; i++) {
1463             velocity += skeleton.joints[i].velocity * scale;
1464         }
1465         velocity /= skeleton.num_joints;
1466
1467         if (Random() % 2 == 0) {
1468             if (weaponactive != -1 && animTarget != rabbitkickanim && num_weapons > 0) {
1469                 weapons[weaponids[0]].owner = -1;
1470                 weapons[weaponids[0]].hitsomething = 0;
1471                 weapons[weaponids[0]].velocity = skeleton.joints[skeleton.jointlabels[righthand]].velocity * scale * -.3;
1472                 weapons[weaponids[0]].velocity.x += .01;
1473                 weapons[weaponids[0]].tipvelocity = skeleton.joints[skeleton.jointlabels[righthand]].velocity * scale;
1474                 weapons[weaponids[0]].missed = 1;
1475                 weapons[weaponids[0]].freetime = 0;
1476                 weapons[weaponids[0]].firstfree = 1;
1477                 weapons[weaponids[0]].physics = 1;
1478                 num_weapons--;
1479                 if (num_weapons) {
1480                     weaponids[0] = weaponids[num_weapons];
1481                     if (weaponstuck == num_weapons)
1482                         weaponstuck = 0;
1483                 }
1484                 weaponactive = -1;
1485                 for (i = 0; i < numplayers; i++) {
1486                     player[i].wentforweapon = 0;
1487                 }
1488             }
1489         }
1490
1491         animTarget = bounceidleanim;
1492         animCurrent = bounceidleanim;
1493         frameTarget = 0;
1494         frameCurrent = 0;
1495     }
1496 }
1497
1498
1499
1500 void Person::FootLand(int which, float opacity)
1501 {
1502     static XYZ terrainlight;
1503     static XYZ footvel, footpoint;
1504     if (opacity >= 1 || skiddelay <= 0)
1505         if (opacity > 1) {
1506             footvel = 0;
1507             if (which == 0)
1508                 footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
1509             if (which == 1)
1510                 footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
1511             //footpoint.y=coords.y;
1512             if (distsq(&footpoint, &viewer))
1513                 Sprite::MakeSprite(cloudsprite, footpoint, footvel, 1, 1, 1, .5, .2 * opacity);
1514         } else if (environment == snowyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1515             footvel = velocity / 5;
1516             if (footvel.y < .8)
1517                 footvel.y = .8;
1518             if (which == 0)
1519                 footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
1520             if (which == 1)
1521                 footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
1522             footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1523             terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1524             if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1525                 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7 * opacity);
1526             if (opacity >= 1 || detail == 2)
1527                 if (detail == 2)
1528                     if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1529                         terrain.MakeDecal(footprintdecal, footpoint, .2, 1 * opacity, yaw);
1530         } else if (environment == grassyenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1531             footvel = velocity / 5;
1532             if (footvel.y < .8)
1533                 footvel.y = .8;
1534             if (which == 0)
1535                 footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
1536             if (which == 1)
1537                 footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
1538             footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1539             terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1540             if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1541                 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5 * opacity);
1542         } else if (environment == desertenvironment && onterrain && terrain.getOpacity(coords.x, coords.z) < .2) {
1543             footvel = velocity / 5;
1544             if (footvel.y < .8)
1545                 footvel.y = .8;
1546             if (which == 0)
1547                 footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
1548             if (which == 1)
1549                 footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
1550             footpoint.y = terrain.getHeight(footpoint.x, footpoint.z);
1551             terrainlight = terrain.getLighting(footpoint.x, footpoint.z);
1552             if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1553                 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7 * opacity);
1554             if (opacity >= 1 || detail == 2)
1555                 if (detail == 2)
1556                     if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1557                         terrain.MakeDecal(footprintdecal, footpoint, .2, .25 * opacity, yaw);
1558         } else if (isLanding() || animTarget == jumpupanim || isLandhard()) {
1559             footvel = velocity / 5;
1560             if (footvel.y < .8)
1561                 footvel.y = .8;
1562             if (which == 0)
1563                 footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
1564             if (which == 1)
1565                 footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
1566             //footpoint.y=coords.y;
1567             if (distsq(&footpoint, &viewer) < viewdistance * viewdistance / 4)
1568                 Sprite::MakeSprite(cloudsprite, footpoint, footvel * .6, 1, 1, 1, .5, .2 * opacity);
1569         }
1570 }
1571
1572 void Person::Puff(int whichlabel)
1573 {
1574     static XYZ footvel, footpoint;
1575
1576     footvel = 0;
1577     footpoint = DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position, 0, yaw, 0) * scale + coords;
1578     Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .9, .3);
1579 }
1580
1581 Joint& Person::getJointFor(int bodypart)
1582 {
1583     return skeleton.joints[skeleton.jointlabels[bodypart]];
1584 }
1585
1586 void Person::setAnimation(int animation)
1587 {
1588     animTarget = animation;
1589     frameTarget = 0;
1590     target = 0;
1591 }
1592
1593 void    Person::DoAnimations()
1594 {
1595     if (!skeleton.free) {
1596         int i = 0;
1597         static float oldtarget;
1598
1599         if (isIdle() && animCurrent != getIdle())
1600             normalsupdatedelay = 0;
1601
1602         if (animTarget == tempanim || animCurrent == tempanim) {
1603             animation[tempanim] = tempanimation;
1604         }
1605         if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
1606             float gLoc[3];
1607             float vel[3];
1608             gLoc[0] = coords.x;
1609             gLoc[1] = coords.y;
1610             gLoc[2] = coords.z;
1611             vel[0] = velocity.x;
1612             vel[1] = velocity.y;
1613             vel[2] = velocity.z;
1614
1615             if (id == 0) {
1616                 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1617                 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
1618             }
1619             if (((velocity.y < -15) || (crouchkeydown && velocity.y < -8)) && abs(velocity.y) * 4 > fast_sqrt(velocity.x * velocity.x * velocity.z * velocity.z))
1620                 landhard = 1;
1621             if (!crouchkeydown && velocity.y >= -15)
1622                 landhard = 0;
1623         }
1624         if ((animCurrent == jumpupanim || animTarget == jumpdownanim)/*&&velocity.y<40*/ && !isFlip() && (!isLanding() && !isLandhard()) && ((crouchkeydown && !crouchtogglekeydown))) {
1625             XYZ targfacing;
1626             targfacing = 0;
1627             targfacing.z = 1;
1628
1629             targfacing = DoRotation(targfacing, 0, targetyaw, 0);
1630
1631             if (normaldotproduct(targfacing, velocity) >= -.3)
1632                 animTarget = flipanim;
1633             else
1634                 animTarget = backflipanim;
1635             crouchtogglekeydown = 1;
1636             frameTarget = 0;
1637             target = 0;
1638
1639             if (id == 0)
1640                 numflipped++;
1641         }
1642
1643         if (animation[animTarget].attack != reversed)
1644             feint = 0;
1645         if (!crouchkeydown || (isLanding() || isLandhard()) || (wasLanding() || wasLandhard())) {
1646             crouchtogglekeydown = 0;
1647             if (aitype == playercontrolled)
1648                 feint = 0;
1649         } else {
1650             if (!crouchtogglekeydown && animation[animTarget].attack == reversed && aitype == playercontrolled && (escapednum < 2 || reversaltrain))
1651                 feint = 1;
1652             if (!isFlip())
1653                 crouchtogglekeydown = 1;
1654         }
1655
1656
1657         if (animation[animTarget].attack || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim) {
1658             if (detail)
1659                 normalsupdatedelay = 0;
1660         }
1661
1662         if (target >= 1) {
1663             if (animTarget == rollanim && frameTarget == 3 && onfire) {
1664                 onfire = 0;
1665                 emit_sound_at(fireendsound, coords);
1666                 pause_sound(stream_firesound);
1667                 deathbleeding = 0;
1668             }
1669
1670             if (animTarget == rabbittacklinganim && frameTarget == 1) {
1671                 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->animTarget].attack==neutral&&victim->id!=0)Reverse();
1672                 if (victim->aitype == attacktypecutoff && victim->stunned <= 0 && victim->surprised <= 0 && victim->id != 0)
1673                     Reverse();
1674                 if (animTarget == rabbittacklinganim && frameTarget == 1 && !victim->isCrouch() && victim->animTarget != backhandspringanim) {
1675                     if (normaldotproduct(victim->facing, facing) > 0)
1676                         victim->animTarget = rabbittackledbackanim;
1677                     else
1678                         victim->animTarget = rabbittackledfrontanim;
1679                     victim->frameTarget = 2;
1680                     victim->target = 0;
1681                     victim->yaw = yaw;
1682                     victim->targetyaw = yaw;
1683                     if (victim->aitype == gethelptype)
1684                         victim->DoDamage(victim->damagetolerance - victim->damage);
1685                     //victim->DoDamage(30);
1686                     if (creature == wolftype) {
1687                         DoBloodBig(0, 255);
1688                         emit_sound_at(clawslicesound, victim->coords);
1689                         victim->spurt = 1;
1690                         victim->DoBloodBig(1 / victim->armorhead, 210);
1691                     }
1692                     award_bonus(id, TackleBonus,
1693                                 victim->aitype == gethelptype ? 50 : 0);
1694                 }
1695             }
1696
1697             if (!drawtogglekeydown && drawkeydown && (weaponactive == -1 || num_weapons == 1) && (animation[animTarget].label[frameTarget] || (animTarget != animCurrent && animCurrent == rollanim)) && num_weapons > 0 && creature != wolftype) {
1698                 if (weapons[weaponids[0]].getType() == knife) {
1699                     if (weaponactive == -1)
1700                         weaponactive = 0;
1701                     else if (weaponactive == 0)
1702                         weaponactive = -1;
1703
1704                     if (weaponactive == -1) {
1705                         emit_sound_at(knifesheathesound, coords);
1706                     }
1707                     if (weaponactive != -1) {
1708                         emit_sound_at(knifedrawsound, coords, 128);
1709                     }
1710                 }
1711                 drawtogglekeydown = 1;
1712             }
1713             //Footstep sounds
1714             if (tutoriallevel != 1 || id == 0)
1715                 if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1716                     int whichsound;
1717                     if (onterrain) {
1718                         if (terrain.getOpacity(coords.x, coords.z) < .2) {
1719                             if (animation[animTarget].label[frameTarget] == 1)
1720                                 whichsound = footstepsound;
1721                             else
1722                                 whichsound = footstepsound2;
1723                             if (animation[animTarget].label[frameTarget] == 1)
1724                                 FootLand(0, 1);
1725                             if (animation[animTarget].label[frameTarget] == 2)
1726                                 FootLand(1, 1);
1727                             if (animation[animTarget].label[frameTarget] == 3 && isRun()) {
1728                                 FootLand(1, 1);
1729                                 FootLand(0, 1);
1730                             }
1731
1732                         }
1733                         if (terrain.getOpacity(coords.x, coords.z) >= .2) {
1734                             if (animation[animTarget].label[frameTarget] == 1)
1735                                 whichsound = footstepsound3;
1736                             else
1737                                 whichsound = footstepsound4;
1738                         }
1739                     }
1740                     if (!onterrain) {
1741                         if (animation[animTarget].label[frameTarget] == 1)
1742                             whichsound = footstepsound3;
1743                         else
1744                             whichsound = footstepsound4;
1745                     }
1746                     if (animation[animTarget].label[frameTarget] == 4 && (weaponactive == -1 || (animTarget != knifeslashstartanim && animTarget != knifethrowanim && animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != knifefollowanim))) {
1747                         if (animation[animTarget].attack != neutral) {
1748                             i = abs(Random() % 3);
1749                             if (i == 0)
1750                                 whichsound = lowwhooshsound;
1751                             if (i == 1)
1752                                 whichsound = midwhooshsound;
1753                             if (i == 2)
1754                                 whichsound = highwhooshsound;
1755                         }
1756                         if (animation[animTarget].attack == neutral)
1757                             whichsound = movewhooshsound;
1758                     } else if (animation[animTarget].label[frameTarget] == 4)
1759                         whichsound = knifeswishsound;
1760                     if (animation[animTarget].label[frameTarget] == 8 && tutoriallevel != 1)
1761                         whichsound = landsound2;
1762
1763                     emit_sound_at(whichsound, coords, 256.);
1764
1765                     if (id == 0)
1766                         if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) {
1767                             envsound[numenvsounds] = coords;
1768                             if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim)
1769                                 envsoundvol[numenvsounds] = 15;
1770                             else
1771                                 envsoundvol[numenvsounds] = 6;
1772                             envsoundlife[numenvsounds] = .4;
1773                             numenvsounds++;
1774                         }
1775
1776                     if (animation[animTarget].label[frameTarget] == 3) {
1777                         whichsound--;
1778                         emit_sound_at(whichsound, coords, 128.);
1779                     }
1780                 }
1781
1782             //Combat sounds
1783             if (tutoriallevel != 1 || id == 0)
1784                 if (speechdelay <= 0)
1785                     if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
1786                         if ((animation[animTarget].label[frameTarget] && (animation[animTarget].label[frameTarget] < 5 || animation[animTarget].label[frameTarget] == 8))/*||(animTarget==rollanim&&frameTarget==animation[rollanim].numframes-1)*/) {
1787                             int whichsound = -1;
1788                             if (animation[animTarget].label[frameTarget] == 4 && aitype != playercontrolled) {
1789                                 if (animation[animTarget].attack != neutral) {
1790                                     i = abs(Random() % 4);
1791                                     if (creature == rabbittype) {
1792                                         if (i == 0) whichsound = rabbitattacksound;
1793                                         if (i == 1) whichsound = rabbitattack2sound;
1794                                         if (i == 2) whichsound = rabbitattack3sound;
1795                                         if (i == 3) whichsound = rabbitattack4sound;
1796                                     }
1797                                     if (creature == wolftype) {
1798                                         if (i == 0) whichsound = barksound;
1799                                         if (i == 1) whichsound = bark2sound;
1800                                         if (i == 2) whichsound = bark3sound;
1801                                         if (i == 3) whichsound = barkgrowlsound;
1802                                     }
1803                                     speechdelay = .3;
1804                                 }
1805                                 //if(animation[animTarget].attack==neutral)whichsound=movewhooshsound;
1806                             }
1807                             //else if(animation[animTarget].label[frameTarget]==4)whichsound=knifeswishsound;
1808                             //if(animation[animTarget].label[frameTarget]==8)whichsound=landsound2;
1809
1810                             if (whichsound != -1) {
1811                                 emit_sound_at(whichsound, coords);
1812                             }
1813                         }
1814
1815
1816
1817             if ((!wasLanding() && !wasLandhard()) && animCurrent != getIdle() && (isLanding() || isLandhard())) {
1818                 FootLand(0, 1);
1819                 FootLand(1, 1);
1820             }
1821
1822             transspeed = 0;
1823             currentoffset = targetoffset;
1824             frameTarget = frameCurrent;
1825             animCurrent = animTarget;
1826             frameTarget++;
1827
1828             if (animTarget == removeknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1829                 for (i = 0; i < weapons.size(); i++) {
1830                     if (weapons[i].owner == -1)
1831                         if (distsqflat(&coords, &weapons[i].position) < 4 && weaponactive == -1) {
1832                             if (distsq(&coords, &weapons[i].position) >= 1) {
1833                                 if (weapons[i].getType() != staff) {
1834                                     emit_sound_at(knifedrawsound, coords, 128.);
1835                                 }
1836
1837                                 weaponactive = 0;
1838                                 weapons[i].owner = id;
1839                                 if (num_weapons > 0) {
1840                                     weaponids[num_weapons] = weaponids[0];
1841                                 }
1842                                 num_weapons++;
1843                                 weaponids[0] = i;
1844                             }
1845                         }
1846                 }
1847             }
1848
1849             if (animTarget == crouchremoveknifeanim && animation[animTarget].label[frameCurrent] == 5) {
1850                 for (i = 0; i < weapons.size(); i++) {
1851                     bool willwork = true;
1852                     if (weapons[i].owner != -1)
1853                         if (player[weapons[i].owner].weaponstuck != -1)
1854                             if (player[weapons[i].owner].weaponids[player[weapons[i].owner].weaponstuck] == i)
1855                                 if (player[weapons[i].owner].num_weapons > 1)
1856                                     willwork = 0;
1857                     if ((weapons[i].owner == -1) || (hasvictim && weapons[i].owner == victim->id && victim->skeleton.free))
1858                         if (willwork && distsqflat(&coords, &weapons[i].position) < 3 && weaponactive == -1) {
1859                             if (distsq(&coords, &weapons[i].position) < 1 || hasvictim) {
1860                                 bool fleshstuck = false;
1861                                 if (weapons[i].owner != -1)
1862                                     if (victim->weaponstuck != -1) {
1863                                         if (victim->weaponids[victim->weaponstuck] == i) {
1864                                             fleshstuck = true;
1865                                         }
1866                                     }
1867                                 if (fleshstuck) {
1868                                     emit_sound_at(fleshstabremovesound, coords, 128.);
1869                                 } else {
1870                                     if (weapons[i].getType() != staff) {
1871                                         emit_sound_at(knifedrawsound, coords, 128.);
1872                                     }
1873                                 }
1874                                 weaponactive = 0;
1875                                 if (weapons[i].owner != -1) {
1876
1877                                     victim = &player[weapons[i].owner];
1878                                     if (victim->num_weapons == 1)
1879                                         victim->num_weapons = 0;
1880                                     else
1881                                         victim->num_weapons = 1;
1882
1883                                     //victim->weaponactive=-1;
1884                                     victim->skeleton.longdead = 0;
1885                                     victim->skeleton.free = 1;
1886                                     victim->skeleton.broken = 0;
1887
1888                                     for (int j = 0; j < victim->skeleton.num_joints; j++) {
1889                                         victim->skeleton.joints[j].velchange = 0;
1890                                         victim->skeleton.joints[j].locked = 0;
1891                                     }
1892
1893                                     XYZ relative;
1894                                     relative = 0;
1895                                     relative.y = 10;
1896                                     Normalise(&relative);
1897                                     XYZ footvel, footpoint;
1898                                     footvel = 0;
1899                                     footpoint = weapons[i].position;
1900                                     if (victim->weaponstuck != -1) {
1901                                         if (victim->weaponids[victim->weaponstuck] == i) {
1902                                             if (bloodtoggle)
1903                                                 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
1904                                             weapons[i].bloody = 2;
1905                                             weapons[i].blooddrip = 5;
1906                                             victim->weaponstuck = -1;
1907                                         }
1908                                     }
1909                                     if (victim->num_weapons > 0) {
1910                                         if (victim->weaponstuck != 0 && victim->weaponstuck != -1)
1911                                             victim->weaponstuck = 0;
1912                                         if (victim->weaponids[0] == i)
1913                                             victim->weaponids[0] = victim->weaponids[victim->num_weapons];
1914                                     }
1915
1916                                     victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * 6;
1917                                     victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity += relative * 6;
1918                                     victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity += relative * 6;
1919                                     victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity += relative * 6;
1920                                 }
1921                                 weapons[i].owner = id;
1922                                 if (num_weapons > 0) {
1923                                     weaponids[num_weapons] = weaponids[0];
1924                                 }
1925                                 num_weapons++;
1926                                 weaponids[0] = i;
1927                             }
1928                         }
1929                 }
1930             }
1931
1932             if (animCurrent == drawleftanim && animation[animTarget].label[frameCurrent] == 5) {
1933                 if (weaponactive == -1)
1934                     weaponactive = 0;
1935                 else if (weaponactive == 0) {
1936                     weaponactive = -1;
1937                     if (num_weapons == 2) {
1938                         int buffer;
1939                         buffer = weaponids[0];
1940                         weaponids[0] = weaponids[1];
1941                         weaponids[1] = buffer;
1942                     }
1943                 }
1944                 if (weaponactive == -1) {
1945                     emit_sound_at(knifesheathesound, coords, 128.);
1946                 }
1947                 if (weaponactive != -1) {
1948                     emit_sound_at(knifedrawsound, coords, 128.);
1949                 }
1950             }
1951
1952
1953             if ((animCurrent == walljumprightkickanim && animTarget == walljumprightkickanim) || (animCurrent == walljumpleftkickanim && animTarget == walljumpleftkickanim)) {
1954                 XYZ rotatetarget = DoRotation(skeleton.forward, 0, yaw, 0);
1955                 Normalise(&rotatetarget);
1956                 targetyaw = -asin(0 - rotatetarget.x);
1957                 targetyaw *= 360 / 6.28;
1958                 if (rotatetarget.z < 0)
1959                     targetyaw = 180 - targetyaw;
1960
1961                 if (animTarget == walljumprightkickanim)
1962                     targetyaw += 40;
1963                 if (animTarget == walljumpleftkickanim)
1964                     targetyaw -= 40;
1965             }
1966
1967             bool dojumpattack;
1968             dojumpattack = 0;
1969             if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && frameTarget == 3 && (jumpkeydown || attackkeydown || id != 0))
1970                 dojumpattack = 1;
1971             if (hasvictim)
1972                 if (distsq(&victim->coords, &/*player[i].*/coords) < 5 && victim->aitype == gethelptype && (attackkeydown) && !victim->skeleton.free && victim->isRun() && victim->runninghowlong >= 1)
1973                     dojumpattack = 1;
1974             if (!hostile)
1975                 dojumpattack = 0;
1976             if (dojumpattack) {
1977                 if ((animTarget == rabbitrunninganim || animTarget == wolfrunninganim) && id == 0) {
1978                     animTarget = rabbittackleanim;
1979                     frameTarget = 0;
1980                     emit_sound_at(jumpsound, coords);
1981                 }
1982
1983                 float closestdist;
1984                 closestdist = 0;
1985                 int closestid;
1986                 closestid = -1;
1987                 XYZ targetloc;
1988                 targetloc = velocity;
1989                 Normalise(&targetloc);
1990                 targetloc += coords;
1991                 for (i = 0; i < numplayers; i++) {
1992                     if (i != id)
1993                         if (distsq(&targetloc, &player[i].coords) < closestdist || closestdist == 0) {
1994                             closestdist = distsq(&targetloc, &player[i].coords);
1995                             closestid = i;
1996                         }
1997                 }
1998                 if (closestid != -1)
1999                     if (closestdist < 5 && !player[closestid].dead && animation[player[closestid].animTarget].height != lowheight && player[closestid].animTarget != backhandspringanim) {
2000                         hasvictim = 1;
2001                         victim = &player[closestid];
2002                         coords = victim->coords;
2003                         animCurrent = rabbittacklinganim;
2004                         animTarget = rabbittacklinganim;
2005                         frameCurrent = 0;
2006                         frameTarget = 1;
2007                         XYZ rotatetarget;
2008                         if (coords.z != victim->coords.z || coords.x != victim->coords.x) {
2009                             rotatetarget = coords - victim->coords;
2010                             Normalise(&rotatetarget);
2011                             targetyaw = -asin(0 - rotatetarget.x);
2012                             targetyaw *= 360 / 6.28;
2013                             if (rotatetarget.z < 0)
2014                                 targetyaw = 180 - targetyaw;
2015                         }
2016                         if (animTarget != rabbitrunninganim) {
2017                             emit_sound_at(jumpsound, coords, 128.);
2018                         }
2019                     }
2020             }
2021
2022             //Move impacts
2023             float damagemult = 1 * power;
2024             if (creature == wolftype)
2025                 damagemult = 2.5 * power;
2026             if (hasvictim) {
2027                 damagemult /= victim->damagetolerance / 200;
2028             }
2029             //if(onfire)damagemult=3;
2030             if ((animation[animTarget].attack == normalattack || animTarget == walljumprightkickanim || animTarget == walljumpleftkickanim) && (!feint) && (victim->skeleton.free != 2 || animTarget == killanim || animTarget == dropkickanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == staffgroundsmashanim)) {
2031                 if (animTarget == spinkickanim && animation[animTarget].label[frameCurrent] == 5) {
2032                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2033                         escapednum = 0;
2034                         if (id == 0)
2035                             camerashake += .4;
2036                         if (Random() % 2 || creature == wolftype) {
2037                             victim->spurt = 1;
2038                             DoBlood(.2, 250);
2039                             if (creature == wolftype)
2040                                 DoBloodBig(0, 250);
2041                         }
2042                         if (tutoriallevel != 1) {
2043                             emit_sound_at(heavyimpactsound, victim->coords, 128.);
2044                         }
2045                         if (creature == wolftype) {
2046                             emit_sound_at(clawslicesound, victim->coords, 128.);
2047                             victim->spurt = 1;
2048                             victim->DoBloodBig(2 / victim->armorhead, 175);
2049                         }
2050                         victim->RagDoll(0);
2051                         XYZ relative;
2052                         relative = victim->coords - coords;
2053                         relative.y = 0;
2054                         Normalise(&relative);
2055                         relative = DoRotation(relative, 0, -90, 0);
2056                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2057                             victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2058                         }
2059                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
2060                         //FootLand(1,2);
2061                         victim->Puff(head);
2062                         victim->DoDamage(damagemult * 100 / victim->protectionhead);
2063
2064                         SolidHitBonus(id);
2065                     }
2066                 }
2067
2068                 if (animTarget == wolfslapanim && animation[animTarget].label[frameCurrent] == 5) {
2069                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && 3 && animation[victim->animTarget].height != lowheight) {
2070                         escapednum = 0;
2071                         if (id == 0)
2072                             camerashake += .4;
2073                         if (Random() % 2 || creature == wolftype) {
2074                             victim->spurt = 1;
2075                             if (creature == wolftype)
2076                                 DoBloodBig(0, 235);
2077                         }
2078                         emit_sound_at(whooshhitsound, victim->coords);
2079                         if (creature == wolftype) {
2080                             emit_sound_at(clawslicesound, victim->coords, 128.);
2081                             victim->spurt = 1;
2082                             victim->DoBloodBig(2, 175);
2083                         }
2084                         victim->RagDoll(0);
2085                         XYZ relative;
2086                         relative = victim->coords - coords;
2087                         relative.y = 0;
2088                         Normalise(&relative);
2089                         relative.y -= 1;
2090                         Normalise(&relative);
2091                         relative = DoRotation(relative, 0, 90, 0);
2092                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2093                             victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2094                         }
2095                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 100;
2096                         //FootLand(1,2);
2097                         victim->Puff(head);
2098                         victim->DoDamage(damagemult * 50 / victim->protectionhead);
2099                     }
2100                 }
2101
2102                 if (animTarget == walljumprightkickanim && animation[animTarget].label[frameCurrent] == 5) {
2103                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2104                         escapednum = 0;
2105                         if (id == 0)
2106                             camerashake += .4;
2107                         victim->spurt = 1;
2108                         DoBlood(.2, 250);
2109                         if (tutoriallevel != 1) {
2110                             emit_sound_at(heavyimpactsound, victim->coords, 160.);
2111                         }
2112                         if (creature == wolftype) {
2113                             emit_sound_at(clawslicesound, victim->coords, 128.);
2114                             victim->spurt = 1;
2115                             victim->DoBloodBig(2 / victim->armorhead, 175);
2116                         }
2117                         victim->RagDoll(0);
2118                         XYZ relative;
2119                         relative = facing;
2120                         relative.y = 0;
2121                         Normalise(&relative);
2122                         relative = DoRotation(relative, 0, -90, 0);
2123                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2124                             victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2125                         }
2126                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
2127                         //FootLand(1,2);
2128                         victim->Puff(head);
2129                         victim->DoDamage(damagemult * 150 / victim->protectionhead);
2130
2131                         if (victim->damage > victim->damagetolerance)
2132                             award_bonus(id, style);
2133                         else
2134                             SolidHitBonus(id);
2135                     }
2136                 }
2137
2138                 if (animTarget == walljumpleftkickanim && animation[animTarget].label[frameCurrent] == 5) {
2139                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2140                         escapednum = 0;
2141                         if (id == 0)
2142                             camerashake += .4;
2143                         victim->spurt = 1;
2144                         DoBlood(.2, 250);
2145                         if (tutoriallevel != 1) {
2146                             emit_sound_at(heavyimpactsound, victim->coords, 160.);
2147                         }
2148                         if (creature == wolftype) {
2149                             emit_sound_at(clawslicesound, victim->coords, 128.);
2150                             victim->spurt = 1;
2151                             victim->DoBloodBig(2 / victim->armorhead, 175);
2152                         }
2153                         victim->RagDoll(0);
2154                         XYZ relative;
2155                         relative = facing;
2156                         relative.y = 0;
2157                         Normalise(&relative);
2158                         relative = DoRotation(relative, 0, 90, 0);
2159                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2160                             victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2161                         }
2162                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
2163                         //FootLand(1,2);
2164                         victim->Puff(head);
2165                         victim->DoDamage(damagemult * 150 / victim->protectionhead);
2166
2167                         if (victim->damage > victim->damagetolerance)
2168                             award_bonus(id, style);
2169                         else
2170                             SolidHitBonus(id);
2171                     }
2172                 }
2173
2174                 if (animTarget == blockhighleftstrikeanim && animation[animTarget].label[frameCurrent] == 5) {
2175                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != lowheight) {
2176                         escapednum = 0;
2177                         if (id == 0)
2178                             camerashake += .4;
2179                         if (Random() % 2) {
2180                             victim->spurt = 1;
2181                             DoBlood(.2, 235);
2182                         }
2183                         emit_sound_at(whooshhitsound, victim->coords);
2184                         victim->RagDoll(0);
2185                         XYZ relative;
2186                         relative = victim->coords - coords;
2187                         relative.y = 0;
2188                         Normalise(&relative);
2189                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2190                             victim->skeleton.joints[i].velocity += relative * damagemult * 30;
2191                         }
2192                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 100;
2193                         //FootLand(1,2);
2194                         victim->Puff(head);
2195                         victim->DoDamage(damagemult * 50 / victim->protectionhead);
2196                     }
2197                 }
2198
2199                 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 8) {
2200                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim->dead) {
2201                         escapednum = 0;
2202                         if (id == 0)
2203                             camerashake += .2;
2204                         emit_sound_at(whooshhitsound, victim->coords, 128.);
2205
2206                         victim->skeleton.longdead = 0;
2207                         victim->skeleton.free = 1;
2208                         victim->skeleton.broken = 0;
2209                         victim->skeleton.spinny = 1;
2210
2211                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2212                             victim->skeleton.joints[i].velchange = 0;
2213                             victim->skeleton.joints[i].delay = 0;
2214                             victim->skeleton.joints[i].locked = 0;
2215                             //victim->skeleton.joints[i].velocity=0;
2216                         }
2217
2218                         XYZ relative;
2219                         relative = 0;
2220                         relative.y = 1;
2221                         Normalise(&relative);
2222                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2223                             victim->skeleton.joints[i].velocity.y = relative.y * 10;
2224                             victim->skeleton.joints[i].position.y += relative.y * .3;
2225                             victim->skeleton.joints[i].oldposition.y += relative.y * .3;
2226                             victim->skeleton.joints[i].realoldposition.y += relative.y * .3;
2227                         }
2228                         victim->Puff(abdomen);
2229                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y = relative.y * 400;
2230                     }
2231                 }
2232
2233                 if (animTarget == killanim && animation[animTarget].label[frameCurrent] == 5) {
2234                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->dead) {
2235                         escapednum = 0;
2236                         if (id == 0)
2237                             camerashake += .4;
2238                         if (tutoriallevel != 1) {
2239                             emit_sound_at(heavyimpactsound, coords, 128.);
2240                         }
2241                         XYZ relative;
2242                         relative = victim->coords - coords;
2243                         relative.y = 0;
2244                         Normalise(&relative);
2245                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2246                             victim->skeleton.joints[i].velocity += relative * damagemult * 90;
2247                         }
2248                         victim->Puff(abdomen);
2249                         if (victim->dead != 2 && victim->permanentdamage > victim->damagetolerance - 250 && autoslomo) {
2250                             slomo = 1;
2251                             slomodelay = .2;
2252                         }
2253                         victim->DoDamage(damagemult * 500 / victim->protectionhigh);
2254                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 300;
2255                     }
2256                 }
2257
2258                 if (animTarget == dropkickanim && animation[animTarget].label[frameCurrent] == 7) {
2259                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 9 && victim->skeleton.free) {
2260                         escapednum = 0;
2261                         if (id == 0)
2262                             camerashake += .4;
2263                         if (tutoriallevel != 1) {
2264                             emit_sound_at(thudsound, coords);
2265                         }
2266
2267                         victim->skeleton.longdead = 0;
2268                         victim->skeleton.free = 1;
2269                         victim->skeleton.broken = 0;
2270                         victim->skeleton.spinny = 1;
2271
2272                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2273                             victim->skeleton.joints[i].velchange = 0;
2274                             //victim->skeleton.joints[i].delay=0;
2275                             victim->skeleton.joints[i].locked = 0;
2276                         }
2277                         XYZ relative;
2278                         relative = victim->coords - coords;
2279                         Normalise(&relative);
2280                         relative.y += .3;
2281                         Normalise(&relative);
2282                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2283                             victim->skeleton.joints[i].velocity += relative * damagemult * 20;
2284                         }
2285                         if (!victim->dead)
2286                             SolidHitBonus(id);
2287
2288                         victim->Puff(abdomen);
2289                         victim->DoDamage(damagemult * 20 / victim->protectionhigh);
2290                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
2291                         staggerdelay = .5;
2292                         if (!victim->dead)
2293                             staggerdelay = 1.2;
2294
2295
2296                     }
2297                 }
2298
2299                 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 5) {
2300                     //if(id==0)camerashake+=.4;
2301
2302                     if (hasvictim)
2303                         if (!victim->skeleton.free)
2304                             hasvictim = 0;
2305
2306                     if (!hasvictim) {
2307                         terrain.MakeDecal(blooddecalfast, (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2), .08, .6, Random() % 360);
2308                         emit_sound_at(knifesheathesound, coords, 128.);
2309                     }
2310
2311                     if (victim && hasvictim) {
2312                         if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2313
2314                             XYZ where, startpoint, endpoint, movepoint, colpoint;
2315                             float rotationpoint;
2316                             int whichtri;
2317                             if (weapons[weaponids[weaponactive]].getType() == knife) {
2318                                 where = (weapons[weaponids[weaponactive]].tippoint * .6 + weapons[weaponids[weaponactive]].position * .4);
2319                                 where -= victim->coords;
2320                                 if (!victim->skeleton.free)
2321                                     where = DoRotation(where, 0, -victim->yaw, 0);
2322                                 //where=scale;
2323                                 startpoint = where;
2324                                 startpoint.y += 100;
2325                                 endpoint = where;
2326                                 endpoint.y -= 100;
2327                             }
2328                             if (weapons[weaponids[weaponactive]].getType() == sword) {
2329                                 where = weapons[weaponids[weaponactive]].position;
2330                                 where -= victim->coords;
2331                                 if (!victim->skeleton.free)
2332                                     where = DoRotation(where, 0, -victim->yaw, 0);
2333                                 startpoint = where;
2334                                 where = weapons[weaponids[weaponactive]].tippoint;
2335                                 where -= victim->coords;
2336                                 if (!victim->skeleton.free)
2337                                     where = DoRotation(where, 0, -victim->yaw, 0);
2338                                 endpoint = where;
2339                             }
2340                             if (weapons[weaponids[weaponactive]].getType() == staff) {
2341                                 where = weapons[weaponids[weaponactive]].position;
2342                                 where -= victim->coords;
2343                                 if (!victim->skeleton.free)
2344                                     where = DoRotation(where, 0, -victim->yaw, 0);
2345                                 startpoint = where;
2346                                 where = weapons[weaponids[weaponactive]].tippoint;
2347                                 where -= victim->coords;
2348                                 if (!victim->skeleton.free)
2349                                     where = DoRotation(where, 0, -victim->yaw, 0);
2350                                 endpoint = where;
2351                             }
2352                             movepoint = 0;
2353                             rotationpoint = 0;
2354                             whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &colpoint, &movepoint, &rotationpoint);
2355
2356                             if (whichtri != -1) {
2357                                 if (victim->dead != 2) {
2358                                     victim->DoDamage(abs((victim->damagetolerance - victim->permanentdamage) * 2));
2359                                     if (!victim->dead)
2360                                         award_bonus(id, FinishedBonus);
2361                                 }
2362                                 if (bloodtoggle)
2363                                     weapons[weaponids[weaponactive]].bloody = 2;
2364
2365                                 victim->skeleton.longdead = 0;
2366                                 victim->skeleton.free = 1;
2367                                 victim->skeleton.broken = 0;
2368
2369                                 for (i = 0; i < victim->skeleton.num_joints; i++) {
2370                                     victim->skeleton.joints[i].velchange = 0;
2371                                     victim->skeleton.joints[i].locked = 0;
2372                                     //victim->skeleton.joints[i].velocity=0;
2373                                 }
2374                                 emit_sound_at(fleshstabsound, coords, 128);
2375
2376                             }
2377                             if (whichtri != -1 || weapons[weaponids[weaponactive]].bloody) {
2378                                 weapons[weaponids[weaponactive]].blooddrip += 5;
2379                                 weapons[weaponids[weaponactive]].blooddripdelay = 0;
2380                             }
2381                             if (whichtri == -1) {
2382                                 hasvictim = 0;
2383                                 emit_sound_at(knifesheathesound, coords, 128.);
2384                             }
2385                         }
2386                     }
2387                 }
2388
2389                 if ((animTarget == crouchstabanim || animTarget == swordgroundstabanim) && animation[animTarget].label[frameCurrent] == 6) {
2390                     if (!hasvictim) {
2391                         emit_sound_at(knifedrawsound, coords, 128);
2392                     }
2393
2394                     if (victim && hasvictim) {
2395                         XYZ footvel, footpoint;
2396
2397                         emit_sound_at(fleshstabremovesound, coords, 128.);
2398
2399                         footvel = 0;
2400                         footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2401
2402                         if (weapons[weaponids[weaponactive]].getType() == sword) {
2403                             XYZ where, startpoint, endpoint, movepoint;
2404                             float rotationpoint;
2405                             int whichtri;
2406
2407                             where = weapons[weaponids[weaponactive]].position;
2408                             where -= victim->coords;
2409                             if (!victim->skeleton.free)
2410                                 where = DoRotation(where, 0, -victim->yaw, 0);
2411                             startpoint = where;
2412                             where = weapons[weaponids[weaponactive]].tippoint;
2413                             where -= victim->coords;
2414                             if (!victim->skeleton.free)
2415                                 where = DoRotation(where, 0, -victim->yaw, 0);
2416                             endpoint = where;
2417
2418                             movepoint = 0;
2419                             rotationpoint = 0;
2420                             whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2421                             footpoint += victim->coords;
2422
2423                             if (whichtri == -1) {
2424                                 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2425                             }
2426                         }
2427                         if (weapons[weaponids[weaponactive]].getType() == staff) {
2428                             XYZ where, startpoint, endpoint, movepoint;
2429                             float rotationpoint;
2430                             int whichtri;
2431
2432                             where = weapons[weaponids[weaponactive]].position;
2433                             where -= victim->coords;
2434                             if (!victim->skeleton.free)
2435                                 where = DoRotation(where, 0, -victim->yaw, 0);
2436                             startpoint = where;
2437                             where = weapons[weaponids[weaponactive]].tippoint;
2438                             where -= victim->coords;
2439                             if (!victim->skeleton.free)
2440                                 where = DoRotation(where, 0, -victim->yaw, 0);
2441                             endpoint = where;
2442
2443                             movepoint = 0;
2444                             rotationpoint = 0;
2445                             whichtri = victim->skeleton.drawmodel.LineCheck(&startpoint, &endpoint, &footpoint, &movepoint, &rotationpoint);
2446                             footpoint += victim->coords;
2447
2448                             if (whichtri == -1) {
2449                                 footpoint = (weapons[weaponids[weaponactive]].tippoint * .8 + weapons[weaponids[weaponactive]].position * .2);
2450                             }
2451                         }
2452                         hasvictim = victim->DoBloodBigWhere(2, 220, footpoint);
2453                         if (hasvictim) {
2454                             if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2455                                 victim->skeleton.longdead = 0;
2456                                 victim->skeleton.free = 1;
2457                                 victim->skeleton.broken = 0;
2458
2459                                 for (i = 0; i < victim->skeleton.num_joints; i++) {
2460                                     victim->skeleton.joints[i].velchange = 0;
2461                                     victim->skeleton.joints[i].locked = 0;
2462                                     //victim->skeleton.joints[i].velocity=0;
2463                                 }
2464
2465                                 XYZ relative;
2466                                 relative = 0;
2467                                 relative.y = 10;
2468                                 Normalise(&relative);
2469                                 //victim->Puff(abdomen);
2470                                 if (bloodtoggle)
2471                                     Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .8, .3);
2472
2473                                 if (victim->bloodloss < victim->damagetolerance) {
2474                                     victim->bloodloss += 1000;
2475                                     victim->bled = 0;
2476                                 }
2477
2478                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 20;
2479                             }
2480                         }
2481                     }
2482                     if (!hasvictim && onterrain) {
2483                         weapons[weaponids[weaponactive]].bloody = 0;
2484                         weapons[weaponids[weaponactive]].blooddrip = 0;
2485                     }
2486                 }
2487
2488                 if (animTarget == upunchanim && animation[animTarget].label[frameCurrent] == 5) {
2489                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3) {
2490                         escapednum = 0;
2491                         if (id == 0)
2492                             camerashake += .4;
2493                         if (Random() % 2) {
2494                             victim->spurt = 1;
2495                             DoBlood(.2, 235);
2496                         }
2497                         if (tutoriallevel != 1) {
2498                             emit_sound_at(heavyimpactsound, victim->coords, 128);
2499                         }
2500
2501                         victim->RagDoll(0);
2502                         XYZ relative;
2503                         relative = victim->coords - coords;
2504                         relative.y = 0;
2505                         Normalise(&relative);
2506                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2507                             victim->skeleton.joints[i].velocity = relative * 30;
2508                         }
2509                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 150;
2510
2511                         victim->frameTarget = 0;
2512                         victim->animTarget = staggerbackhardanim;
2513                         victim->targetyaw = targetyaw + 180;
2514                         victim->target = 0;
2515                         victim->stunned = 1;
2516
2517                         victim->Puff(head);
2518                         victim->Puff(abdomen);
2519                         victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2520
2521                         SolidHitBonus(id);
2522                     }
2523                 }
2524
2525
2526                 if (animTarget == winduppunchanim && animation[animTarget].label[frameCurrent] == 5) {
2527                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 2) {
2528                         escapednum = 0;
2529                         if (id == 0)
2530                             camerashake += .4;
2531                         if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height != lowheight) {
2532                             if (tutoriallevel != 1) {
2533                                 emit_sound_at(thudsound, victim->coords);
2534                             }
2535                         } else if (victim->damage <= victim->damagetolerance - 60 && normaldotproduct(victim->facing, victim->coords - coords) < (scale * 5) * (scale * 5) * 0 && animation[victim->animTarget].height == lowheight) {
2536                             if (tutoriallevel != 1) {
2537                                 emit_sound_at(whooshhitsound, victim->coords);
2538                             }
2539                         } else {
2540                             if (tutoriallevel != 1) {
2541                                 emit_sound_at(heavyimpactsound, victim->coords);
2542                             }
2543                         }
2544
2545                         if (victim->damage > victim->damagetolerance - 60 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || animation[victim->animTarget].height == lowheight)
2546                             victim->RagDoll(0);
2547                         XYZ relative;
2548                         relative = victim->coords - coords;
2549                         relative.y = 0;
2550                         Normalise(&relative);
2551                         relative.y = .3;
2552                         Normalise(&relative);
2553                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2554                             victim->skeleton.joints[i].velocity = relative * 5;
2555                         }
2556                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 400;
2557
2558                         victim->frameTarget = 0;
2559                         victim->animTarget = staggerbackhardanim;
2560                         victim->targetyaw = targetyaw + 180;
2561                         victim->target = 0;
2562                         victim->stunned = 1;
2563
2564                         victim->Puff(abdomen);
2565                         victim->DoDamage(damagemult * 60 / victim->protectionhigh);
2566
2567                         SolidHitBonus(id);
2568                     }
2569                 }
2570
2571                 if (animTarget == blockhighleftanim && animation[animTarget].label[frameCurrent] == 5) {
2572                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2573                         if (victim->id == 0)
2574                             camerashake += .4;
2575                         emit_sound_at(landsound2, victim->coords);
2576
2577                         Puff(righthand);
2578                     }
2579                 }
2580
2581                 if (animTarget == swordslashparryanim && animation[animTarget].label[frameCurrent] == 5) {
2582                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4) {
2583                         if (victim->id == 0)
2584                             camerashake += .4;
2585
2586                         if (weaponactive != -1) {
2587                             if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2588                                 if (weapons[victim->weaponids[0]].getType() == staff)
2589                                     weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2590                                 if (weapons[weaponids[0]].getType() == staff)
2591                                     weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2592
2593                                 emit_sound_at(swordstaffsound, victim->coords);
2594                             } else {
2595                                 emit_sound_at(metalhitsound, victim->coords);
2596                             }
2597                         }
2598
2599                         //Puff(righthand);
2600                     }
2601                 }
2602
2603                 if (animTarget == knifethrowanim && animation[animTarget].label[frameCurrent] == 5) {
2604                     if (weaponactive != -1) {
2605                         escapednum = 0;
2606                         XYZ aim;
2607                         weapons[weaponids[0]].owner = -1;
2608                         aim = victim->coords + DoRotation(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position, 0, victim->yaw, 0) * victim->scale + victim->velocity * findDistance(&victim->coords, &coords) / 50 - (coords + DoRotation(skeleton.joints[skeleton.jointlabels[righthand]].position, 0, yaw, 0) * scale);
2609                         Normalise(&aim);
2610                         /*if(victim->animTarget==jumpupanim||victim->animTarget==jumpdownanim){
2611                         aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2612                         }*/
2613                         weapons[weaponids[0]].velocity = aim * 50;
2614                         weapons[weaponids[0]].tipvelocity = aim * 50;
2615                         weapons[weaponids[0]].missed = 0;
2616                         weapons[weaponids[0]].hitsomething = 0;
2617                         weapons[weaponids[0]].freetime = 0;
2618                         weapons[weaponids[0]].firstfree = 1;
2619                         weapons[weaponids[0]].physics = 0;
2620                         num_weapons--;
2621                         if (num_weapons) {
2622                             weaponids[0] = weaponids[num_weapons];
2623                         }
2624                         weaponactive = -1;
2625                     }
2626                 }
2627
2628                 if (animTarget == knifeslashstartanim && animation[animTarget].label[frameCurrent] == 5) {
2629                     if (hasvictim)
2630                         if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 4.5 &&/*animation[victim->animTarget].height!=lowheight&&*/victim->animTarget != dodgebackanim && victim->animTarget != rollanim) {
2631                             escapednum = 0;
2632                             if (tutoriallevel != 1)
2633                                 victim->DoBloodBig(1.5 / victim->armorhigh, 225);
2634
2635                             award_bonus(id, Slicebonus);
2636                             if (tutoriallevel != 1) {
2637                                 emit_sound_at(knifeslicesound, victim->coords);
2638                             }
2639                             //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2640                             if (animation[victim->animTarget].attack && (victim->aitype != playercontrolled || victim->animTarget == knifeslashstartanim) && (victim->creature == rabbittype || victim->deathbleeding <= 0)) {
2641                                 if (victim->id != 0 || difficulty == 2) {
2642                                     victim->frameTarget = 0;
2643                                     victim->animTarget = staggerbackhardanim;
2644                                     victim->targetyaw = targetyaw + 180;
2645                                     victim->target = 0;
2646                                 }
2647                             }
2648                             victim->lowreversaldelay = 0;
2649                             victim->highreversaldelay = 0;
2650                             if (aitype != playercontrolled)
2651                                 weaponmissdelay = .6;
2652
2653                             if (tutoriallevel != 1)
2654                                 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2655                                     weapons[weaponids[weaponactive]].bloody = 1;
2656                             if (tutoriallevel != 1)
2657                                 weapons[weaponids[weaponactive]].blooddrip += 3;
2658
2659                             XYZ footvel, footpoint;
2660                             footvel = 0;
2661                             if (skeleton.free) {
2662                                 footpoint = (victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position + victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position) / 2 * victim->scale + victim->coords;
2663                             }
2664                             if (!skeleton.free) {
2665                                 footpoint = DoRotation((victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position + victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2666                             }
2667                             if (tutoriallevel != 1) {
2668                                 if (bloodtoggle)
2669                                     Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .6, .3);
2670                                 footvel = DoRotation(facing, 0, 90, 0) * .8;
2671                                 //footvel.y-=.3;
2672                                 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2673                                 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2674                                 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
2675                                 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
2676                             }
2677                             if (tutoriallevel == 1) {
2678                                 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 1, 1, .6, .3);
2679                             }
2680                             victim->DoDamage(damagemult * 0);
2681                         }
2682                 }
2683                 if (animTarget == swordslashanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2684                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim) {
2685                         if (victim->weaponactive == -1 || normaldotproduct(victim->facing, victim->coords - coords) > 0 || (Random() % 2 == 0)) {
2686                             award_bonus(id, Slashbonus);
2687                             escapednum = 0;
2688                             if (tutoriallevel != 1) {
2689                                 if (normaldotproduct(victim->facing, victim->coords - coords) < 0)
2690                                     victim->DoBloodBig(2 / victim->armorhigh, 190);
2691                                 else
2692                                     victim->DoBloodBig(2 / victim->armorhigh, 185);
2693                                 victim->deathbleeding = 1;
2694                                 emit_sound_at(swordslicesound, victim->coords);
2695                             }
2696                             //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2697                             if (tutoriallevel != 1) {
2698                                 victim->frameTarget = 0;
2699                                 victim->animTarget = staggerbackhardanim;
2700                                 victim->targetyaw = targetyaw + 180;
2701                                 victim->target = 0;
2702                             }
2703
2704                             if (tutoriallevel != 1) {
2705                                 if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
2706                                     weapons[weaponids[weaponactive]].bloody = 1;
2707                                 weapons[weaponids[weaponactive]].blooddrip += 3;
2708
2709                                 float bloodlossamount;
2710                                 bloodlossamount = 200 + abs((float)(Random() % 40)) - 20;
2711                                 victim->bloodloss += bloodlossamount / victim->armorhigh;
2712                                 //victim->bloodloss+=100*(6.5-distsq(&coords,&victim->coords));
2713                                 victim->DoDamage(damagemult * 0);
2714
2715                                 XYZ footvel, footpoint;
2716                                 footvel = 0;
2717                                 if (skeleton.free) {
2718                                     footpoint = (victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position + victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position) / 2 * victim->scale + victim->coords;
2719                                 }
2720                                 if (!skeleton.free) {
2721                                     footpoint = DoRotation((victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position + victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position) / 2, 0, victim->yaw, 0) * victim->scale + victim->coords;
2722                                 }
2723                                 if (bloodtoggle)
2724                                     Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
2725                                 footvel = DoRotation(facing, 0, 90, 0) * .8;
2726                                 footvel.y -= .3;
2727                                 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2728                                 Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
2729                                 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
2730                                 Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
2731                             }
2732                         } else {
2733                             if (victim->weaponactive != -1) {
2734                                 if (weapons[victim->weaponids[0]].getType() == staff || weapons[weaponids[0]].getType() == staff) {
2735                                     if (weapons[victim->weaponids[0]].getType() == staff)
2736                                         weapons[victim->weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2737                                     if (weapons[weaponids[0]].getType() == staff)
2738                                         weapons[weaponids[0]].damage += .2 + float(abs(Random() % 100) - 50) / 250;
2739
2740                                     emit_sound_at(swordstaffsound, victim->coords);
2741                                 } else {
2742                                     emit_sound_at(metalhitsound, victim->coords);
2743                                 }
2744                             }
2745
2746
2747                             XYZ aim;
2748                             victim->Puff(righthand);
2749                             victim->target = 0;
2750                             victim->frameTarget = 0;
2751                             victim->animTarget = staggerbackhighanim;
2752                             victim->targetyaw = targetyaw + 180;
2753                             victim->target = 0;
2754                             weapons[victim->weaponids[0]].owner = -1;
2755                             aim = DoRotation(facing, 0, 90, 0) * 21;
2756                             aim.y += 7;
2757                             weapons[victim->weaponids[0]].velocity = aim * -.2;
2758                             weapons[victim->weaponids[0]].tipvelocity = aim;
2759                             weapons[victim->weaponids[0]].missed = 1;
2760                             weapons[weaponids[0]].hitsomething = 0;
2761                             weapons[victim->weaponids[0]].freetime = 0;
2762                             weapons[victim->weaponids[0]].firstfree = 1;
2763                             weapons[victim->weaponids[0]].physics = 1;
2764                             victim->num_weapons--;
2765                             if (victim->num_weapons) {
2766                                 victim->weaponids[0] = victim->weaponids[num_weapons];
2767                                 if (victim->weaponstuck == victim->num_weapons)
2768                                     victim->weaponstuck = 0;
2769                             }
2770                             victim->weaponactive = -1;
2771                             for (i = 0; i < numplayers; i++) {
2772                                 player[i].wentforweapon = 0;
2773                             }
2774
2775                         }
2776                     }
2777                 }
2778
2779                 if (animTarget == staffhitanim && 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 += .4 + float(abs(Random() % 100) - 50) / 250;
2783                             escapednum = 0;
2784                             if (id == 0)
2785                                 camerashake += .4;
2786                             if (Random() % 2 || creature == wolftype) {
2787                                 victim->spurt = 1;
2788                             }
2789                             emit_sound_at(staffheadsound, victim->coords);
2790                         }
2791                         victim->RagDoll(0);
2792                         XYZ relative;
2793                         relative = victim->coords - coords;
2794                         relative.y = 0;
2795                         Normalise(&relative);
2796                         relative = DoRotation(relative, 0, 90, 0);
2797                         relative.y -= 1;
2798                         Normalise(&relative);
2799                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2800                             victim->skeleton.joints[i].velocity += relative * damagemult * 60;
2801                         }
2802                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 230;
2803                         victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity += relative * damagemult * 230;
2804                         //FootLand(1,2);
2805                         victim->Puff(head);
2806                         if (tutoriallevel != 1) {
2807                             victim->DoDamage(damagemult * 120 / victim->protectionhigh);
2808
2809                             award_bonus(id, solidhit, 30);
2810                         }
2811                     }
2812                 }
2813
2814                 if (animTarget == staffspinhitanim && animation[animTarget].label[frameCurrent] == 5 && victim->animTarget != rollanim) {
2815                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5 && victim->animTarget != dodgebackanim && victim->animTarget != sweepanim) {
2816                         if (tutoriallevel != 1) {
2817                             weapons[weaponids[0]].damage += .6 + float(abs(Random() % 100) - 50) / 250;
2818                             escapednum = 0;
2819                             if (id == 0)
2820                                 camerashake += .4;
2821                             if (Random() % 2 || creature == wolftype) {
2822                                 victim->spurt = 1;
2823                             }
2824                             emit_sound_at(staffheadsound, victim->coords);
2825                         }
2826                         victim->RagDoll(0);
2827                         XYZ relative;
2828                         relative = victim->coords - coords;
2829                         relative.y = 0;
2830                         Normalise(&relative);
2831                         relative = DoRotation(relative, 0, -90, 0);
2832                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2833                             victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2834                         }
2835                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 220;
2836                         victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity += relative * damagemult * 220;
2837                         //FootLand(1,2);
2838                         victim->Puff(head);
2839                         if (tutoriallevel != 1) {
2840                             victim->DoDamage(damagemult * 350 / victim->protectionhead);
2841
2842                             award_bonus(id, solidhit, 60);
2843                         }
2844                     }
2845                 }
2846
2847                 if (animTarget == staffgroundsmashanim && animation[animTarget].label[frameCurrent] == 5) {
2848                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 6.5) {
2849                         escapednum = 0;
2850                         if (tutoriallevel != 1) {
2851                             if (!victim->dead)
2852                                 weapons[weaponids[0]].damage += .4 + float(abs(Random() % 100) - 50) / 500;
2853                             if (id == 0)
2854                                 camerashake += .4;
2855                             if (Random() % 2 || creature == wolftype) {
2856                                 victim->spurt = 1;
2857                             }
2858                             emit_sound_at(staffbodysound, victim->coords);
2859                         }
2860                         victim->skeleton.longdead = 0;
2861                         victim->skeleton.free = 1;
2862                         victim->skeleton.broken = 0;
2863
2864                         for (i = 0; i < victim->skeleton.num_joints; i++) {
2865                             victim->skeleton.joints[i].velchange = 0;
2866                             victim->skeleton.joints[i].locked = 0;
2867                             //victim->skeleton.joints[i].velocity=0;
2868                         }
2869
2870                         victim->RagDoll(0);
2871                         XYZ relative;
2872                         relative = 0;
2873                         /*relative=victim->coords-coords;
2874                         relative.y=0;
2875                         Normalise(&relative);
2876                         relative=DoRotation(relative,0,90,0);*/
2877                         relative.y = -1;
2878                         Normalise(&relative);
2879                         if (!victim->dead) {
2880                             for (i = 0; i < victim->skeleton.num_joints; i++) {
2881                                 victim->skeleton.joints[i].velocity = relative * damagemult * 40;
2882                             }
2883                             //FootLand(1,2);
2884                             victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 40;
2885                         }
2886                         if (victim->dead) {
2887                             for (i = 0; i < victim->skeleton.num_joints; i++) {
2888                                 victim->skeleton.joints[i].velocity = relative * damagemult * abs(Random() % 20);
2889                             }
2890                             //FootLand(1,2);
2891                             //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2892                         }
2893                         victim->Puff(abdomen);
2894                         if (tutoriallevel != 1) {
2895                             victim->DoDamage(damagemult * 100 / victim->protectionhigh);
2896
2897                             if (!victim->dead) {
2898                                 award_bonus(id, solidhit, 40);
2899                             }
2900                         }
2901                     }
2902                 }
2903
2904                 if (animTarget == lowkickanim && animation[animTarget].label[frameCurrent] == 5) {
2905                     if (distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && animation[victim->animTarget].height != highheight) {
2906                         escapednum = 0;
2907                         if (id == 0)
2908                             camerashake += .4;
2909                         XYZ relative;
2910                         relative = victim->coords - coords;
2911                         relative.y = 0;
2912                         Normalise(&relative);
2913
2914                         SolidHitBonus(id);
2915
2916                         if (animation[victim->animTarget].height == lowheight) {
2917                             if (Random() % 2) {
2918                                 victim->spurt = 1;
2919                                 DoBlood(.2, 250);
2920                             }
2921                             victim->RagDoll(0);
2922                             for (i = 0; i < victim->skeleton.num_joints; i++) {
2923                                 victim->skeleton.joints[i].velocity += relative * damagemult * 40;
2924                             }
2925                             victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
2926                             if (tutoriallevel != 1) {
2927                                 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2928                             }
2929                             victim->Puff(head);
2930                             victim->DoDamage(damagemult * 100 / victim->protectionhead);
2931                             if (victim->howactive == typesleeping)
2932                                 victim->DoDamage(damagemult * 150 / victim->protectionhead);
2933                             if (creature == wolftype) {
2934                                 emit_sound_at(clawslicesound, victim->coords, 128.);
2935                                 victim->spurt = 1;
2936                                 victim->DoBloodBig(2 / victim->armorhead, 175);
2937                             }
2938                         } else {
2939                             if (victim->damage >= victim->damagetolerance)
2940                                 victim->RagDoll(0);
2941                             for (i = 0; i < victim->skeleton.num_joints; i++) {
2942                                 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
2943                             }
2944                             victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
2945                             victim->frameTarget = 0;
2946                             victim->animTarget = staggerbackhighanim;
2947                             victim->targetyaw = targetyaw + 180;
2948                             victim->target = 0;
2949                             if (tutoriallevel != 1) {
2950                                 emit_sound_at(landsound2, victim->coords, 128.);
2951                             }
2952                             victim->Puff(abdomen);
2953                             victim->DoDamage(damagemult * 30 / victim->protectionhigh);
2954                             if (creature == wolftype) {
2955                                 emit_sound_at(clawslicesound, victim->coords, 128.);
2956                                 victim->spurt = 1;
2957                                 victim->DoBloodBig(2 / victim->armorhigh, 170);
2958                             }
2959                         }
2960
2961                     }
2962                 }
2963
2964                 if (animTarget == sweepanim && animation[animTarget].label[frameCurrent] == 5) {
2965                     if (victim->animTarget != jumpupanim && distsq(&coords, &victim->coords) < (scale * 5) * (scale * 5) * 3 && victim != this) {
2966                         escapednum = 0;
2967                         if (id == 0)
2968                             camerashake += .2;
2969                         if (tutoriallevel != 1) {
2970                             emit_sound_at(landsound2, victim->coords, 128.);
2971                         }
2972                         XYZ relative;
2973                         relative = victim->coords - coords;
2974                         relative.y = 0;
2975                         Normalise(&relative);
2976
2977                         if (animation[victim->animTarget].height == middleheight || animation[victim->animCurrent].height == middleheight || victim->damage >= victim->damagetolerance - 40) {
2978                             victim->RagDoll(0);
2979
2980                             for (i = 0; i < victim->skeleton.num_joints; i++) {
2981                                 victim->skeleton.joints[i].velocity += relative * damagemult * 15;
2982                             }
2983                             relative = DoRotation(relative, 0, -90, 0);
2984                             relative.y += .1;
2985                             for (i = 0; i < victim->skeleton.num_joints; i++) {
2986                                 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)
2987                                     victim->skeleton.joints[i].velocity = relative * 80;
2988                             }
2989                             victim->Puff(rightankle);
2990                             victim->Puff(leftankle);
2991                             victim->DoDamage(damagemult * 40 / victim->protectionlow);
2992                         } else {
2993                             if (victim->damage >= victim->damagetolerance)
2994                                 victim->RagDoll(0);
2995                             for (i = 0; i < victim->skeleton.num_joints; i++) {
2996                                 victim->skeleton.joints[i].velocity += relative * damagemult * 10;
2997                             }
2998                             relative = DoRotation(relative, 0, -90, 0);
2999                             for (i = 0; i < victim->skeleton.num_joints; i++) {
3000                                 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)
3001                                     victim->skeleton.joints[i].velocity += relative * damagemult * 80;
3002                             }
3003                             victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
3004                             victim->frameTarget = 0;
3005                             victim->animTarget = staggerbackhighanim;
3006                             victim->targetyaw = targetyaw + 180;
3007                             victim->target = 0;
3008                             if (tutoriallevel != 1) {
3009                                 emit_sound_at(landsound2, victim->coords, 128.);
3010                             }
3011                             victim->Puff(abdomen);
3012                             victim->DoDamage(damagemult * 30 / victim->protectionlow);
3013                         }
3014
3015                         SolidHitBonus(id);
3016
3017                     }
3018                 }
3019             }
3020             if (animation[animTarget].attack == reversal && (!victim->feint || (victim->lastattack == victim->lastattack2 && victim->lastattack2 == victim->lastattack3 && Random() % 2) || animTarget == knifefollowanim)) {
3021                 if (animTarget == spinkickreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3022                     escapednum = 0;
3023                     if (id == 0)
3024                         camerashake += .4;
3025                     if (Random() % 2) {
3026                         victim->spurt = 1;
3027                         DoBlood(.2, 230);
3028                     }
3029                     if (tutoriallevel != 1) {
3030                         emit_sound_at(heavyimpactsound, victim->coords, 128.);
3031                     }
3032                     if (creature == wolftype) {
3033                         emit_sound_at(clawslicesound, victim->coords, 128);
3034                         victim->spurt = 1;
3035                         victim->DoBloodBig(2 / victim->armorhigh, 170);
3036                     }
3037                     victim->RagDoll(0);
3038                     XYZ relative;
3039                     relative = victim->coords - oldcoords;
3040                     relative.y = 0;
3041                     Normalise(&relative);
3042                     //relative=DoRotation(relative,0,-90,0);
3043                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3044                         victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3045                     }
3046                     victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
3047                     //FootLand(1,2);
3048                     victim->Puff(abdomen);
3049                     victim->DoDamage(damagemult * 150 / victim->protectionhigh);
3050
3051                     award_bonus(id, Reversal);
3052                 }
3053
3054                 if ((animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim) && animation[animTarget].label[frameCurrent] == 5) {
3055                     if (victim->weaponactive != -1 && victim->num_weapons > 0) {
3056                         if (weapons[victim->weaponids[victim->weaponactive]].owner == victim->id) {
3057                             weapons[victim->weaponids[victim->weaponactive]].owner = id;
3058                             weaponactive = 0;
3059                             if (num_weapons > 0) {
3060                                 weaponids[num_weapons] = weaponids[victim->weaponactive];
3061                             }
3062                             num_weapons++;
3063                             weaponids[0] = victim->weaponids[victim->weaponactive];
3064                             victim->num_weapons--;
3065                             if (victim->num_weapons > 0) {
3066                                 victim->weaponids[victim->weaponactive] = victim->weaponids[victim->num_weapons];
3067                                 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
3068                             }
3069                             victim->weaponactive = -1;
3070                         }
3071                     }
3072                 }
3073
3074                 if (animTarget == staffhitreversalanim && animation[animTarget].label[frameCurrent] == 5) {
3075                     escapednum = 0;
3076                     if (id == 0)
3077                         camerashake += .4;
3078                     if (Random() % 2) {
3079                         victim->spurt = 1;
3080                         DoBlood(.2, 230);
3081                     }
3082                     emit_sound_at(whooshhitsound, victim->coords, 128.);
3083                     victim->RagDoll(0);
3084                     XYZ relative;
3085                     relative = victim->coords - oldcoords;
3086                     relative.y = 0;
3087                     Normalise(&relative);
3088                     //relative=DoRotation(relative,0,-90,0);
3089                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3090                         victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3091                     }
3092                     victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
3093                     //FootLand(1,2);
3094                     victim->Puff(head);
3095                     victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3096                 }
3097
3098                 if (animTarget == staffspinhitreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3099                     escapednum = 0;
3100                     if (id == 0)
3101                         camerashake += .4;
3102                     if (Random() % 2) {
3103                         victim->spurt = 1;
3104                         DoBlood(.2, 230);
3105                     }
3106
3107                     award_bonus(id, staffreversebonus);
3108
3109                     if (tutoriallevel != 1) {
3110                         emit_sound_at(heavyimpactsound, victim->coords, 128.);
3111                     }
3112                     victim->RagDoll(0);
3113                     award_bonus(id, staffreversebonus); // Huh, again?
3114
3115                     XYZ relative;
3116                     relative = victim->coords - oldcoords;
3117                     relative.y = 0;
3118                     Normalise(&relative);
3119                     //relative=DoRotation(relative,0,-90,0);
3120                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3121                         victim->skeleton.joints[i].velocity += relative * damagemult * 30;
3122                     }
3123                     victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
3124                     //FootLand(1,2);
3125                     victim->Puff(head);
3126                     victim->DoDamage(damagemult * 70 / victim->protectionhigh);
3127                 }
3128
3129                 if (animTarget == upunchreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3130                     escapednum = 0;
3131                     victim->RagDoll(1);
3132                     XYZ relative;
3133                     relative = facing;
3134                     relative.y = 0;
3135                     Normalise(&relative);
3136                     //relative*=-1;
3137                     relative.y -= .1;
3138                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3139                         victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3140                     }
3141                     victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity *= .1;
3142                     victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity *= .2;
3143                     victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity *= .5;
3144                     victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity *= .7;
3145                     victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity *= .1;
3146                     victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity *= .2;
3147                     victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity *= .5;
3148                     victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity *= .7;
3149
3150                     victim->Puff(abdomen);
3151                     victim->DoDamage(damagemult * 90 / victim->protectionhigh);
3152
3153                     award_bonus(id, Reversal);
3154
3155                     bool doslice;
3156                     doslice = 0;
3157                     if (weaponactive != -1 || creature == wolftype)
3158                         doslice = 1;
3159                     if (creature == rabbittype && weaponactive != -1)
3160                         if (weapons[weaponids[0]].getType() == staff)
3161                             doslice = 0;
3162                     if (doslice) {
3163                         if (weaponactive != -1) {
3164                             victim->DoBloodBig(2 / victim->armorhigh, 225);
3165                             emit_sound_at(knifeslicesound, victim->coords);
3166                             if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3167                                 weapons[weaponids[weaponactive]].bloody = 1;
3168                             weapons[weaponids[weaponactive]].blooddrip += 3;
3169                         }
3170                         if (weaponactive == -1 && creature == wolftype) {
3171                             ;
3172                             emit_sound_at(clawslicesound, victim->coords, 128.);
3173                             victim->spurt = 1;
3174                             victim->DoBloodBig(2 / victim->armorhigh, 175);
3175                         }
3176                     }
3177                 }
3178
3179
3180
3181                 if (animTarget == swordslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3182                     escapednum = 0;
3183                     victim->RagDoll(1);
3184                     XYZ relative;
3185                     relative = facing;
3186                     relative.y = 0;
3187                     Normalise(&relative);
3188                     //relative*=-1;
3189                     relative.y -= .1;
3190                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3191                         victim->skeleton.joints[i].velocity += relative * damagemult * 70;
3192                     }
3193                     victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity *= .1 - 1;
3194                     victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity *= .2 - 1;
3195                     victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity *= .5 - 1;
3196                     victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity *= .7 - 1;
3197                     victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity *= .1 - 1;
3198                     victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity *= .2 - 1;
3199                     victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity *= .5 - 1;
3200                     victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity *= .7 - 1;
3201
3202                     award_bonus(id, swordreversebonus);
3203                 }
3204
3205                 if (hasvictim && animTarget == knifeslashreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3206                     escapednum = 0;
3207                     if (id == 0)
3208                         camerashake += .4;
3209                     if (Random() % 2) {
3210                         victim->spurt = 1;
3211                         DoBlood(.2, 230);
3212                     }
3213                     if (tutoriallevel != 1) {
3214                         emit_sound_at(heavyimpactsound, victim->coords, 128.);
3215                     }
3216                     victim->RagDoll(0);
3217                     XYZ relative;
3218                     relative = victim->coords - oldcoords;
3219                     relative.y = 0;
3220                     Normalise(&relative);
3221                     relative = DoRotation(relative, 0, -90, 0);
3222                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3223                         victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3224                     }
3225                     victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity += relative * damagemult * 200;
3226                     //FootLand(1,2);
3227                     victim->Puff(abdomen);
3228                     victim->DoDamage(damagemult * 30 / victim->protectionhigh);
3229
3230                     award_bonus(id, Reversal);
3231                 }
3232
3233                 if (hasvictim && animTarget == sneakattackanim && animation[animTarget].label[frameCurrent] == 7) {
3234                     escapednum = 0;
3235                     victim->RagDoll(0);
3236                     victim->skeleton.spinny = 0;
3237                     XYZ relative;
3238                     relative = facing * -1;
3239                     relative.y = -3;
3240                     Normalise(&relative);
3241                     if (victim->id == 0)
3242                         relative /= 30;
3243                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3244                         victim->skeleton.joints[i].velocity += relative * damagemult * 40;
3245                     }
3246                     //victim->DoDamage(1000);
3247                     victim->damage = victim->damagetolerance;
3248                     victim->permanentdamage = victim->damagetolerance - 1;
3249                     bool doslice;
3250                     doslice = 0;
3251                     if (weaponactive != -1 || creature == wolftype)
3252                         doslice = 1;
3253                     if (creature == rabbittype && weaponactive != -1)
3254                         if (weapons[weaponids[0]].getType() == staff)
3255                             doslice = 0;
3256                     if (doslice) {
3257                         if (weaponactive != -1) {
3258                             victim->DoBloodBig(200, 225);
3259                             emit_sound_at(knifeslicesound, victim->coords);
3260                             if (bloodtoggle)
3261                                 weapons[weaponids[weaponactive]].bloody = 2;
3262                             weapons[weaponids[weaponactive]].blooddrip += 5;
3263                         }
3264
3265                         if (creature == wolftype && weaponactive == -1) {
3266                             emit_sound_at(clawslicesound, victim->coords, 128.);
3267                             victim->spurt = 1;
3268                             victim->DoBloodBig(2, 175);
3269                         }
3270                     }
3271                     award_bonus(id, spinecrusher);
3272                 }
3273
3274                 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3275                     if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3276                         escapednum = 0;
3277                         if (animTarget == knifefollowanim)
3278                             victim->DoBloodBig(200, 210);
3279                         if (animTarget == knifesneakattackanim) {
3280                             /*victim->DoBloodBig(200,195);
3281                             XYZ bloodvel;
3282                             bloodvel=0;
3283                             bloodvel.z=20;
3284                             bloodvel.y=5;
3285                             bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
3286                             Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3287                             */
3288                             XYZ footvel, footpoint;
3289                             footvel = 0;
3290                             footpoint = weapons[weaponids[0]].tippoint;
3291                             if (bloodtoggle)
3292                                 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3293                             footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3294                             Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3295                             Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3296                             Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3297                             Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3298                             victim->DoBloodBig(200, 195);
3299                             award_bonus(id, tracheotomy);
3300                         }
3301                         if (animTarget == knifefollowanim) {
3302                             award_bonus(id, Stabbonus);
3303                             XYZ footvel, footpoint;
3304                             footvel = 0;
3305                             footpoint = weapons[weaponids[0]].tippoint;
3306                             if (bloodtoggle)
3307                                 Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3308                             footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3309                             Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3310                             Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3311                             Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .2, 1);
3312                             Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .2, 1);
3313
3314                         }
3315                         victim->bloodloss += 10000;
3316                         victim->velocity = 0;
3317                         emit_sound_at(fleshstabsound, victim->coords);
3318                         if (bloodtoggle)
3319                             weapons[weaponids[weaponactive]].bloody = 2;
3320                         weapons[weaponids[weaponactive]].blooddrip += 5;
3321                     }
3322                 }
3323
3324                 if (hasvictim && (animTarget == knifefollowanim || animTarget == knifesneakattackanim) && animation[animTarget].label[frameCurrent] == 6) {
3325                     escapednum = 0;
3326                     victim->velocity = 0;
3327                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3328                         victim->skeleton.joints[i].velocity = 0;
3329                     }
3330                     if (animTarget == knifefollowanim) {
3331                         victim->RagDoll(0);
3332                         for (i = 0; i < victim->skeleton.num_joints; i++) {
3333                             victim->skeleton.joints[i].velocity = 0;
3334                         }
3335                     }
3336                     if (weaponactive != -1 && animation[victim->animTarget].attack != reversal) {
3337                         emit_sound_at(fleshstabremovesound, victim->coords);
3338                         if (bloodtoggle)
3339                             weapons[weaponids[weaponactive]].bloody = 2;
3340                         weapons[weaponids[weaponactive]].blooddrip += 5;
3341
3342                         XYZ footvel, footpoint;
3343                         footvel = 0;
3344                         footpoint = weapons[weaponids[0]].tippoint;
3345                         if (bloodtoggle)
3346                             Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3347                         footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3348                         Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3349                         Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3350                         Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3351                         Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3352                     }
3353                 }
3354
3355                 if (hasvictim && (animTarget == swordsneakattackanim) && animation[animTarget].label[frameCurrent] == 5) {
3356                     if (weaponactive != -1 && victim->bloodloss < victim->damagetolerance) {
3357                         award_bonus(id, backstab);
3358
3359                         escapednum = 0;
3360
3361                         XYZ footvel, footpoint;
3362                         footvel = 0;
3363                         footpoint = (weapons[weaponids[0]].tippoint + weapons[weaponids[0]].position) / 2;
3364                         if (bloodtoggle)
3365                             Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3366                         footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position);
3367                         Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3368                         Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3369                         Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 5, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3370                         Sprite::MakeSprite(bloodflamesprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .3, 1);
3371                         victim->DoBloodBig(200, 180);
3372                         victim->DoBloodBig(200, 215);
3373                         victim->bloodloss += 10000;
3374                         victim->velocity = 0;
3375                         emit_sound_at(fleshstabsound, victim->coords);
3376                         if (bloodtoggle)
3377                             weapons[weaponids[weaponactive]].bloody = 2;
3378                         weapons[weaponids[weaponactive]].blooddrip += 5;
3379                     }
3380                 }
3381
3382                 if (hasvictim && animTarget == swordsneakattackanim && animation[animTarget].label[frameCurrent] == 6) {
3383                     escapednum = 0;
3384                     victim->velocity = 0;
3385                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3386                         victim->skeleton.joints[i].velocity = 0;
3387                     }
3388                     if (weaponactive != -1) {
3389                         emit_sound_at(fleshstabremovesound, victim->coords);
3390                         if (bloodtoggle)
3391                             weapons[weaponids[weaponactive]].bloody = 2;
3392                         weapons[weaponids[weaponactive]].blooddrip += 5;
3393
3394                         XYZ footvel, footpoint;
3395                         footvel = 0;
3396                         footpoint = weapons[weaponids[0]].tippoint;
3397                         if (bloodtoggle)
3398                             Sprite::MakeSprite(cloudimpactsprite, footpoint, footvel, 1, 0, 0, .9, .3);
3399                         footvel = (weapons[weaponids[0]].tippoint - weapons[weaponids[0]].position) * -1;
3400                         Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 7, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3401                         Sprite::MakeSprite(bloodsprite, footpoint, DoRotation(footvel * 3, (float)(Random() % 20), (float)(Random() % 20), 0), 1, 1, 1, .05, .9);
3402                         Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 5, 1, 1, 1, .3, 1);
3403                         Sprite::MakeSprite(bloodflamesprite, footpoint, footvel * 2, 1, 1, 1, .3, 1);
3404                     }
3405                 }
3406
3407                 if (animTarget == sweepreversalanim && animation[animTarget].label[frameCurrent] == 7) {
3408                     escapednum = 0;
3409                     if (id == 0)
3410                         camerashake += .4;
3411                     if (Random() % 2) {
3412                         victim->spurt = 1;
3413                         DoBlood(.2, 240);
3414                     }
3415                     if (weaponactive == -1) {
3416                         if (tutoriallevel != 1) {
3417                             emit_sound_at(heavyimpactsound, victim->coords, 128.);
3418                         }
3419                     }
3420                     bool doslice;
3421                     doslice = 0;
3422                     if (weaponactive != -1 || creature == wolftype)
3423                         doslice = 1;
3424                     if (creature == rabbittype && weaponactive != -1)
3425                         if (weapons[weaponids[0]].getType() == staff)
3426                             doslice = 0;
3427                     if (doslice) {
3428                         if (weaponactive != -1) {
3429                             victim->DoBloodBig(2 / victim->armorhead, 225);
3430                             emit_sound_at(knifeslicesound, victim->coords);
3431                             if (bloodtoggle && !weapons[weaponids[weaponactive]].bloody)
3432                                 weapons[weaponids[weaponactive]].bloody = 1;
3433                             weapons[weaponids[weaponactive]].blooddrip += 3;
3434                         }
3435                         if (weaponactive == -1 && creature == wolftype) {
3436                             emit_sound_at(clawslicesound, victim->coords, 128.);
3437                             victim->spurt = 1;
3438                             victim->DoBloodBig(2 / victim->armorhead, 175);
3439                         }
3440                     }
3441
3442                     award_bonus(id, Reversal);
3443
3444                     victim->Puff(neck);
3445
3446                     XYZ relative;
3447                     //relative=victim->coords-oldcoords;
3448                     relative = facing * -1;
3449                     relative.y = 0;
3450                     Normalise(&relative);
3451                     relative = DoRotation(relative, 0, 90, 0);
3452                     relative.y = .5;
3453                     Normalise(&relative);
3454                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3455                         victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3456                     }
3457                     victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
3458                     if (victim->damage < victim->damagetolerance - 100)
3459                         victim->velocity = relative * 200;
3460                     victim->DoDamage(damagemult * 100 / victim->protectionhead);
3461                     victim->velocity = 0;
3462                 }
3463
3464                 if (animTarget == sweepreversalanim && ((animation[animTarget].label[frameCurrent] == 9 && victim->damage < victim->damagetolerance) || (animation[animTarget].label[frameCurrent] == 7 && victim->damage > victim->damagetolerance))) {
3465                     escapednum = 0;
3466                     victim->RagDoll(0);
3467                     XYZ relative;
3468                     //relative=victim->coords-oldcoords;
3469                     relative = facing * -1;
3470                     relative.y = 0;
3471                     Normalise(&relative);
3472                     relative = DoRotation(relative, 0, 90, 0);
3473                     relative.y = .5;
3474                     Normalise(&relative);
3475                     for (i = 0; i < victim->skeleton.num_joints; i++) {
3476                         victim->skeleton.joints[i].velocity += relative * damagemult * 20;
3477                     }
3478                     victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity += relative * damagemult * 200;
3479                 }
3480
3481                 if (hasvictim && (animTarget == spinkickreversalanim || animTarget == sweepreversalanim || animTarget == rabbitkickreversalanim || animTarget == upunchreversalanim || animTarget == jumpreversalanim || animTarget == swordslashreversalanim || animTarget == knifeslashreversalanim || animTarget == rabbittacklereversal || animTarget == wolftacklereversal || animTarget == staffhitreversalanim || animTarget == staffspinhitreversalanim))
3482                     if (victim->damage > victim->damagetolerance && bonus != reverseko) {
3483                         award_bonus(id, reverseko);
3484                     }
3485             }
3486
3487
3488             //Animation end
3489             if (frameTarget > animation[animCurrent].numframes - 1) {
3490                 frameTarget = 0;
3491                 if (wasStop()) {
3492                     animTarget = getIdle();
3493                     FootLand(0, 1);
3494                     FootLand(1, 1);
3495                 }
3496                 if (animCurrent == rabbittackleanim || animCurrent == rabbittacklinganim) {
3497                     animTarget = rollanim;
3498                     frameTarget = 3;
3499                     emit_sound_at(movewhooshsound, coords, 128.);
3500                 }
3501                 if (animCurrent == staggerbackhighanim) {
3502                     animTarget = getIdle();
3503                 }
3504                 if (animCurrent == staggerbackhardanim) {
3505                     animTarget = getIdle();
3506                 }
3507                 if (animCurrent == removeknifeanim) {
3508                     animTarget = getIdle();
3509                 }
3510                 if (animCurrent == crouchremoveknifeanim) {
3511                     animTarget = getCrouch();
3512                 }
3513                 if (animCurrent == backhandspringanim) {
3514                     animTarget = getIdle();
3515                 }
3516                 if (animCurrent == dodgebackanim) {
3517                     animTarget = getIdle();
3518                 }
3519                 if (animCurrent == drawleftanim) {
3520                     animTarget = getIdle();
3521                 }
3522                 if (animCurrent == drawrightanim || animCurrent == crouchdrawrightanim) {
3523                     animTarget = getIdle();
3524                     if (animCurrent == crouchdrawrightanim) {
3525                         animTarget = getCrouch();
3526                     }
3527                     if (weaponactive == -1)
3528                         weaponactive = 0;
3529                     else if (weaponactive == 0) {
3530                         weaponactive = -1;
3531                         if (num_weapons == 2) {
3532                             int buffer;
3533                             buffer = weaponids[0];
3534                             weaponids[0] = weaponids[1];
3535                             weaponids[1] = buffer;
3536                         }
3537                     }
3538
3539                     if (weaponactive == -1) {
3540                         emit_sound_at(knifesheathesound, coords, 128.);
3541                     }
3542                     if (weaponactive != -1) {
3543                         emit_sound_at(knifedrawsound, coords, 128.);
3544                     }
3545                 }
3546                 if (animCurrent == rollanim) {
3547                     animTarget = getCrouch();
3548                     FootLand(0, 1);
3549                     FootLand(1, 1);
3550                 }
3551                 if (isFlip()) {
3552                     if (animTarget == walljumprightkickanim) {
3553                         targetrot = -190;
3554                     }
3555                     if (animTarget == walljumpleftkickanim) {
3556                         targetrot = 190;
3557                     }
3558                     animTarget = jumpdownanim;
3559                 }
3560                 if (animCurrent == climbanim) {
3561                     animTarget = getCrouch();
3562                     frameTarget = 1;
3563                     coords += facing * .1;
3564                     if (!isnormal(coords.x))
3565                         coords = oldcoords;
3566                     oldcoords = coords;
3567                     collided = 0;
3568                     targetoffset = 0;
3569                     currentoffset = 0;
3570                     grabdelay = 1;
3571                     velocity = 0;
3572                     collided = 0;
3573                     avoidcollided = 0;
3574                 }
3575                 if (animTarget == rabbitkickreversalanim) {
3576                     animTarget = getCrouch();
3577                     lastfeint = 0;
3578                 }
3579                 if (animTarget == jumpreversalanim) {
3580                     animTarget = getCrouch();
3581                     lastfeint = 0;
3582                 }
3583                 if (animTarget == walljumprightanim || animTarget == walljumpbackanim || animTarget == walljumpfrontanim) {
3584                     if (attackkeydown && animTarget != walljumpfrontanim) {
3585                         int closest = -1;
3586                         float closestdist = -1;
3587                         float distance;
3588                         if (numplayers > 1)
3589                             for (i = 0; i < numplayers; i++) {
3590                                 if (id != i && player[i].coords.y < coords.y && !player[i].skeleton.free) {
3591                                     distance = distsq(&player[i].coords, &coords);
3592                                     if (closestdist == -1 || distance < closestdist) {
3593                                         closestdist = distance;
3594                                         closest = i;
3595                                     }
3596                                 }
3597                             }
3598                         if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3599                             victim = &player[closest];
3600                             animTarget = walljumprightkickanim;
3601                             frameTarget = 0;
3602                             XYZ rotatetarget = victim->coords - coords;
3603                             Normalise(&rotatetarget);
3604                             yaw = -asin(0 - rotatetarget.x);
3605                             yaw *= 360 / 6.28;
3606                             if (rotatetarget.z < 0)
3607                                 yaw = 180 - yaw;
3608                             targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3609                             velocity = (victim->coords - coords) * 4;
3610                             velocity.y += 2;
3611                             transspeed = 40;
3612                         }
3613                     }
3614                     if (animTarget == walljumpbackanim) {
3615                         animTarget = backflipanim;
3616                         frameTarget = 3;
3617                         velocity = facing * -8;
3618                         velocity.y = 4;
3619                         if (id == 0)
3620                             resume_stream(whooshsound);
3621                     }
3622                     if (animTarget == walljumprightanim) {
3623                         animTarget = rightflipanim;
3624                         frameTarget = 4;
3625                         targetyaw -= 90;
3626                         yaw -= 90;
3627                         velocity = DoRotation(facing, 0, 30, 0) * -8;
3628                         velocity.y = 4;
3629                     }
3630                     if (animTarget == walljumpfrontanim) {
3631                         animTarget = frontflipanim;
3632                         frameTarget = 2;
3633                         //targetyaw-=180;
3634                         ////yaw-=180;
3635                         velocity = facing * 8;
3636                         velocity.y = 4;
3637                     }
3638                     if (id == 0)
3639                         resume_stream(whooshsound);
3640                 }
3641                 if (animTarget == walljumpleftanim) {
3642                     if (attackkeydown) {
3643                         int closest = -1;
3644                         float closestdist = -1;
3645                         float distance;
3646                         if (numplayers > 1)
3647                             for (i = 0; i < numplayers; i++) {
3648                                 if (id != i && player[i].coords.y < coords.y && !player[i].skeleton.free) {
3649                                     distance = distsq(&player[i].coords, &coords);
3650                                     if (closestdist == -1 || distance < closestdist) {
3651                                         closestdist = distance;
3652                                         closest = i;
3653                                     }
3654                                 }
3655                             }
3656                         if (closestdist > 0 && closest >= 0 && closestdist < 16) {
3657                             victim = &player[closest];
3658                             animTarget = walljumpleftkickanim;
3659                             frameTarget = 0;
3660                             XYZ rotatetarget = victim->coords - coords;
3661                             Normalise(&rotatetarget);
3662                             yaw = -asin(0 - rotatetarget.x);
3663                             yaw *= 360 / 6.28;
3664                             if (rotatetarget.z < 0)
3665                                 yaw = 180 - yaw;
3666                             targettilt2 = -asin(rotatetarget.y) * 360 / 6.28;
3667                             velocity = (victim->coords - coords) * 4;
3668                             velocity.y += 2;
3669                             transspeed = 40;
3670                         }
3671                     }
3672                     if (animTarget != walljumpleftkickanim) {
3673                         animTarget = leftflipanim;
3674                         frameTarget = 4;
3675                         targetyaw += 90;
3676                         yaw += 90;
3677                         velocity = DoRotation(facing, 0, -30, 0) * -8;
3678                         velocity.y = 4;
3679                     }
3680                     if (id == 0)
3681                         resume_stream(whooshsound);
3682                 }
3683                 if (animTarget == sneakattackanim) {
3684                     animCurrent = getCrouch();
3685                     animTarget = getCrouch();
3686                     frameTarget = 1;
3687                     frameCurrent = 0;
3688                     targetyaw += 180;
3689                     yaw += 180;
3690                     targettilt2 *= -1;
3691                     tilt2 *= -1;
3692                     transspeed = 1000000;
3693                     targetheadyaw += 180;
3694                     coords -= facing * .7;
3695                     if (onterrain)
3696                         coords.y = terrain.getHeight(coords.x, coords.z);
3697
3698                     lastfeint = 0;
3699                 }
3700                 if (animTarget == knifesneakattackanim || animTarget == swordsneakattackanim) {
3701                     animTarget = getIdle();
3702                     frameTarget = 0;
3703                     if (onterrain)
3704                         coords.y = terrain.getHeight(coords.x, coords.z);
3705
3706                     lastfeint = 0;
3707                 }
3708                 if (animCurrent == knifefollowanim) {
3709                     animTarget = getIdle();
3710                     lastfeint = 0;
3711                 }
3712                 if (animation[animTarget].attack == reversal && animCurrent != sneakattackanim && animCurrent != knifesneakattackanim && animCurrent != swordsneakattackanim && animCurrent != knifefollowanim) {
3713                     float ycoords = oldcoords.y;
3714                     animTarget = getStop();
3715                     targetyaw += 180;
3716                     yaw += 180;
3717                     targettilt2 *= -1;
3718                     tilt2 *= -1;
3719                     transspeed = 1000000;
3720                     targetheadyaw += 180;
3721                     if (!isnormal(coords.x))
3722                         coords = oldcoords;
3723                     if (animCurrent == spinkickreversalanim || animCurrent == swordslashreversalanim)
3724                         oldcoords = coords + facing * .5;
3725                     else if (animCurrent == sweepreversalanim)
3726                         oldcoords = coords + facing * 1.1;
3727                     else if (animCurrent == upunchreversalanim) {
3728                         oldcoords = coords + facing * 1.5;
3729                         targetyaw += 180;
3730                         yaw += 180;
3731                         targetheadyaw += 180;
3732                         targettilt2 *= -1;
3733                         tilt2 *= -1;
3734                     } else if (animCurrent == knifeslashreversalanim) {
3735                         oldcoords = coords + facing * .5;
3736                         targetyaw += 90;
3737                         yaw += 90;
3738                         targetheadyaw += 90;
3739                         targettilt2 = 0;
3740                         tilt2 = 0;
3741                     } else if (animCurrent == staffspinhitreversalanim) {
3742                         targetyaw += 180;
3743                         yaw += 180;
3744                         targetheadyaw += 180;
3745                         targettilt2 = 0;
3746                         tilt2 = 0;
3747                     }
3748                     if (onterrain)
3749                         oldcoords.y = terrain.getHeight(oldcoords.x, oldcoords.z);
3750                     else
3751                         oldcoords.y = ycoords;
3752                     currentoffset = coords - oldcoords;
3753                     targetoffset = 0;
3754                     coords = oldcoords;
3755
3756                     lastfeint = 0;
3757                 }
3758                 if (animCurrent == knifesneakattackedanim || animCurrent == swordsneakattackedanim) {
3759                     velocity = 0;
3760                     velocity.y = -5;
3761                     RagDoll(0);
3762                 }
3763                 if (animation[animTarget].attack == reversed) {
3764                     escapednum++;
3765                     if (animTarget == sweepreversedanim)
3766                         targetyaw += 90;
3767                     animTarget = backhandspringanim;
3768                     frameTarget = 2;
3769                     emit_sound_at(landsound, coords, 128);
3770
3771                     if (animCurrent == upunchreversedanim || animCurrent == swordslashreversedanim) {
3772                         animTarget = rollanim;
3773                         frameTarget = 5;
3774                         oldcoords = coords;
3775                         coords += (DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) + DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0)) / 2 * scale;
3776                         coords.y = oldcoords.y;
3777                     }
3778                     if (animCurrent == knifeslashreversedanim) {
3779                         animTarget = rollanim;
3780                         frameTarget = 0;
3781                         targetyaw += 90;
3782                         yaw += 90;
3783                         oldcoords = coords;
3784                         coords += (DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) + DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0)) / 2 * scale;
3785                         coords.y = oldcoords.y;
3786                     }
3787                 }
3788                 if (wasFlip()) {
3789                     animTarget = jumpdownanim;
3790                 }
3791                 if (wasLanding())
3792                     animTarget = getIdle();
3793                 if (wasLandhard())
3794                     animTarget = getIdle();
3795                 if (animCurrent == spinkickanim || animCurrent == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == lowkickanim) {
3796                     animTarget = getIdle();
3797                     oldcoords = coords;
3798                     coords += (DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) + DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0)) / 2 * scale;
3799                     coords.y = oldcoords.y;
3800                     //coords+=DoRotation(animation[animCurrent].offset,0,yaw,0)*scale;
3801                     targetoffset.y = coords.y;
3802                     if (onterrain)
3803                         targetoffset.y = terrain.getHeight(coords.x, coords.z);
3804                     currentoffset = DoRotation(animation[animCurrent].offset * -1, 0, yaw, 0) * scale;
3805                     currentoffset.y -= (coords.y - targetoffset.y);
3806                     coords.y = targetoffset.y;
3807                     targetoffset = 0;
3808                     normalsupdatedelay = 0;
3809                 }
3810                 if (animCurrent == upunchanim) {
3811                     animTarget = getStop();
3812                     normalsupdatedelay = 0;
3813                     lastfeint = 0;
3814                 }
3815                 if (animCurrent == rabbitkickanim && animTarget != backflipanim) {
3816                     targetyaw = yaw;
3817                     bool hasstaff;
3818                     hasstaff = 0;
3819                     if (num_weapons > 0)
3820                         if (weapons[0].getType() == staff)
3821                             hasstaff = 1;
3822                     if (!hasstaff)
3823                         DoDamage(35);
3824                     RagDoll(0);
3825                     lastfeint = 0;
3826                     rabbitkickragdoll = 1;
3827                 }
3828                 if (animCurrent == rabbitkickreversedanim) {
3829                     if (!feint) {
3830                         velocity = 0;
3831                         velocity.y = -10;
3832                         //DoDamage(100);
3833                         RagDoll(0);
3834                         skeleton.spinny = 0;
3835                         SolidHitBonus(!id); // FIXME: tricky id
3836                     }
3837                     if (feint) {
3838                         escapednum++;
3839                         animTarget = rollanim;
3840                         coords += facing;
3841                         if (id == 0)
3842                             pause_sound(whooshsound);
3843                     }
3844                     lastfeint = 0;
3845                 }
3846                 if (animCurrent == rabbittackledbackanim || animCurrent == rabbittackledfrontanim) {
3847                     velocity = 0;
3848                     velocity.y = -10;
3849                     RagDoll(0);
3850                     skeleton.spinny = 0;
3851                 }
3852                 if (animCurrent == jumpreversedanim) {
3853                     if (!feint) {
3854                         velocity = 0;
3855                         velocity.y = -10;
3856                         //DoDamage(100);
3857                         RagDoll(0);
3858                         skeleton.spinny = 0;
3859                         SolidHitBonus(!id); // FIXME: tricky id
3860                     }
3861                     if (feint) {
3862                         escapednum++;
3863                         animTarget = rollanim;
3864                         coords += facing * 2;
3865                         if (id == 0)
3866                             pause_sound(whooshsound);
3867                     }
3868                     lastfeint = 0;
3869                 }
3870
3871                 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) {
3872                     animTarget = getupfromfrontanim;
3873                     lastfeint = 0;
3874                 } else if (animation[animCurrent].attack == normalattack) {
3875                     animTarget = getIdle();
3876                     lastfeint = 0;
3877                 }
3878                 if (animCurrent == blockhighleftanim && aitype != playercontrolled) {
3879                     animTarget = blockhighleftstrikeanim;
3880                 }
3881                 if (animCurrent == knifeslashstartanim || animCurrent == knifethrowanim || animCurrent == swordslashanim || animCurrent == staffhitanim || animCurrent == staffgroundsmashanim || animCurrent == staffspinhitanim) {
3882                     animTarget = getIdle();
3883                     lastfeint = 0;
3884                 }
3885                 if (animCurrent == spinkickanim && victim->skeleton.free) {
3886                     if (creature == rabbittype)
3887                         animTarget = fightidleanim;
3888                 }
3889             }
3890             target = 0;
3891
3892             if (isIdle() && !wasIdle())
3893                 normalsupdatedelay = 0;
3894
3895             if (animCurrent == jumpupanim && velocity.y < 0 && !isFlip()) {
3896                 animTarget = jumpdownanim;
3897             }
3898         }
3899         if (!skeleton.free) {
3900             oldtarget = target;
3901             if (!transspeed && animation[animTarget].attack != 2 && animation[animTarget].attack != 3) {
3902                 if (!isRun() || !wasRun()) {
3903                     if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
3904                         target += multiplier * animation[animTarget].speed[frameTarget] * speed * 2;
3905                     if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
3906                         target += multiplier * animation[animCurrent].speed[frameCurrent] * speed * 2;
3907                 }
3908                 if (isRun() && wasRun()) {
3909                     float tempspeed;
3910                     tempspeed = velspeed;
3911                     if (tempspeed < 10 * speedmult)
3912                         tempspeed = 10 * speedmult;
3913                     target += multiplier * animation[animTarget].speed[frameCurrent] * speed * 1.7 * tempspeed / (speed * 45 * scale);
3914                 }
3915             } else if (transspeed)
3916                 target += multiplier * transspeed * speed * 2;
3917             else {
3918                 if (!isRun() || !wasRun()) {
3919                     if (animation[animTarget].speed[frameTarget] > animation[animCurrent].speed[frameCurrent])
3920                         target += multiplier * animation[animTarget].speed[frameTarget] * 2;
3921                     if (animation[animTarget].speed[frameTarget] <= animation[animCurrent].speed[frameCurrent])
3922                         target += multiplier * animation[animCurrent].speed[frameCurrent] * 2;
3923                 }
3924             }
3925
3926             if (animCurrent != animTarget)
3927                 target = (target + oldtarget) / 2;
3928
3929             if (target > 1) {
3930                 frameCurrent = frameTarget;
3931                 target = 1;
3932             }
3933             oldrot = rot;
3934             rot = targetrot * target;
3935             yaw += rot - oldrot;
3936             if (target == 1) {
3937                 rot = 0;
3938                 oldrot = 0;
3939                 targetrot = 0;
3940             }
3941             if (animCurrent != oldanimCurrent || animTarget != oldanimTarget || ((frameCurrent != oldframeCurrent || frameTarget != oldframeTarget) && !calcrot)) {
3942                 //Old rotates
3943                 for (i = 0; i < skeleton.num_joints; i++) {
3944                     skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent];
3945                 }
3946
3947                 skeleton.FindForwards();
3948
3949                 for (i = 0; i < skeleton.num_muscles; i++) {
3950                     if (skeleton.muscles[i].visible) {
3951                         skeleton.FindRotationMuscle(i, animTarget);
3952                     }
3953                 }
3954                 for (i = 0; i < skeleton.num_muscles; i++) {
3955                     if (skeleton.muscles[i].visible) {
3956                         if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
3957                             skeleton.muscles[i].oldrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
3958                         if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
3959                             skeleton.muscles[i].oldrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
3960                         if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
3961                             skeleton.muscles[i].oldrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
3962                     }
3963                 }
3964
3965                 //New rotates
3966                 for (i = 0; i < skeleton.num_joints; i++) {
3967                     skeleton.joints[i].position = animation[animTarget].position[i][frameTarget];
3968                 }
3969
3970                 skeleton.FindForwards();
3971
3972                 for (i = 0; i < skeleton.num_muscles; i++) {
3973                     if (skeleton.muscles[i].visible) {
3974                         skeleton.FindRotationMuscle(i, animTarget);
3975                     }
3976                 }
3977                 for (i = 0; i < skeleton.num_muscles; i++) {
3978                     if (skeleton.muscles[i].visible) {
3979                         if (isnormal((float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100))
3980                             skeleton.muscles[i].newrotate1 = (float)((int)(skeleton.muscles[i].rotate1 * 100) % 36000) / 100;
3981                         if (isnormal((float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100))
3982                             skeleton.muscles[i].newrotate2 = (float)((int)(skeleton.muscles[i].rotate2 * 100) % 36000) / 100;
3983                         if (isnormal((float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100))
3984                             skeleton.muscles[i].newrotate3 = (float)((int)(skeleton.muscles[i].rotate3 * 100) % 36000) / 100;
3985                         if (skeleton.muscles[i].newrotate3 > skeleton.muscles[i].oldrotate3 + 180) skeleton.muscles[i].newrotate3 -= 360;
3986                         if (skeleton.muscles[i].newrotate3 < skeleton.muscles[i].oldrotate3 - 180) skeleton.muscles[i].newrotate3 += 360;
3987                         if (skeleton.muscles[i].newrotate2 > skeleton.muscles[i].oldrotate2 + 180) skeleton.muscles[i].newrotate2 -= 360;
3988                         if (skeleton.muscles[i].newrotate2 < skeleton.muscles[i].oldrotate2 - 180) skeleton.muscles[i].newrotate2 += 360;
3989                         if (skeleton.muscles[i].newrotate1 > skeleton.muscles[i].oldrotate1 + 180) skeleton.muscles[i].newrotate1 -= 360;
3990                         if (skeleton.muscles[i].newrotate1 < skeleton.muscles[i].oldrotate1 - 180) skeleton.muscles[i].newrotate1 += 360;
3991                     }
3992                 }
3993             }
3994             if (frameCurrent >= animation[animCurrent].numframes)
3995                 frameCurrent = animation[animCurrent].numframes - 1;
3996
3997             oldanimCurrent = animCurrent;
3998             oldanimTarget = animTarget;
3999             oldframeTarget = frameTarget;
4000             oldframeCurrent = frameCurrent;
4001
4002             for (i = 0; i < skeleton.num_joints; i++) {
4003                 skeleton.joints[i].velocity = (animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target) - skeleton.joints[i].position) / multiplier;
4004                 skeleton.joints[i].position = animation[animCurrent].position[i][frameCurrent] * (1 - target) + animation[animTarget].position[i][frameTarget] * (target);
4005             }
4006             offset = currentoffset * (1 - target) + targetoffset * target;
4007             for (i = 0; i < skeleton.num_muscles; i++) {
4008                 if (skeleton.muscles[i].visible) {
4009                     skeleton.muscles[i].rotate1 = skeleton.muscles[i].oldrotate1 * (1 - target) + skeleton.muscles[i].newrotate1 * (target);
4010                     skeleton.muscles[i].rotate2 = skeleton.muscles[i].oldrotate2 * (1 - target) + skeleton.muscles[i].newrotate2 * (target);
4011                     skeleton.muscles[i].rotate3 = skeleton.muscles[i].oldrotate3 * (1 - target) + skeleton.muscles[i].newrotate3 * (target);
4012                 }
4013             }
4014         }
4015
4016         if (isLanding() && landhard) {
4017             if (id == 0)
4018                 camerashake += .4;
4019             animTarget = getLandhard();
4020             frameTarget = 0;
4021             target = 0;
4022             landhard = 0;
4023             transspeed = 15;
4024         }
4025     }
4026     //skeleton.DoConstraints();
4027 }
4028
4029 void    Person::DoStuff()
4030 {
4031     static XYZ terrainnormal;
4032     static XYZ flatfacing;
4033     static XYZ flatvelocity;
4034     static float flatvelspeed;
4035     static int i, j, l;
4036     static XYZ average;
4037     static int howmany;
4038     static int bloodsize;
4039     static int startx, starty, endx, endy;
4040     static GLubyte color;
4041     static XYZ bloodvel;
4042
4043     onfiredelay -= multiplier;
4044     if (onfiredelay < 0 && onfire) {
4045         if (Random() % 2 == 0) {
4046             crouchkeydown = 1;
4047         }
4048         onfiredelay = 0.3;
4049     }
4050
4051     crouchkeydowntime += multiplier;
4052     if (!crouchkeydown)
4053         crouchkeydowntime = 0;
4054     jumpkeydowntime += multiplier;
4055     if (!jumpkeydown && skeleton.free)
4056         jumpkeydowntime = 0;
4057
4058     if (hostile || damage > 0 || bloodloss > 0)
4059         immobile = 0;
4060
4061     if (isIdle() || isRun())
4062         targetoffset = 0;
4063
4064     if (num_weapons == 1 && weaponactive != -1)
4065         weaponstuck = -1;
4066
4067     if (id == 0)
4068         blooddimamount -= multiplier * .3;
4069     speechdelay -= multiplier;
4070     texupdatedelay -= multiplier;
4071     interestdelay -= multiplier;
4072     flamedelay -= multiplier;
4073     parriedrecently -= multiplier;
4074     if (!victim) {
4075         victim = this;
4076         hasvictim = 0;
4077     }
4078
4079     if (id == 0)
4080         speed = 1.1 * speedmult;
4081     else
4082         speed = 1.0 * speedmult;
4083     if (!skeleton.free)
4084         rabbitkickragdoll = 0;
4085
4086     speed *= speedmult;
4087
4088     if (id != 0 && (creature == rabbittype || difficulty != 2))
4089         superruntoggle = 0;
4090     if (id != 0 && creature == wolftype && difficulty == 2) {
4091         superruntoggle = 0;
4092         if (aitype != passivetype) {
4093             superruntoggle = 1;
4094             if (aitype == attacktypecutoff && (player[0].isIdle() || player[0].isCrouch() || player[0].skeleton.free || player[0].animTarget == getupfrombackanim || player[0].animTarget == getupfromfrontanim || player[0].animTarget == sneakanim) && distsq(&coords, &player[0].coords) < 16) {
4095                 superruntoggle = 0;
4096             }
4097         }
4098         if (scale < 0.2)
4099             superruntoggle = 0;
4100         if (animTarget == wolfrunninganim && !superruntoggle) {
4101             animTarget = getRun();
4102             frameTarget = 0;
4103         }
4104     }
4105     if (weaponactive == -1 && num_weapons > 0) {
4106         if (weapons[weaponids[0]].getType() == staff) {
4107             weaponactive = 0;
4108         }
4109     }
4110
4111     if (onfire) {
4112         burnt += multiplier;
4113         /*if(aitype!=playercontrolled)*///deathbleeding=5;
4114         /*if(aitype!=playercontrolled)*/
4115         deathbleeding = 1;
4116         if (burnt > .6)
4117             burnt = .6;
4118         OPENAL_SetVolume(channels[stream_firesound], 256 + 256 * findLength(&velocity) / 3);
4119
4120         if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
4121             float gLoc[3];
4122             float vel[3];
4123             gLoc[0] = coords.x;
4124             gLoc[1] = coords.y;
4125             gLoc[2] = coords.z;
4126             vel[0] = velocity.x;
4127             vel[1] = velocity.y;
4128             vel[2] = velocity.z;
4129
4130             if (id == 0) {
4131                 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4132                 OPENAL_SetVolume(channels[whooshsound], 64 * findLength(&velocity) / 5);
4133             }
4134         }
4135     }
4136     while (flamedelay < 0 && onfire) {
4137         flamedelay += .006;
4138         howmany = abs(Random() % (skeleton.num_joints));
4139         if (!skeleton.free)
4140             flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4141         if (skeleton.free)
4142             flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4143         if (!skeleton.free)
4144             flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4145         if (skeleton.free)
4146             flatfacing = skeleton.joints[howmany].position * scale + coords;
4147         Sprite::MakeSprite(flamesprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, 1);
4148     }
4149
4150     while (flamedelay < 0 && !onfire && tutoriallevel == 1 && id != 0) {
4151         flamedelay += .05;
4152         howmany = abs(Random() % (skeleton.num_joints));
4153         if (!skeleton.free)
4154             flatvelocity = (coords - oldcoords) / multiplier / 2; //velocity/2;
4155         if (skeleton.free)
4156             flatvelocity = skeleton.joints[howmany].velocity * scale / 2;
4157         if (!skeleton.free)
4158             flatfacing = DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position, 0, 0, tilt), tilt2, 0, 0), 0, yaw, 0) * scale + coords;
4159         if (skeleton.free)
4160             flatfacing = skeleton.joints[howmany].position * scale + coords;
4161         Sprite::MakeSprite(breathsprite, flatfacing, flatvelocity, 1, 1, 1, .6 + (float)abs(Random() % 100) / 200 - .25, .3);
4162     }
4163
4164     if (bleeding > 0) {
4165         bleeding -= multiplier * .3;
4166         if (bloodtoggle == 2) {
4167             skeleton.drawmodel.textureptr.bind();
4168             if (bleeding <= 0 && (detail != 2 || osx))
4169                 DoMipmaps();
4170         }
4171     }
4172
4173     if (neckspurtamount > 0) {
4174         neckspurtamount -= multiplier;
4175         neckspurtdelay -= multiplier * 3;
4176         neckspurtparticledelay -= multiplier * 3;
4177         if (neckspurtparticledelay < 0 && neckspurtdelay > 2) {
4178             spurt = 0;
4179             bloodvel = 0;
4180             if (!skeleton.free) {
4181                 bloodvel.z = 5 * neckspurtamount;
4182                 bloodvel = DoRotation(bloodvel, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4183             }
4184             if (skeleton.free) {
4185                 bloodvel -= DoRotation(skeleton.forward * 10 * scale, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0);
4186             }
4187             if (skeleton.free)
4188                 bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity, ((float)(Random() % 100)) / 40, yaw + ((float)(Random() % 100)) / 40, 0) * scale;
4189             if (!skeleton.free)
4190                 bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 40, ((float)(Random() % 100)) / 40, 0) * scale;
4191             if (skeleton.free)
4192                 Sprite::MakeSprite(bloodsprite, (skeleton.joints[skeleton.jointlabels[neck]].position + (skeleton.joints[skeleton.jointlabels[neck]].position - skeleton.joints[skeleton.jointlabels[head]].position) / 5)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4193             if (!skeleton.free)
4194                 Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position + (skeleton.joints[skeleton.jointlabels[neck]].position - skeleton.joints[skeleton.jointlabels[head]].position) / 5, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, .9);
4195             neckspurtparticledelay = .05;
4196         }
4197         if (neckspurtdelay < 0) {
4198             neckspurtdelay = 3;
4199         }
4200     }
4201
4202     if (deathbleeding > 0 && dead != 2) {
4203         if (deathbleeding < 5)
4204             bleeddelay -= deathbleeding * multiplier / 4;
4205         else
4206             bleeddelay -= 5 * multiplier / 4;
4207         if (bleeddelay < 0 && bloodtoggle) {
4208             bleeddelay = 1;
4209             XYZ bloodvel;
4210             if (bloodtoggle) {
4211                 bloodvel = 0;
4212                 if (skeleton.free)
4213                     bloodvel += DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity, ((float)(Random() % 100)) / 4, yaw + ((float)(Random() % 100)) / 4, 0) * scale;
4214                 if (!skeleton.free)
4215                     bloodvel += DoRotation(velocity, ((float)(Random() % 100)) / 4, ((float)(Random() % 100)) / 4, 0) * scale;
4216                 if (skeleton.free)
4217                     Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position * scale + coords, bloodvel, 1, 1, 1, .05, 1);
4218                 if (!skeleton.free)
4219                     Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[abdomen]].position + skeleton.joints[skeleton.jointlabels[abdomen]].position) / 2, 0, yaw, 0)*scale + coords, bloodvel, 1, 1, 1, .05, 1);
4220             }
4221         }
4222         bloodloss += deathbleeding * multiplier * 80;
4223         deathbleeding -= multiplier * 1.6;
4224         //if(id==0)deathbleeding-=multiplier*.2;
4225         if (deathbleeding < 0)
4226             deathbleeding = 0;
4227         if (bloodloss > damagetolerance && animation[animTarget].attack == neutral) {
4228             if (weaponactive != -1) {
4229                 weapons[weaponids[0]].owner = -1;
4230                 weapons[weaponids[0]].velocity = velocity * scale * -.3;
4231                 weapons[weaponids[0]].velocity.x += .01;
4232                 weapons[weaponids[0]].tipvelocity = velocity * scale;
4233                 weapons[weaponids[0]].missed = 1;
4234                 weapons[weaponids[0]].hitsomething = 0;
4235                 weapons[weaponids[0]].freetime = 0;
4236                 weapons[weaponids[0]].firstfree = 1;
4237                 weapons[weaponids[0]].physics = 1;
4238                 num_weapons--;
4239                 if (num_weapons) {
4240                     weaponids[0] = weaponids[num_weapons];
4241                     if (weaponstuck == num_weapons)
4242                         weaponstuck = 0;
4243                 }
4244                 weaponactive = -1;
4245                 for (i = 0; i < numplayers; i++) {
4246                     player[i].wentforweapon = 0;
4247                 }
4248
4249                 if (id == 0) {
4250                     flashamount = .5;
4251                     flashr = 1;
4252                     flashg = 0;
4253                     flashb = 0;
4254                     flashdelay = 0;
4255                 }
4256             }
4257
4258             if (!dead && creature == wolftype) {
4259                 award_bonus(0, Wolfbonus);
4260             }
4261             dead = 2;
4262             if (animTarget == knifefollowedanim && !skeleton.free) {
4263                 for (i = 0; i < skeleton.num_joints; i++) {
4264                     skeleton.joints[i].velocity = 0;
4265                     skeleton.joints[i].velocity.y = -2;
4266                 }
4267             }
4268             if (id != 0 && unconscioustime > .1) {
4269                 numafterkill++;
4270             }
4271
4272             RagDoll(0);
4273         }
4274     }
4275
4276     if (texupdatedelay < 0 && bleeding > 0 && bloodtoggle == 2 && distsq(&viewer, &coords) < 9) {
4277         texupdatedelay = .12;
4278
4279         bloodsize = 5 - realtexdetail;
4280
4281         startx = 0;
4282         starty = 0;
4283         startx = bleedy; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4284         starty = bleedx; //abs(Random()%(skeleton.skinsize-bloodsize-1));
4285         endx = startx + bloodsize;
4286         endy = starty + bloodsize;
4287
4288         if (startx < 0) {
4289             startx = 0;
4290             bleeding = 0;
4291         }
4292         if (starty < 0) {
4293             starty = 0;
4294             bleeding = 0;
4295         }
4296         if (endx > skeleton.skinsize - 1) {
4297             endx = skeleton.skinsize - 1;
4298             bleeding = 0;
4299         }
4300         if (endy > skeleton.skinsize - 1) {
4301             endy = skeleton.skinsize - 1;
4302             bleeding = 0;
4303         }
4304         if (endx < startx)
4305             endx = startx;
4306         if (endy < starty)
4307             endy = starty;
4308
4309         for (i = startx; i < endx; i++) {
4310             for (j = starty; j < endy; j++) {
4311                 if (Random() % 2 == 0) {
4312                     color = Random() % 85 + 170;
4313                     if (skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] > color / 2)
4314                         skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 0] = color / 2;
4315                     skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 1] = 0;
4316                     skeleton.skinText[i * skeleton.skinsize * 3 + j * 3 + 2] = 0;
4317                 }
4318             }
4319         }
4320         if (!osx && detail > 1) {
4321             skeleton.drawmodel.textureptr.bind();
4322             DoMipmaps();
4323         }
4324
4325         if (!skeleton.free) {
4326             bleedy -= 4 / realtexdetail;
4327             if (detail == 2)
4328                 bleedx += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4329             else
4330                 bleedx += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4331         }
4332         if (skeleton.free) {
4333             bleedx += 4 * direction / realtexdetail;
4334             if (detail == 2)
4335                 bleedy += (abs(Random() % 3) - 1) * 2 / realtexdetail;
4336             else
4337                 bleedy += (abs(Random() % 3) - 1) * 4 / realtexdetail;
4338         }
4339     }
4340
4341     if (abs(righthandmorphness - targetrighthandmorphness) < multiplier * 4) {
4342         righthandmorphness = targetrighthandmorphness;
4343         righthandmorphstart = righthandmorphend;
4344     } else if (righthandmorphness > targetrighthandmorphness) {
4345         righthandmorphness -= multiplier * 4;
4346     } else if (righthandmorphness < targetrighthandmorphness) {
4347         righthandmorphness += multiplier * 4;
4348     }
4349
4350     if (abs(lefthandmorphness - targetlefthandmorphness) < multiplier * 4) {
4351         lefthandmorphness = targetlefthandmorphness;
4352         lefthandmorphstart = lefthandmorphend;
4353     } else if (lefthandmorphness > targetlefthandmorphness) {
4354         lefthandmorphness -= multiplier * 4;
4355     } else if (lefthandmorphness < targetlefthandmorphness) {
4356         lefthandmorphness += multiplier * 4;
4357     }
4358
4359     if (creature == rabbittype || targettailmorphness == 5 || targettailmorphness == 0) {
4360         if (abs(tailmorphness - targettailmorphness) < multiplier * 10) {
4361             tailmorphness = targettailmorphness;
4362             tailmorphstart = tailmorphend;
4363         } else if (tailmorphness > targettailmorphness) {
4364             tailmorphness -= multiplier * 10;
4365         } else if (tailmorphness < targettailmorphness) {
4366             tailmorphness += multiplier * 10;
4367         }
4368     }
4369
4370     if (creature == wolftype) {
4371         if (abs(tailmorphness - targettailmorphness) < multiplier * 4) {
4372             tailmorphness = targettailmorphness;
4373             tailmorphstart = tailmorphend;
4374         } else if (tailmorphness > targettailmorphness) {
4375             tailmorphness -= multiplier * 2;
4376         } else if (tailmorphness < targettailmorphness) {
4377             tailmorphness += multiplier * 2;
4378         }
4379     }
4380
4381     if (headmorphend == 3 || headmorphstart == 3) {
4382         if (abs(headmorphness - targetheadmorphness) < multiplier * 7) {
4383             headmorphness = targetheadmorphness;
4384             headmorphstart = headmorphend;
4385         } else if (headmorphness > targetheadmorphness) {
4386             headmorphness -= multiplier * 7;
4387         } else if (headmorphness < targetheadmorphness) {
4388             headmorphness += multiplier * 7;
4389         }
4390     } else if (headmorphend == 5 || headmorphstart == 5) {
4391         if (abs(headmorphness - targetheadmorphness) < multiplier * 10) {
4392             headmorphness = targetheadmorphness;
4393             headmorphstart = headmorphend;
4394         } else if (headmorphness > targetheadmorphness) {
4395             headmorphness -= multiplier * 10;
4396         } else if (headmorphness < targetheadmorphness) {
4397             headmorphness += multiplier * 10;
4398         }
4399     } else {
4400         if (abs(headmorphness - targetheadmorphness) < multiplier * 4) {
4401             headmorphness = targetheadmorphness;
4402             headmorphstart = headmorphend;
4403         } else if (headmorphness > targetheadmorphness) {
4404             headmorphness -= multiplier * 4;
4405         } else if (headmorphness < targetheadmorphness) {
4406             headmorphness += multiplier * 4;
4407         }
4408     }
4409
4410     if (abs(chestmorphness - targetchestmorphness) < multiplier) {
4411         chestmorphness = targetchestmorphness;
4412         chestmorphstart = chestmorphend;
4413     } else if (chestmorphness > targetchestmorphness) {
4414         chestmorphness -= multiplier;
4415     } else if (chestmorphness < targetchestmorphness) {
4416         chestmorphness += multiplier;
4417     }
4418
4419     if (dead != 2 && howactive <= typesleeping) {
4420         if (chestmorphstart == 0 && chestmorphend == 0) {
4421             chestmorphness = 0;
4422             targetchestmorphness = 1;
4423             chestmorphend = 3;
4424         }
4425         if (chestmorphstart != 0 && chestmorphend != 0) {
4426             chestmorphness = 0;
4427             targetchestmorphness = 1;
4428             chestmorphend = 0;
4429             if (environment == snowyenvironment) {
4430                 XYZ footpoint;
4431                 XYZ footvel;
4432                 if (!skeleton.free)
4433                     footvel = DoRotation(skeleton.specialforward[0], 0, yaw, 0) * -1;
4434                 if (skeleton.free)
4435                     footvel = skeleton.specialforward[0] * -1;
4436                 if (!skeleton.free)
4437                     footpoint = DoRotation((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2, 0, yaw, 0) * scale + coords;
4438                 if (skeleton.free)
4439                     footpoint = ((skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2) * scale + coords;
4440                 if (animTarget == sleepanim)
4441                     footvel = DoRotation(footvel, 0, 90, 0);
4442                 Sprite::MakeSprite(breathsprite, footpoint + footvel * .2, footvel * .4, 1, 1, 1, .4, .3);
4443             }
4444         }
4445
4446         if (!dead && howactive < typesleeping) {
4447             blinkdelay -= multiplier * 2;
4448             if (headmorphstart == 0 && headmorphend == 0 && blinkdelay <= 0) {
4449                 headmorphness = 0;
4450                 targetheadmorphness = 1;
4451                 headmorphend = 3;
4452                 blinkdelay = (float)(abs(Random() % 40)) / 5;
4453             }
4454             if (headmorphstart == 3 && headmorphend == 3) {
4455                 headmorphness = 0;
4456                 targetheadmorphness = 1;
4457                 headmorphend = 0;
4458             }
4459         }
4460         if (!dead) {
4461             twitchdelay -= multiplier * 1.5;
4462             if (animTarget != hurtidleanim) {
4463                 if (headmorphstart == 0 && headmorphend == 0 && twitchdelay <= 0) {
4464                     headmorphness = 0;
4465                     targetheadmorphness = 1;
4466                     headmorphend = 5;
4467                     twitchdelay = (float)(abs(Random() % 40)) / 5;
4468                 }
4469                 if (headmorphstart == 5 && headmorphend == 5) {
4470                     headmorphness = 0;
4471                     targetheadmorphness = 1;
4472                     headmorphend = 0;
4473                 }
4474             }
4475             if ((isIdle() || isCrouch()) && animTarget != hurtidleanim) {
4476                 twitchdelay3 -= multiplier * 1;
4477                 if (Random() % 2 == 0) {
4478                     if (righthandmorphstart == 0 && righthandmorphend == 0 && twitchdelay3 <= 0) {
4479                         righthandmorphness = 0;
4480                         targetrighthandmorphness = 1;
4481                         righthandmorphend = 1;
4482                         if (Random() % 2 == 0)twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4483                     }
4484                     if (righthandmorphstart == 1 && righthandmorphend == 1) {
4485                         righthandmorphness = 0;
4486                         targetrighthandmorphness = 1;
4487                         righthandmorphend = 0;
4488                     }
4489                 }
4490                 if (Random() % 2 == 0) {
4491                     if (lefthandmorphstart == 0 && lefthandmorphend == 0 && twitchdelay3 <= 0) {
4492                         lefthandmorphness = 0;
4493                         targetlefthandmorphness = 1;
4494                         lefthandmorphend = 1;
4495                         twitchdelay3 = (float)(abs(Random() % 40)) / 5;
4496                     }
4497                     if (lefthandmorphstart == 1 && lefthandmorphend == 1) {
4498                         lefthandmorphness = 0;
4499                         targetlefthandmorphness = 1;
4500                         lefthandmorphend = 0;
4501                     }
4502                 }
4503             }
4504         }
4505         if (!dead) {
4506             if (creature == rabbittype) {
4507                 if (howactive < typesleeping)
4508                     twitchdelay2 -= multiplier * 1.5;
4509                 else
4510                     twitchdelay2 -= multiplier * 0.5;
4511                 if (howactive <= typesleeping) {
4512                     if (tailmorphstart == 0 && tailmorphend == 0 && twitchdelay2 <= 0) {
4513                         tailmorphness = 0;
4514                         targettailmorphness = 1;
4515                         tailmorphend = 1;
4516                         twitchdelay2 = (float)(abs(Random() % 40)) / 5;
4517                     }
4518                     if (tailmorphstart == 1 && tailmorphend == 1) {
4519                         tailmorphness = 0;
4520                         targettailmorphness = 1;
4521                         tailmorphend = 2;
4522                     }
4523                     if (tailmorphstart == 2 && tailmorphend == 2) {
4524                         tailmorphness = 0;
4525                         targettailmorphness = 1;
4526                         tailmorphend = 0;
4527                     }
4528                 }
4529             }
4530         }
4531     }
4532     if (creature == wolftype) {
4533         twitchdelay2 -= multiplier * 1.5;
4534         if (tailmorphend != 0)
4535             if ((isRun() || animTarget == jumpupanim || animTarget == jumpdownanim || animTarget == backflipanim) && !skeleton.free) {
4536                 tailmorphness = 0;
4537                 targettailmorphness = 1;
4538                 tailmorphend = 0;
4539                 twitchdelay2 = .1;
4540             }
4541         if (tailmorphend != 5)
4542             if (animTarget == flipanim || animTarget == frontflipanim || animTarget == rollanim || skeleton.free) {
4543                 tailmorphness = 0;
4544                 targettailmorphness = 1;
4545                 tailmorphend = 5;
4546                 twitchdelay2 = .1;
4547             }
4548         if (twitchdelay2 <= 0) {
4549             if (((tailmorphstart == 0 && tailmorphend == 0) || (tailmorphstart == 5 && tailmorphend == 5))) {
4550                 tailmorphness = 0;
4551                 targettailmorphness = 1;
4552                 tailmorphend = 1;
4553             }
4554             if (tailmorphstart == 1 && tailmorphend == 1) {
4555                 tailmorphness = 0;
4556                 targettailmorphness = 1;
4557                 tailmorphend = 2;
4558             }
4559             if (tailmorphstart == 2 && tailmorphend == 2) {
4560                 tailmorphness = 0;
4561                 targettailmorphness = 1;
4562                 tailmorphend = 3;
4563             }
4564             if (tailmorphstart == 3 && tailmorphend == 3) {
4565                 tailmorphness = 0;
4566                 targettailmorphness = 1;
4567                 tailmorphend = 4;
4568             }
4569             if (tailmorphstart == 4 && tailmorphend == 4) {
4570                 tailmorphness = 0;
4571                 targettailmorphness = 1;
4572                 tailmorphend = 1;
4573             }
4574         }
4575     }
4576
4577     if (dead != 1)
4578         unconscioustime = 0;
4579
4580     if (dead == 1 || howactive == typesleeping) {
4581         unconscioustime += multiplier;
4582         //If unconscious, close eyes and mouth
4583         if (righthandmorphend != 0)
4584             righthandmorphness = 0;
4585         righthandmorphend = 0;
4586         targetrighthandmorphness = 1;
4587
4588         if (lefthandmorphend != 0)
4589             lefthandmorphness = 0;
4590         lefthandmorphend = 0;
4591         targetlefthandmorphness = 1;
4592
4593         if (headmorphend != 3 && headmorphend != 5)
4594             headmorphness = 0;
4595         headmorphend = 3;
4596         targetheadmorphness = 1;
4597     }
4598
4599
4600     if (howactive > typesleeping) {
4601         XYZ headpoint;
4602         headpoint = coords;
4603         if (bloodtoggle && !bled) {
4604             terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4605         }
4606         if (bloodtoggle && !bled)
4607             for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4608                 j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4609                 XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4610                 float size = .8;
4611                 float opacity = .6;
4612                 float yaw = 0;
4613                 objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4614             }
4615         bled = 1;
4616     }
4617
4618     if (dead == 2 || howactive > typesleeping) {
4619         //If dead, open mouth and hands
4620         if (righthandmorphend != 0)
4621             righthandmorphness = 0;
4622         righthandmorphend = 0;
4623         targetrighthandmorphness = 1;
4624
4625         if (lefthandmorphend != 0)
4626             lefthandmorphness = 0;
4627         lefthandmorphend = 0;
4628         targetlefthandmorphness = 1;
4629
4630         if (headmorphend != 2)
4631             headmorphness = 0;
4632         headmorphend = 2;
4633         targetheadmorphness = 1;
4634     }
4635
4636     if (stunned > 0 && !dead && headmorphend != 2) {
4637         if (headmorphend != 4)
4638             headmorphness = 0;
4639         headmorphend = 4;
4640         targetheadmorphness = 1;
4641     }
4642
4643     if (damage > damagetolerance && !dead) {
4644
4645         dead = 1;
4646         unconscioustime = 0;
4647
4648         if (creature == wolftype) {
4649             award_bonus(0, Wolfbonus);
4650         }
4651
4652         RagDoll(0);
4653
4654         if (weaponactive != -1) {
4655             weapons[weaponids[0]].owner = -1;
4656             weapons[weaponids[0]].velocity = velocity * scale * -.3;
4657             weapons[weaponids[0]].velocity.x += .01;
4658             weapons[weaponids[0]].tipvelocity = velocity * scale;
4659             weapons[weaponids[0]].missed = 1;
4660             weapons[weaponids[0]].hitsomething = 0;
4661             weapons[weaponids[0]].freetime = 0;
4662             weapons[weaponids[0]].firstfree = 1;
4663             weapons[weaponids[0]].physics = 1;
4664             num_weapons--;
4665             if (num_weapons) {
4666                 weaponids[0] = weaponids[num_weapons];
4667                 if (weaponstuck == num_weapons)
4668                     weaponstuck = 0;
4669             }
4670             weaponactive = -1;
4671             for (i = 0; i < numplayers; i++) {
4672                 player[i].wentforweapon = 0;
4673             }
4674         }
4675
4676
4677
4678         if ((id == 0 || distsq(&coords, &viewer) < 50) && autoslomo) {
4679             slomo = 1;
4680             slomodelay = .2;
4681         }
4682
4683         damage += 20;
4684     }
4685
4686     //if(dead)damage-=multiplier/4;
4687     if (!dead)
4688         damage -= multiplier * 13;
4689     //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4690     if (!dead)
4691         permanentdamage -= multiplier * 4;
4692     if (isIdle() || isCrouch()) {
4693         if (!dead)
4694             permanentdamage -= multiplier * 4;
4695         //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4696     }
4697     if (damage < 0)
4698         damage = 0;
4699     if (permanentdamage < 0)
4700         permanentdamage = 0;
4701     if (superpermanentdamage < 0)
4702         superpermanentdamage = 0;
4703     if (permanentdamage < superpermanentdamage) {
4704         permanentdamage = superpermanentdamage;
4705     }
4706     if (damage < permanentdamage) {
4707         damage = permanentdamage;
4708     }
4709     if (dead == 1 && damage < damagetolerance) {
4710         dead = 0;
4711         skeleton.free = 1;
4712         damage -= 20;
4713         for (i = 0; i < skeleton.num_joints; i++) {
4714             skeleton.joints[i].velocity = 0;
4715         }
4716     }
4717     if (permanentdamage > damagetolerance && dead != 2) {
4718         DoBlood(1, 255);
4719
4720         if (weaponactive != -1) {
4721             weapons[weaponids[0]].owner = -1;
4722             weapons[weaponids[0]].velocity = velocity * scale * -.3;
4723             weapons[weaponids[0]].velocity.x += .01;
4724             weapons[weaponids[0]].tipvelocity = velocity * scale;
4725             weapons[weaponids[0]].missed = 1;
4726             weapons[weaponids[0]].hitsomething = 0;
4727             weapons[weaponids[0]].freetime = 0;
4728             weapons[weaponids[0]].firstfree = 1;
4729             weapons[weaponids[0]].physics = 1;
4730             num_weapons--;
4731             if (num_weapons) {
4732                 weaponids[0] = weaponids[num_weapons];
4733                 if (weaponstuck == num_weapons)
4734                     weaponstuck = 0;
4735             }
4736             weaponactive = -1;
4737             for (i = 0; i < numplayers; i++) {
4738                 player[i].wentforweapon = 0;
4739             }
4740         }
4741
4742         bled = 0;
4743
4744         if (!dead && creature == wolftype) {
4745             award_bonus(0, Wolfbonus);
4746         }
4747
4748         if (unconscioustime < .1 && (bonus != spinecrusher || bonustime > 1) && (bonus != FinishedBonus || bonustime > 1) && bloodloss < damagetolerance)
4749             award_bonus(id, touchofdeath);
4750         if (id != 0 && unconscioustime > .1) {
4751             numafterkill++;
4752         }
4753
4754         dead = 2;
4755
4756         skeleton.free = 1;
4757
4758         emit_sound_at(breaksound, coords);
4759     }
4760
4761     if (skeleton.free == 1) {
4762         if (id == 0)
4763             pause_sound(whooshsound);
4764
4765         if (!dead) {
4766             //If knocked over, open hands and close mouth
4767             if (righthandmorphend != 0)
4768                 righthandmorphness = 0;
4769             righthandmorphend = 0;
4770             targetrighthandmorphness = 1;
4771
4772             if (lefthandmorphend != 0)
4773                 lefthandmorphness = 0;
4774             lefthandmorphend = 0;
4775             targetlefthandmorphness = 1;
4776
4777             if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5) {
4778                 if (headmorphend != 0)
4779                     headmorphness = 0;
4780                 headmorphend = 0;
4781                 targetheadmorphness = 1;
4782             }
4783         }
4784
4785         skeleton.DoGravity(&scale);
4786         float damageamount;
4787         damageamount = skeleton.DoConstraints(&coords, &scale) * 5;
4788         if (damage > damagetolerance - damageamount && !dead && (bonus != spinecrusher || bonustime > 1) && (bonus != style || bonustime > 1) && (bonus != cannon || bonustime > 1))
4789             award_bonus(id, deepimpact);
4790         DoDamage(damageamount / ((protectionhigh + protectionhead + protectionlow) / 3));
4791
4792         average = 0;
4793         howmany = 0;
4794         for (j = 0; j < skeleton.num_joints; j++) {
4795             average += skeleton.joints[j].position;
4796             howmany++;
4797         }
4798         average /= howmany;
4799         coords += average * scale;
4800         for (j = 0; j < skeleton.num_joints; j++) {
4801             skeleton.joints[j].position -= average;
4802         }
4803         average /= multiplier;
4804
4805         //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
4806         velocity = 0;
4807         for (i = 0; i < skeleton.num_joints; i++) {
4808             velocity += skeleton.joints[i].velocity * scale;
4809         }
4810         velocity /= skeleton.num_joints;
4811
4812         if (!isnormal(velocity.x) && velocity.x) {
4813             velocity = 0;
4814         }
4815
4816         if (findLength(&average) < 10 && dead && skeleton.free) {
4817             skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
4818             if (skeleton.longdead > 2000) {
4819                 if (skeleton.longdead > 6000) {
4820                     if (id == 0)
4821                         pause_sound(whooshsound);
4822                     skeleton.free = 3;
4823                     DrawSkeleton();
4824                     skeleton.free = 2;
4825                 }
4826                 if (dead == 2 && bloodloss < damagetolerance) {
4827                     XYZ headpoint;
4828                     headpoint = (skeleton.joints[skeleton.jointlabels[head]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2 * scale + coords;
4829                     DoBlood(1, 255);
4830                     if (bloodtoggle && !bled) {
4831                         terrain.MakeDecal(blooddecal, headpoint, .2 * 1.2, .5, 0);
4832                     }
4833                     if (bloodtoggle && !bled)
4834                         for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4835                             j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4836                             XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4837                             float size = .2 * 1.2;
4838                             float opacity = .6;
4839                             float yaw = 0;
4840                             objects.model[j].MakeDecal(blooddecal, &point, &size, &opacity, &yaw);
4841                         }
4842                     bled = 1;
4843                 }
4844                 if (dead == 2 && bloodloss >= damagetolerance) {
4845                     XYZ headpoint;
4846                     headpoint = (skeleton.joints[skeleton.jointlabels[abdomen]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2 * scale + coords;
4847                     if (bleeding <= 0)
4848                         DoBlood(1, 255);
4849                     if (bloodtoggle && !bled) {
4850                         terrain.MakeDecal(blooddecalslow, headpoint, .8, .5, 0);
4851                     }
4852                     if (bloodtoggle && !bled)
4853                         for (l = 0; l < terrain.patchobjectnum[whichpatchx][whichpatchz]; l++) {
4854                             j = terrain.patchobjects[whichpatchx][whichpatchz][l];
4855                             XYZ point = DoRotation(headpoint - objects.position[j], 0, -objects.yaw[j], 0);
4856                             float size = .8;
4857                             float opacity = .6;
4858                             float yaw = 0;
4859                             objects.model[j].MakeDecal(blooddecalslow, &point, &size, &opacity, &yaw);
4860                         }
4861                     bled = 1;
4862                 }
4863             }
4864         }
4865
4866         if (!dead && crouchkeydown && skeleton.freetime > .5 && id == 0 && skeleton.free) {
4867             bool canrecover = 1;
4868             XYZ startpoint, endpoint, colpoint, colviewer, coltarget;
4869             startpoint = coords;
4870             endpoint = coords;
4871             endpoint.y -= .7;
4872             if (terrain.lineTerrain(startpoint, endpoint, &colpoint) != -1)
4873                 canrecover = 0;
4874             if (velocity.y < -30)
4875                 canrecover = 0;
4876             for (i = 0; i < objects.numobjects; i++) {
4877                 if (objects.type[i] != treeleavestype && objects.type[i] != bushtype && objects.type[i] != firetype) {
4878                     colviewer = startpoint;
4879                     coltarget = endpoint;
4880                     if (objects.model[i].LineCheck(&colviewer, &coltarget, &colpoint, &objects.position[i], &objects.yaw[i]) != -1)
4881                         canrecover = 0;
4882                 }
4883             }
4884             if (canrecover) {
4885                 skeleton.free = 0;
4886                 XYZ middle;
4887                 middle = 0;
4888
4889                 terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[abdomen]].position;
4890                 if (skeleton.joints[skeleton.jointlabels[groin]].locked && skeleton.joints[skeleton.jointlabels[abdomen]].locked) {
4891                     terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[abdomen]].position;
4892                     middle = (skeleton.joints[skeleton.jointlabels[groin]].position + skeleton.joints[skeleton.jointlabels[abdomen]].position) / 2;
4893                 }
4894                 if (skeleton.joints[skeleton.jointlabels[abdomen]].locked && skeleton.joints[skeleton.jointlabels[neck]].locked) {
4895                     terrainnormal = skeleton.joints[skeleton.jointlabels[abdomen]].position - skeleton.joints[skeleton.jointlabels[neck]].position;
4896                     middle = (skeleton.joints[skeleton.jointlabels[neck]].position + skeleton.joints[skeleton.jointlabels[abdomen]].position) / 2;
4897                 }
4898                 if (skeleton.joints[skeleton.jointlabels[groin]].locked && skeleton.joints[skeleton.jointlabels[neck]].locked) {
4899                     terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[neck]].position;
4900                     middle = (skeleton.joints[skeleton.jointlabels[groin]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2;
4901                 }
4902                 Normalise(&terrainnormal);
4903
4904                 targetyaw = -asin(0 - terrainnormal.x);
4905                 targetyaw *= 360 / 6.28;
4906                 if (terrainnormal.z < 0)
4907                     targetyaw = 180 - targetyaw;
4908                 yaw = targetyaw;
4909
4910                 frameTarget = 0;
4911                 //      frameTarget=2;
4912                 animTarget = flipanim;
4913                 crouchtogglekeydown = 1;
4914                 target = 0;
4915                 tilt2 = 0;
4916                 targettilt2 = 0;
4917
4918                 animCurrent = tempanim;
4919                 frameCurrent = 0;
4920                 target = 0;
4921                 //tilt2=targettilt2;
4922
4923                 //if(middle.y>0)targetoffset.y=middle.y+1;
4924
4925                 for (i = 0; i < skeleton.num_joints; i++) {
4926                     tempanimation.position[i][0] = skeleton.joints[i].position;
4927                     tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
4928                 }
4929             }
4930         }
4931
4932         if (findLength(&average) < 10 && !dead && skeleton.free) {
4933             skeleton.longdead += (2000 - findLength(&average)) * multiplier + multiplier;
4934             if (skeleton.longdead > (damage + 500) * 1.5) {
4935                 if (id == 0)
4936                     pause_sound(whooshsound);
4937                 skeleton.free = 0;
4938                 velocity = 0;
4939                 XYZ middle;
4940                 middle = 0;
4941
4942                 terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[abdomen]].position;
4943                 if (skeleton.joints[skeleton.jointlabels[groin]].locked && skeleton.joints[skeleton.jointlabels[abdomen]].locked) {
4944                     terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[abdomen]].position;
4945                     middle = (skeleton.joints[skeleton.jointlabels[groin]].position + skeleton.joints[skeleton.jointlabels[abdomen]].position) / 2;
4946                 }
4947                 if (skeleton.joints[skeleton.jointlabels[abdomen]].locked && skeleton.joints[skeleton.jointlabels[neck]].locked) {
4948                     terrainnormal = skeleton.joints[skeleton.jointlabels[abdomen]].position - skeleton.joints[skeleton.jointlabels[neck]].position;
4949                     middle = (skeleton.joints[skeleton.jointlabels[neck]].position + skeleton.joints[skeleton.jointlabels[abdomen]].position) / 2;
4950                 }
4951                 if (skeleton.joints[skeleton.jointlabels[groin]].locked && skeleton.joints[skeleton.jointlabels[neck]].locked) {
4952                     terrainnormal = skeleton.joints[skeleton.jointlabels[groin]].position - skeleton.joints[skeleton.jointlabels[neck]].position;
4953                     middle = (skeleton.joints[skeleton.jointlabels[groin]].position + skeleton.joints[skeleton.jointlabels[neck]].position) / 2;
4954                 }
4955                 Normalise(&terrainnormal);
4956
4957                 targetyaw = -asin(0 - terrainnormal.x);
4958                 targetyaw *= 360 / 6.28;
4959                 if (terrainnormal.z < 0)
4960                     targetyaw = 180 - targetyaw;
4961                 yaw = targetyaw;
4962
4963                 targettilt2 = asin(terrainnormal.y) * 180 / 3.14 * -1;
4964
4965
4966                 if (skeleton.forward.y < 0) {
4967                     animTarget = getupfrombackanim;
4968                     frameTarget = 0;
4969                     targettilt2 = 0;
4970                 }
4971                 if (skeleton.forward.y > -.3) {
4972                     animTarget = getupfromfrontanim;
4973                     yaw += 180;
4974                     targetyaw += 180;
4975                     targettilt2 *= -1;
4976                     frameTarget = 0;
4977                     targettilt2 = 0;
4978                 }
4979
4980                 if ((Random() % 8 == 0 && id != 0 && creature == rabbittype) || (Random() % 2 == 0 && id != 0 && creature == wolftype) || (id == 0 && crouchkeydown && (forwardkeydown || backkeydown || leftkeydown || rightkeydown))) {
4981                     animTarget = rollanim;
4982                     targetyaw = lookyaw;
4983                     if (id == 0) {
4984                         if (rightkeydown) {
4985                             targetyaw -= 90;
4986                             if (forwardkeydown)
4987                                 targetyaw += 45;
4988                             if (backkeydown)
4989                                 targetyaw -= 45;
4990                         }
4991                         if (leftkeydown) {
4992                             targetyaw += 90;
4993                             if (forwardkeydown)
4994                                 targetyaw -= 45;
4995                             if (backkeydown)
4996                                 targetyaw += 45;
4997                         }
4998                         if (backkeydown) {
4999                             if ( !leftkeydown && !rightkeydown)
5000                                 targetyaw += 180;
5001                         }
5002                         targetyaw += 180;
5003                     }
5004                 }
5005
5006                 if (abs(targettilt2) > 50)
5007                     targettilt2 = 0;
5008                 animCurrent = tempanim;
5009                 frameCurrent = 0;
5010                 target = 0;
5011                 tilt2 = targettilt2;
5012
5013                 if (middle.y > 0 && animTarget != rollanim)
5014                     targetoffset.y = middle.y + 1;
5015
5016                 for (i = 0; i < skeleton.num_joints; i++) {
5017                     tempanimation.position[i][0] = skeleton.joints[i].position;
5018                     tempanimation.position[i][0] = DoRotation(tempanimation.position[i][0], 0, -yaw, 0);
5019                 }
5020             }
5021         }
5022
5023         bool hasstaff;
5024         hasstaff = 0;
5025         if (num_weapons > 0)
5026             if (weapons[0].getType() == staff)
5027                 hasstaff = 1;
5028         if (!skeleton.freefall && freefall && ((jumpkeydown && jumpkeydowntime < .2) || (hasstaff && rabbitkickragdoll)) && !dead) {
5029             if (velocity.y > -30) {
5030                 XYZ tempvelocity;
5031                 tempvelocity = velocity;
5032                 Normalise(&tempvelocity);
5033                 targetyaw = -asin(0 - tempvelocity.x);
5034                 targetyaw *= 360 / 6.28;
5035                 if (velocity.z < 0)
5036                     targetyaw = 180 - targetyaw;
5037                 //targetyaw+=180;
5038
5039                 skeleton.free = 0;
5040                 if (dotproduct(&skeleton.forward, &tempvelocity) < 0) {
5041                     animTarget = rollanim;
5042                     frameTarget = 2;
5043                 } else {
5044                     animTarget = backhandspringanim;
5045                     targetyaw += 180;
5046                     frameTarget = 6;
5047                 }
5048                 target = 0;
5049
5050                 emit_sound_at(movewhooshsound, coords, 128.);
5051
5052                 animCurrent = animTarget;
5053                 frameCurrent = frameTarget - 1;
5054                 target = 0;
5055
5056                 velocity = 0;
5057
5058                 yaw = targetyaw;
5059                 tilt = 0;
5060                 targettilt = 0;
5061                 tilt2 = 0;
5062                 targettilt2 = 0;
5063             }
5064         }
5065         if (skeleton.freefall == 0)
5066             freefall = 0;
5067
5068     }
5069
5070     if (aitype != passivetype || skeleton.free == 1)
5071         if (findLengthfast(&velocity) > .1)
5072             for (i = 0; i < objects.numobjects; i++) {
5073                 if (objects.type[i] == firetype)
5074                     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) {
5075                         if (onfire) {
5076                             if (!objects.onfire[i]) {
5077                                 emit_sound_at(firestartsound, objects.position[i]);
5078                             }
5079                             objects.onfire[i] = 1;
5080                         }
5081                         if (!onfire) {
5082                             if (objects.onfire[i]) {
5083                                 CatchFire();
5084                             }
5085                         }
5086                     }
5087                 if (objects.type[i] == bushtype)
5088                     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) {
5089                         if (onfire) {
5090                             if (!objects.onfire[i]) {
5091                                 emit_sound_at(firestartsound, objects.position[i]);
5092                             }
5093                             objects.onfire[i] = 1;
5094                         }
5095
5096                         if (!onfire) {
5097                             if (objects.onfire[i]) {
5098                                 CatchFire();
5099                             }
5100                         }
5101                         if (objects.messedwith[i] <= 0) {
5102                             XYZ tempvel;
5103                             XYZ pos;
5104
5105                             emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5106
5107                             if (id == 0) {
5108                                 envsound[numenvsounds] = coords;
5109                                 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5110                                 envsoundlife[numenvsounds] = .4;
5111                                 numenvsounds++;
5112                             }
5113
5114                             int howmany;
5115                             if (environment == grassyenvironment)
5116                                 howmany = findLength(&velocity) * 4;
5117                             if (environment == snowyenvironment)
5118                                 howmany = findLength(&velocity) * 2;
5119                             if (detail == 2)
5120                                 if (environment != desertenvironment)
5121                                     for (j = 0; j < howmany; j++) {
5122                                         tempvel.x = float(abs(Random() % 100) - 50) / 20;
5123                                         tempvel.y = float(abs(Random() % 100) - 50) / 20;
5124                                         tempvel.z = float(abs(Random() % 100) - 50) / 20;
5125                                         pos = coords;
5126                                         pos.y += 1;
5127                                         pos.x += float(abs(Random() % 100) - 50) / 200;
5128                                         pos.y += float(abs(Random() % 100) - 50) / 200;
5129                                         pos.z += float(abs(Random() % 100) - 50) / 200;
5130                                         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);
5131                                         Sprite::setLastSpriteSpecial(1);
5132                                     }
5133                             howmany = findLength(&velocity) * 4;
5134                             if (detail == 2)
5135                                 if (environment == snowyenvironment)
5136                                     for (j = 0; j < howmany; j++) {
5137                                         tempvel.x = float(abs(Random() % 100) - 50) / 20;
5138                                         tempvel.y = float(abs(Random() % 100) - 50) / 20;
5139                                         tempvel.z = float(abs(Random() % 100) - 50) / 20;
5140                                         pos = coords;
5141                                         pos.y += 1;
5142                                         pos.x += float(abs(Random() % 100) - 50) / 200;
5143                                         pos.y += float(abs(Random() % 100) - 50) / 200;
5144                                         pos.z += float(abs(Random() % 100) - 50) / 200;
5145                                         Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5146                                         Sprite::setLastSpriteSpecial(2);
5147                                     }
5148                         }
5149                         objects.rotx[i] += velocity.x * multiplier * 6;
5150                         objects.roty[i] += velocity.z * multiplier * 6;
5151                         objects.messedwith[i] = .5;
5152                     }
5153                 XYZ tempcoord;
5154                 if (objects.type[i] == treeleavestype && environment != desertenvironment) {
5155                     if (objects.pitch[i] == 0)
5156                         tempcoord = coords;
5157                     else {
5158                         tempcoord = coords - objects.position[i];
5159                         tempcoord = DoRotation(tempcoord, 0, -objects.yaw[i], 0);
5160                         tempcoord = DoRotation(tempcoord, -objects.pitch[i], 0, 0);
5161                         tempcoord += objects.position[i];
5162                     }
5163                     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]) {
5164                         if (objects.messedwith[i] <= 0) {
5165                             XYZ tempvel;
5166                             XYZ pos;
5167
5168                             emit_sound_at(bushrustle, coords, 40 * findLength(&velocity));
5169
5170                             if (id == 0) {
5171                                 envsound[numenvsounds] = coords;
5172                                 envsoundvol[numenvsounds] = 4 * findLength(&velocity);
5173                                 envsoundlife[numenvsounds] = .4;
5174                                 numenvsounds++;
5175                             }
5176
5177                             int howmany;
5178                             if (environment == grassyenvironment)
5179                                 howmany = findLength(&velocity) * 4;
5180                             if (environment == snowyenvironment)
5181                                 howmany = findLength(&velocity) * 2;
5182                             if (detail == 2)
5183                                 if (environment != desertenvironment)
5184                                     for (j = 0; j < howmany; j++) {
5185                                         tempvel.x = float(abs(Random() % 100) - 50) / 20;
5186                                         tempvel.y = float(abs(Random() % 100) - 50) / 20;
5187                                         tempvel.z = float(abs(Random() % 100) - 50) / 20;
5188                                         pos = coords;
5189                                         pos += velocity * .1;
5190                                         pos.y += 1;
5191                                         pos.x += float(abs(Random() % 100) - 50) / 150;
5192                                         pos.y += float(abs(Random() % 100) - 50) / 150;
5193                                         pos.z += float(abs(Random() % 100) - 50) / 150;
5194                                         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);
5195                                         Sprite::setLastSpriteSpecial(1);
5196                                     }
5197                             howmany = findLength(&velocity) * 4;
5198                             if (detail == 2)
5199                                 if (environment == snowyenvironment)
5200                                     for (j = 0; j < howmany; j++) {
5201                                         tempvel.x = float(abs(Random() % 100) - 50) / 20;
5202                                         tempvel.y = float(abs(Random() % 100) - 50) / 20;
5203                                         tempvel.z = float(abs(Random() % 100) - 50) / 20;
5204                                         pos = coords;
5205                                         pos += velocity * .1;
5206                                         pos.y += 1;
5207                                         pos.x += float(abs(Random() % 100) - 50) / 150;
5208                                         pos.y += float(abs(Random() % 100) - 50) / 150;
5209                                         pos.z += float(abs(Random() % 100) - 50) / 150;
5210                                         Sprite::MakeSprite(splintersprite, pos, tempvel * .3 + velocity * float(abs(Random() % 100)) / 100 / 2, 1, 1, 1, .1, 1);
5211                                         Sprite::setLastSpriteSpecial(2);
5212                                     }
5213                         }
5214                         objects.messedwith[i] = .5;
5215                     }
5216                 }
5217             }
5218
5219     if (!skeleton.free) {
5220         bool play;
5221         play = 0;
5222         if ((stunned > 0 || surprised > 0) && numplayers > 2 && aitype != passivetype)
5223             play = 1;
5224         if (hasvictim)
5225             if (aitype != passivetype && victim->skeleton.free && !victim->dead)
5226                 play = 1;
5227         if (tutoriallevel == 1 && id != 0)
5228             play = 0;
5229         if (play && aitype != playercontrolled) {
5230             int whichsound = -1;
5231             i = abs(Random() % 4);
5232             if (speechdelay <= 0) {
5233                 if (creature == rabbittype) {
5234                     if (i == 0)
5235                         whichsound = rabbitchitter;
5236                     if (i == 1)
5237                         whichsound = rabbitchitter2;
5238                 }
5239                 if (creature == wolftype) {
5240                     if (i == 0)
5241                         whichsound = growlsound;
5242                     if (i == 1)
5243                         whichsound = growl2sound;
5244                 }
5245             }
5246             speechdelay = .3;
5247
5248             if (whichsound != -1) {
5249                 emit_sound_at(whichsound, coords);
5250             }
5251         }
5252
5253         if (animTarget == staggerbackhighanim)
5254             staggerdelay = 1;
5255         if (animTarget == staggerbackhardanim)
5256             staggerdelay = 1;
5257         staggerdelay -= multiplier;
5258         if (animTarget != crouchstabanim && animTarget != swordgroundstabanim && animTarget != staffgroundsmashanim)
5259             hasvictim = 1;
5260         if (velocity.y < -30 && animTarget == jumpdownanim)
5261             RagDoll(0);
5262         if (animCurrent != getIdle() && wasIdle() && animTarget != getIdle() && isIdle()) {
5263             animTarget = getIdle();
5264             frameTarget = 0;
5265             target = 0;
5266         }
5267         weaponmissdelay -= multiplier;
5268         highreversaldelay -= multiplier;
5269         lowreversaldelay -= multiplier;
5270         lastcollide -= multiplier;
5271         skiddelay -= multiplier;
5272         if (!isnormal(velocity.x) && velocity.x) {
5273             velocity = 0;
5274         }
5275         if (!isnormal(targettilt) && targettilt) {
5276             targettilt = 0;
5277         }
5278         if (!isnormal(targettilt2) && targettilt2) {
5279             targettilt2 = 0;
5280         }
5281         if (!isnormal(targetyaw) && targetyaw) {
5282             targetyaw = 0;
5283         }
5284
5285         if (animTarget == bounceidleanim || animTarget == wolfidle || animTarget == walkanim || animTarget == drawrightanim || animTarget == crouchdrawrightanim || animTarget == drawleftanim || animTarget == fightidleanim || animTarget == fightsidestep || animTarget == hanganim || isCrouch() || animTarget == backhandspringanim) {
5286             //open hands and close mouth
5287             if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5288                 righthandmorphness = 0;
5289                 righthandmorphend = 0;
5290                 targetrighthandmorphness = 1;
5291             }
5292
5293             if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5294                 lefthandmorphness = 0;
5295                 lefthandmorphend = 0;
5296                 targetlefthandmorphness = 1;
5297             }
5298
5299             if (headmorphend != 3 && headmorphend != 5 && headmorphstart != 3 && headmorphstart != 5 && headmorphend != 0 && headmorphness == targetheadmorphness) {
5300                 headmorphness = 0;
5301                 headmorphend = 0;
5302                 targetheadmorphness = 1;
5303             }
5304         }
5305
5306         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) {
5307             //open hands and mouth
5308             if (righthandmorphend != 0 && righthandmorphness == targetrighthandmorphness) {
5309                 righthandmorphness = 0;
5310                 righthandmorphend = 0;
5311                 targetrighthandmorphness = 1;
5312             }
5313
5314             if (lefthandmorphend != 0 && lefthandmorphness == targetlefthandmorphness) {
5315                 lefthandmorphness = 0;
5316                 lefthandmorphend = 0;
5317                 targetlefthandmorphness = 1;
5318             }
5319
5320             if (headmorphend != 1 && headmorphness == targetheadmorphness) {
5321                 headmorphness = 0;
5322                 headmorphend = 1;
5323                 targetheadmorphness = 1;
5324             }
5325         }
5326
5327         if (animTarget == jumpupanim || animTarget == crouchstabanim || animTarget == swordgroundstabanim || animTarget == swordfightidlebothanim || animTarget == blockhighleftanim || animTarget == blockhighleftanim) {
5328             //close hands and mouth
5329             if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5330                 righthandmorphness = 0;
5331                 righthandmorphend = 1;
5332                 targetrighthandmorphness = 1;
5333             }
5334
5335             if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5336                 lefthandmorphness = 0;
5337                 lefthandmorphend = 1;
5338                 targetlefthandmorphness = 1;
5339             }
5340
5341             if (headmorphend != 0 && headmorphness == targetheadmorphness) {
5342                 headmorphness = 0;
5343                 headmorphend = 0;
5344                 targetheadmorphness = 1;
5345             }
5346         }
5347
5348         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) {
5349             //close hands and yell
5350             if (righthandmorphend != 1 && righthandmorphness == targetrighthandmorphness) {
5351                 righthandmorphness = 0;
5352                 righthandmorphend = 1;
5353                 targetrighthandmorphness = 1;
5354             }
5355
5356             if (lefthandmorphend != 1 && lefthandmorphness == targetlefthandmorphness) {
5357                 lefthandmorphness = 0;
5358                 lefthandmorphend = 1;
5359                 targetlefthandmorphness = 1;
5360             }
5361
5362             if (headmorphend != 2 && headmorphness == targetheadmorphness) {
5363                 headmorphness = 1;
5364                 headmorphend = 2;
5365                 targetheadmorphness = 1;
5366             }
5367         }
5368
5369         bool behind;
5370         behind = 0;
5371         if (hasvictim) {
5372             if (victim != this && !victim->dead && victim->aitype != passivetype && victim->aitype != searchtype && aitype != passivetype && aitype != searchtype && victim->id < numplayers && aitype != passivetype) {
5373                 behind = (normaldotproduct(facing, coords - victim->coords) > 0);
5374             }
5375         }
5376
5377         if (!dead && animTarget != hurtidleanim)
5378             if (behind || animTarget == killanim || animTarget == knifethrowanim || animTarget == knifefollowanim || animTarget == spinkickreversalanim || animTarget == rabbitkickreversedanim || animTarget == jumpreversedanim) {
5379                 if (headmorphend != 4 || headmorphness == targetheadmorphness) {
5380                     headmorphend = 4;
5381                     //headmorphness=1;
5382                     targetheadmorphness = 1;
5383                 }
5384             }
5385
5386         if (weaponactive != -1) {
5387             if (weapons[weaponids[weaponactive]].getType() != staff) {
5388                 righthandmorphstart = 1;
5389                 righthandmorphend = 1;
5390             }
5391             if (weapons[weaponids[weaponactive]].getType() == staff) {
5392                 righthandmorphstart = 2;
5393                 righthandmorphend = 2;
5394             }
5395             targetrighthandmorphness = 1;
5396         }
5397
5398         terrainnormal = terrain.getNormal(coords.x, coords.z);
5399
5400         if (animation[animTarget].attack != reversal) {
5401             if (!isnormal(coords.x))
5402                 coords = oldcoords;
5403             oldcoords = coords;
5404         }
5405
5406         flatfacing = 0;
5407         flatfacing.z = 1;
5408
5409         flatfacing = DoRotation(flatfacing, 0, yaw, 0);
5410         facing = flatfacing;
5411         ReflectVector(&facing, terrainnormal);
5412         Normalise(&facing);
5413
5414         if (isRun() || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim) {
5415             if (onterrain)
5416                 targettilt2 = -facing.y * 20;
5417             else
5418                 targettilt2 = 0;
5419         }
5420         onterrain = 0;
5421         if (!isRun() && !animation[animTarget].attack && animTarget != getupfromfrontanim && animTarget != getupfrombackanim && animTarget != sneakanim)
5422             targettilt2 = 0;
5423         if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5424             flatvelocity = velocity;
5425             flatvelocity.y = 0;
5426             flatvelspeed = findLength(&flatvelocity);
5427             targettilt = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(DoRotation(flatfacing, 0, -90, 0), flatvelocity);
5428             targettilt2 = flatvelspeed * fast_sqrt(abs(velocity.y) * .7) * normaldotproduct(flatfacing, flatvelocity);
5429             if (velocity.y < 0)
5430                 targettilt2 *= -1;
5431             if (velocity.y < 0)
5432                 targettilt *= -1;
5433             if (targettilt > 25)
5434                 targettilt = 25;
5435             if (targettilt < -25)
5436                 targettilt = -25;
5437         }
5438
5439         if (targettilt2 > 45)
5440             targettilt2 = 45;
5441         if (targettilt2 < -45)
5442             targettilt2 = -45;
5443         if (abs(tilt2 - targettilt2) < multiplier * 400)
5444             tilt2 = targettilt2;
5445         else if (tilt2 > targettilt2) {
5446             tilt2 -= multiplier * 400;
5447         } else if (tilt2 < targettilt2) {
5448             tilt2 += multiplier * 400;
5449         }
5450         if (!animation[animTarget].attack && animTarget != getupfrombackanim && animTarget != getupfromfrontanim) {
5451             if (tilt2 > 25)
5452                 tilt2 = 25;
5453             if (tilt2 < -25)
5454                 tilt2 = -25;
5455         }
5456
5457         if (!isnormal(targettilt) && targettilt) {
5458             targettilt = 0;
5459         }
5460         if (!isnormal(targettilt2) && targettilt2) {
5461             targettilt2 = 0;
5462         }
5463
5464         //Running velocity
5465         //if(!creature==wolftype||animTarget==rabbitkickanim)
5466         if (animTarget == rabbittackleanim) {
5467             velocity += facing * multiplier * speed * 700 * scale;
5468             velspeed = findLength(&velocity);
5469             if (velspeed > speed * 65 * scale) {
5470                 velocity /= velspeed;
5471                 velspeed = speed * 65 * scale;
5472                 velocity *= velspeed;
5473             }
5474             velocity.y += gravity * multiplier * 20;
5475             ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5476             velspeed = findLength(&velocity);
5477             velocity = flatfacing * velspeed;
5478         }
5479         if (animTarget != rabbitrunninganim && animTarget != wolfrunninganim) {
5480             if (isRun() || animTarget == rabbitkickanim) {
5481                 velocity += facing * multiplier * speed * 700 * scale;
5482                 velspeed = findLength(&velocity);
5483                 if (velspeed > speed * 45 * scale) {
5484                     velocity /= velspeed;
5485                     velspeed = speed * 45 * scale;
5486                     velocity *= velspeed;
5487                 }
5488                 velocity.y += gravity * multiplier * 20;
5489                 ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5490                 velspeed = findLength(&velocity);
5491                 if (velspeed < speed * 30 * scale)
5492                     velspeed = speed * 30 * scale;
5493                 velocity = flatfacing * velspeed;
5494             }
5495         } else if (isRun()) {
5496             velocity += facing * multiplier * speed * 700 * scale;
5497             velspeed = findLength(&velocity);
5498             if (creature == rabbittype) {
5499                 if (velspeed > speed * 55 * scale) {
5500                     velocity /= velspeed;
5501                     velspeed = speed * 55 * scale;
5502                     velocity *= velspeed;
5503                 }
5504             }
5505             if (creature == wolftype) {
5506                 if (velspeed > speed * 75 * scale) {
5507                     velocity /= velspeed;
5508                     velspeed = speed * 75 * scale;
5509                     velocity *= velspeed;
5510                 }
5511             }
5512             velocity.y += gravity * multiplier * 20;
5513             ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5514             velspeed = findLength(&velocity);
5515             velocity = flatfacing * velspeed;
5516         }
5517
5518         if (animTarget == rollanim && animation[animTarget].label[frameTarget] != 6) {
5519             velocity += facing * multiplier * speed * 700 * scale;
5520             velspeed = findLength(&velocity);
5521             if (velspeed > speed * 45 * scale) {
5522                 velocity /= velspeed;
5523                 velspeed = speed * 45 * scale;
5524                 velocity *= velspeed;
5525             }
5526             velocity.y += gravity * multiplier * 20;
5527             ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5528             velspeed = findLength(&velocity);
5529             velocity = flatfacing * velspeed;
5530         }
5531
5532
5533         /*if(animCurrent==rollanim&&(isCrouch()||isIdle())){
5534         velocity+=facing*multiplier*speed*700*scale;
5535         velspeed=findLength(&velocity);
5536         if(velspeed>speed*25*scale){
5537         velocity/=velspeed;
5538         velspeed=speed*25*scale;
5539         velocity*=velspeed;
5540         }
5541         velocity.y+=gravity*multiplier*20;
5542         ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5543         velspeed=findLength(&velocity);
5544         velocity=flatfacing*velspeed;
5545         }*/
5546
5547         if (animTarget == sneakanim || animTarget == walkanim) {
5548             velocity += facing * multiplier * speed * 700 * scale;
5549             velspeed = findLength(&velocity);
5550             if (velspeed > speed * 12 * scale) {
5551                 velocity /= velspeed;
5552                 velspeed = speed * 12 * scale;
5553                 velocity *= velspeed;
5554             }
5555             velocity.y += gravity * multiplier * 20;
5556             ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5557             velspeed = findLength(&velocity);
5558             velocity = flatfacing * velspeed;
5559         }
5560
5561         if ((animTarget == fightidleanim || animTarget == knifefightidleanim) && (animCurrent == bounceidleanim || animCurrent == hurtidleanim)) {
5562             velocity += facing * multiplier * speed * 700 * scale;
5563             velspeed = findLength(&velocity);
5564             if (velspeed > speed * 2 * scale) {
5565                 velocity /= velspeed;
5566                 velspeed = speed * 2 * scale;
5567                 velocity *= velspeed;
5568             }
5569             velocity.y += gravity * multiplier * 20;
5570             ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5571             velspeed = findLength(&velocity);
5572             velocity = flatfacing * velspeed;
5573         }
5574
5575
5576         if ((animTarget == bounceidleanim || animCurrent == hurtidleanim) && (animCurrent == fightidleanim || animCurrent == knifefightidleanim)) {
5577             velocity -= facing * multiplier * speed * 700 * scale;
5578             velspeed = findLength(&velocity);
5579             if (velspeed > speed * 2 * scale) {
5580                 velocity /= velspeed;
5581                 velspeed = speed * 2 * scale;
5582                 velocity *= velspeed;
5583             }
5584             velocity.y += gravity * multiplier * 20;
5585             ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5586             velspeed = findLength(&velocity);
5587             velocity = flatfacing * velspeed * -1;
5588         }
5589
5590         if (animTarget == fightsidestep) {
5591             velocity += DoRotation(facing * multiplier * speed * 700 * scale, 0, -90, 0);
5592             velspeed = findLength(&velocity);
5593             if (velspeed > speed * 12 * scale) {
5594                 velocity /= velspeed;
5595                 velspeed = speed * 12 * scale;
5596                 velocity *= velspeed;
5597             }
5598             velocity.y += gravity * multiplier * 20;
5599             ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5600             velspeed = findLength(&velocity);
5601             velocity = DoRotation(flatfacing * velspeed, 0, -90, 0);
5602         }
5603
5604         if (animTarget == staggerbackhighanim) {
5605             coords -= facing * multiplier * speed * 16 * scale;
5606             velocity = 0;
5607         }
5608         if (animTarget == staggerbackhardanim && animation[staggerbackhardanim].label[frameTarget] != 6) {
5609             coords -= facing * multiplier * speed * 20 * scale;
5610             velocity = 0;
5611         }
5612
5613         if (animTarget == backhandspringanim) {
5614             //coords-=facing*multiplier*50*scale;
5615             velocity += facing * multiplier * speed * 700 * scale * -1;
5616             velspeed = findLength(&velocity);
5617             if (velspeed > speed * 50 * scale) {
5618                 velocity /= velspeed;
5619                 velspeed = speed * 50 * scale;
5620                 velocity *= velspeed;
5621             }
5622             velocity.y += gravity * multiplier * 20;
5623             ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5624             velspeed = findLength(&velocity);
5625             velocity = flatfacing * velspeed * -1;
5626         }
5627         if (animTarget == dodgebackanim) {
5628             //coords-=facing*multiplier*50*scale;
5629             velocity += facing * multiplier * speed * 700 * scale * -1;
5630             velspeed = findLength(&velocity);
5631             if (velspeed > speed * 60 * scale) {
5632                 velocity /= velspeed;
5633                 velspeed = speed * 60 * scale;
5634                 velocity *= velspeed;
5635             }
5636             velocity.y += gravity * multiplier * 20;
5637             ReflectVector(&velocity, terrain.getNormal(coords.x, coords.z));
5638             velspeed = findLength(&velocity);
5639             velocity = flatfacing * velspeed * -1;
5640         }
5641
5642         if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5643             velspeed = findLength(&velocity);
5644         }
5645
5646
5647         if (animTarget == jumpupanim || animTarget == jumpdownanim || isFlip()) {
5648             velocity.y += gravity * multiplier;
5649         }
5650
5651         if (animTarget != climbanim && animTarget != hanganim && !isWallJump())
5652             coords += velocity * multiplier;
5653
5654         if (coords.y < terrain.getHeight(coords.x, coords.z) && (animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
5655             if (isFlip() && animation[animTarget].label[frameTarget] == 7)
5656                 RagDoll(0);
5657
5658             if (animTarget == jumpupanim) {
5659                 jumppower = -4;
5660                 animTarget = getIdle();
5661             }
5662             target = 0;
5663             frameTarget = 0;
5664             onterrain = 1;
5665
5666             if (id == 0) {
5667                 pause_sound(whooshsound);
5668                 OPENAL_SetVolume(channels[whooshsound], 0);
5669             }
5670
5671             if (animTarget == jumpdownanim || isFlip()) {
5672                 if (isFlip())jumppower = -4;
5673                 animTarget = getLanding();
5674                 emit_sound_at(landsound, coords, 128.);
5675
5676                 if (id == 0) {
5677                     envsound[numenvsounds] = coords;
5678                     envsoundvol[numenvsounds] = 16;
5679                     envsoundlife[numenvsounds] = .4;
5680                     numenvsounds++;
5681                 }
5682             }
5683         }
5684
5685         if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && animTarget != climbanim && animTarget != hanganim && !isWallJump())
5686             coords.y += gravity * multiplier * 2;
5687         if (animTarget != jumpupanim && animTarget != jumpdownanim && !isFlip() && coords.y < terrain.getHeight(coords.x, coords.z)) {
5688             coords.y = terrain.getHeight(coords.x, coords.z);
5689             onterrain = 1;
5690         }
5691
5692
5693         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)) {
5694             velspeed = findLength(&velocity);
5695             velocity.y = 0;
5696             if (velspeed < multiplier * 300 * scale) {
5697                 velocity = 0;
5698             } else
5699                 velocity -= velocity / velspeed * multiplier * 300 * scale;
5700             if (velspeed > 5 && (isLanding() || isLandhard())) {
5701                 skiddingdelay += multiplier;
5702                 if (skiddelay <= 0) {
5703                     FootLand(0, .5);
5704                     FootLand(1, .5);
5705                     skiddelay = .02;
5706                 }
5707             } else
5708                 skiddingdelay = 0;
5709         }
5710
5711         if (isLandhard()) {
5712             velspeed = findLength(&velocity);
5713             velocity.y = 0;
5714             if (velspeed < multiplier * 600 * scale) {
5715                 velocity = 0;
5716             } else
5717                 velocity -= velocity / velspeed * multiplier * 600 * scale;
5718             velocity = 0;
5719             if (velspeed > 5 && (isLanding() || isLandhard())) {
5720                 skiddingdelay += multiplier;
5721                 if (skiddelay <= 0) {
5722                     FootLand(0, .5);
5723                     FootLand(1, .5);
5724                     skiddelay = .02;
5725                 }
5726             } else
5727                 skiddingdelay = 0;
5728         }
5729
5730         if (skiddingdelay < 0)
5731             skiddingdelay += multiplier;
5732         if (skiddingdelay > .02 && !forwardkeydown && !backkeydown && !leftkeydown && !rightkeydown && !jumpkeydown && isLanding() && !landhard) {
5733             skiddingdelay = -1;
5734             if (!onterrain || environment == grassyenvironment) {
5735                 emit_sound_at(skidsound, coords, 128 * velspeed / 10);
5736             } else {
5737                 emit_sound_at(snowskidsound, coords, 128 * velspeed / 10);
5738             }
5739         }
5740
5741         if (animation[animTarget].attack == normalattack && animTarget != rabbitkickanim && !victim->skeleton.free) {
5742             terrainnormal = victim->coords - coords;
5743             Normalise(&terrainnormal);
5744             targetyaw = -asin(0 - terrainnormal.x);
5745             targetyaw *= 360 / 6.28;
5746             if (terrainnormal.z < 0)
5747                 targetyaw = 180 - targetyaw;
5748             targettilt2 = -asin(terrainnormal.y) * 360 / 6.28; //*-70;
5749         }
5750
5751         if (animation[animTarget].attack == reversal && animTarget != rabbittacklinganim) {
5752             targetyaw = victim->targetyaw;
5753         }
5754         if (animTarget == rabbittacklinganim) {
5755             coords = victim->coords;
5756         }
5757     }
5758     skeleton.oldfree = skeleton.free;
5759
5760     XYZ midterrain;
5761     midterrain = 0;
5762     midterrain.x = terrain.size * terrain.scale / 2;
5763     midterrain.z = terrain.size * terrain.scale / 2;
5764     if (distsqflat(&coords, &midterrain) > (terrain.size * terrain.scale / 2 - viewdistance) * (terrain.size * terrain.scale / 2 - viewdistance)) {
5765         XYZ tempposit;
5766         tempposit = coords - midterrain;
5767         tempposit.y = 0;
5768         Normalise(&tempposit);
5769         tempposit *= (terrain.size * terrain.scale / 2 - viewdistance);
5770         coords.x = tempposit.x + midterrain.x;
5771         coords.z = tempposit.z + midterrain.z;
5772     }
5773 }
5774
5775 int Person::DrawSkeleton()
5776 {
5777     int oldplayerdetail;
5778     if ((frustum.SphereInFrustum(coords.x, coords.y + scale * 3, coords.z, scale * 8) && distsq(&viewer, &coords) < viewdistance * viewdistance) || skeleton.free == 3) {
5779         if (onterrain && (isIdle() || isCrouch() || wasIdle() || wasCrouch()) && !skeleton.free) {
5780             calcrot = 1;
5781         }
5782
5783         if (headless) {
5784             headmorphness = 0;
5785             headmorphstart = 6;
5786             headmorphend = 6;
5787         }
5788
5789         glAlphaFunc(GL_GREATER, 0.0001);
5790         XYZ terrainlight;
5791         float terrainheight;
5792         float distance;
5793         if (!isnormal(yaw))
5794             yaw = 0;
5795         if (!isnormal(tilt))
5796             tilt = 0;
5797         if (!isnormal(tilt2))
5798             tilt2 = 0;
5799         oldplayerdetail = playerdetail;
5800         playerdetail = 0;
5801         if (distsq(&viewer, &coords) < viewdistance * viewdistance / 32 && detail == 2) {
5802             playerdetail = 1;
5803         }
5804         if (distsq(&viewer, &coords) < viewdistance * viewdistance / 128 && detail == 1) {
5805             playerdetail = 1;
5806         }
5807         if (distsq(&viewer, &coords) < viewdistance * viewdistance / 256 && (detail != 1 && detail != 2)) {
5808             playerdetail = 1;
5809         }
5810         if (id == 0)
5811             playerdetail = 1;
5812         if (playerdetail != oldplayerdetail) {
5813             updatedelay = 0;
5814             normalsupdatedelay = 0;
5815         }
5816         static float updatedelaychange;
5817         static float morphness;
5818         static float framemult;
5819         if (calcrot) {
5820             skeleton.FindForwards();
5821             if (howactive == typesittingwall) {
5822                 skeleton.specialforward[1] = 0;
5823                 skeleton.specialforward[1].z = 1;
5824             }
5825         }
5826         static XYZ mid;
5827         static float M[16];
5828         static int i, j, k;
5829         static int weaponattachmuscle;
5830         static int weaponrotatemuscle;
5831         static XYZ weaponpoint;
5832         static int start, endthing;
5833         if ((dead != 2 || skeleton.free != 2) && updatedelay <= 0) {
5834             if (!isSleeping() && !isSitting()) {
5835                 if (onterrain && ((isIdle() || isCrouch() || isLanding() || isLandhard() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim) && (wasIdle() || wasCrouch() || wasLanding() || wasLandhard() || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim)) && !skeleton.free) {
5836                     XYZ point, newpoint, change, change2;
5837                     point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
5838                     heightleft = terrain.getHeight(point.x, point.z) + .04;
5839                     point.y = heightleft;
5840                     change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5841                     change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5842                     skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0);
5843                     skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
5844                     skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
5845
5846                     point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
5847                     heightright = terrain.getHeight(point.x, point.z) + .04;
5848                     point.y = heightright;
5849                     change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5850                     change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5851                     skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0);
5852                     skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
5853                     skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
5854                     skeleton.DoConstraints(&coords, &scale);
5855
5856                     if (creature == wolftype) {
5857                         point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
5858                         heightleft = terrain.getHeight(point.x, point.z) + .04;
5859                         point.y = heightleft;
5860                         change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5861                         change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5862                         skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0);
5863                         skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
5864                         skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
5865
5866                         point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
5867                         heightright = terrain.getHeight(point.x, point.z) + .04;
5868                         point.y = heightright;
5869                         change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5870                         change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5871                         skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0);
5872                         skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
5873                         skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
5874                         skeleton.DoConstraints(&coords, &scale);
5875                     }
5876                 }
5877                 if (onterrain && ((isIdle() || isCrouch() || isLanding() || isLandhard() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim) && !(wasIdle() || wasCrouch() || wasLanding() || wasLandhard() || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim)) && !skeleton.free) {
5878                     XYZ point, newpoint, change, change2;
5879                     point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
5880                     heightleft = terrain.getHeight(point.x, point.z) + .04;
5881                     point.y = heightleft;
5882                     change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5883                     change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5884                     skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * target + skeleton.joints[skeleton.jointlabels[leftfoot]].position * (1 - target);
5885                     skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
5886                     skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
5887
5888                     point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
5889                     heightright = terrain.getHeight(point.x, point.z) + .04;
5890                     point.y = heightright;
5891                     change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5892                     change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5893                     skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * target + skeleton.joints[skeleton.jointlabels[rightfoot]].position * (1 - target);
5894                     skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
5895                     skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
5896                     skeleton.DoConstraints(&coords, &scale);
5897
5898                     if (creature == wolftype) {
5899                         point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
5900                         heightleft = terrain.getHeight(point.x, point.z) + .04;
5901                         point.y = heightleft;
5902                         change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5903                         change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5904                         skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * target + skeleton.joints[skeleton.jointlabels[leftfoot]].position * (1 - target);
5905                         skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
5906                         skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
5907
5908                         point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
5909                         heightright = terrain.getHeight(point.x, point.z) + .04;
5910                         point.y = heightright;
5911                         change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5912                         change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5913                         skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * target + skeleton.joints[skeleton.jointlabels[rightfoot]].position * (1 - target);
5914                         skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
5915                         skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
5916                         skeleton.DoConstraints(&coords, &scale);
5917                     }
5918                 }
5919
5920                 if (onterrain && (!(isIdle() || isCrouch() || isLanding() || isLandhard() || animTarget == drawrightanim || animTarget == drawleftanim || animTarget == crouchdrawrightanim) && (wasIdle() || wasCrouch() || wasLanding() || wasLandhard() || animCurrent == drawrightanim || animCurrent == drawleftanim || animCurrent == crouchdrawrightanim)) && !skeleton.free) {
5921                     XYZ point, newpoint, change, change2;
5922                     point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
5923                     heightleft = terrain.getHeight(point.x, point.z) + .04;
5924                     point.y = heightleft;
5925                     change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5926                     change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5927                     skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * (1 - target) + skeleton.joints[skeleton.jointlabels[leftfoot]].position * target;
5928                     skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
5929                     skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
5930
5931                     point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
5932                     heightright = terrain.getHeight(point.x, point.z) + .04;
5933                     point.y = heightright;
5934                     change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5935                     change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5936                     skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * (1 - target) + skeleton.joints[skeleton.jointlabels[rightfoot]].position * target;
5937                     skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
5938                     skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
5939                     skeleton.DoConstraints(&coords, &scale);
5940
5941                     if (creature == wolftype) {
5942                         point = DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position, 0, yaw, 0) * scale + coords;
5943                         heightleft = terrain.getHeight(point.x, point.z) + .04;
5944                         point.y = heightleft;
5945                         change = skeleton.joints[skeleton.jointlabels[leftankle]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5946                         change2 = skeleton.joints[skeleton.jointlabels[leftknee]].position - skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5947                         skeleton.joints[skeleton.jointlabels[leftfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * (1 - target) + skeleton.joints[skeleton.jointlabels[leftfoot]].position * target;
5948                         skeleton.joints[skeleton.jointlabels[leftankle]].position = skeleton.joints[skeleton.jointlabels[leftfoot]].position + change;
5949                         skeleton.joints[skeleton.jointlabels[leftknee]].position = (skeleton.joints[skeleton.jointlabels[leftfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[leftknee]].position) / 2;
5950
5951                         point = DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position, 0, yaw, 0) * scale + coords;
5952                         heightright = terrain.getHeight(point.x, point.z) + .04;
5953                         point.y = heightright;
5954                         change = skeleton.joints[skeleton.jointlabels[rightankle]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5955                         change2 = skeleton.joints[skeleton.jointlabels[rightknee]].position - skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5956                         skeleton.joints[skeleton.jointlabels[rightfoot]].position = DoRotation((point - coords) / scale, 0, -yaw, 0) * (1 - target) + skeleton.joints[skeleton.jointlabels[rightfoot]].position * target;
5957                         skeleton.joints[skeleton.jointlabels[rightankle]].position = skeleton.joints[skeleton.jointlabels[rightfoot]].position + change;
5958                         skeleton.joints[skeleton.jointlabels[rightknee]].position = (skeleton.joints[skeleton.jointlabels[rightfoot]].position + change2) / 2 + (skeleton.joints[skeleton.jointlabels[rightknee]].position) / 2;
5959                         skeleton.DoConstraints(&coords, &scale);
5960                     }
5961                 }
5962             }
5963             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()))
5964                 DoHead();
5965             else {
5966                 targetheadyaw = -targetyaw;
5967                 targetheadpitch = 0;
5968                 if (animation[animTarget].attack == 3)
5969                     targetheadyaw += 180;
5970             }
5971             for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
5972                 skeleton.drawmodel.vertex[i] = 0;
5973                 skeleton.drawmodel.vertex[i].y = 999;
5974             }
5975             for (i = 0; i < skeleton.drawmodellow.vertexNum; i++) {
5976                 skeleton.drawmodellow.vertex[i] = 0;
5977                 skeleton.drawmodellow.vertex[i].y = 999;
5978             }
5979             for (i = 0; i < skeleton.drawmodelclothes.vertexNum; i++) {
5980                 skeleton.drawmodelclothes.vertex[i] = 0;
5981                 skeleton.drawmodelclothes.vertex[i].y = 999;
5982             }
5983             for (i = 0; i < skeleton.num_muscles; i++) {
5984                 if ((skeleton.muscles[i].numvertices > 0 && playerdetail) || (skeleton.muscles[i].numverticeslow > 0 && !playerdetail)) {
5985                     morphness = 0;
5986                     start = 0;
5987                     endthing = 0;
5988                     if (skeleton.muscles[i].parent1->label == righthand || skeleton.muscles[i].parent2->label == righthand) {
5989                         morphness = righthandmorphness;
5990                         start = righthandmorphstart;
5991                         endthing = righthandmorphend;
5992                     }
5993                     if (skeleton.muscles[i].parent1->label == lefthand || skeleton.muscles[i].parent2->label == lefthand) {
5994                         morphness = lefthandmorphness;
5995                         start = lefthandmorphstart;
5996                         endthing = lefthandmorphend;
5997                     }
5998                     if (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head) {
5999                         morphness = headmorphness;
6000                         start = headmorphstart;
6001                         endthing = headmorphend;
6002                     }
6003                     if ((skeleton.muscles[i].parent1->label == neck && skeleton.muscles[i].parent2->label == abdomen) || (skeleton.muscles[i].parent2->label == neck && skeleton.muscles[i].parent1->label == abdomen)) {
6004                         morphness = chestmorphness;
6005                         start = chestmorphstart;
6006                         endthing = chestmorphend;
6007                     }
6008                     if ((skeleton.muscles[i].parent1->label == groin && skeleton.muscles[i].parent2->label == abdomen) || (skeleton.muscles[i].parent2->label == groin && skeleton.muscles[i].parent1->label == abdomen)) {
6009                         morphness = tailmorphness;
6010                         start = tailmorphstart;
6011                         endthing = tailmorphend;
6012                     }
6013                     if (calcrot)
6014                         skeleton.FindRotationMuscle(i, animTarget);
6015                     mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6016                     glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
6017                     glPushMatrix();
6018                     glLoadIdentity();
6019                     if (!skeleton.free)
6020                         glRotatef(tilt2, 1, 0, 0);
6021                     if (!skeleton.free)
6022                         glRotatef(tilt, 0, 0, 1);
6023
6024
6025                     glTranslatef(mid.x, mid.y, mid.z);
6026
6027                     skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6028                     glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6029
6030                     skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6031                     glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6032
6033                     skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6034                     glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6035
6036                     if (playerdetail || skeleton.free == 3) {
6037                         for (j = 0; j < skeleton.muscles[i].numvertices; j++) {
6038                             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
6039                             glPushMatrix();
6040                             if (skeleton.muscles[i].parent1->label == abdomen || skeleton.muscles[i].parent2->label == abdomen)
6041                                 glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x * morphness)*proportionbody.x,
6042                                              (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y * morphness)*proportionbody.y,
6043                                              (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z * morphness)*proportionbody.z);
6044                             if (skeleton.muscles[i].parent1->label == lefthand || skeleton.muscles[i].parent1->label == righthand || skeleton.muscles[i].parent1->label == leftwrist || skeleton.muscles[i].parent1->label == rightwrist || skeleton.muscles[i].parent1->label == leftelbow || skeleton.muscles[i].parent1->label == rightelbow || skeleton.muscles[i].parent2->label == leftelbow || skeleton.muscles[i].parent2->label == rightelbow)
6045                                 glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x * morphness)*proportionarms.x,
6046                                              (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y * morphness)*proportionarms.y,
6047                                              (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z * morphness)*proportionarms.z);
6048                             if (skeleton.muscles[i].parent1->label == leftfoot || skeleton.muscles[i].parent1->label == rightfoot || skeleton.muscles[i].parent1->label == leftankle || skeleton.muscles[i].parent1->label == rightankle || skeleton.muscles[i].parent1->label == leftknee || skeleton.muscles[i].parent1->label == rightknee || skeleton.muscles[i].parent2->label == leftknee || skeleton.muscles[i].parent2->label == rightknee)
6049                                 glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x * morphness)*proportionlegs.x,
6050                                              (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y * morphness)*proportionlegs.y,
6051                                              (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z * morphness)*proportionlegs.z);
6052                             if (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)
6053                                 glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x * morphness)*proportionhead.x,
6054                                              (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y * morphness)*proportionhead.y,
6055                                              (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z * (1 - morphness) + skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z * morphness)*proportionhead.z);
6056                             glGetFloatv(GL_MODELVIEW_MATRIX, M);
6057                             //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
6058                             //if(!isnormal(scale))test=1;
6059                             skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x = M[12] * scale;
6060                             skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y = M[13] * scale;
6061                             skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z = M[14] * scale;
6062                             //test=2;
6063                             glPopMatrix();
6064                         }
6065                     }
6066                     if (!playerdetail || skeleton.free == 3) {
6067                         for (j = 0; j < skeleton.muscles[i].numverticeslow; j++) {
6068                             glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
6069                             glPushMatrix();
6070                             if (skeleton.muscles[i].parent1->label == abdomen || skeleton.muscles[i].parent2->label == abdomen)
6071                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
6072                                              (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
6073                                              (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
6074                             if (skeleton.muscles[i].parent1->label == lefthand || skeleton.muscles[i].parent1->label == righthand || skeleton.muscles[i].parent1->label == leftwrist || skeleton.muscles[i].parent1->label == rightwrist || skeleton.muscles[i].parent1->label == leftelbow || skeleton.muscles[i].parent1->label == rightelbow || skeleton.muscles[i].parent2->label == leftelbow || skeleton.muscles[i].parent2->label == rightelbow)
6075                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
6076                                              (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
6077                                              (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
6078                             if (skeleton.muscles[i].parent1->label == leftfoot || skeleton.muscles[i].parent1->label == rightfoot || skeleton.muscles[i].parent1->label == leftankle || skeleton.muscles[i].parent1->label == rightankle || skeleton.muscles[i].parent1->label == leftknee || skeleton.muscles[i].parent1->label == rightknee || skeleton.muscles[i].parent2->label == leftknee || skeleton.muscles[i].parent2->label == rightknee)
6079                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
6080                                              (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
6081                                              (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
6082                             if (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)
6083                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
6084                                              (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
6085                                              (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
6086
6087                             glGetFloatv(GL_MODELVIEW_MATRIX, M);
6088                             skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x = M[12] * scale;
6089                             skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y = M[13] * scale;
6090                             skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z = M[14] * scale;
6091                             glPopMatrix();
6092                         }
6093                     }
6094                     glPopMatrix();
6095                 }
6096                 if (skeleton.clothes && skeleton.muscles[i].numverticesclothes > 0) {
6097                     mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
6098
6099                     glMatrixMode(GL_MODELVIEW);                                                 // Select The Modelview Matrix
6100                     glPushMatrix();
6101                     glLoadIdentity();
6102                     if (!skeleton.free)
6103                         glRotatef(tilt2, 1, 0, 0);
6104                     if (!skeleton.free)
6105                         glRotatef(tilt, 0, 0, 1);
6106                     glTranslatef(mid.x, mid.y, mid.z);
6107                     skeleton.muscles[i].lastrotate1 = skeleton.muscles[i].rotate1;
6108                     glRotatef(-skeleton.muscles[i].lastrotate1 + 90, 0, 1, 0);
6109
6110                     skeleton.muscles[i].lastrotate2 = skeleton.muscles[i].rotate2;
6111                     glRotatef(-skeleton.muscles[i].lastrotate2 + 90, 0, 0, 1);
6112
6113                     skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
6114                     glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
6115
6116                     for (j = 0; j < skeleton.muscles[i].numverticesclothes; j++) {
6117                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6118                         glPushMatrix();
6119                         if (skeleton.muscles[i].parent1->label == abdomen || skeleton.muscles[i].parent2->label == abdomen)
6120                             glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
6121                                          (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
6122                                          (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
6123                         if (skeleton.muscles[i].parent1->label == lefthand || skeleton.muscles[i].parent1->label == righthand || skeleton.muscles[i].parent1->label == leftwrist || skeleton.muscles[i].parent1->label == rightwrist || skeleton.muscles[i].parent1->label == leftelbow || skeleton.muscles[i].parent1->label == rightelbow || skeleton.muscles[i].parent2->label == leftelbow || skeleton.muscles[i].parent2->label == rightelbow)
6124                             glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
6125                                          (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
6126                                          (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
6127                         if (skeleton.muscles[i].parent1->label == leftfoot || skeleton.muscles[i].parent1->label == rightfoot || skeleton.muscles[i].parent1->label == leftankle || skeleton.muscles[i].parent1->label == rightankle || skeleton.muscles[i].parent1->label == leftknee || skeleton.muscles[i].parent1->label == rightknee || skeleton.muscles[i].parent2->label == leftknee || skeleton.muscles[i].parent2->label == rightknee)
6128                             glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
6129                                          (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
6130                                          (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
6131                         if (skeleton.muscles[i].parent1->label == head || skeleton.muscles[i].parent2->label == head)
6132                             glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
6133                                          (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
6134                                          (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
6135                         glGetFloatv(GL_MODELVIEW_MATRIX, M);
6136                         skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x = M[12] * scale;
6137                         skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y = M[13] * scale;
6138                         skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z = M[14] * scale;
6139                         glPopMatrix();
6140                     }
6141                     glPopMatrix();
6142                 }
6143                 updatedelay = 1 + (float)(Random() % 100) / 1000;
6144             }
6145             if (skeleton.free != 2 && (skeleton.free == 1 || skeleton.free == 3 || id == 0 || (normalsupdatedelay <= 0) || animTarget == getupfromfrontanim || animTarget == getupfrombackanim || animCurrent == getupfromfrontanim || animCurrent == getupfrombackanim)) {
6146                 normalsupdatedelay = 1;
6147                 if (playerdetail || skeleton.free == 3)
6148                     skeleton.drawmodel.CalculateNormals(0);
6149                 if (!playerdetail || skeleton.free == 3)
6150                     skeleton.drawmodellow.CalculateNormals(0);
6151                 if (skeleton.clothes)
6152                     skeleton.drawmodelclothes.CalculateNormals(0);
6153             } else {
6154                 if (playerdetail || skeleton.free == 3)
6155                     skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
6156                 if (!playerdetail || skeleton.free == 3)
6157                     skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
6158                 if (skeleton.clothes) {
6159                     skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6160                 }
6161             }
6162         }
6163         framemult = .01;
6164         updatedelaychange = -framemult * 4 * (45 - findDistance(&viewer, &coords) * 1);
6165         if (updatedelaychange > -realmultiplier * 30)
6166             updatedelaychange = -realmultiplier * 30;
6167         if (updatedelaychange > -framemult * 4)
6168             updatedelaychange = -framemult * 4;
6169         if (skeleton.free == 1)
6170             updatedelaychange *= 6;
6171         if (id == 0)
6172             updatedelaychange *= 8;
6173         updatedelay += updatedelaychange;
6174
6175         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6176         glPushMatrix();
6177         if (!skeleton.free)
6178             glTranslatef(coords.x, coords.y - .02, coords.z);
6179         if (skeleton.free)
6180             glTranslatef(coords.x, coords.y - .02, coords.z);
6181         if (!skeleton.free)
6182             glTranslatef(offset.x * scale, offset.y * scale, offset.z * scale);
6183         if (!skeleton.free)
6184             glRotatef(yaw, 0, 1, 0);
6185         if (showpoints) {
6186             glPointSize(5);
6187             glColor4f(.4, 1, .4, 1);
6188             glDisable(GL_LIGHTING);
6189             glDisable(GL_TEXTURE_2D);
6190             glBegin(GL_POINTS);
6191             if (playerdetail)
6192                 for (i = 0; i < skeleton.drawmodel.vertexNum; i++) {
6193                     glVertex3f(skeleton.drawmodel.vertex[i].x, skeleton.drawmodel.vertex[i].y, skeleton.drawmodel.vertex[i].z);
6194                 }
6195             glEnd();
6196             glBegin(GL_LINES);
6197
6198             if (playerdetail)
6199                 for (i = 0; i < skeleton.drawmodel.TriangleNum; i++) {
6200                     glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].z);
6201                     glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].z);
6202                     glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].z);
6203                     glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].z);
6204                     glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].z);
6205                     glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].x, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].y, skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].z);
6206                 }
6207
6208             glEnd();
6209         }
6210
6211         terrainlight = terrain.getLighting(coords.x, coords.z);
6212         distance = distsq(&viewer, &coords);
6213         distance = (viewdistance * viewdistance - (distance - (viewdistance * viewdistance * fadestart)) * (1 / (1 - fadestart))) / viewdistance / viewdistance;
6214         if (distance > 1)
6215             distance = 1;
6216         if (distance > 0) {
6217             terrainheight = (coords.y - terrain.getHeight(coords.x, coords.z)) / 3 + 1;
6218             if (terrainheight < 1)
6219                 terrainheight = 1;
6220             if (terrainheight > 1.7)
6221                 terrainheight = 1.7;
6222
6223             //burnt=0;
6224             glColor4f((1 - (1 - terrainlight.x) / terrainheight) - burnt, (1 - (1 - terrainlight.y) / terrainheight) - burnt, (1 - (1 - terrainlight.z) / terrainheight) - burnt, distance);
6225             glDisable(GL_BLEND);
6226             glAlphaFunc(GL_GREATER, 0.0001);
6227             glEnable(GL_TEXTURE_2D);
6228             if (cellophane) {
6229                 glDisable(GL_TEXTURE_2D);
6230                 glColor4f(.7, .35, 0, .5);
6231                 glDepthMask(0);
6232                 glEnable(GL_LIGHTING);
6233                 glEnable(GL_BLEND);
6234             }
6235             if (tutoriallevel && id != 0) {
6236                 //glDisable(GL_TEXTURE_2D);
6237                 glColor4f(.7, .7, .7, 0.6);
6238                 glDepthMask(0);
6239                 glEnable(GL_LIGHTING);
6240                 glEnable(GL_BLEND);
6241                 if (canattack && cananger)
6242                     if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6243                         glDisable(GL_TEXTURE_2D);
6244                         glColor4f(1, 0, 0, 0.8);
6245                     }
6246                 glMatrixMode(GL_TEXTURE);
6247                 glPushMatrix();
6248                 glTranslatef(0, -smoketex, 0);
6249                 glTranslatef(-smoketex, 0, 0);
6250             }
6251             if (playerdetail) {
6252                 if (!showpoints) {
6253                     if ((tutoriallevel && id != 0))
6254                         skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6255                     else
6256                         skeleton.drawmodel.draw();
6257                 }
6258             }
6259             if (!playerdetail) {
6260                 if ((tutoriallevel && id != 0))
6261                     skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6262                 else
6263                     skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6264             }
6265
6266             if (!(animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed))
6267                 if (tutoriallevel && id != 0) {
6268                     glPopMatrix();
6269                     glMatrixMode(GL_MODELVIEW);
6270                     glEnable(GL_TEXTURE_2D);
6271                     glColor4f(.7, .7, .7, 0.6);
6272                     glDepthMask(0);
6273                     glEnable(GL_LIGHTING);
6274                     glEnable(GL_BLEND);
6275                     if (canattack && cananger)
6276                         if (animation[animTarget].attack == normalattack || animation[animTarget].attack == reversed) {
6277                             glDisable(GL_TEXTURE_2D);
6278                             glColor4f(1, 0, 0, 0.8);
6279                         }
6280                     glMatrixMode(GL_TEXTURE);
6281                     glPushMatrix();
6282                     glTranslatef(0, -smoketex * .6, 0);
6283                     glTranslatef(smoketex * .6, 0, 0);
6284                     if (playerdetail) {
6285                         if (!showpoints) {
6286                             if ((tutoriallevel && id != 0))
6287                                 skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6288                             else
6289                                 skeleton.drawmodel.draw();
6290                         }
6291                     }
6292                     if (!playerdetail) {
6293                         if ((tutoriallevel && id != 0))
6294                             skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6295                         else
6296                             skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6297                     }
6298                 }
6299
6300
6301             if (tutoriallevel && id != 0) {
6302                 glPopMatrix();
6303                 glMatrixMode(GL_MODELVIEW);
6304                 glEnable(GL_TEXTURE_2D);
6305             }
6306             if (skeleton.clothes) {
6307                 glDepthMask(0);
6308                 glEnable(GL_BLEND);
6309                 if (!immediate)
6310                     skeleton.drawmodelclothes.draw();
6311                 if (immediate)
6312                     skeleton.drawmodelclothes.drawimmediate();
6313                 glDepthMask(1);
6314             }
6315         }
6316         glPopMatrix();
6317
6318         if (num_weapons > 0) {
6319             for (k = 0; k < num_weapons; k++) {
6320                 i = weaponids[k];
6321                 if (weaponactive == k) {
6322                     if (weapons[i].getType() != staff) {
6323                         for (j = 0; j < skeleton.num_muscles; j++) {
6324                             if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6325                                 weaponattachmuscle = j;
6326                             }
6327                         }
6328                         for (j = 0; j < skeleton.num_muscles; j++) {
6329                             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) {
6330                                 weaponrotatemuscle = j;
6331                             }
6332                         }
6333                         weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6334                         if (creature == wolftype)
6335                             weaponpoint = (skeleton.joints[skeleton.jointlabels[rightwrist]].position * .7 + skeleton.joints[skeleton.jointlabels[righthand]].position * .3);
6336                     }
6337                     if (weapons[i].getType() == staff) {
6338                         for (j = 0; j < skeleton.num_muscles; j++) {
6339                             if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
6340                                 weaponattachmuscle = j;
6341                             }
6342                         }
6343                         for (j = 0; j < skeleton.num_muscles; j++) {
6344                             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) {
6345                                 weaponrotatemuscle = j;
6346                             }
6347                         }
6348                         //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
6349                         weaponpoint = (skeleton.muscles[weaponattachmuscle].parent1->position + skeleton.muscles[weaponattachmuscle].parent2->position) / 2;
6350                         //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6351                         XYZ tempnormthing, vec1, vec2;
6352                         vec1 = (skeleton.joints[skeleton.jointlabels[rightwrist]].position - skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6353                         vec2 = (skeleton.joints[skeleton.jointlabels[rightwrist]].position - skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
6354                         CrossProduct(&vec1, &vec2, &tempnormthing);
6355                         Normalise(&tempnormthing);
6356                         if (animTarget != staffhitanim && animCurrent != staffhitanim && animTarget != staffgroundsmashanim && animCurrent != staffgroundsmashanim && animTarget != staffspinhitanim && animCurrent != staffspinhitanim)
6357                             weaponpoint += tempnormthing * .1 - skeleton.specialforward[1] * .3 + (skeleton.joints[skeleton.jointlabels[rightwrist]].position - skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6358                     }
6359                 }
6360                 if (weaponactive != k && weaponstuck != k) {
6361                     if (weapons[i].getType() == knife)
6362                         weaponpoint = skeleton.joints[skeleton.jointlabels[abdomen]].position + (skeleton.joints[skeleton.jointlabels[righthip]].position - skeleton.joints[skeleton.jointlabels[lefthip]].position) * .1 + (skeleton.joints[skeleton.jointlabels[rightshoulder]].position - skeleton.joints[skeleton.jointlabels[leftshoulder]].position) * .35;
6363                     if (weapons[i].getType() == sword)
6364                         weaponpoint = skeleton.joints[skeleton.jointlabels[abdomen]].position + (skeleton.joints[skeleton.jointlabels[lefthip]].position - skeleton.joints[skeleton.jointlabels[righthip]].position) * .09 + (skeleton.joints[skeleton.jointlabels[leftshoulder]].position - skeleton.joints[skeleton.jointlabels[rightshoulder]].position) * .33;
6365                     if (weapons[i].getType() == staff)
6366                         weaponpoint = skeleton.joints[skeleton.jointlabels[abdomen]].position + (skeleton.joints[skeleton.jointlabels[lefthip]].position - skeleton.joints[skeleton.jointlabels[righthip]].position) * .09 + (skeleton.joints[skeleton.jointlabels[leftshoulder]].position - skeleton.joints[skeleton.jointlabels[rightshoulder]].position) * .33;
6367                     for (j = 0; j < skeleton.num_muscles; j++) {
6368                         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) {
6369                             weaponrotatemuscle = j;
6370                         }
6371                     }
6372                 }
6373                 if (weaponstuck == k) {
6374                     if (weaponstuckwhere == 0)
6375                         weaponpoint = skeleton.joints[skeleton.jointlabels[abdomen]].position * .5 + skeleton.joints[skeleton.jointlabels[neck]].position * .5 - skeleton.forward * .8;
6376                     else
6377                         weaponpoint = skeleton.joints[skeleton.jointlabels[abdomen]].position * .5 + skeleton.joints[skeleton.jointlabels[neck]].position * .5 + skeleton.forward * .8;
6378                     for (j = 0; j < skeleton.num_muscles; j++) {
6379                         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) {
6380                             weaponrotatemuscle = j;
6381                         }
6382                     }
6383                 }
6384                 if (skeleton.free) {
6385                     weapons[i].position = weaponpoint * scale + coords;
6386                     weapons[i].bigrotation = 0;
6387                     weapons[i].bigtilt = 0;
6388                     weapons[i].bigtilt2 = 0;
6389                 } else {
6390                     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;
6391                     weapons[i].bigrotation = yaw;
6392                     weapons[i].bigtilt = tilt;
6393                     weapons[i].bigtilt2 = tilt2;
6394                 }
6395                 weapons[i].rotation1 = skeleton.muscles[weaponrotatemuscle].lastrotate1;
6396                 weapons[i].rotation2 = skeleton.muscles[weaponrotatemuscle].lastrotate2;
6397                 weapons[i].rotation3 = skeleton.muscles[weaponrotatemuscle].lastrotate3;
6398                 if (weaponactive == k) {
6399                     if (weapons[i].getType() == knife) {
6400                         weapons[i].smallrotation = 180;
6401                         weapons[i].smallrotation2 = 0;
6402                         if (isCrouch() || wasCrouch()) {
6403                             weapons[i].smallrotation2 = 20;
6404                         }
6405                         if (animTarget == hurtidleanim) {
6406                             weapons[i].smallrotation2 = 50;
6407                         }
6408                         if ((animCurrent == crouchstabanim && animTarget == crouchstabanim) || (animCurrent == backhandspringanim && animTarget == backhandspringanim)) {
6409                             XYZ temppoint1, temppoint2, tempforward;
6410                             float distance;
6411
6412                             temppoint1 = skeleton.joints[skeleton.jointlabels[righthand]].position;
6413                             temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6414                             distance = findDistance(&temppoint1, &temppoint2);
6415                             weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6416                             weapons[i].rotation2 *= 360 / 6.28;
6417                             temppoint1.y = 0;
6418                             temppoint2.y = 0;
6419                             weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6420                             weapons[i].rotation1 *= 360 / 6.28;
6421                             weapons[i].rotation3 = 0;
6422                             weapons[i].smallrotation = -90;
6423                             weapons[i].smallrotation2 = 0;
6424                             if (temppoint1.x > temppoint2.x)
6425                                 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6426                         }
6427                         if ((animCurrent == knifeslashreversalanim && animTarget == knifeslashreversalanim) || (animCurrent == knifeslashreversedanim && animTarget == knifeslashreversedanim)) {
6428                             XYZ temppoint1, temppoint2, tempforward;
6429                             float distance;
6430
6431                             temppoint1 = skeleton.joints[skeleton.jointlabels[righthand]].position;
6432                             temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6433                             distance = findDistance(&temppoint1, &temppoint2);
6434                             weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6435                             weapons[i].rotation2 *= 360 / 6.28;
6436                             temppoint1.y = 0;
6437                             temppoint2.y = 0;
6438                             weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6439                             weapons[i].rotation1 *= 360 / 6.28;
6440                             weapons[i].rotation3 = 0;
6441                             weapons[i].smallrotation = 90;
6442                             weapons[i].smallrotation2 = 0;
6443                             if (temppoint1.x > temppoint2.x)
6444                                 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6445                         }
6446                         if (animTarget == knifethrowanim) {
6447                             weapons[i].smallrotation = 90;
6448                             //weapons[i].smallrotation2=-90;
6449                             weapons[i].smallrotation2 = 0;
6450                             weapons[i].rotation1 = 0;
6451                             weapons[i].rotation2 = 0;
6452                             weapons[i].rotation3 = 0;
6453                         }
6454                         if (animTarget == knifesneakattackanim && frameTarget < 5) {
6455                             weapons[i].smallrotation = -90;
6456                             weapons[i].rotation1 = 0;
6457                             weapons[i].rotation2 = 0;
6458                             weapons[i].rotation3 = 0;
6459                         }
6460                     }
6461                     if (weapons[i].getType() == sword) {
6462                         weapons[i].smallrotation = 0;
6463                         weapons[i].smallrotation2 = 0;
6464                         if (animTarget == knifethrowanim) {
6465                             weapons[i].smallrotation = -90;
6466                             weapons[i].smallrotation2 = 0;
6467                             weapons[i].rotation1 = 0;
6468                             weapons[i].rotation2 = 0;
6469                             weapons[i].rotation3 = 0;
6470                         }
6471                         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)) {
6472                             XYZ temppoint1, temppoint2, tempforward;
6473                             float distance;
6474
6475                             temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6476                             temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6477                             distance = findDistance(&temppoint1, &temppoint2);
6478                             weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6479                             weapons[i].rotation2 *= 360 / 6.28;
6480                             temppoint1.y = 0;
6481                             temppoint2.y = 0;
6482                             weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6483                             weapons[i].rotation1 *= 360 / 6.28;
6484                             weapons[i].rotation3 = 0;
6485                             weapons[i].smallrotation = 90;
6486                             weapons[i].smallrotation2 = 0;
6487                             if (temppoint1.x > temppoint2.x)
6488                                 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6489                         }
6490                     }
6491                     if (weapons[i].getType() == staff) {
6492                         weapons[i].smallrotation = 100;
6493                         weapons[i].smallrotation2 = 0;
6494                         if ((animTarget == staffhitanim && animCurrent == staffhitanim) || (animTarget == staffhitreversedanim && animCurrent == staffhitreversedanim) || (animTarget == staffspinhitreversedanim && animCurrent == staffspinhitreversedanim) || (animTarget == staffgroundsmashanim && animCurrent == staffgroundsmashanim) || (animTarget == staffspinhitanim && animCurrent == staffspinhitanim)) {
6495                             XYZ temppoint1, temppoint2, tempforward;
6496                             float distance;
6497
6498                             temppoint1 = animation[animCurrent].position[skeleton.jointlabels[righthand]][frameCurrent] * (1 - target) + animation[animTarget].position[skeleton.jointlabels[righthand]][frameTarget] * (target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6499                             temppoint2 = animation[animCurrent].weapontarget[frameCurrent] * (1 - target) + animation[animTarget].weapontarget[frameTarget] * (target);
6500                             distance = findDistance(&temppoint1, &temppoint2);
6501                             weapons[i].rotation2 = asin((temppoint1.y - temppoint2.y) / distance);
6502                             weapons[i].rotation2 *= 360 / 6.28;
6503                             temppoint1.y = 0;
6504                             temppoint2.y = 0;
6505                             weapons[i].rotation1 = acos((temppoint1.z - temppoint2.z) / findDistance(&temppoint1, &temppoint2));
6506                             weapons[i].rotation1 *= 360 / 6.28;
6507                             weapons[i].rotation3 = 0;
6508                             weapons[i].smallrotation = 90;
6509                             weapons[i].smallrotation2 = 0;
6510                             if (temppoint1.x > temppoint2.x)
6511                                 weapons[i].rotation1 = 360 - weapons[i].rotation1;
6512                         }
6513                     }
6514                 }
6515                 if (weaponactive != k && weaponstuck != k) {
6516                     if (weapons[i].getType() == knife) {
6517                         weapons[i].smallrotation = -70;
6518                         weapons[i].smallrotation2 = 10;
6519                     }
6520                     if (weapons[i].getType() == sword) {
6521                         weapons[i].smallrotation = -100;
6522                         weapons[i].smallrotation2 = -8;
6523                     }
6524                     if (weapons[i].getType() == staff) {
6525                         weapons[i].smallrotation = -100;
6526                         weapons[i].smallrotation2 = -8;
6527                     }
6528                 }
6529                 if (weaponstuck == k) {
6530                     if (weaponstuckwhere == 0)
6531                         weapons[i].smallrotation = 180;
6532                     else
6533                         weapons[i].smallrotation = 0;
6534                     weapons[i].smallrotation2 = 10;
6535                 }
6536             }
6537         }
6538     }
6539
6540     calcrot = 0;
6541     if (skeleton.free)
6542         calcrot = 1;
6543     if (animation[animTarget].attack || isRun() || animTarget == staggerbackhardanim || isFlip() || animTarget == climbanim || animTarget == sneakanim || animTarget == rollanim || animTarget == walkanim || animTarget == backhandspringanim || isFlip() || isWallJump())
6544         calcrot = 1;
6545     if (animCurrent != animTarget)
6546         calcrot = 1;
6547     //if(id==0)calcrot=1;
6548     if (skeleton.free == 2)
6549         calcrot = 0;
6550
6551     return 0;
6552 }
6553
6554
6555 int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6556 {
6557     static int i, j;
6558     static float distance;
6559     static float olddistance;
6560     static int intersecting;
6561     static int firstintersecting;
6562     static XYZ point;
6563     static XYZ oldp1;
6564     static XYZ start, end;
6565     static float slopethreshold = -.4;
6566
6567     firstintersecting = -1;
6568
6569     oldp1 = *p1;
6570     *p1 = *p1 - *move;
6571     if (distsq(p1, &model->boundingspherecenter) > radius * radius + model->boundingsphereradius * model->boundingsphereradius)
6572         return -1;
6573     if (*rotate)
6574         *p1 = DoRotation(*p1, 0, -*rotate, 0);
6575     for (i = 0; i < 4; i++) {
6576         for (j = 0; j < model->TriangleNum; j++) {
6577             if (model->facenormals[j].y <= slopethreshold) {
6578                 intersecting = 0;
6579                 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)));
6580                 if (distance < radius) {
6581                     point = *p1 - model->facenormals[j] * distance;
6582                     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]]))
6583                         intersecting = 1;
6584                     if (!intersecting)
6585                         intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6586                                                          &model->vertex[model->Triangles[j].vertex[1]],
6587                                                          p1, &radius);
6588                     if (!intersecting)
6589                         intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6590                                                          &model->vertex[model->Triangles[j].vertex[2]],
6591                                                          p1, &radius);
6592                     if (!intersecting)
6593                         intersecting = sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6594                                                          &model->vertex[model->Triangles[j].vertex[2]],
6595                                                          p1, &radius);
6596                     end = *p1 - point;
6597                     if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6598                         start = *p1;
6599                         end = *p1;
6600                         end.y -= radius;
6601                         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)) {
6602                             p1->y = point.y + radius;
6603                             if ((animTarget == jumpdownanim || isFlip())) {
6604                                 if (isFlip() && (frameTarget < 5 || animation[animTarget].label[frameTarget] == 7 || animation[animTarget].label[frameTarget] == 4))
6605                                     RagDoll(0);
6606
6607                                 if (animTarget == jumpupanim) {
6608                                     jumppower = -4;
6609                                     animTarget = getIdle();
6610                                 }
6611                                 target = 0;
6612                                 frameTarget = 0;
6613                                 onterrain = 1;
6614
6615                                 if (id == 0) {
6616                                     pause_sound(whooshsound);
6617                                     OPENAL_SetVolume(channels[whooshsound], 0);
6618                                 }
6619
6620                                 if ((animTarget == jumpdownanim || isFlip()) && !wasLanding() && !wasLandhard()) {
6621                                     if (isFlip())
6622                                         jumppower = -4;
6623                                     animTarget = getLanding();
6624                                     emit_sound_at(landsound, coords, 128.);
6625
6626                                     if (id == 0) {
6627                                         envsound[numenvsounds] = coords;
6628                                         envsoundvol[numenvsounds] = 16;
6629                                         envsoundlife[numenvsounds] = .4;
6630                                         numenvsounds++;
6631                                     }
6632                                 }
6633                             }
6634                         }
6635                     }
6636                 }
6637                 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6638                     olddistance = distance;
6639                     firstintersecting = j;
6640                     *p = point;
6641                 }
6642             }
6643         }
6644         for (j = 0; j < model->TriangleNum; j++) {
6645             if (model->facenormals[j].y > slopethreshold) {
6646                 intersecting = 0;
6647                 start = *p1;
6648                 start.y -= radius / 4;
6649                 distance = abs((model->facenormals[j].x * start.x) + (model->facenormals[j].y * start.y) + (model->facenormals[j].z * start.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)));
6650                 if (distance < radius * .5) {
6651                     point = start - model->facenormals[j] * distance;
6652                     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]]))
6653                         intersecting = 1;
6654                     if (!intersecting)
6655                         intersecting = sphere_line_intersection(model->vertex[model->Triangles[j].vertex[0]].x, model->vertex[model->Triangles[j].vertex[0]].y, model->vertex[model->Triangles[j].vertex[0]].z,
6656                                                          model->vertex[model->Triangles[j].vertex[1]].x, model->vertex[model->Triangles[j].vertex[1]].y, model->vertex[model->Triangles[j].vertex[1]].z,
6657                                                          p1->x, p1->y, p1->z, radius / 2);
6658                     if (!intersecting)
6659                         intersecting = sphere_line_intersection(model->vertex[model->Triangles[j].vertex[1]].x, model->vertex[model->Triangles[j].vertex[1]].y, model->vertex[model->Triangles[j].vertex[1]].z,
6660                                                          model->vertex[model->Triangles[j].vertex[2]].x, model->vertex[model->Triangles[j].vertex[2]].y, model->vertex[model->Triangles[j].vertex[2]].z,
6661                                                          p1->x, p1->y, p1->z, radius / 2);
6662                     if (!intersecting)
6663                         intersecting = sphere_line_intersection(model->vertex[model->Triangles[j].vertex[0]].x, model->vertex[model->Triangles[j].vertex[0]].y, model->vertex[model->Triangles[j].vertex[0]].z,
6664                                                          model->vertex[model->Triangles[j].vertex[2]].x, model->vertex[model->Triangles[j].vertex[2]].y, model->vertex[model->Triangles[j].vertex[2]].z,
6665                                                          p1->x, p1->y, p1->z, radius / 2);
6666                     end = *p1 - point;
6667                     if (dotproduct(&model->facenormals[j], &end) > 0 && intersecting) {
6668                         if ((animTarget == jumpdownanim || animTarget == jumpupanim || isFlip())) {
6669                             start = velocity;
6670                             velocity -= DoRotation(model->facenormals[j], 0, *rotate, 0) * findLength(&velocity) * abs(normaldotproduct(velocity, DoRotation(model->facenormals[j], 0, *rotate, 0))); //(distance-radius*.5)/multiplier;
6671                             if (findLengthfast(&start) < findLengthfast(&velocity))
6672                                 velocity = start;
6673                         }
6674                         *p1 += model->facenormals[j] * (distance - radius * .5);
6675                     }
6676                 }
6677                 if ((distance < olddistance || firstintersecting == -1) && intersecting) {
6678                     olddistance = distance;
6679                     firstintersecting = j;
6680                     *p = point;
6681                 }
6682             }
6683         }
6684     }
6685     if (*rotate)
6686         *p = DoRotation(*p, 0, *rotate, 0);
6687     *p = *p + *move;
6688     if (*rotate)
6689         *p1 = DoRotation(*p1, 0, *rotate, 0);
6690     *p1 += *move;
6691     return firstintersecting;
6692 }