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