Removed that logo from this bramch aswell..
[dbw.git] / src / mission.cpp
blobc7d3591dc69a91d6eb3d7b3e1f635d16af5214d6
1 /*
2 Copyright © 2004 Parallel Realities
3 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "CAudio.h"
23 #include "CGame.h"
24 #include "CGameData.h"
25 #include "CGraphics.h"
26 #include "CMap.h"
27 #include "CMath.h"
28 #include "CObjective.h"
29 #include "gettext.hpp"
30 #include "mission.h"
32 // This is for easy mode
33 void skipBossMission()
35 if (game.stagesCleared == 5)
37 gameData.addCompletedObjective("BioMech Supply Depot", "Easy Mode Skip", 1, 1);
38 game.stagesCleared = 6;
41 if (game.stagesCleared == 10)
43 gameData.addCompletedObjective("BioMech Communications", "Easy Mode Skip", 1, 1);
44 game.hasAquaLung = true;
45 game.stagesCleared = 11;
46 SDL_FillRect(graphics.screen, NULL, graphics.black);
47 graphics.delay(250);
48 graphics.drawString(_("You got the Aqua Lung!"), bx+320, by+420, TXT_CENTERED, graphics.screen);
49 graphics.delay(2000);
50 SDL_FillRect(graphics.screen, NULL, graphics.black);
53 if (game.stagesCleared == 15)
55 gameData.addCompletedObjective("BioMech Assimilator", "Easy Mode Skip", 1, 1);
56 game.hasJetPack = true;
57 game.stagesCleared = 16;
58 SDL_FillRect(graphics.screen, NULL, graphics.black);
59 graphics.delay(250);
60 graphics.drawString(_("You got the Jet Pack!"), bx+320, by+420, TXT_CENTERED, graphics.screen);
61 graphics.delay(2000);
62 SDL_FillRect(graphics.screen, NULL, graphics.black);
65 if (game.stagesCleared == 21)
67 gameData.addCompletedObjective("BioMech HQ", "Easy Mode Skip", 1, 1);
68 game.stagesCleared = 22;
72 void processPostMissionData()
74 char string[1024];
76 if (!gameData.stagePreviouslyCleared(game.stageName))
78 game.stagesCleared++;
81 if (game.skill == 0)
83 skipBossMission();
86 gameData.setMIARescueCount(map.name, map.foundMIAs, map.totalMIAs);
88 Objective *objective = (Objective*)map.objectiveList.getHead();
89 Entity *mia = (Entity*)map.miaList.getHead();
91 while (objective->next != NULL)
93 objective = (Objective*)objective->next;
95 gameData.addCompletedObjective(map.name, objective->description, objective->currentValue, objective->targetValue);
98 bool miaFound;
100 while (mia->next != NULL)
102 mia = (Entity*)mia->next;
104 miaFound = true;
106 if (mia->health > 0)
107 miaFound = false;
109 sprintf(string, "MIA_%s", mia->name);
111 if (miaFound)
113 gameData.addCompletedObjective(map.name, string, 1, 1);
115 else
117 gameData.addCompletedObjective(map.name, string, 0, 1);
121 game.totalUpStats();
124 void clearAllMissionData()
126 char levelMIAKey[100];
128 sprintf(levelMIAKey, "%s MIAs", game.stageName);
130 Data *data = (Data*)gameData.dataList.getHead();
131 Data *previous = data;
133 while (data->next != NULL)
135 data = (Data*)data->next;
137 if ((strcmp(data->key, game.stageName) == 0) || (strstr(data->key, levelMIAKey)))
139 gameData.dataList.remove(previous, data);
140 data = previous;
142 else
144 previous = data;
148 map.destroyPersistant(map.name);
151 void showMissionClear()
153 int colCount = 7;
154 bool perfect = perfectlyCompleted();
156 SDL_Surface *clear;
158 (perfect) ? clear = graphics.loadImage("gfx/main/areaPerfect.png") : clear = graphics.loadImage("gfx/main/areaClear.png");
160 graphics.loadBackground("gfx/main/areaClearBackGround.jpg", false);
162 SDL_Surface *panel = graphics.alphaRect(550, 420, 0x00, 0x00, 0x00);
163 SDL_SetAlpha(panel, SDL_SRCALPHA|SDL_RLEACCEL, 180);
164 graphics.drawRect(1, 1, panel->w - 2, panel->h - 2 , graphics.black, graphics.white, panel);
166 graphics.blit(panel, (640 - panel->w) / 2, (480 - panel->h) / 2, graphics.background, false);
168 audio.loadSound(0, "sound/pop1.wav");
169 audio.loadSound(1, "sound/cheer.wav");
171 SDL_FillRect(graphics.screen, NULL, graphics.black);
172 graphics.updateScreen();
174 int y = 520;
175 int miaY = 335;
176 int clearY = 520;
177 Objective *objective = (Objective*)map.objectiveList.getHead();
178 Entity *mia = (Entity*)map.miaList.getHead();
179 Sprite *teleportStar = graphics.getSprite("TeleportStar", true);
180 char message[100];
181 int col1 = 360;
182 int col2 = 380;
183 int count = 0;
184 int place = 0;
185 int nextStarBurst = 10 * (rand() % 6);
187 float px, py, dx, dy;
190 while (mia->next != NULL)
192 mia = (Entity*)mia->next;
194 if (mia->health > 0)
195 continue;
197 mia->x = 700;
199 mia->y = miaY;
201 count++;
203 if (count > colCount)
205 miaY += 25;
206 count = 0;
209 place += 25;
212 if (count > colCount)
213 count = colCount;
215 if (place > (colCount * 25))
216 place = colCount * 25;
218 place = (640 - place) / 2;
220 graphics.setFontSize(1);
222 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
224 engine.flushInput();
225 engine.clearInput();
227 y = 130;
229 if (map.totalMIAs > 0)
231 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
232 sprintf(message, "%s", _("Rescue %d MIAs").c_str());
233 sprintf(message, message, map.requiredMIAs);
234 graphics.drawString(message, col1, y, TXT_RIGHT, graphics.background);
236 if (map.foundMIAs < map.requiredMIAs)
238 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
239 sprintf(message, "%d / %d", map.foundMIAs, map.requiredMIAs);
240 graphics.drawString(message, col2, y, TXT_LEFT, graphics.background);
242 else
244 graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
245 graphics.drawString(_("Completed"), col2, y, TXT_LEFT, graphics.background);
249 objective = (Objective*)map.objectiveList.getHead();
251 //engine.setPlayerPosition(0, 0, -1, -1, -1, -1);
252 map.offsetX = - bx; map.offsetY = - by;
254 while (objective->next != NULL)
256 objective = (Objective*)objective->next;
258 y += 20;
260 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
262 if ((game.skill < 3) && (strstr(objective->description, "L.R.T.S.")) && (!gameData.completedWorld))
264 graphics.drawString("???? ???????? ????", col1, y, TXT_RIGHT, graphics.background);
266 else
268 graphics.drawString(_(objective->description), col1, y, TXT_RIGHT, graphics.background);
271 if (objective->currentValue < objective->targetValue)
273 if (objective->targetValue == 1)
275 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
276 graphics.drawString(_("Incomplete"), col2, y, TXT_LEFT, graphics.background);
278 else
280 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
281 sprintf(message, "%d / %d", objective->currentValue, objective->targetValue);
282 graphics.drawString(message, col2, y, TXT_LEFT, graphics.background);
285 else
287 graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
288 graphics.drawString(_("Completed"), col2, y, TXT_LEFT, graphics.background);
292 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
294 unsigned int frameLimit = SDL_GetTicks() + 16;
296 if (perfect)
297 audio.playSound(1, 1);
299 while (true)
301 engine.getInput();
302 graphics.updateScreen();
303 graphics.animateSprites();
305 if (engine.userAccepts())
306 break;
308 graphics.drawBackground();
310 graphics.blit(clear, bx + 320, by + clearY, graphics.screen, true);
312 Math::limitInt(&(clearY -= 5), 70, 520);
314 count = 0;
316 mia = (Entity*)map.miaList.getHead();
318 if (clearY == 70)
320 while (mia->next != NULL)
322 mia = (Entity*)mia->next;
324 if (mia->health > 0)
325 continue;
327 if (count > colCount)
328 count = 0;
330 graphics.blit(mia->getFaceImage(), bx + (int)mia->x, by + (int)mia->y, graphics.screen, false);
332 if (mia->x == 700)
333 audio.playSound(0, 0);
335 if (mia->x > (place + (count * 25)))
336 Math::limitFloat(&(mia->x -= 35), place + (count * 25), 640);
338 if (mia->x > place + (count * 25))
339 break;
341 count++;
344 if (perfect)
346 Math::limitInt(&(--nextStarBurst), 0, 999);
348 if (nextStarBurst == 0)
350 nextStarBurst = 10 * (rand() % 6);
352 px = Math::rrand(50, 585);
353 py = Math::rrand(55, 85);
355 for (int i = 0 ; i < 50 ; i++)
357 dx = Math::rrand(-30, 30); dx /= 20;
358 dy = Math::rrand(-30, 30); dy /= 20;
359 map.addParticle(px, py, dx, dy, Math::rrand(30, 60), graphics.red, teleportStar, PAR_WEIGHTLESS);
363 doParticles();
367 sprintf(message, "%s - %.2d:%.2d:%.2d", _("Mission Time").c_str(), game.currentMissionHours, game.currentMissionMinutes, game.currentMissionSeconds);
368 graphics.drawString(message, bx + 320, by + 420, true, graphics.screen);
370 while (SDL_GetTicks() < frameLimit){}
371 frameLimit = SDL_GetTicks() + 16;
374 audio.stopMusic();
376 #if !DEMO
377 processPostMissionData();
379 if (!engine.practice)
381 saveGame();
383 #endif