2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
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.
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.
15 See the GNU General Public License for more details.
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.
22 /**> HEADER FILES <**/
25 extern float multiplier;
26 extern Animation animation[animation_count];
27 extern FSOUND_SAMPLE *samp[100];
28 extern int channels[100];
29 extern Terrain terrain;
31 extern int environment;
32 extern Sprites sprites;
34 extern FRUSTUM frustum;
36 extern float realmultiplier;
38 extern float slomodelay;
39 extern bool cellophane;
40 extern float texdetail;
41 extern GLubyte bloodText[512*512*3];
42 extern int bloodtoggle;
43 extern Objects objects;
45 extern bool autoslomo;
46 extern float camerashake;
48 extern float terraindetail;
49 extern float viewdistance;
50 extern float blackout;
51 extern int difficulty;
52 extern Person player[maxplayers];
53 extern int numplayers;
56 extern float bonusvalue;
57 extern float bonustotal;
58 extern float bonustime;
59 extern int tutoriallevel;
60 extern int numthrowkill;
61 extern "C" void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
63 void Weapons::DoStuff(){
64 static int i,whichpatchx,whichpatchz,j,k,whichhit,m;
65 static XYZ start,end,colpoint,normalrot,footvel,footpoint;
66 static XYZ terrainnormal;
69 static XYZ newpoint1,newpoint2;
70 static float friction=3.5;
71 static float elasticity=.4;
72 static XYZ bounceness;
73 static float frictionness;
74 static float moveamount;
76 static float closestdistance;
77 static float distance;
79 static XYZ closestpoint;
80 static XYZ closestswordpoint;
82 static float proportion;
83 static float tempmult;
87 for(i=0;i<numweapons;i++){
91 if(damage[i]>=2&&type[i]==staff&&owner[i]!=-1){
94 gLoc[0]=tippoint[i].x;
95 gLoc[1]=tippoint[i].y;
96 gLoc[2]=tippoint[i].z;
100 PlaySoundEx( staffbreaksound, samp[staffbreaksound], NULL, true);
101 FSOUND_3D_SetAttributes(channels[staffbreaksound], gLoc, vel);
102 FSOUND_SetVolume(channels[staffbreaksound], 256);
103 FSOUND_SetPaused(channels[staffbreaksound], false);
106 //speed=(tippoint[i]-oldtippoint[i])/multiplier/6;
109 tempvel.x=float(abs(Random()%100)-50)/20;
110 tempvel.y=float(abs(Random()%100)-50)/20;
111 tempvel.z=float(abs(Random()%100)-50)/20;
113 sprites.MakeSprite(cloudimpactsprite, position[i]+(tippoint[i]-position[i])*((float)j-2)/8,tempvel*.5, 115/255,73/255,12/255, .15+float(abs(Random()%100)-50)/1000, .7);
116 tempvel.x=float(abs(Random()%100)-50)/20;
117 tempvel.y=float(abs(Random()%100)-50)/20;
118 tempvel.z=float(abs(Random()%100)-50)/20;
120 sprites.MakeSprite(splintersprite, position[i]+(tippoint[i]-position[i])*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
132 player[tempowner].num_weapons--;
133 if(player[tempowner].num_weapons){
134 player[tempowner].weaponids[0]=player[tempowner].weaponids[player[tempowner].num_weapons];
135 if(player[tempowner].weaponstuck==player[tempowner].num_weapons)player[tempowner].weaponstuck=0;
137 player[tempowner].weaponactive=-1;
140 oldposition[i]=position[i];
141 oldtippoint[i]=tippoint[i];
142 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&!physics[i]){
143 position[i]+=velocity[i]*multiplier;
144 tippoint[i]+=velocity[i]*multiplier;
145 whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale*terraindetail);
146 whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale*terraindetail);
147 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
148 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
149 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
150 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
151 start=oldtippoint[i];
153 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
155 if(objects.type[k]==treetrunktype){
156 objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),.1,1,Random()%360);
157 normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0);
159 if(type[i]==knife)position[i]=colpoint-normalrot*.1;
160 if(type[i]==sword)position[i]=colpoint-normalrot*.2;
161 if(type[i]==staff)position[i]=colpoint-normalrot*.2;
162 XYZ temppoint1,temppoint2,tempforward;
166 temppoint2=normalrot;
167 distance=findDistance(&temppoint1,&temppoint2);
168 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
169 rotation2[i]*=360/6.28;
172 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
173 rotation1[i]*=360/6.28;
174 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
185 gLoc[0]=position[i].x;
186 gLoc[1]=position[i].y;
187 gLoc[2]=position[i].z;
191 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
192 FSOUND_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
193 FSOUND_SetVolume(channels[knifesheathesound], 128);
194 FSOUND_SetPaused(channels[knifesheathesound], false);
198 sprites.MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);
203 position[i]-=velocity[i]*multiplier;
204 tippoint[i]-=velocity[i]*multiplier;
205 tipvelocity[i]=velocity[i];
210 if(velocity[i].x||velocity[i].y||velocity[i].z)
211 for(j=0;j<numplayers;j++){
213 footpoint=DoRotation((player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].position+player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].position)/2,0,player[j].rotation,0)*player[j].scale+player[j].coords;
214 if(owner[i]==-1&&findDistancefastflat(&position[i],&player[j].coords)<1.5&&findDistancefast(&position[i],&player[j].coords)<4&&player[j].weaponstuck==-1&&!player[j].skeleton.free&&j!=oldowner[i]){
215 if((player[j].aitype!=attacktypecutoff||abs(Random()%6)==0||(player[j].targetanimation!=backhandspringanim&&player[j].targetanimation!=rollanim&&player[j].targetanimation!=flipanim&&Random()%2==0))&&!missed[i]){
217 if((player[j].creature==wolftype&&Random()%3!=0&&player[j].weaponactive==-1&&(player[j].isIdle()||player[j].isRun()||player[j].targetanimation==walkanim))||(player[j].creature==rabbittype&&Random()%2==0&&player[j].aitype==attacktypecutoff&&player[j].weaponactive==-1)){
220 gLoc[0]=player[j].coords.x;
221 gLoc[1]=player[j].coords.y;
222 gLoc[2]=player[j].coords.z;
223 vel[0]=player[j].velocity.x;
224 vel[1]=player[j].velocity.y;
225 vel[2]=player[j].velocity.z;
226 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
227 FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
228 FSOUND_SetVolume(channels[knifedrawsound], 128);
229 FSOUND_SetPaused(channels[knifedrawsound], false);
231 player[j].weaponactive=0;
232 player[j].targetanimation=removeknifeanim;
233 player[j].targetframe=1;
235 owner[i]=player[j].id;
236 if(player[j].num_weapons>0){
237 player[j].weaponids[player[j].num_weapons]=player[j].weaponids[0];
239 player[j].num_weapons++;
240 player[j].weaponids[0]=i;
242 player[j].aitype=attacktypecutoff;
245 if(j!=0)numthrowkill++;
246 player[j].num_weapons++;
247 player[j].weaponstuck=player[j].num_weapons-1;
248 if(normaldotproduct(player[j].facing,velocity[i])>0)player[j].weaponstuckwhere=1;
249 else player[j].weaponstuckwhere=0;
251 player[j].weaponids[player[j].num_weapons-1]=i;
253 player[j].RagDoll(0);
254 player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].velocity+=velocity[i]*2;
255 player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].velocity+=velocity[i]*2;
256 player[j].skeleton.joints[player[j].skeleton.jointlabels[rightshoulder]].velocity+=velocity[i]*2;
257 player[j].skeleton.joints[player[j].skeleton.jointlabels[leftshoulder]].velocity+=velocity[i]*2;
258 //player[j].Puff(abdomen);
259 if(bloodtoggle&&tutoriallevel!=1)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
260 if(tutoriallevel==1)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
261 footvel=tippoint[i]-position[i];
263 if(bloodtoggle&&tutoriallevel!=1)sprites.MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
265 if(tutoriallevel!=1){
266 if(player[j].weaponstuckwhere==0)player[j].DoBloodBig(2,205);
267 if(player[j].weaponstuckwhere==1)player[j].DoBloodBig(2,200);
268 player[j].damage+=200/player[j].armorhigh;
269 player[j].deathbleeding=1;
270 player[j].bloodloss+=(200+abs((float)(Random()%40))-20)/player[j].armorhigh;
278 gLoc[0]=position[i].x;
279 gLoc[1]=position[i].y;
280 gLoc[2]=position[i].z;
284 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
285 FSOUND_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
286 FSOUND_SetVolume(channels[fleshstabsound], 128);
287 FSOUND_SetPaused(channels[fleshstabsound], false);
289 if(animation[player[0].targetanimation].height==highheight){
304 if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
305 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
307 if(terrain.lineTerrain(oldposition[i],position[i],&colpoint)!=-1){
308 position[i]=colpoint*terrain.scale;
310 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
312 terrain.MakeDecal(shadowdecalpermanent,position[i],.06,.5,0);
313 normalrot=terrain.getNormal(position[i].x,position[i].z)*-1;
315 //position[i]-=normalrot*.1;
316 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
320 glRotatef(bigrotation[i],0,1,0);
321 glRotatef(bigtilt2[i],1,0,0);
322 glRotatef(bigtilt[i],0,0,1);
323 glRotatef(-rotation1[i]+90,0,1,0);
324 glRotatef(-rotation2[i]+90,0,0,1);
325 glRotatef(-rotation3[i],0,1,0);
326 glRotatef(smallrotation[i],1,0,0);
327 glRotatef(smallrotation2[i],0,1,0);
329 glGetFloatv(GL_MODELVIEW_MATRIX,M);
334 position[i]-=tippoint[i]*.15;
335 XYZ temppoint1,temppoint2,tempforward;
347 gLoc[0]=position[i].x;
348 gLoc[1]=position[i].y;
349 gLoc[2]=position[i].z;
353 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
354 FSOUND_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
355 FSOUND_SetVolume(channels[knifesheathesound], 128);
356 FSOUND_SetPaused(channels[knifesheathesound], false);
359 terrainlight=terrain.getLighting(position[i].x,position[i].z);
360 if(environment==snowyenvironment){
361 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
363 else if(environment==grassyenvironment){
364 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
366 else if(environment==desertenvironment){
367 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
375 position[i]-=velocity[i]*multiplier;
376 tippoint[i]-=velocity[i]*multiplier;
377 tipvelocity[i]=velocity[i];
380 if(velocity[i].x!=0||velocity[i].z!=0||velocity[i].y!=0){
381 velocity[i].y+=gravity*multiplier;
383 XYZ temppoint1,temppoint2,tempforward;
387 temppoint2=velocity[i];
388 distance=findDistance(&temppoint1,&temppoint2);
389 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
390 rotation2[i]*=360/6.28;
393 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
394 rotation1[i]*=360/6.28;
401 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
411 for(int l=0;l<10;l++){
412 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&physics[i]){
414 position[i]+=velocity[i]*multiplier;
415 tippoint[i]+=tipvelocity[i]*multiplier;
418 midp=(position[i]*mass[i]+tippoint[i]*tipmass[i])/(mass[i]+tipmass[i]);
419 vel=tippoint[i]-midp;
421 newpoint1=midp-vel*length[i]*(tipmass[i]/(mass[i]+tipmass[i]));
422 newpoint2=midp+vel*length[i]*(mass[i]/(mass[i]+tipmass[i]));
424 if(freetime[i]>.04)velocity[i]=velocity[i]+(newpoint1-position[i])/multiplier;
425 if(freetime[i]>.04)tipvelocity[i]=tipvelocity[i]+(newpoint2-tippoint[i])/multiplier;
427 position[i]=newpoint1;
428 tippoint[i]=newpoint2;
432 whichpatchx=(position[i].x)/(terrain.size/subdivision*terrain.scale*terraindetail);
433 whichpatchz=(position[i].z)/(terrain.size/subdivision*terrain.scale*terraindetail);
434 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
435 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
436 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
437 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
441 start=position[i]-(tippoint[i]-position[i])/5;
442 end=tippoint[i]+(tippoint[i]-position[i])/30;
443 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
446 diff=(colpoint-tippoint[i]);
450 position[i]+=(colpoint-tippoint[i])+diff*.05;
451 tippoint[i]=colpoint+diff*.05;
452 oldposition[i]=position[i];
453 oldtippoint[i]=tippoint[i];
457 start=tippoint[i]-(position[i]-tippoint[i])/5;
458 end=position[i]+(position[i]-tippoint[i])/30;
459 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
462 diff=(colpoint-position[i]);
466 tippoint[i]+=(colpoint-position[i])+diff*.05;
467 position[i]=colpoint+diff*.05;
468 oldtippoint[i]=tippoint[i];
469 oldposition[i]=tippoint[i];
474 start=oldposition[i];
476 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
479 position[i]=colpoint;
480 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
481 ReflectVector(&velocity[i],&terrainnormal);
482 position[i]+=terrainnormal*.002;
484 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
485 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
486 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
487 velocity[i]-=bounceness;
488 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
490 velocity[i]+=bounceness*elasticity;
492 if(findLengthfast(&bounceness)>1){
495 //int whichsound=clank1sound+abs(Random()%4);
497 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
498 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
499 gLoc[1]=position[i].y;
500 gLoc[2]=position[i].z;
504 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
505 FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
506 FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
507 FSOUND_SetPaused(channels[whichsound], false);
510 start=oldtippoint[i];
512 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
515 tippoint[i]=colpoint;
516 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
517 ReflectVector(&tipvelocity[i],&terrainnormal);
518 tippoint[i]+=terrainnormal*.002;
520 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
521 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
522 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
523 tipvelocity[i]-=bounceness;
524 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
525 else tipvelocity[i]=0;
526 tipvelocity[i]+=bounceness*elasticity;
528 if(findLengthfast(&bounceness)>1){
531 //int whichsound=clank1sound+abs(Random()%4);
533 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
534 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
535 gLoc[0]=position[i].x;
536 gLoc[1]=position[i].y;
537 gLoc[2]=position[i].z;
541 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
542 FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
543 FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
544 FSOUND_SetPaused(channels[whichsound], false);
548 if((objects.type[k]!=boxtype&&objects.type[k]!=platformtype&&objects.type[k]!=walltype&&objects.type[k]!=weirdtype)||objects.rotation2[k]!=0)
550 mid=(position[i]*(21+(float)m*10)+tippoint[i]*(19-(float)m*10))/40;
552 oldmid=(oldposition[i]*(21+(float)m*10)+oldtippoint[i]*(19-(float)m*10))/40;
556 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
560 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
561 ReflectVector(&velocity[i],&terrainnormal);
563 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
564 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
565 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
566 velocity[i]-=bounceness;
567 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
569 velocity[i]+=bounceness*elasticity;
571 if(findLengthfast(&bounceness)>1){
574 //int whichsound=clank1sound+abs(Random()%4);
576 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
577 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
583 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
584 FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
585 FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
586 FSOUND_SetPaused(channels[whichsound], false);
588 position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
591 mid=(position[i]*(19-(float)m*10)+tippoint[i]*(21+(float)m*10))/40;
593 oldmid=(oldposition[i]*(19-(float)m*10)+oldtippoint[i]*(21+(float)m*10))/40;
597 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
601 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
602 ReflectVector(&tipvelocity[i],&terrainnormal);
604 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
605 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
606 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
607 tipvelocity[i]-=bounceness;
608 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
609 else tipvelocity[i]=0;
610 tipvelocity[i]+=bounceness*elasticity;
612 if(findLengthfast(&bounceness)>1){
615 //int whichsound=clank1sound+abs(Random()%4);
617 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
618 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
624 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
625 FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
626 FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
627 FSOUND_SetPaused(channels[whichsound], false);
629 tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
636 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
640 closestswordpoint=colpoint;//(position[i]+tippoint[i])/2;
641 point[0]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]],0,objects.rotation[k],0)+objects.position[k];
642 point[1]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]],0,objects.rotation[k],0)+objects.position[k];
643 point[2]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]],0,objects.rotation[k],0)+objects.position[k];
644 if(DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance,&colpoint ))
645 if(distance<closestdistance||closestdistance==-1){
646 closestpoint=colpoint;
647 closestdistance=distance;
650 if(DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance,&colpoint ))
651 if(distance<closestdistance||closestdistance==-1){
652 closestpoint=colpoint;
653 closestdistance=distance;
656 if(DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance,&colpoint ))
657 if(distance<closestdistance||closestdistance==-1){
658 closestpoint=colpoint;
659 closestdistance=distance;
662 if(closestdistance!=-1&&isnormal(closestdistance)){
663 if(DistancePointLine(&closestpoint, &position[i], &tippoint[i], &distance,&colpoint )){
664 closestswordpoint=colpoint;
665 velocity[i]+=(closestpoint-closestswordpoint);
666 tipvelocity[i]+=(closestpoint-closestswordpoint);
667 position[i]+=(closestpoint-closestswordpoint);
668 tippoint[i]+=(closestpoint-closestswordpoint);
677 whichhit=terrain.lineTerrain(oldposition[i],position[i],&colpoint);
678 if(whichhit!=-1||position[i].y<terrain.getHeight(position[i].x,position[i].z)){
680 if(whichhit!=-1)position[i]=colpoint*terrain.scale;
681 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
683 terrainnormal=terrain.getNormal(position[i].x,position[i].z);
684 ReflectVector(&velocity[i],&terrainnormal);
685 position[i]+=terrainnormal*.002;
686 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
687 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
688 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
689 velocity[i]-=bounceness;
690 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
692 if(terrain.getOpacity(position[i].x,position[i].z)<.2)velocity[i]+=bounceness*elasticity*.3;
693 else velocity[i]+=bounceness*elasticity;
694 //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
695 if(findLengthfast(&bounceness)>1){
699 if(terrain.getOpacity(position[i].x,position[i].z)>.2){
700 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
701 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
703 else whichsound=footstepsound+abs(Random()%2);
704 gLoc[0]=position[i].x;
705 gLoc[1]=position[i].y;
706 gLoc[2]=position[i].z;
710 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
711 FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
712 if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
713 else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
714 FSOUND_SetPaused(channels[whichsound], false);
716 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
718 terrainlight=terrain.getLighting(position[i].x,position[i].z);
719 if(environment==snowyenvironment){
720 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
722 else if(environment==grassyenvironment){
723 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
725 else if(environment==desertenvironment){
726 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
731 whichhit=terrain.lineTerrain(oldtippoint[i],tippoint[i],&colpoint);
732 if(whichhit!=-1||tippoint[i].y<terrain.getHeight(tippoint[i].x,tippoint[i].z)){
733 if(whichhit!=-1)tippoint[i]=colpoint*terrain.scale;
734 else tippoint[i].y=terrain.getHeight(tippoint[i].x,tippoint[i].z);
736 terrainnormal=terrain.getNormal(tippoint[i].x,tippoint[i].z);
737 ReflectVector(&tipvelocity[i],&terrainnormal);
738 tippoint[i]+=terrainnormal*.002;
739 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
740 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
741 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
742 tipvelocity[i]-=bounceness;
743 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
744 else tipvelocity[i]=0;
745 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
746 else tipvelocity[i]+=bounceness*elasticity;
747 //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
749 if(findLengthfast(&bounceness)>1){
753 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
754 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
755 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
757 else whichsound=footstepsound+abs(Random()%2);
758 gLoc[0]=tippoint[i].x;
759 gLoc[1]=tippoint[i].y;
760 gLoc[2]=tippoint[i].z;
764 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
765 FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
766 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
767 else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
768 FSOUND_SetPaused(channels[whichsound], false);
770 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
772 terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
773 if(environment==snowyenvironment){
774 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
776 else if(environment==grassyenvironment){
777 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
779 else if(environment==desertenvironment){
780 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
787 mid=position[i]+tippoint[i];
789 mid+=(position[i]-mid)/20;
791 if(mid.y<terrain.getHeight(mid.x,mid.z)){
793 mid.y=terrain.getHeight(mid.x,mid.z);
795 terrainnormal=terrain.getNormal(mid.x,mid.z);
796 ReflectVector(&velocity[i],&terrainnormal);
797 //mid+=terrainnormal*.002;
798 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
799 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
800 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
801 velocity[i]-=bounceness;
802 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
804 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
805 else velocity[i]+=bounceness*elasticity;
807 if(findLengthfast(&bounceness)>1){
811 if(terrain.getOpacity(mid.x,mid.z)>.2){
812 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
813 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
815 else whichsound=footstepsound+abs(Random()%2);
822 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
823 FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
824 if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
825 else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
826 FSOUND_SetPaused(channels[whichsound], false);
828 position[i]+=(mid-oldmid)*20;
831 mid=position[i]+tippoint[i];
833 mid+=(tippoint[i]-mid)/20;
835 if(mid.y<terrain.getHeight(mid.x,mid.z)){
837 mid.y=terrain.getHeight(mid.x,mid.z);
839 terrainnormal=terrain.getNormal(mid.x,mid.z);
840 ReflectVector(&tipvelocity[i],&terrainnormal);
841 //mid+=terrainnormal*.002;
842 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
843 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
844 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
845 tipvelocity[i]-=bounceness;
846 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
847 else tipvelocity[i]=0;
848 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
849 else tipvelocity[i]+=bounceness*elasticity;
851 if(findLengthfast(&bounceness)>1){
855 if(terrain.getOpacity(mid.x,mid.z)>.2){
856 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
857 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
859 else whichsound=footstepsound+abs(Random()%2);
866 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
867 FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
868 if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
869 else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
870 FSOUND_SetPaused(channels[whichsound], false);
872 tippoint[i]+=(mid-oldmid)*20;
875 mid=position[i]+tippoint[i];
877 if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
879 position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
881 terrainnormal=terrain.getNormal(mid.x,mid.z);
882 ReflectVector(&velocity[i],&terrainnormal);
883 position[i]+=terrainnormal*.002;
884 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
885 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
886 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
887 velocity[i]-=bounceness;
888 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
890 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
891 else velocity[i]+=bounceness*elasticity;
893 if(findLengthfast(&bounceness)>1){
897 if(terrain.getOpacity(mid.x,mid.z)>.2){
898 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
899 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
901 else whichsound=footstepsound+abs(Random()%2);
902 gLoc[0]=position[i].x;
903 gLoc[1]=position[i].y;
904 gLoc[2]=position[i].z;
908 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
909 FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
910 if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
911 else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
912 FSOUND_SetPaused(channels[whichsound], false);
916 if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
918 tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
920 terrainnormal=terrain.getNormal(mid.x,mid.z);
921 ReflectVector(&tipvelocity[i],&terrainnormal);
922 tippoint[i]+=terrainnormal*.002;
923 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
924 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
925 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
926 tipvelocity[i]-=bounceness;
927 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
928 else tipvelocity[i]=0;
929 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
930 else tipvelocity[i]+=bounceness*elasticity;
932 if(findLengthfast(&bounceness)>1){
936 if(terrain.getOpacity(mid.x,mid.z)>.2){
937 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
938 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
940 else whichsound=footstepsound+abs(Random()%2);
941 gLoc[0]=tippoint[i].x;
942 gLoc[1]=tippoint[i].y;
943 gLoc[2]=tippoint[i].z;
947 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
948 FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
949 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
950 else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
951 FSOUND_SetPaused(channels[whichsound], false);
955 //Fix terrain edge collision
958 whichhit=terrain.lineTerrain(start,end,&colpoint);
969 tipvelocity[i].y+=.1;
972 whichhit=terrain.lineTerrain(start,end,&colpoint);
974 closestpoint=colpoint*terrain.scale;
979 tipvelocity[i].y-=.1;
982 whichhit=terrain.lineTerrain(start,end,&colpoint);
987 tipvelocity[i].y+=.01;
990 whichhit=terrain.lineTerrain(start,end,&colpoint);
992 closestpoint=colpoint*terrain.scale;
996 whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
998 colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
999 proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
1001 while(whichhit!=-1){
1002 position[i].y+=.1*proportion;
1003 tippoint[i].y+=.1*(1-proportion);
1004 velocity[i].y+=.1*proportion;
1005 tipvelocity[i].y+=.1*(1-proportion);
1008 whichhit=terrain.lineTerrain(start,end,&colpoint);
1010 position[i].y-=.1*proportion;
1011 tippoint[i].y-=.1*(1-proportion);
1012 velocity[i].y-=.1*proportion;
1013 tipvelocity[i].y-=.1*(1-proportion);
1016 whichhit=terrain.lineTerrain(start,end,&colpoint);
1017 while(whichhit!=-1){
1018 position[i].y+=.01*proportion;
1019 tippoint[i].y+=.01*(1-proportion);
1020 velocity[i].y+=.01*proportion;
1021 tipvelocity[i].y+=.01*(1-proportion);
1024 whichhit=terrain.lineTerrain(start,end,&colpoint);
1031 velocity[i].y+=gravity*multiplier;
1032 tipvelocity[i].y+=gravity*multiplier;
1033 //position[i].y+=gravity*multiplier*multiplier;
1034 //tippoint[i].y+=gravity*multiplier*multiplier;
1037 XYZ temppoint1,temppoint2,tempforward;
1040 temppoint1=position[i];
1041 temppoint2=tippoint[i];
1042 distance=findDistance(&temppoint1,&temppoint2);
1043 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
1044 rotation2[i]*=360/6.28;
1047 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
1048 rotation1[i]*=360/6.28;
1050 smallrotation[i]=90;
1051 smallrotation2[i]=0;
1055 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
1058 if(findLengthfast(&velocity[i])<.3&&findLengthfast(&tipvelocity[i])<.3&&hitsomething[i]){
1059 freetime[i]+=multiplier;
1062 //velocity[i]=(position[i]-oldposition[i])/multiplier;
1063 //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;
1071 multiplier=tempmult;
1072 if(blooddrip[i]&&bloody[i]){
1073 blooddripdelay[i]-=blooddrip[i]*multiplier/2;
1074 blooddrip[i]-=multiplier;
1075 if(blooddrip[i]<0)blooddrip[i]=0;
1076 if(blooddrip[i]>5)blooddrip[i]=5;
1077 if(blooddripdelay[i]<0&&bloodtoggle){
1078 blooddripdelay[i]=1;
1081 bloodloc=position[i]+(tippoint[i]-position[i])*.7;
1085 sprites.MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
1090 flamedelay[i]-=multiplier;
1091 if(onfire[i]&&flamedelay[i]<=0){
1093 flamedelay[i]-=multiplier;
1096 normalrot=player[owner[i]].velocity;
1100 if(player[owner[i]].onterrain){
1104 sprites.MakeSprite(weaponflamesprite, position[i]+tippoint[i]*(((float)abs(Random()%100))/600+.05),normalrot, 1,1,1, (.6+(float)abs(Random()%100)/200-.25)*1/3, 1);
1105 sprites.speed[sprites.numsprites-1]=4;
1106 sprites.alivetime[sprites.numsprites-1]=.3;
1110 if(!onfire[i]&&owner[i]==-1&&type[i]!=staff){
1111 flamedelay[i]-=multiplier;
1112 if(flamedelay[i]<=0){
1114 flamedelay[i]-=multiplier;
1116 if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
1118 shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
1119 sprites.MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
1120 sprites.speed[sprites.numsprites-1]=4;
1121 sprites.alivetime[sprites.numsprites-1]=.3;
1131 static XYZ terrainlight;
1132 static GLfloat M[16];
1134 glAlphaFunc(GL_GREATER, 0.9);
1135 glEnable(GL_TEXTURE_2D);
1137 glEnable(GL_CULL_FACE);
1138 glCullFace(GL_FRONT);
1140 for(i=0;i<numweapons;i++)
1142 if((frustum.SphereInFrustum(position[i].x,position[i].y,position[i].z,1)&&findDistancefast(&viewer,&position[i])<viewdistance*viewdistance))
1148 if(velocity[i].x&&!physics[i])drawhowmany[i]=10;
1149 else drawhowmany[i]=1;
1153 if(player[owner[i]].occluded<25)
1154 if((frustum.SphereInFrustum(player[owner[i]].coords.x,player[owner[i]].coords.y+player[owner[i]].scale*3,player[owner[i]].coords.z,player[owner[i]].scale*8)&&findDistancefast(&viewer,&player[owner[i]].coords)<viewdistance*viewdistance)||player[owner[i]].skeleton.free==3)
1156 if((player[owner[i]].targetanimation==knifeslashstartanim||player[owner[i]].targetanimation==swordsneakattackanim||(player[owner[i]].currentanimation==staffhitanim&&player[owner[i]].currentframe>1)||(player[owner[i]].currentanimation==staffhitreversedanim&&player[owner[i]].currentframe>1)||(player[owner[i]].currentanimation==staffspinhitanim&&player[owner[i]].currentframe>1)||(player[owner[i]].currentanimation==staffspinhitreversedanim&&player[owner[i]].currentframe>1)||(player[owner[i]].currentanimation==staffgroundsmashanim&&player[owner[i]].currentframe>1)||(player[owner[i]].targetanimation==swordslashanim&&player[owner[i]].targetframe<7)||player[owner[i]].targetanimation==crouchstabanim||player[owner[i]].targetanimation==swordslashreversalanim||player[owner[i]].targetanimation==swordslashreversedanim||player[owner[i]].targetanimation==knifefollowanim||player[owner[i]].targetanimation==swordgroundstabanim||player[owner[i]].targetanimation==knifethrowanim)&&player[owner[i]].targetanimation==lastdrawnanim[i]&&!player[owner[i]].skeleton.free)
1160 else drawhowmany[i]=1;
1161 if(player[owner[i]].targetanimation==swordgroundstabanim)
1163 lastdrawnrotation1[i]=rotation1[i];
1164 lastdrawnrotation2[i]=rotation2[i];
1165 lastdrawnrotation3[i]=rotation3[i];
1166 lastdrawnbigrotation[i]=bigrotation[i];
1167 lastdrawnbigtilt[i]=bigtilt[i];
1168 lastdrawnbigtilt2[i]=bigtilt2[i];
1169 lastdrawnsmallrotation[i]=smallrotation[i];
1170 lastdrawnsmallrotation2[i]=smallrotation2[i];
1175 terrainlight=terrain.getLighting(position[i].x,position[i].z);
1176 if(drawhowmany[i]>0)
1178 glAlphaFunc(GL_GREATER, 0.01);
1180 for(j=drawhowmany[i];j>0;j--)
1182 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1184 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany[i]);
1185 if(owner[i]!=-1)glTranslatef(position[i].x*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].x*(1-((float)(j))/drawhowmany[i]),position[i].y*(((float)(j))/drawhowmany[i])-.02+lastdrawnposition[i].y*(1-((float)(j))/drawhowmany[i]),position[i].z*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].z*(1-((float)(j))/drawhowmany[i]));
1186 if(owner[i]==-1)glTranslatef(position[i].x*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].x*(1-((float)(j))/drawhowmany[i]),position[i].y*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].y*(1-((float)(j))/drawhowmany[i]),position[i].z*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].z*(1-((float)(j))/drawhowmany[i]));
1187 //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1188 glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1189 glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1190 glRotatef(bigtilt[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt[i]*(1-((float)(j))/drawhowmany[i]),0,0,1);
1191 glRotatef(-rotation1[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation1[i]*(1-((float)(j))/drawhowmany[i])+90,0,1,0);
1192 glRotatef(-rotation2[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation2[i]*(1-((float)(j))/drawhowmany[i])+90,0,0,1);
1193 glRotatef(-rotation3[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation3[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1194 glRotatef(smallrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1195 glRotatef(smallrotation2[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation2[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1199 if(player[owner[i]].targetanimation==staffhitanim||player[owner[i]].currentanimation==staffhitanim||player[owner[i]].targetanimation==staffhitreversedanim||player[owner[i]].currentanimation==staffhitreversedanim)
1201 glTranslatef(0,0,-.3);
1203 if(player[owner[i]].targetanimation==staffgroundsmashanim||player[owner[i]].currentanimation==staffgroundsmashanim||player[owner[i]].targetanimation==staffspinhitreversedanim||player[owner[i]].currentanimation==staffspinhitreversedanim||player[owner[i]].targetanimation==staffspinhitanim||player[owner[i]].currentanimation==staffspinhitanim)
1205 glTranslatef(0,0,-.1);
1208 /*if(type[i]==knife){
1210 if(!physics[i]&&findDistance(&position[i],&oldposition[i])*5>1)glScalef(1,1,findDistance(&position[i],&oldposition[i])*5);
1216 glEnable(GL_LIGHTING);
1217 if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
1220 if(bloody[i]==1)throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
1221 if(bloody[i]==2)throwingknifemodel.drawdifftex(bloodknifetextureptr);
1226 glEnable(GL_LIGHTING);
1227 if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
1230 if(bloody[i]==1)swordmodel.drawdifftex(lightbloodswordtextureptr);
1231 if(bloody[i]==2)swordmodel.drawdifftex(bloodswordtextureptr);
1236 glEnable(GL_LIGHTING);
1237 staffmodel.drawdifftex(stafftextureptr);
1243 lastdrawnposition[i]=position[i];
1244 lastdrawntippoint[i]=tippoint[i];
1245 lastdrawnrotation1[i]=rotation1[i];
1246 lastdrawnrotation2[i]=rotation2[i];
1247 lastdrawnrotation3[i]=rotation3[i];
1248 lastdrawnbigrotation[i]=bigrotation[i];
1249 lastdrawnbigtilt[i]=bigtilt[i];
1250 lastdrawnbigtilt2[i]=bigtilt2[i];
1251 lastdrawnsmallrotation[i]=smallrotation[i];
1252 lastdrawnsmallrotation2[i]=smallrotation2[i];
1253 if(owner[i]!=-1)lastdrawnanim[i]=player[owner[i]].currentanimation;
1257 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1260 glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1261 glRotatef(bigrotation[i],0,1,0);
1262 glRotatef(bigtilt2[i],1,0,0);
1263 glRotatef(bigtilt[i],0,0,1);
1264 glRotatef(-rotation1[i]+90,0,1,0);
1265 glRotatef(-rotation2[i]+90,0,0,1);
1266 glRotatef(-rotation3[i],0,1,0);
1267 glRotatef(smallrotation[i],1,0,0);
1268 glRotatef(smallrotation2[i],0,1,0);
1269 glTranslatef(0,0,length[i]);
1270 glGetFloatv(GL_MODELVIEW_MATRIX,M);
1271 tippoint[i].x=M[12];
1272 tippoint[i].y=M[13];
1273 tippoint[i].z=M[14];
1279 shinepoint=position[i];
1280 sprites.MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1281 sprites.speed[sprites.numsprites-1]=4;
1282 sprites.alivetime[sprites.numsprites-1]=.3;
1283 shinepoint=tippoint[i];
1284 sprites.MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1285 sprites.speed[sprites.numsprites-1]=4;
1286 sprites.alivetime[sprites.numsprites-1]=.3;*/
1296 // Model throwingknifemodel;
1297 knifetextureptr = 0;
1298 lightbloodknifetextureptr = 0;
1299 bloodknifetextureptr = 0;
1301 // Model swordmodel;
1302 swordtextureptr = 0;
1303 lightbloodswordtextureptr = 0;
1304 bloodswordtextureptr = 0;
1306 // Model staffmodel;
1307 stafftextureptr = 0;
1312 if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
1313 if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
1314 if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
1315 if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
1316 if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
1317 if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
1318 if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );