+ } else if (selected == 2) {
+ stereoreverse = !stereoreverse;
+ } else if (selected == 3) {
+ flash();
+ mainmenu = 3;
+
+ stereomode = newstereomode;
+ InitStereo(stereomode);
+ }
+ }
+ updateStereoConfigMenu();
+ break;
+ }
+ }
+
+ if (Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)) {
+ tryquit = 1;
+ if (mainmenu == 3) {
+ SaveSettings();
+ }
+ }
+
+ OPENAL_SetFrequency(channels[stream_menutheme], 22050);
+
+ if (entername) {
+ inputText(displaytext[0], &displayselected, &displaychars[0]);
+ if (!waiting) { // the input as finished
+ if (displaychars[0]) { // with enter
+ accountactive = Account::add(string(displaytext[0]));
+
+ mainmenu = 8;
+
+ flash();
+
+ fireSound(firestartsound);
+
+ for (int i = 0; i < 255; i++) {
+ displaytext[0][i] = 0;
+ }
+ displaychars[0] = 0;
+
+ displayselected = 0;
+ }
+ entername = 0;
+ LoadMenu();
+ }
+
+ displayblinkdelay -= multiplier;
+ if (displayblinkdelay <= 0) {
+ displayblinkdelay = .3;
+ displayblink = 1 - displayblink;
+ }
+ }
+
+ if (entername) {
+ Menu::setText(0, displaytext[0], 20, 400, -1, -1);
+ Menu::setText(-2, displayblink ? "_" : "", 20 + displayselected * 10, 400, -1, -1);
+ }
+
+ if (oldmainmenu != mainmenu)
+ LoadMenu();
+ oldmainmenu = mainmenu;
+
+}
+
+void Game::Tick()
+{
+ static XYZ facing, flatfacing;
+ static int target;
+
+ for (int i = 0; i < 15; i++) {
+ displaytime[i] += multiplier;
+ }
+
+ keyboardfrozen = false;
+ Input::Tick();
+
+ if (Input::isKeyPressed(SDLK_F6)) {
+ if (Input::isKeyDown(SDLK_LSHIFT))
+ stereoreverse = true;
+ else
+ stereoreverse = false;
+
+ if (stereoreverse)
+ printf("Stereo reversed\n");
+ else
+ printf("Stereo unreversed\n");
+ }
+
+ if (Input::isKeyDown(SDLK_F7)) {
+ if (Input::isKeyDown(SDLK_LSHIFT))
+ stereoseparation -= 0.001;
+ else
+ stereoseparation -= 0.010;
+ printf("Stereo decreased increased to %f\n", stereoseparation);
+ }
+
+ if (Input::isKeyDown(SDLK_F8)) {
+ if (Input::isKeyDown(SDLK_LSHIFT))
+ stereoseparation += 0.001;
+ else
+ stereoseparation += 0.010;
+ printf("Stereo separation increased to %f\n", stereoseparation);
+ }
+
+
+ if (Input::isKeyPressed(SDLK_TAB) && tutoriallevel) {
+ if (tutorialstage != 51)
+ tutorialstagetime = tutorialmaxtime;
+ emit_sound_np(consolefailsound, 128.);
+ }
+
+ /*
+ Values of mainmenu :
+ 1 Main menu
+ 2 Menu pause (resume/end game)
+ 3 Option menu
+ 4 Controls configuration menu
+ 5 Main game menu (choose level or challenge)
+ 6 Deleting user menu
+ 7 User managment menu (select/add)
+ 8 Choose difficulty menu
+ 9 Challenge level selection menu
+ 10 End of the campaign congratulation (is that really a menu?)
+ 11 Same that 9 ??? => unused
+ 18 stereo configuration
+ */
+
+ if (!console) {
+ //campaign over?
+ if (mainmenu && endgame == 1)
+ mainmenu = 10;
+ //go to level select after completing a campaign level
+ if (campaign && winfreeze && mainmenu == 0 && campaignlevels[actuallevel].choosenext == 1) {
+ mainmenu = 5;
+ gameon = 0;
+ winfreeze = 0;
+ fireSound();
+ flash();
+ if (musictoggle) {
+ OPENAL_SetFrequency(OPENAL_ALL, 0.001);
+ emit_stream_np(stream_menutheme);
+ pause_sound(leveltheme);
+ }
+ LoadMenu();
+ }
+ //escape key pressed
+ if (Input::isKeyPressed(SDLK_ESCAPE) &&
+ (gameon || mainmenu == 0 || (mainmenu >= 3 && mainmenu != 8 && !(mainmenu == 7 && entername)))) {
+ selected = -1;
+ if (mainmenu == 0 && !winfreeze)
+ mainmenu = 2; //pause
+ else if (mainmenu == 1 || mainmenu == 2) {
+ mainmenu = 0; //unpause
+ }
+ //play menu theme
+ if (musictoggle && (mainmenu == 1 || mainmenu == 2)) {
+ OPENAL_SetFrequency(OPENAL_ALL, 0.001);
+ emit_stream_np(stream_menutheme);
+ pause_sound(leveltheme);
+ }
+ //on resume, play level music
+ if (!mainmenu) {
+ pause_sound(stream_menutheme);
+ resume_stream(leveltheme);
+ }
+ //finished with settings menu
+ if (mainmenu == 3) {
+ SaveSettings();
+ }
+ //effects
+ if (mainmenu >= 3 && mainmenu != 8) {
+ fireSound();
+ flash();
+ }
+ //go back
+ switch (mainmenu) {
+ case 3:
+ case 5:
+ mainmenu = gameon ? 2 : 1;
+ break;
+ case 4:
+ case 18:
+ mainmenu = 3;
+ break;
+ case 6:
+ case 7:
+ case 9:
+ case 10:
+ mainmenu = 5;
+ break;
+ }
+ }
+ }
+
+ if (mainmenu) {
+ MenuTick();
+ }
+
+ if (!mainmenu) {
+ if (hostile == 1)
+ hostiletime += multiplier;
+ else
+ hostiletime = 0;
+ if (!winfreeze)
+ leveltime += multiplier;
+
+ //keys
+ if (Input::isKeyPressed(SDLK_v) && debugmode) {
+ freeze = 1 - freeze;
+ if (freeze) {
+ OPENAL_SetFrequency(OPENAL_ALL, 0.001);
+ }
+ }
+
+ if (Input::isKeyPressed(chatkey) && !console && !chatting && debugmode)
+ chatting = 1;
+
+ if (chatting) {
+ inputText(displaytext[0], &displayselected, &displaychars[0]);
+ if (!waiting) {
+ if (displaychars[0]) {
+ for (int j = 0; j < 255; j++)
+ displaytext[0][j] = 0;
+ displaychars[0] = 0;
+ displayselected = 0;
+ }
+ chatting = 0;
+ }
+
+ displayblinkdelay -= multiplier;
+ if (displayblinkdelay <= 0) {
+ displayblinkdelay = .3;
+ displayblink = 1 - displayblink;
+ }
+ }
+ if (chatting)
+ keyboardfrozen = true;
+
+ if (Input::isKeyPressed(consolekey) && debugmode) {
+ console = !console;
+ if (console) {
+ OPENAL_SetFrequency(OPENAL_ALL, 0.001);
+ } else {
+ freeze = 0;
+ waiting = false;
+ }
+ }
+
+ if (console)
+ freeze = 1;
+ if (console && !Input::isKeyDown(SDLK_LMETA)) {
+ inputText(consoletext[0], &consoleselected, &consolechars[0]);
+ if (!waiting) {
+ if (consolechars[0] > 0) {
+ consoletext[0][consolechars[0]] = '\0';
+ cmd_dispatch(consoletext[0]);
+ for (int k = 14; k >= 1; k--) {
+ for (int j = 0; j < 255; j++)
+ consoletext[k][j] = consoletext[k - 1][j];
+ consolechars[k] = consolechars[k - 1];
+ }
+ for (int j = 0; j < 255; j++)
+ consoletext[0][j] = 0;
+ consolechars[0] = 0;
+ consoleselected = 0;
+ }
+ }
+
+ consoleblinkdelay -= multiplier;
+ if (consoleblinkdelay <= 0) {
+ consoleblinkdelay = .3;
+ consoleblink = 1 - consoleblink;
+ }
+ }
+
+
+
+ if (Input::isKeyDown(SDLK_q) && Input::isKeyDown(SDLK_LMETA)) {
+ tryquit = 1;
+ if (mainmenu == 3) {
+ SaveSettings();
+ }
+ }
+
+ static int oldwinfreeze;
+ if (winfreeze && !oldwinfreeze) {
+ OPENAL_SetFrequency(OPENAL_ALL, 0.001);
+ emit_sound_np(consolesuccesssound);
+ }
+ if (winfreeze == 0)
+ oldwinfreeze = winfreeze;
+ else
+ oldwinfreeze++;
+
+ if ((Input::isKeyPressed(jumpkey) || Input::isKeyPressed(SDLK_SPACE)) && !campaign)
+ if (winfreeze)
+ winfreeze = 0;
+ if ((Input::isKeyDown(SDLK_ESCAPE)) && !campaign && gameon) {
+ if (console) {
+ console = false;
+ freeze = 0;
+ } else if (winfreeze) {
+ mainmenu = 9;
+ gameon = 0;
+ }
+ }
+
+
+
+ if (!freeze && !winfreeze && !(mainmenu && gameon) && (gameon || !gamestarted)) {
+
+ //dialogues
+ static float talkdelay = 0;
+
+ if (indialogue != -1)
+ talkdelay = 1;
+ talkdelay -= multiplier;
+
+ if (talkdelay <= 0 && indialogue == -1 && animation[Person::players[0]->animTarget].height != highheight)
+ for (int i = 0; i < numdialogues; i++) {
+ int realdialoguetype;
+ bool special;
+ if (dialoguetype[i] > 49) {
+ realdialoguetype = dialoguetype[i] - 50;
+ special = 1;
+ } else if (dialoguetype[i] > 39) {
+ realdialoguetype = dialoguetype[i] - 40;
+ special = 1;
+ } else if (dialoguetype[i] > 29) {
+ realdialoguetype = dialoguetype[i] - 30;
+ special = 1;
+ } else if (dialoguetype[i] > 19) {
+ realdialoguetype = dialoguetype[i] - 20;
+ special = 1;
+ } else if (dialoguetype[i] > 9) {
+ realdialoguetype = dialoguetype[i] - 10;
+ special = 1;
+ } else {
+ realdialoguetype = dialoguetype[i];
+ special = 0;