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