]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Weapons.cpp
Make animation types an enum, move to a separate file
[lugaru.git] / Source / Weapons.cpp
index 390dbd3bc36d71fb9db1f23ac3b529e965fec336..2c48dd80256b10566a3dea78a312f1c50f96e281 100644 (file)
@@ -1,14 +1,36 @@
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
 /**> HEADER FILES <**/
 #include "Weapons.h"
+#include "openal_wrapper.h"
+#include "Animation.h"
 
 extern float multiplier;
 extern Animation animation[animation_count];
-extern FSOUND_SAMPLE   *samp[100];
+extern OPENAL_SAMPLE   *samp[100];
 extern int channels[100];
 extern Terrain terrain;
 extern float gravity;
 extern int environment;
-extern Sprites sprites;
 extern int detail;
 extern FRUSTUM frustum;
 extern XYZ viewer;
@@ -37,9 +59,9 @@ extern float bonustotal;
 extern float bonustime;
 extern int tutoriallevel;
 extern int numthrowkill;
-extern "C"     void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused);
+extern "C"     void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 
-void   Weapons::DoStuff(){
+void   Weapons::DoStuff(){
        static int i,whichpatchx,whichpatchz,j,k,whichhit,m;
        static XYZ start,end,colpoint,normalrot,footvel,footpoint;
        static XYZ terrainnormal;
@@ -76,27 +98,20 @@ void        Weapons::DoStuff(){
                        vel[0]=0;
                        vel[1]=0;
                        vel[2]=0;
-                       PlaySoundEx( staffbreaksound, samp[staffbreaksound], NULL, TRUE);
-                       FSOUND_3D_SetAttributes(channels[staffbreaksound], gLoc, vel);
-                       FSOUND_SetVolume(channels[staffbreaksound], 256);
-                       FSOUND_SetPaused(channels[staffbreaksound], FALSE);
+                       PlaySoundEx( staffbreaksound, samp[staffbreaksound], NULL, true);
+                       OPENAL_3D_SetAttributes(channels[staffbreaksound], gLoc, vel);
+                       OPENAL_SetVolume(channels[staffbreaksound], 256);
+                       OPENAL_SetPaused(channels[staffbreaksound], false);
                        XYZ tempvel;
                        XYZ speed;
                        //speed=(tippoint[i]-oldtippoint[i])/multiplier/6;
                        speed=0;
-                       /*for(j=0;j<10;j++){
-                       tempvel.x=float(abs(Random()%100)-50)/20;
-                       tempvel.y=float(abs(Random()%100)-50)/20;
-                       tempvel.z=float(abs(Random()%100)-50)/20;
-                       tempvel+=speed;
-                       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);
-                       }*/
                        for(j=0;j<40;j++){
                                tempvel.x=float(abs(Random()%100)-50)/20;
                                tempvel.y=float(abs(Random()%100)-50)/20;
                                tempvel.z=float(abs(Random()%100)-50)/20;
                                tempvel+=speed;
-                               sprites.MakeSprite(splintersprite, position[i]+(tippoint[i]-position[i])*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
+                               Sprite::MakeSprite(splintersprite, position[i]+(tippoint[i]-position[i])*((float)j-8)/32,tempvel*.5, 115/255,73/255,12/255, .1, 1);
                        }
                        int tempowner;
                        tempowner=owner[i];
@@ -167,14 +182,14 @@ void      Weapons::DoStuff(){
                                                                vel[0]=0;
                                                                vel[1]=0;
                                                                vel[2]=0;
-                                                               PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, TRUE);
-                                                               FSOUND_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
-                                                               FSOUND_SetVolume(channels[knifesheathesound], 128);
-                                                               FSOUND_SetPaused(channels[knifesheathesound], FALSE);
+                                                               PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
+                                                               OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
+                                                               OPENAL_SetVolume(channels[knifesheathesound], 128);
+                                                               OPENAL_SetPaused(channels[knifesheathesound], false);
 
                                                                bloody[i]=0;
 
-                                                               sprites.MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);                          
+                                                               Sprite::MakeSprite(cloudimpactsprite, position[i],velocity[i], 1,1,1, .8, .3);
                                                        }
                                                        else {
                                                                physics[i]=1;
@@ -183,13 +198,13 @@ void      Weapons::DoStuff(){
                                                                tippoint[i]-=velocity[i]*multiplier;
                                                                tipvelocity[i]=velocity[i];
                                                        }
-                                               }       
+                                               }
                                        }
                                }
                                if(velocity[i].x||velocity[i].y||velocity[i].z)
                                        for(j=0;j<numplayers;j++){
                                                footvel=0;
-                                               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;                         
+                                               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;
                                                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]){
                                                        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]){
                                                                bool caught=0;
@@ -202,10 +217,10 @@ void      Weapons::DoStuff(){
                                                                        vel[0]=player[j].velocity.x;
                                                                        vel[1]=player[j].velocity.y;
                                                                        vel[2]=player[j].velocity.z;
-                                                                       PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, TRUE);
-                                                                       FSOUND_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
-                                                                       FSOUND_SetVolume(channels[knifedrawsound], 128);
-                                                                       FSOUND_SetPaused(channels[knifedrawsound], FALSE);
+                                                                       PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
+                                                                       OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
+                                                                       OPENAL_SetVolume(channels[knifedrawsound], 128);
+                                                                       OPENAL_SetPaused(channels[knifedrawsound], false);
 
                                                                        player[j].weaponactive=0;
                                                                        player[j].targetanimation=removeknifeanim;
@@ -235,11 +250,11 @@ void      Weapons::DoStuff(){
                                                                        player[j].skeleton.joints[player[j].skeleton.jointlabels[rightshoulder]].velocity+=velocity[i]*2;
                                                                        player[j].skeleton.joints[player[j].skeleton.jointlabels[leftshoulder]].velocity+=velocity[i]*2;
                                                                        //player[j].Puff(abdomen);
-                                                                       if(bloodtoggle&&tutoriallevel!=1)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
-                                                                       if(tutoriallevel==1)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
+                                                                       if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
+                                                                       if(tutoriallevel==1)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .8, .3);
                                                                        footvel=tippoint[i]-position[i];
                                                                        Normalise(&footvel);
-                                                                       if(bloodtoggle&&tutoriallevel!=1)sprites.MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
+                                                                       if(bloodtoggle&&tutoriallevel!=1)Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*-1, 1,0,0, .6, 1);
 
                                                                        if(tutoriallevel!=1){
                                                                                if(player[j].weaponstuckwhere==0)player[j].DoBloodBig(2,205);
@@ -260,10 +275,10 @@ void      Weapons::DoStuff(){
                                                                        vel[0]=0;
                                                                        vel[1]=0;
                                                                        vel[2]=0;
-                                                                       PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, TRUE);
-                                                                       FSOUND_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
-                                                                       FSOUND_SetVolume(channels[fleshstabsound], 128);
-                                                                       FSOUND_SetPaused(channels[fleshstabsound], FALSE);
+                                                                       PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
+                                                                       OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
+                                                                       OPENAL_SetVolume(channels[fleshstabsound], 128);
+                                                                       OPENAL_SetPaused(channels[fleshstabsound], false);
 
                                                                        if(animation[player[0].targetanimation].height==highheight){
                                                                                bonus=ninja;
@@ -278,7 +293,7 @@ void        Weapons::DoStuff(){
                                                                }
                                                        }
                                                        else missed[i]=1;
-                                               }       
+                                               }
                                        }
                                        if(position[i].y<terrain.getHeight(position[i].x,position[i].z)){
                                                if(terrain.getOpacity(position[i].x,position[i].z)<.2){
@@ -304,7 +319,7 @@ void        Weapons::DoStuff(){
                                                                glRotatef(-rotation3[i],0,1,0);
                                                                glRotatef(smallrotation[i],1,0,0);
                                                                glRotatef(smallrotation2[i],0,1,0);
-                                                               glTranslatef(0,0,1);            
+                                                               glTranslatef(0,0,1);
                                                                glGetFloatv(GL_MODELVIEW_MATRIX,M);
                                                                tippoint[i].x=M[12];
                                                                tippoint[i].y=M[13];
@@ -329,21 +344,21 @@ void      Weapons::DoStuff(){
                                                        vel[0]=0;
                                                        vel[1]=0;
                                                        vel[2]=0;
-                                                       PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, TRUE);
-                                                       FSOUND_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
-                                                       FSOUND_SetVolume(channels[knifesheathesound], 128);
-                                                       FSOUND_SetPaused(channels[knifesheathesound], FALSE);
+                                                       PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
+                                                       OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
+                                                       OPENAL_SetVolume(channels[knifesheathesound], 128);
+                                                       OPENAL_SetPaused(channels[knifesheathesound], false);
 
                                                        XYZ terrainlight;
                                                        terrainlight=terrain.getLighting(position[i].x,position[i].z);
                                                        if(environment==snowyenvironment){
-                                                               if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
+                                                               if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
                                                        }
                                                        else if(environment==grassyenvironment){
-                                                               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);
+                                                               if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
                                                        }
                                                        else if(environment==desertenvironment){
-                                                               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);
+                                                               if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
                                                        }
 
                                                        bloody[i]=0;
@@ -427,7 +442,7 @@ void        Weapons::DoStuff(){
                                                                                hitsomething[i]=1;
 
                                                                                position[i]+=(colpoint-tippoint[i])+diff*.05;
-                                                                               tippoint[i]=colpoint+diff*.05;                                                  
+                                                                               tippoint[i]=colpoint+diff*.05;
                                                                                oldposition[i]=position[i];
                                                                                oldtippoint[i]=tippoint[i];
                                                                        }
@@ -443,7 +458,7 @@ void        Weapons::DoStuff(){
                                                                                hitsomething[i]=1;
 
                                                                                tippoint[i]+=(colpoint-position[i])+diff*.05;
-                                                                               position[i]=colpoint+diff*.05;                                                  
+                                                                               position[i]=colpoint+diff*.05;
                                                                                oldtippoint[i]=tippoint[i];
                                                                                oldposition[i]=tippoint[i];
                                                                        }
@@ -455,7 +470,7 @@ void        Weapons::DoStuff(){
                                                        whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
                                                        if(whichhit!=-1){
                                                                hitsomething[i]=1;
-                                                               position[i]=colpoint;                   
+                                                               position[i]=colpoint;
                                                                terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
                                                                ReflectVector(&velocity[i],&terrainnormal);
                                                                position[i]+=terrainnormal*.002;
@@ -480,10 +495,10 @@ void      Weapons::DoStuff(){
                                                                        vel[0]=0;
                                                                        vel[1]=0;
                                                                        vel[2]=0;
-                                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
-                                                                       FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                                       FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                                       FSOUND_SetPaused(channels[whichsound], FALSE);
+                                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
+                                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
+                                                                       OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
+                                                                       OPENAL_SetPaused(channels[whichsound], false);
                                                                }
                                                        }
                                                        start=oldtippoint[i];
@@ -491,7 +506,7 @@ void        Weapons::DoStuff(){
                                                        whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
                                                        if(whichhit!=-1){
                                                                hitsomething[i]=1;
-                                                               tippoint[i]=colpoint;                   
+                                                               tippoint[i]=colpoint;
                                                                terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
                                                                ReflectVector(&tipvelocity[i],&terrainnormal);
                                                                tippoint[i]+=terrainnormal*.002;
@@ -517,10 +532,10 @@ void      Weapons::DoStuff(){
                                                                        vel[0]=0;
                                                                        vel[1]=0;
                                                                        vel[2]=0;
-                                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
-                                                                       FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                                       FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                                       FSOUND_SetPaused(channels[whichsound], FALSE);
+                                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
+                                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
+                                                                       OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
+                                                                       OPENAL_SetPaused(channels[whichsound], false);
                                                                }
                                                        }
 
@@ -535,7 +550,7 @@ void        Weapons::DoStuff(){
                                                                        whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
                                                                        if(whichhit!=-1){
                                                                                hitsomething[i]=1;
-                                                                               mid=colpoint;                   
+                                                                               mid=colpoint;
                                                                                terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
                                                                                ReflectVector(&velocity[i],&terrainnormal);
 
@@ -559,10 +574,10 @@ void      Weapons::DoStuff(){
                                                                                        vel[0]=0;
                                                                                        vel[1]=0;
                                                                                        vel[2]=0;
-                                                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
-                                                                                       FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                                                       FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                                                       FSOUND_SetPaused(channels[whichsound], FALSE);
+                                                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
+                                                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
+                                                                                       OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
+                                                                                       OPENAL_SetPaused(channels[whichsound], false);
                                                                                }
                                                                                position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
                                                                        }
@@ -576,7 +591,7 @@ void        Weapons::DoStuff(){
                                                                        whichhit=objects.model[k].LineCheck(&start,&end,&colpoint,&objects.position[k],&objects.rotation[k]);
                                                                        if(whichhit!=-1){
                                                                                hitsomething[i]=1;
-                                                                               mid=colpoint;                   
+                                                                               mid=colpoint;
                                                                                terrainnormal=DoRotation(objects.model[k].facenormals[whichhit],0,objects.rotation[k],0)*-1;
                                                                                ReflectVector(&tipvelocity[i],&terrainnormal);
 
@@ -600,10 +615,10 @@ void      Weapons::DoStuff(){
                                                                                        vel[0]=0;
                                                                                        vel[1]=0;
                                                                                        vel[2]=0;
-                                                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
-                                                                                       FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                                                       FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                                                       FSOUND_SetPaused(channels[whichsound], FALSE);
+                                                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
+                                                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
+                                                                                       OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
+                                                                                       OPENAL_SetPaused(channels[whichsound], false);
                                                                                }
                                                                                tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
                                                                        }
@@ -643,7 +658,7 @@ void        Weapons::DoStuff(){
                                                                                                                closestswordpoint=colpoint;
                                                                                                                velocity[i]+=(closestpoint-closestswordpoint);
                                                                                                                tipvelocity[i]+=(closestpoint-closestswordpoint);
-                                                                                                               position[i]+=(closestpoint-closestswordpoint);          
+                                                                                                               position[i]+=(closestpoint-closestswordpoint);
                                                                                                                tippoint[i]+=(closestpoint-closestswordpoint);
                                                                                                        }
                                                                                                }
@@ -670,7 +685,7 @@ void        Weapons::DoStuff(){
                                                else velocity[i]=0;
                                                if(terrain.getOpacity(position[i].x,position[i].z)<.2)velocity[i]+=bounceness*elasticity*.3;
                                                else velocity[i]+=bounceness*elasticity;
-
+//if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
                                                if(findLengthfast(&bounceness)>1){
                                                        float gLoc[3];
                                                        float vel[3];
@@ -686,23 +701,23 @@ void      Weapons::DoStuff(){
                                                        vel[0]=0;
                                                        vel[1]=0;
                                                        vel[2]=0;
-                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
-                                                       FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                       else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
-                                                       FSOUND_SetPaused(channels[whichsound], FALSE);
+                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
+                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
+                                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
+                                                       else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
+                                                       OPENAL_SetPaused(channels[whichsound], false);
 
                                                        if(terrain.getOpacity(position[i].x,position[i].z)<.2){
                                                                XYZ terrainlight;
                                                                terrainlight=terrain.getLighting(position[i].x,position[i].z);
                                                                if(environment==snowyenvironment){
-                                                                       if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
+                                                                       if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
                                                                }
                                                                else if(environment==grassyenvironment){
-                                                                       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);
+                                                                       if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
                                                                }
                                                                else if(environment==desertenvironment){
-                                                                       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);
+                                                                       if(findDistancefast(&position[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, position[i],velocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
                                                                }
                                                        }
                                                }
@@ -723,6 +738,7 @@ void        Weapons::DoStuff(){
                                                else tipvelocity[i]=0;
                                                if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
                                                else tipvelocity[i]+=bounceness*elasticity;
+//if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
 
                                                if(findLengthfast(&bounceness)>1){
                                                        float gLoc[3];
@@ -739,23 +755,23 @@ void      Weapons::DoStuff(){
                                                        vel[0]=0;
                                                        vel[1]=0;
                                                        vel[2]=0;
-                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
-                                                       FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                       if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                       else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
-                                                       FSOUND_SetPaused(channels[whichsound], FALSE);
+                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
+                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
+                                                       if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
+                                                       else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
+                                                       OPENAL_SetPaused(channels[whichsound], false);
 
                                                        if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
                                                                XYZ terrainlight;
                                                                terrainlight=terrain.getLighting(tippoint[i].x,tippoint[i].z);
                                                                if(environment==snowyenvironment){
-                                                                       if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)sprites.MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
+                                                                       if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x,terrainlight.y,terrainlight.z, .5, .7);
                                                                }
                                                                else if(environment==grassyenvironment){
-                                                                       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);
+                                                                       if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5);
                                                                }
                                                                else if(environment==desertenvironment){
-                                                                       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);
+                                                                       if(findDistancefast(&tippoint[i],&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, tippoint[i],tipvelocity[i], terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7);
                                                                }
                                                        }
                                                }
@@ -797,11 +813,11 @@ void      Weapons::DoStuff(){
                                                        vel[0]=0;
                                                        vel[1]=0;
                                                        vel[2]=0;
-                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
-                                                       FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                       else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
-                                                       FSOUND_SetPaused(channels[whichsound], FALSE);
+                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
+                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
+                                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
+                                                       else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
+                                                       OPENAL_SetPaused(channels[whichsound], false);
                                                }
                                                position[i]+=(mid-oldmid)*20;
                                        }
@@ -841,11 +857,11 @@ void      Weapons::DoStuff(){
                                                        vel[0]=0;
                                                        vel[1]=0;
                                                        vel[2]=0;
-                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
-                                                       FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                       else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
-                                                       FSOUND_SetPaused(channels[whichsound], FALSE);
+                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
+                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
+                                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
+                                                       else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
+                                                       OPENAL_SetPaused(channels[whichsound], false);
                                                }
                                                tippoint[i]+=(mid-oldmid)*20;
                                        }
@@ -883,11 +899,11 @@ void      Weapons::DoStuff(){
                                        vel[0]=0;
                                        vel[1]=0;
                                        vel[2]=0;
-                                       PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
-                                       FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                       else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
-                                       FSOUND_SetPaused(channels[whichsound], FALSE);
+                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
+                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
+                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
+                                       else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
+                                       OPENAL_SetPaused(channels[whichsound], false);
                                        }
                                        }
 
@@ -922,11 +938,11 @@ void      Weapons::DoStuff(){
                                        vel[0]=0;
                                        vel[1]=0;
                                        vel[2]=0;
-                                       PlaySoundEx( whichsound, samp[whichsound], NULL, TRUE);
-                                       FSOUND_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                       if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)FSOUND_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                       else FSOUND_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
-                                       FSOUND_SetPaused(channels[whichsound], FALSE);
+                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
+                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
+                                       if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
+                                       else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
+                                       OPENAL_SetPaused(channels[whichsound], false);
                                        }
                                        }*/
 
@@ -1038,7 +1054,7 @@ void      Weapons::DoStuff(){
                                        }
 
                                        //velocity[i]=(position[i]-oldposition[i])/multiplier;
-                                       //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;                      
+                                       //tipvelocity[i]==(tippoint[i-+oldtippoint[i])/multiplier;
                                        if(freetime[i]>.4){
                                                velocity[i]=0;
                                                tipvelocity[i]=0;
@@ -1060,8 +1076,8 @@ void      Weapons::DoStuff(){
                                bloodloc.y-=.05;
                                if(bloodtoggle){
                                        bloodvel=0;
-                                       sprites.MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
-                               }                       
+                                       Sprite::MakeSprite(bloodsprite, bloodloc,bloodvel, 1,1,1, .03, 1);
+                               }
                        }
                }
                if(onfire[i]){
@@ -1079,9 +1095,9 @@ void      Weapons::DoStuff(){
                                                normalrot.y=1;
                                        }
                                }
-                               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);
-                               sprites.speed[sprites.numsprites-1]=4;
-                               sprites.alivetime[sprites.numsprites-1]=.3;
+                               Sprite::MakeSprite(weaponflamesprite, position[i]+tippoint[i]*(((float)abs(Random()%100))/600+.05),normalrot, 1,1,1, (.6+(float)abs(Random()%100)/200-.25)*1/3, 1);
+                               Sprite::setLastSpriteSpeed(4);
+                               Sprite::setLastSpriteAlivetime(.3);
                        }
                }
 
@@ -1094,9 +1110,9 @@ void      Weapons::DoStuff(){
                                if(Random()%50==0&&findDistancefast(&position[i],&viewer)>80){
                                        XYZ shinepoint;
                                        shinepoint=position[i]+(tippoint[i]-position[i])*(((float)abs(Random()%100))/100);
-                                       sprites.MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
-                                       sprites.speed[sprites.numsprites-1]=4;
-                                       sprites.alivetime[sprites.numsprites-1]=.3;
+                                       Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1);
+                                       Sprite::setLastSpriteSpeed(4);
+                                       Sprite::setLastSpriteAlivetime(.3);
                                }
                        }
                }
@@ -1160,8 +1176,8 @@ int Weapons::Draw()
                                        glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
                                        glPushMatrix();
                                                glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,j/drawhowmany[i]);
-                                               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]));             
-                                               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]));                 
+                                               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]));
+                                               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]));
                                                //glTranslatef(position[i].x,position[i].y-.02,position[i].z);
                                                glRotatef(bigrotation[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigrotation[i]*(1-((float)(j))/drawhowmany[i]),0,1,0);
                                                glRotatef(bigtilt2[i]*(((float)(j))/drawhowmany[i])+lastdrawnbigtilt2[i]*(1-((float)(j))/drawhowmany[i]),1,0,0);
@@ -1191,7 +1207,7 @@ int Weapons::Draw()
 
                                                if(type[i]==knife)
                                                {
-                                                       glEnable(GL_LIGHTING);  
+                                                       glEnable(GL_LIGHTING);
                                                        if(!bloody[i]||!bloodtoggle)throwingknifemodel.drawdifftex(knifetextureptr);
                                                        if(bloodtoggle)
                                                        {
@@ -1201,7 +1217,7 @@ int Weapons::Draw()
                                                }
                                                if(type[i]==sword)
                                                {
-                                                       glEnable(GL_LIGHTING);  
+                                                       glEnable(GL_LIGHTING);
                                                        if(!bloody[i]||!bloodtoggle)swordmodel.drawdifftex(swordtextureptr);
                                                        if(bloodtoggle)
                                                        {
@@ -1211,7 +1227,7 @@ int Weapons::Draw()
                                                }
                                                if(type[i]==staff)
                                                {
-                                                       glEnable(GL_LIGHTING);  
+                                                       glEnable(GL_LIGHTING);
                                                        staffmodel.drawdifftex(stafftextureptr);
                                                }
 
@@ -1244,7 +1260,7 @@ int Weapons::Draw()
                                        glRotatef(-rotation3[i],0,1,0);
                                        glRotatef(smallrotation[i],1,0,0);
                                        glRotatef(smallrotation2[i],0,1,0);
-                                       glTranslatef(0,0,length[i]);            
+                                       glTranslatef(0,0,length[i]);
                                        glGetFloatv(GL_MODELVIEW_MATRIX,M);
                                        tippoint[i].x=M[12];
                                        tippoint[i].y=M[13];
@@ -1255,13 +1271,13 @@ int Weapons::Draw()
                        XYZ nothingpoint;
                        nothingpoint=0;
                        shinepoint=position[i];
-                       sprites.MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
-                       sprites.speed[sprites.numsprites-1]=4;
-                       sprites.alivetime[sprites.numsprites-1]=.3;
+                       Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
+                       Sprite::speed[Sprite::numsprites-1]=4;
+                       Sprite::alivetime[Sprite::numsprites-1]=.3;
                        shinepoint=tippoint[i];
-                       sprites.MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
-                       sprites.speed[sprites.numsprites-1]=4;
-                       sprites.alivetime[sprites.numsprites-1]=.3;*/
+                       Sprite::MakeSprite(weaponshinesprite, shinepoint,nothingpoint, 1,1,1,multiplier*2, 1);
+                       Sprite::speed[Sprite::numsprites-1]=4;
+                       Sprite::alivetime[Sprite::numsprites-1]=.3;*/
                }
        }
        return 0;
@@ -1269,53 +1285,7 @@ int Weapons::Draw()
 
 Weapons::Weapons()
 {
-       rotation1.resize(max_weaponinstances);
-       rotation2.resize(max_weaponinstances);
-       rotation3.resize(max_weaponinstances);
-       bigrotation.resize(max_weaponinstances);
-       bigtilt.resize(max_weaponinstances);
-       bigtilt2.resize(max_weaponinstances);
-       smallrotation.resize(max_weaponinstances);
-       smallrotation2.resize(max_weaponinstances);
-       damage.resize(max_weaponinstances);
-
        numweapons = 0;
-       tippoint.resize(max_weaponinstances);
-       oldtippoint.resize(max_weaponinstances);
-       position.resize(max_weaponinstances);
-       lastmult.resize(max_weaponinstances);
-       oldposition.resize(max_weaponinstances);
-       velocity.resize(max_weaponinstances);
-       tipvelocity.resize(max_weaponinstances);
-       type.resize(max_weaponinstances);
-       oldowner.resize(max_weaponinstances);
-       owner.resize(max_weaponinstances);
-       bloody.resize(max_weaponinstances);
-       blooddrip.resize(max_weaponinstances);
-       blooddripdelay.resize(max_weaponinstances);
-       onfire.resize(max_weaponinstances);
-       flamedelay.resize(max_weaponinstances);
-       missed.resize(max_weaponinstances);
-       mass.resize(max_weaponinstances);
-       tipmass.resize(max_weaponinstances);
-       length.resize(max_weaponinstances);
-       freetime.resize(max_weaponinstances);
-       firstfree.resize(max_weaponinstances);
-       physics.resize(max_weaponinstances);
-       drawhowmany.resize(max_weaponinstances);
-       hitsomething.resize(max_weaponinstances);
-
-       lastdrawnposition.resize(max_weaponinstances);
-       lastdrawntippoint.resize(max_weaponinstances);
-       lastdrawnrotation1.resize(max_weaponinstances);
-       lastdrawnrotation2.resize(max_weaponinstances);
-       lastdrawnrotation3.resize(max_weaponinstances);
-       lastdrawnbigrotation.resize(max_weaponinstances);
-       lastdrawnbigtilt.resize(max_weaponinstances);
-       lastdrawnbigtilt2.resize(max_weaponinstances);
-       lastdrawnsmallrotation.resize(max_weaponinstances);
-       lastdrawnsmallrotation2.resize(max_weaponinstances);
-       lastdrawnanim.resize(max_weaponinstances);
 
        //              Model throwingknifemodel;
        knifetextureptr = 0;
@@ -1333,12 +1303,12 @@ Weapons::Weapons()
 
 Weapons::~Weapons()
 {
-       if (stafftextureptr) glDeleteTextures( 1, (const unsigned long *)&stafftextureptr );
-       if (knifetextureptr) glDeleteTextures( 1, (const unsigned long *)&knifetextureptr );
-       if (lightbloodknifetextureptr) glDeleteTextures( 1, (const unsigned long *)&lightbloodknifetextureptr );
-       if (bloodknifetextureptr) glDeleteTextures( 1, (const unsigned long *)&bloodknifetextureptr );
-       if (swordtextureptr) glDeleteTextures( 1, (const unsigned long *)&swordtextureptr );
-       if (lightbloodswordtextureptr) glDeleteTextures( 1, (const unsigned long *)&lightbloodswordtextureptr );
-       if (bloodswordtextureptr) glDeleteTextures( 1, (const unsigned long *)&bloodswordtextureptr );
+       if (stafftextureptr) glDeleteTextures( 1, &stafftextureptr );
+       if (knifetextureptr) glDeleteTextures( 1, &knifetextureptr );
+       if (lightbloodknifetextureptr) glDeleteTextures( 1, &lightbloodknifetextureptr );
+       if (bloodknifetextureptr) glDeleteTextures( 1, &bloodknifetextureptr );
+       if (swordtextureptr) glDeleteTextures( 1, &swordtextureptr );
+       if (lightbloodswordtextureptr) glDeleteTextures( 1, &lightbloodswordtextureptr );
+       if (bloodswordtextureptr) glDeleteTextures( 1, &bloodswordtextureptr );
 }