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  * along 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 
23 #include "ngi/ngi.h"
24 
25 #include "ngi/objectnames.h"
26 #include "ngi/constants.h"
27 
28 #include "ngi/gameloader.h"
29 #include "ngi/motion.h"
30 #include "ngi/scenes.h"
31 #include "ngi/statics.h"
32 
33 #include "ngi/interaction.h"
34 #include "ngi/behavior.h"
35 
36 #include "ngi/modal.h"
37 
38 #include "audio/mixer.h"
39 
40 namespace NGI {
41 
sceneFinal_initScene()42 void sceneFinal_initScene() {
43 	g_nmi->_gameLoader->loadScene(SC_FINAL2);
44 	g_nmi->accessScene(SC_FINAL2)->setPictureObjectsFlag4();
45 	g_nmi->_gameLoader->loadScene(SC_FINAL3);
46 	g_nmi->accessScene(SC_FINAL3)->setPictureObjectsFlag4();
47 	g_nmi->_gameLoader->loadScene(SC_FINAL4);
48 	g_nmi->accessScene(SC_FINAL4)->setPictureObjectsFlag4();
49 
50 	getGameLoaderInventory()->setIsLocked(0);
51 	getGameLoaderInventory()->slideIn();
52 
53 	g_nmi->_updateFlag = 0;
54 	g_nmi->_flgCanOpenMap = 0;
55 
56 	g_vars->sceneFinal_var01 = 0;
57 	g_vars->sceneFinal_var02 = 0;
58 	g_vars->sceneFinal_var03 = 0;
59 	g_vars->sceneFinal_trackHasStarted = false;
60 }
61 
sceneFinal_updateCursor()62 int sceneFinal_updateCursor() {
63 	if (g_vars->sceneFinal_var01)
64 		g_nmi->_cursorId = 0;
65 	else
66 		g_nmi->updateCursorCommon();
67 
68 	return g_nmi->_cursorId;
69 }
70 
sceneHandlerFinal_endFinal()71 void sceneHandlerFinal_endFinal() {
72 	g_vars->sceneFinal_var01 = 0;
73 }
74 
sceneHandlerFinal_startMusic(const char * track)75 void sceneHandlerFinal_startMusic(const char *track) {
76 	g_nmi->startSoundStream1(track);
77 	g_vars->sceneFinal_trackHasStarted = true;
78 }
79 
sceneHandlerFinal_goto4()80 void sceneHandlerFinal_goto4() {
81 	g_nmi->_currentScene = g_nmi->accessScene(SC_FINAL4);
82 
83 	g_nmi->_gameLoader->loadScene(SC_FINAL4);
84 
85 	chainQueue(QU_FN4_DOFINAL, 1);
86 }
87 
sceneHandlerFinal_goto3()88 void sceneHandlerFinal_goto3() {
89 	g_nmi->_currentScene = g_nmi->accessScene(SC_FINAL3);
90 
91 	chainQueue(QU_FN3_DOFINAL, 1);
92 }
93 
sceneHandlerFinal_goto2()94 void sceneHandlerFinal_goto2() {
95 	g_nmi->_currentScene = g_nmi->accessScene(SC_FINAL2);
96 
97 	chainQueue(QU_FN2_DOFINAL, 1);
98 }
99 
sceneHandlerFinal_startFinal()100 void sceneHandlerFinal_startFinal() {
101 	g_vars->sceneFinal_var01 = 1;
102 
103 	getCurrSceneSc2MotionController()->deactivate();
104 	getGameLoaderInteractionController()->disableFlag24();
105 
106 	g_nmi->_aniMan2 = 0;
107 
108 	g_nmi->_aniMan->_flags &= 0xFFFB;
109 
110 	chainQueue(QU_FIN1_TAKECOIN, 1);
111 
112 	g_nmi->playTrack(g_nmi->getGameLoaderGameVar()->getSubVarByName("SC_FINAL1"), "MUSIC2", 1);
113 
114 	g_nmi->_modalObject = new ModalFinal;
115 }
116 
sceneHandlerFinal_fallCoin()117 void sceneHandlerFinal_fallCoin() {
118 	StaticANIObject *coin = g_nmi->_currentScene->getStaticANIObject1ById(ANI_FIN_COIN, -1);
119 
120 	if (!coin->_movement) {
121 		if (!coin->_statics || coin->_statics->_staticsId != ST_FCN_NORM)
122 			chainQueue(QU_FIN1_FALLCOIN, 1);
123 	}
124 }
125 
updateMusic()126 void updateMusic() {
127 	if (g_vars->sceneFinal_trackHasStarted && !g_nmi->_mixer->isSoundHandleActive(g_nmi->_soundStream1)) { // loop music
128 		sceneHandlerFinal_startMusic("track16.ogg");
129 	}
130 }
131 
sceneHandlerFinal(ExCommand * cmd)132 int sceneHandlerFinal(ExCommand *cmd) {
133 	if (cmd->_messageKind != 17)
134 		return 0;
135 
136 	switch (cmd->_messageNum) {
137 	case MSG_FIN_ENDFINAL:
138 		sceneHandlerFinal_endFinal();
139 		break;
140 
141 	case MSG_FN4_STARTMUSIC:
142 		sceneHandlerFinal_startMusic("track16.ogg");
143 		break;
144 
145 	case MSG_FIN_GOTO4:
146 		sceneHandlerFinal_goto4();
147 
148 		g_nmi->playTrack(g_nmi->getGameLoaderGameVar()->getSubVarByName("SC_FINAL1"), "MUSIC3", 1);
149 		break;
150 
151 	case MSG_FIN_GOTO3:
152 		sceneHandlerFinal_goto3();
153 		break;
154 
155 	case MSG_FIN_GOTO2:
156 		sceneHandlerFinal_goto2();
157 		break;
158 
159 	case MSG_FIN_STARTFINAL:
160 		sceneHandlerFinal_startFinal();
161 		break;
162 
163 	case 33:
164 		if (g_nmi->_aniMan2) {
165 			g_vars->sceneFinal_var03 = g_nmi->_aniMan2->_ox;
166 
167 			if (g_vars->sceneFinal_var03 < 450 && g_vars->sceneFinal_var02 >= 450 )
168 				sceneHandlerFinal_fallCoin();
169 
170 			g_vars->sceneFinal_var02 = g_vars->sceneFinal_var03;
171 		}
172 
173 		g_nmi->_behaviorManager->updateBehaviors();
174 
175 		g_nmi->startSceneTrack();
176 
177 		break;
178 
179 	default:
180 		break;
181 	}
182 
183 	updateMusic();
184 
185 	return 0;
186 }
187 
188 } // End of namespace NGI
189