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