1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * aint32 with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  *
22  * Based on the original sources
23  *   Faery Tale II -- The Halls of the Dead
24  *   (c) 1993-1996 The Wyrmkeep Entertainment Co.
25  */
26 
27 #include "common/config-manager.h"
28 
29 #include "saga2/saga2.h"
30 #include "saga2/fta.h"
31 #include "saga2/player.h"
32 #include "saga2/display.h"
33 #include "saga2/panel.h"
34 #include "saga2/vpal.h"
35 
36 namespace Saga2 {
37 
38 #define VIDEO_EXTENSION ".SMK"
39 
40 #define INTRO_VID1  "TRIMARK" VIDEO_EXTENSION
41 #define INTRO_VID2  "INTRO" VIDEO_EXTENSION
42 
43 #define WIN_VID_1   "END_1" VIDEO_EXTENSION
44 #define WIN_VID_2   "END_2" VIDEO_EXTENSION
45 #define WIN_VID_3   "END_3A" VIDEO_EXTENSION
46 #define WIN_VID_4   "END_3B" VIDEO_EXTENSION
47 
48 #define LOSE_VID    "END_4" VIDEO_EXTENSION
49 
50 
51 #define ERASE_BETWEEN true
52 #define VIDEO_X 0
53 #define VIDEO_Y 0
54 
55 extern bool allPlayerActorsDead;
56 
57 int16 OptionsDialog(bool disableSaveResume = false);
58 void SystemEventLoop(void);
59 void freeAllTileBanks(void);
60 void resetInputDevices(void);
61 void blackOut(void);
62 void cursorFullHide(bool onOff);
63 
64 static void doIntro(void);
65 static void doWintro(int16 whichOne);
66 static void doLostro(void);
67 
68 static void waitForVideo(void);
69 void waitForInput(void);
70 
71 static void TroModeSetup(void);
72 static void TroModeCleanup(void);
73 
74 static bool abortFlag = false;
75 //DO_OUTRO_IN_CLEANUP
76 static int whichOutro = -1;
77 
78 // ------------------------------------------------------------------------
79 // Play intro video
80 
setIntroMode(void)81 void setIntroMode(void) {
82 	blackOut();
83 	if (!abortFlag) {
84 		TroModeSetup();
85 		doIntro();
86 		TroModeCleanup();
87 	}
88 	showLoadMessage();
89 	resetInputDevices();
90 }
91 
92 // ------------------------------------------------------------------------
93 // Play outro video
94 
setOutroMode(void)95 void setOutroMode(void) {
96 }
97 
98 // ------------------------------------------------------------------------
99 // Winning videos
100 extern GameWorld            *currentWorld;          // pointer to the current world
101 
setWintroMode(int16 whichOne)102 void setWintroMode(int16 whichOne) {
103 	whichOutro = whichOne;
104 	allPlayerActorsDead = true;
105 }
106 
107 // ------------------------------------------------------------------------
108 // Losing video
109 
110 void fadeDown();
111 void fadeUp();
112 void dumpGBASE(char *msg);
113 
setLostroMode(void)114 void setLostroMode(void) {
115 	abortFlag = false;
116 	allPlayerActorsDead = false;
117 	if (GameMode::newmodeFlag)
118 		GameMode::update();
119 
120 	if (!abortFlag) {
121 		freeAllTileBanks();
122 		TroModeSetup();
123 		if (whichOutro >= 0)
124 			doWintro(whichOutro);
125 		else
126 			doLostro();
127 		whichOutro = -1;
128 		TroModeCleanup();
129 	}
130 	OptionsDialog(true);
131 	reDrawScreen();
132 }
133 
134 /* ===================================================================== *
135    Entry & termination
136  * ===================================================================== */
137 
TroModeExternEvent(void)138 void TroModeExternEvent(void) {
139 	abortFlag = true;
140 }
141 
142 // ------------------------------------------------------------------------
143 // Entry code
144 
TroModeSetup(void)145 static void TroModeSetup(void) {
146 	suspendAudio();
147 	g_vm->_pointer->hide();
148 	g_vm->_pal->quickSavePalette();
149 	blackOut();
150 	displayDisable(PlayingVideo);
151 	pushVidState();
152 	resetInputDevices();
153 	abortFlag = false;
154 }
155 
156 // ------------------------------------------------------------------------
157 // Exit
158 
TroModeCleanup(void)159 static void TroModeCleanup(void) {
160 	g_vm->endVideo();
161 	popVidState();
162 	displayEnable(PlayingVideo);
163 	blackOut();
164 	g_vm->_pal->quickRestorePalette();
165 	resumeAudio();
166 	g_vm->_pointer->show();
167 //	g_vm->_pointer->manditoryShow();                     //  hide mouse pointer
168 	resetInputDevices();
169 }
170 
171 /* ===================================================================== *
172    Wait for Event type routines
173  * ===================================================================== */
174 
175 // ------------------------------------------------------------------------
176 // Wait till a video completes
177 
waitForVideo(void)178 static void waitForVideo(void) {
179 	while (g_vm->checkVideo()) {
180 		SystemEventLoop();
181 		if (abortFlag)
182 			return;
183 
184 		g_system->delayMillis(10);
185 	}
186 }
187 
188 // ------------------------------------------------------------------------
189 // Wait till the user hits a key or clicks or screams or whatever
190 
waitForInput(void)191 void waitForInput(void) {
192 	abortFlag = false;
193 	while (!abortFlag) {
194 		SystemEventLoop();
195 		if (abortFlag)
196 			return;
197 
198 		g_system->updateScreen();
199 		g_system->delayMillis(10);
200 	}
201 }
202 
203 /* ===================================================================== *
204    Video playback
205  * ===================================================================== */
206 
playAVideo(const char * fileName,int x,int y)207 static void playAVideo(const char *fileName, int x, int y) { //, int16 from, int16 to )
208 	g_vm->startVideo(fileName, x, y);
209 	if (!g_vm->checkVideo()) {
210 		g_vm->endVideo();
211 		abortFlag = true;
212 		return;
213 	}
214 	waitForVideo();
215 }
216 
217 
218 /* ===================================================================== *
219    These are the actual video routines
220  * ===================================================================== */
221 
222 // ------------------------------------------------------------------------
223 // intro video(s)
224 
doIntro(void)225 static void doIntro(void) {
226 	playAVideo(INTRO_VID1, 0, 0);
227 	abortFlag = false;
228 	playAVideo(INTRO_VID2, 0, 0);
229 }
230 
231 // ------------------------------------------------------------------------
232 // one of several endings
233 
doWintro(int16 whichOne)234 static void doWintro(int16 whichOne) {
235 	switch (whichOne) {
236 	case 0:
237 		playAVideo(WIN_VID_1, 0, 0);
238 		return;
239 	case 1:
240 		playAVideo(WIN_VID_2, 0, 0);
241 		return;
242 	case 2:
243 		playAVideo(WIN_VID_3, 0, 0);
244 		return;
245 	case 3:
246 		playAVideo(WIN_VID_4, 0, 0);
247 		return;
248 	}
249 }
250 
251 // ------------------------------------------------------------------------
252 // lost
253 
doLostro(void)254 static void doLostro(void) {
255 	playAVideo(LOSE_VID, 0, 0);
256 }
257 
258 } // end of namespace Saga2
259