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