]> git.jsancho.org Git - lugaru.git/blob - Source/Weapons.cpp
More work: compiles, missing like 5 symbols.
[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
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
727                                                 if(findLengthfast(&bounceness)>1){
728                                                         float gLoc[3];
729                                                         float vel[3];
730                                                         int whichsound;
731                                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
732                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
733                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
734                                                         }
735                                                         else whichsound=footstepsound+abs(Random()%2);
736                                                         gLoc[0]=tippoint[i].x;
737                                                         gLoc[1]=tippoint[i].y;
738                                                         gLoc[2]=tippoint[i].z;
739                                                         vel[0]=0;
740                                                         vel[1]=0;
741                                                         vel[2]=0;
742                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
743                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
744                                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
745                                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
746                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
747
748                                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
749                                                                 XYZ terrainlight;
750                                                                 terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
751                                                                 if(environment==snowyenvironment){
752                                                                         if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
753                                                                 }
754                                                                 else if(environment==grassyenvironment){
755                                                                         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);
756                                                                 }
757                                                                 else if(environment==desertenvironment){
758                                                                         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);
759                                                                 }
760                                                         }
761                                                 }
762                                         }
763
764                                         //Edges
765                                         mid=position[i]+tippoint[i];
766                                         mid/=2;
767                                         mid+=(position[i]-mid)/20;
768                                         oldmid=mid;
769                                         if(mid.y<terrain.getHeight(mid.x,mid.z)){
770                                                 hitsomething[i]=1;
771                                                 mid.y=terrain.getHeight(mid.x,mid.z);
772
773                                                 terrainnormal=terrain.getNormal(mid.x,mid.z);
774                                                 ReflectVector(&velocity[i],&terrainnormal);
775                                                 //mid+=terrainnormal*.002;
776                                                 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
777                                                 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
778                                                 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
779                                                 velocity[i]-=bounceness;
780                                                 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
781                                                 else velocity[i]=0;
782                                                 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
783                                                 else velocity[i]+=bounceness*elasticity;
784
785                                                 if(findLengthfast(&bounceness)>1){
786                                                         float gLoc[3];
787                                                         float vel[3];
788                                                         int whichsound;
789                                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
790                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
791                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
792                                                         }
793                                                         else whichsound=footstepsound+abs(Random()%2);
794                                                         gLoc[0]=mid.x;
795                                                         gLoc[1]=mid.y;
796                                                         gLoc[2]=mid.z;
797                                                         vel[0]=0;
798                                                         vel[1]=0;
799                                                         vel[2]=0;
800                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
801                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
802                                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
803                                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
804                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
805                                                 }
806                                                 position[i]+=(mid-oldmid)*20;
807                                         }
808
809                                         mid=position[i]+tippoint[i];
810                                         mid/=2;
811                                         mid+=(tippoint[i]-mid)/20;
812                                         oldmid=mid;
813                                         if(mid.y<terrain.getHeight(mid.x,mid.z)){
814                                                 hitsomething[i]=1;
815                                                 mid.y=terrain.getHeight(mid.x,mid.z);
816
817                                                 terrainnormal=terrain.getNormal(mid.x,mid.z);
818                                                 ReflectVector(&tipvelocity[i],&terrainnormal);
819                                                 //mid+=terrainnormal*.002;
820                                                 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
821                                                 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
822                                                 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
823                                                 tipvelocity[i]-=bounceness;
824                                                 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
825                                                 else tipvelocity[i]=0;
826                                                 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
827                                                 else tipvelocity[i]+=bounceness*elasticity;
828
829                                                 if(findLengthfast(&bounceness)>1){
830                                                         float gLoc[3];
831                                                         float vel[3];
832                                                         int whichsound;
833                                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
834                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
835                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
836                                                         }
837                                                         else whichsound=footstepsound+abs(Random()%2);
838                                                         gLoc[0]=mid.x;
839                                                         gLoc[1]=mid.y;
840                                                         gLoc[2]=mid.z;
841                                                         vel[0]=0;
842                                                         vel[1]=0;
843                                                         vel[2]=0;
844                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
845                                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
846                                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
847                                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
848                                                         FSOUND_SetPaused(channels[whichsound], FALSE);
849                                                 }
850                                                 tippoint[i]+=(mid-oldmid)*20;
851                                         }
852                                         /*XYZ mid;
853                                         mid=position[i]+tippoint[i];
854                                         mid/=2;
855                                         if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
856                                         hitsomething[i]=1;
857                                         position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
858
859                                         terrainnormal=terrain.getNormal(mid.x,mid.z);
860                                         ReflectVector(&velocity[i],&terrainnormal);
861                                         position[i]+=terrainnormal*.002;
862                                         bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
863                                         if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
864                                         frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
865                                         velocity[i]-=bounceness;
866                                         if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
867                                         else velocity[i]=0;
868                                         if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
869                                         else velocity[i]+=bounceness*elasticity;
870
871                                         if(findLengthfast(&bounceness)>1){
872                                         float gLoc[3];
873                                         float vel[3];
874                                         int whichsound;
875                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
876                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
877                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
878                                         }
879                                         else whichsound=footstepsound+abs(Random()%2);
880                                         gLoc[0]=position[i].x;
881                                         gLoc[1]=position[i].y;
882                                         gLoc[2]=position[i].z;
883                                         vel[0]=0;
884                                         vel[1]=0;
885                                         vel[2]=0;
886                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
887                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
888                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
889                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
890                                         FSOUND_SetPaused(channels[whichsound], FALSE);
891                                         }
892                                         }
893
894                                         if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
895                                         hitsomething[i]=1;
896                                         tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
897
898                                         terrainnormal=terrain.getNormal(mid.x,mid.z);
899                                         ReflectVector(&tipvelocity[i],&terrainnormal);
900                                         tippoint[i]+=terrainnormal*.002;
901                                         bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
902                                         if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
903                                         frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
904                                         tipvelocity[i]-=bounceness;
905                                         if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
906                                         else tipvelocity[i]=0;
907                                         if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
908                                         else tipvelocity[i]+=bounceness*elasticity;
909
910                                         if(findLengthfast(&bounceness)>1){
911                                         float gLoc[3];
912                                         float vel[3];
913                                         int whichsound;
914                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
915                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
916                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
917                                         }
918                                         else whichsound=footstepsound+abs(Random()%2);
919                                         gLoc[0]=tippoint[i].x;
920                                         gLoc[1]=tippoint[i].y;
921                                         gLoc[2]=tippoint[i].z;
922                                         vel[0]=0;
923                                         vel[1]=0;
924                                         vel[2]=0;
925                                         PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
926                                         FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
927                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
928                                         else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
929                                         FSOUND_SetPaused(channels[whichsound], FALSE);
930                                         }
931                                         }*/
932
933                                         //Fix terrain edge collision
934                                         /*start=position[i];
935                                         end=tippoint[i];
936                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
937                                         if(whichhit!=-1){
938                                         XYZ tippoi,posit;
939                                         tippoi=tippoint[i];
940                                         posit=position[i];
941
942
943                                         while(whichhit!=-1){
944                                         position[i].y+=.1;
945                                         tippoint[i].y+=.1;
946                                         velocity[i].y+=.1;
947                                         tipvelocity[i].y+=.1;
948                                         start=position[i];
949                                         end=tippoint[i];
950                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
951                                         if(whichhit!=-1)
952                                         closestpoint=colpoint*terrain.scale;
953                                         }
954                                         position[i].y-=.1;
955                                         tippoint[i].y-=.1;
956                                         velocity[i].y-=.1;
957                                         tipvelocity[i].y-=.1;
958                                         start=position[i];
959                                         end=tippoint[i];
960                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
961                                         while(whichhit!=-1){
962                                         position[i].y+=.01;
963                                         tippoint[i].y+=.01;
964                                         velocity[i].y+=.01;
965                                         tipvelocity[i].y+=.01;
966                                         start=position[i];
967                                         end=tippoint[i];
968                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
969                                         if(whichhit!=-1)
970                                         closestpoint=colpoint*terrain.scale;
971                                         }
972                                         }*/
973                                         /*if(whichhit!=-1){
974                                         whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
975                                         if(whichhit!=-1){
976                                         colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
977                                         proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
978                                         if(proportion<=1){
979                                         while(whichhit!=-1){
980                                         position[i].y+=.1*proportion;
981                                         tippoint[i].y+=.1*(1-proportion);
982                                         velocity[i].y+=.1*proportion;
983                                         tipvelocity[i].y+=.1*(1-proportion);
984                                         start=position[i];
985                                         end=tippoint[i];
986                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
987                                         }
988                                         position[i].y-=.1*proportion;
989                                         tippoint[i].y-=.1*(1-proportion);
990                                         velocity[i].y-=.1*proportion;
991                                         tipvelocity[i].y-=.1*(1-proportion);
992                                         start=position[i];
993                                         end=tippoint[i];
994                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
995                                         while(whichhit!=-1){
996                                         position[i].y+=.01*proportion;
997                                         tippoint[i].y+=.01*(1-proportion);
998                                         velocity[i].y+=.01*proportion;
999                                         tipvelocity[i].y+=.01*(1-proportion);
1000                                         start=position[i];
1001                                         end=tippoint[i];
1002                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
1003                                         }
1004                                         }
1005                                         }
1006                                         }
1007                                         */
1008                                         //Gravity
1009                                         velocity[i].y+=gravity*multiplier;
1010                                         tipvelocity[i].y+=gravity*multiplier;
1011                                         //position[i].y+=gravity*multiplier*multiplier;
1012                                         //tippoint[i].y+=gravity*multiplier*multiplier;
1013
1014                                         //Rotation
1015                                         XYZ temppoint1,temppoint2,tempforward;
1016                                         float distance;
1017
1018                                         temppoint1=position[i];
1019                                         temppoint2=tippoint[i];
1020                                         distance=findDistance(&temppoint1,&temppoint2);
1021                                         rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
1022                                         rotation2[i]*=360/6.28;
1023                                         temppoint1.y=0;
1024                                         temppoint2.y=0;
1025                                         rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
1026                                         rotation1[i]*=360/6.28;
1027                                         rotation3[i]=0;
1028                                         smallrotation[i]=90;
1029                                         smallrotation2[i]=0;
1030                                         bigtilt[i]=0;
1031                                         bigtilt2[i]=0;
1032                                         bigrotation[i]=0;
1033                                         if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
1034
1035                                         //Stop moving
1036                                         if(findLengthfast(&velocity[i])<.3&&findLengthfast(&tipvelocity[i])<.3&&hitsomething[i]){
1037                                                 freetime[i]+=multiplier;
1038                                         }
1039
1040                                         //velocity[i]=(position[i]-oldposition[i])/multiplier;
1041                                         //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;                      
1042                                         if(freetime[i]>.4){
1043                                                 velocity[i]=0;
1044                                                 tipvelocity[i]=0;
1045                                         }
1046                                         firstfree[i]=0;
1047                         }
1048                 }
1049                 multiplier=tempmult;
1050                 if(blooddrip[i]&&bloody[i]){
1051                         blooddripdelay[i]-=blooddrip[i]*multiplier/2;
1052                         blooddrip[i]-=multiplier;
1053                         if(blooddrip[i]<0)blooddrip[i]=0;
1054                         if(blooddrip[i]>5)blooddrip[i]=5;
1055                         if(blooddripdelay[i]<0&&bloodtoggle){
1056                                 blooddripdelay[i]=1;
1057                                 XYZ bloodvel;
1058                                 XYZ bloodloc;
1059                                 bloodloc=position[i]+(tippoint[i]-position[i])*.7;
1060                                 bloodloc.y-=.05;
1061                                 if(bloodtoggle){
1062                                         bloodvel=0;
1063                                         sprites.MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
1064                                 }                       
1065                         }
1066                 }
1067                 if(onfire[i]){
1068                         flamedelay[i]-=multiplier;
1069                         if(onfire[i]&&flamedelay[i]<=0){
1070                                 flamedelay[i]=.020;
1071                                 flamedelay[i]-=multiplier;
1072                                 normalrot=0;
1073                                 if(owner[i]!=-1){
1074                                         normalrot=player[owner[i]].velocity;
1075                                 }
1076                                 normalrot.y+=1;
1077                                 if(owner[i]!=-1){
1078                                         if(player[owner[i]].onterrain){
1079                                                 normalrot.y=1;
1080                                         }
1081                                 }
1082                                 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);
1083                                 sprites.speed[sprites.numsprites-1]=4;
1084                                 sprites.alivetime[sprites.numsprites-1]=.3;
1085                         }
1086                 }
1087
1088                 if(!onfire[i]&&owner[i]==-1&&type[i]!=staff){
1089                         flamedelay[i]-=multiplier;
1090                         if(flamedelay[i]<=0){
1091                                 flamedelay[i]=.020;
1092                                 flamedelay[i]-=multiplier;
1093                                 normalrot=0;
1094                                 if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
1095                                         XYZ shinepoint;
1096                                         shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
1097                                         sprites.MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
1098                                         sprites.speed[sprites.numsprites-1]=4;
1099                                         sprites.alivetime[sprites.numsprites-1]=.3;
1100                                 }
1101                         }
1102                 }
1103         }
1104 }
1105
1106 int Weapons::Draw()
1107 {
1108         static int i,j;
1109         static XYZ terrainlight;
1110         static GLfloat M[16];
1111         static bool draw;
1112         glAlphaFunc(GL_GREATER, 0.9);
1113         glEnable(GL_TEXTURE_2D);
1114         glEnable(GL_BLEND);
1115         glEnable(GL_CULL_FACE);
1116         glCullFace(GL_FRONT);
1117         glDepthMask(1);
1118         for(i=0;i<numweapons;i++)
1119         {
1120                 if((frustum.SphereInFrustum(position[i].x,position[i].y,position[i].z,1)&&findDistancefast(&viewer,&position[i])<viewdistance*viewdistance))
1121                 {
1122                         draw=0;
1123                         if(owner[i]==-1)
1124                         {
1125                                 draw=1;
1126                                 if(velocity[i].x&&!physics[i])drawhowmany[i]=10;
1127                                 else drawhowmany[i]=1;
1128                         }
1129                         if(owner[i]!=-1)
1130                         {
1131                                 if(player[owner[i]].occluded<25)
1132                                         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)
1133                                                 draw=1;
1134                                 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)
1135                                 {
1136                                         drawhowmany[i]=10;
1137                                 }
1138                                 else drawhowmany[i]=1;
1139                                 if(player[owner[i]].targetanimation==swordgroundstabanim)
1140                                 {
1141                                         lastdrawnrotation1[i]=rotation1[i];
1142                                         lastdrawnrotation2[i]=rotation2[i];
1143                                         lastdrawnrotation3[i]=rotation3[i];
1144                                         lastdrawnbigrotation[i]=bigrotation[i];
1145                                         lastdrawnbigtilt[i]=bigtilt[i];
1146                                         lastdrawnbigtilt2[i]=bigtilt2[i];
1147                                         lastdrawnsmallrotation[i]=smallrotation[i];
1148                                         lastdrawnsmallrotation2[i]=smallrotation2[i];
1149                                 }
1150                         }
1151                         if(draw)
1152                         {
1153                                 terrainlight=terrain.getLighting(position[i].x,position[i].z);
1154                                 if(drawhowmany[i]>0)
1155                                 {
1156                                         glAlphaFunc(GL_GREATER, 0.01);
1157                                 }
1158                                 for(j=drawhowmany[i];j>0;j--)
1159                                 {
1160                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1161                                         glPushMatrix();
1162                                                 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany[i]);
1163                                                 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]));             
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])+lastdrawnposition[i].y*(1-((float)(j))/drawhowmany[i]),position[i].z*(((float)(j))/drawhowmany[i])+lastdrawnposition[i].z*(1-((float)(j))/drawhowmany[i]));                 
1165                                                 //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1166                                                 glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1167                                                 glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1168                                                 glRotatef(bigtilt[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt[i]*(1-((float)(j))/drawhowmany[i]),0,0,1);
1169                                                 glRotatef(-rotation1[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation1[i]*(1-((float)(j))/drawhowmany[i])+90,0,1,0);
1170                                                 glRotatef(-rotation2[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation2[i]*(1-((float)(j))/drawhowmany[i])+90,0,0,1);
1171                                                 glRotatef(-rotation3[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation3[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1172                                                 glRotatef(smallrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1173                                                 glRotatef(smallrotation2[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation2[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1174
1175                                                 if(owner[i]!=-1)
1176                                                 {
1177                                                         if(player[owner[i]].targetanimation==staffhitanim||player[owner[i]].currentanimation==staffhitanim||player[owner[i]].targetanimation==staffhitreversedanim||player[owner[i]].currentanimation==staffhitreversedanim)
1178                                                         {
1179                                                                 glTranslatef(0,0,-.3);
1180                                                         }
1181                                                         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)
1182                                                         {
1183                                                                 glTranslatef(0,0,-.1);
1184                                                         }
1185                                                 }
1186                                                 /*if(type[i]==knife){
1187                                                 if(owner[i]==-1){
1188                                                 if(!physics[i]&&findDistance(&position[i],&oldposition[i])*5>1)glScalef(1,1,findDistance(&position[i],&oldposition[i])*5);
1189                                                 }
1190                                                 }*/
1191
1192                                                 if(type[i]==knife)
1193                                                 {
1194                                                         glEnable(GL_LIGHTING);  
1195                                                         if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
1196                                                         if(bloodtoggle)
1197                                                         {
1198                                                                 if(bloody[i]==1)throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
1199                                                                 if(bloody[i]==2)throwingknifemodel.drawdifftex(bloodknifetextureptr);
1200                                                         }
1201                                                 }
1202                                                 if(type[i]==sword)
1203                                                 {
1204                                                         glEnable(GL_LIGHTING);  
1205                                                         if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
1206                                                         if(bloodtoggle)
1207                                                         {
1208                                                                 if(bloody[i]==1)swordmodel.drawdifftex(lightbloodswordtextureptr);
1209                                                                 if(bloody[i]==2)swordmodel.drawdifftex(bloodswordtextureptr);
1210                                                         }
1211                                                 }
1212                                                 if(type[i]==staff)
1213                                                 {
1214                                                         glEnable(GL_LIGHTING);  
1215                                                         staffmodel.drawdifftex(stafftextureptr);
1216                                                 }
1217
1218                                         glPopMatrix();
1219                                 }
1220
1221                                 lastdrawnposition[i]=position[i];
1222                                 lastdrawntippoint[i]=tippoint[i];
1223                                 lastdrawnrotation1[i]=rotation1[i];
1224                                 lastdrawnrotation2[i]=rotation2[i];
1225                                 lastdrawnrotation3[i]=rotation3[i];
1226                                 lastdrawnbigrotation[i]=bigrotation[i];
1227                                 lastdrawnbigtilt[i]=bigtilt[i];
1228                                 lastdrawnbigtilt2[i]=bigtilt2[i];
1229                                 lastdrawnsmallrotation[i]=smallrotation[i];
1230                                 lastdrawnsmallrotation2[i]=smallrotation2[i];
1231                                 if(owner[i]!=-1)lastdrawnanim[i]=player[owner[i]].currentanimation;
1232                         }
1233                         if(owner[i]!=-1)
1234                         {
1235                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1236                                 glPushMatrix();
1237                                         glLoadIdentity();
1238                                         glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1239                                         glRotatef(bigrotation[i],0,1,0);
1240                                         glRotatef(bigtilt2[i],1,0,0);
1241                                         glRotatef(bigtilt[i],0,0,1);
1242                                         glRotatef(-rotation1[i]+90,0,1,0);
1243                                         glRotatef(-rotation2[i]+90,0,0,1);
1244                                         glRotatef(-rotation3[i],0,1,0);
1245                                         glRotatef(smallrotation[i],1,0,0);
1246                                         glRotatef(smallrotation2[i],0,1,0);
1247                                         glTranslatef(0,0,length[i]);            
1248                                         glGetFloatv(GL_MODELVIEW_MATRIX,M);
1249                                         tippoint[i].x=M[12];
1250                                         tippoint[i].y=M[13];
1251                                         tippoint[i].z=M[14];
1252                                 glPopMatrix();
1253                         }
1254                         /*XYZ shinepoint;
1255                         XYZ nothingpoint;
1256                         nothingpoint=0;
1257                         shinepoint=position[i];
1258                         sprites.MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1259                         sprites.speed[sprites.numsprites-1]=4;
1260                         sprites.alivetime[sprites.numsprites-1]=.3;
1261                         shinepoint=tippoint[i];
1262                         sprites.MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1263                         sprites.speed[sprites.numsprites-1]=4;
1264                         sprites.alivetime[sprites.numsprites-1]=.3;*/
1265                 }
1266         }
1267         return 0;
1268 }
1269
1270 Weapons::Weapons()
1271 {
1272         rotation1.resize(max_weaponinstances);
1273         rotation2.resize(max_weaponinstances);
1274         rotation3.resize(max_weaponinstances);
1275         bigrotation.resize(max_weaponinstances);
1276         bigtilt.resize(max_weaponinstances);
1277         bigtilt2.resize(max_weaponinstances);
1278         smallrotation.resize(max_weaponinstances);
1279         smallrotation2.resize(max_weaponinstances);
1280         damage.resize(max_weaponinstances);
1281
1282         numweapons = 0;
1283         tippoint.resize(max_weaponinstances);
1284         oldtippoint.resize(max_weaponinstances);
1285         position.resize(max_weaponinstances);
1286         lastmult.resize(max_weaponinstances);
1287         oldposition.resize(max_weaponinstances);
1288         velocity.resize(max_weaponinstances);
1289         tipvelocity.resize(max_weaponinstances);
1290         type.resize(max_weaponinstances);
1291         oldowner.resize(max_weaponinstances);
1292         owner.resize(max_weaponinstances);
1293         bloody.resize(max_weaponinstances);
1294         blooddrip.resize(max_weaponinstances);
1295         blooddripdelay.resize(max_weaponinstances);
1296         onfire.resize(max_weaponinstances);
1297         flamedelay.resize(max_weaponinstances);
1298         missed.resize(max_weaponinstances);
1299         mass.resize(max_weaponinstances);
1300         tipmass.resize(max_weaponinstances);
1301         length.resize(max_weaponinstances);
1302         freetime.resize(max_weaponinstances);
1303         firstfree.resize(max_weaponinstances);
1304         physics.resize(max_weaponinstances);
1305         drawhowmany.resize(max_weaponinstances);
1306         hitsomething.resize(max_weaponinstances);
1307
1308         lastdrawnposition.resize(max_weaponinstances);
1309         lastdrawntippoint.resize(max_weaponinstances);
1310         lastdrawnrotation1.resize(max_weaponinstances);
1311         lastdrawnrotation2.resize(max_weaponinstances);
1312         lastdrawnrotation3.resize(max_weaponinstances);
1313         lastdrawnbigrotation.resize(max_weaponinstances);
1314         lastdrawnbigtilt.resize(max_weaponinstances);
1315         lastdrawnbigtilt2.resize(max_weaponinstances);
1316         lastdrawnsmallrotation.resize(max_weaponinstances);
1317         lastdrawnsmallrotation2.resize(max_weaponinstances);
1318         lastdrawnanim.resize(max_weaponinstances);
1319
1320         //              Model throwingknifemodel;
1321         knifetextureptr = 0;
1322         lightbloodknifetextureptr = 0;
1323         bloodknifetextureptr = 0;
1324
1325         //              Model swordmodel;
1326         swordtextureptr = 0;
1327         lightbloodswordtextureptr = 0;
1328         bloodswordtextureptr = 0;
1329
1330         //              Model staffmodel;
1331         stafftextureptr = 0;
1332 }
1333
1334 Weapons::~Weapons()
1335 {
1336         if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
1337         if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
1338         if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
1339         if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
1340         if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
1341         if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
1342         if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );
1343 }
1344