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