]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameTick.cpp
Cleanup sound emission
[lugaru.git] / Source / GameTick.cpp
index b3114ede00ef316177d82a46fc01e3b8a03aea50..38d379ecbe6da7f6b1c6cf86c51fe37f9bab95af 100644 (file)
@@ -32,6 +32,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "openal_wrapper.h"
 #include "Settings.h"
 #include "Input.h"
+#include "Animation.h"
+#include "Awards.h"
 
 using namespace std;
 
@@ -47,9 +49,7 @@ extern XYZ viewer;
 extern int environment;
 extern float texscale;
 extern Terrain terrain;
-extern OPENAL_SAMPLE *samp[100];
 extern int channels[100];
-extern Sprites sprites;
 extern int kTextureSize;
 extern float screenwidth,screenheight;
 extern float gravity;
@@ -60,7 +60,6 @@ extern int slomo;
 extern float slomodelay;
 extern bool floatjump;
 extern float volume;
-extern Animation animation[animation_count];
 extern Light light;
 extern float texdetail;
 extern GLubyte bloodText[512*512*3];
@@ -72,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;
@@ -116,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;
@@ -145,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;
@@ -170,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];
@@ -243,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);
 
@@ -1018,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;
@@ -1053,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)
@@ -1160,7 +1119,7 @@ static void cmd_dispatch(Game *game, const char *cmd)
 }
 
 /********************> Tick() <*****/
-extern void ScreenShot(const char * fname);
+extern bool save_image(const char * fname);
 void Screenshot        (void)
 {
        char temp[1024];
@@ -1173,8 +1132,8 @@ void Screenshot   (void)
        #else
        mkdir("Screenshots", S_IRWXU);
        #endif
-
-       ScreenShot(temp);
+       
+       save_image(temp);
 }
 
 
@@ -1390,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);
                }
@@ -1400,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);
 
@@ -1449,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);
 
@@ -1500,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);
 
@@ -1574,26 +1509,6 @@ void     Game::Loadlevel(int which){
        whichlevel=which;
 }
 
-/*char * Game::MD5_string (unsigned char *string){
-char temp[50];
-char temp2[100];
-
-strcpy(temp2,(const char *)string);
-strcat((char *)temp2,(const char *)"Lugaru");
-sprintf (temp, "%d",strlen((char *)temp2));
-strcat((char *)temp2,temp);
-
-MD5 context;
-unsigned int len = strlen ( (char *)temp2);
-
-context.update   ((unsigned char *)temp2, len);
-context.finalize ();
-
-return context.hex_digest();
-}*/
-
-
-
 void   Game::Loadlevel(char *name){
        int i,j,k,l,m;
        static int oldlevel;
@@ -1650,7 +1565,7 @@ void      Game::Loadlevel(char *name){
                won=0;
 
                //campaign=0;
-               animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
+               animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
 
                numdialogues=0;
 
@@ -1720,7 +1635,7 @@ void      Game::Loadlevel(char *name){
                if(!stealthloading)
                {
                        terrain.numdecals=0;
-                       sprites.numsprites=0;
+                       Sprite::deleteSprites();
                        for(i=0;i<objects.numobjects;i++)
                        {
                                objects.model[i].numdecals=0;
@@ -2216,7 +2131,7 @@ void      Game::Loadlevel(char *name){
                                player[i].proportionlegs.z=0;
                        }
 
-                       player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
+                       player[i].tempanimation.Load((char *)"Tempanim",0,0);
 
                        player[i].headmorphness=0;
                        player[i].targetheadmorphness=1;
@@ -2317,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);
                        }
@@ -2329,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);
                        }
@@ -2339,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);
                        }
@@ -2424,7 +2339,7 @@ void      Game::Tick()
                if(mainmenu&&endgame==1)mainmenu=10;
                if( (Input::isKeyDown(SDLK_ESCAPE)||(mainmenu==0&&((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))
                    && !mainmenutogglekeydown
-                   && (!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==10)
+                   && (!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==10)
                  ) { // go back
                        selected=-1;
                        if(mainmenu==1||mainmenu==2||mainmenu==0){
@@ -2437,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);
@@ -2460,7 +2375,7 @@ void      Game::Tick()
 
                                SaveSettings(*this);
                        }
-                       if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==13||mainmenu==10||mainmenu==11||mainmenu==100){
+                       if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==10||mainmenu==100){
                                fireSound();
 
                                flash();
@@ -2473,8 +2388,6 @@ void      Game::Tick()
                        if(mainmenu==6)mainmenu=5;
                        if(mainmenu==7)mainmenu=1;
                        if(mainmenu==9)mainmenu=5;
-                       if(mainmenu==11)mainmenu=5;
-                       if(mainmenu==13)mainmenu=12;
                        if(mainmenu==10)mainmenu=5;
                        if(mainmenu==100){
                                mainmenu=5;
@@ -2488,16 +2401,6 @@ void     Game::Tick()
                }
        }
 
-       /*static bool minimaptogglekeydown;
-       if(Input::isKeyDown(SDLK_TAB)&&!minimaptogglekeydown){
-       minimap=1-minimap;
-       minimaptogglekeydown=1;
-       }
-       if(!Input::isKeyDown(SDLK_TAB)){
-       minimaptogglekeydown=0;
-       }
-       */
-
        static bool minimaptogglekeydown;
        if(Input::isKeyDown(SDLK_TAB)&&!minimaptogglekeydown&&tutoriallevel){
                if(tutorialstage!=51)
@@ -2656,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);
                                }
@@ -2759,7 +2662,7 @@ void      Game::Tick()
                                gameon=1;
                                OPENAL_SetPaused(channels[stream_music3], true);
                        }
-                       if(Input::Button()&&!oldbutton&&(selected-7>=accountactive->getCampaignChoicesMade())){//selected>=7&&(selected-7<=campaignnumchoices)){
+                       if(Input::Button()&&!oldbutton&&(selected-7>=accountactive->getCampaignChoicesMade())){
                                fireSound();
 
                                flash();
@@ -2826,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();
 
@@ -2856,36 +2759,6 @@ void     Game::Tick()
                                mainmenu=5;
                        }
                }
-               if(mainmenu==11){
-                       if(Input::Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountactive->getProgress()){
-                               fireSound();
-
-                               flash();
-
-                               startbonustotal=0;
-
-                               loading=2;
-                               loadtime=0;
-                               targetlevel=selected;
-                               if(firstload) {
-                                       TickOnceAfter();
-                                       Loadlevel(selected);
-                               } else
-                                       LoadStuff();
-                               campaign=0;
-
-                               mainmenu=0;
-                               gameon=1;
-                               OPENAL_SetPaused(channels[stream_music3], true);
-                       }
-                       if(Input::Button()&&!oldbutton&&selected==numchallengelevels){
-                               fireSound();
-
-                               flash();
-
-                               mainmenu=5;
-                       }
-               }
                if(mainmenu==10){
                        endgame=2;
                        if(Input::Button()&&!oldbutton&&selected==3){
@@ -3230,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;
@@ -3264,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;
                                                        }
@@ -3293,7 +3156,7 @@ void      Game::Tick()
                                                                hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
                                                                hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
                                                                hotspotsprite+=hotspot[i];
-                                                               sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
+                                                               Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
                                                                hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
                                                        }
                                                }
@@ -3354,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){
@@ -3373,7 +3225,7 @@ void      Game::Tick()
                                                                        if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
                                                                        if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
                                                                        if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
-                                                                       sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
+                                                                       Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
                                                                }
                                                        }
 
@@ -3606,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){
@@ -3625,7 +3466,7 @@ void      Game::Tick()
                                                                        if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
                                                                        if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
                                                                        if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
-                                                                       sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
+                                                                       Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
                                                                }
                                                        }
 
@@ -3813,7 +3654,7 @@ void      Game::Tick()
                                                                footpoint.y+=((float)abs(Random()%1200))/100-6;
                                                                footpoint.x+=((float)abs(Random()%1200))/100-6;
                                                                footpoint.z+=((float)abs(Random()%1200))/100-6;
-                                                               sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
+                                                               Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
                                                        }
                                                }
                                                for(k=0;k<numplayers;k++){
@@ -3896,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);
@@ -3927,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);
@@ -3958,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);
@@ -3989,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);
@@ -4043,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;
@@ -4154,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);
@@ -4215,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;
                                                                                                }
@@ -4320,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;
@@ -4354,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);
                                                                                        }
                                                                                }
 
@@ -4410,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;
@@ -4446,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;
@@ -4516,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);
                                                }
@@ -4822,29 +4554,14 @@ void    Game::Tick()
                                                                                flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
                                                                                headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
                                                                                Normalise(&headspurtdirection);
-                                                                               sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
+                                                                               Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
                                                                                flatvelocity2+=headspurtdirection*8;
-                                                                               sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
+                                                                               Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
                                                                        }
-                                                                       sprites.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);
+                                                                       Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
+
+                                                                       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);
@@ -4876,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;
@@ -4903,9 +4605,9 @@ void      Game::Tick()
                                                                                flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
-                                                                               sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
-                                                                               sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
-                                                                               sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
+                                                                               Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
+                                                                               Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
+                                                                               Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
                                                                        }
 
                                                                        for(i=0;i<player[closest].skeleton.num_joints; i++){
@@ -4916,8 +4618,8 @@ void      Game::Tick()
                                                                                flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
-                                                                               sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
-                                                                               sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
+                                                                               Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
+                                                                               Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
                                                                        }
 
                                                                        for(i=0;i<player[closest].skeleton.num_joints; i++){
@@ -4928,8 +4630,8 @@ void      Game::Tick()
                                                                                flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
-                                                                               sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
-                                                                               sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
+                                                                               Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
+                                                                               Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
                                                                        }
 
                                                                        for(i=0;i<player[closest].skeleton.num_joints; i++){
@@ -4940,8 +4642,8 @@ void      Game::Tick()
                                                                                flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
-                                                                               sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
-                                                                               sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
+                                                                               Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
+                                                                               Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
                                                                        }
 
                                                                        XYZ temppos;
@@ -4992,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;
@@ -5164,7 +4855,7 @@ void      Game::Tick()
                                                                        player[numplayers].proportionlegs.z=0;
                                                                }
 
-                                                               player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
+                                                               player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
 
                                                                player[numplayers].damagetolerance=200;
 
@@ -5389,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;
@@ -5812,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);
 
@@ -5906,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;
@@ -5920,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);
                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                }
                                                                                                                                                                                                                        }
@@ -6740,21 +6397,6 @@ void     Game::Tick()
                                                                                                                                        else player[i].targetrotation-=90;
                                                                                                                                }
                                                                                                                        }
-                                                                                                                       /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
-                                                                                                                       if(abs(Random()%6)){
-                                                                                                                       player[i].crouchkeydown=1;
-                                                                                                                       if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
-                                                                                                                       if(player[i].isRun()){
-                                                                                                                       player[i].targetframe=0;
-                                                                                                                       player[i].target=0;
-                                                                                                                       player[i].targetanimation=sneakanim;
-                                                                                                                       }
-                                                                                                                       }
-                                                                                                                       else player[i].forwardkeydown=0;
-                                                                                                                       }
-                                                                                                                       else player[i].crouchkeydown=0;
-                                                                                                                       }
-                                                                                                                       else player[i].crouchkeydown=0;*/
                                                                                                                }
 
                                                                                                                player[i].leftkeydown=0;
@@ -7078,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;
@@ -7125,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;
@@ -7178,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){
@@ -7194,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){
@@ -7231,7 +6833,7 @@ void      Game::Tick()
                                                                                                                                                                footpoint=weapons.position[k];
                                                                                                                                                                if(player[i].victim->weaponstuck!=-1){
                                                                                                                                                                        if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
-                                                                                                                                                                               if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
+                                                                                                                                                                               if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
                                                                                                                                                                                weapons.bloody[k]=2;
                                                                                                                                                                                weapons.blooddrip[k]=5;
                                                                                                                                                                                player[i].victim->weaponstuck=-1;
@@ -7620,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();
@@ -7737,154 +7323,124 @@ void  Game::Tick()
 
                                                        objects.DoStuff();
                                                        
-                                                       if(numenvsounds!=0)
-                                                               for(j=numenvsounds-1;j>=0;j--){
-                                                                       envsoundlife[j]-=multiplier;
-                                                                       if(envsoundlife[j]<0){
-                                                                               numenvsounds--;
-                                                                               envsoundlife[j]=envsoundlife[numenvsounds];
-                                                                               envsound[j]=envsound[numenvsounds];
-                                                                       }
+                                                       for(j=numenvsounds-1;j>=0;j--){
+                                                               envsoundlife[j]-=multiplier;
+                                                               if(envsoundlife[j]<0){
+                                                                       numenvsounds--;
+                                                                       envsoundlife[j]=envsoundlife[numenvsounds];
+                                                                       envsound[j]=envsound[numenvsounds];
                                                                }
-                                                               if(!slomo)OPENAL_SetFrequency(OPENAL_ALL, 22050);
-                                                               if(slomo)OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
-
-                                                               if(tutoriallevel==1){
-                                                                       XYZ temp;
-                                                                       XYZ temp2;
-                                                                       XYZ temp3;
-                                                                       XYZ oldtemp;
-                                                                       XYZ oldtemp2;
-                                                                       temp.x=1011;
-                                                                       temp.y=84;
-                                                                       temp.z=491;
-                                                                       temp2.x=1025;
-                                                                       temp2.y=75;
-                                                                       temp2.z=447;
-                                                                       temp3.x=1038;
-                                                                       temp3.y=76;
-                                                                       temp3.z=453;
-                                                                       oldtemp=temp;
-                                                                       oldtemp2=temp2;
-                                                                       if(tutorialstage>=51)
+                                                       }
+                                                       if(slomo) OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
+                                                       else OPENAL_SetFrequency(OPENAL_ALL, 22050);
+
+                                                       if(tutoriallevel==1){
+                                                               XYZ temp;
+                                                               XYZ temp2;
+                                                               XYZ temp3;
+                                                               XYZ oldtemp;
+                                                               XYZ oldtemp2;
+                                                               temp.x=1011;
+                                                               temp.y=84;
+                                                               temp.z=491;
+                                                               temp2.x=1025;
+                                                               temp2.y=75;
+                                                               temp2.z=447;
+                                                               temp3.x=1038;
+                                                               temp3.y=76;
+                                                               temp3.z=453;
+                                                               oldtemp=temp;
+                                                               oldtemp2=temp2;
+                                                               if(tutorialstage>=51)
+                                                                       if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
+                                                                               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, samp[stream_music3], NULL, true);
+                                                                               OPENAL_SetPaused(channels[stream_music3], false);
+                                                                               OPENAL_SetVolume(channels[stream_music3], 256);
+
+                                                                               gameon=0;
+                                                                               mainmenu=5;
+
+                                                                               fireSound();
+
+                                                                               flash();
+                                                                       }
+                                                                       if(tutorialstage<51)
                                                                                if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
-                                                   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);
-                                                                                       OPENAL_SetPaused(channels[stream_music3], false);
-                                                                                       OPENAL_SetVolume(channels[stream_music3], 256);
-
-                                                                                       gameon=0;
-                                                                                       mainmenu=5;
+                                                                                       emit_sound_at(fireendsound, player[0].coords);
 
-                                                                                       float gLoc[3]={0,0,0};
-                                                                                       float vel[3]={0,0,0};
-                                                                                       OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                                                                                       PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                                                       OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                                                                                       OPENAL_SetVolume(channels[fireendsound], 256);
-                                                                                       OPENAL_SetPaused(channels[fireendsound], false);
-                                                                                       OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
+                                                                                       player[0].coords=(oldtemp+oldtemp2)/2;
 
                                                                                        flash();
                                                                                }
-                                                                               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);
-
-                                                                                               player[0].coords=(oldtemp+oldtemp2)/2;
-
-                                                                                               flash();
-                                                                                       }
-                                                                                       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);
-
-                                                                                                       for(int i=0;i<player[1].skeleton.num_joints;i++){
-                                                                                                               if(Random()%2==0){
-                                                                                                                       if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
-                                                                                                                       if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
-                                                                                                                       if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
-                                                                                                                       if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
-                                                                                                                       sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
-                                                                                                               }
+                                                                               if(tutorialstage>=14&&tutorialstage<50)
+                                                                                       if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
+                                                                                               emit_sound_at(fireendsound, player[1].coords);
+
+                                                                                               for(int i=0;i<player[1].skeleton.num_joints;i++){
+                                                                                                       if(Random()%2==0){
+                                                                                                               if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
+                                                                                                               if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
+                                                                                                               if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
+                                                                                                               if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
+                                                                                                               Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
                                                                                                        }
+                                                                                               }
 
-                                                                                                       player[1].coords=(oldtemp+oldtemp2)/2;
-                                                                                                       for(int i=0;i<player[1].skeleton.num_joints;i++){
-                                                                                                               player[1].skeleton.joints[i].velocity=0;
-                                                                                                               if(Random()%2==0){
-                                                                                                                       if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
-                                                                                                                       if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
-                                                                                                                       if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
-                                                                                                                       if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
-                                                                                                                       sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
-                                                                                                               }
+                                                                                               player[1].coords=(oldtemp+oldtemp2)/2;
+                                                                                               for(int i=0;i<player[1].skeleton.num_joints;i++){
+                                                                                                       player[1].skeleton.joints[i].velocity=0;
+                                                                                                       if(Random()%2==0){
+                                                                                                               if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
+                                                                                                               if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
+                                                                                                               if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
+                                                                                                               if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
+                                                                                                               Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
                                                                                                        }
                                                                                                }
-                                                               }
+                                                                                       }
+                                                       }
 
 
-                                                               //3d sound
-                                                               static float gLoc[3];
-                                                               gLoc[0]=viewer.x;
-                                                               gLoc[1]=viewer.y;
-                                                               gLoc[2]=viewer.z;
-                                                               static float vel[3];
-                                                               vel[0]=(viewer.x-oldviewer.x)/multiplier;
-                                                               vel[1]=(viewer.y-oldviewer.y)/multiplier;
-                                                               vel[2]=(viewer.z-oldviewer.z)/multiplier;
+                                                       //3d sound
+                                                       static float gLoc[3];
+                                                       gLoc[0]=viewer.x;
+                                                       gLoc[1]=viewer.y;
+                                                       gLoc[2]=viewer.z;
+                                                       static float vel[3];
+                                                       vel[0]=(viewer.x-oldviewer.x)/multiplier;
+                                                       vel[1]=(viewer.y-oldviewer.y)/multiplier;
+                                                       vel[2]=(viewer.z-oldviewer.z)/multiplier;
 
-                                                               //Set orientation with forward and up vectors
-                                                               static XYZ upvector;
-                                                               upvector=0;
-                                                               upvector.z=-1;
+                                                       //Set orientation with forward and up vectors
+                                                       static XYZ upvector;
+                                                       upvector=0;
+                                                       upvector.z=-1;
 
-                                                               upvector=DoRotation(upvector,-rotation2+90,0,0);
-                                                               upvector=DoRotation(upvector,0,0-rotation,0);
+                                                       upvector=DoRotation(upvector,-rotation2+90,0,0);
+                                                       upvector=DoRotation(upvector,0,0-rotation,0);
 
-                                                               facing=0;
-                                                               facing.z=-1;
+                                                       facing=0;
+                                                       facing.z=-1;
 
-                                                               facing=DoRotation(facing,-rotation2,0,0);
-                                                               facing=DoRotation(facing,0,0-rotation,0);
+                                                       facing=DoRotation(facing,-rotation2,0,0);
+                                                       facing=DoRotation(facing,0,0-rotation,0);
 
 
-                                                               static float ori[6];
-                                                               ori[0] = -facing.x;
-                                                               ori[1] = facing.y;
-                                                               ori[2] = -facing.z;
-                                                               ori[3] = -upvector.x;
-                                                               ori[4] = upvector.y;
-                                                               ori[5] = -upvector.z;
+                                                       static float ori[6];
+                                                       ori[0] = -facing.x;
+                                                       ori[1] = facing.y;
+                                                       ori[2] = -facing.z;
+                                                       ori[3] = -upvector.x;
+                                                       ori[4] = upvector.y;
+                                                       ori[5] = -upvector.z;
 
-                                                               OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
-                                                               OPENAL_Update();
+                                                       OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
+                                                       OPENAL_Update();
 
-                                                               oldviewer=viewer;
+                                                       oldviewer=viewer;
                }
        }
 
@@ -7895,15 +7451,16 @@ void    Game::Tick()
 }
 
 void   Game::TickOnce(){
-       if(!mainmenu)
-               if(directing||indialogue==-1){
+       if(mainmenu)
+               rotation+=multiplier*5;
+       else
+               if(directing||indialogue==-1) {
                        rotation+=deltah*.7;
                        if(!invertmouse)rotation2+=deltav*.7;
                        if(invertmouse)rotation2-=deltav*.7;
                        if(rotation2>90)rotation2=90;
                        if(rotation2<-70)rotation2=-70;
                }
-               if(mainmenu)rotation+=multiplier*5;
 }
 
 void   Game::TickOnceAfter(){
@@ -7991,31 +7548,17 @@ 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(!musictoggle){
-                       OPENAL_SetPaused(channels[music1], true);
-                       OPENAL_SetPaused(channels[stream_music2], true);
-                       OPENAL_SetPaused(channels[stream_music3], true);
-
-                       for(i=0;i<4;i++){
-                               oldmusicvolume[i]=0;
-                               musicvolume[i]=0;
-                       }
-               }
-
-               if(musictoggle){
                        if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
                                OPENAL_SetPaused(channels[music1], true);
                        }
@@ -8039,283 +7582,276 @@ void  Game::TickOnceAfter(){
                        for(i=0;i<3;i++){
                                oldmusicvolume[i]=musicvolume[i];
                        }
+               } else {
+                       OPENAL_SetPaused(channels[music1], true);
+                       OPENAL_SetPaused(channels[stream_music2], true);
+                       OPENAL_SetPaused(channels[stream_music3], true);
+
+                       for(i=0;i<4;i++){
+                               oldmusicvolume[i]=0;
+                               musicvolume[i]=0;
+                       }
                }
 
                killhotspot=2;
-               if(numhotspots)
-                       for(i=0;i<numhotspots;i++){
-                               if(hotspottype[i]>10&&hotspottype[i]<20){
-                                       if(player[hotspottype[i]-10].dead==0){
-                                               killhotspot=0;
-                                       }
-                                       else if(killhotspot==2)
-                                               killhotspot=1;
+               for(i=0;i<numhotspots;i++){
+                       if(hotspottype[i]>10&&hotspottype[i]<20){
+                               if(player[hotspottype[i]-10].dead==0){
+                                       killhotspot=0;
                                }
+                               else if(killhotspot==2)
+                                       killhotspot=1;
                        }
-                       if(killhotspot==2)killhotspot=0;
+               }
+               if(killhotspot==2)killhotspot=0;
 
 
-                       winhotspot=0;
-                       if(numhotspots)
-                               for(i=0;i<numhotspots;i++){
-                                       if(hotspottype[i]==-1){
-                                               if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
-                                                       winhotspot=1;
-                                       }
-                               }
+               winhotspot=0;
+               for(i=0;i<numhotspots;i++){
+                       if(hotspottype[i]==-1){
+                               if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
+                                       winhotspot=1;
+                       }
+               }
 
-                               int numalarmed=0;
-                               if(numplayers>1)
-                                       for(i=1;i<numplayers;i++){
-                                               if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
-                                       }
-                                       if(numalarmed>maxalarmed)maxalarmed=numalarmed;
+               int numalarmed=0;
+               for(i=1;i<numplayers;i++){
+                       if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
+               }
+               if(numalarmed>maxalarmed)maxalarmed=numalarmed;
 
-                                       if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
-                                               if(player[0].dead&&changedelay<=0){
-                                                       changedelay=1;
-                                                       targetlevel=whichlevel;
-                                               }
-                                               alldead=1;
-                                               if(numplayers>1)
-                                                       for(i=1;i<numplayers;i++){
-                                                               if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
-                                                       }
+               if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
+                       if(player[0].dead&&changedelay<=0){
+                               changedelay=1;
+                               targetlevel=whichlevel;
+                       }
+                       alldead=1;
+                       for(i=1;i<numplayers;i++){
+                               if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
+                       }
 
 
-                                                       if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
-                                                               changedelay=1;
-                                                               targetlevel=whichlevel+1;
-                                                               if(targetlevel>numchallengelevels-1)targetlevel=0;
-                                                       }
-                                                       if(winhotspot||windialogue){
-                                                               changedelay=0.1;
-                                                               targetlevel=whichlevel+1;
-                                                               if(targetlevel>numchallengelevels-1)targetlevel=0;
-                                                       }
+                       if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
+                               changedelay=1;
+                               targetlevel=whichlevel+1;
+                               if(targetlevel>numchallengelevels-1)targetlevel=0;
+                       }
+                       if(winhotspot||windialogue){
+                               changedelay=0.1;
+                               targetlevel=whichlevel+1;
+                               if(targetlevel>numchallengelevels-1)targetlevel=0;
+                       }
 
 
-                                                       if(killhotspot){
-                                                               changedelay=1;
-                                                               targetlevel=whichlevel+1;
-                                                               if(targetlevel>numchallengelevels-1)targetlevel=0;
-                                                       }
+                       if(killhotspot){
+                               changedelay=1;
+                               targetlevel=whichlevel+1;
+                               if(targetlevel>numchallengelevels-1)targetlevel=0;
+                       }
 
-                                                       if(changedelay>0&&!player[0].dead&&!won){
-                                                               //high scores, awards, win
-                                                               if(campaign){
-                                                                       won=1;
-                                                                       accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
-                                                                       /*accountcampaignchoices[accountactive][accountactive->getCampaignChoicesMade()]=whichchoice;
-                                                                       accountactive->getCampaignChoicesMade()++;
-                                                                       accountcampaignscore[accountactive]+=bonustotal;
-                                                                       accountcampaigntime[accountactive]+=leveltime;
-                                                                       if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])
-                                                                               accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];*/
-                                                                       scoreadded=1;
-                                                               }
-                                                               else
-                                                               {
-                                                                       won=1;
-                                                                       accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
-                                                               }
-                                                       }
-                                       }
+                       if(changedelay>0&&!player[0].dead&&!won){
+                               //high scores, awards, win
+                               if(campaign){
+                                       accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
+                                       scoreadded=1;
+                               }
+                               else
+                               {
+                                       accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
+                               }
+                               won=1;
+                       }
+               }
 
-                                       if(!winfreeze){
+               if(!winfreeze){
 
-                                               if(leveltime<1){
-                                                       loading=0;
-                                                       changedelay=.1;
-                                                       alldead=0;
-                                                       winhotspot=0;
-                                                       killhotspot=0;
-                                               }
+                       if(leveltime<1){
+                               loading=0;
+                               changedelay=.1;
+                               alldead=0;
+                               winhotspot=0;
+                               killhotspot=0;
+                       }
 
-                                               if(!editorenabled&&gameon&&!mainmenu){
-                                                       if(changedelay!=-999)changedelay-=multiplier/7;
-                                                       if(player[0].dead)targetlevel=whichlevel;
-                                                       if(loading==2&&!campaign){
-                                                               flash();
+                       if(!editorenabled&&gameon&&!mainmenu){
+                               if(changedelay!=-999)changedelay-=multiplier/7;
+                               if(player[0].dead)targetlevel=whichlevel;
+                               if(loading==2&&!campaign){
+                                       flash();
 
-                                                               fireSound(firestartsound);
+                                       fireSound(firestartsound);
 
-                                                               if(!player[0].dead&&targetlevel!=whichlevel){
-                                                                       startbonustotal=bonustotal;
-                                                               }
-                                                               if(!player[0].dead)Loadlevel(targetlevel);
-                                                               if(player[0].dead)Loadlevel(whichlevel);
+                                       if(!player[0].dead&&targetlevel!=whichlevel){
+                                               startbonustotal=bonustotal;
+                                       }
+                                       if(player[0].dead) Loadlevel(whichlevel);
+                                       else Loadlevel(targetlevel);
 
-                                                               fireSound();
+                                       fireSound();
 
-                                                               loading=3;
-                                                       }
-                                                       if(loading==2&&targetlevel==whichlevel){
-                                                               flash();
-                                                               loadtime=0;
+                                       loading=3;
+                               }
+                               if(loading==2&&targetlevel==whichlevel){
+                                       flash();
+                                       loadtime=0;
 
-                                                               float gLoc[3]={0,0,0};
-                                                               float vel[3]={0,0,0};
-                                                               fireSound(firestartsound);
+                                       fireSound(firestartsound);
 
-                                                               for(i=0;i<255;i++){
-                                                                       mapname[i]='\0';
-                                                               }
-                                                               mapname[0]=':';
-                                                               mapname[1]='D';
-                                                               mapname[2]='a';
-                                                               mapname[3]='t';
-                                                               mapname[4]='a';
-                                                               mapname[5]=':';
-                                                               mapname[6]='M';
-                                                               mapname[7]='a';
-                                                               mapname[8]='p';
-                                                               mapname[9]='s';
-                                                               mapname[10]=':';
-                                                               strcat(mapname,campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);//[campaignchoicewhich[whichchoice]]);
-                                                               Loadlevel(mapname);
-
-                                                               fireSound();
-
-                                                               loading=3;
-                                                       }
-                                                       if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
-                                                       if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
-                        {
-                                                                       if(whichlevel!=-2&&!loading&&!player[0].dead){
-                                                                               winfreeze=1;
-                                                                               changedelay=-999;
-                                                                       }
-                                                                       if(player[0].dead)loading=1;
-                                                               }
-                                                       }
-                                               }
+                                       for(i=0;i<255;i++){
+                                               mapname[i]='\0';
+                                       }
+                                       mapname[0]=':';
+                                       mapname[1]='D';
+                                       mapname[2]='a';
+                                       mapname[3]='t';
+                                       mapname[4]='a';
+                                       mapname[5]=':';
+                                       mapname[6]='M';
+                                       mapname[7]='a';
+                                       mapname[8]='p';
+                                       mapname[9]='s';
+                                       mapname[10]=':';
+                                       strcat(mapname,campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);//[campaignchoicewhich[whichchoice]]);
+                                       Loadlevel(mapname);
 
-                                               if(campaign)
-                                                       if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
-                                                               if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
-                                                                       endgame=1;
-                                                               }
-                                                       }
-                                                       else if(mainmenu==0&&winfreeze){
-                                                               if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
-                                                                       stealthloading=1;
-                                                               else stealthloading=0;
+                                       fireSound();
 
-                                                               if(!stealthloading){
-                                                                       float gLoc[3]={0,0,0};
-                                                                       float vel[3]={0,0,0};
-                                                                       fireSound(firestartsound);
+                                       loading=3;
+                               }
+                               if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
+                               if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
+                       {
+                                               if(whichlevel!=-2&&!loading&&!player[0].dead){
+                                                       winfreeze=1;
+                                                       changedelay=-999;
+                                               }
+                                               if(player[0].dead)loading=1;
+                                       }
+                               }
+                       }
 
-                                                                       flash();
-                                                               }
+                       if(campaign)
+                               if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
+                                       if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
+                                               endgame=1;
+                                       }
+                               }
+                               else if(mainmenu==0&&winfreeze){
+                                       if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
+                                               stealthloading=1;
+                                       else stealthloading=0;
 
-                                                               startbonustotal=0;
-
-                                                               ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
-                                                               ipstream.ignore(256,':');
-                                                               ipstream >> campaignnumlevels;
-                                                               for(i=0;i<campaignnumlevels;i++){
-                                                                       ipstream.ignore(256,':');
-                                                                       ipstream.ignore(256,':');
-                                                                       ipstream.ignore(256,' ');
-                                                                       ipstream >> campaignmapname[i];
-                                                                       ipstream.ignore(256,':');
-                                                                       ipstream >> campaigndescription[i];
-                                                                       for(j=0;j<256;j++){
-                                                                               if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
-                                                                       }
-                                                                       ipstream.ignore(256,':');
-                                                                       ipstream >> campaignchoosenext[i];
-                                                                       ipstream.ignore(256,':');
-                                                                       ipstream >> campaignnumnext[i];
-                                                                       if(campaignnumnext[i])
-                                                                               for(j=0;j<campaignnumnext[i];j++){
-                                                                                       ipstream.ignore(256,':');
-                                                                                       ipstream >> campaignnextlevel[i][j];
-                                                                                       campaignnextlevel[i][j]-=1;
-                                                                               }
-                                                                               ipstream.ignore(256,':');
-                                                                               ipstream >> campaignlocationx[i];
-                                                                               ipstream.ignore(256,':');
-                                                                               ipstream >> campaignlocationy[i];
-                                                               }
-                                                               ipstream.close();
+                                       if(!stealthloading){
+                                               float gLoc[3]={0,0,0};
+                                               float vel[3]={0,0,0};
+                                               fireSound(firestartsound);
 
-                                                               for(i=0;i<campaignnumlevels;i++){
-                                                                       levelvisible[i]=0;
-                                                                       levelhighlight[i]=0;
-                                                               }
+                                               flash();
+                                       }
 
+                                       startbonustotal=0;
+
+                                       ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
+                                       ipstream.ignore(256,':');
+                                       ipstream >> campaignnumlevels;
+                                       for(i=0;i<campaignnumlevels;i++){
+                                               ipstream.ignore(256,':');
+                                               ipstream.ignore(256,':');
+                                               ipstream.ignore(256,' ');
+                                               ipstream >> campaignmapname[i];
+                                               ipstream.ignore(256,':');
+                                               ipstream >> campaigndescription[i];
+                                               for(j=0;j<256;j++){
+                                                       if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
+                                               }
+                                               ipstream.ignore(256,':');
+                                               ipstream >> campaignchoosenext[i];
+                                               ipstream.ignore(256,':');
+                                               ipstream >> campaignnumnext[i];
+                                               for(j=0;j<campaignnumnext[i];j++){
+                                                       ipstream.ignore(256,':');
+                                                       ipstream >> campaignnextlevel[i][j];
+                                                       campaignnextlevel[i][j]-=1;
+                                               }
+                                               ipstream.ignore(256,':');
+                                               ipstream >> campaignlocationx[i];
+                                               ipstream.ignore(256,':');
+                                               ipstream >> campaignlocationy[i];
+                                       }
+                                       ipstream.close();
 
-                                                               for(i=0;i<campaignnumlevels;i++){
-                                                                       levelvisible[i]=0;
-                                                                       levelhighlight[i]=0;
-                                                               }
+                                       for(i=0;i<campaignnumlevels;i++){
+                                               levelvisible[i]=0;
+                                               levelhighlight[i]=0;
+                                       }
 
-                                                               levelorder[0]=0;
-                                                               levelvisible[0]=1;
-                                                               if(accountactive->getCampaignChoicesMade())
-                                                                       for(i=0;i<accountactive->getCampaignChoicesMade();i++){
-                                                                               levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
-                                                                               levelvisible[levelorder[i+1]]=1;
-                                                                       }
-                                                                       int whichlevelstart;
-                                                                       whichlevelstart=accountactive->getCampaignChoicesMade()-1;
-                                                                       if(whichlevelstart<0){
-                                                                               campaignchoicenum=1;
-                                                                               campaignchoicewhich[0]=0;
-                                                                       }
-                                                                       else
-                                                                       {
-                                                                               campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
-                                                                               if(campaignchoicenum)
-                                                                                       for(i=0;i<campaignchoicenum;i++){
-                                                                                               campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
-                                                                                               levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-                                                                                               levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-                                                                                       }
-                                                                       }
 
-                                                                       loading=2;
-                                                                       loadtime=0;
-                                                                       targetlevel=7;
-                                                                       //if(firstload)TickOnceAfter();
-                                                                       if(!firstload)LoadStuff();
-                                                                       //else {
-                                                                       for(i=0;i<255;i++){
-                                                                               mapname[i]='\0';
-                                                                       }
-                                                                       mapname[0]=':';
-                                                                       mapname[1]='D';
-                                                                       mapname[2]='a';
-                                                                       mapname[3]='t';
-                                                                       mapname[4]='a';
-                                                                       mapname[5]=':';
-                                                                       mapname[6]='M';
-                                                                       mapname[7]='a';
-                                                                       mapname[8]='p';
-                                                                       mapname[9]='s';
-                                                                       mapname[10]=':';
-
-                                                                       strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
-                                                                       whichchoice=0;
-                                                                       visibleloading=1;
-                                                                       stillloading=1;
-                                                                       Loadlevel(mapname);
-                                                                       campaign=1;
-                                                                       mainmenu=0;
-                                                                       gameon=1;
-                                                                       OPENAL_SetPaused(channels[stream_music3], true);
-
-                                                                       stealthloading=0;
-                                                       }
+                                       for(i=0;i<campaignnumlevels;i++){
+                                               levelvisible[i]=0;
+                                               levelhighlight[i]=0;
+                                       }
 
-                                                       if(loading==3)loading=0;
+                                       levelorder[0]=0;
+                                       levelvisible[0]=1;
+                                       for(i=0;i<accountactive->getCampaignChoicesMade();i++){
+                                               levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
+                                               levelvisible[levelorder[i+1]]=1;
+                                       }
+                                       int whichlevelstart;
+                                       whichlevelstart=accountactive->getCampaignChoicesMade()-1;
+                                       if(whichlevelstart<0){
+                                               campaignchoicenum=1;
+                                               campaignchoicewhich[0]=0;
+                                       }
+                                       else
+                                       {
+                                               campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
+                                               for(i=0;i<campaignchoicenum;i++){
+                                                       campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
+                                                       levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
+                                                       levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
+                                               }
+                                       }
 
+                                       loading=2;
+                                       loadtime=0;
+                                       targetlevel=7;
+                                       //if(firstload)TickOnceAfter();
+                                       if(!firstload)LoadStuff();
+                                       //else {
+                                       for(i=0;i<255;i++){
+                                               mapname[i]='\0';
                                        }
+                                       mapname[0]=':';
+                                       mapname[1]='D';
+                                       mapname[2]='a';
+                                       mapname[3]='t';
+                                       mapname[4]='a';
+                                       mapname[5]=':';
+                                       mapname[6]='M';
+                                       mapname[7]='a';
+                                       mapname[8]='p';
+                                       mapname[9]='s';
+                                       mapname[10]=':';
+
+                                       strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
+                                       whichchoice=0;
+                                       visibleloading=1;
+                                       stillloading=1;
+                                       Loadlevel(mapname);
+                                       campaign=1;
+                                       mainmenu=0;
+                                       gameon=1;
+                                       OPENAL_SetPaused(channels[stream_music3], true);
+
+                                       stealthloading=0;
+                               }
+
+                               if(loading==3)loading=0;
+
+                       }
 
-                                       oldmusictype=musictype;
+                       oldmusictype=musictype;
        }
 
        facing=0;