makefile: support a MinGW cross-compilation environment
[blobwars-mingw.git] / src / cutscene.cpp
blob331799b8d5e69cb05295a95c462b55551d99c95c
1 /*
2 Copyright (C) 2004 Parallel Realities
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.
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.
13 See the GNU General Public License for more details.
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.
21 #include "cutscene.h"
23 void createSceneList()
25 char sceneLine[1024];
26 char *line = NULL;
27 int waitTime = 0;
28 Cutscene *scene = NULL;
30 while (true)
32 line = strtok(NULL, "\n");
33 if (line == NULL)
34 break;
36 if (strcmp(sceneLine, "@EOF@") == 0)
37 break;
39 if (line[0] == '[')
40 break;
42 if (strcmp(line, "END") == 0)
43 break;
45 if (strcmp(line, "NEW") == 0)
47 scene = new Cutscene();
48 sceneList.add(scene);
50 // Assume graphics is first line after new
51 line = strtok(NULL, "\n");
52 if (strcmp(line, "@none@") != 0)
54 strcpy(scene->sprite, line);
55 debug(("Loading cutscene image %s\n", scene->sprite));
56 graphics.quickSprite(scene->sprite, graphics.loadImage(scene->sprite));
58 line = strtok(NULL, "\n");
59 sscanf(line, "%d", &waitTime);
60 scene->waitTime = (waitTime * 100);
61 line = strtok(NULL, "\n");
64 if (strcmp(line, "@none@") != 0)
66 scene->appendText(line);
71 bool setupScene(char *stagename)
73 sceneList.clear();
75 char sceneLine[1024];
77 if (!engine.loadData(_("data/ending")))
78 graphics.showErrorAndExit("Couldn't load cutscene data file (%s)", _("data/ending"));
80 char *line = strtok((char*)engine.dataBuffer, "\n");
81 int i = 0;
83 graphics.clearChatString();
85 bool found = false;
87 while (!found)
89 if (line[0] == '[')
91 sscanf(line, "%*c %[^]]", sceneLine);
92 if (strcmp(sceneLine, stagename) == 0)
94 found = true;
98 if (!found)
100 line = strtok(NULL, "\n");
101 if (line == NULL)
102 break;
105 i++;
107 // sanity check!
108 if (i == 10000)
110 exit(1);
114 if (found)
116 createSceneList();
119 return found;
122 void showScene(bool allowSkip)
124 graphics.setFontSize(0);
125 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
127 SDL_FillRect(graphics.screen, NULL, graphics.black);
128 graphics.delay(500);
130 Cutscene *scene = (Cutscene*)sceneList.getHead();
132 SDL_Surface *panel = graphics.quickSprite("panel", graphics.createSurface(640, 90));
133 SDL_Surface *image = NULL;
134 SDL_FillRect(panel, NULL, graphics.black);
136 float panelAlpha = 0;
138 SDL_SetAlpha(panel, SDL_SRCALPHA|SDL_RLEACCEL, 0);
140 engine.clearInput();
141 engine.flushInput();
143 float changeTime = 100;
145 engine.resetTimeDifference();
147 audio.playMusicOnce();
149 while (true)
151 graphics.updateScreen();
152 engine.getInput();
153 config.populate();
155 engine.doTimeDifference();
157 if ((engine.userAccepts()) && (allowSkip))
159 changeTime = 0;
160 panelAlpha = 255;
161 engine.clearInput();
164 if (panelAlpha < 256)
166 panelAlpha += (1 * engine.getTimeDifference());
167 SDL_SetAlpha(panel, SDL_SRCALPHA|SDL_RLEACCEL, (int)panelAlpha);
168 if (image != NULL)
170 SDL_SetAlpha(image, SDL_SRCALPHA|SDL_RLEACCEL, (int)panelAlpha);
171 graphics.blit(image, 0, 0, graphics.screen, false);
173 graphics.blit(panel, 0, 390, graphics.screen, false);
176 changeTime -= (1 * engine.getTimeDifference());
178 if (changeTime <= 0)
180 if (scene->next != NULL)
182 scene = (Cutscene*)scene->next;
183 panelAlpha = 0;
184 changeTime = scene->waitTime;
185 graphics.clearChatString();
186 graphics.createChatString(scene->text);
187 SDL_FillRect(panel, NULL, graphics.black);
188 graphics.drawChatString(panel, 0);
189 image = NULL;
191 if (strcmp(scene->sprite, "") != 0)
193 debug(("Getting cutscene %s\n", scene->sprite));
194 image = graphics.getSprite(scene->sprite, true)->image[0];
195 SDL_SetColorKey(image, 0, SDL_MapRGB(image->format, 0, 0, 0));
198 else
200 break;
204 SDL_Delay(16);
207 SDL_FillRect(graphics.screen, NULL, graphics.black);
208 graphics.delay(500);
211 void checkStartCutscene()
213 // Easy mode doesn't have cutscenes!
214 if (game.skill == 0)
216 return;
219 audio.loadMusic("music/daisyChain2.mod");
221 char sceneName[1024];
222 sprintf(sceneName, "%s Start", game.stageName);
224 if (setupScene(sceneName))
226 showScene(true);
229 graphics.free();
230 audio.free();
233 void checkEndCutscene()
235 // Easy mode doesn't have cutscenes!
236 if (game.skill == 0)
238 return;
241 if (strcmp(game.stageName, "Final Battle") != 0)
243 audio.loadMusic("music/daisyChain2.mod");
245 else
247 audio.loadMusic("music/sweetDreams.xm");
250 char sceneName[1024];
251 sprintf(sceneName, "%s End", game.stageName);
253 debug(("%s\n", sceneName));
255 bool allowSkip = true;
257 // Don't let the player skip the end of game cutscene...
258 // So we get the music timed well! :)
259 if (strcmp(game.stageName, "Final Battle") == 0)
261 allowSkip = false;
264 if (setupScene(sceneName))
266 showScene(allowSkip);
269 graphics.free();
270 audio.free();
273 void easyGameFinished()
275 graphics.free();
276 audio.free();
278 audio.loadMusic("music/friendDied.mod");
279 setupScene("Easy Game Finished");
280 showScene(true);
281 audio.fadeMusic();
282 graphics.delay(3500);
284 graphics.free();
285 audio.free();