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