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 "neverhood/module.h"
24 #include "neverhood/navigationscene.h"
25 #include "neverhood/smackerscene.h"
26 #include "neverhood/modules/module1000.h"
27 #include "neverhood/modules/module1500.h"
28 
29 namespace Neverhood {
30 
Module(NeverhoodEngine * vm,Module * parentModule)31 Module::Module(NeverhoodEngine *vm, Module *parentModule)
32 	: Entity(vm, 0), _parentModule(parentModule), _childObject(NULL),
33 	_done(false), _sceneType(kSceneTypeNormal) {
34 
35 	SetMessageHandler(&Module::handleMessage);
36 
37 }
38 
~Module()39 Module::~Module() {
40 	delete _childObject;
41 }
42 
draw()43 void Module::draw() {
44 	if (_childObject)
45 		_childObject->draw();
46 }
47 
handleMessage(int messageNum,const MessageParam & param,Entity * sender)48 uint32 Module::handleMessage(int messageNum, const MessageParam &param, Entity *sender) {
49 	switch (messageNum) {
50 	case 0x0008:
51 		sendMessage(_parentModule, 0x0008, 0);
52 		return 0;
53 	case 0x1009:
54 		_moduleResult = param.asInteger();
55 		_done = true;
56 		return 0;
57 	case 0x100A:
58 	case 0x1023:
59 	case 0x1024:
60 		// Unused resource preloading messages
61 		return 0;
62 	default:
63 		if (_childObject && sender == _parentModule)
64 			return sender->sendMessage(_childObject, messageNum, param);
65 	}
66 	return 0;
67 }
68 
navigationScene()69 NavigationScene *Module::navigationScene() {
70 	return (NavigationScene*)_childObject;
71 }
72 
createNavigationScene(uint32 navigationListId,int navigationIndex,const byte * itemsTypes)73 void Module::createNavigationScene(uint32 navigationListId, int navigationIndex, const byte *itemsTypes) {
74 	_sceneType = kSceneTypeNavigation;
75 	_childObject = new NavigationScene(_vm, this, navigationListId, navigationIndex, itemsTypes);
76 }
77 
createSmackerScene(uint32 fileHash,bool doubleSurface,bool canSkip,bool canAbort)78 void Module::createSmackerScene(uint32 fileHash, bool doubleSurface, bool canSkip, bool canAbort) {
79 	_sceneType = kSceneTypeSmacker;
80 	SmackerScene *smackerScene = new SmackerScene(_vm, this, doubleSurface, canSkip, canAbort);
81 	smackerScene->setFileHash(fileHash);
82 	smackerScene->nextVideo();
83 	_childObject = smackerScene;
84 }
85 
createSmackerScene(const uint32 * fileHashList,bool doubleSurface,bool canSkip,bool canAbort)86 void Module::createSmackerScene(const uint32 *fileHashList, bool doubleSurface, bool canSkip, bool canAbort) {
87 	_sceneType = kSceneTypeSmacker;
88 	SmackerScene *smackerScene = new SmackerScene(_vm, this, doubleSurface, canSkip, canAbort);
89 	smackerScene->setFileHashList(fileHashList);
90 	smackerScene->nextVideo();
91 	_childObject = smackerScene;
92 }
93 
createStaticScene(uint32 backgroundFileHash,uint32 cursorFileHash)94 void Module::createStaticScene(uint32 backgroundFileHash, uint32 cursorFileHash) {
95 	_childObject = new StaticScene(_vm, this, backgroundFileHash, cursorFileHash);
96 }
97 
createDemoScene()98 void Module::createDemoScene() {
99 	_childObject = new Scene1501(_vm, this, 0x0009B624, 0, 288, 0);
100 }
101 
updateChild()102 bool Module::updateChild() {
103 	if (_childObject) {
104 		_childObject->handleUpdate();
105 		if (_done) {
106 			_done = false;
107 			// Save the last area type if it's a NavigationScene for further processing
108 			if (_sceneType == kSceneTypeNavigation)
109 				_navigationAreaType = navigationScene()->getNavigationAreaType();
110 			delete _childObject;
111 			_childObject = NULL;
112 			_sceneType = kSceneTypeNormal;
113 			return false;
114 		}
115 	}
116 	return true;
117 }
118 
leaveModule(uint32 result)119 void Module::leaveModule(uint32 result) {
120 	sendMessage(_parentModule, 0x1009, result);
121 }
122 
123 } // End of namespace Neverhood
124