]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameTick.cpp
Cleanup sound emission
[lugaru.git] / Source / GameTick.cpp
index bf754b6f6a71f135f2eaa6fe6ddfd9876ad48e66..38d379ecbe6da7f6b1c6cf86c51fe37f9bab95af 100644 (file)
@@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Settings.h"
 #include "Input.h"
 #include "Animation.h"
+#include "Awards.h"
 
 using namespace std;
 
@@ -48,7 +49,6 @@ extern XYZ viewer;
 extern int environment;
 extern float texscale;
 extern Terrain terrain;
-extern OPENAL_SAMPLE *samp[100];
 extern int channels[100];
 extern int kTextureSize;
 extern float screenwidth,screenheight;
@@ -71,9 +71,6 @@ extern float blackout;
 extern bool cellophane;
 extern bool musictoggle;
 extern int difficulty;
-extern Weapons weapons;
-extern Person player[maxplayers];
-extern int numplayers;
 extern int bloodtoggle;
 extern bool invertmouse;
 extern float windvar;
@@ -115,14 +112,7 @@ extern bool decals;
 extern bool vblsync;
 extern bool immediate;
 extern bool velocityblur;
-extern int bonus;
-extern int oldbonus;
-extern float bonusvalue;
-extern float bonustotal;
-extern float bonustime;
-extern float startbonustotal;
 extern float tintr,tintg,tintb;
-extern float bonusnum[100];
 extern bool skyboxtexture;
 extern float skyboxr;
 extern float skyboxg;
@@ -144,7 +134,6 @@ extern bool reversaltrain;
 extern bool canattack;
 extern bool cananger;
 extern float damagedealt;
-extern float damagetaken;
 extern int maptype;
 extern int editoractive;
 extern int editorpathtype;
@@ -169,23 +158,6 @@ extern int hostile;
 extern bool stillloading;
 extern bool winfreeze;
 
-extern int numfalls;
-extern int numflipfail;
-extern int numseen;
-extern int numstaffattack;
-extern int numswordattack;
-extern int numknifeattack;
-extern int numunarmedattack;
-extern int numescaped;
-extern int numflipped;
-extern int numwallflipped;
-extern int numthrowkill;
-extern int numafterkill;
-extern int numreversals;
-extern int numattacks;
-extern int maxalarmed;
-extern int numresponded;
-
 extern int numdialogues;
 extern int numdialogueboxes[max_dialogues];
 extern int dialoguetype[max_dialogues];
@@ -242,7 +214,6 @@ static bool stripfx(const char *str, const char *pfx)
   return !strncasecmp(str, pfx, strlen(pfx));
 }
 
-extern OPENAL_STREAM * strm[20];
 extern "C"     void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 
@@ -1017,20 +988,12 @@ static void ch_play(Game *game, const char *args)
   directing=0;
   indialogue=0;
 
-  float gLoc[3];
-  float vel[3];
   XYZ temppos;
   temppos=player[participantfocus[whichdialogue][indialogue]].coords;
   temppos=temppos-viewer;
   Normalise(&temppos);
   temppos+=viewer;
 
-  gLoc[0]=temppos.x;
-  gLoc[1]=temppos.y;
-  gLoc[2]=temppos.z;
-  vel[0]=0;
-  vel[1]=0;
-  vel[2]=0;
   int whichsoundplay;
   whichsoundplay=rabbitchitter;
   if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
@@ -1052,10 +1015,7 @@ static void ch_play(Game *game, const char *args)
   if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
   if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
   if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
-  PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
-  OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
-  OPENAL_SetVolume(channels[whichsoundplay], 256);
-  OPENAL_SetPaused(channels[whichsoundplay], false);
+  emit_sound_at(whichsoundplay, temppos);
 }
 
 static void ch_mapkilleveryone(Game *game, const char *args)
@@ -1389,7 +1349,7 @@ void      Game::Setenvironment(int which)
                windvector.z=3;
                if(ambientsound){
                        //PlaySoundEx( wind, samp[wind], NULL, true);
-                       PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
+                       PlayStreamEx(stream_wind, samp[stream_wind], 0, true);
                        OPENAL_SetPaused(channels[stream_wind], false);
                        OPENAL_SetVolume(channels[stream_wind], 256);
                }
@@ -1399,18 +1359,10 @@ void    Game::Setenvironment(int which)
                LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
                LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
 
-               OPENAL_Sample_Free(samp[footstepsound]);
-               OPENAL_Sample_Free(samp[footstepsound2]);
-               OPENAL_Sample_Free(samp[footstepsound3]);
-               OPENAL_Sample_Free(samp[footstepsound4]);
-               samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
+               footstepsound = footstepsn1;
+               footstepsound2 = footstepsn2;
+               footstepsound3 = footstepst1;
+               footstepsound4 = footstepst2;
 
                LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
 
@@ -1448,23 +1400,15 @@ void    Game::Setenvironment(int which)
 
                if(ambientsound){
                        //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
-                       PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
+                       PlayStreamEx( stream_desertambient, samp[stream_desertambient], NULL, true);
                        OPENAL_SetPaused(channels[stream_desertambient], false);
                        OPENAL_SetVolume(channels[stream_desertambient], 256);
                }
 
-               OPENAL_Sample_Free(samp[footstepsound]);
-               OPENAL_Sample_Free(samp[footstepsound2]);
-               OPENAL_Sample_Free(samp[footstepsound3]);
-               OPENAL_Sample_Free(samp[footstepsound4]);
-               samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
+               footstepsound = footstepsn1;
+               footstepsound2 = footstepsn2;
+               footstepsound3 = footstepsn1;
+               footstepsound4 = footstepsn2;
 
                LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
 
@@ -1499,23 +1443,15 @@ void    Game::Setenvironment(int which)
                LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
 
                if(ambientsound){
-                       PlayStreamEx( stream_wind, strm[stream_wind], NULL, true);
+                       PlayStreamEx( stream_wind, samp[stream_wind], NULL, true);
                        OPENAL_SetPaused(channels[stream_wind], false);
                        OPENAL_SetVolume(channels[stream_wind], 100);
                }
 
-               OPENAL_Sample_Free(samp[footstepsound]);
-               OPENAL_Sample_Free(samp[footstepsound2]);
-               OPENAL_Sample_Free(samp[footstepsound3]);
-               OPENAL_Sample_Free(samp[footstepsound4]);
-               samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepgrass1.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepgrass2.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
+               footstepsound = footstepgr1;
+               footstepsound2 = footstepgr2;
+               footstepsound3 = footstepst1;
+               footstepsound4 = footstepst2;
 
                LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
 
@@ -2296,7 +2232,7 @@ void      Game::Loadlevel(char *name){
                {
                        if(ambientsound)
                        {
-                               PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
+                               PlayStreamEx(stream_wind, samp[stream_wind], NULL, true);
                                OPENAL_SetPaused(channels[stream_wind], false);
                                OPENAL_SetVolume(channels[stream_wind], 256);
                        }
@@ -2308,7 +2244,7 @@ void      Game::Loadlevel(char *name){
                                //PlaySoundEx(desertambient,
                                //      samp[desertambient], NULL, true);
                                PlayStreamEx(stream_desertambient,
-                                       strm[stream_desertambient], NULL, true);
+                                       samp[stream_desertambient], NULL, true);
                                OPENAL_SetPaused(channels[stream_desertambient], false);
                                OPENAL_SetVolume(channels[stream_desertambient], 256);
                        }
@@ -2318,7 +2254,7 @@ void      Game::Loadlevel(char *name){
                        if(ambientsound)
                        {
                                //PlaySoundEx(wind, samp[wind], NULL, true);
-                               PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
+                               PlayStreamEx(stream_wind, samp[stream_wind], NULL, true);
                                OPENAL_SetPaused(channels[stream_wind], false);
                                OPENAL_SetVolume(channels[stream_wind], 100);
                        }
@@ -2416,7 +2352,7 @@ void      Game::Tick()
                                if(mainmenu&&musictoggle){
                                        if(mainmenu==1||mainmenu==2||mainmenu==100){
                                                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
-                                               PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
+                                               PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
                                                OPENAL_SetPaused(channels[stream_music3], false);
                                                OPENAL_SetVolume(channels[stream_music3], 256);
                                                OPENAL_SetPaused(channels[music1], true);
@@ -2623,7 +2559,7 @@ void      Game::Tick()
                                }
 
                                if(musictoggle){
-                                       PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
+                                       PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
                                        OPENAL_SetPaused(channels[stream_music3], false);
                                        OPENAL_SetVolume(channels[stream_music3], 256);
                                }
@@ -2793,7 +2729,7 @@ void      Game::Tick()
                                mainmenu=9;
                        }
                }
-               if(mainmenu==9){
+               else if(mainmenu==9){
                        if(Input::Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountactive->getProgress()){
                                fireSound();
 
@@ -3167,19 +3103,12 @@ void    Game::Tick()
                                                                dialoguetime=0;
                                                                dialoguegonethrough[i]++;
                                                                if(dialogueboxsound[whichdialogue][indialogue]!=0){
-                                                                       static float gLoc[3];
-                                                                       static float vel[3];
                                                                        XYZ temppos;
                                                                        temppos=player[participantfocus[whichdialogue][indialogue]].coords;
                                                                        temppos=temppos-viewer;
                                                                        Normalise(&temppos);
                                                                        temppos+=viewer;
 
-                                                                       gLoc[0]=temppos.x;
-                                                                       gLoc[1]=temppos.y;
-                                                                       gLoc[2]=temppos.z;vel[0]=0;
-                                                                       vel[1]=0;
-                                                                       vel[2]=0;
                                                                        int whichsoundplay;
                                                                        if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
                                                                        if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
@@ -3201,10 +3130,7 @@ void     Game::Tick()
                                                                        if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
                                                                        if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
                                                                        if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
-                                                                       PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
-                                                                       OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
-                                                                       OPENAL_SetVolume(channels[whichsoundplay], 256);
-                                                                       OPENAL_SetPaused(channels[whichsoundplay], false);
+                                                                       emit_sound_at(whichsoundplay, temppos);
                                                                }
                                                                if(Input::isKeyDown(attackkey))oldbuttondialogue=1;
                                                        }
@@ -3291,18 +3217,7 @@ void     Game::Tick()
 
                                                        player[1].coords=(temp+temp2)/2;
 
-                                                       float gLoc[3];
-                                                       float vel[3];
-                                                       gLoc[0]=player[1].coords.x;
-                                                       gLoc[1]=player[1].coords.y;
-                                                       gLoc[2]=player[1].coords.z;
-                                                       vel[0]=0;
-                                                       vel[1]=0;
-                                                       vel[2]=0;
-                                                       PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                       OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                                                       OPENAL_SetVolume(channels[fireendsound], 256);
-                                                       OPENAL_SetPaused(channels[fireendsound], false);
+                                                       emit_sound_at(fireendsound, player[1].coords);
 
                                                        for(i=0;i<player[1].skeleton.num_joints;i++){
                                                                if(Random()%2==0){
@@ -3543,18 +3458,7 @@ void     Game::Tick()
                                                        tutorialmaxtime=8;
 
                                                        XYZ temp,temp2;
-                                                       float gLoc[3];
-                                                       float vel[3];
-                                                       gLoc[0]=player[1].coords.x;
-                                                       gLoc[1]=player[1].coords.y;
-                                                       gLoc[2]=player[1].coords.z;
-                                                       vel[0]=0;
-                                                       vel[1]=0;
-                                                       vel[2]=0;
-                                                       PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                       OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                                                       OPENAL_SetVolume(channels[fireendsound], 256);
-                                                       OPENAL_SetPaused(channels[fireendsound], false);
+                                                       emit_sound_at(fireendsound, player[1].coords);
 
                                                        for(i=0;i<player[1].skeleton.num_joints;i++){
                                                                if(Random()%2==0){
@@ -3833,18 +3737,7 @@ void     Game::Tick()
                                                                                                                        player[k].target=0;
                                                                                                                        player[k].targetanimation=walljumpleftanim;
                                                                                                                        player[k].targetframe=0;
-                                                                                                                       float gLoc[3];
-                                                                                                                       float vel[3];
-                                                                                                                       gLoc[0]=player[k].coords.x;
-                                                                                                                       gLoc[1]=player[k].coords.y;
-                                                                                                                       gLoc[2]=player[k].coords.z;
-                                                                                                                       vel[0]=0;
-                                                                                                                       vel[1]=0;
-                                                                                                                       vel[2]=0;
-                                                                                                                       PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
-                                                                                                                       OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
-                                                                                                                       OPENAL_SetVolume(channels[movewhooshsound], 256);
-                                                                                                                       OPENAL_SetPaused(channels[movewhooshsound], false);
+                                                                                                                       emit_sound_at(movewhooshsound, player[k].coords);
                                                                                                                        if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
 
                                                                                                                        lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
@@ -3864,18 +3757,7 @@ void     Game::Tick()
                                                                                                                                player[k].target=0;
                                                                                                                                player[k].targetanimation=walljumprightanim;
                                                                                                                                player[k].targetframe=0;
-                                                                                                                               float gLoc[3];
-                                                                                                                               float vel[3];
-                                                                                                                               gLoc[0]=player[k].coords.x;
-                                                                                                                               gLoc[1]=player[k].coords.y;
-                                                                                                                               gLoc[2]=player[k].coords.z;
-                                                                                                                               vel[0]=0;
-                                                                                                                               vel[1]=0;
-                                                                                                                               vel[2]=0;
-                                                                                                                               PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
-                                                                                                                               OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
-                                                                                                                               OPENAL_SetVolume(channels[movewhooshsound], 256);
-                                                                                                                               OPENAL_SetPaused(channels[movewhooshsound], false);
+                                                                                                                               emit_sound_at(movewhooshsound, player[k].coords);
                                                                                                                                if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
 
                                                                                                                                lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
@@ -3895,18 +3777,7 @@ void     Game::Tick()
                                                                                                                                        player[k].target=0;
                                                                                                                                        player[k].targetanimation=walljumpbackanim;
                                                                                                                                        player[k].targetframe=0;
-                                                                                                                                       float gLoc[3];
-                                                                                                                                       float vel[3];
-                                                                                                                                       gLoc[0]=player[k].coords.x;
-                                                                                                                                       gLoc[1]=player[k].coords.y;
-                                                                                                                                       gLoc[2]=player[k].coords.z;
-                                                                                                                                       vel[0]=0;
-                                                                                                                                       vel[1]=0;
-                                                                                                                                       vel[2]=0;
-                                                                                                                                       PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
-                                                                                                                                       OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
-                                                                                                                                       OPENAL_SetVolume(channels[movewhooshsound], 256);
-                                                                                                                                       OPENAL_SetPaused(channels[movewhooshsound], false);
+                                                                                                                                       emit_sound_at(movewhooshsound, player[k].coords);
                                                                                                                                        if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
 
                                                                                                                                        lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
@@ -3926,18 +3797,7 @@ void     Game::Tick()
                                                                                                                                                player[k].target=0;
                                                                                                                                                player[k].targetanimation=walljumpfrontanim;
                                                                                                                                                player[k].targetframe=0;
-                                                                                                                                               float gLoc[3];
-                                                                                                                                               float vel[3];
-                                                                                                                                               gLoc[0]=player[k].coords.x;
-                                                                                                                                               gLoc[1]=player[k].coords.y;
-                                                                                                                                               gLoc[2]=player[k].coords.z;
-                                                                                                                                               vel[0]=0;
-                                                                                                                                               vel[1]=0;
-                                                                                                                                               vel[2]=0;
-                                                                                                                                               PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
-                                                                                                                                               OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
-                                                                                                                                               OPENAL_SetVolume(channels[movewhooshsound], 256);
-                                                                                                                                               OPENAL_SetPaused(channels[movewhooshsound], false);
+                                                                                                                                               emit_sound_at(movewhooshsound, player[k].coords);
                                                                                                                                                if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
 
                                                                                                                                                lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
@@ -3980,18 +3840,7 @@ void     Game::Tick()
                                                                                                                if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
                                                                                                                        if(player[k].isFlip())player[k].jumppower=-4;
                                                                                                                        player[k].targetanimation=player[k].getLanding();
-                                                                                                                       float gLoc[3];
-                                                                                                                       float vel[3];
-                                                                                                                       gLoc[0]=player[k].coords.x;
-                                                                                                                       gLoc[1]=player[k].coords.y;
-                                                                                                                       gLoc[2]=player[k].coords.z;
-                                                                                                                       vel[0]=player[k].velocity.x;
-                                                                                                                       vel[1]=player[k].velocity.y;
-                                                                                                                       vel[2]=player[k].velocity.z;
-                                                                                                                       PlaySoundEx( landsound, samp[landsound], NULL, true);
-                                                                                                                       OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
-                                                                                                                       OPENAL_SetVolume(channels[landsound], 128);
-                                                                                                                       OPENAL_SetPaused(channels[landsound], false);
+                                                                                                                       emit_sound_at(landsound, player[k].coords, 128.);
                                                                                                                        if(k==0){
                                                                                                                                envsound[numenvsounds]=player[k].coords;
                                                                                                                                envsoundvol[numenvsounds]=16;
@@ -4091,18 +3940,7 @@ void     Game::Tick()
                                                                                                                                                                                                                if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
                                                                                                                                                                                                                        if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
                                                                                                                                                                                                                }
-                                                                                                                                                                                                               float gLoc[3];
-                                                                                                                                                                                                               float vel[3];
-                                                                                                                                                                                                               gLoc[0]=player[k].coords.x;
-                                                                                                                                                                                                               gLoc[1]=player[k].coords.y;
-                                                                                                                                                                                                               gLoc[2]=player[k].coords.z;
-                                                                                                                                                                                                               vel[0]=player[k].velocity.x;
-                                                                                                                                                                                                               vel[1]=player[k].velocity.y;
-                                                                                                                                                                                                               vel[2]=player[k].velocity.z;
-                                                                                                                                                                                                               PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
-                                                                                                                                                                                                               OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
-                                                                                                                                                                                                               OPENAL_SetVolume(channels[jumpsound], 128);
-                                                                                                                                                                                                               OPENAL_SetPaused(channels[jumpsound], false);
+                                                                                                                                                                                                               emit_sound_at(jumpsound, player[k].coords, 128.);
 
                                                                                                                                                                                                                lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
                                                                                                                                                                                                                player[k].rotation=-asin(0-lowpointtarget.x);
@@ -4152,20 +3990,8 @@ void     Game::Tick()
                                                                                                                player[k].targetframe=0;
                                                                                                                player[k].target=0;
 
-                                                                                                               float gLoc[3];
-                                                                                                               float vel[3];
-                                                                                                               gLoc[0]=player[k].coords.x;
-                                                                                                               gLoc[1]=player[k].coords.y;
-                                                                                                               gLoc[2]=player[k].coords.z;
-                                                                                                               vel[0]=player[k].velocity.x;
-                                                                                                               vel[1]=player[k].velocity.y;
-                                                                                                               vel[2]=player[k].velocity.z;
-                                                                                                               if(k==0){
-                                                                                                                       PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
-                                                                                                                       OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
-                                                                                                                       OPENAL_SetVolume(channels[whooshsound], 128);
-                                                                                                                       OPENAL_SetPaused(channels[whooshsound], false);
-                                                                                                               }
+                                                                                                               if(!k)
+                                                                                                                 emit_sound_at(whooshsound, player[k].coords, 128.);
                                                                                                        }
                                                                                                        player[k].velocity.y+=gravity;
                                                                                                }
@@ -4257,19 +4083,12 @@ void    Game::Tick()
                                                                                indialogue++;
                                                                                if(indialogue<numdialogueboxes[whichdialogue]){
                                                                                        if(dialogueboxsound[whichdialogue][indialogue]!=0){
-                                                                                               static float gLoc[3];
-                                                                                               static float vel[3];
                                                                                                XYZ temppos;
                                                                                                temppos=player[participantfocus[whichdialogue][indialogue]].coords;
                                                                                                temppos=temppos-viewer;
                                                                                                Normalise(&temppos);
                                                                                                temppos+=viewer;
 
-                                                                                               gLoc[0]=temppos.x;
-                                                                                               gLoc[1]=temppos.y;
-                                                                                               gLoc[2]=temppos.z;vel[0]=0;
-                                                                                               vel[1]=0;
-                                                                                               vel[2]=0;
                                                                                                int whichsoundplay;
                                                                                                if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
                                                                                                if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
@@ -4291,10 +4110,7 @@ void     Game::Tick()
                                                                                                if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
                                                                                                if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
                                                                                                if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
-                                                                                               PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
-                                                                                               OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
-                                                                                               OPENAL_SetVolume(channels[whichsoundplay], 256);
-                                                                                               OPENAL_SetPaused(channels[whichsoundplay], false);
+                                                                                               emit_sound_at(whichsoundplay, temppos);
                                                                                        }
                                                                                }
 
@@ -4347,19 +4163,12 @@ void    Game::Tick()
                                                                                        endkeydown=1;
                                                                                        if(indialogue<numdialogueboxes[whichdialogue]){
                                                                                                if(dialogueboxsound[whichdialogue][indialogue]!=0){
-                                                                                                       static float gLoc[3];
-                                                                                                       static float vel[3];
                                                                                                        XYZ temppos;
                                                                                                        temppos=player[participantfocus[whichdialogue][indialogue]].coords;
                                                                                                        temppos=temppos-viewer;
                                                                                                        Normalise(&temppos);
                                                                                                        temppos+=viewer;
 
-                                                                                                       gLoc[0]=temppos.x;
-                                                                                                       gLoc[1]=temppos.y;
-                                                                                                       gLoc[2]=temppos.z;vel[0]=0;
-                                                                                                       vel[1]=0;
-                                                                                                       vel[2]=0;
                                                                                                        int whichsoundplay;
                                                                                                        if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
                                                                                                        if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
@@ -4383,10 +4192,7 @@ void     Game::Tick()
                                                                                                        if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
                                                                                                        if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
                                                                                                        if(dialogueboxsound[whichdialogue][indialogue]!=-5){
-                                                                                                               PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
-                                                                                                               OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
-                                                                                                               OPENAL_SetVolume(channels[whichsoundplay], 256);
-                                                                                                               OPENAL_SetPaused(channels[whichsoundplay], false);
+                                                                                                               emit_sound_at(whichsoundplay, temppos);
                                                                                                        }
                                                                                                        if(dialogueboxsound[whichdialogue][indialogue]==-5){
                                                                                                                hotspot[numhotspots]=player[0].coords;
@@ -4453,18 +4259,7 @@ void     Game::Tick()
 
                                                if(hawkcalldelay<=0)
                                                {
-                                                       static float gLoc[3];
-                                                       static float vel[3];
-                                                       gLoc[0]=realhawkcoords.x;
-                                                       gLoc[1]=realhawkcoords.y;
-                                                       gLoc[2]=realhawkcoords.z;
-                                                       vel[0]=0;
-                                                       vel[1]=0;
-                                                       vel[2]=0;
-                                                       PlaySoundEx( hawksound, samp[hawksound], NULL, true);
-                                                       OPENAL_3D_SetAttributes(channels[hawksound], gLoc, vel);
-                                                       OPENAL_SetVolume(channels[hawksound], 128);
-                                                       OPENAL_SetPaused(channels[hawksound], false);
+                                                       emit_sound_at(hawksound, realhawkcoords);
 
                                                        hawkcalldelay=16+abs(Random()%8);
                                                }
@@ -4765,23 +4560,8 @@ void     Game::Tick()
                                                                        }
                                                                        Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
 
-                                                                       float gLoc[3];
-                                                                       float vel[3];
-                                                                       gLoc[0]=blah.x;
-                                                                       gLoc[1]=blah.y;
-                                                                       gLoc[2]=blah.z;
-                                                                       vel[0]=0;
-                                                                       vel[1]=0;
-                                                                       vel[2]=0;
-                                                                       PlaySoundEx( splattersound, samp[splattersound], NULL, true);
-                                                                       OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
-                                                                       OPENAL_SetVolume(channels[splattersound], 256);
-                                                                       OPENAL_SetPaused(channels[splattersound], false);
-
-                                                                       PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
-                                                                       OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
-                                                                       OPENAL_SetVolume(channels[breaksound2], 100);
-                                                                       OPENAL_SetPaused(channels[breaksound2], false);
+                                                                       emit_sound_at(splattersound, blah);
+                                                                       emit_sound_at(breaksound2, blah, 100.);
 
                                                                        if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
                                                                        player[closest].RagDoll(0);
@@ -4813,24 +4593,9 @@ void     Game::Tick()
                                                                }
 
                                                                if(closest!=-1){
-                                                                       float gLoc[3];
-                                                                       float vel[3];
-                                                                       gLoc[0]=blah.x;
-                                                                       gLoc[1]=blah.y;
-                                                                       gLoc[2]=blah.z;
-                                                                       vel[0]=0;
-                                                                       vel[1]=0;
-                                                                       vel[2]=0;
-
-                                                                       PlaySoundEx( splattersound, samp[splattersound], NULL, true);
-                                                                       OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
-                                                                       OPENAL_SetVolume(channels[splattersound], 256);
-                                                                       OPENAL_SetPaused(channels[splattersound], false);
-
-                                                                       PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
-                                                                       OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
-                                                                       OPENAL_SetVolume(channels[breaksound2], 600);
-                                                                       OPENAL_SetPaused(channels[breaksound2], false);
+                                                                       emit_sound_at(splattersound, blah);
+
+                                                                       emit_sound_at(breaksound2, blah);
 
                                                                        for(i=0;i<player[closest].skeleton.num_joints; i++){
                                                                                if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
@@ -4929,18 +4694,7 @@ void     Game::Tick()
                                                                player[0].CatchFire();
                                                        }
                                                        if(!player[0].onfire){
-                                                               float gLoc[3];
-                                                               float vel[3];
-                                                               gLoc[0]=player[0].coords.x;
-                                                               gLoc[1]=player[0].coords.y;
-                                                               gLoc[2]=player[0].coords.z;
-                                                               vel[0]=0;
-                                                               vel[1]=0;
-                                                               vel[2]=0;
-                                                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                                                               OPENAL_SetVolume(channels[fireendsound], 256);
-                                                               OPENAL_SetPaused(channels[fireendsound], false);
+                                                               emit_sound_at(fireendsound, player[0].coords);
                                                                OPENAL_SetPaused(channels[stream_firesound], true);
                                                        }
                                                        slomotogglekeydown=1;
@@ -5326,18 +5080,7 @@ void     Game::Tick()
                                                        //player[0].spurt=1;
                                                        //player[0].DoDamage(1000);
 
-                                                       float gLoc[3];
-                                                       float vel[3];
-                                                       gLoc[0]=player[0].coords.x;
-                                                       gLoc[1]=player[0].coords.y;
-                                                       gLoc[2]=player[0].coords.z;
-                                                       vel[0]=player[0].velocity.x;
-                                                       vel[1]=player[0].velocity.y;
-                                                       vel[2]=player[0].velocity.z;
-                                                       PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
-                                                       OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
-                                                       OPENAL_SetVolume(channels[whooshsound], 128);
-                                                       OPENAL_SetPaused(channels[whooshsound], false);
+                                                       emit_sound_at(whooshsound, player[0].coords, 128.);
                                                        //OPENAL_SetPaused(channels[whooshsound], true);
 
                                                        texturesizetogglekeydown=1;
@@ -5749,35 +5492,20 @@ void    Game::Tick()
                                                                                                                                                                                                                if(((((findLengthfast(&rotatetarget)>150&&(i!=0&&k!=0))||(findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll/*currentanimation==rabbitkickanim*/&&(i==0||k==0)))&&normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&((i==0||k==0)||((player[i].skeleton.oldfree==1&&k!=0&&animation[player[k].currentanimation].attack==neutral)||(player[k].skeleton.oldfree==1&&i!=0&&animation[player[i].currentanimation].attack==neutral)||(player[i].isFlip()&&!player[i].skeleton.oldfree&&(i==0||k==0))||(player[k].isFlip()&&!player[k].skeleton.oldfree&&(i==0||k==0))||(i==0||k==0))))||((player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&(i==0||k==0)&&(!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree))){
                                                                                                                                                                                                                        //If hit by body
                                                                                                                                                                                                                        if((i!=0||player[i].skeleton.free)&&(k!=0||player[k].skeleton.free)||(animation[player[i].targetanimation].height==highheight&&animation[player[k].targetanimation].height==highheight)){
-                                                                                                                                                                                                                               static float gLoc[3];
-                                                                                                                                                                                                                               static float vel[3];
-                                                                                                                                                                                                                               gLoc[0]=player[i].coords.x;
-                                                                                                                                                                                                                               gLoc[1]=player[i].coords.y;
-                                                                                                                                                                                                                               gLoc[2]=player[i].coords.z;
-                                                                                                                                                                                                                               vel[0]=player[i].velocity.x;
-                                                                                                                                                                                                                               vel[1]=player[i].velocity.y;
-                                                                                                                                                                                                                               vel[2]=player[i].velocity.z;
                                                                                                                                                                                                                                if(tutoriallevel!=1){
-                                                                                                                                                                                                                                       PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
-                                                                                                                                                                                                                                       OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
-                                                                                                                                                                                                                                       OPENAL_SetVolume(channels[heavyimpactsound], 256);
-                                                                                                                                                                                                                                       OPENAL_SetPaused(channels[heavyimpactsound], false);
+                                                                                                                                                                                                                                       emit_sound_at(heavyimpactsound, player[i].coords);
                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                //player[i].velocity=player[k].velocity;
                                                                                                                                                                                                                                //player[k].velocity=player[i].velocity;
 
                                                                                                                                                                                                                                player[i].RagDoll(0);
                                                                                                                                                                                                                                if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
-                                                                                                                                                                                                                                       bonus=aimbonus;
-                                                                                                                                                                                                                                       bonustime=0;
-                                                                                                                                                                                                                                       bonusvalue=150;
+                                                                                                                                                                                                                                 award_bonus(0, aimbonus);
                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                player[i].DoDamage(findLengthfast(&rotatetarget)/4);
                                                                                                                                                                                                                                player[k].RagDoll(0);
                                                                                                                                                                                                                                if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
-                                                                                                                                                                                                                                       bonus=aimbonus;
-                                                                                                                                                                                                                                       bonustime=0;
-                                                                                                                                                                                                                                       bonusvalue=150;
+                                                                                                                                                                                                                                 award_bonus(0, aimbonus); // Huh, again?
                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                player[k].DoDamage(findLengthfast(&rotatetarget)/4);
 
@@ -5843,11 +5571,7 @@ void     Game::Tick()
                                                                                                                                                                                                                                                player[i].DoDamage(20);
                                                                                                                                                                                                                                                player[i].RagDoll(0);
                                                                                                                                                                                                                                                player[k].lastcollide=1;
-                                                                                                                                                                                                                                               if(k==0){
-                                                                                                                                                                                                                                                       bonus=AboveBonus;
-                                                                                                                                                                                                                                                       bonustime=0;
-                                                                                                                                                                                                                                                       bonusvalue=50;
-                                                                                                                                                                                                                                               }
+                                                                                                                                                                                                                                               award_bonus(k, AboveBonus);
                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                        if(i==0&&k!=0&&player[i].targetanimation==jumpdownanim&&!player[k].isCrouch()&&player[k].targetanimation!=rollanim&&!player[i].skeleton.oldfree&&!player[i].skeleton.free&&player[i].lastcollide<=0&&player[i].velocity.y<-10){
                                                                                                                                                                                                                                                player[k].velocity=player[i].velocity;
@@ -5857,11 +5581,7 @@ void     Game::Tick()
                                                                                                                                                                                                                                                player[k].DoDamage(20);
                                                                                                                                                                                                                                                player[k].RagDoll(0);
                                                                                                                                                                                                                                                player[i].lastcollide=1;
-                                                                                                                                                                                                                                               if(i==0){
-                                                                                                                                                                                                                                                       bonus=AboveBonus;
-                                                                                                                                                                                                                                                       bonustime=0;
-                                                                                                                                                                                                                                                       bonusvalue=50;
-                                                                                                                                                                                                                                               }
+                                                                                                                                                                                                                                               award_bonus(i, AboveBonus);
                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                }
                                                                                                                                                                                                                        }
@@ -7000,20 +6720,8 @@ void     Game::Tick()
                                                                                                                                if((((weapons.velocity[j].x==0&&weapons.velocity[j].y==0&&weapons.velocity[j].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[j]==-1)||(player[i].victim&&weapons.owner[j]==player[i].victim->id))
                                                                                                                                        if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
                                                                                                                                                if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
-                                                                                                                                                       float gLoc[3];
-                                                                                                                                                       float vel[3];
-                                                                                                                                                       gLoc[0]=player[i].coords.x;
-                                                                                                                                                       gLoc[1]=player[i].coords.y;
-                                                                                                                                                       gLoc[2]=player[i].coords.z;
-                                                                                                                                                       vel[0]=player[i].velocity.x;
-                                                                                                                                                       vel[1]=player[i].velocity.y;
-                                                                                                                                                       vel[2]=player[i].velocity.z;
-                                                                                                                                                       if(weapons.type[j]!=staff){
-                                                                                                                                                               PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
-                                                                                                                                                               OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
-                                                                                                                                                               OPENAL_SetVolume(channels[knifedrawsound], 128);
-                                                                                                                                                               OPENAL_SetPaused(channels[knifedrawsound], false);
-                                                                                                                                                       }
+                                                                                                                                                       if(weapons.type[j]!=staff)
+                                                                                                                                                         emit_sound_at(knifedrawsound, player[i].coords, 128.);
 
                                                                                                                                                        player[i].weaponactive=0;
                                                                                                                                                        weapons.owner[j]=player[i].id;
@@ -7047,20 +6755,8 @@ void     Game::Tick()
                                                                                                                                        if(player[i].weaponactive==-1)
                                                                                                                                                if((((weapons.velocity[k].x==0&&weapons.velocity[k].y==0&&weapons.velocity[k].z==0)||player[i].aitype==playercontrolled)&&weapons.owner[k]==-1)||(player[i].victim&&weapons.owner[k]==player[i].victim->id))
                                                                                                                                                        if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
-                                                                                                                                                               float gLoc[3];
-                                                                                                                                                               float vel[3];
-                                                                                                                                                               gLoc[0]=player[i].coords.x;
-                                                                                                                                                               gLoc[1]=player[i].coords.y;
-                                                                                                                                                               gLoc[2]=player[i].coords.z;
-                                                                                                                                                               vel[0]=player[i].velocity.x;
-                                                                                                                                                               vel[1]=player[i].velocity.y;
-                                                                                                                                                               vel[2]=player[i].velocity.z;
-                                                                                                                                                               if(weapons.type[k]!=staff){
-                                                                                                                                                                       PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
-                                                                                                                                                                       OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
-                                                                                                                                                                       OPENAL_SetVolume(channels[knifedrawsound], 128);
-                                                                                                                                                                       OPENAL_SetPaused(channels[knifedrawsound], false);
-                                                                                                                                                               }
+                                                                                                                                                               if(weapons.type[k]!=staff)
+                                                                                                                                                                 emit_sound_at(knifedrawsound, player[i].coords, 128.);
 
                                                                                                                                                                player[i].weaponactive=0;
                                                                                                                                                                weapons.owner[k]=player[i].id;
@@ -7100,14 +6796,6 @@ void     Game::Tick()
                                                                                                                                                player[i].hasvictim=1;
                                                                                                                                                int k = player[j].weaponids[0];
                                                                                                                                                if(player[i].hasvictim){
-                                                                                                                                                       float gLoc[3];
-                                                                                                                                                       float vel[3];
-                                                                                                                                                       gLoc[0]=player[i].coords.x;
-                                                                                                                                                       gLoc[1]=player[i].coords.y;
-                                                                                                                                                       gLoc[2]=player[i].coords.z;
-                                                                                                                                                       vel[0]=player[i].velocity.x;
-                                                                                                                                                       vel[1]=player[i].velocity.y;
-                                                                                                                                                       vel[2]=player[i].velocity.z;
                                                                                                                                                        bool fleshstuck;
                                                                                                                                                        fleshstuck=0;
                                                                                                                                                        if(player[i].victim->weaponstuck!=-1){
@@ -7116,19 +6804,11 @@ void    Game::Tick()
                                                                                                                                                                }
                                                                                                                                                        }
                                                                                                                                                        if(!fleshstuck){
-                                                                                                                                                               if(weapons.type[k]!=staff){
-                                                                                                                                                                       PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
-                                                                                                                                                                       OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
-                                                                                                                                                                       OPENAL_SetVolume(channels[knifedrawsound], 128);
-                                                                                                                                                                       OPENAL_SetPaused(channels[knifedrawsound], false);
-                                                                                                                                                               }
-                                                                                                                                                       }
-                                                                                                                                                       if(fleshstuck){
-                                                                                                                                                               PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
-                                                                                                                                                               OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
-                                                                                                                                                               OPENAL_SetVolume(channels[fleshstabremovesound], 128);
-                                                                                                                                                               OPENAL_SetPaused(channels[fleshstabremovesound], false);
+                                                                                                                                                               if(weapons.type[k]!=staff)
+                                                                                                                                                                 emit_sound_at(knifedrawsound, player[i].coords, 128.);
                                                                                                                                                        }
+                                                                                                                                                       if(fleshstuck)
+                                                                                                                                                         emit_sound_at(fleshstabremovesound, player[i].coords, 128.);
 
                                                                                                                                                        player[i].weaponactive=0;
                                                                                                                                                        if(weapons.owner[k]!=-1){
@@ -7542,26 +7222,10 @@ void    Game::Tick()
                                                                                                                player[i].coords.y+=.2;
                                                                                                                player[i].jumppower-=1;
 
-                                                                                                               static float gLoc[3];
-                                                                                                               static float vel[3];
-                                                                                                               gLoc[0]=player[i].coords.x;
-                                                                                                               gLoc[1]=player[i].coords.y;
-                                                                                                               gLoc[2]=player[i].coords.z;
-                                                                                                               vel[0]=player[i].velocity.x;
-                                                                                                               vel[1]=player[i].velocity.y;
-                                                                                                               vel[2]=player[i].velocity.z;
-
-                                                                                                               if(i==0){
-                                                                                                                       PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
-                                                                                                                       OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
-                                                                                                                       OPENAL_SetVolume(channels[whooshsound], 128);
-                                                                                                                       OPENAL_SetPaused(channels[whooshsound], false);
-                                                                                                               }
+                                                                                                               if (!i)
+                                                                                                                 emit_sound_at(whooshsound, player[i].coords, 128.);
 
-                                                                                                               PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
-                                                                                                               OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
-                                                                                                               OPENAL_SetVolume(channels[jumpsound], 128);
-                                                                                                               OPENAL_SetPaused(channels[jumpsound], false);
+                                                                                                               emit_sound_at(jumpsound, player[i].coords, 128.);
                                                                                                }
                                                                                                if((player[i].isIdle())&&player[i].jumppower>1){
                                                                                                        player[i].targetanimation=player[i].getLanding();
@@ -7692,7 +7356,7 @@ void      Game::Tick()
                                                                                OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
                                                                                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
 
-                                                                               PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
+                                                                               PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
                                                                                OPENAL_SetPaused(channels[stream_music3], false);
                                                                                OPENAL_SetVolume(channels[stream_music3], 256);
 
@@ -7705,18 +7369,7 @@ void     Game::Tick()
                                                                        }
                                                                        if(tutorialstage<51)
                                                                                if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
-                                                                                       float gLoc[3];
-                                                                                       float vel[3];
-                                                                                       gLoc[0]=player[0].coords.x;
-                                                                                       gLoc[1]=player[0].coords.y;
-                                                                                       gLoc[2]=player[0].coords.z;
-                                                                                       vel[0]=0;
-                                                                                       vel[1]=0;
-                                                                                       vel[2]=0;
-                                                                                       PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                                                       OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                                                                                       OPENAL_SetVolume(channels[fireendsound], 256);
-                                                                                       OPENAL_SetPaused(channels[fireendsound], false);
+                                                                                       emit_sound_at(fireendsound, player[0].coords);
 
                                                                                        player[0].coords=(oldtemp+oldtemp2)/2;
 
@@ -7724,18 +7377,7 @@ void     Game::Tick()
                                                                                }
                                                                                if(tutorialstage>=14&&tutorialstage<50)
                                                                                        if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
-                                                                                               float gLoc[3];
-                                                                                               float vel[3];
-                                                                                               gLoc[0]=player[1].coords.x;
-                                                                                               gLoc[1]=player[1].coords.y;
-                                                                                               gLoc[2]=player[1].coords.z;
-                                                                                               vel[0]=0;
-                                                                                               vel[1]=0;
-                                                                                               vel[2]=0;
-                                                                                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                                                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                                                                                               OPENAL_SetVolume(channels[fireendsound], 256);
-                                                                                               OPENAL_SetPaused(channels[fireendsound], false);
+                                                                                               emit_sound_at(fireendsound, player[1].coords);
 
                                                                                                for(int i=0;i<player[1].skeleton.num_joints;i++){
                                                                                                        if(Random()%2==0){
@@ -7906,15 +7548,15 @@ void    Game::TickOnceAfter(){
 
                if(musictoggle){
                        if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
-                               PlayStreamEx( music1, strm[music1], NULL, true);
+                               PlayStreamEx( music1, samp[music1], NULL, true);
                                OPENAL_SetPaused(channels[music1], false);
                        }
                        if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
-                               PlayStreamEx( stream_music2, strm[stream_music2], NULL, true);
+                               PlayStreamEx( stream_music2, samp[stream_music2], NULL, true);
                                OPENAL_SetPaused(channels[stream_music2], false);
                        }
                        if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
-                               PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
+                               PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
                                OPENAL_SetPaused(channels[stream_music3], false);
                        }
                        if(musicvolume[0]<=0&&oldmusicvolume[0]>0){