]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/mission.cpp
Don't define variables in header files.
[quix0rs-blobwars.git] / src / mission.cpp
1 /*
2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
4
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.
9
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.
13
14 See the GNU General Public License for more details.
15
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.
19
20 */
21
22 #include "mission.h"
23
24 // This is for easy mode
25 void skipBossMission()
26 {
27         if (game.stagesCleared == 5)
28         {
29                 gameData.addCompletedObjective("BioMech Supply Depot", "Easy Mode Skip", 1, 1);
30                 game.stagesCleared = 6;
31         }
32         
33         if (game.stagesCleared == 10)
34         {
35                 gameData.addCompletedObjective("BioMech Communications", "Easy Mode Skip", 1, 1);
36                 game.hasAquaLung = true;
37                 game.stagesCleared = 11;
38                 SDL_FillRect(graphics.screen, NULL, graphics.black);
39                 graphics.delay(250);
40                 graphics.drawString(_("You got the Aqua Lung!"), 320, 420, TXT_CENTERED, graphics.screen);
41                 graphics.delay(2000);
42                 SDL_FillRect(graphics.screen, NULL, graphics.black);
43         }
44         
45         if (game.stagesCleared == 15)
46         {
47                 gameData.addCompletedObjective("BioMech Assimilator", "Easy Mode Skip", 1, 1);
48                 game.hasJetPack = true;
49                 game.stagesCleared = 16;
50                 SDL_FillRect(graphics.screen, NULL, graphics.black);
51                 graphics.delay(250);
52                 graphics.drawString(_("You got the Jet Pack!"), 320, 420, TXT_CENTERED, graphics.screen);
53                 graphics.delay(2000);
54                 SDL_FillRect(graphics.screen, NULL, graphics.black);
55         }
56         
57         if (game.stagesCleared == 21)
58         {
59                 gameData.addCompletedObjective("BioMech HQ", "Easy Mode Skip", 1, 1);
60                 game.stagesCleared = 22;
61         }
62 }
63
64 void processPostMissionData()
65 {
66         char string[1024];
67         
68         if (!gameData.stagePreviouslyCleared(game.stageName))
69         {
70                 presentPlayerMedal(game.stageName);
71                 game.stagesCleared++;
72         }
73         
74         if (game.skill == 0)
75         {
76                 skipBossMission();
77         }
78         
79         gameData.setMIARescueCount(map.name, map.foundMIAs, map.totalMIAs);
80
81         Objective *objective = (Objective*)map.objectiveList.getHead();
82         Entity *mia = (Entity*)map.miaList.getHead();
83
84         while (objective->next != NULL)
85         {
86                 objective = (Objective*)objective->next;
87                 
88                 gameData.addCompletedObjective(map.name, objective->description, objective->currentValue, objective->targetValue);
89         }
90
91         bool miaFound;
92
93         while (mia->next != NULL)
94         {
95                 mia = (Entity*)mia->next;
96
97                 miaFound = true;
98
99                 if (mia->health > 0)
100                         miaFound = false;
101
102                 snprintf(string, sizeof string, "MIA_%s", mia->name);
103                 
104                 if (miaFound)
105                 {
106                         gameData.addCompletedObjective(map.name, string, 1, 1);
107                 }
108                 else
109                 {
110                         gameData.addCompletedObjective(map.name, string, 0, 1);
111                 }
112         }
113
114         game.totalUpStats();
115         
116         if (game.totalEnemiesDefeated >= 1000)
117         {
118                 presentPlayerMedal("1000_Enemies");
119         }
120         
121         if (game.totalEnemiesDefeated >= 2500)
122         {
123                 presentPlayerMedal("2500_Enemies");
124         }
125 }
126
127 void clearAllMissionData()
128 {
129         char levelMIAKey[100];
130         
131         snprintf(levelMIAKey, sizeof levelMIAKey, "%s MIAs", game.stageName);
132         
133         Data *data = (Data*)gameData.dataList.getHead();
134         Data *previous = data;
135         
136         while (data->next != NULL)
137         {
138                 data = (Data*)data->next;
139                 
140                 if ((strcmp(data->key, game.stageName) == 0) || (strstr(data->key, levelMIAKey)))
141                 {
142                         gameData.dataList.remove(previous, data);
143                         data = previous;
144                 }
145                 else
146                 {
147                         previous = data;
148                 }
149         }
150         
151         map.destroyPersistant(map.name);
152 }
153
154 void showMissionClear()
155 {
156         int colCount = 7;
157         bool perfect = perfectlyCompleted();
158
159         SDL_Surface *clear;
160
161         (perfect) ? clear = graphics.loadImage("gfx/main/areaPerfect.png") : clear = graphics.loadImage("gfx/main/areaClear.png");
162
163         graphics.loadBackground("gfx/main/areaClearBackGround.jpg");
164
165         SDL_Surface *panel = graphics.alphaRect(550, 420, 0x00, 0x00, 0x00);
166         SDL_SetAlpha(panel, 180);
167         graphics.drawRect(1, 1, panel->w - 2, panel->h - 2 , graphics.black, graphics.white, panel);
168
169         graphics.blit(panel, (640 - panel->w) / 2, (480 - panel->h) / 2, graphics.background, false);
170
171         audio.loadSound(0, "sound/pop1");
172         audio.loadSound(1, "sound/cheer");
173
174         SDL_FillRect(graphics.screen, NULL, graphics.black);
175         graphics.updateScreen();
176
177         int y = 520;
178         int miaY = 335;
179         int clearY = 520;
180         Objective *objective = (Objective*)map.objectiveList.getHead();
181         Entity *mia = (Entity*)map.miaList.getHead();
182         Sprite *teleportStar = graphics.getSprite("TeleportStar", true);
183         char message[256];
184         int col1 = 360;
185         int col2 = 380;
186         int count = 0;
187         int place = 0;
188         int nextStarBurst = 10 * (Math::prand() % 6);
189
190         float px, py, dx, dy;
191
192
193         while (mia->next != NULL)
194         {
195                 mia = (Entity*)mia->next;
196
197                 if (mia->health > 0)
198                         continue;
199
200                 mia->x = 700;
201                 
202                 mia->y = miaY;
203                 
204                 count++;
205
206                 if (count > colCount)
207                 {
208                         miaY += 25;
209                         count = 0;
210                 }
211
212                 place += 25;
213         }
214
215         if (count > colCount)
216                 count = colCount;
217
218         if (place > (colCount * 25))
219                 place = colCount * 25;
220
221         place = (640 - place) / 2;
222
223         graphics.setFontSize(1);
224
225         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
226
227         engine.flushInput();
228         engine.clearInput();
229
230         y = 130;
231         
232         if (map.totalMIAs > 0)
233         {
234                 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
235                 snprintf(message, sizeof message, _("Rescue %d MIAs"), map.requiredMIAs);
236                 graphics.drawString(message, col1, y, TXT_RIGHT, graphics.background);
237
238                 if (map.foundMIAs < map.requiredMIAs)
239                 {
240                         graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
241                         snprintf(message, sizeof message, "%d / %d", map.foundMIAs, map.requiredMIAs);
242                         graphics.drawString(message, col2, y, TXT_LEFT, graphics.background);
243                 }
244                 else
245                 {
246                         graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
247                         graphics.drawString(_("Completed"), col2, y, TXT_LEFT, graphics.background);
248                 }
249         }
250
251         objective = (Objective*)map.objectiveList.getHead();
252
253         engine.setPlayerPosition(0, 0, -1, -1, -1, -1);
254
255         while (objective->next != NULL)
256         {
257                 objective = (Objective*)objective->next;
258
259                 y += 20;
260
261                 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
262                 
263                 if ((game.skill < 3) &&  (strstr(objective->description, "L.R.T.S.")) && (!gameData.completedWorld))
264                 {
265                         graphics.drawString(_("???? ???????? ????"), col1, y, TXT_RIGHT, graphics.background);
266                 }
267                 else
268                 {
269                         graphics.drawString(_(objective->description), col1, y, TXT_RIGHT, graphics.background);
270                 }
271
272                 if (objective->currentValue < objective->targetValue)
273                 {
274                         if (objective->targetValue == 1)
275                         {
276                                 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
277                                 graphics.drawString(_("Incomplete"), col2, y, TXT_LEFT, graphics.background);
278                         }
279                         else
280                         {
281                                 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
282                                 snprintf(message, sizeof message, "%d / %d", objective->currentValue, objective->targetValue);
283                                 graphics.drawString(message, col2, y, TXT_LEFT, graphics.background);
284                         }
285                 }
286                 else
287                 {
288                         graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
289                         graphics.drawString(_("Completed"), col2, y, TXT_LEFT, graphics.background);
290                 }
291         }
292         
293         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
294
295         unsigned int frameLimit = SDL_GetTicks() + 16;
296
297         if (perfect)
298                 audio.playSound(1, 1);
299
300         while (true)
301         {
302                 engine.getInput();
303                 config.populate();
304                 graphics.updateScreen();
305                 graphics.animateSprites();
306
307                 if (engine.userAccepts())
308                         break;
309
310                 graphics.drawBackground();
311
312                 graphics.blit(clear, 320, clearY, graphics.screen, true);
313
314                 Math::limitInt(&(clearY -= 5), 70, 520);
315
316                 count = 0;
317
318                 mia = (Entity*)map.miaList.getHead();
319
320                 if (clearY == 70)
321                 {
322                         while (mia->next != NULL)
323                         {
324                                 mia = (Entity*)mia->next;
325
326                                 if (mia->health > 0)
327                                         continue;
328
329                                 if (count > colCount)
330                                         count = 0;
331
332                                 graphics.blit(mia->getFaceImage(), (int)mia->x, (int)mia->y, graphics.screen, false);
333
334                                 if (mia->x == 700)
335                                         audio.playSound(0, 0);
336
337                                 if (mia->x > (place + (count * 25)))
338                                         Math::limitFloat(&(mia->x -= 35), place + (count * 25), 640);
339
340                                 if (mia->x > place + (count * 25))
341                                         break;
342
343                                 count++;
344                         }
345                         
346                         if (perfect)
347                         {
348                                 Math::limitInt(&(--nextStarBurst), 0, 999);
349
350                                 if (nextStarBurst == 0)
351                                 {
352                                         nextStarBurst = 10 * (Math::prand() % 6);
353
354                                         px = Math::rrand(50, 585);
355                                         py = Math::rrand(55, 85);
356
357                                         for (int i = 0 ; i < 50 ; i++)
358                                         {
359                                                 dx = Math::rrand(-30, 30); dx /= 20;
360                                                 dy = Math::rrand(-30, 30); dy /= 20;
361                                                 map.addParticle(px, py, dx, dy, Math::rrand(30, 60), graphics.red, teleportStar, PAR_WEIGHTLESS);
362                                         }
363                                 }
364
365                                 doParticles();
366                         }
367                 }
368
369                 static Graphics::SurfaceCache cache;
370                 snprintf(message, sizeof message, "%s - %.2d:%.2d:%.2d", _("Mission Time"), game.currentMissionHours, game.currentMissionMinutes, game.currentMissionSeconds);
371                 graphics.drawString(message, 320, 420, true, graphics.screen, cache);
372
373                 engine.delay(frameLimit);
374                 frameLimit = SDL_GetTicks() + 16;
375         }
376
377         audio.stopMusic();
378
379         processPostMissionData();
380
381         if (!engine.practice)
382         {
383                 saveGame();
384         }
385 }
386