]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameTick.cpp
Move stats vars and award computation to Awards.cpp
[lugaru.git] / Source / GameTick.cpp
index 0330b0e460c23f6b432e52050ce6d08675ac6080..466da3ed7f5cae785acc2b96faf596baf2dfa50b 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,7 +49,6 @@ extern XYZ viewer;
 extern int environment;
 extern float texscale;
 extern Terrain terrain;
-extern OPENAL_SAMPLE *samp[100];
 extern int channels[100];
 extern int kTextureSize;
 extern float screenwidth,screenheight;
@@ -59,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];
@@ -71,9 +71,6 @@ extern float blackout;
 extern bool cellophane;
 extern bool musictoggle;
 extern int difficulty;
-extern Weapons weapons;
-extern Person player[maxplayers];
-extern int numplayers;
 extern int bloodtoggle;
 extern bool invertmouse;
 extern float windvar;
@@ -144,7 +141,6 @@ extern bool reversaltrain;
 extern bool canattack;
 extern bool cananger;
 extern float damagedealt;
-extern float damagetaken;
 extern int maptype;
 extern int editoractive;
 extern int editorpathtype;
@@ -169,23 +165,6 @@ extern int hostile;
 extern bool stillloading;
 extern bool winfreeze;
 
-extern int numfalls;
-extern int numflipfail;
-extern int numseen;
-extern int numstaffattack;
-extern int numswordattack;
-extern int numknifeattack;
-extern int numunarmedattack;
-extern int numescaped;
-extern int numflipped;
-extern int numwallflipped;
-extern int numthrowkill;
-extern int numafterkill;
-extern int numreversals;
-extern int numattacks;
-extern int maxalarmed;
-extern int numresponded;
-
 extern int numdialogues;
 extern int numdialogueboxes[max_dialogues];
 extern int dialoguetype[max_dialogues];
@@ -242,7 +221,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);
 
@@ -1389,7 +1367,7 @@ void      Game::Setenvironment(int which)
                windvector.z=3;
                if(ambientsound){
                        //PlaySoundEx( wind, samp[wind], NULL, true);
-                       PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
+                       PlayStreamEx(stream_wind, samp[stream_wind], 0, true);
                        OPENAL_SetPaused(channels[stream_wind], false);
                        OPENAL_SetVolume(channels[stream_wind], 256);
                }
@@ -1399,18 +1377,10 @@ void    Game::Setenvironment(int which)
                LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
                LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
 
-               OPENAL_Sample_Free(samp[footstepsound]);
-               OPENAL_Sample_Free(samp[footstepsound2]);
-               OPENAL_Sample_Free(samp[footstepsound3]);
-               OPENAL_Sample_Free(samp[footstepsound4]);
-               samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone1.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepstone2.ogg"), OPENAL_HW3D, 0, 0);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
+               footstepsound = footstepsn1;
+               footstepsound2 = footstepsn2;
+               footstepsound3 = footstepst1;
+               footstepsound4 = footstepst2;
 
                LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
 
@@ -1448,23 +1418,15 @@ void    Game::Setenvironment(int which)
 
                if(ambientsound){
                        //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
-                       PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
+                       PlayStreamEx( stream_desertambient, samp[stream_desertambient], NULL, true);
                        OPENAL_SetPaused(channels[stream_desertambient], false);
                        OPENAL_SetVolume(channels[stream_desertambient], 256);
                }
 
-               OPENAL_Sample_Free(samp[footstepsound]);
-               OPENAL_Sample_Free(samp[footstepsound2]);
-               OPENAL_Sample_Free(samp[footstepsound3]);
-               OPENAL_Sample_Free(samp[footstepsound4]);
-               samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow1.ogg"), OPENAL_HW3D, 0, 0);
-               samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ConvertFileName(":Data:Sounds:footstepsnow2.ogg"), OPENAL_HW3D, 0, 0);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
-               OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
+               footstepsound = footstepsn1;
+               footstepsound2 = footstepsn2;
+               footstepsound3 = footstepsn1;
+               footstepsound4 = footstepsn2;
 
                LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
 
@@ -1499,23 +1461,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);
 
@@ -1629,7 +1583,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;
 
@@ -2195,7 +2149,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;
@@ -2296,7 +2250,7 @@ void      Game::Loadlevel(char *name){
                {
                        if(ambientsound)
                        {
-                               PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
+                               PlayStreamEx(stream_wind, samp[stream_wind], NULL, true);
                                OPENAL_SetPaused(channels[stream_wind], false);
                                OPENAL_SetVolume(channels[stream_wind], 256);
                        }
@@ -2308,7 +2262,7 @@ void      Game::Loadlevel(char *name){
                                //PlaySoundEx(desertambient,
                                //      samp[desertambient], NULL, true);
                                PlayStreamEx(stream_desertambient,
-                                       strm[stream_desertambient], NULL, true);
+                                       samp[stream_desertambient], NULL, true);
                                OPENAL_SetPaused(channels[stream_desertambient], false);
                                OPENAL_SetVolume(channels[stream_desertambient], 256);
                        }
@@ -2318,7 +2272,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);
                        }
@@ -2403,7 +2357,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){
@@ -2416,7 +2370,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);
@@ -2439,7 +2393,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();
@@ -2452,8 +2406,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;
@@ -2467,16 +2419,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)
@@ -2635,7 +2577,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);
                                }
@@ -2738,7 +2680,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();
@@ -2805,7 +2747,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();
 
@@ -2835,36 +2777,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){
@@ -5143,7 +5055,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;
 
@@ -7734,7 +7646,7 @@ void      Game::Tick()
                                                                                OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
                                                                                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
 
-                                                                               PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
+                                                                               PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
                                                                                OPENAL_SetPaused(channels[stream_music3], false);
                                                                                OPENAL_SetVolume(channels[stream_music3], 256);
 
@@ -7948,15 +7860,15 @@ void    Game::TickOnceAfter(){
 
                if(musictoggle){
                        if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
-                               PlayStreamEx( music1, strm[music1], NULL, true);
+                               PlayStreamEx( music1, samp[music1], NULL, true);
                                OPENAL_SetPaused(channels[music1], false);
                        }
                        if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
-                               PlayStreamEx( stream_music2, strm[stream_music2], NULL, true);
+                               PlayStreamEx( stream_music2, samp[stream_music2], NULL, true);
                                OPENAL_SetPaused(channels[stream_music2], false);
                        }
                        if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
-                               PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
+                               PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
                                OPENAL_SetPaused(channels[stream_music3], false);
                        }
                        if(musicvolume[0]<=0&&oldmusicvolume[0]>0){