]> git.jsancho.org Git - lugaru.git/blob - Source/Weapons.cpp
e51b07b53cae40b60ab11778aa2e45cdaafd8f07
[lugaru.git] / Source / Weapons.cpp
1 /**> HEADER FILES <**/
2 #include "Weapons.h"
3
4 extern float multiplier;
5 extern Animation animation[animation_count];
6 extern FSOUND_SAMPLE    *samp[100];
7 extern int channels[100];
8 extern Terrain terrain;
9 extern float gravity;
10 extern int environment;
11 extern Sprites sprites;
12 extern int detail;
13 extern FRUSTUM frustum;
14 extern XYZ viewer;
15 extern float realmultiplier;
16 extern int slomo;
17 extern float slomodelay;
18 extern bool cellophane;
19 extern float texdetail;
20 extern GLubyte bloodText[512*512*3];
21 extern int bloodtoggle;
22 extern Objects objects;
23 extern bool osx;
24 extern bool autoslomo;
25 extern float camerashake;
26 extern float woozy;
27 extern float terraindetail;
28 extern float viewdistance;
29 extern float blackout;
30 extern int difficulty;
31 extern Person player[maxplayers];
32 extern int numplayers;
33 extern bool freeze;
34 extern int bonus;
35 extern float bonusvalue;
36 extern float bonustotal;
37 extern float bonustime;
38 extern int tutoriallevel;
39 extern int numthrowkill;
40 extern "C"      void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
41
42 void    Weapons::DoStuff(){
43         static int i,whichpatchx,whichpatchz,j,k,whichhit,m;
44         static XYZ start,end,colpoint,normalrot,footvel,footpoint;
45         static XYZ terrainnormal;
46         static XYZ vel;
47         static XYZ midp;
48         static XYZ newpoint1,newpoint2;
49         static float friction=3.5;
50         static float elasticity=.4;
51         static XYZ bounceness;
52         static float frictionness;
53         static float moveamount;
54         int closestline;
55         static float closestdistance;
56         static float distance;
57         static XYZ point[3];
58         static XYZ closestpoint;
59         static XYZ closestswordpoint;
60         static XYZ extramove;
61         static float proportion;
62         static float tempmult;
63
64         //Move
65
66         for(i=0;i<numweapons;i++){
67                 if(owner[i]!=-1){
68                         oldowner[i]=owner[i];
69                 }
70                 if(damage[i]>=2&&type[i]==staff&&owner[i]!=-1){
71                         float gLoc[3];
72                         float vel[3];
73                         gLoc[0]=tippoint[i].x;
74                         gLoc[1]=tippoint[i].y;
75                         gLoc[2]=tippoint[i].z;
76                         vel[0]=0;
77                         vel[1]=0;
78                         vel[2]=0;
79                         PlaySoundEx( staffbreaksound, samp[staffbreaksound], NULL, TRUE);
80                         FSOUND_3D_SetAttributes(channels[staffbreaksound], gLoc, vel);
81                         FSOUND_SetVolume(channels[staffbreaksound], 256);
82                         FSOUND_SetPaused(channels[staffbreaksound], FALSE);
83                         XYZ tempvel;
84                         XYZ speed;
85                         //speed=(tippoint[i]-oldtippoint[i])/multiplier/6;
86                         speed=0;
87                         /*for(j=0;j<10;j++){
88                         tempvel.x=float(abs(Random()%100)-50)/20;
89                         tempvel.y=float(abs(Random()%100)-50)/20;
90                         tempvel.z=float(abs(Random()%100)-50)/20;
91                         tempvel+=speed;
92                         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);
93                         }*/
94                         for(j=0;j<40;j++){
95                                 tempvel.x=float(abs(Random()%100)-50)/20;
96                                 tempvel.y=float(abs(Random()%100)-50)/20;
97                                 tempvel.z=float(abs(Random()%100)-50)/20;
98                                 tempvel+=speed;
99                                 sprites.MakeSprite(splintersprite, position[i]+(tippoint[i]-position[i])*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
100                         }
101                         int tempowner;
102                         tempowner=owner[i];
103                         owner[i]=-1;
104                         hitsomething[i]=0;
105                         missed[i]=1;
106                         freetime[i]=0;
107                         firstfree[i]=1;
108                         position[i]=0;
109                         physics[i]=0;
110                         if(tempowner!=-1){
111                                 player[tempowner].num_weapons--;
112                                 if(player[tempowner].num_weapons){
113                                         player[tempowner].weaponids[0]=player[tempowner].weaponids[player[tempowner].num_weapons];
114                                         if(player[tempowner].weaponstuck==player[tempowner].num_weapons)player[tempowner].weaponstuck=0;
115                                 }
116                                 player[tempowner].weaponactive=-1;
117                         }
118                 }
119                 oldposition[i]=position[i];
120                 oldtippoint[i]=tippoint[i];
121                 if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&!physics[i]){
122                         position[i]+=velocity[i]*multiplier;
123                         tippoint[i]+=velocity[i]*multiplier;
124                         whichpatchx=position[i].x/(terrain.size/subdivision*terrain.scale*terraindetail);
125                         whichpatchz=position[i].z/(terrain.size/subdivision*terrain.scale*terraindetail);
126                         if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
127                                 if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
128                                         for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
129                                                 k=terrain.patchobjects[whichpatchx][whichpatchz][j];
130                                                 start=oldtippoint[i];
131                                                 end=tippoint[i];
132                                                 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
133                                                 if(whichhit!=-1){
134                                                         if(objects.type[k]==treetrunktype){
135                                                                 objects.model[k].MakeDecal(breakdecal,DoRotation(colpoint-objects.position[k],0,-objects.rotation[k],0),.1,1,Random()%360);
136                                                                 normalrot=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0);
137                                                                 velocity[i]=0;
138                                                                 if(type[i]==knife)position[i]=colpoint-normalrot*.1;
139                                                                 if(type[i]==sword)position[i]=colpoint-normalrot*.2;
140                                                                 if(type[i]==staff)position[i]=colpoint-normalrot*.2;
141                                                                 XYZ temppoint1,temppoint2,tempforward;
142                                                                 float distance;
143
144                                                                 temppoint1=0;
145                                                                 temppoint2=normalrot;
146                                                                 distance=findDistance(&temppoint1,&temppoint2);
147                                                                 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
148                                                                 rotation2[i]*=360/6.28;
149                                                                 temppoint1.y=0;
150                                                                 temppoint2.y=0;
151                                                                 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
152                                                                 rotation1[i]*=360/6.28;
153                                                                 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
154
155                                                                 rotation3[i]=0;
156                                                                 smallrotation[i]=90;
157                                                                 smallrotation2[i]=0;
158                                                                 bigtilt[i]=0;
159                                                                 bigtilt2[i]=0;
160                                                                 bigrotation[i]=0;
161
162                                                                 float gLoc[3];
163                                                                 float vel[3];
164                                                                 gLoc[0]=position[i].x;
165                                                                 gLoc[1]=position[i].y;
166                                                                 gLoc[2]=position[i].z;
167                                                                 vel[0]=0;
168                                                                 vel[1]=0;
169                                                                 vel[2]=0;
170                                                                 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, TRUE);
171                                                                 FSOUND_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
172                                                                 FSOUND_SetVolume(channels[knifesheathesound], 128);
173                                                                 FSOUND_SetPaused(channels[knifesheathesound], FALSE);
174
175                                                                 bloody[i]=0;
176
177                                                                 sprites.MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);                          
178                                                         }
179                                                         else {
180                                                                 physics[i]=1;
181                                                                 firstfree[i]=1;
182                                                                 position[i]-=velocity[i]*multiplier;
183                                                                 tippoint[i]-=velocity[i]*multiplier;
184                                                                 tipvelocity[i]=velocity[i];
185                                                         }
186                                                 }       
187                                         }
188                                 }
189                                 if(velocity[i].x||velocity[i].y||velocity[i].z)
190                                         for(j=0;j<numplayers;j++){
191                                                 footvel=0;
192                                                 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;                         
193                                                 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]){
194                                                         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]){
195                                                                 bool caught=0;
196                                                                 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)){
197                                                                         float gLoc[3];
198                                                                         float vel[3];
199                                                                         gLoc[0]=player[j].coords.x;
200                                                                         gLoc[1]=player[j].coords.y;
201                                                                         gLoc[2]=player[j].coords.z;
202                                                                         vel[0]=player[j].velocity.x;
203                                                                         vel[1]=player[j].velocity.y;
204                                                                         vel[2]=player[j].velocity.z;
205                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
206                                                                         FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
207                                                                         FSOUND_SetVolume(channels[knifedrawsound], 128);
208                                                                         FSOUND_SetPaused(channels[knifedrawsound], FALSE);
209
210                                                                         player[j].weaponactive=0;
211                                                                         player[j].targetanimation=removeknifeanim;
212                                                                         player[j].targetframe=1;
213                                                                         player[j].target=1;
214                                                                         owner[i]=player[j].id;
215                                                                         if(player[j].num_weapons>0){
216                                                                                 player[j].weaponids[player[j].num_weapons]=player[j].weaponids[0];
217                                                                         }
218                                                                         player[j].num_weapons++;
219                                                                         player[j].weaponids[0]=i;
220
221                                                                         player[j].aitype=attacktypecutoff;
222                                                                 }
223                                                                 else {
224                                                                         if(j!=0)numthrowkill++;
225                                                                         player[j].num_weapons++;
226                                                                         player[j].weaponstuck=player[j].num_weapons-1;
227                                                                         if(normaldotproduct(player[j].facing,velocity[i])>0)player[j].weaponstuckwhere=1;
228                                                                         else player[j].weaponstuckwhere=0;
229
230                                                                         player[j].weaponids[player[j].num_weapons-1]=i;
231
232                                                                         player[j].RagDoll(0);
233                                                                         player[j].skeleton.joints[player[j].skeleton.jointlabels[abdomen]].velocity+=velocity[i]*2;
234                                                                         player[j].skeleton.joints[player[j].skeleton.jointlabels[neck]].velocity+=velocity[i]*2;
235                                                                         player[j].skeleton.joints[player[j].skeleton.jointlabels[rightshoulder]].velocity+=velocity[i]*2;
236                                                                         player[j].skeleton.joints[player[j].skeleton.jointlabels[leftshoulder]].velocity+=velocity[i]*2;
237                                                                         //player[j].Puff(abdomen);
238                                                                         if(bloodtoggle&&tutoriallevel!=1)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
239                                                                         if(tutoriallevel==1)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
240                                                                         footvel=tippoint[i]-position[i];
241                                                                         Normalise(&footvel);
242                                                                         if(bloodtoggle&&tutoriallevel!=1)sprites.MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
243
244                                                                         if(tutoriallevel!=1){
245                                                                                 if(player[j].weaponstuckwhere==0)player[j].DoBloodBig(2,205);
246                                                                                 if(player[j].weaponstuckwhere==1)player[j].DoBloodBig(2,200);
247                                                                                 player[j].damage+=200/player[j].armorhigh;
248                                                                                 player[j].deathbleeding=1;
249                                                                                 player[j].bloodloss+=(200+abs((float)(Random()%40))-20)/player[j].armorhigh;
250                                                                                 owner[i]=j;
251                                                                                 bloody[i]=2;
252                                                                                 blooddrip[i]=5;
253                                                                         }
254
255                                                                         float gLoc[3];
256                                                                         float vel[3];
257                                                                         gLoc[0]=position[i].x;
258                                                                         gLoc[1]=position[i].y;
259                                                                         gLoc[2]=position[i].z;
260                                                                         vel[0]=0;
261                                                                         vel[1]=0;
262                                                                         vel[2]=0;
263                                                                         PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, TRUE);
264                                                                         FSOUND_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
265                                                                         FSOUND_SetVolume(channels[fleshstabsound], 128);
266                                                                         FSOUND_SetPaused(channels[fleshstabsound], FALSE);
267
268                                                                         if(animation[player[0].targetanimation].height==highheight){
269                                                                                 bonus=ninja;
270                                                                                 bonustime=0;
271                                                                                 bonusvalue=60;
272                                                                         }
273                                                                         else{
274                                                                                 bonus=Bullseyebonus;
275                                                                                 bonustime=0;
276                                                                                 bonusvalue=30;
277                                                                         }
278                                                                 }
279                                                         }
280                                                         else missed[i]=1;
281                                                 }       
282                                         }
283                                         if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
284                                                 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
285                                                         velocity[i]=0;
286                                                         if(terrain.lineTerrain(oldposition[i],position[i],&colpoint)!=-1){
287                                                                 position[i]=colpoint*terrain.scale;
288                                                         }
289                                                         else position[i].y=terrain.getHeight(position[i].x,position[i].z);
290
291                                                         terrain.MakeDecal(shadowdecalpermanent,position[i],.06,.5,0);
292                                                         normalrot=terrain.getNormal(position[i].x,position[i].z)*-1;
293                                                         velocity[i]=0;
294                                                         //position[i]-=normalrot*.1;
295                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
296                                                         glPushMatrix();
297                                                                 GLfloat M[16];
298                                                                 glLoadIdentity();
299                                                                 glRotatef(bigrotation[i],0,1,0);
300                                                                 glRotatef(bigtilt2[i],1,0,0);
301                                                                 glRotatef(bigtilt[i],0,0,1);
302                                                                 glRotatef(-rotation1[i]+90,0,1,0);
303                                                                 glRotatef(-rotation2[i]+90,0,0,1);
304                                                                 glRotatef(-rotation3[i],0,1,0);
305                                                                 glRotatef(smallrotation[i],1,0,0);
306                                                                 glRotatef(smallrotation2[i],0,1,0);
307                                                                 glTranslatef(0,0,1);            
308                                                                 glGetFloatv(GL_MODELVIEW_MATRIX,M);
309                                                                 tippoint[i].x=M[12];
310                                                                 tippoint[i].y=M[13];
311                                                                 tippoint[i].z=M[14];
312                                                         glPopMatrix();
313                                                         position[i]-=tippoint[i]*.15;
314                                                         XYZ temppoint1,temppoint2,tempforward;
315                                                         float distance;
316
317                                                         rotation3[i]=0;
318                                                         smallrotation[i]=90;
319                                                         smallrotation2[i]=0;
320                                                         bigtilt[i]=0;
321                                                         bigtilt2[i]=0;
322                                                         bigrotation[i]=0;
323
324                                                         float gLoc[3];
325                                                         float vel[3];
326                                                         gLoc[0]=position[i].x;
327                                                         gLoc[1]=position[i].y;
328                                                         gLoc[2]=position[i].z;
329                                                         vel[0]=0;
330                                                         vel[1]=0;
331                                                         vel[2]=0;
332                                                         PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, TRUE);
333                                                         FSOUND_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
334                                                         FSOUND_SetVolume(channels[knifesheathesound], 128);
335                                                         FSOUND_SetPaused(channels[knifesheathesound], FALSE);
336
337                                                         XYZ terrainlight;
338                                                         terrainlight=terrain.getLighting(position[i].x,position[i].z);
339                                                         if(environment==snowyenvironment){
340                                                                 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
341                                                         }
342                                                         else if(environment==grassyenvironment){
343                                                                 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);
344                                                         }
345                                                         else if(environment==desertenvironment){
346                                                                 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);
347                                                         }
348
349                                                         bloody[i]=0;
350                                                 }
351                                                 else {
352                                                         physics[i]=1;
353                                                         firstfree[i]=1;
354                                                         position[i]-=velocity[i]*multiplier;
355                                                         tippoint[i]-=velocity[i]*multiplier;
356                                                         tipvelocity[i]=velocity[i];
357                                                 }
358                                         }
359                                         if(velocity[i].x!=0||velocity[i].z!=0||velocity[i].y!=0){
360                                                 velocity[i].y+=gravity*multiplier;
361
362                                                 XYZ temppoint1,temppoint2,tempforward;
363                                                 float distance;
364
365                                                 temppoint1=0;
366                                                 temppoint2=velocity[i];
367                                                 distance=findDistance(&temppoint1,&temppoint2);
368                                                 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
369                                                 rotation2[i]*=360/6.28;
370                                                 temppoint1.y=0;
371                                                 temppoint2.y=0;
372                                                 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
373                                                 rotation1[i]*=360/6.28;
374                                                 rotation3[i]=0;
375                                                 smallrotation[i]=90;
376                                                 smallrotation2[i]=0;
377                                                 bigtilt[i]=0;
378                                                 bigtilt2[i]=0;
379                                                 bigrotation[i]=0;
380                                                 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
381                                         }
382                 }
383                 //Sword physics
384                 XYZ mid;
385                 XYZ oldmid;
386                 XYZ oldmid2;
387
388                 tempmult=multiplier;
389                 multiplier/=10;
390                 for(int l=0;l<10;l++){
391                         if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&physics[i]){
392                                 //move
393                                 position[i]+=velocity[i]*multiplier;
394                                 tippoint[i]+=tipvelocity[i]*multiplier;
395
396                                 //Length constrain
397                                 midp=(position[i]*mass[i]+tippoint[i]*tipmass[i])/(mass[i]+tipmass[i]);
398                                 vel=tippoint[i]-midp;
399                                 Normalise(&vel);
400                                 newpoint1=midp-vel*length[i]*(tipmass[i]/(mass[i]+tipmass[i]));
401                                 newpoint2=midp+vel*length[i]*(mass[i]/(mass[i]+tipmass[i]));
402                                 if(!freeze){
403                                         if(freetime[i]>.04)velocity[i]=velocity[i]+(newpoint1-position[i])/multiplier;
404                                         if(freetime[i]>.04)tipvelocity[i]=tipvelocity[i]+(newpoint2-tippoint[i])/multiplier;
405                                 }
406                                 position[i]=newpoint1;
407                                 tippoint[i]=newpoint2;
408
409
410                                 //Object collisions
411                                 whichpatchx=(position[i].x)/(terrain.size/subdivision*terrain.scale*terraindetail);
412                                 whichpatchz=(position[i].z)/(terrain.size/subdivision*terrain.scale*terraindetail);
413                                 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
414                                         if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
415                                                 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
416                                                         k=terrain.patchobjects[whichpatchx][whichpatchz][j];
417
418                                                         if(firstfree[i]){
419                                                                 if(type[i]!=staff){
420                                                                         start=position[i]-(tippoint[i]-position[i])/5;
421                                                                         end=tippoint[i]+(tippoint[i]-position[i])/30;
422                                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
423                                                                         if(whichhit!=-1){
424                                                                                 XYZ diff;
425                                                                                 diff=(colpoint-tippoint[i]);
426                                                                                 Normalise(&diff);
427                                                                                 hitsomething[i]=1;
428
429                                                                                 position[i]+=(colpoint-tippoint[i])+diff*.05;
430                                                                                 tippoint[i]=colpoint+diff*.05;                                                  
431                                                                                 oldposition[i]=position[i];
432                                                                                 oldtippoint[i]=tippoint[i];
433                                                                         }
434                                                                 }
435                                                                 if(type[i]==staff){
436                                                                         start=tippoint[i]-(position[i]-tippoint[i])/5;
437                                                                         end=position[i]+(position[i]-tippoint[i])/30;
438                                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
439                                                                         if(whichhit!=-1){
440                                                                                 XYZ diff;
441                                                                                 diff=(colpoint-position[i]);
442                                                                                 Normalise(&diff);
443                                                                                 hitsomething[i]=1;
444
445                                                                                 tippoint[i]+=(colpoint-position[i])+diff*.05;
446                                                                                 position[i]=colpoint+diff*.05;                                                  
447                                                                                 oldtippoint[i]=tippoint[i];
448                                                                                 oldposition[i]=tippoint[i];
449                                                                         }
450                                                                 }
451                                                         }
452
453                                                         start=oldposition[i];
454                                                         end=position[i];
455                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
456                                                         if(whichhit!=-1){
457                                                                 hitsomething[i]=1;
458                                                                 position[i]=colpoint;                   
459                                                                 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
460                                                                 ReflectVector(&velocity[i],&terrainnormal);
461                                                                 position[i]+=terrainnormal*.002;
462
463                                                                 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
464                                                                 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
465                                                                 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
466                                                                 velocity[i]-=bounceness;
467                                                                 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
468                                                                 else velocity[i]=0;
469                                                                 velocity[i]+=bounceness*elasticity;
470
471                                                                 if(findLengthfast(&bounceness)>1){
472                                                                         float gLoc[3];
473                                                                         float vel[3];
474                                                                         //int whichsound=clank1sound+abs(Random()%4);
475                                                                         int whichsound;
476                                                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
477                                                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
478                                                                         gLoc[1]=position[i].y;
479                                                                         gLoc[2]=position[i].z;
480                                                                         vel[0]=0;
481                                                                         vel[1]=0;
482                                                                         vel[2]=0;
483                                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
484                                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
485                                                                         FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
486                                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
487                                                                 }
488                                                         }
489                                                         start=oldtippoint[i];
490                                                         end=tippoint[i];
491                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
492                                                         if(whichhit!=-1){
493                                                                 hitsomething[i]=1;
494                                                                 tippoint[i]=colpoint;                   
495                                                                 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
496                                                                 ReflectVector(&tipvelocity[i],&terrainnormal);
497                                                                 tippoint[i]+=terrainnormal*.002;
498
499                                                                 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
500                                                                 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
501                                                                 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
502                                                                 tipvelocity[i]-=bounceness;
503                                                                 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
504                                                                 else tipvelocity[i]=0;
505                                                                 tipvelocity[i]+=bounceness*elasticity;
506
507                                                                 if(findLengthfast(&bounceness)>1){
508                                                                         float gLoc[3];
509                                                                         float vel[3];
510                                                                         //int whichsound=clank1sound+abs(Random()%4);
511                                                                         int whichsound;
512                                                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
513                                                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
514                                                                         gLoc[0]=position[i].x;
515                                                                         gLoc[1]=position[i].y;
516                                                                         gLoc[2]=position[i].z;
517                                                                         vel[0]=0;
518                                                                         vel[1]=0;
519                                                                         vel[2]=0;
520                                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
521                                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
522                                                                         FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
523                                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
524                                                                 }
525                                                         }
526
527                                                         if((objects.type[k]!=boxtype&&objects.type[k]!=platformtype&&objects.type[k]!=walltype&&objects.type[k]!=weirdtype)||objects.rotation2[k]!=0)
528                                                                 for(m=0;m<2;m++){
529                                                                         mid=(position[i]*(21+(float)m*10)+tippoint[i]*(19-(float)m*10))/40;
530                                                                         oldmid2=mid;
531                                                                         oldmid=(oldposition[i]*(21+(float)m*10)+oldtippoint[i]*(19-(float)m*10))/40;
532
533                                                                         start=oldmid;
534                                                                         end=mid;
535                                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
536                                                                         if(whichhit!=-1){
537                                                                                 hitsomething[i]=1;
538                                                                                 mid=colpoint;                   
539                                                                                 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
540                                                                                 ReflectVector(&velocity[i],&terrainnormal);
541
542                                                                                 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
543                                                                                 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
544                                                                                 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
545                                                                                 velocity[i]-=bounceness;
546                                                                                 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
547                                                                                 else velocity[i]=0;
548                                                                                 velocity[i]+=bounceness*elasticity;
549
550                                                                                 if(findLengthfast(&bounceness)>1){
551                                                                                         float gLoc[3];
552                                                                                         float vel[3];
553                                                                                         //int whichsound=clank1sound+abs(Random()%4);
554                                                                                         int whichsound;
555                                                                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
556                                                                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
557                                                                                         gLoc[1]=mid.y;
558                                                                                         gLoc[2]=mid.z;
559                                                                                         vel[0]=0;
560                                                                                         vel[1]=0;
561                                                                                         vel[2]=0;
562                                                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
563                                                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
564                                                                                         FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
565                                                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
566                                                                                 }
567                                                                                 position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
568                                                                         }
569
570                                                                         mid=(position[i]*(19-(float)m*10)+tippoint[i]*(21+(float)m*10))/40;
571                                                                         oldmid2=mid;
572                                                                         oldmid=(oldposition[i]*(19-(float)m*10)+oldtippoint[i]*(21+(float)m*10))/40;
573
574                                                                         start=oldmid;
575                                                                         end=mid;
576                                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
577                                                                         if(whichhit!=-1){
578                                                                                 hitsomething[i]=1;
579                                                                                 mid=colpoint;                   
580                                                                                 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
581                                                                                 ReflectVector(&tipvelocity[i],&terrainnormal);
582
583                                                                                 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
584                                                                                 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
585                                                                                 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
586                                                                                 tipvelocity[i]-=bounceness;
587                                                                                 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
588                                                                                 else tipvelocity[i]=0;
589                                                                                 tipvelocity[i]+=bounceness*elasticity;
590
591                                                                                 if(findLengthfast(&bounceness)>1){
592                                                                                         float gLoc[3];
593                                                                                         float vel[3];
594                                                                                         //int whichsound=clank1sound+abs(Random()%4);
595                                                                                         int whichsound;
596                                                                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
597                                                                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
598                                                                                         gLoc[1]=mid.y;
599                                                                                         gLoc[2]=mid.z;
600                                                                                         vel[0]=0;
601                                                                                         vel[1]=0;
602                                                                                         vel[2]=0;
603                                                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
604                                                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
605                                                                                         FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
606                                                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
607                                                                                 }
608                                                                                 tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
609                                                                         }
610                                                                 }
611                                                         else
612                                                         {
613                                                                 start=position[i];
614                                                                 end=tippoint[i];
615                                                                 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
616                                                                 if(whichhit!=-1){
617                                                                         hitsomething[i]=1;
618                                                                         closestdistance=-1;
619                                                                         closestswordpoint=colpoint;//(position[i]+tippoint[i])/2;
620                                                                         point[0]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]],0,objects.rotation[k],0)+objects.position[k];
621                                                                         point[1]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]],0,objects.rotation[k],0)+objects.position[k];
622                                                                         point[2]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]],0,objects.rotation[k],0)+objects.position[k];
623                                                                         if(DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance,&colpoint ))
624                                                                                 if(distance<closestdistance||closestdistance==-1){
625                                                                                         closestpoint=colpoint;
626                                                                                         closestdistance=distance;
627                                                                                         closestline=0;
628                                                                                 }
629                                                                                 if(DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance,&colpoint ))
630                                                                                         if(distance<closestdistance||closestdistance==-1){
631                                                                                                 closestpoint=colpoint;
632                                                                                                 closestdistance=distance;
633                                                                                                 closestline=1;
634                                                                                         }
635                                                                                         if(DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance,&colpoint ))
636                                                                                                 if(distance<closestdistance||closestdistance==-1){
637                                                                                                         closestpoint=colpoint;
638                                                                                                         closestdistance=distance;
639                                                                                                         closestline=2;
640                                                                                                 }
641                                                                                                 if(closestdistance!=-1&&isnormal(closestdistance)){
642                                                                                                         if(DistancePointLine(&closestpoint, &position[i], &tippoint[i], &distance,&colpoint )){
643                                                                                                                 closestswordpoint=colpoint;
644                                                                                                                 velocity[i]+=(closestpoint-closestswordpoint);
645                                                                                                                 tipvelocity[i]+=(closestpoint-closestswordpoint);
646                                                                                                                 position[i]+=(closestpoint-closestswordpoint);          
647                                                                                                                 tippoint[i]+=(closestpoint-closestswordpoint);
648                                                                                                         }
649                                                                                                 }
650                                                                 }
651                                                         }
652
653                                                 }
654                                         }
655                                         //Terrain collisions
656                                         whichhit=terrain.lineTerrain(oldposition[i],position[i],&colpoint);
657                                         if(whichhit!=-1||position[i].y<terrain.getHeight(position[i].x,position[i].z)){
658                                                 hitsomething[i]=1;
659                                                 if(whichhit!=-1)position[i]=colpoint*terrain.scale;
660                                                 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
661
662                                                 terrainnormal=terrain.getNormal(position[i].x,position[i].z);
663                                                 ReflectVector(&velocity[i],&terrainnormal);
664                                                 position[i]+=terrainnormal*.002;
665                                                 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
666                                                 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
667                                                 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
668                                                 velocity[i]-=bounceness;
669                                                 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
670                                                 else velocity[i]=0;
671                                                 if(terrain.getOpacity(position[i].x,position[i].z)<.2)velocity[i]+=bounceness*elasticity*.3;
672                                                 else velocity[i]+=bounceness*elasticity;
673 //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
674                                                 if(findLengthfast(&bounceness)>1){
675                                                         float gLoc[3];
676                                                         float vel[3];
677                                                         int whichsound;
678                                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2){
679                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
680                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
681                                                         }
682                                                         else whichsound=footstepsound+abs(Random()%2);
683                                                         gLoc[0]=position[i].x;
684                                                         gLoc[1]=position[i].y;
685                                                         gLoc[2]=position[i].z;
686                                                         vel[0]=0;
687                                                         vel[1]=0;
688                                                         vel[2]=0;
689                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
690                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
691                                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
692                                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
693                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
694
695                                                         if(terrain.getOpacity(position[i].x,position[i].z)<.2){
696                                                                 XYZ terrainlight;
697                                                                 terrainlight=terrain.getLighting(position[i].x,position[i].z);
698                                                                 if(environment==snowyenvironment){
699                                                                         if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
700                                                                 }
701                                                                 else if(environment==grassyenvironment){
702                                                                         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);
703                                                                 }
704                                                                 else if(environment==desertenvironment){
705                                                                         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);
706                                                                 }
707                                                         }
708                                                 }
709                                         }
710                                         whichhit=terrain.lineTerrain(oldtippoint[i],tippoint[i],&colpoint);
711                                         if(whichhit!=-1||tippoint[i].y<terrain.getHeight(tippoint[i].x,tippoint[i].z)){
712                                                 if(whichhit!=-1)tippoint[i]=colpoint*terrain.scale;
713                                                 else tippoint[i].y=terrain.getHeight(tippoint[i].x,tippoint[i].z);
714
715                                                 terrainnormal=terrain.getNormal(tippoint[i].x,tippoint[i].z);
716                                                 ReflectVector(&tipvelocity[i],&terrainnormal);
717                                                 tippoint[i]+=terrainnormal*.002;
718                                                 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
719                                                 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
720                                                 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
721                                                 tipvelocity[i]-=bounceness;
722                                                 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
723                                                 else tipvelocity[i]=0;
724                                                 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
725                                                 else tipvelocity[i]+=bounceness*elasticity;
726 //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
727
728                                                 if(findLengthfast(&bounceness)>1){
729                                                         float gLoc[3];
730                                                         float vel[3];
731                                                         int whichsound;
732                                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
733                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
734                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
735                                                         }
736                                                         else whichsound=footstepsound+abs(Random()%2);
737                                                         gLoc[0]=tippoint[i].x;
738                                                         gLoc[1]=tippoint[i].y;
739                                                         gLoc[2]=tippoint[i].z;
740                                                         vel[0]=0;
741                                                         vel[1]=0;
742                                                         vel[2]=0;
743                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
744                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
745                                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
746                                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
747                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
748
749                                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
750                                                                 XYZ terrainlight;
751                                                                 terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
752                                                                 if(environment==snowyenvironment){
753                                                                         if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
754                                                                 }
755                                                                 else if(environment==grassyenvironment){
756                                                                         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);
757                                                                 }
758                                                                 else if(environment==desertenvironment){
759                                                                         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);
760                                                                 }
761                                                         }
762                                                 }
763                                         }
764
765                                         //Edges
766                                         mid=position[i]+tippoint[i];
767                                         mid/=2;
768                                         mid+=(position[i]-mid)/20;
769                                         oldmid=mid;
770                                         if(mid.y<terrain.getHeight(mid.x,mid.z)){
771                                                 hitsomething[i]=1;
772                                                 mid.y=terrain.getHeight(mid.x,mid.z);
773
774                                                 terrainnormal=terrain.getNormal(mid.x,mid.z);
775                                                 ReflectVector(&velocity[i],&terrainnormal);
776                                                 //mid+=terrainnormal*.002;
777                                                 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
778                                                 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
779                                                 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
780                                                 velocity[i]-=bounceness;
781                                                 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
782                                                 else velocity[i]=0;
783                                                 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
784                                                 else velocity[i]+=bounceness*elasticity;
785
786                                                 if(findLengthfast(&bounceness)>1){
787                                                         float gLoc[3];
788                                                         float vel[3];
789                                                         int whichsound;
790                                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
791                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
792                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
793                                                         }
794                                                         else whichsound=footstepsound+abs(Random()%2);
795                                                         gLoc[0]=mid.x;
796                                                         gLoc[1]=mid.y;
797                                                         gLoc[2]=mid.z;
798                                                         vel[0]=0;
799                                                         vel[1]=0;
800                                                         vel[2]=0;
801                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
802                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
803                                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
804                                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
805                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
806                                                 }
807                                                 position[i]+=(mid-oldmid)*20;
808                                         }
809
810                                         mid=position[i]+tippoint[i];
811                                         mid/=2;
812                                         mid+=(tippoint[i]-mid)/20;
813                                         oldmid=mid;
814                                         if(mid.y<terrain.getHeight(mid.x,mid.z)){
815                                                 hitsomething[i]=1;
816                                                 mid.y=terrain.getHeight(mid.x,mid.z);
817
818                                                 terrainnormal=terrain.getNormal(mid.x,mid.z);
819                                                 ReflectVector(&tipvelocity[i],&terrainnormal);
820                                                 //mid+=terrainnormal*.002;
821                                                 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
822                                                 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
823                                                 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
824                                                 tipvelocity[i]-=bounceness;
825                                                 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
826                                                 else tipvelocity[i]=0;
827                                                 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
828                                                 else tipvelocity[i]+=bounceness*elasticity;
829
830                                                 if(findLengthfast(&bounceness)>1){
831                                                         float gLoc[3];
832                                                         float vel[3];
833                                                         int whichsound;
834                                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
835                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
836                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
837                                                         }
838                                                         else whichsound=footstepsound+abs(Random()%2);
839                                                         gLoc[0]=mid.x;
840                                                         gLoc[1]=mid.y;
841                                                         gLoc[2]=mid.z;
842                                                         vel[0]=0;
843                                                         vel[1]=0;
844                                                         vel[2]=0;
845                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
846                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
847                                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
848                                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
849                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
850                                                 }
851                                                 tippoint[i]+=(mid-oldmid)*20;
852                                         }
853                                         /*XYZ mid;
854                                         mid=position[i]+tippoint[i];
855                                         mid/=2;
856                                         if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
857                                         hitsomething[i]=1;
858                                         position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
859
860                                         terrainnormal=terrain.getNormal(mid.x,mid.z);
861                                         ReflectVector(&velocity[i],&terrainnormal);
862                                         position[i]+=terrainnormal*.002;
863                                         bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
864                                         if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
865                                         frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
866                                         velocity[i]-=bounceness;
867                                         if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
868                                         else velocity[i]=0;
869                                         if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
870                                         else velocity[i]+=bounceness*elasticity;
871
872                                         if(findLengthfast(&bounceness)>1){
873                                         float gLoc[3];
874                                         float vel[3];
875                                         int whichsound;
876                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
877                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
878                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
879                                         }
880                                         else whichsound=footstepsound+abs(Random()%2);
881                                         gLoc[0]=position[i].x;
882                                         gLoc[1]=position[i].y;
883                                         gLoc[2]=position[i].z;
884                                         vel[0]=0;
885                                         vel[1]=0;
886                                         vel[2]=0;
887                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
888                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
889                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
890                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
891                                         FSOUND_SetPaused(channels[whichsound], FALSE);
892                                         }
893                                         }
894
895                                         if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
896                                         hitsomething[i]=1;
897                                         tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
898
899                                         terrainnormal=terrain.getNormal(mid.x,mid.z);
900                                         ReflectVector(&tipvelocity[i],&terrainnormal);
901                                         tippoint[i]+=terrainnormal*.002;
902                                         bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
903                                         if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
904                                         frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
905                                         tipvelocity[i]-=bounceness;
906                                         if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
907                                         else tipvelocity[i]=0;
908                                         if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
909                                         else tipvelocity[i]+=bounceness*elasticity;
910
911                                         if(findLengthfast(&bounceness)>1){
912                                         float gLoc[3];
913                                         float vel[3];
914                                         int whichsound;
915                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
916                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
917                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
918                                         }
919                                         else whichsound=footstepsound+abs(Random()%2);
920                                         gLoc[0]=tippoint[i].x;
921                                         gLoc[1]=tippoint[i].y;
922                                         gLoc[2]=tippoint[i].z;
923                                         vel[0]=0;
924                                         vel[1]=0;
925                                         vel[2]=0;
926                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
927                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
928                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
929                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
930                                         FSOUND_SetPaused(channels[whichsound], FALSE);
931                                         }
932                                         }*/
933
934                                         //Fix terrain edge collision
935                                         /*start=position[i];
936                                         end=tippoint[i];
937                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
938                                         if(whichhit!=-1){
939                                         XYZ tippoi,posit;
940                                         tippoi=tippoint[i];
941                                         posit=position[i];
942
943
944                                         while(whichhit!=-1){
945                                         position[i].y+=.1;
946                                         tippoint[i].y+=.1;
947                                         velocity[i].y+=.1;
948                                         tipvelocity[i].y+=.1;
949                                         start=position[i];
950                                         end=tippoint[i];
951                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
952                                         if(whichhit!=-1)
953                                         closestpoint=colpoint*terrain.scale;
954                                         }
955                                         position[i].y-=.1;
956                                         tippoint[i].y-=.1;
957                                         velocity[i].y-=.1;
958                                         tipvelocity[i].y-=.1;
959                                         start=position[i];
960                                         end=tippoint[i];
961                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
962                                         while(whichhit!=-1){
963                                         position[i].y+=.01;
964                                         tippoint[i].y+=.01;
965                                         velocity[i].y+=.01;
966                                         tipvelocity[i].y+=.01;
967                                         start=position[i];
968                                         end=tippoint[i];
969                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
970                                         if(whichhit!=-1)
971                                         closestpoint=colpoint*terrain.scale;
972                                         }
973                                         }*/
974                                         /*if(whichhit!=-1){
975                                         whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
976                                         if(whichhit!=-1){
977                                         colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
978                                         proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
979                                         if(proportion<=1){
980                                         while(whichhit!=-1){
981                                         position[i].y+=.1*proportion;
982                                         tippoint[i].y+=.1*(1-proportion);
983                                         velocity[i].y+=.1*proportion;
984                                         tipvelocity[i].y+=.1*(1-proportion);
985                                         start=position[i];
986                                         end=tippoint[i];
987                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
988                                         }
989                                         position[i].y-=.1*proportion;
990                                         tippoint[i].y-=.1*(1-proportion);
991                                         velocity[i].y-=.1*proportion;
992                                         tipvelocity[i].y-=.1*(1-proportion);
993                                         start=position[i];
994                                         end=tippoint[i];
995                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
996                                         while(whichhit!=-1){
997                                         position[i].y+=.01*proportion;
998                                         tippoint[i].y+=.01*(1-proportion);
999                                         velocity[i].y+=.01*proportion;
1000                                         tipvelocity[i].y+=.01*(1-proportion);
1001                                         start=position[i];
1002                                         end=tippoint[i];
1003                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
1004                                         }
1005                                         }
1006                                         }
1007                                         }
1008                                         */
1009                                         //Gravity
1010                                         velocity[i].y+=gravity*multiplier;
1011                                         tipvelocity[i].y+=gravity*multiplier;
1012                                         //position[i].y+=gravity*multiplier*multiplier;
1013                                         //tippoint[i].y+=gravity*multiplier*multiplier;
1014
1015                                         //Rotation
1016                                         XYZ temppoint1,temppoint2,tempforward;
1017                                         float distance;
1018
1019                                         temppoint1=position[i];
1020                                         temppoint2=tippoint[i];
1021                                         distance=findDistance(&temppoint1,&temppoint2);
1022                                         rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
1023                                         rotation2[i]*=360/6.28;
1024                                         temppoint1.y=0;
1025                                         temppoint2.y=0;
1026                                         rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
1027                                         rotation1[i]*=360/6.28;
1028                                         rotation3[i]=0;
1029                                         smallrotation[i]=90;
1030                                         smallrotation2[i]=0;
1031                                         bigtilt[i]=0;
1032                                         bigtilt2[i]=0;
1033                                         bigrotation[i]=0;
1034                                         if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
1035
1036                                         //Stop moving
1037                                         if(findLengthfast(&velocity[i])<.3&&findLengthfast(&tipvelocity[i])<.3&&hitsomething[i]){
1038                                                 freetime[i]+=multiplier;
1039                                         }
1040
1041                                         //velocity[i]=(position[i]-oldposition[i])/multiplier;
1042                                         //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;                      
1043                                         if(freetime[i]>.4){
1044                                                 velocity[i]=0;
1045                                                 tipvelocity[i]=0;
1046                                         }
1047                                         firstfree[i]=0;
1048                         }
1049                 }
1050                 multiplier=tempmult;
1051                 if(blooddrip[i]&&bloody[i]){
1052                         blooddripdelay[i]-=blooddrip[i]*multiplier/2;
1053                         blooddrip[i]-=multiplier;
1054                         if(blooddrip[i]<0)blooddrip[i]=0;
1055                         if(blooddrip[i]>5)blooddrip[i]=5;
1056                         if(blooddripdelay[i]<0&&bloodtoggle){
1057                                 blooddripdelay[i]=1;
1058                                 XYZ bloodvel;
1059                                 XYZ bloodloc;
1060                                 bloodloc=position[i]+(tippoint[i]-position[i])*.7;
1061                                 bloodloc.y-=.05;
1062                                 if(bloodtoggle){
1063                                         bloodvel=0;
1064                                         sprites.MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
1065                                 }                       
1066                         }
1067                 }
1068                 if(onfire[i]){
1069                         flamedelay[i]-=multiplier;
1070                         if(onfire[i]&&flamedelay[i]<=0){
1071                                 flamedelay[i]=.020;
1072                                 flamedelay[i]-=multiplier;
1073                                 normalrot=0;
1074                                 if(owner[i]!=-1){
1075                                         normalrot=player[owner[i]].velocity;
1076                                 }
1077                                 normalrot.y+=1;
1078                                 if(owner[i]!=-1){
1079                                         if(player[owner[i]].onterrain){
1080                                                 normalrot.y=1;
1081                                         }
1082                                 }
1083                                 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);
1084                                 sprites.speed[sprites.numsprites-1]=4;
1085                                 sprites.alivetime[sprites.numsprites-1]=.3;
1086                         }
1087                 }
1088
1089                 if(!onfire[i]&&owner[i]==-1&&type[i]!=staff){
1090                         flamedelay[i]-=multiplier;
1091                         if(flamedelay[i]<=0){
1092                                 flamedelay[i]=.020;
1093                                 flamedelay[i]-=multiplier;
1094                                 normalrot=0;
1095                                 if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
1096                                         XYZ shinepoint;
1097                                         shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
1098                                         sprites.MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
1099                                         sprites.speed[sprites.numsprites-1]=4;
1100                                         sprites.alivetime[sprites.numsprites-1]=.3;
1101                                 }
1102                         }
1103                 }
1104         }
1105 }
1106
1107 int Weapons::Draw()
1108 {
1109         static int i,j;
1110         static XYZ terrainlight;
1111         static GLfloat M[16];
1112         static bool draw;
1113         glAlphaFunc(GL_GREATER, 0.9);
1114         glEnable(GL_TEXTURE_2D);
1115         glEnable(GL_BLEND);
1116         glEnable(GL_CULL_FACE);
1117         glCullFace(GL_FRONT);
1118         glDepthMask(1);
1119         for(i=0;i<numweapons;i++)
1120         {
1121                 if((frustum.SphereInFrustum(position[i].x,position[i].y,position[i].z,1)&&findDistancefast(&viewer,&position[i])<viewdistance*viewdistance))
1122                 {
1123                         draw=0;
1124                         if(owner[i]==-1)
1125                         {
1126                                 draw=1;
1127                                 if(velocity[i].x&&!physics[i])drawhowmany[i]=10;
1128                                 else drawhowmany[i]=1;
1129                         }
1130                         if(owner[i]!=-1)
1131                         {
1132                                 if(player[owner[i]].occluded<25)
1133                                         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)
1134                                                 draw=1;
1135                                 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)
1136                                 {
1137                                         drawhowmany[i]=10;
1138                                 }
1139                                 else drawhowmany[i]=1;
1140                                 if(player[owner[i]].targetanimation==swordgroundstabanim)
1141                                 {
1142                                         lastdrawnrotation1[i]=rotation1[i];
1143                                         lastdrawnrotation2[i]=rotation2[i];
1144                                         lastdrawnrotation3[i]=rotation3[i];
1145                                         lastdrawnbigrotation[i]=bigrotation[i];
1146                                         lastdrawnbigtilt[i]=bigtilt[i];
1147                                         lastdrawnbigtilt2[i]=bigtilt2[i];
1148                                         lastdrawnsmallrotation[i]=smallrotation[i];
1149                                         lastdrawnsmallrotation2[i]=smallrotation2[i];
1150                                 }
1151                         }
1152                         if(draw)
1153                         {
1154                                 terrainlight=terrain.getLighting(position[i].x,position[i].z);
1155                                 if(drawhowmany[i]>0)
1156                                 {
1157                                         glAlphaFunc(GL_GREATER, 0.01);
1158                                 }
1159                                 for(j=drawhowmany[i];j>0;j--)
1160                                 {
1161                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1162                                         glPushMatrix();
1163                                                 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany[i]);
1164                                                 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]));             
1165                                                 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]));                 
1166                                                 //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1167                                                 glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1168                                                 glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1169                                                 glRotatef(bigtilt[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt[i]*(1-((float)(j))/drawhowmany[i]),0,0,1);
1170                                                 glRotatef(-rotation1[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation1[i]*(1-((float)(j))/drawhowmany[i])+90,0,1,0);
1171                                                 glRotatef(-rotation2[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation2[i]*(1-((float)(j))/drawhowmany[i])+90,0,0,1);
1172                                                 glRotatef(-rotation3[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation3[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1173                                                 glRotatef(smallrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1174                                                 glRotatef(smallrotation2[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation2[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1175
1176                                                 if(owner[i]!=-1)
1177                                                 {
1178                                                         if(player[owner[i]].targetanimation==staffhitanim||player[owner[i]].currentanimation==staffhitanim||player[owner[i]].targetanimation==staffhitreversedanim||player[owner[i]].currentanimation==staffhitreversedanim)
1179                                                         {
1180                                                                 glTranslatef(0,0,-.3);
1181                                                         }
1182                                                         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)
1183                                                         {
1184                                                                 glTranslatef(0,0,-.1);
1185                                                         }
1186                                                 }
1187                                                 /*if(type[i]==knife){
1188                                                 if(owner[i]==-1){
1189                                                 if(!physics[i]&&findDistance(&position[i],&oldposition[i])*5>1)glScalef(1,1,findDistance(&position[i],&oldposition[i])*5);
1190                                                 }
1191                                                 }*/
1192
1193                                                 if(type[i]==knife)
1194                                                 {
1195                                                         glEnable(GL_LIGHTING);  
1196                                                         if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
1197                                                         if(bloodtoggle)
1198                                                         {
1199                                                                 if(bloody[i]==1)throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
1200                                                                 if(bloody[i]==2)throwingknifemodel.drawdifftex(bloodknifetextureptr);
1201                                                         }
1202                                                 }
1203                                                 if(type[i]==sword)
1204                                                 {
1205                                                         glEnable(GL_LIGHTING);  
1206                                                         if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
1207                                                         if(bloodtoggle)
1208                                                         {
1209                                                                 if(bloody[i]==1)swordmodel.drawdifftex(lightbloodswordtextureptr);
1210                                                                 if(bloody[i]==2)swordmodel.drawdifftex(bloodswordtextureptr);
1211                                                         }
1212                                                 }
1213                                                 if(type[i]==staff)
1214                                                 {
1215                                                         glEnable(GL_LIGHTING);  
1216                                                         staffmodel.drawdifftex(stafftextureptr);
1217                                                 }
1218
1219                                         glPopMatrix();
1220                                 }
1221
1222                                 lastdrawnposition[i]=position[i];
1223                                 lastdrawntippoint[i]=tippoint[i];
1224                                 lastdrawnrotation1[i]=rotation1[i];
1225                                 lastdrawnrotation2[i]=rotation2[i];
1226                                 lastdrawnrotation3[i]=rotation3[i];
1227                                 lastdrawnbigrotation[i]=bigrotation[i];
1228                                 lastdrawnbigtilt[i]=bigtilt[i];
1229                                 lastdrawnbigtilt2[i]=bigtilt2[i];
1230                                 lastdrawnsmallrotation[i]=smallrotation[i];
1231                                 lastdrawnsmallrotation2[i]=smallrotation2[i];
1232                                 if(owner[i]!=-1)lastdrawnanim[i]=player[owner[i]].currentanimation;
1233                         }
1234                         if(owner[i]!=-1)
1235                         {
1236                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1237                                 glPushMatrix();
1238                                         glLoadIdentity();
1239                                         glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1240                                         glRotatef(bigrotation[i],0,1,0);
1241                                         glRotatef(bigtilt2[i],1,0,0);
1242                                         glRotatef(bigtilt[i],0,0,1);
1243                                         glRotatef(-rotation1[i]+90,0,1,0);
1244                                         glRotatef(-rotation2[i]+90,0,0,1);
1245                                         glRotatef(-rotation3[i],0,1,0);
1246                                         glRotatef(smallrotation[i],1,0,0);
1247                                         glRotatef(smallrotation2[i],0,1,0);
1248                                         glTranslatef(0,0,length[i]);            
1249                                         glGetFloatv(GL_MODELVIEW_MATRIX,M);
1250                                         tippoint[i].x=M[12];
1251                                         tippoint[i].y=M[13];
1252                                         tippoint[i].z=M[14];
1253                                 glPopMatrix();
1254                         }
1255                         /*XYZ shinepoint;
1256                         XYZ nothingpoint;
1257                         nothingpoint=0;
1258                         shinepoint=position[i];
1259                         sprites.MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1260                         sprites.speed[sprites.numsprites-1]=4;
1261                         sprites.alivetime[sprites.numsprites-1]=.3;
1262                         shinepoint=tippoint[i];
1263                         sprites.MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1264                         sprites.speed[sprites.numsprites-1]=4;
1265                         sprites.alivetime[sprites.numsprites-1]=.3;*/
1266                 }
1267         }
1268         return 0;
1269 }
1270
1271 Weapons::Weapons()
1272 {
1273         numweapons = 0;
1274
1275         //              Model throwingknifemodel;
1276         knifetextureptr = 0;
1277         lightbloodknifetextureptr = 0;
1278         bloodknifetextureptr = 0;
1279
1280         //              Model swordmodel;
1281         swordtextureptr = 0;
1282         lightbloodswordtextureptr = 0;
1283         bloodswordtextureptr = 0;
1284
1285         //              Model staffmodel;
1286         stafftextureptr = 0;
1287 }
1288
1289 Weapons::~Weapons()
1290 {
1291         if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
1292         if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
1293         if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
1294         if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
1295         if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
1296         if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
1297         if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );
1298 }
1299