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