]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/info.cpp
Fix color key and alpha blending.
[quix0rs-blobwars.git] / src / info.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 "info.h"
22
23 void doTimeRemaining()
24 {               
25         map.remainingSeconds--;
26         
27         if ((map.remainingMinutes == 0) && (map.remainingSeconds <= 10) && (map.remainingSeconds > 0))
28         {
29                 audio.playSound(SND_CLOCK, CH_TOUCH);
30         }
31         
32         if (map.remainingSeconds < 0)
33         {
34                 if (map.remainingMinutes > 0)
35                 {
36                         map.remainingSeconds = 59;
37                         map.remainingMinutes--;
38                 }
39         }
40         
41         if ((map.remainingSeconds == 0) && (map.remainingMinutes == 0))
42         {
43                 player.health = 0;
44                 player.immune = 0;
45                 Math::removeBit(&player.flags, ENT_FLIES);
46                 game.setMissionOver(MIS_TIMEUP);
47         }
48         
49         replayData.header.time++;
50 }
51
52 void doStatusBar()
53 {
54         static Graphics::SurfaceCache healthCache;
55         static Graphics::SurfaceCache oxygenCache;
56         static Graphics::SurfaceCache jetpackCache;
57
58         graphics.setFontSize(0);
59         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
60
61         char string[1024];
62
63         graphics.blit(graphics.infoBar, 0, 0, graphics.screen, false);
64
65         graphics.drawString(_("Health"), 50, 5, TXT_RIGHT, graphics.screen, healthCache);
66
67         for (int i = 0 ; i < MAX_HEALTH ; i++)
68         {
69                 if (i < player.health)
70                         graphics.blit(graphics.getSprite("HealthBlock", true)->getCurrentFrame(), 60 + (i * 15), 7, graphics.screen, false);
71                 else
72                         graphics.blit(graphics.getSprite("HealthBlockEmpty", true)->getCurrentFrame(), 60 + (i * 15), 7, graphics.screen, false);
73         }
74
75         if (player.health <= 3)
76                 if (engine.getFrameLoop() < 30)
77                         for (int i = 0 ; i < player.health ; i++)
78                                 graphics.blit(graphics.getSprite("WarningBlock", true)->getCurrentFrame(), 60 + (i * 15), 7, graphics.screen, false);
79
80         if ((!game.hasAquaLung) && (!engine.cheatExtras))
81         {
82                 graphics.drawString(_("Oxygen"), 305, 5, TXT_RIGHT, graphics.screen, oxygenCache);
83
84                 for (int i = 0 ; i < 7 ; i++)
85                 {
86                         if (i < player.oxygen)
87                                 graphics.blit(graphics.getSprite("OxygenBlock", true)->getCurrentFrame(), 315 + (i * 15), 7, graphics.screen, false);
88                         else
89                                 graphics.blit(graphics.getSprite("OxygenBlockEmpty", true)->getCurrentFrame(), 315 + (i * 15), 7, graphics.screen, false);
90                 }
91
92                 if (player.oxygen <= 3)
93                         if (engine.getFrameLoop() < 30)
94                                 for (int i = 0 ; i < player.oxygen ; i++)
95                                         graphics.blit(graphics.getSprite("WarningBlock", true)->getCurrentFrame(), 315 + (i * 15), 7, graphics.screen, false);
96         }
97         else if ((game.hasJetPack) || (engine.cheatExtras))
98         {
99                 graphics.drawString(_("Jetpack"), 305, 5, TXT_RIGHT, graphics.screen, jetpackCache);
100
101                 for (int i = 0 ; i < 7 ; i++)
102                 {
103                         if (i < player.fuel)
104                                 graphics.blit(graphics.getSprite("OxygenBlock", true)->getCurrentFrame(), 315 + (i * 15), 7, graphics.screen, false);
105                         else
106                                 graphics.blit(graphics.getSprite("OxygenBlockEmpty", true)->getCurrentFrame(), 315 + (i * 15), 7, graphics.screen, false);
107                 }
108
109                 if ((player.fuel < 3) && (!(player.flags & ENT_FLIES)))
110                         if (engine.getFrameLoop() < 30)
111                                 for (int i = 0 ; i < player.fuel ; i++)
112                                         graphics.blit(graphics.getSprite("WarningBlock", true)->getCurrentFrame(), 315 + (i * 15), 7, graphics.screen, false);
113         }
114
115         if ((map.mainBossPart == NULL || strstr(engine.message, "Aqua") || strstr(engine.message, "Jet")) && (game.missionOverReason != MIS_GAMECOMPLETE))
116         {
117                 if (engine.messageTime > -1)
118                 {
119                         switch (engine.messageType)
120                         {
121                                 case INFO_NORMAL:
122                                         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
123                                         break;
124                                 case INFO_OBJECTIVE:
125                                         graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
126                                         break;
127                                 case INFO_HINT:
128                                         graphics.setFontColor(0xff, 0xaa, 0x00, 0x00, 0x00, 0x00);
129                                         break;
130                                 case INFO_ACTIVATE:
131                                         graphics.setFontColor(0x00, 0xff, 0xff, 0x00, 0x00, 0x00);
132                                         break;
133                                 case INFO_BAD:
134                                         graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
135                                         break;
136                         }
137         
138                         static Graphics::SurfaceCache cache;
139                         graphics.blit(graphics.infoBar, 0, 455, graphics.screen, false);
140                         graphics.drawString(_(engine.message), 320, 466, true, graphics.screen, cache);
141                         
142                         engine.messageTime--;
143                         if (engine.messageTime == -1)
144                         {
145                                 engine.messagePriority = -1;
146                                 engine.message[0] = 0;
147                         }
148         
149                         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
150                 }
151         }
152         else
153         {
154                 if (map.mainBossPart != NULL)
155                 {
156                         graphics.blit(graphics.infoBar, 0, 455, graphics.screen, false);
157                         
158                         static Graphics::SurfaceCache cache;
159                         graphics.drawString(_(map.mainBossPart->name), 255, 460, TXT_RIGHT, graphics.screen, cache);
160                         graphics.drawRect(265 - 1, 463 - 1, 200 + 2, 10 + 2, graphics.white, graphics.screen);
161                         graphics.drawRect(265, 463, 200, 10, graphics.black, graphics.screen);
162                         
163                         if (map.mainBossPart->health > 0)
164                         {
165                                 graphics.drawRect(265, 463, (int)(map.mainBossPart->health * map.bossEnergyMeterBit), 10, graphics.red, graphics.screen);
166                         }
167                 }
168         }
169
170         static Graphics::SurfaceCache weaponCache;
171         snprintf(string, sizeof string, "%s %s", _("Weapon:"), _(player.currentWeapon->name));
172         graphics.drawString(string, 630, 5, TXT_RIGHT, graphics.screen, weaponCache);
173         
174         if (game.skill == 3)
175         {
176                 snprintf(string, sizeof string, _("Time Remaining: %.2d:%.2d"), map.remainingMinutes, map.remainingSeconds);
177                 graphics.blit(graphics.infoBar, 0, 25, graphics.screen, false);
178                 
179                 if ((map.remainingMinutes > 0) || (map.remainingSeconds > 0))
180                 {
181                         if (map.remainingMinutes == 0)
182                         {
183                                 if (map.remainingSeconds > 0)
184                                 {
185                                         if (map.remainingSeconds <= 10)
186                                         {
187                                                 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
188                                         }
189                                         else if (map.remainingSeconds <= 30)
190                                         {
191                                                 graphics.setFontColor(0xff, 0xff, 0x00, 0x00, 0x00, 0x00);
192                                         }
193                                 }
194                         }
195                         static Graphics::SurfaceCache cache;
196                         graphics.drawString(string, 320, 35, TXT_CENTERED, graphics.screen, cache);
197                 }
198                 else
199                 {
200                         static Graphics::SurfaceCache cache;
201                         graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
202                         graphics.setFontSize(3);
203                         graphics.drawString(_("Mission Failed! Time Up!"), 320, 220, TXT_CENTERED, graphics.screen, cache);
204                         graphics.setFontSize(0);
205                         game.canContinue = 0;
206                 }
207         }
208 }
209
210 void doPauseInfo()
211 {
212         int col1, col2, y;
213
214         col1 = 310;
215         col2 = 330;
216         y = 60;
217
218         graphics.fade(130);
219
220         char string[1024];
221         string[0] = 0;
222         
223         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
224
225         #if DEBUG
226         snprintf(string, sizeof string, _("Position = %d:%d"), (int)player.x, (int)player.y);
227         graphics.drawString(string, 5, 25, false, graphics.screen);
228         #endif
229
230         graphics.drawString(_("*** PAUSED ***"), 320, y, TXT_CENTERED, graphics.screen);
231
232         graphics.drawString(_("MIAs in Area"), col1, y += 30, TXT_RIGHT, graphics.screen);
233         snprintf(string, sizeof string, "%d", map.totalMIAs - map.foundMIAs);
234         graphics.drawString(string, col2, y, TXT_LEFT, graphics.screen);
235
236         graphics.drawString(_("Enemies Defeated"), col1, y += 20, TXT_RIGHT, graphics.screen);
237         snprintf(string, sizeof string, "%d", game.currentMissionEnemiesDefeated);
238         graphics.drawString(string, col2, y, TXT_LEFT, graphics.screen);
239
240         graphics.drawString(_("Items Collected"), col1, y += 20, TXT_RIGHT, graphics.screen);
241         snprintf(string, sizeof string, "%d / %d", map.foundItems, map.totalItems);
242         graphics.drawString(string, col2, y, TXT_LEFT, graphics.screen);
243
244         graphics.drawString(_("Best Combo"), col1, y += 20, TXT_RIGHT, graphics.screen);
245         snprintf(string, sizeof string, _("%d Hits"), game.maxComboHits);
246         graphics.drawString(string, col2, y, TXT_LEFT, graphics.screen);
247
248         graphics.drawString(_("++ Inventory ++"), 320, y += 40, TXT_CENTERED, graphics.screen);
249         showCarriedItems();
250
251         // Do the objectives list
252         Objective *objective = (Objective*)map.objectiveList.getHead();
253         char message[256];
254
255         y += 60;
256
257         if (map.totalMIAs > 0)
258         {
259                 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
260                 snprintf(message, sizeof message, _("Rescue %d MIAs"), map.requiredMIAs);
261                 graphics.drawString(message, col1, y, TXT_RIGHT, graphics.screen);
262
263                 if (map.foundMIAs < map.requiredMIAs)
264                 {
265                         graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
266                         snprintf(message, sizeof message, "%d / %d", map.foundMIAs, map.requiredMIAs);
267                         graphics.drawString(message, col2, y, TXT_LEFT, graphics.screen);
268                 }
269                 else
270                 {
271                         graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
272                         graphics.drawString(_("Completed"), col2, y, TXT_LEFT, graphics.screen);
273                 }
274         }
275
276         while (objective->next != NULL)
277         {
278                 objective = (Objective*)objective->next;
279
280                 y += 20;
281                 
282                 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
283                 
284                 if ((game.skill < 3) &&  (strstr(objective->description, "L.R.T.S.")) && (!gameData.completedWorld))
285                 {
286                         graphics.drawString(_("???? ???????? ????"), col1, y, TXT_RIGHT, graphics.screen);
287                 }
288                 else
289                 {
290                         graphics.drawString(_(objective->description), col1, y, TXT_RIGHT, graphics.screen);
291                 }
292                 
293                 // this is a fake objective (for the 4th Ancient Tomb)
294                 if (objective->targetValue == -1)
295                 {
296                         graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
297                         graphics.drawString(_("Incomplete"), col2, y, TXT_LEFT, graphics.screen);
298                 }
299                 else if (objective->currentValue < objective->targetValue)
300                 {
301                         graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
302                         if (objective->targetValue == 1)
303                         {
304                                 graphics.drawString(_("Incomplete"), col2, y, TXT_LEFT, graphics.screen);
305                         }
306                         else
307                         {
308                                 snprintf(message, sizeof message, "%d / %d", objective->currentValue, objective->targetValue);
309                         graphics.drawString(message, col2, y, TXT_LEFT, graphics.screen);
310                         }
311
312                         if (!objective->required)
313                         {
314                                 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
315                                 graphics.drawString(_("(optional)"), 450, y, TXT_LEFT, graphics.screen);
316                         }
317                 }
318                 else
319                 {
320                         graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
321                         graphics.drawString(_("Completed"), col2, y, TXT_LEFT, graphics.screen);
322                 }
323         }
324
325         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
326
327         y += 10;
328
329         snprintf(string, sizeof string, "%s - %.2d:%.2d:%.2d", _("Mission Time"), game.currentMissionHours, game.currentMissionMinutes, game.currentMissionSeconds);
330         graphics.drawString(string, 320, 430, TXT_CENTERED, graphics.screen);
331 }
332
333 void doMusicInfo(unsigned int ticks)
334 {
335         if(!audio.songtitle[0])
336                 return;
337
338         if(ticks != (unsigned int)-1) {
339                 if(ticks > 12000 || ticks < 5000)
340                         return;
341
342                 unsigned int r = rand() & 0x3ff;
343
344                 if(ticks - 5000 < r || 12000 - ticks < r)
345                         return;
346         }
347
348         graphics.setFontSize(0);
349         graphics.setFontColor(0xff, 0xff, 0xff, 0x40, 0x40, 0x40);
350
351         SDL_Surface *text;
352
353         const int x = 620;
354         int y = 420;
355
356         static int w = 0;
357         static int h = 0;
358
359         if(w && h)
360                 graphics.drawRect(x - w - 5, y - h - 5, w + 10, h + 10, graphics.darkGrey, graphics.screen);
361
362         w = h = 0;
363
364         text = graphics.getString(audio.songtitle, true);
365         y -= text->h;
366         h = text->h;
367         w = text->w;
368
369         graphics.blit(text, x - text->w, y, graphics.screen, false);
370         SDL_FreeSurface(text);
371
372         if(audio.songalbum[0])
373         {
374                 graphics.setFontColor(0x80, 0xc0, 0xff, 0x40, 0x40, 0x40);
375                 
376                 text = graphics.getString(audio.songalbum, true);
377                 y -= text->h + 4;
378                 h += text->h + 4;
379                 if(text->w > w)
380                         w = text->w;
381
382                 graphics.blit(text, x - text->w, y, graphics.screen, false);
383                 SDL_FreeSurface(text);
384         }
385
386         if(audio.songartist[0])
387         {
388                 graphics.setFontColor(0xff, 0xc0, 0x80, 0x40, 0x40, 0x40);
389
390                 text = graphics.getString(audio.songartist, true);
391                 y -= text->h + 4;
392                 h += text->h + 4;
393                 if(text->w > w)
394                         w = text->w;
395
396                 graphics.blit(text, x - text->w, y, graphics.screen, false);
397                 SDL_FreeSurface(text);
398         }
399
400         if(audio.songlicense >= 0)
401         {
402                 SDL_Surface *icon = graphics.license[audio.songlicense];
403
404                 y -= icon->h + 8;
405                 h += icon->h + 8;
406                 if(icon->w > w)
407                         w = icon->w;
408
409                 graphics.blit(icon, x - icon->w, y, graphics.screen, false);
410         }
411 }
412