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