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 <**/
24 #include "openal_wrapper.h"
25 #include "Animation.h"
30 extern float multiplier;
31 extern int channels[100];
32 extern Terrain terrain;
34 extern int environment;
36 extern FRUSTUM frustum;
38 extern float realmultiplier;
40 extern float slomodelay;
41 extern bool cellophane;
42 extern float texdetail;
43 extern GLubyte bloodText[512*512*3];
44 extern int bloodtoggle;
45 extern Objects objects;
47 extern bool autoslomo;
48 extern float camerashake;
50 extern float terraindetail;
51 extern float viewdistance;
52 extern float blackout;
53 extern int difficulty;
55 extern int tutoriallevel;
56 extern int numthrowkill;
57 extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
59 void Weapons::DoStuff(){
60 static int i,whichpatchx,whichpatchz,j,k,whichhit,m;
61 static XYZ start,end,colpoint,normalrot,footvel,footpoint;
62 static XYZ terrainnormal;
65 static XYZ newpoint1,newpoint2;
66 static float friction=3.5;
67 static float elasticity=.4;
68 static XYZ bounceness;
69 static float frictionness;
70 static float moveamount;
72 static float closestdistance;
73 static float distance;
75 static XYZ closestpoint;
76 static XYZ closestswordpoint;
78 static float proportion;
79 static float tempmult;
83 for(i=0;i<numweapons;i++){
87 if(damage[i]>=2&&type[i]==staff&&owner[i]!=-1){
90 gLoc[0]=tippoint[i].x;
91 gLoc[1]=tippoint[i].y;
92 gLoc[2]=tippoint[i].z;
96 PlaySoundEx( staffbreaksound, samp[staffbreaksound], NULL, true);
97 OPENAL_3D_SetAttributes(channels[staffbreaksound], gLoc, vel);
98 OPENAL_SetVolume(channels[staffbreaksound], 256);
99 OPENAL_SetPaused(channels[staffbreaksound], false);
102 //speed=(tippoint[i]-oldtippoint[i])/multiplier/6;
105 tempvel.x=float(abs(Random()%100)-50)/20;
106 tempvel.y=float(abs(Random()%100)-50)/20;
107 tempvel.z=float(abs(Random()%100)-50)/20;
109 Sprite::MakeSprite(splintersprite, position[i]+(tippoint[i]-position[i])*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
121 player[tempowner].num_weapons--;
122 if(player[tempowner].num_weapons){
123 player[tempowner].weaponids[0]=player[tempowner].weaponids[player[tempowner].num_weapons];
124 if(player[tempowner].weaponstuck==player[tempowner].num_weapons)player[tempowner].weaponstuck=0;
126 player[tempowner].weaponactive=-1;
129 oldposition[i]=position[i];
130 oldtippoint[i]=tippoint[i];
131 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&!physics[i]){
132 position[i]+=velocity[i]*multiplier;
133 tippoint[i]+=velocity[i]*multiplier;
134 whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale*terraindetail);
135 whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale*terraindetail);
136 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
137 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
138 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
139 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
140 start=oldtippoint[i];
142 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
144 if(objects.type[k]==treetrunktype){
145 objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),.1,1,Random()%360);
146 normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0);
148 if(type[i]==knife)position[i]=colpoint-normalrot*.1;
149 if(type[i]==sword)position[i]=colpoint-normalrot*.2;
150 if(type[i]==staff)position[i]=colpoint-normalrot*.2;
151 XYZ temppoint1,temppoint2,tempforward;
155 temppoint2=normalrot;
156 distance=findDistance(&temppoint1,&temppoint2);
157 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
158 rotation2[i]*=360/6.28;
161 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
162 rotation1[i]*=360/6.28;
163 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
174 gLoc[0]=position[i].x;
175 gLoc[1]=position[i].y;
176 gLoc[2]=position[i].z;
180 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
181 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
182 OPENAL_SetVolume(channels[knifesheathesound], 128);
183 OPENAL_SetPaused(channels[knifesheathesound], false);
187 Sprite::MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);
192 position[i]-=velocity[i]*multiplier;
193 tippoint[i]-=velocity[i]*multiplier;
194 tipvelocity[i]=velocity[i];
199 if(velocity[i].x||velocity[i].y||velocity[i].z)
200 for(j=0;j<numplayers;j++){
202 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;
203 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]){
204 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]){
206 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)){
209 gLoc[0]=player[j].coords.x;
210 gLoc[1]=player[j].coords.y;
211 gLoc[2]=player[j].coords.z;
212 vel[0]=player[j].velocity.x;
213 vel[1]=player[j].velocity.y;
214 vel[2]=player[j].velocity.z;
215 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
216 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
217 OPENAL_SetVolume(channels[knifedrawsound], 128);
218 OPENAL_SetPaused(channels[knifedrawsound], false);
220 player[j].weaponactive=0;
221 player[j].targetanimation=removeknifeanim;
222 player[j].targetframe=1;
224 owner[i]=player[j].id;
225 if(player[j].num_weapons>0){
226 player[j].weaponids[player[j].num_weapons]=player[j].weaponids[0];
228 player[j].num_weapons++;
229 player[j].weaponids[0]=i;
231 player[j].aitype=attacktypecutoff;
234 if(j!=0)numthrowkill++;
235 player[j].num_weapons++;
236 player[j].weaponstuck=player[j].num_weapons-1;
237 if(normaldotproduct(player[j].facing,velocity[i])>0)player[j].weaponstuckwhere=1;
238 else player[j].weaponstuckwhere=0;
240 player[j].weaponids[player[j].num_weapons-1]=i;
242 player[j].RagDoll(0);
243 player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].velocity+=velocity[i]*2;
244 player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].velocity+=velocity[i]*2;
245 player[j].skeleton.joints[player[j].skeleton.jointlabels[rightshoulder]].velocity+=velocity[i]*2;
246 player[j].skeleton.joints[player[j].skeleton.jointlabels[leftshoulder]].velocity+=velocity[i]*2;
247 //player[j].Puff(abdomen);
248 if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
249 if(tutoriallevel==1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
250 footvel=tippoint[i]-position[i];
252 if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
254 if(tutoriallevel!=1){
255 if(player[j].weaponstuckwhere==0)player[j].DoBloodBig(2,205);
256 if(player[j].weaponstuckwhere==1)player[j].DoBloodBig(2,200);
257 player[j].damage+=200/player[j].armorhigh;
258 player[j].deathbleeding=1;
259 player[j].bloodloss+=(200+abs((float)(Random()%40))-20)/player[j].armorhigh;
267 gLoc[0]=position[i].x;
268 gLoc[1]=position[i].y;
269 gLoc[2]=position[i].z;
273 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
274 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
275 OPENAL_SetVolume(channels[fleshstabsound], 128);
276 OPENAL_SetPaused(channels[fleshstabsound], false);
278 if(animation[player[0].targetanimation].height==highheight){
293 if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
294 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
296 if(terrain.lineTerrain(oldposition[i],position[i],&colpoint)!=-1){
297 position[i]=colpoint*terrain.scale;
299 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
301 terrain.MakeDecal(shadowdecalpermanent,position[i],.06,.5,0);
302 normalrot=terrain.getNormal(position[i].x,position[i].z)*-1;
304 //position[i]-=normalrot*.1;
305 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
309 glRotatef(bigrotation[i],0,1,0);
310 glRotatef(bigtilt2[i],1,0,0);
311 glRotatef(bigtilt[i],0,0,1);
312 glRotatef(-rotation1[i]+90,0,1,0);
313 glRotatef(-rotation2[i]+90,0,0,1);
314 glRotatef(-rotation3[i],0,1,0);
315 glRotatef(smallrotation[i],1,0,0);
316 glRotatef(smallrotation2[i],0,1,0);
318 glGetFloatv(GL_MODELVIEW_MATRIX,M);
323 position[i]-=tippoint[i]*.15;
324 XYZ temppoint1,temppoint2,tempforward;
336 gLoc[0]=position[i].x;
337 gLoc[1]=position[i].y;
338 gLoc[2]=position[i].z;
342 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
343 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
344 OPENAL_SetVolume(channels[knifesheathesound], 128);
345 OPENAL_SetPaused(channels[knifesheathesound], false);
348 terrainlight=terrain.getLighting(position[i].x,position[i].z);
349 if(environment==snowyenvironment){
350 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
352 else if(environment==grassyenvironment){
353 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
355 else if(environment==desertenvironment){
356 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
364 position[i]-=velocity[i]*multiplier;
365 tippoint[i]-=velocity[i]*multiplier;
366 tipvelocity[i]=velocity[i];
369 if(velocity[i].x!=0||velocity[i].z!=0||velocity[i].y!=0){
370 velocity[i].y+=gravity*multiplier;
372 XYZ temppoint1,temppoint2,tempforward;
376 temppoint2=velocity[i];
377 distance=findDistance(&temppoint1,&temppoint2);
378 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
379 rotation2[i]*=360/6.28;
382 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
383 rotation1[i]*=360/6.28;
390 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
400 for(int l=0;l<10;l++){
401 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&physics[i]){
403 position[i]+=velocity[i]*multiplier;
404 tippoint[i]+=tipvelocity[i]*multiplier;
407 midp=(position[i]*mass[i]+tippoint[i]*tipmass[i])/(mass[i]+tipmass[i]);
408 vel=tippoint[i]-midp;
410 newpoint1=midp-vel*length[i]*(tipmass[i]/(mass[i]+tipmass[i]));
411 newpoint2=midp+vel*length[i]*(mass[i]/(mass[i]+tipmass[i]));
413 if(freetime[i]>.04)velocity[i]=velocity[i]+(newpoint1-position[i])/multiplier;
414 if(freetime[i]>.04)tipvelocity[i]=tipvelocity[i]+(newpoint2-tippoint[i])/multiplier;
416 position[i]=newpoint1;
417 tippoint[i]=newpoint2;
421 whichpatchx=(position[i].x)/(terrain.size/subdivision*terrain.scale*terraindetail);
422 whichpatchz=(position[i].z)/(terrain.size/subdivision*terrain.scale*terraindetail);
423 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
424 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
425 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
426 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
430 start=position[i]-(tippoint[i]-position[i])/5;
431 end=tippoint[i]+(tippoint[i]-position[i])/30;
432 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
435 diff=(colpoint-tippoint[i]);
439 position[i]+=(colpoint-tippoint[i])+diff*.05;
440 tippoint[i]=colpoint+diff*.05;
441 oldposition[i]=position[i];
442 oldtippoint[i]=tippoint[i];
446 start=tippoint[i]-(position[i]-tippoint[i])/5;
447 end=position[i]+(position[i]-tippoint[i])/30;
448 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
451 diff=(colpoint-position[i]);
455 tippoint[i]+=(colpoint-position[i])+diff*.05;
456 position[i]=colpoint+diff*.05;
457 oldtippoint[i]=tippoint[i];
458 oldposition[i]=tippoint[i];
463 start=oldposition[i];
465 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
468 position[i]=colpoint;
469 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
470 ReflectVector(&velocity[i],&terrainnormal);
471 position[i]+=terrainnormal*.002;
473 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
474 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
475 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
476 velocity[i]-=bounceness;
477 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
479 velocity[i]+=bounceness*elasticity;
481 if(findLengthfast(&bounceness)>1){
484 //int whichsound=clank1sound+abs(Random()%4);
486 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
487 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
488 gLoc[1]=position[i].y;
489 gLoc[2]=position[i].z;
493 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
494 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
495 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
496 OPENAL_SetPaused(channels[whichsound], false);
499 start=oldtippoint[i];
501 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
504 tippoint[i]=colpoint;
505 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
506 ReflectVector(&tipvelocity[i],&terrainnormal);
507 tippoint[i]+=terrainnormal*.002;
509 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
510 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
511 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
512 tipvelocity[i]-=bounceness;
513 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
514 else tipvelocity[i]=0;
515 tipvelocity[i]+=bounceness*elasticity;
517 if(findLengthfast(&bounceness)>1){
520 //int whichsound=clank1sound+abs(Random()%4);
522 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
523 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
524 gLoc[0]=position[i].x;
525 gLoc[1]=position[i].y;
526 gLoc[2]=position[i].z;
530 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
531 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
532 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
533 OPENAL_SetPaused(channels[whichsound], false);
537 if((objects.type[k]!=boxtype&&objects.type[k]!=platformtype&&objects.type[k]!=walltype&&objects.type[k]!=weirdtype)||objects.rotation2[k]!=0)
539 mid=(position[i]*(21+(float)m*10)+tippoint[i]*(19-(float)m*10))/40;
541 oldmid=(oldposition[i]*(21+(float)m*10)+oldtippoint[i]*(19-(float)m*10))/40;
545 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
549 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
550 ReflectVector(&velocity[i],&terrainnormal);
552 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
553 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
554 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
555 velocity[i]-=bounceness;
556 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
558 velocity[i]+=bounceness*elasticity;
560 if(findLengthfast(&bounceness)>1){
563 //int whichsound=clank1sound+abs(Random()%4);
565 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
566 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
572 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
573 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
574 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
575 OPENAL_SetPaused(channels[whichsound], false);
577 position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
580 mid=(position[i]*(19-(float)m*10)+tippoint[i]*(21+(float)m*10))/40;
582 oldmid=(oldposition[i]*(19-(float)m*10)+oldtippoint[i]*(21+(float)m*10))/40;
586 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
590 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
591 ReflectVector(&tipvelocity[i],&terrainnormal);
593 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
594 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
595 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
596 tipvelocity[i]-=bounceness;
597 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
598 else tipvelocity[i]=0;
599 tipvelocity[i]+=bounceness*elasticity;
601 if(findLengthfast(&bounceness)>1){
604 //int whichsound=clank1sound+abs(Random()%4);
606 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
607 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
613 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
614 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
615 OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
616 OPENAL_SetPaused(channels[whichsound], false);
618 tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
625 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
629 closestswordpoint=colpoint;//(position[i]+tippoint[i])/2;
630 point[0]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]],0,objects.rotation[k],0)+objects.position[k];
631 point[1]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]],0,objects.rotation[k],0)+objects.position[k];
632 point[2]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]],0,objects.rotation[k],0)+objects.position[k];
633 if(DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance,&colpoint ))
634 if(distance<closestdistance||closestdistance==-1){
635 closestpoint=colpoint;
636 closestdistance=distance;
639 if(DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance,&colpoint ))
640 if(distance<closestdistance||closestdistance==-1){
641 closestpoint=colpoint;
642 closestdistance=distance;
645 if(DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance,&colpoint ))
646 if(distance<closestdistance||closestdistance==-1){
647 closestpoint=colpoint;
648 closestdistance=distance;
651 if(closestdistance!=-1&&isnormal(closestdistance)){
652 if(DistancePointLine(&closestpoint, &position[i], &tippoint[i], &distance,&colpoint )){
653 closestswordpoint=colpoint;
654 velocity[i]+=(closestpoint-closestswordpoint);
655 tipvelocity[i]+=(closestpoint-closestswordpoint);
656 position[i]+=(closestpoint-closestswordpoint);
657 tippoint[i]+=(closestpoint-closestswordpoint);
666 whichhit=terrain.lineTerrain(oldposition[i],position[i],&colpoint);
667 if(whichhit!=-1||position[i].y<terrain.getHeight(position[i].x,position[i].z)){
669 if(whichhit!=-1)position[i]=colpoint*terrain.scale;
670 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
672 terrainnormal=terrain.getNormal(position[i].x,position[i].z);
673 ReflectVector(&velocity[i],&terrainnormal);
674 position[i]+=terrainnormal*.002;
675 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
676 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
677 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
678 velocity[i]-=bounceness;
679 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
681 if(terrain.getOpacity(position[i].x,position[i].z)<.2)velocity[i]+=bounceness*elasticity*.3;
682 else velocity[i]+=bounceness*elasticity;
683 //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
684 if(findLengthfast(&bounceness)>1){
688 if(terrain.getOpacity(position[i].x,position[i].z)>.2){
689 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
690 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
692 else whichsound=footstepsound+abs(Random()%2);
693 gLoc[0]=position[i].x;
694 gLoc[1]=position[i].y;
695 gLoc[2]=position[i].z;
699 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
700 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
701 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
702 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
703 OPENAL_SetPaused(channels[whichsound], false);
705 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
707 terrainlight=terrain.getLighting(position[i].x,position[i].z);
708 if(environment==snowyenvironment){
709 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
711 else if(environment==grassyenvironment){
712 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
714 else if(environment==desertenvironment){
715 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
720 whichhit=terrain.lineTerrain(oldtippoint[i],tippoint[i],&colpoint);
721 if(whichhit!=-1||tippoint[i].y<terrain.getHeight(tippoint[i].x,tippoint[i].z)){
722 if(whichhit!=-1)tippoint[i]=colpoint*terrain.scale;
723 else tippoint[i].y=terrain.getHeight(tippoint[i].x,tippoint[i].z);
725 terrainnormal=terrain.getNormal(tippoint[i].x,tippoint[i].z);
726 ReflectVector(&tipvelocity[i],&terrainnormal);
727 tippoint[i]+=terrainnormal*.002;
728 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
729 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
730 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
731 tipvelocity[i]-=bounceness;
732 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
733 else tipvelocity[i]=0;
734 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
735 else tipvelocity[i]+=bounceness*elasticity;
736 //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
738 if(findLengthfast(&bounceness)>1){
742 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
743 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
744 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
746 else whichsound=footstepsound+abs(Random()%2);
747 gLoc[0]=tippoint[i].x;
748 gLoc[1]=tippoint[i].y;
749 gLoc[2]=tippoint[i].z;
753 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
754 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
755 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
756 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
757 OPENAL_SetPaused(channels[whichsound], false);
759 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
761 terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
762 if(environment==snowyenvironment){
763 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
765 else if(environment==grassyenvironment){
766 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
768 else if(environment==desertenvironment){
769 if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
776 mid=position[i]+tippoint[i];
778 mid+=(position[i]-mid)/20;
780 if(mid.y<terrain.getHeight(mid.x,mid.z)){
782 mid.y=terrain.getHeight(mid.x,mid.z);
784 terrainnormal=terrain.getNormal(mid.x,mid.z);
785 ReflectVector(&velocity[i],&terrainnormal);
786 //mid+=terrainnormal*.002;
787 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
788 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
789 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
790 velocity[i]-=bounceness;
791 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
793 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
794 else velocity[i]+=bounceness*elasticity;
796 if(findLengthfast(&bounceness)>1){
800 if(terrain.getOpacity(mid.x,mid.z)>.2){
801 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
802 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
804 else whichsound=footstepsound+abs(Random()%2);
811 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
812 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
813 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
814 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
815 OPENAL_SetPaused(channels[whichsound], false);
817 position[i]+=(mid-oldmid)*20;
820 mid=position[i]+tippoint[i];
822 mid+=(tippoint[i]-mid)/20;
824 if(mid.y<terrain.getHeight(mid.x,mid.z)){
826 mid.y=terrain.getHeight(mid.x,mid.z);
828 terrainnormal=terrain.getNormal(mid.x,mid.z);
829 ReflectVector(&tipvelocity[i],&terrainnormal);
830 //mid+=terrainnormal*.002;
831 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
832 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
833 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
834 tipvelocity[i]-=bounceness;
835 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
836 else tipvelocity[i]=0;
837 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
838 else tipvelocity[i]+=bounceness*elasticity;
840 if(findLengthfast(&bounceness)>1){
844 if(terrain.getOpacity(mid.x,mid.z)>.2){
845 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
846 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
848 else whichsound=footstepsound+abs(Random()%2);
855 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
856 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
857 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
858 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
859 OPENAL_SetPaused(channels[whichsound], false);
861 tippoint[i]+=(mid-oldmid)*20;
864 mid=position[i]+tippoint[i];
866 if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
868 position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
870 terrainnormal=terrain.getNormal(mid.x,mid.z);
871 ReflectVector(&velocity[i],&terrainnormal);
872 position[i]+=terrainnormal*.002;
873 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
874 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
875 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
876 velocity[i]-=bounceness;
877 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
879 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
880 else velocity[i]+=bounceness*elasticity;
882 if(findLengthfast(&bounceness)>1){
886 if(terrain.getOpacity(mid.x,mid.z)>.2){
887 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
888 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
890 else whichsound=footstepsound+abs(Random()%2);
891 gLoc[0]=position[i].x;
892 gLoc[1]=position[i].y;
893 gLoc[2]=position[i].z;
897 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
898 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
899 if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
900 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
901 OPENAL_SetPaused(channels[whichsound], false);
905 if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
907 tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
909 terrainnormal=terrain.getNormal(mid.x,mid.z);
910 ReflectVector(&tipvelocity[i],&terrainnormal);
911 tippoint[i]+=terrainnormal*.002;
912 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
913 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
914 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
915 tipvelocity[i]-=bounceness;
916 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
917 else tipvelocity[i]=0;
918 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
919 else tipvelocity[i]+=bounceness*elasticity;
921 if(findLengthfast(&bounceness)>1){
925 if(terrain.getOpacity(mid.x,mid.z)>.2){
926 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
927 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
929 else whichsound=footstepsound+abs(Random()%2);
930 gLoc[0]=tippoint[i].x;
931 gLoc[1]=tippoint[i].y;
932 gLoc[2]=tippoint[i].z;
936 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
937 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
938 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
939 else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
940 OPENAL_SetPaused(channels[whichsound], false);
944 //Fix terrain edge collision
947 whichhit=terrain.lineTerrain(start,end,&colpoint);
958 tipvelocity[i].y+=.1;
961 whichhit=terrain.lineTerrain(start,end,&colpoint);
963 closestpoint=colpoint*terrain.scale;
968 tipvelocity[i].y-=.1;
971 whichhit=terrain.lineTerrain(start,end,&colpoint);
976 tipvelocity[i].y+=.01;
979 whichhit=terrain.lineTerrain(start,end,&colpoint);
981 closestpoint=colpoint*terrain.scale;
985 whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
987 colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
988 proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
991 position[i].y+=.1*proportion;
992 tippoint[i].y+=.1*(1-proportion);
993 velocity[i].y+=.1*proportion;
994 tipvelocity[i].y+=.1*(1-proportion);
997 whichhit=terrain.lineTerrain(start,end,&colpoint);
999 position[i].y-=.1*proportion;
1000 tippoint[i].y-=.1*(1-proportion);
1001 velocity[i].y-=.1*proportion;
1002 tipvelocity[i].y-=.1*(1-proportion);
1005 whichhit=terrain.lineTerrain(start,end,&colpoint);
1006 while(whichhit!=-1){
1007 position[i].y+=.01*proportion;
1008 tippoint[i].y+=.01*(1-proportion);
1009 velocity[i].y+=.01*proportion;
1010 tipvelocity[i].y+=.01*(1-proportion);
1013 whichhit=terrain.lineTerrain(start,end,&colpoint);
1020 velocity[i].y+=gravity*multiplier;
1021 tipvelocity[i].y+=gravity*multiplier;
1022 //position[i].y+=gravity*multiplier*multiplier;
1023 //tippoint[i].y+=gravity*multiplier*multiplier;
1026 XYZ temppoint1,temppoint2,tempforward;
1029 temppoint1=position[i];
1030 temppoint2=tippoint[i];
1031 distance=findDistance(&temppoint1,&temppoint2);
1032 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
1033 rotation2[i]*=360/6.28;
1036 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
1037 rotation1[i]*=360/6.28;
1039 smallrotation[i]=90;
1040 smallrotation2[i]=0;
1044 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
1047 if(findLengthfast(&velocity[i])<.3&&findLengthfast(&tipvelocity[i])<.3&&hitsomething[i]){
1048 freetime[i]+=multiplier;
1051 //velocity[i]=(position[i]-oldposition[i])/multiplier;
1052 //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;
1060 multiplier=tempmult;
1061 if(blooddrip[i]&&bloody[i]){
1062 blooddripdelay[i]-=blooddrip[i]*multiplier/2;
1063 blooddrip[i]-=multiplier;
1064 if(blooddrip[i]<0)blooddrip[i]=0;
1065 if(blooddrip[i]>5)blooddrip[i]=5;
1066 if(blooddripdelay[i]<0&&bloodtoggle){
1067 blooddripdelay[i]=1;
1070 bloodloc=position[i]+(tippoint[i]-position[i])*.7;
1074 Sprite::MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
1079 flamedelay[i]-=multiplier;
1080 if(onfire[i]&&flamedelay[i]<=0){
1082 flamedelay[i]-=multiplier;
1085 normalrot=player[owner[i]].velocity;
1089 if(player[owner[i]].onterrain){
1093 Sprite::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);
1094 Sprite::setLastSpriteSpeed(4);
1095 Sprite::setLastSpriteAlivetime(.3);
1099 if(!onfire[i]&&owner[i]==-1&&type[i]!=staff){
1100 flamedelay[i]-=multiplier;
1101 if(flamedelay[i]<=0){
1103 flamedelay[i]-=multiplier;
1105 if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
1107 shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
1108 Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
1109 Sprite::setLastSpriteSpeed(4);
1110 Sprite::setLastSpriteAlivetime(.3);
1120 static XYZ terrainlight;
1121 static GLfloat M[16];
1123 glAlphaFunc(GL_GREATER, 0.9);
1124 glEnable(GL_TEXTURE_2D);
1126 glEnable(GL_CULL_FACE);
1127 glCullFace(GL_FRONT);
1129 for(i=0;i<numweapons;i++)
1131 if((frustum.SphereInFrustum(position[i].x,position[i].y,position[i].z,1)&&findDistancefast(&viewer,&position[i])<viewdistance*viewdistance))
1137 if(velocity[i].x&&!physics[i])drawhowmany[i]=10;
1138 else drawhowmany[i]=1;
1142 if(player[owner[i]].occluded<25)
1143 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)
1145 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)
1149 else drawhowmany[i]=1;
1150 if(player[owner[i]].targetanimation==swordgroundstabanim)
1152 lastdrawnrotation1[i]=rotation1[i];
1153 lastdrawnrotation2[i]=rotation2[i];
1154 lastdrawnrotation3[i]=rotation3[i];
1155 lastdrawnbigrotation[i]=bigrotation[i];
1156 lastdrawnbigtilt[i]=bigtilt[i];
1157 lastdrawnbigtilt2[i]=bigtilt2[i];
1158 lastdrawnsmallrotation[i]=smallrotation[i];
1159 lastdrawnsmallrotation2[i]=smallrotation2[i];
1164 terrainlight=terrain.getLighting(position[i].x,position[i].z);
1165 if(drawhowmany[i]>0)
1167 glAlphaFunc(GL_GREATER, 0.01);
1169 for(j=drawhowmany[i];j>0;j--)
1171 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1173 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany[i]);
1174 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]));
1175 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]));
1176 //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1177 glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1178 glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1179 glRotatef(bigtilt[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt[i]*(1-((float)(j))/drawhowmany[i]),0,0,1);
1180 glRotatef(-rotation1[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation1[i]*(1-((float)(j))/drawhowmany[i])+90,0,1,0);
1181 glRotatef(-rotation2[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation2[i]*(1-((float)(j))/drawhowmany[i])+90,0,0,1);
1182 glRotatef(-rotation3[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation3[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1183 glRotatef(smallrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1184 glRotatef(smallrotation2[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation2[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1188 if(player[owner[i]].targetanimation==staffhitanim||player[owner[i]].currentanimation==staffhitanim||player[owner[i]].targetanimation==staffhitreversedanim||player[owner[i]].currentanimation==staffhitreversedanim)
1190 glTranslatef(0,0,-.3);
1192 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)
1194 glTranslatef(0,0,-.1);
1197 /*if(type[i]==knife){
1199 if(!physics[i]&&findDistance(&position[i],&oldposition[i])*5>1)glScalef(1,1,findDistance(&position[i],&oldposition[i])*5);
1205 glEnable(GL_LIGHTING);
1206 if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
1209 if(bloody[i]==1)throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
1210 if(bloody[i]==2)throwingknifemodel.drawdifftex(bloodknifetextureptr);
1215 glEnable(GL_LIGHTING);
1216 if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
1219 if(bloody[i]==1)swordmodel.drawdifftex(lightbloodswordtextureptr);
1220 if(bloody[i]==2)swordmodel.drawdifftex(bloodswordtextureptr);
1225 glEnable(GL_LIGHTING);
1226 staffmodel.drawdifftex(stafftextureptr);
1232 lastdrawnposition[i]=position[i];
1233 lastdrawntippoint[i]=tippoint[i];
1234 lastdrawnrotation1[i]=rotation1[i];
1235 lastdrawnrotation2[i]=rotation2[i];
1236 lastdrawnrotation3[i]=rotation3[i];
1237 lastdrawnbigrotation[i]=bigrotation[i];
1238 lastdrawnbigtilt[i]=bigtilt[i];
1239 lastdrawnbigtilt2[i]=bigtilt2[i];
1240 lastdrawnsmallrotation[i]=smallrotation[i];
1241 lastdrawnsmallrotation2[i]=smallrotation2[i];
1242 if(owner[i]!=-1)lastdrawnanim[i]=player[owner[i]].currentanimation;
1246 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
1249 glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1250 glRotatef(bigrotation[i],0,1,0);
1251 glRotatef(bigtilt2[i],1,0,0);
1252 glRotatef(bigtilt[i],0,0,1);
1253 glRotatef(-rotation1[i]+90,0,1,0);
1254 glRotatef(-rotation2[i]+90,0,0,1);
1255 glRotatef(-rotation3[i],0,1,0);
1256 glRotatef(smallrotation[i],1,0,0);
1257 glRotatef(smallrotation2[i],0,1,0);
1258 glTranslatef(0,0,length[i]);
1259 glGetFloatv(GL_MODELVIEW_MATRIX,M);
1260 tippoint[i].x=M[12];
1261 tippoint[i].y=M[13];
1262 tippoint[i].z=M[14];
1268 shinepoint=position[i];
1269 Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1270 Sprite::speed[Sprite::numsprites-1]=4;
1271 Sprite::alivetime[Sprite::numsprites-1]=.3;
1272 shinepoint=tippoint[i];
1273 Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1274 Sprite::speed[Sprite::numsprites-1]=4;
1275 Sprite::alivetime[Sprite::numsprites-1]=.3;*/
1285 // Model throwingknifemodel;
1286 knifetextureptr = 0;
1287 lightbloodknifetextureptr = 0;
1288 bloodknifetextureptr = 0;
1290 // Model swordmodel;
1291 swordtextureptr = 0;
1292 lightbloodswordtextureptr = 0;
1293 bloodswordtextureptr = 0;
1295 // Model staffmodel;
1296 stafftextureptr = 0;
1301 if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
1302 if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
1303 if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
1304 if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
1305 if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
1306 if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
1307 if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );