2 Copyright (C) 2004 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[SDLK_ESCAPE]))
104 engine.keyState[SDLK_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 if ((SDL_GetAppState() & SDL_APPINPUTFOCUS) == 0)
281 engine.paused = true;
284 replayData.set(config.command);
291 audio.stopAmbiance();
293 if (!engine.loadWidgets(_("data/gameOverWidgets")))
295 graphics.showErrorAndExit(ERR_FILE, _("data/gameOverWidgets"));
298 SDL_Surface *gameover = graphics.quickSprite("Game Over", graphics.loadImage("gfx/main/gameover.png"));
300 audio.loadGameOverMusic();
306 unsigned int frameLimit = SDL_GetTicks() + 16;
308 bool showGameOverOptions = false;
309 int cont, quit, menuSound;
310 cont = quit = menuSound = 0;
312 engine.setWidgetVariable("gameOverNo", &cont);
313 engine.setWidgetVariable("gameOverYes", &quit);
315 if (game.canContinue > 1)
317 Widget *widget = engine.getWidgetByName("gameOverNo");
318 sprintf(widget->label, "%s (%d)", widget->label, game.canContinue);
324 audio.playMenuSound(menuSound);
329 graphics.blit(gameover, 320, 240, graphics.screen, true);
331 if (engine.userAccepts())
333 if (!showGameOverOptions)
335 showGameOverOptions = true;
336 engine.showWidgetGroup("gameover", true);
337 engine.highlightWidget("gameOverNo");
342 // Can't continue on a boss mission or if no checkpoints reached!
343 if ((map.isBossMission) || (!game.canContinue))
345 engine.showWidgetGroup("gameover", false);
350 if (showGameOverOptions)
353 menuSound = engine.processWidgets();
356 if ((cont) || (quit))
359 engine.delay(frameLimit);
360 frameLimit = SDL_GetTicks() + 16;
366 graphics.fadeToBlack();
369 return SECTION_TITLE;
372 game.continueFromCheckPoint = true;
374 audio.reloadLevelMusic();
379 void showMissionInformation()
381 SDL_FillRect(graphics.screen, NULL, graphics.black);
382 graphics.updateScreen();
384 SDL_Surface *panel = graphics.createSurface(400, 300);
385 SDL_Surface *panelBack = graphics.alphaRect(400, 300, 0x00, 0x00, 0x00);
386 SDL_SetColorKey(panel, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(panel->format, 0, 0, 0));
388 graphics.drawRect(1, 1, 398, 298, graphics.black, graphics.white, panelBack);
395 Objective *objective;
397 graphics.setFontSize(0);
399 graphics.setFontSize(3);
400 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
401 graphics.drawString(_(game.stageName), 200, 20, TXT_CENTERED, panel);
403 graphics.setFontSize(0);
407 if (map.totalMIAs > 0)
409 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
410 sprintf(message, _("Rescue %d MIAs"), map.requiredMIAs);
411 graphics.drawString(message, col1, y, TXT_LEFT, panel);
413 if (map.foundMIAs < map.requiredMIAs)
415 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
416 sprintf(message, "%d / %d", map.foundMIAs, map.requiredMIAs);
417 graphics.drawString(message, col2, y, TXT_RIGHT, panel);
421 graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
422 graphics.drawString(_("Completed"), col2, y, TXT_RIGHT, panel);
426 objective = (Objective*)map.objectiveList.getHead();
428 while (objective->next != NULL)
430 objective = (Objective*)objective->next;
434 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
436 if ((game.skill < 3) && (strstr(objective->description, "L.R.T.S.")) && (!gameData.completedWorld))
438 graphics.drawString(_("???? ???????? ????"), col1, y, TXT_LEFT, panel);
442 graphics.drawString(_(objective->description), col1, y, TXT_LEFT, panel);
445 // this is a fake objective (for the 4th Ancient Tomb)
446 if (objective->targetValue == -1)
448 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
449 graphics.drawString(_("Incomplete"), col2, y, TXT_RIGHT, panel);
451 else if (objective->currentValue < objective->targetValue)
453 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
454 if (objective->targetValue == 1)
456 graphics.drawString(_("Incomplete"), col2, y, TXT_RIGHT, panel);
460 sprintf(message, "%d / %d", objective->currentValue, objective->targetValue);
461 graphics.drawString(message, col2, y, TXT_RIGHT, panel);
466 graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
467 graphics.drawString(_("Completed"), col2, y, TXT_RIGHT, panel);
473 graphics.setFontColor(0xff, 0xff, 0x00, 0x00, 0x00, 0x00);
474 sprintf(message, _("Time Limit - %d:%.2d Minutes"), map.remainingMinutes, map.remainingSeconds);
475 graphics.drawString(message, 200, 260, TXT_CENTERED, panel);
478 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
479 graphics.drawString(_("Press Fire to Continue"), 200, 280, TXT_CENTERED, panel);
486 map.getRandomEntityPosition(&px, &py);
487 map.getRandomEntityPosition(&player.tx, &player.ty);
492 unsigned int frameLimit = SDL_GetTicks() + 16;
496 if ((int)player.x < player.tx) player.x += 2;
497 if ((int)player.x > player.tx) player.x -= 2;
498 if ((int)player.y < player.ty) player.y += 2;
499 if ((int)player.y > player.ty) player.y -= 2;
501 if (Collision::collision(player.x, player.y, 5, 5, player.tx, player.ty, 5, 5))
502 map.getRandomEntityPosition(&player.tx, &player.ty);
504 engine.setPlayerPosition((int)player.x, (int)player.y, map.limitLeft, map.limitRight, map.limitUp, map.limitDown);
508 graphics.blit(panelBack, 320, 220, graphics.screen, true);
509 graphics.blit(panel, 320, 220, graphics.screen, true);
511 engine.delay(frameLimit);
512 frameLimit = SDL_GetTicks() + 16;
514 if (engine.userAccepts())
518 SDL_FreeSurface(panel);
519 SDL_FreeSurface(panelBack);
521 SDL_FillRect(graphics.screen, NULL, graphics.black);
522 graphics.delay(1000);
527 game.getCheckPoint(&player.x, &player.y);
529 int beamInTime = 180;
531 unsigned int frameLimit = SDL_GetTicks() + 16;
533 audio.playSound(SND_TELEPORT1, CH_ANY);
535 engine.setPlayerPosition((int)player.x, (int)player.y, map.limitLeft, map.limitRight, map.limitUp, map.limitDown);
537 while (beamInTime > 0)
539 engine.delay(frameLimit);
540 frameLimit = SDL_GetTicks() + 16;
545 if ((beamInTime % 10) == 0)
546 addTeleportParticles(player.x + 10, player.y + 10, 50, -1);
551 game.getCheckPoint(&player.x, &player.y);
556 player.environment = ENV_AIR;
559 Math::removeBit(&player.flags, ENT_FLIES);
564 graphics.setFontSize(0);
566 SDL_FillRect(graphics.screen, NULL, graphics.black);
567 graphics.delay(1000);
569 Uint32 then, frames, frameLimit, millis, frameCounter;
577 engine.messageTime = -1;
578 engine.messagePriority = -1;
581 audio.playAmbiance();
583 if (!game.continueFromCheckPoint)
587 if ((!map.isBossMission) && (replayData.replayMode == REPLAY_MODE::NONE))
589 showMissionInformation();
592 game.levelsStarted++;
596 game.useObjectiveCheckPoint();
599 player.setVelocity(0, 1);
600 player.baseThink = 60;
601 player.health = MAX_HEALTH;
603 if (game.continueFromCheckPoint)
605 player.health = (MAX_HEALTH / 2);
606 player.setSprites(graphics.getSprite("BobRight", true), graphics.getSprite("BobLeft", true), graphics.getSprite("BobSpin", true));
610 player.currentWeapon = &weapon[WP_PISTOL];
613 game.resetMissionOver();
615 frameLimit = SDL_GetTicks() + 16;
617 then = SDL_GetTicks();
618 frameCounter = SDL_GetTicks();
620 if ((strcmp(map.name, "Space Station") == 0) && (!game.continueFromCheckPoint))
632 debug(("Map Clipping is %d %d %d %d\n", map.limitLeft, map.limitRight, map.limitUp, map.limitDown));
634 game.continueFromCheckPoint = false;
636 engine.paused = false;
643 if (game.missionOverReason != MIS_PLAYEROUT)
645 engine.setPlayerPosition((int)player.x, (int)player.y, map.limitLeft, map.limitRight, map.limitUp, map.limitDown);
654 if ((player.environment == ENV_SLIME) || (player.environment == ENV_LAVA) || (player.health < 1))
656 if (player.health < 1)
658 game.setMissionOver(MIS_PLAYERDEAD);
660 audio.stopAmbiance();
664 game.setMissionOver(MIS_PLAYEROUT);
669 if (config.isControl(CONTROL::MAP))
671 if (!map.isBossMission)
673 showMap((int)(player.x / 32), (int)(player.y / 32));
677 engine.setInfoMessage("Automap is not available!", 1, INFO_HINT);
684 if ((engine.keyState[SDLK_ESCAPE]) && (game.missionOver == 0))
686 if (replayData.replayMode == REPLAY_MODE::NONE)
696 if (allObjectivesCompleted())
698 if (game.missionOver == 0)
700 if (map.isBossMission)
702 map.killAllEnemies();
706 audio.stopAmbiance();
708 game.setMissionOver(MIS_COMPLETE);
709 engine.setInfoMessage("All Required Objectives Met - Mission Complete", 10, INFO_OBJECTIVE);
713 if (game.missionOver > 0)
717 if (game.missionOver == 0)
719 if (game.missionOverReason == MIS_PLAYEROUT)
721 SDL_FillRect(graphics.screen, NULL, graphics.black);
722 graphics.updateScreen();
723 graphics.delay(1000);
727 game.resetMissionOver();
731 if (game.missionOverReason == MIS_COMPLETE)
733 game.missionOver = MAX_FPS * 2;
735 if (strcmp(map.name, "Space Station") != 0)
737 addTeleportParticles(player.x, player.y, 50, SND_TELEPORT3);
739 game.missionOverReason = MIS_PLAYERESCAPE;
746 else if (game.missionOverReason == MIS_GAMECOMPLETE)
748 addTeleportParticles(player.x, player.y, 50, SND_TELEPORT3);
749 game.missionOverReason = MIS_PLAYERESCAPE;
750 game.missionOver = MAX_FPS * 4;
754 if (replayData.replayMode != REPLAY_MODE::NONE)
765 Math::limitInt(&(--game.lastComboTime), 0, 60);
771 if ((game.missionOverReason == MIS_INPROGRESS) || (game.missionOverReason == MIS_PLAYEROUT))
773 game.incrementMissionTime();
788 while (engine.paused)
793 graphics.updateScreen();
794 then = SDL_GetTicks();
805 if ((engine.keyState[SDLK_F3]) && (engine.cheatSkipLevel))
807 autoCompleteAllObjectives(true);
808 engine.setInfoMessage("Skipping Mission...", 2, INFO_OBJECTIVE);
812 if (engine.keyState[SDLK_F1])
814 autoCompleteAllObjectives(false);
818 if (replayData.replayMode != REPLAY_MODE::PLAYBACK)
820 engine.delay(frameLimit);
822 else if (!replayData.fast)
824 engine.delay(frameLimit);
827 if (engine.keyState[SDLK_F5])
829 replayData.fast = !replayData.fast;
830 engine.keyState[SDLK_F5] = 0;
833 frameLimit = SDL_GetTicks() + 16;
835 if (game.missionOverReason == MIS_GAMECOMPLETE)
836 frameLimit = SDL_GetTicks() + 64;
839 graphics.drawString(fps, 600, 30, true, graphics.screen);
841 if (SDL_GetTicks() > frameCounter + 500)
843 now = SDL_GetTicks();
844 sprintf(fps, "%2.2f fps", ((double)frames*1000)/(now - then));
845 then = frameCounter = SDL_GetTicks();
851 if (allObjectivesCompleted())
853 if (strcmp(map.name, "Final Battle") == 0)
855 game.missionOverReason = MIS_GAMECOMPLETE;
859 game.missionOverReason = MIS_COMPLETE;
863 switch (game.missionOverReason)
866 if (strcmp(map.name, "Space Station"))
868 graphics.delay(1000);
869 audio.loadMusic("music/commando.xm");
871 graphics.fadeToBlack();
873 bool previouslyCompleted = gameData.stagePreviouslyCleared(game.stageName);
879 return SECTION_TITLE;
882 if (!previouslyCompleted)
890 graphics.fadeToBlack();
891 processPostMissionData();
893 game.setMapName("data/finalBattle");
894 game.setStageName("Final Battle");
899 case MIS_GAMECOMPLETE:
900 SDL_FillRect(graphics.screen, NULL, graphics.white);
901 graphics.updateScreen();
902 graphics.fadeToBlack();
904 // we've finished the game. Extreme mode is now available! :)
905 engine.extremeAvailable = true;
910 return SECTION_CREDITS;
914 game.canContinue = 0;
916 if (player.health > -60)
921 return SECTION_GAMEOVER;
924 case MIS_PLAYERESCAPE:
926 if (gameData.stagePreviouslyCleared(game.stageName))
928 processPostMissionData();
934 case MIS_PLAYERRESTART:
935 clearAllMissionData();
940 return SECTION_TITLE;
944 return SECTION_TITLE;