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