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