]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Weapons.cpp
Remove some extra declarations of "channels"
[lugaru.git] / Source / Weapons.cpp
index c4ee9f5aab46efaa74613997cf8141f5c167ed6a..0edca797df5ab4415985668e044efdeb9e15a4ab 100644 (file)
@@ -21,15 +21,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 /**> HEADER FILES <**/
 #include "Weapons.h"
+#include "openal_wrapper.h"
+#include "Animation.h"
+#include "Sounds.h"
+#include "Game.h"
+#include "Awards.h"
 
 extern float multiplier;
-extern Animation animation[animation_count];
-extern FSOUND_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;
@@ -49,16 +50,9 @@ extern float terraindetail;
 extern float viewdistance;
 extern float blackout;
 extern int difficulty;
-extern Person player[maxplayers];
-extern int numplayers;
 extern bool freeze;
-extern int bonus;
-extern float bonusvalue;
-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);
 
 void   Weapons::DoStuff(){
        static int i,whichpatchx,whichpatchz,j,k,whichhit,m;
@@ -89,35 +83,17 @@ void        Weapons::DoStuff(){
                        oldowner[i]=owner[i];
                }
                if(damage[i]>=2&&type[i]==staff&&owner[i]!=-1){
-                       float gLoc[3];
-                       float vel[3];
-                       gLoc[0]=tippoint[i].x;
-                       gLoc[1]=tippoint[i].y;
-                       gLoc[2]=tippoint[i].z;
-                       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);
+                       emit_sound_at(staffbreaksound, tippoint[i]);
                        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];
@@ -180,22 +156,11 @@ void      Weapons::DoStuff(){
                                                                bigtilt2[i]=0;
                                                                bigrotation[i]=0;
 
-                                                               float gLoc[3];
-                                                               float vel[3];
-                                                               gLoc[0]=position[i].x;
-                                                               gLoc[1]=position[i].y;
-                                                               gLoc[2]=position[i].z;
-                                                               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);
+                                                               emit_sound_at(knifesheathesound, position[i], 128.);
 
                                                                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;
@@ -215,18 +180,7 @@ void       Weapons::DoStuff(){
                                                        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;
                                                                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)){
-                                                                       float gLoc[3];
-                                                                       float vel[3];
-                                                                       gLoc[0]=player[j].coords.x;
-                                                                       gLoc[1]=player[j].coords.y;
-                                                                       gLoc[2]=player[j].coords.z;
-                                                                       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);
+                                                                       emit_sound_at(knifedrawsound, player[j].coords, 128.);
 
                                                                        player[j].weaponactive=0;
                                                                        player[j].targetanimation=removeknifeanim;
@@ -256,11 +210,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);
@@ -273,29 +227,12 @@ void      Weapons::DoStuff(){
                                                                                blooddrip[i]=5;
                                                                        }
 
-                                                                       float gLoc[3];
-                                                                       float vel[3];
-                                                                       gLoc[0]=position[i].x;
-                                                                       gLoc[1]=position[i].y;
-                                                                       gLoc[2]=position[i].z;
-                                                                       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);
-
-                                                                       if(animation[player[0].targetanimation].height==highheight){
-                                                                               bonus=ninja;
-                                                                               bonustime=0;
-                                                                               bonusvalue=60;
-                                                                       }
-                                                                       else{
-                                                                               bonus=Bullseyebonus;
-                                                                               bonustime=0;
-                                                                               bonusvalue=30;
-                                                                       }
+                                                                       emit_sound_at(fleshstabsound, position[i], 128.);
+
+                                                                       if(animation[player[0].targetanimation].height==highheight)
+                                                                         award_bonus(0, ninja);
+                                                                       else
+                                                                         award_bonus(0, Bullseyebonus);
                                                                }
                                                        }
                                                        else missed[i]=1;
@@ -342,29 +279,18 @@ void      Weapons::DoStuff(){
                                                        bigtilt2[i]=0;
                                                        bigrotation[i]=0;
 
-                                                       float gLoc[3];
-                                                       float vel[3];
-                                                       gLoc[0]=position[i].x;
-                                                       gLoc[1]=position[i].y;
-                                                       gLoc[2]=position[i].z;
-                                                       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);
+                                                       emit_sound_at(knifesheathesound, position[i], 128.);
 
                                                        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;
@@ -490,21 +416,10 @@ void      Weapons::DoStuff(){
                                                                velocity[i]+=bounceness*elasticity;
 
                                                                if(findLengthfast(&bounceness)>1){
-                                                                       float gLoc[3];
-                                                                       float vel[3];
-                                                                       //int whichsound=clank1sound+abs(Random()%4);
                                                                        int whichsound;
                                                                        if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
-                                                                       if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
-                                                                       gLoc[1]=position[i].y;
-                                                                       gLoc[2]=position[i].z;
-                                                                       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);
+                                                                       if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
+                                                                       emit_sound_at(whichsound, position[i], 128*findLengthfast(&bounceness));
                                                                }
                                                        }
                                                        start=oldtippoint[i];
@@ -526,22 +441,10 @@ void      Weapons::DoStuff(){
                                                                tipvelocity[i]+=bounceness*elasticity;
 
                                                                if(findLengthfast(&bounceness)>1){
-                                                                       float gLoc[3];
-                                                                       float vel[3];
-                                                                       //int whichsound=clank1sound+abs(Random()%4);
                                                                        int whichsound;
                                                                        if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
-                                                                       if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=position[i].x;
-                                                                       gLoc[0]=position[i].x;
-                                                                       gLoc[1]=position[i].y;
-                                                                       gLoc[2]=position[i].z;
-                                                                       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);
+                                                                       if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
+                                                                       emit_sound_at(whichsound, position[i], 128*findLengthfast(&bounceness));
                                                                }
                                                        }
 
@@ -569,21 +472,10 @@ void      Weapons::DoStuff(){
                                                                                velocity[i]+=bounceness*elasticity;
 
                                                                                if(findLengthfast(&bounceness)>1){
-                                                                                       float gLoc[3];
-                                                                                       float vel[3];
-                                                                                       //int whichsound=clank1sound+abs(Random()%4);
                                                                                        int whichsound;
                                                                                        if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
-                                                                                       if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
-                                                                                       gLoc[1]=mid.y;
-                                                                                       gLoc[2]=mid.z;
-                                                                                       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);
+                                                                                       if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
+                                                                                       emit_sound_at(whichsound, mid, 128*findLengthfast(&bounceness));
                                                                                }
                                                                                position[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
                                                                        }
@@ -610,21 +502,10 @@ void      Weapons::DoStuff(){
                                                                                tipvelocity[i]+=bounceness*elasticity;
 
                                                                                if(findLengthfast(&bounceness)>1){
-                                                                                       float gLoc[3];
-                                                                                       float vel[3];
-                                                                                       //int whichsound=clank1sound+abs(Random()%4);
                                                                                        int whichsound;
                                                                                        if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
-                                                                                       if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);gLoc[0]=mid.x;
-                                                                                       gLoc[1]=mid.y;
-                                                                                       gLoc[2]=mid.z;
-                                                                                       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);
+                                                                                       if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
+                                                                                       emit_sound_at(whichsound, mid, 128*findLengthfast(&bounceness));
                                                                                }
                                                                                tippoint[i]+=(mid-oldmid2)*(20/(1+(float)m*10));
                                                                        }
@@ -693,37 +574,29 @@ void      Weapons::DoStuff(){
                                                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];
                                                        int whichsound;
                                                        if(terrain.getOpacity(position[i].x,position[i].z)>.2){
                                                                if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
                                                                if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
                                                        }
                                                        else whichsound=footstepsound+abs(Random()%2);
-                                                       gLoc[0]=position[i].x;
-                                                       gLoc[1]=position[i].y;
-                                                       gLoc[2]=position[i].z;
-                                                       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);
+                                                       emit_sound_at(whichsound, position[i],
+                                                                     findLengthfast(&bounceness)
+                                                                     * (terrain.getOpacity(position[i].x,position[i].z) > .2
+                                                                        ? 128.
+                                                                        : 32.));
 
                                                        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);
                                                                }
                                                        }
                                                }
@@ -747,37 +620,29 @@ void      Weapons::DoStuff(){
 //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];
-                                                       float vel[3];
                                                        int whichsound;
                                                        if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
                                                                if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
                                                                if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
                                                        }
                                                        else whichsound=footstepsound+abs(Random()%2);
-                                                       gLoc[0]=tippoint[i].x;
-                                                       gLoc[1]=tippoint[i].y;
-                                                       gLoc[2]=tippoint[i].z;
-                                                       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);
+                                                       emit_sound_at(whichsound, tippoint[i],
+                                                                     findLengthfast(&bounceness)
+                                                                     * (terrain.getOpacity(tippoint[i].x,tippoint[i].z) > .2
+                                                                        ? 128.
+                                                                        : 32.));
 
                                                        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);
                                                                }
                                                        }
                                                }
@@ -805,25 +670,17 @@ void      Weapons::DoStuff(){
                                                else velocity[i]+=bounceness*elasticity;
 
                                                if(findLengthfast(&bounceness)>1){
-                                                       float gLoc[3];
-                                                       float vel[3];
                                                        int whichsound;
                                                        if(terrain.getOpacity(mid.x,mid.z)>.2){
                                                                if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
                                                                if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
                                                        }
                                                        else whichsound=footstepsound+abs(Random()%2);
-                                                       gLoc[0]=mid.x;
-                                                       gLoc[1]=mid.y;
-                                                       gLoc[2]=mid.z;
-                                                       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);
+                                                       emit_sound_at(whichsound, mid,
+                                                                     findLengthfast(&bounceness)
+                                                                     * (terrain.getOpacity(position[i].x,position[i].z) > .2
+                                                                        ? 128.
+                                                                        : 32.));
                                                }
                                                position[i]+=(mid-oldmid)*20;
                                        }
@@ -849,184 +706,20 @@ void     Weapons::DoStuff(){
                                                else tipvelocity[i]+=bounceness*elasticity;
 
                                                if(findLengthfast(&bounceness)>1){
-                                                       float gLoc[3];
-                                                       float vel[3];
                                                        int whichsound;
                                                        if(terrain.getOpacity(mid.x,mid.z)>.2){
                                                                if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
                                                                if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
                                                        }
                                                        else whichsound=footstepsound+abs(Random()%2);
-                                                       gLoc[0]=mid.x;
-                                                       gLoc[1]=mid.y;
-                                                       gLoc[2]=mid.z;
-                                                       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);
+                                                       emit_sound_at(whichsound, mid,
+                                                                     findLengthfast(&bounceness)
+                                                                     * (terrain.getOpacity(position[i].x,position[i].z) > .2
+                                                                        ? 128.
+                                                                        : 32.));
                                                }
                                                tippoint[i]+=(mid-oldmid)*20;
                                        }
-                                       /*XYZ mid;
-                                       mid=position[i]+tippoint[i];
-                                       mid/=2;
-                                       if(position[i].y<terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z)){
-                                       hitsomething[i]=1;
-                                       position[i].y=terrain.getHeightExtrude(mid.x,mid.z,position[i].x,position[i].z);
-
-                                       terrainnormal=terrain.getNormal(mid.x,mid.z);
-                                       ReflectVector(&velocity[i],&terrainnormal);
-                                       position[i]+=terrainnormal*.002;
-                                       bounceness=terrainnormal*findLength(&velocity[i])*(abs(normaldotproduct(velocity[i],terrainnormal)));
-                                       if(findLengthfast(&velocity[i])<findLengthfast(&bounceness))bounceness=0;
-                                       frictionness=abs(normaldotproduct(velocity[i],terrainnormal));
-                                       velocity[i]-=bounceness;
-                                       if(1-friction*frictionness>0)velocity[i]*=1-friction*frictionness;
-                                       else velocity[i]=0;
-                                       if(terrain.getOpacity(mid.x,mid.z)<.2)velocity[i]+=bounceness*elasticity*.3;
-                                       else velocity[i]+=bounceness*elasticity;
-
-                                       if(findLengthfast(&bounceness)>1){
-                                       float gLoc[3];
-                                       float vel[3];
-                                       int whichsound;
-                                       if(terrain.getOpacity(mid.x,mid.z)>.2){
-                                       if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
-                                       if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
-                                       }
-                                       else whichsound=footstepsound+abs(Random()%2);
-                                       gLoc[0]=position[i].x;
-                                       gLoc[1]=position[i].y;
-                                       gLoc[2]=position[i].z;
-                                       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);
-                                       }
-                                       }
-
-                                       if(tippoint[i].y<terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z)){
-                                       hitsomething[i]=1;
-                                       tippoint[i].y=terrain.getHeightExtrude(mid.x,mid.z,tippoint[i].x,tippoint[i].z);
-
-                                       terrainnormal=terrain.getNormal(mid.x,mid.z);
-                                       ReflectVector(&tipvelocity[i],&terrainnormal);
-                                       tippoint[i]+=terrainnormal*.002;
-                                       bounceness=terrainnormal*findLength(&tipvelocity[i])*(abs(normaldotproduct(tipvelocity[i],terrainnormal)));
-                                       if(findLengthfast(&tipvelocity[i])<findLengthfast(&bounceness))bounceness=0;
-                                       frictionness=abs(normaldotproduct(tipvelocity[i],terrainnormal));
-                                       tipvelocity[i]-=bounceness;
-                                       if(1-friction*frictionness>0)tipvelocity[i]*=1-friction*frictionness;
-                                       else tipvelocity[i]=0;
-                                       if(terrain.getOpacity(mid.x,mid.z)<.2)tipvelocity[i]+=bounceness*elasticity*.3;
-                                       else tipvelocity[i]+=bounceness*elasticity;
-
-                                       if(findLengthfast(&bounceness)>1){
-                                       float gLoc[3];
-                                       float vel[3];
-                                       int whichsound;
-                                       if(terrain.getOpacity(mid.x,mid.z)>.2){
-                                       if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
-                                       if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
-                                       }
-                                       else whichsound=footstepsound+abs(Random()%2);
-                                       gLoc[0]=tippoint[i].x;
-                                       gLoc[1]=tippoint[i].y;
-                                       gLoc[2]=tippoint[i].z;
-                                       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);
-                                       }
-                                       }*/
-
-                                       //Fix terrain edge collision
-                                       /*start=position[i];
-                                       end=tippoint[i];
-                                       whichhit=terrain.lineTerrain(start,end,&colpoint);
-                                       if(whichhit!=-1){
-                                       XYZ tippoi,posit;
-                                       tippoi=tippoint[i];
-                                       posit=position[i];
-
-
-                                       while(whichhit!=-1){
-                                       position[i].y+=.1;
-                                       tippoint[i].y+=.1;
-                                       velocity[i].y+=.1;
-                                       tipvelocity[i].y+=.1;
-                                       start=position[i];
-                                       end=tippoint[i];
-                                       whichhit=terrain.lineTerrain(start,end,&colpoint);
-                                       if(whichhit!=-1)
-                                       closestpoint=colpoint*terrain.scale;
-                                       }
-                                       position[i].y-=.1;
-                                       tippoint[i].y-=.1;
-                                       velocity[i].y-=.1;
-                                       tipvelocity[i].y-=.1;
-                                       start=position[i];
-                                       end=tippoint[i];
-                                       whichhit=terrain.lineTerrain(start,end,&colpoint);
-                                       while(whichhit!=-1){
-                                       position[i].y+=.01;
-                                       tippoint[i].y+=.01;
-                                       velocity[i].y+=.01;
-                                       tipvelocity[i].y+=.01;
-                                       start=position[i];
-                                       end=tippoint[i];
-                                       whichhit=terrain.lineTerrain(start,end,&colpoint);
-                                       if(whichhit!=-1)
-                                       closestpoint=colpoint*terrain.scale;
-                                       }
-                                       }*/
-                                       /*if(whichhit!=-1){
-                                       whichhit=terrain.lineTerrain(end,start,&closestswordpoint);
-                                       if(whichhit!=-1){
-                                       colpoint=(closestswordpoint*terrain.scale+colpoint*terrain.scale)/2;
-                                       proportion=findDistance(&tippoint[i],&colpoint)/findDistance(&position[i],&tippoint[i]);
-                                       if(proportion<=1){
-                                       while(whichhit!=-1){
-                                       position[i].y+=.1*proportion;
-                                       tippoint[i].y+=.1*(1-proportion);
-                                       velocity[i].y+=.1*proportion;
-                                       tipvelocity[i].y+=.1*(1-proportion);
-                                       start=position[i];
-                                       end=tippoint[i];
-                                       whichhit=terrain.lineTerrain(start,end,&colpoint);
-                                       }
-                                       position[i].y-=.1*proportion;
-                                       tippoint[i].y-=.1*(1-proportion);
-                                       velocity[i].y-=.1*proportion;
-                                       tipvelocity[i].y-=.1*(1-proportion);
-                                       start=position[i];
-                                       end=tippoint[i];
-                                       whichhit=terrain.lineTerrain(start,end,&colpoint);
-                                       while(whichhit!=-1){
-                                       position[i].y+=.01*proportion;
-                                       tippoint[i].y+=.01*(1-proportion);
-                                       velocity[i].y+=.01*proportion;
-                                       tipvelocity[i].y+=.01*(1-proportion);
-                                       start=position[i];
-                                       end=tippoint[i];
-                                       whichhit=terrain.lineTerrain(start,end,&colpoint);
-                                       }
-                                       }
-                                       }
-                                       }
-                                       */
                                        //Gravity
                                        velocity[i].y+=gravity*multiplier;
                                        tipvelocity[i].y+=gravity*multiplier;
@@ -1082,7 +775,7 @@ 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);
                                }
                        }
                }
@@ -1101,9 +794,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);
                        }
                }
 
@@ -1116,9 +809,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);
                                }
                        }
                }
@@ -1277,13 +970,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;