2 Copyright (C) 2004-2011 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 map.persistantList.clear();
28 engine.practice = false;
30 game.skill = engine.skill;
33 void showInGameOptions()
35 if (!engine.loadWidgets(_("data/inGameWidgets")))
37 graphics.showErrorAndExit(ERR_FILE, _("data/inGameWidgets"));
40 graphics.drawRect(120, 100, 400, 300, graphics.black, graphics.white, graphics.screen);
42 int cont, options, escape, quit, escapeyes, escapeno, warnno, warnyes, quitno, quityes, train, trainno, trainyes, restart, restartno, restartyes;
43 cont = options = escape = quit = escapeyes = escapeno = warnno = warnyes = quitno = quityes = train = trainno = trainyes = restart = restartno = restartyes = 0;
45 engine.setWidgetVariable("continue", &cont);
46 engine.setWidgetVariable("options", &options);
47 engine.setWidgetVariable("escape", &escape);
48 engine.setWidgetVariable("restart", &restart);
49 engine.setWidgetVariable("quit", &quit);
50 engine.setWidgetVariable("train", &train);
52 engine.setWidgetVariable("warnno", &warnno);
53 engine.setWidgetVariable("warnyes", &warnyes);
55 engine.setWidgetVariable("restartno", &restartno);
56 engine.setWidgetVariable("restartyes", &restartyes);
58 engine.setWidgetVariable("quitno", &quitno);
59 engine.setWidgetVariable("quityes", &quityes);
61 engine.setWidgetVariable("trainno", &quitno);
62 engine.setWidgetVariable("trainyes", &quityes);
64 engine.setWidgetVariable("escapeno", &escapeno);
65 engine.setWidgetVariable("escapeyes", &escapeyes);
67 engine.showWidgetGroup("warning", false);
68 engine.showWidgetGroup("restartconf", false);
69 engine.showWidgetGroup("escapeconf", false);
70 engine.showWidgetGroup("quitconf", false);
71 engine.showWidgetGroup("trainconf", false);
73 if ((map.isBossMission) || (engine.practice) || (strcmp(map.name, "Space Station") == 0))
75 engine.enableWidget("escape", false);
76 engine.enableWidget("restart", false);
81 engine.showWidget("train", false);
85 engine.showWidget("quit", false);
92 audio.playMenuSound(2);
98 graphics.updateScreen();
102 if ((config.isControl(CONTROL::PAUSE)) || (engine.keyState[SDL_SCANCODE_ESCAPE]))
104 engine.keyState[SDL_SCANCODE_ESCAPE] = 0;
105 config.resetControl(CONTROL::PAUSE);
109 menuSound = engine.processWidgets();
113 graphics.drawRect(120, 100, 400, 300, graphics.black, graphics.white, graphics.screen);
115 audio.playMenuSound(menuSound);
125 engine.showWidgetGroup("options", false);
127 if (!gameData.stagePreviouslyCleared(game.stageName))
129 engine.showWidgetGroup("warning", true);
130 engine.highlightWidget("warnno");
134 engine.showWidgetGroup("escapeconf", true);
135 engine.highlightWidget("escapeno");
138 graphics.drawRect(120, 100, 400, 300, graphics.black, graphics.white, graphics.screen);
143 if ((escapeyes) || (warnyes))
146 audio.stopAmbiance();
147 addTeleportParticles(player.x, player.y, 50, SND_TELEPORT3);
149 game.setMissionOver(MIS_PLAYERESCAPE);
159 if ((warnno) || (quitno) || (escapeno) || (trainno) || (restartno))
161 engine.highlightWidget("continue");
162 engine.showWidgetGroup("options", true);
163 engine.showWidgetGroup("warning", false);
164 engine.showWidgetGroup("trainconf", false);
165 engine.showWidgetGroup("escapeconf", false);
166 engine.showWidgetGroup("quitconf", false);
167 engine.showWidgetGroup("restartconf", false);
169 if (!engine.practice)
171 engine.showWidget("train", false);
175 engine.showWidget("quit", false);
178 graphics.drawRect(120, 100, 400, 300, graphics.black, graphics.white, graphics.screen);
180 quitno = trainno = warnno = escapeno = restartno = 0;
185 engine.showWidgetGroup("options", false);
186 engine.showWidgetGroup("quitconf", true);
187 engine.highlightWidget("quitno");
189 graphics.drawRect(120, 100, 400, 300, graphics.black, graphics.white, graphics.screen);
196 engine.showWidgetGroup("options", false);
197 engine.showWidgetGroup("trainconf", true);
198 engine.highlightWidget("trainno");
200 graphics.drawRect(120, 100, 400, 300, graphics.black, graphics.white, graphics.screen);
207 engine.showWidgetGroup("options", false);
208 engine.showWidgetGroup("restartconf", true);
209 engine.highlightWidget("restartno");
211 graphics.drawRect(120, 100, 400, 300, graphics.black, graphics.white, graphics.screen);
216 if ((quityes) || (trainyes))
218 game.setMissionOver(MIS_PLAYERQUIT);
224 game.setMissionOver(MIS_PLAYERRESTART);
225 SDL_FillRect(graphics.screen, NULL, graphics.black);
227 audio.stopAmbiance();
240 replayData.read(config.command);
242 if (game.missionOverReason == MIS_INPROGRESS)
247 engine.doFrameLoop();
249 graphics.updateScreen();
250 graphics.animateSprites();
251 graphics.drawBackground();
263 if (map.isBossMission)
272 if (map.isBlizzardLevel)
279 replayData.set(config.command);
286 audio.stopAmbiance();
288 if (!engine.loadWidgets(_("data/gameOverWidgets")))
290 graphics.showErrorAndExit(ERR_FILE, _("data/gameOverWidgets"));
293 SDL_Surface *gameover = graphics.quickSprite("Game Over", graphics.loadImage("gfx/main/gameover.png"));
294 graphics.setTransparent(gameover);
296 audio.loadGameOverMusic();
302 unsigned int frameLimit = SDL_GetTicks() + 16;
304 bool showGameOverOptions = false;
305 int cont, quit, menuSound;
306 cont = quit = menuSound = 0;
308 engine.setWidgetVariable("gameOverNo", &cont);
309 engine.setWidgetVariable("gameOverYes", &quit);
311 if (game.canContinue > 1)
313 Widget *widget = engine.getWidgetByName("gameOverNo");
315 snprintf(postfix, sizeof postfix, " (%d)", game.canContinue);
316 strlcat(widget->label, postfix, sizeof widget->label);
322 audio.playMenuSound(menuSound);
327 graphics.blit(gameover, 320, 240, graphics.screen, true);
329 if (engine.userAccepts())
331 if (!showGameOverOptions)
333 showGameOverOptions = true;
334 engine.showWidgetGroup("gameover", true);
335 engine.highlightWidget("gameOverNo");
340 // Can't continue on a boss mission or if no checkpoints reached!
341 if ((map.isBossMission) || (!game.canContinue))
343 engine.showWidgetGroup("gameover", false);
348 if (showGameOverOptions)
351 menuSound = engine.processWidgets();
354 if ((cont) || (quit))
357 engine.delay(frameLimit);
358 frameLimit = SDL_GetTicks() + 16;
364 graphics.fadeToBlack();
367 return SECTION_TITLE;
370 game.continueFromCheckPoint = true;
372 audio.reloadLevelMusic();
377 void showMissionInformation()
379 SDL_FillRect(graphics.screen, NULL, graphics.black);
380 graphics.updateScreen();
382 SDL_Surface *panel = graphics.createSurface(400, 300);
383 SDL_Surface *panelBack = graphics.alphaRect(400, 300, 0x00, 0x00, 0x00);
384 SDL_SetColorKey(panel, SDL_RLEACCEL, SDL_MapRGB(panel->format, 0, 0, 0));
386 graphics.drawRect(1, 1, 398, 298, graphics.black, graphics.white, panelBack);
393 Objective *objective;
395 graphics.setFontSize(0);
397 graphics.setFontSize(3);
398 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
399 graphics.drawString(_(game.stageName), 200, 20, TXT_CENTERED, panel);
401 graphics.setFontSize(0);
405 if (map.totalMIAs > 0)
407 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
408 snprintf(message, sizeof message, _("Rescue %d MIAs"), map.requiredMIAs);
409 graphics.drawString(message, col1, y, TXT_LEFT, panel);
411 if (map.foundMIAs < map.requiredMIAs)
413 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
414 snprintf(message, sizeof message, "%d / %d", map.foundMIAs, map.requiredMIAs);
415 graphics.drawString(message, col2, y, TXT_RIGHT, panel);
419 graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
420 graphics.drawString(_("Completed"), col2, y, TXT_RIGHT, panel);
424 objective = (Objective*)map.objectiveList.getHead();
426 while (objective->next != NULL)
428 objective = (Objective*)objective->next;
432 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
434 if ((game.skill < 3) && (strstr(objective->description, "L.R.T.S.")) && (!gameData.completedWorld))
436 graphics.drawString(_("???? ???????? ????"), col1, y, TXT_LEFT, panel);
440 graphics.drawString(_(objective->description), col1, y, TXT_LEFT, panel);
443 // this is a fake objective (for the 4th Ancient Tomb)
444 if (objective->targetValue == -1)
446 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
447 graphics.drawString(_("Incomplete"), col2, y, TXT_RIGHT, panel);
449 else if (objective->currentValue < objective->targetValue)
451 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
452 if (objective->targetValue == 1)
454 graphics.drawString(_("Incomplete"), col2, y, TXT_RIGHT, panel);
458 snprintf(message, sizeof message, "%d / %d", objective->currentValue, objective->targetValue);
459 graphics.drawString(message, col2, y, TXT_RIGHT, panel);
464 graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
465 graphics.drawString(_("Completed"), col2, y, TXT_RIGHT, panel);
471 graphics.setFontColor(0xff, 0xff, 0x00, 0x00, 0x00, 0x00);
472 snprintf(message, sizeof message, _("Time Limit - %d:%.2d Minutes"), map.remainingMinutes, map.remainingSeconds);
473 graphics.drawString(message, 200, 260, TXT_CENTERED, panel);
476 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
477 graphics.drawString(_("Press Fire to Continue"), 200, 280, TXT_CENTERED, panel);
484 map.getRandomEntityPosition(&px, &py);
485 map.getRandomEntityPosition(&player.tx, &player.ty);
490 unsigned int frameLimit = SDL_GetTicks() + 16;
494 if ((int)player.x < player.tx) player.x += 2;
495 if ((int)player.x > player.tx) player.x -= 2;
496 if ((int)player.y < player.ty) player.y += 2;
497 if ((int)player.y > player.ty) player.y -= 2;
499 if (Collision::collision(player.x, player.y, 5, 5, player.tx, player.ty, 5, 5))
500 map.getRandomEntityPosition(&player.tx, &player.ty);
502 engine.setPlayerPosition((int)player.x, (int)player.y, map.limitLeft, map.limitRight, map.limitUp, map.limitDown);
506 graphics.blit(panelBack, 320, 220, graphics.screen, true);
507 graphics.blit(panel, 320, 220, graphics.screen, true);
509 engine.delay(frameLimit);
510 frameLimit = SDL_GetTicks() + 16;
512 if (engine.userAccepts())
516 SDL_FreeSurface(panel);
517 SDL_FreeSurface(panelBack);
519 SDL_FillRect(graphics.screen, NULL, graphics.black);
520 graphics.delay(1000);
525 game.getCheckPoint(&player.x, &player.y);
527 int beamInTime = 180;
529 unsigned int frameLimit = SDL_GetTicks() + 16;
531 audio.playSound(SND_TELEPORT1, CH_ANY);
533 engine.setPlayerPosition((int)player.x, (int)player.y, map.limitLeft, map.limitRight, map.limitUp, map.limitDown);
535 while (beamInTime > 0)
537 engine.delay(frameLimit);
538 frameLimit = SDL_GetTicks() + 16;
543 if ((beamInTime % 10) == 0)
544 addTeleportParticles(player.x + 10, player.y + 10, 50, -1);
549 game.getCheckPoint(&player.x, &player.y);
554 player.environment = ENV_AIR;
557 Math::removeBit(&player.flags, ENT_FLIES);
562 graphics.setFontSize(0);
564 SDL_FillRect(graphics.screen, NULL, graphics.black);
565 graphics.delay(1000);
567 Uint32 then, frames, frameLimit, millis;
571 Uint32 now, frameCounter;
573 strlcpy(fps, "fps", sizeof fps);
576 engine.messageTime = -1;
577 engine.messagePriority = -1;
580 audio.playAmbiance();
582 if (!game.continueFromCheckPoint)
586 if ((!map.isBossMission) && (replayData.replayMode == REPLAY_MODE::NONE))
588 showMissionInformation();
591 game.levelsStarted++;
595 game.useObjectiveCheckPoint();
598 player.setVelocity(0, 1);
599 player.baseThink = 60;
600 player.health = MAX_HEALTH;
602 if (game.continueFromCheckPoint)
604 player.health = (MAX_HEALTH / 2);
605 player.setSprites(graphics.getSprite("BobRight", true), graphics.getSprite("BobLeft", true), graphics.getSprite("BobSpin", true));
609 player.currentWeapon = &weapon[WP_PISTOL];
612 game.resetMissionOver();
614 frameLimit = SDL_GetTicks() + 16;
616 start = then = SDL_GetTicks();
618 frameCounter = SDL_GetTicks();
621 if ((strcmp(map.name, "Space Station") == 0) && (!game.continueFromCheckPoint))
633 debug(("Map Clipping is %d %d %d %d\n", map.limitLeft, map.limitRight, map.limitUp, map.limitDown));
635 game.continueFromCheckPoint = false;
637 engine.paused = false;
643 cur = SDL_GetTicks();
645 if (game.missionOverReason != MIS_PLAYEROUT)
647 engine.setPlayerPosition((int)player.x, (int)player.y, map.limitLeft, map.limitRight, map.limitUp, map.limitDown);
656 if ((player.environment == ENV_SLIME) || (player.environment == ENV_LAVA) || (player.health < 1))
658 if (player.health < 1)
660 game.setMissionOver(MIS_PLAYERDEAD);
662 audio.stopAmbiance();
666 game.setMissionOver(MIS_PLAYEROUT);
671 if (config.isControl(CONTROL::MAP))
673 if (!map.isBossMission)
675 showMap((int)(player.x / 32), (int)(player.y / 32));
679 engine.setInfoMessage("Automap is not available!", 1, INFO_HINT);
685 doMusicInfo(cur - start);
687 if ((engine.keyState[SDL_SCANCODE_ESCAPE]) && (game.missionOver == 0))
689 if (replayData.replayMode == REPLAY_MODE::NONE)
699 if (allObjectivesCompleted())
701 if (game.missionOver == 0)
703 if (map.isBossMission)
705 map.killAllEnemies();
709 audio.stopAmbiance();
711 game.setMissionOver(MIS_COMPLETE);
712 engine.setInfoMessage("All Required Objectives Met - Mission Complete", 10, INFO_OBJECTIVE);
716 if (game.missionOver > 0)
720 if (game.missionOver == 0)
722 if (game.missionOverReason == MIS_PLAYEROUT)
724 SDL_FillRect(graphics.screen, NULL, graphics.black);
725 graphics.updateScreen();
726 graphics.delay(1000);
730 game.resetMissionOver();
734 if (game.missionOverReason == MIS_COMPLETE)
736 game.missionOver = MAX_FPS * 2;
738 if (strcmp(map.name, "Space Station") != 0)
740 addTeleportParticles(player.x, player.y, 50, SND_TELEPORT3);
742 game.missionOverReason = MIS_PLAYERESCAPE;
749 else if (game.missionOverReason == MIS_GAMECOMPLETE)
751 addTeleportParticles(player.x, player.y, 50, SND_TELEPORT3);
752 game.missionOverReason = MIS_PLAYERESCAPE;
753 game.missionOver = MAX_FPS * 4;
757 if (replayData.replayMode != REPLAY_MODE::NONE)
768 Math::limitInt(&(--game.lastComboTime), 0, 60);
774 if ((game.missionOverReason == MIS_INPROGRESS) || (game.missionOverReason == MIS_PLAYEROUT))
776 game.incrementMissionTime();
791 while (engine.paused)
796 graphics.updateScreen();
797 then = SDL_GetTicks();
808 if ((engine.keyState[SDL_SCANCODE_F3]) && (engine.cheatSkipLevel))
810 autoCompleteAllObjectives(true);
811 engine.keyState[SDL_SCANCODE_F3] = 0;
812 engine.setInfoMessage("Skipping Mission...", 2, INFO_OBJECTIVE);
816 if (engine.keyState[SDL_SCANCODE_F1])
818 autoCompleteAllObjectives(false);
822 if (replayData.replayMode != REPLAY_MODE::PLAYBACK)
824 engine.delay(frameLimit);
826 else if (!replayData.fast)
828 engine.delay(frameLimit);
831 if (engine.keyState[SDL_SCANCODE_F5])
833 replayData.fast = !replayData.fast;
834 engine.keyState[SDL_SCANCODE_F5] = 0;
837 frameLimit = SDL_GetTicks() + 16;
839 if (game.missionOverReason == MIS_GAMECOMPLETE)
840 frameLimit = SDL_GetTicks() + 64;
843 static Graphics::SurfaceCache fpsCache;
844 graphics.drawString(fps, 600, 30, true, graphics.screen, fpsCache);
846 if (SDL_GetTicks() > frameCounter + 500)
848 now = SDL_GetTicks();
849 snprintf(fps, sizeof fps, "%2.2f fps", ((double)frames*1000)/(now - then));
850 then = frameCounter = SDL_GetTicks();
856 if (allObjectivesCompleted())
858 if (strcmp(map.name, "Final Battle") == 0)
860 game.missionOverReason = MIS_GAMECOMPLETE;
864 game.missionOverReason = MIS_COMPLETE;
868 switch (game.missionOverReason)
871 if (strcmp(map.name, "Space Station"))
873 graphics.delay(1000);
874 audio.loadMusic("music/grasslands");
876 graphics.fadeToBlack();
878 bool previouslyCompleted = gameData.stagePreviouslyCleared(game.stageName);
884 return SECTION_TITLE;
887 if (!previouslyCompleted)
895 graphics.fadeToBlack();
896 processPostMissionData();
898 game.setMapName("data/finalBattle");
899 game.setStageName("Final Battle");
904 case MIS_GAMECOMPLETE:
905 SDL_FillRect(graphics.screen, NULL, graphics.white);
906 graphics.updateScreen();
907 graphics.fadeToBlack();
909 // we've finished the game. Extreme mode is now available! :)
910 engine.extremeAvailable = true;
915 return SECTION_CREDITS;
919 game.canContinue = 0;
921 if (player.health > -60)
926 return SECTION_GAMEOVER;
929 case MIS_PLAYERESCAPE:
931 if (gameData.stagePreviouslyCleared(game.stageName))
933 processPostMissionData();
939 case MIS_PLAYERRESTART:
940 clearAllMissionData();
945 return SECTION_TITLE;
949 return SECTION_TITLE;