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