]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameTick.cpp
Move dialogue stuff to Game.{cpp,h}
[lugaru.git] / Source / GameTick.cpp
index 38d379ecbe6da7f6b1c6cf86c51fe37f9bab95af..383052eedb45b72dbeb79c6377b10059082dade9 100644 (file)
@@ -49,7 +49,6 @@ extern XYZ viewer;
 extern int environment;
 extern float texscale;
 extern Terrain terrain;
-extern int channels[100];
 extern int kTextureSize;
 extern float screenwidth,screenheight;
 extern float gravity;
@@ -158,28 +157,6 @@ extern int hostile;
 extern bool stillloading;
 extern bool winfreeze;
 
-extern int numdialogues;
-extern int numdialogueboxes[max_dialogues];
-extern int dialoguetype[max_dialogues];
-extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
-extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
-extern int dialogueboxsound[max_dialogues][max_dialoguelength];
-extern char dialoguetext[max_dialogues][max_dialoguelength][128];
-extern char dialoguename[max_dialogues][max_dialoguelength][64];
-extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
-extern XYZ participantlocation[max_dialogues][10];
-extern int participantfocus[max_dialogues][max_dialoguelength];
-extern int participantaction[max_dialogues][max_dialoguelength];
-extern float participantrotation[max_dialogues][10];
-extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
-extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
-extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
-extern int indialogue;
-extern int whichdialogue;
-extern int directing;
-extern float dialoguetime;
-extern int dialoguegonethrough[20];
-
 extern bool campaign;
 
 extern float oldgamespeed;
@@ -214,10 +191,6 @@ static bool stripfx(const char *str, const char *pfx)
   return !strncasecmp(str, pfx, strlen(pfx));
 }
 
-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);
-
-
 static const char *cmd_names[] = {
 #define DECLARE_COMMAND(cmd) #cmd " ",
 #include "ConsoleCmds.h"
@@ -610,7 +583,7 @@ static void set_clothes(int pnum, Game *game, const char *args)
   if (!game->AddClothes(buf,0,1,&player[pnum].skeleton.skinText[pnum],&player[pnum].skeleton.skinsize))
     return;
 
-  player[pnum].DoMipmaps(5,0,0,player[pnum].skeleton.skinsize,player[pnum].skeleton.skinsize);
+  player[pnum].DoMipmaps();
   strcpy(player[pnum].clothes[player[pnum].numclothes],buf);
   player[pnum].clothestintr[player[pnum].numclothes]=tintr;
   player[pnum].clothestintg[player[pnum].numclothes]=tintg;
@@ -1104,18 +1077,7 @@ static void cmd_dispatch(Game *game, const char *cmd)
        cmd_handlers[i](game, cmd + strlen(cmd_names[i]));
        break;
       }
-  if (i < n_cmds)
-    {
-      PlaySoundEx(consolesuccesssound, samp[consolesuccesssound], NULL, true);
-      OPENAL_SetVolume(channels[consolesuccesssound], 256);
-      OPENAL_SetPaused(channels[consolesuccesssound], false);
-    }
-  else
-    {
-      PlaySoundEx(consolefailsound, samp[consolefailsound], NULL, true);
-      OPENAL_SetVolume(channels[consolefailsound], 256);
-      OPENAL_SetPaused(channels[consolefailsound], false);
-    }
+  emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
 }
 
 /********************> Tick() <*****/
@@ -1330,29 +1292,19 @@ void    Game::Setenvironment(int which)
 
        float temptexdetail;
        environment=which;
-/*
-       OPENAL_SetPaused(channels[music1snow], true);
-       OPENAL_SetPaused(channels[music1grass], true);
-       OPENAL_SetPaused(channels[music1desert], true);
-       OPENAL_SetPaused(channels[wind], true);
-       OPENAL_SetPaused(channels[desertambient], true);
-*/
-       OPENAL_SetPaused(channels[stream_music1snow], true);
-       OPENAL_SetPaused(channels[stream_music1grass], true);
-       OPENAL_SetPaused(channels[stream_music1desert], true);
-       OPENAL_SetPaused(channels[stream_wind], true);
-       OPENAL_SetPaused(channels[stream_desertambient], true);
+
+       pause_sound(stream_music1snow);
+       pause_sound(stream_music1grass);
+       pause_sound(stream_music1desert);
+       pause_sound(stream_wind);
+       pause_sound(stream_desertambient);
 
 
        if(environment==snowyenvironment){
                windvector=0;
                windvector.z=3;
-               if(ambientsound){
-                       //PlaySoundEx( wind, samp[wind], NULL, true);
-                       PlayStreamEx(stream_wind, samp[stream_wind], 0, true);
-                       OPENAL_SetPaused(channels[stream_wind], false);
-                       OPENAL_SetVolume(channels[stream_wind], 256);
-               }
+               if(ambientsound)
+                 emit_stream_np(stream_wind);
 
                LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
                LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
@@ -1398,12 +1350,8 @@ void     Game::Setenvironment(int which)
                LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
 
 
-               if(ambientsound){
-                       //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
-                       PlayStreamEx( stream_desertambient, samp[stream_desertambient], NULL, true);
-                       OPENAL_SetPaused(channels[stream_desertambient], false);
-                       OPENAL_SetVolume(channels[stream_desertambient], 256);
-               }
+               if(ambientsound)
+                 emit_stream_np(stream_desertambient);
 
                footstepsound = footstepsn1;
                footstepsound2 = footstepsn2;
@@ -1442,11 +1390,8 @@ void     Game::Setenvironment(int which)
                LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
                LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
 
-               if(ambientsound){
-                       PlayStreamEx( stream_wind, samp[stream_wind], NULL, true);
-                       OPENAL_SetPaused(channels[stream_wind], false);
-                       OPENAL_SetVolume(channels[stream_wind], 100);
-               }
+               if(ambientsound)
+                 emit_stream_np(stream_wind, 100.);
 
                footstepsound = footstepgr1;
                footstepsound2 = footstepgr2;
@@ -1543,8 +1488,8 @@ void      Game::Loadlevel(char *name){
        if(!firstload){
                oldlevel=50;
        }
-       OPENAL_SetPaused(channels[whooshsound], true);
-       OPENAL_SetPaused(channels[stream_firesound], true);
+       pause_sound(whooshsound);
+       pause_sound(stream_firesound);
 
        // Change the map filename into something that is os specific
        char *FixedFN = ConvertFileName(name);
@@ -1554,7 +1499,7 @@ void      Game::Loadlevel(char *name){
        tfile=fopen( FixedFN, "rb" );
        if(tfile)
        {
-               OPENAL_SetPaused(channels[stream_firesound], true);
+               pause_sound(stream_firesound);
 
 
                scoreadded=0;
@@ -1625,9 +1570,7 @@ void      Game::Loadlevel(char *name){
                changedelay=0;
                if(console)
                {
-                       PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
-                       OPENAL_SetVolume(channels[consolesuccesssound], 256);
-                       OPENAL_SetPaused(channels[consolesuccesssound], false);
+                       emit_sound_np(consolesuccesssound);
                        freeze=0;
                        console=0;
                }
@@ -1721,21 +1664,6 @@ void     Game::Loadlevel(char *name){
                        player[0].creature=rabbittype;
                }
 
-               for(i=0;i<max_dialogues;i++)
-               {
-                       for(j=0;j<max_dialoguelength;j++)
-                       {
-                               for(k=0;k<128;k++)
-                               {
-                                       dialoguetext[i][j][k]='\0';
-                               }
-                               for(k=0;k<64;k++)
-                               {
-                                       dialoguename[i][j][k]='\0';
-                               }
-                       }
-               }
-
                player[0].lastattack=-1;
                player[0].lastattack2=-1;
                player[0].lastattack3=-1;
@@ -1772,6 +1700,7 @@ void      Game::Loadlevel(char *name){
                                                                funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
                                                                if(dialoguetext[k][l][m]=='\0')break;
                                                        }
+                                                       dialoguetext[k][l][m] = 0;
 
                                                        funpackf(tfile, "Bi",&templength);
                                                        if(templength>64||templength<=0)templength=64;
@@ -1781,6 +1710,7 @@ void      Game::Loadlevel(char *name){
                                                                        break;
                                                                }
                                                        }
+                                                       dialoguename[k][l][m] = 0;
                                                        funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
                                                        funpackf(tfile, "Bi", &participantfocus[k][l]);
                                                        funpackf(tfile, "Bi", &participantaction[k][l]);
@@ -2060,7 +1990,7 @@ void      Game::Loadlevel(char *name){
                                        tintb=player[i].clothestintb[j];
                                        AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
                                }
-                               player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
+                               player[i].DoMipmaps();
                        }
 
                        player[i].currentanimation=bounceidleanim;
@@ -2231,33 +2161,17 @@ void    Game::Loadlevel(char *name){
                if(environment==snowyenvironment)
                {
                        if(ambientsound)
-                       {
-                               PlayStreamEx(stream_wind, samp[stream_wind], NULL, true);
-                               OPENAL_SetPaused(channels[stream_wind], false);
-                               OPENAL_SetVolume(channels[stream_wind], 256);
-                       }
+                         emit_stream_np(stream_wind);
                }
                else if(environment==desertenvironment)
                {
                        if(ambientsound)
-                       {
-                               //PlaySoundEx(desertambient,
-                               //      samp[desertambient], NULL, true);
-                               PlayStreamEx(stream_desertambient,
-                                       samp[stream_desertambient], NULL, true);
-                               OPENAL_SetPaused(channels[stream_desertambient], false);
-                               OPENAL_SetVolume(channels[stream_desertambient], 256);
-                       }
+                         emit_stream_np(stream_desertambient);
                }
                else if(environment==grassyenvironment)
                {
                        if(ambientsound)
-                       {
-                               //PlaySoundEx(wind, samp[wind], NULL, true);
-                               PlayStreamEx(stream_wind, samp[stream_wind], NULL, true);
-                               OPENAL_SetPaused(channels[stream_wind], false);
-                               OPENAL_SetVolume(channels[stream_wind], 100);
-                       }
+                         emit_stream_np(stream_wind, 100.);
                }
                oldmusicvolume[0]=0;
                oldmusicvolume[1]=0;
@@ -2352,15 +2266,13 @@ void    Game::Tick()
                                if(mainmenu&&musictoggle){
                                        if(mainmenu==1||mainmenu==2||mainmenu==100){
                                                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);
-                                               OPENAL_SetPaused(channels[music1], true);
+                                               emit_stream_np(stream_music3);
+                                               pause_sound(music1);
                                        }
                                }
                                if(!mainmenu){
-                                       OPENAL_SetPaused(channels[stream_music3], true);
-                                       OPENAL_SetPaused(channels[music1], false);
+                                       pause_sound(stream_music3);
+                                       resume_stream(music1);
                                }
                        }
                        if(mainmenu==3){
@@ -2405,9 +2317,7 @@ void      Game::Tick()
        if(Input::isKeyDown(SDLK_TAB)&&!minimaptogglekeydown&&tutoriallevel){
                if(tutorialstage!=51)
                        tutorialstagetime=tutorialmaxtime;
-               PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
-               OPENAL_SetVolume(channels[consolefailsound], 128);
-               OPENAL_SetPaused(channels[consolefailsound], false);
+               emit_sound_np(consolefailsound, 128.);
                minimaptogglekeydown=1;
        }
        if(!Input::isKeyDown(SDLK_TAB)){
@@ -2435,8 +2345,8 @@ void      Game::Tick()
                                {
                                        //resume
                                        mainmenu=0;
-                                       OPENAL_SetPaused(channels[stream_music3], true);
-                                       OPENAL_SetPaused(channels[music1], false);
+                                       pause_sound(stream_music3);
+                                       resume_stream(music1);
                                }
                        }
 
@@ -2465,7 +2375,7 @@ void      Game::Tick()
                                if(!gameon){
                                        //quit
                                        tryquit=1;
-                                       OPENAL_SetPaused(channels[stream_music3], true);
+                                       pause_sound(stream_music3);
                                }
                                else{
                                        //end game
@@ -2548,9 +2458,9 @@ void      Game::Tick()
                                musictoggle=1-musictoggle;
 
                                if(!musictoggle){
-                                       OPENAL_SetPaused(channels[music1], true);
-                                       OPENAL_SetPaused(channels[stream_music2], true);
-                                       OPENAL_SetPaused(channels[stream_music3], true);
+                                       pause_sound(music1);
+                                       pause_sound(stream_music2);
+                                       pause_sound(stream_music3);
 
                                        for(i=0;i<4;i++){
                                                oldmusicvolume[i]=0;
@@ -2558,11 +2468,8 @@ void     Game::Tick()
                                        }
                                }
 
-                               if(musictoggle){
-                                       PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
-                                       OPENAL_SetPaused(channels[stream_music3], false);
-                                       OPENAL_SetVolume(channels[stream_music3], 256);
-                               }
+                               if(musictoggle)
+                                 emit_stream_np(stream_music3);
                        }
                        if(Input::Button()&&!oldbutton&&selected==9){
                                invertmouse=1-invertmouse;
@@ -2660,7 +2567,7 @@ void      Game::Tick()
 
                                mainmenu=0;
                                gameon=1;
-                               OPENAL_SetPaused(channels[stream_music3], true);
+                               pause_sound(stream_music3);
                        }
                        if(Input::Button()&&!oldbutton&&(selected-7>=accountactive->getCampaignChoicesMade())){
                                fireSound();
@@ -2697,7 +2604,7 @@ void      Game::Tick()
                                campaign=1;
                                mainmenu=0;
                                gameon=1;
-                               OPENAL_SetPaused(channels[stream_music3], true);
+                               pause_sound(stream_music3);
                        }
                        if(Input::Button()&&!oldbutton&&selected==4){
                                fireSound();
@@ -2749,7 +2656,7 @@ void      Game::Tick()
 
                                mainmenu=0;
                                gameon=1;
-                               OPENAL_SetPaused(channels[stream_music3], true);
+                               pause_sound(stream_music3);
                        }
                        if(Input::Button()&&!oldbutton&&selected==numchallengelevels){
                                fireSound();
@@ -3029,9 +2936,7 @@ void      Game::Tick()
                static int oldwinfreeze;
                if(winfreeze&&!oldwinfreeze){
                        OPENAL_SetFrequency(OPENAL_ALL, 0.001);
-                       PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
-                       OPENAL_SetVolume(channels[consolesuccesssound], 256);
-                       OPENAL_SetPaused(channels[consolesuccesssound], false);
+                       emit_sound_np(consolesuccesssound);
                }
                if(winfreeze==0)oldwinfreeze=winfreeze;
                else oldwinfreeze++;
@@ -3602,9 +3507,7 @@ void      Game::Tick()
 
 
                                                if(tutorialstagetime==tutorialmaxtime-3){
-                                                       PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
-                                                       OPENAL_SetVolume(channels[consolesuccesssound], 256);
-                                                       OPENAL_SetPaused(channels[consolesuccesssound], false);
+                                                       emit_sound_np(consolesuccesssound);
                                                }
 
                                                if(tutorialsuccess>=1){
@@ -3622,16 +3525,12 @@ void    Game::Tick()
 
                                        if(tutoriallevel!=1){
                                                if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
-                                                       PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
-                                                       OPENAL_SetVolume(channels[consolesuccesssound], 256);
-                                                       OPENAL_SetPaused(channels[consolesuccesssound], false);
+                                                       emit_sound_np(consolesuccesssound);
                                                }
                                        }
                                        else
                                                if(bonustime==0){
-                                                       PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                       OPENAL_SetVolume(channels[fireendsound], 256);
-                                                       OPENAL_SetPaused(channels[fireendsound], false);
+                                                       emit_sound_np(fireendsound);
                                                }
                                                if(bonustime==0){
                                                        if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
@@ -3738,7 +3637,7 @@ void      Game::Tick()
                                                                                                                        player[k].targetanimation=walljumpleftanim;
                                                                                                                        player[k].targetframe=0;
                                                                                                                        emit_sound_at(movewhooshsound, player[k].coords);
-                                                                                                                       if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
+                                                                                                                       if(k==0)pause_sound(whooshsound);
 
                                                                                                                        lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
                                                                                                                        player[k].rotation=-asin(0-lowpointtarget.x);
@@ -3758,7 +3657,7 @@ void      Game::Tick()
                                                                                                                                player[k].targetanimation=walljumprightanim;
                                                                                                                                player[k].targetframe=0;
                                                                                                                                emit_sound_at(movewhooshsound, player[k].coords);
-                                                                                                                               if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
+                                                                                                                               if(k==0)pause_sound(whooshsound);
 
                                                                                                                                lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
                                                                                                                                player[k].rotation=-asin(0-lowpointtarget.x);
@@ -3778,7 +3677,7 @@ void      Game::Tick()
                                                                                                                                        player[k].targetanimation=walljumpbackanim;
                                                                                                                                        player[k].targetframe=0;
                                                                                                                                        emit_sound_at(movewhooshsound, player[k].coords);
-                                                                                                                                       if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
+                                                                                                                                       if(k==0)pause_sound(whooshsound);
 
                                                                                                                                        lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
                                                                                                                                        player[k].rotation=-asin(0-lowpointtarget.x);
@@ -3798,7 +3697,7 @@ void      Game::Tick()
                                                                                                                                                player[k].targetanimation=walljumpfrontanim;
                                                                                                                                                player[k].targetframe=0;
                                                                                                                                                emit_sound_at(movewhooshsound, player[k].coords);
-                                                                                                                                               if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
+                                                                                                                                               if(k==0)pause_sound(whooshsound);
 
                                                                                                                                                lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
                                                                                                                                                player[k].rotation=-asin(0-lowpointtarget.x);
@@ -3833,7 +3732,7 @@ void      Game::Tick()
                                                                                                                player[k].onterrain=1;
 
                                                                                                                if(player[k].id==0){
-                                                                                                                       OPENAL_SetPaused(channels[whooshsound], true);
+                                                                                                                       pause_sound(whooshsound);
                                                                                                                        OPENAL_SetVolume(channels[whooshsound], 0);
                                                                                                                }
 
@@ -3938,7 +3837,7 @@ void      Game::Tick()
 
                                                                                                                                                                                                        if(j>10||!player[k].isRun()){
                                                                                                                                                                                                                if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
-                                                                                                                                                                                                                       if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
+                                                                                                                                                                                                                       if(k==0)pause_sound(whooshsound);
                                                                                                                                                                                                                }
                                                                                                                                                                                                                emit_sound_at(jumpsound, player[k].coords, 128.);
 
@@ -4148,7 +4047,7 @@ void      Game::Tick()
                                                                                        }
                                                        }
                                                        if(!directing){
-                                                               OPENAL_SetPaused(channels[whooshsound], true);
+                                                               pause_sound(whooshsound);
                                                                viewer=dialoguecamera[whichdialogue][indialogue];
                                                                if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
                                                                        viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
@@ -4426,7 +4325,7 @@ void      Game::Tick()
                                                                                tintb=player[closest].clothestintb[i];
                                                                                AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
                                                                        }
-                                                                       player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
+                                                                       player[closest].DoMipmaps();
                                                                }
 
                                                                detailtogglekeydown=1;
@@ -4695,7 +4594,7 @@ void      Game::Tick()
                                                        }
                                                        if(!player[0].onfire){
                                                                emit_sound_at(fireendsound, player[0].coords);
-                                                               OPENAL_SetPaused(channels[stream_firesound], true);
+                                                               pause_sound(stream_firesound);
                                                        }
                                                        slomotogglekeydown=1;
                                                }
@@ -4884,7 +4783,7 @@ void      Game::Tick()
                                                                                AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
                                                                        }
                                                                        if(player[numplayers].numclothes){
-                                                                               player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
+                                                                               player[numplayers].DoMipmaps();
                                                                        }
 
                                                                        player[numplayers].power=player[0].power;
@@ -5081,7 +4980,6 @@ void      Game::Tick()
                                                        //player[0].DoDamage(1000);
 
                                                        emit_sound_at(whooshsound, player[0].coords, 128.);
-                                                       //OPENAL_SetPaused(channels[whooshsound], true);
 
                                                        texturesizetogglekeydown=1;
                                                }
@@ -7356,9 +7254,7 @@ void      Game::Tick()
                                                                                OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
                                                                                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
 
-                                                                               PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
-                                                                               OPENAL_SetPaused(channels[stream_music3], false);
-                                                                               OPENAL_SetVolume(channels[stream_music3], 256);
+                                                                               emit_stream_np(stream_music3);
 
                                                                                gameon=0;
                                                                                mainmenu=5;
@@ -7516,17 +7412,7 @@ void     Game::TickOnceAfter(){
 
                if(musictoggle){
                        if(musictype!=oldmusictype&&musictype==stream_music2){
-                               static float gLoc[3];
-                               static float vel[3];
-                               gLoc[0]=cameraloc.x;
-                               gLoc[1]=cameraloc.y;
-                               gLoc[2]=cameraloc.z;
-                               vel[0]=0;
-                               vel[1]=0;
-                               vel[2]=0;
-                               PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
-                               OPENAL_SetVolume(channels[alarmsound], 512);
-                               OPENAL_SetPaused(channels[alarmsound], false);
+                               emit_sound_np(alarmsound);
 
                        }
                }
@@ -7547,26 +7433,20 @@ void    Game::TickOnceAfter(){
                if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
 
                if(musictoggle){
-                       if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
-                               PlayStreamEx( music1, samp[music1], NULL, true);
-                               OPENAL_SetPaused(channels[music1], false);
-                       }
-                       if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
-                               PlayStreamEx( stream_music2, samp[stream_music2], NULL, true);
-                               OPENAL_SetPaused(channels[stream_music2], false);
-                       }
-                       if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
-                               PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
-                               OPENAL_SetPaused(channels[stream_music3], false);
-                       }
+                       if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
+                         emit_stream_np(music1, musicvolume[0]);
+                       if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
+                         emit_stream_np(stream_music2, musicvolume[1]);
+                       if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
+                         emit_stream_np(stream_music3, musicvolume[2]);
                        if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
-                               OPENAL_SetPaused(channels[music1], true);
+                               pause_sound(music1);
                        }
                        if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
-                               OPENAL_SetPaused(channels[stream_music2], true);
+                               pause_sound(stream_music2);
                        }
                        if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
-                               OPENAL_SetPaused(channels[stream_music3], true);
+                               pause_sound(stream_music3);
                        }
 
                        if(musicvolume[0]!=oldmusicvolume[0]){
@@ -7583,9 +7463,9 @@ void      Game::TickOnceAfter(){
                                oldmusicvolume[i]=musicvolume[i];
                        }
                } else {
-                       OPENAL_SetPaused(channels[music1], true);
-                       OPENAL_SetPaused(channels[stream_music2], true);
-                       OPENAL_SetPaused(channels[stream_music3], true);
+                       pause_sound(music1);
+                       pause_sound(stream_music2);
+                       pause_sound(stream_music3);
 
                        for(i=0;i<4;i++){
                                oldmusicvolume[i]=0;
@@ -7842,7 +7722,7 @@ void      Game::TickOnceAfter(){
                                        campaign=1;
                                        mainmenu=0;
                                        gameon=1;
-                                       OPENAL_SetPaused(channels[stream_music3], true);
+                                       pause_sound(stream_music3);
 
                                        stealthloading=0;
                                }