]> git.jsancho.org Git - lugaru.git/blob - Source/Weapons.cpp
212bdb453d946de39ba3e2aa0961544e5ff14470
[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                                                                                 bonus=ninja;
280                                                                                 bonustime=0;
281                                                                                 bonusvalue=60;
282                                                                         }
283                                                                         else{
284                                                                                 bonus=Bullseyebonus;
285                                                                                 bonustime=0;
286                                                                                 bonusvalue=30;
287                                                                         }
288                                                                 }
289                                                         }
290                                                         else missed[i]=1;
291                                                 }
292                                         }
293                                         if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
294                                                 if(terrain.getOpacity(position[i].x,position[i].z)<.2){
295                                                         velocity[i]=0;
296                                                         if(terrain.lineTerrain(oldposition[i],position[i],&colpoint)!=-1){
297                                                                 position[i]=colpoint*terrain.scale;
298                                                         }
299                                                         else position[i].y=terrain.getHeight(position[i].x,position[i].z);
300
301                                                         terrain.MakeDecal(shadowdecalpermanent,position[i],.06,.5,0);
302                                                         normalrot=terrain.getNormal(position[i].x,position[i].z)*-1;
303                                                         velocity[i]=0;
304                                                         //position[i]-=normalrot*.1;
305                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
306                                                         glPushMatrix();
307                                                                 GLfloat M[16];
308                                                                 glLoadIdentity();
309                                                                 glRotatef(bigrotation[i],0,1,0);
310                                                                 glRotatef(bigtilt2[i],1,0,0);
311                                                                 glRotatef(bigtilt[i],0,0,1);
312                                                                 glRotatef(-rotation1[i]+90,0,1,0);
313                                                                 glRotatef(-rotation2[i]+90,0,0,1);
314                                                                 glRotatef(-rotation3[i],0,1,0);
315                                                                 glRotatef(smallrotation[i],1,0,0);
316                                                                 glRotatef(smallrotation2[i],0,1,0);
317                                                                 glTranslatef(0,0,1);
318                                                                 glGetFloatv(GL_MODELVIEW_MATRIX,M);
319                                                                 tippoint[i].x=M[12];
320                                                                 tippoint[i].y=M[13];
321                                                                 tippoint[i].z=M[14];
322                                                         glPopMatrix();
323                                                         position[i]-=tippoint[i]*.15;
324                                                         XYZ temppoint1,temppoint2,tempforward;
325                                                         float distance;
326
327                                                         rotation3[i]=0;
328                                                         smallrotation[i]=90;
329                                                         smallrotation2[i]=0;
330                                                         bigtilt[i]=0;
331                                                         bigtilt2[i]=0;
332                                                         bigrotation[i]=0;
333
334                                                         float gLoc[3];
335                                                         float vel[3];
336                                                         gLoc[0]=position[i].x;
337                                                         gLoc[1]=position[i].y;
338                                                         gLoc[2]=position[i].z;
339                                                         vel[0]=0;
340                                                         vel[1]=0;
341                                                         vel[2]=0;
342                                                         PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
343                                                         OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
344                                                         OPENAL_SetVolume(channels[knifesheathesound], 128);
345                                                         OPENAL_SetPaused(channels[knifesheathesound], false);
346
347                                                         XYZ terrainlight;
348                                                         terrainlight=terrain.getLighting(position[i].x,position[i].z);
349                                                         if(environment==snowyenvironment){
350                                                                 if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
351                                                         }
352                                                         else if(environment==grassyenvironment){
353                                                                 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);
354                                                         }
355                                                         else if(environment==desertenvironment){
356                                                                 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);
357                                                         }
358
359                                                         bloody[i]=0;
360                                                 }
361                                                 else {
362                                                         physics[i]=1;
363                                                         firstfree[i]=1;
364                                                         position[i]-=velocity[i]*multiplier;
365                                                         tippoint[i]-=velocity[i]*multiplier;
366                                                         tipvelocity[i]=velocity[i];
367                                                 }
368                                         }
369                                         if(velocity[i].x!=0||velocity[i].z!=0||velocity[i].y!=0){
370                                                 velocity[i].y+=gravity*multiplier;
371
372                                                 XYZ temppoint1,temppoint2,tempforward;
373                                                 float distance;
374
375                                                 temppoint1=0;
376                                                 temppoint2=velocity[i];
377                                                 distance=findDistance(&temppoint1,&temppoint2);
378                                                 rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
379                                                 rotation2[i]*=360/6.28;
380                                                 temppoint1.y=0;
381                                                 temppoint2.y=0;
382                                                 rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
383                                                 rotation1[i]*=360/6.28;
384                                                 rotation3[i]=0;
385                                                 smallrotation[i]=90;
386                                                 smallrotation2[i]=0;
387                                                 bigtilt[i]=0;
388                                                 bigtilt2[i]=0;
389                                                 bigrotation[i]=0;
390                                                 if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
391                                         }
392                 }
393                 //Sword physics
394                 XYZ mid;
395                 XYZ oldmid;
396                 XYZ oldmid2;
397
398                 tempmult=multiplier;
399                 multiplier/=10;
400                 for(int l=0;l<10;l++){
401                         if(owner[i]==-1&&(velocity[i].x||velocity[i].y||velocity[i].z)&&physics[i]){
402                                 //move
403                                 position[i]+=velocity[i]*multiplier;
404                                 tippoint[i]+=tipvelocity[i]*multiplier;
405
406                                 //Length constrain
407                                 midp=(position[i]*mass[i]+tippoint[i]*tipmass[i])/(mass[i]+tipmass[i]);
408                                 vel=tippoint[i]-midp;
409                                 Normalise(&vel);
410                                 newpoint1=midp-vel*length[i]*(tipmass[i]/(mass[i]+tipmass[i]));
411                                 newpoint2=midp+vel*length[i]*(mass[i]/(mass[i]+tipmass[i]));
412                                 if(!freeze){
413                                         if(freetime[i]>.04)velocity[i]=velocity[i]+(newpoint1-position[i])/multiplier;
414                                         if(freetime[i]>.04)tipvelocity[i]=tipvelocity[i]+(newpoint2-tippoint[i])/multiplier;
415                                 }
416                                 position[i]=newpoint1;
417                                 tippoint[i]=newpoint2;
418
419
420                                 //Object collisions
421                                 whichpatchx=(position[i].x)/(terrain.size/subdivision*terrain.scale*terraindetail);
422                                 whichpatchz=(position[i].z)/(terrain.size/subdivision*terrain.scale*terraindetail);
423                                 if(whichpatchx>0&&whichpatchz>0&&whichpatchx<subdivision&&whichpatchz<subdivision)
424                                         if(terrain.patchobjectnum[whichpatchx][whichpatchz]){
425                                                 for(j=0;j<terrain.patchobjectnum[whichpatchx][whichpatchz];j++){
426                                                         k=terrain.patchobjects[whichpatchx][whichpatchz][j];
427
428                                                         if(firstfree[i]){
429                                                                 if(type[i]!=staff){
430                                                                         start=position[i]-(tippoint[i]-position[i])/5;
431                                                                         end=tippoint[i]+(tippoint[i]-position[i])/30;
432                                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
433                                                                         if(whichhit!=-1){
434                                                                                 XYZ diff;
435                                                                                 diff=(colpoint-tippoint[i]);
436                                                                                 Normalise(&diff);
437                                                                                 hitsomething[i]=1;
438
439                                                                                 position[i]+=(colpoint-tippoint[i])+diff*.05;
440                                                                                 tippoint[i]=colpoint+diff*.05;
441                                                                                 oldposition[i]=position[i];
442                                                                                 oldtippoint[i]=tippoint[i];
443                                                                         }
444                                                                 }
445                                                                 if(type[i]==staff){
446                                                                         start=tippoint[i]-(position[i]-tippoint[i])/5;
447                                                                         end=position[i]+(position[i]-tippoint[i])/30;
448                                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
449                                                                         if(whichhit!=-1){
450                                                                                 XYZ diff;
451                                                                                 diff=(colpoint-position[i]);
452                                                                                 Normalise(&diff);
453                                                                                 hitsomething[i]=1;
454
455                                                                                 tippoint[i]+=(colpoint-position[i])+diff*.05;
456                                                                                 position[i]=colpoint+diff*.05;
457                                                                                 oldtippoint[i]=tippoint[i];
458                                                                                 oldposition[i]=tippoint[i];
459                                                                         }
460                                                                 }
461                                                         }
462
463                                                         start=oldposition[i];
464                                                         end=position[i];
465                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
466                                                         if(whichhit!=-1){
467                                                                 hitsomething[i]=1;
468                                                                 position[i]=colpoint;
469                                                                 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
470                                                                 ReflectVector(&velocity[i],&terrainnormal);
471                                                                 position[i]+=terrainnormal*.002;
472
473                                                                 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
474                                                                 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
475                                                                 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
476                                                                 velocity[i]-=bounceness;
477                                                                 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
478                                                                 else velocity[i]=0;
479                                                                 velocity[i]+=bounceness*elasticity;
480
481                                                                 if(findLengthfast(&bounceness)>1){
482                                                                         float gLoc[3];
483                                                                         float vel[3];
484                                                                         //int whichsound=clank1sound+abs(Random()%4);
485                                                                         int whichsound;
486                                                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
487                                                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
488                                                                         gLoc[1]=position[i].y;
489                                                                         gLoc[2]=position[i].z;
490                                                                         vel[0]=0;
491                                                                         vel[1]=0;
492                                                                         vel[2]=0;
493                                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
494                                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
495                                                                         OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
496                                                                         OPENAL_SetPaused(channels[whichsound], false);
497                                                                 }
498                                                         }
499                                                         start=oldtippoint[i];
500                                                         end=tippoint[i];
501                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
502                                                         if(whichhit!=-1){
503                                                                 hitsomething[i]=1;
504                                                                 tippoint[i]=colpoint;
505                                                                 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
506                                                                 ReflectVector(&tipvelocity[i],&terrainnormal);
507                                                                 tippoint[i]+=terrainnormal*.002;
508
509                                                                 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
510                                                                 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
511                                                                 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
512                                                                 tipvelocity[i]-=bounceness;
513                                                                 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
514                                                                 else tipvelocity[i]=0;
515                                                                 tipvelocity[i]+=bounceness*elasticity;
516
517                                                                 if(findLengthfast(&bounceness)>1){
518                                                                         float gLoc[3];
519                                                                         float vel[3];
520                                                                         //int whichsound=clank1sound+abs(Random()%4);
521                                                                         int whichsound;
522                                                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
523                                                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
524                                                                         gLoc[0]=position[i].x;
525                                                                         gLoc[1]=position[i].y;
526                                                                         gLoc[2]=position[i].z;
527                                                                         vel[0]=0;
528                                                                         vel[1]=0;
529                                                                         vel[2]=0;
530                                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
531                                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
532                                                                         OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
533                                                                         OPENAL_SetPaused(channels[whichsound], false);
534                                                                 }
535                                                         }
536
537                                                         if((objects.type[k]!=boxtype&&objects.type[k]!=platformtype&&objects.type[k]!=walltype&&objects.type[k]!=weirdtype)||objects.rotation2[k]!=0)
538                                                                 for(m=0;m<2;m++){
539                                                                         mid=(position[i]*(21+(float)m*10)+tippoint[i]*(19-(float)m*10))/40;
540                                                                         oldmid2=mid;
541                                                                         oldmid=(oldposition[i]*(21+(float)m*10)+oldtippoint[i]*(19-(float)m*10))/40;
542
543                                                                         start=oldmid;
544                                                                         end=mid;
545                                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
546                                                                         if(whichhit!=-1){
547                                                                                 hitsomething[i]=1;
548                                                                                 mid=colpoint;
549                                                                                 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
550                                                                                 ReflectVector(&velocity[i],&terrainnormal);
551
552                                                                                 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
553                                                                                 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
554                                                                                 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
555                                                                                 velocity[i]-=bounceness;
556                                                                                 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
557                                                                                 else velocity[i]=0;
558                                                                                 velocity[i]+=bounceness*elasticity;
559
560                                                                                 if(findLengthfast(&bounceness)>1){
561                                                                                         float gLoc[3];
562                                                                                         float vel[3];
563                                                                                         //int whichsound=clank1sound+abs(Random()%4);
564                                                                                         int whichsound;
565                                                                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
566                                                                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
567                                                                                         gLoc[1]=mid.y;
568                                                                                         gLoc[2]=mid.z;
569                                                                                         vel[0]=0;
570                                                                                         vel[1]=0;
571                                                                                         vel[2]=0;
572                                                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
573                                                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
574                                                                                         OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
575                                                                                         OPENAL_SetPaused(channels[whichsound], false);
576                                                                                 }
577                                                                                 position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
578                                                                         }
579
580                                                                         mid=(position[i]*(19-(float)m*10)+tippoint[i]*(21+(float)m*10))/40;
581                                                                         oldmid2=mid;
582                                                                         oldmid=(oldposition[i]*(19-(float)m*10)+oldtippoint[i]*(21+(float)m*10))/40;
583
584                                                                         start=oldmid;
585                                                                         end=mid;
586                                                                         whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
587                                                                         if(whichhit!=-1){
588                                                                                 hitsomething[i]=1;
589                                                                                 mid=colpoint;
590                                                                                 terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
591                                                                                 ReflectVector(&tipvelocity[i],&terrainnormal);
592
593                                                                                 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
594                                                                                 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
595                                                                                 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
596                                                                                 tipvelocity[i]-=bounceness;
597                                                                                 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
598                                                                                 else tipvelocity[i]=0;
599                                                                                 tipvelocity[i]+=bounceness*elasticity;
600
601                                                                                 if(findLengthfast(&bounceness)>1){
602                                                                                         float gLoc[3];
603                                                                                         float vel[3];
604                                                                                         //int whichsound=clank1sound+abs(Random()%4);
605                                                                                         int whichsound;
606                                                                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
607                                                                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
608                                                                                         gLoc[1]=mid.y;
609                                                                                         gLoc[2]=mid.z;
610                                                                                         vel[0]=0;
611                                                                                         vel[1]=0;
612                                                                                         vel[2]=0;
613                                                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
614                                                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
615                                                                                         OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
616                                                                                         OPENAL_SetPaused(channels[whichsound], false);
617                                                                                 }
618                                                                                 tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
619                                                                         }
620                                                                 }
621                                                         else
622                                                         {
623                                                                 start=position[i];
624                                                                 end=tippoint[i];
625                                                                 whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
626                                                                 if(whichhit!=-1){
627                                                                         hitsomething[i]=1;
628                                                                         closestdistance=-1;
629                                                                         closestswordpoint=colpoint;//(position[i]+tippoint[i])/2;
630                                                                         point[0]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[0]],0,objects.rotation[k],0)+objects.position[k];
631                                                                         point[1]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[1]],0,objects.rotation[k],0)+objects.position[k];
632                                                                         point[2]=DoRotation(objects.model[k].vertex[objects.model[k].Triangles[whichhit].vertex[2]],0,objects.rotation[k],0)+objects.position[k];
633                                                                         if(DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance,&colpoint ))
634                                                                                 if(distance<closestdistance||closestdistance==-1){
635                                                                                         closestpoint=colpoint;
636                                                                                         closestdistance=distance;
637                                                                                         closestline=0;
638                                                                                 }
639                                                                                 if(DistancePointLine(&closestswordpoint, &point[1], &point[2], &distance,&colpoint ))
640                                                                                         if(distance<closestdistance||closestdistance==-1){
641                                                                                                 closestpoint=colpoint;
642                                                                                                 closestdistance=distance;
643                                                                                                 closestline=1;
644                                                                                         }
645                                                                                         if(DistancePointLine(&closestswordpoint, &point[2], &point[0], &distance,&colpoint ))
646                                                                                                 if(distance<closestdistance||closestdistance==-1){
647                                                                                                         closestpoint=colpoint;
648                                                                                                         closestdistance=distance;
649                                                                                                         closestline=2;
650                                                                                                 }
651                                                                                                 if(closestdistance!=-1&&isnormal(closestdistance)){
652                                                                                                         if(DistancePointLine(&closestpoint, &position[i], &tippoint[i], &distance,&colpoint )){
653                                                                                                                 closestswordpoint=colpoint;
654                                                                                                                 velocity[i]+=(closestpoint-closestswordpoint);
655                                                                                                                 tipvelocity[i]+=(closestpoint-closestswordpoint);
656                                                                                                                 position[i]+=(closestpoint-closestswordpoint);
657                                                                                                                 tippoint[i]+=(closestpoint-closestswordpoint);
658                                                                                                         }
659                                                                                                 }
660                                                                 }
661                                                         }
662
663                                                 }
664                                         }
665                                         //Terrain collisions
666                                         whichhit=terrain.lineTerrain(oldposition[i],position[i],&colpoint);
667                                         if(whichhit!=-1||position[i].y<terrain.getHeight(position[i].x,position[i].z)){
668                                                 hitsomething[i]=1;
669                                                 if(whichhit!=-1)position[i]=colpoint*terrain.scale;
670                                                 else position[i].y=terrain.getHeight(position[i].x,position[i].z);
671
672                                                 terrainnormal=terrain.getNormal(position[i].x,position[i].z);
673                                                 ReflectVector(&velocity[i],&terrainnormal);
674                                                 position[i]+=terrainnormal*.002;
675                                                 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
676                                                 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
677                                                 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
678                                                 velocity[i]-=bounceness;
679                                                 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
680                                                 else velocity[i]=0;
681                                                 if(terrain.getOpacity(position[i].x,position[i].z)<.2)velocity[i]+=bounceness*elasticity*.3;
682                                                 else velocity[i]+=bounceness*elasticity;
683 //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
684                                                 if(findLengthfast(&bounceness)>1){
685                                                         float gLoc[3];
686                                                         float vel[3];
687                                                         int whichsound;
688                                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2){
689                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
690                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
691                                                         }
692                                                         else whichsound=footstepsound+abs(Random()%2);
693                                                         gLoc[0]=position[i].x;
694                                                         gLoc[1]=position[i].y;
695                                                         gLoc[2]=position[i].z;
696                                                         vel[0]=0;
697                                                         vel[1]=0;
698                                                         vel[2]=0;
699                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
700                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
701                                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
702                                                         else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
703                                                         OPENAL_SetPaused(channels[whichsound], false);
704
705                                                         if(terrain.getOpacity(position[i].x,position[i].z)<.2){
706                                                                 XYZ terrainlight;
707                                                                 terrainlight=terrain.getLighting(position[i].x,position[i].z);
708                                                                 if(environment==snowyenvironment){
709                                                                         if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
710                                                                 }
711                                                                 else if(environment==grassyenvironment){
712                                                                         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);
713                                                                 }
714                                                                 else if(environment==desertenvironment){
715                                                                         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);
716                                                                 }
717                                                         }
718                                                 }
719                                         }
720                                         whichhit=terrain.lineTerrain(oldtippoint[i],tippoint[i],&colpoint);
721                                         if(whichhit!=-1||tippoint[i].y<terrain.getHeight(tippoint[i].x,tippoint[i].z)){
722                                                 if(whichhit!=-1)tippoint[i]=colpoint*terrain.scale;
723                                                 else tippoint[i].y=terrain.getHeight(tippoint[i].x,tippoint[i].z);
724
725                                                 terrainnormal=terrain.getNormal(tippoint[i].x,tippoint[i].z);
726                                                 ReflectVector(&tipvelocity[i],&terrainnormal);
727                                                 tippoint[i]+=terrainnormal*.002;
728                                                 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
729                                                 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
730                                                 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
731                                                 tipvelocity[i]-=bounceness;
732                                                 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
733                                                 else tipvelocity[i]=0;
734                                                 if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
735                                                 else tipvelocity[i]+=bounceness*elasticity;
736 //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
737
738                                                 if(findLengthfast(&bounceness)>1){
739                                                         float gLoc[3];
740                                                         float vel[3];
741                                                         int whichsound;
742                                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
743                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
744                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
745                                                         }
746                                                         else whichsound=footstepsound+abs(Random()%2);
747                                                         gLoc[0]=tippoint[i].x;
748                                                         gLoc[1]=tippoint[i].y;
749                                                         gLoc[2]=tippoint[i].z;
750                                                         vel[0]=0;
751                                                         vel[1]=0;
752                                                         vel[2]=0;
753                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
754                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
755                                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
756                                                         else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
757                                                         OPENAL_SetPaused(channels[whichsound], false);
758
759                                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
760                                                                 XYZ terrainlight;
761                                                                 terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
762                                                                 if(environment==snowyenvironment){
763                                                                         if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
764                                                                 }
765                                                                 else if(environment==grassyenvironment){
766                                                                         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);
767                                                                 }
768                                                                 else if(environment==desertenvironment){
769                                                                         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);
770                                                                 }
771                                                         }
772                                                 }
773                                         }
774
775                                         //Edges
776                                         mid=position[i]+tippoint[i];
777                                         mid/=2;
778                                         mid+=(position[i]-mid)/20;
779                                         oldmid=mid;
780                                         if(mid.y<terrain.getHeight(mid.x,mid.z)){
781                                                 hitsomething[i]=1;
782                                                 mid.y=terrain.getHeight(mid.x,mid.z);
783
784                                                 terrainnormal=terrain.getNormal(mid.x,mid.z);
785                                                 ReflectVector(&velocity[i],&terrainnormal);
786                                                 //mid+=terrainnormal*.002;
787                                                 bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
788                                                 if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
789                                                 frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
790                                                 velocity[i]-=bounceness;
791                                                 if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
792                                                 else velocity[i]=0;
793                                                 if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
794                                                 else velocity[i]+=bounceness*elasticity;
795
796                                                 if(findLengthfast(&bounceness)>1){
797                                                         float gLoc[3];
798                                                         float vel[3];
799                                                         int whichsound;
800                                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
801                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
802                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
803                                                         }
804                                                         else whichsound=footstepsound+abs(Random()%2);
805                                                         gLoc[0]=mid.x;
806                                                         gLoc[1]=mid.y;
807                                                         gLoc[2]=mid.z;
808                                                         vel[0]=0;
809                                                         vel[1]=0;
810                                                         vel[2]=0;
811                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
812                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
813                                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
814                                                         else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
815                                                         OPENAL_SetPaused(channels[whichsound], false);
816                                                 }
817                                                 position[i]+=(mid-oldmid)*20;
818                                         }
819
820                                         mid=position[i]+tippoint[i];
821                                         mid/=2;
822                                         mid+=(tippoint[i]-mid)/20;
823                                         oldmid=mid;
824                                         if(mid.y<terrain.getHeight(mid.x,mid.z)){
825                                                 hitsomething[i]=1;
826                                                 mid.y=terrain.getHeight(mid.x,mid.z);
827
828                                                 terrainnormal=terrain.getNormal(mid.x,mid.z);
829                                                 ReflectVector(&tipvelocity[i],&terrainnormal);
830                                                 //mid+=terrainnormal*.002;
831                                                 bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
832                                                 if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
833                                                 frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
834                                                 tipvelocity[i]-=bounceness;
835                                                 if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
836                                                 else tipvelocity[i]=0;
837                                                 if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
838                                                 else tipvelocity[i]+=bounceness*elasticity;
839
840                                                 if(findLengthfast(&bounceness)>1){
841                                                         float gLoc[3];
842                                                         float vel[3];
843                                                         int whichsound;
844                                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
845                                                                 if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
846                                                                 if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
847                                                         }
848                                                         else whichsound=footstepsound+abs(Random()%2);
849                                                         gLoc[0]=mid.x;
850                                                         gLoc[1]=mid.y;
851                                                         gLoc[2]=mid.z;
852                                                         vel[0]=0;
853                                                         vel[1]=0;
854                                                         vel[2]=0;
855                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
856                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
857                                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
858                                                         else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
859                                                         OPENAL_SetPaused(channels[whichsound], false);
860                                                 }
861                                                 tippoint[i]+=(mid-oldmid)*20;
862                                         }
863                                         /*XYZ mid;
864                                         mid=position[i]+tippoint[i];
865                                         mid/=2;
866                                         if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
867                                         hitsomething[i]=1;
868                                         position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
869
870                                         terrainnormal=terrain.getNormal(mid.x,mid.z);
871                                         ReflectVector(&velocity[i],&terrainnormal);
872                                         position[i]+=terrainnormal*.002;
873                                         bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
874                                         if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
875                                         frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
876                                         velocity[i]-=bounceness;
877                                         if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
878                                         else velocity[i]=0;
879                                         if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
880                                         else velocity[i]+=bounceness*elasticity;
881
882                                         if(findLengthfast(&bounceness)>1){
883                                         float gLoc[3];
884                                         float vel[3];
885                                         int whichsound;
886                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
887                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
888                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
889                                         }
890                                         else whichsound=footstepsound+abs(Random()%2);
891                                         gLoc[0]=position[i].x;
892                                         gLoc[1]=position[i].y;
893                                         gLoc[2]=position[i].z;
894                                         vel[0]=0;
895                                         vel[1]=0;
896                                         vel[2]=0;
897                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
898                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
899                                         if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
900                                         else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
901                                         OPENAL_SetPaused(channels[whichsound], false);
902                                         }
903                                         }
904
905                                         if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
906                                         hitsomething[i]=1;
907                                         tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
908
909                                         terrainnormal=terrain.getNormal(mid.x,mid.z);
910                                         ReflectVector(&tipvelocity[i],&terrainnormal);
911                                         tippoint[i]+=terrainnormal*.002;
912                                         bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
913                                         if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
914                                         frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
915                                         tipvelocity[i]-=bounceness;
916                                         if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
917                                         else tipvelocity[i]=0;
918                                         if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
919                                         else tipvelocity[i]+=bounceness*elasticity;
920
921                                         if(findLengthfast(&bounceness)>1){
922                                         float gLoc[3];
923                                         float vel[3];
924                                         int whichsound;
925                                         if(terrain.getOpacity(mid.x,mid.z)>.2){
926                                         if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
927                                         if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
928                                         }
929                                         else whichsound=footstepsound+abs(Random()%2);
930                                         gLoc[0]=tippoint[i].x;
931                                         gLoc[1]=tippoint[i].y;
932                                         gLoc[2]=tippoint[i].z;
933                                         vel[0]=0;
934                                         vel[1]=0;
935                                         vel[2]=0;
936                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
937                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
938                                         if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
939                                         else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
940                                         OPENAL_SetPaused(channels[whichsound], false);
941                                         }
942                                         }*/
943
944                                         //Fix terrain edge collision
945                                         /*start=position[i];
946                                         end=tippoint[i];
947                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
948                                         if(whichhit!=-1){
949                                         XYZ tippoi,posit;
950                                         tippoi=tippoint[i];
951                                         posit=position[i];
952
953
954                                         while(whichhit!=-1){
955                                         position[i].y+=.1;
956                                         tippoint[i].y+=.1;
957                                         velocity[i].y+=.1;
958                                         tipvelocity[i].y+=.1;
959                                         start=position[i];
960                                         end=tippoint[i];
961                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
962                                         if(whichhit!=-1)
963                                         closestpoint=colpoint*terrain.scale;
964                                         }
965                                         position[i].y-=.1;
966                                         tippoint[i].y-=.1;
967                                         velocity[i].y-=.1;
968                                         tipvelocity[i].y-=.1;
969                                         start=position[i];
970                                         end=tippoint[i];
971                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
972                                         while(whichhit!=-1){
973                                         position[i].y+=.01;
974                                         tippoint[i].y+=.01;
975                                         velocity[i].y+=.01;
976                                         tipvelocity[i].y+=.01;
977                                         start=position[i];
978                                         end=tippoint[i];
979                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
980                                         if(whichhit!=-1)
981                                         closestpoint=colpoint*terrain.scale;
982                                         }
983                                         }*/
984                                         /*if(whichhit!=-1){
985                                         whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
986                                         if(whichhit!=-1){
987                                         colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
988                                         proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
989                                         if(proportion<=1){
990                                         while(whichhit!=-1){
991                                         position[i].y+=.1*proportion;
992                                         tippoint[i].y+=.1*(1-proportion);
993                                         velocity[i].y+=.1*proportion;
994                                         tipvelocity[i].y+=.1*(1-proportion);
995                                         start=position[i];
996                                         end=tippoint[i];
997                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
998                                         }
999                                         position[i].y-=.1*proportion;
1000                                         tippoint[i].y-=.1*(1-proportion);
1001                                         velocity[i].y-=.1*proportion;
1002                                         tipvelocity[i].y-=.1*(1-proportion);
1003                                         start=position[i];
1004                                         end=tippoint[i];
1005                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
1006                                         while(whichhit!=-1){
1007                                         position[i].y+=.01*proportion;
1008                                         tippoint[i].y+=.01*(1-proportion);
1009                                         velocity[i].y+=.01*proportion;
1010                                         tipvelocity[i].y+=.01*(1-proportion);
1011                                         start=position[i];
1012                                         end=tippoint[i];
1013                                         whichhit=terrain.lineTerrain(start,end,&colpoint);
1014                                         }
1015                                         }
1016                                         }
1017                                         }
1018                                         */
1019                                         //Gravity
1020                                         velocity[i].y+=gravity*multiplier;
1021                                         tipvelocity[i].y+=gravity*multiplier;
1022                                         //position[i].y+=gravity*multiplier*multiplier;
1023                                         //tippoint[i].y+=gravity*multiplier*multiplier;
1024
1025                                         //Rotation
1026                                         XYZ temppoint1,temppoint2,tempforward;
1027                                         float distance;
1028
1029                                         temppoint1=position[i];
1030                                         temppoint2=tippoint[i];
1031                                         distance=findDistance(&temppoint1,&temppoint2);
1032                                         rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
1033                                         rotation2[i]*=360/6.28;
1034                                         temppoint1.y=0;
1035                                         temppoint2.y=0;
1036                                         rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
1037                                         rotation1[i]*=360/6.28;
1038                                         rotation3[i]=0;
1039                                         smallrotation[i]=90;
1040                                         smallrotation2[i]=0;
1041                                         bigtilt[i]=0;
1042                                         bigtilt2[i]=0;
1043                                         bigrotation[i]=0;
1044                                         if(temppoint1.x>temppoint2.x)rotation1[i]=360-rotation1[i];
1045
1046                                         //Stop moving
1047                                         if(findLengthfast(&velocity[i])<.3&&findLengthfast(&tipvelocity[i])<.3&&hitsomething[i]){
1048                                                 freetime[i]+=multiplier;
1049                                         }
1050
1051                                         //velocity[i]=(position[i]-oldposition[i])/multiplier;
1052                                         //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;
1053                                         if(freetime[i]>.4){
1054                                                 velocity[i]=0;
1055                                                 tipvelocity[i]=0;
1056                                         }
1057                                         firstfree[i]=0;
1058                         }
1059                 }
1060                 multiplier=tempmult;
1061                 if(blooddrip[i]&&bloody[i]){
1062                         blooddripdelay[i]-=blooddrip[i]*multiplier/2;
1063                         blooddrip[i]-=multiplier;
1064                         if(blooddrip[i]<0)blooddrip[i]=0;
1065                         if(blooddrip[i]>5)blooddrip[i]=5;
1066                         if(blooddripdelay[i]<0&&bloodtoggle){
1067                                 blooddripdelay[i]=1;
1068                                 XYZ bloodvel;
1069                                 XYZ bloodloc;
1070                                 bloodloc=position[i]+(tippoint[i]-position[i])*.7;
1071                                 bloodloc.y-=.05;
1072                                 if(bloodtoggle){
1073                                         bloodvel=0;
1074                                         Sprite::MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
1075                                 }
1076                         }
1077                 }
1078                 if(onfire[i]){
1079                         flamedelay[i]-=multiplier;
1080                         if(onfire[i]&&flamedelay[i]<=0){
1081                                 flamedelay[i]=.020;
1082                                 flamedelay[i]-=multiplier;
1083                                 normalrot=0;
1084                                 if(owner[i]!=-1){
1085                                         normalrot=player[owner[i]].velocity;
1086                                 }
1087                                 normalrot.y+=1;
1088                                 if(owner[i]!=-1){
1089                                         if(player[owner[i]].onterrain){
1090                                                 normalrot.y=1;
1091                                         }
1092                                 }
1093                                 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);
1094                                 Sprite::setLastSpriteSpeed(4);
1095                                 Sprite::setLastSpriteAlivetime(.3);
1096                         }
1097                 }
1098
1099                 if(!onfire[i]&&owner[i]==-1&&type[i]!=staff){
1100                         flamedelay[i]-=multiplier;
1101                         if(flamedelay[i]<=0){
1102                                 flamedelay[i]=.020;
1103                                 flamedelay[i]-=multiplier;
1104                                 normalrot=0;
1105                                 if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
1106                                         XYZ shinepoint;
1107                                         shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
1108                                         Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
1109                                         Sprite::setLastSpriteSpeed(4);
1110                                         Sprite::setLastSpriteAlivetime(.3);
1111                                 }
1112                         }
1113                 }
1114         }
1115 }
1116
1117 int Weapons::Draw()
1118 {
1119         static int i,j;
1120         static XYZ terrainlight;
1121         static GLfloat M[16];
1122         static bool draw;
1123         glAlphaFunc(GL_GREATER, 0.9);
1124         glEnable(GL_TEXTURE_2D);
1125         glEnable(GL_BLEND);
1126         glEnable(GL_CULL_FACE);
1127         glCullFace(GL_FRONT);
1128         glDepthMask(1);
1129         for(i=0;i<numweapons;i++)
1130         {
1131                 if((frustum.SphereInFrustum(position[i].x,position[i].y,position[i].z,1)&&findDistancefast(&viewer,&position[i])<viewdistance*viewdistance))
1132                 {
1133                         draw=0;
1134                         if(owner[i]==-1)
1135                         {
1136                                 draw=1;
1137                                 if(velocity[i].x&&!physics[i])drawhowmany[i]=10;
1138                                 else drawhowmany[i]=1;
1139                         }
1140                         if(owner[i]!=-1)
1141                         {
1142                                 if(player[owner[i]].occluded<25)
1143                                         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)
1144                                                 draw=1;
1145                                 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)
1146                                 {
1147                                         drawhowmany[i]=10;
1148                                 }
1149                                 else drawhowmany[i]=1;
1150                                 if(player[owner[i]].targetanimation==swordgroundstabanim)
1151                                 {
1152                                         lastdrawnrotation1[i]=rotation1[i];
1153                                         lastdrawnrotation2[i]=rotation2[i];
1154                                         lastdrawnrotation3[i]=rotation3[i];
1155                                         lastdrawnbigrotation[i]=bigrotation[i];
1156                                         lastdrawnbigtilt[i]=bigtilt[i];
1157                                         lastdrawnbigtilt2[i]=bigtilt2[i];
1158                                         lastdrawnsmallrotation[i]=smallrotation[i];
1159                                         lastdrawnsmallrotation2[i]=smallrotation2[i];
1160                                 }
1161                         }
1162                         if(draw)
1163                         {
1164                                 terrainlight=terrain.getLighting(position[i].x,position[i].z);
1165                                 if(drawhowmany[i]>0)
1166                                 {
1167                                         glAlphaFunc(GL_GREATER, 0.01);
1168                                 }
1169                                 for(j=drawhowmany[i];j>0;j--)
1170                                 {
1171                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1172                                         glPushMatrix();
1173                                                 glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany[i]);
1174                                                 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]));
1175                                                 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]));
1176                                                 //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1177                                                 glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1178                                                 glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1179                                                 glRotatef(bigtilt[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt[i]*(1-((float)(j))/drawhowmany[i]),0,0,1);
1180                                                 glRotatef(-rotation1[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation1[i]*(1-((float)(j))/drawhowmany[i])+90,0,1,0);
1181                                                 glRotatef(-rotation2[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation2[i]*(1-((float)(j))/drawhowmany[i])+90,0,0,1);
1182                                                 glRotatef(-rotation3[i]*(((float)(j))/drawhowmany[i])-lastdrawnrotation3[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1183                                                 glRotatef(smallrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
1184                                                 glRotatef(smallrotation2[i]*(((float)(j))/drawhowmany[i])+lastdrawnsmallrotation2[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
1185
1186                                                 if(owner[i]!=-1)
1187                                                 {
1188                                                         if(player[owner[i]].targetanimation==staffhitanim||player[owner[i]].currentanimation==staffhitanim||player[owner[i]].targetanimation==staffhitreversedanim||player[owner[i]].currentanimation==staffhitreversedanim)
1189                                                         {
1190                                                                 glTranslatef(0,0,-.3);
1191                                                         }
1192                                                         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)
1193                                                         {
1194                                                                 glTranslatef(0,0,-.1);
1195                                                         }
1196                                                 }
1197                                                 /*if(type[i]==knife){
1198                                                 if(owner[i]==-1){
1199                                                 if(!physics[i]&&findDistance(&position[i],&oldposition[i])*5>1)glScalef(1,1,findDistance(&position[i],&oldposition[i])*5);
1200                                                 }
1201                                                 }*/
1202
1203                                                 if(type[i]==knife)
1204                                                 {
1205                                                         glEnable(GL_LIGHTING);
1206                                                         if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
1207                                                         if(bloodtoggle)
1208                                                         {
1209                                                                 if(bloody[i]==1)throwingknifemodel.drawdifftex(lightbloodknifetextureptr);
1210                                                                 if(bloody[i]==2)throwingknifemodel.drawdifftex(bloodknifetextureptr);
1211                                                         }
1212                                                 }
1213                                                 if(type[i]==sword)
1214                                                 {
1215                                                         glEnable(GL_LIGHTING);
1216                                                         if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
1217                                                         if(bloodtoggle)
1218                                                         {
1219                                                                 if(bloody[i]==1)swordmodel.drawdifftex(lightbloodswordtextureptr);
1220                                                                 if(bloody[i]==2)swordmodel.drawdifftex(bloodswordtextureptr);
1221                                                         }
1222                                                 }
1223                                                 if(type[i]==staff)
1224                                                 {
1225                                                         glEnable(GL_LIGHTING);
1226                                                         staffmodel.drawdifftex(stafftextureptr);
1227                                                 }
1228
1229                                         glPopMatrix();
1230                                 }
1231
1232                                 lastdrawnposition[i]=position[i];
1233                                 lastdrawntippoint[i]=tippoint[i];
1234                                 lastdrawnrotation1[i]=rotation1[i];
1235                                 lastdrawnrotation2[i]=rotation2[i];
1236                                 lastdrawnrotation3[i]=rotation3[i];
1237                                 lastdrawnbigrotation[i]=bigrotation[i];
1238                                 lastdrawnbigtilt[i]=bigtilt[i];
1239                                 lastdrawnbigtilt2[i]=bigtilt2[i];
1240                                 lastdrawnsmallrotation[i]=smallrotation[i];
1241                                 lastdrawnsmallrotation2[i]=smallrotation2[i];
1242                                 if(owner[i]!=-1)lastdrawnanim[i]=player[owner[i]].currentanimation;
1243                         }
1244                         if(owner[i]!=-1)
1245                         {
1246                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
1247                                 glPushMatrix();
1248                                         glLoadIdentity();
1249                                         glTranslatef(position[i].x,position[i].y-.02,position[i].z);
1250                                         glRotatef(bigrotation[i],0,1,0);
1251                                         glRotatef(bigtilt2[i],1,0,0);
1252                                         glRotatef(bigtilt[i],0,0,1);
1253                                         glRotatef(-rotation1[i]+90,0,1,0);
1254                                         glRotatef(-rotation2[i]+90,0,0,1);
1255                                         glRotatef(-rotation3[i],0,1,0);
1256                                         glRotatef(smallrotation[i],1,0,0);
1257                                         glRotatef(smallrotation2[i],0,1,0);
1258                                         glTranslatef(0,0,length[i]);
1259                                         glGetFloatv(GL_MODELVIEW_MATRIX,M);
1260                                         tippoint[i].x=M[12];
1261                                         tippoint[i].y=M[13];
1262                                         tippoint[i].z=M[14];
1263                                 glPopMatrix();
1264                         }
1265                         /*XYZ shinepoint;
1266                         XYZ nothingpoint;
1267                         nothingpoint=0;
1268                         shinepoint=position[i];
1269                         Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1270                         Sprite::speed[Sprite::numsprites-1]=4;
1271                         Sprite::alivetime[Sprite::numsprites-1]=.3;
1272                         shinepoint=tippoint[i];
1273                         Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
1274                         Sprite::speed[Sprite::numsprites-1]=4;
1275                         Sprite::alivetime[Sprite::numsprites-1]=.3;*/
1276                 }
1277         }
1278         return 0;
1279 }
1280
1281 Weapons::Weapons()
1282 {
1283         numweapons = 0;
1284
1285         //              Model throwingknifemodel;
1286         knifetextureptr = 0;
1287         lightbloodknifetextureptr = 0;
1288         bloodknifetextureptr = 0;
1289
1290         //              Model swordmodel;
1291         swordtextureptr = 0;
1292         lightbloodswordtextureptr = 0;
1293         bloodswordtextureptr = 0;
1294
1295         //              Model staffmodel;
1296         stafftextureptr = 0;
1297 }
1298
1299 Weapons::~Weapons()
1300 {
1301         if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
1302         if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
1303         if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
1304         if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
1305         if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
1306         if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
1307         if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );
1308 }
1309