aboutsummaryrefslogtreecommitdiff
path: root/engines/neverhood/module2100.cpp
blob: 98b6e03cd44ccfc414fd1d94a277f087dba94aa2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "neverhood/module2100.h"
#include "neverhood/gamemodule.h"
#include "neverhood/module1200.h"

namespace Neverhood {

Module2100::Module2100(NeverhoodEngine *vm, Module *parentModule, int which)
	: Module(vm, parentModule) {

	_vm->_soundMan->addMusic(0x10A10C14, 0x11482B95);
	
	if (which < 0) {
		createScene(_vm->gameState().sceneNum, -1);
	} else if (which == 1) {
		createScene(0, 0);
	} else if (which == 2) {
		createScene(0, 3);
	} else {
		createScene(0, 1);
	}

}

Module2100::~Module2100() {
	_vm->_soundMan->deleteMusicGroup(0x10A10C14);
}

void Module2100::createScene(int sceneNum, int which) {
	debug("Module2100::createScene(%d, %d)", sceneNum, which);
	_vm->gameState().sceneNum = sceneNum;
	switch (_vm->gameState().sceneNum) {
	case 0:
		_vm->_soundMan->startMusic(0x11482B95, 0, 1);
		_childObject = new Scene2101(_vm, this, which);
		break;
	}
	SetUpdateHandler(&Module2100::updateScene);
	_childObject->handleUpdate();
}

void Module2100::updateScene() {
	if (!updateChild()) {
		switch (_vm->gameState().sceneNum) {
		case 0:
			if (_moduleResult == 1) {
				setGlobalVar(0x2090590C, 1);
				leaveModule(0);
			} else {
				leaveModule(1);
			}
			break;
		}
	}
}

// Scene2101

Class538::Class538(NeverhoodEngine *vm, bool flag)
	: AnimatedSprite(vm, 1100) {

	// TODO createSurface3(100, dword_4B9018);
	createSurface(100, 640, 480); //TODO: Remove once the line above is done
	_x = 320;
	_y = 240;
	SetUpdateHandler(&AnimatedSprite::update);
	SetMessageHandler(&Class538::handleMessage);
	if (flag) {
		startAnimation(0x0C202B9C, -1, -1);
		_newStickFrameIndex = -2;
	} else {
		setVisible(false);
	}
}

uint32 Class538::handleMessage(int messageNum, const MessageParam &param, Entity *sender) {
	uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
	switch (messageNum) {
	case 0x3002:
		gotoNextState();
		break;
	case 0x4808:
		openDoor();
		break;
	case 0x4809:
		closeDoor();
		break;
	}
	return messageResult;
}

void Class538::openDoor() {
	startAnimation(0x0C202B9C, 0, -1);
	_newStickFrameIndex = -2;
	setVisible(true);
	playSound(0, calcHash("fxDoorOpen32"));
}

void Class538::closeDoor() {
	startAnimation(0xC222A8D4, 0, -1);
	_newStickFrameIndex = -2;
	setVisible(true);
	NextState(&Class538::hide);
	playSound(0, calcHash("fxDoorClose32"));
}

void Class538::hide() {
	stopAnimation();
	setVisible(false);
}

Class539::Class539(NeverhoodEngine *vm, Sprite *klayman)
	: AnimatedSprite(vm, 1400), _klayman(klayman) {
	
	SetUpdateHandler(&AnimatedSprite::update);
	SetMessageHandler(&Class539::handleMessage);
	createSurface(1200, 88, 165);
	setVisible(false);
}

uint32 Class539::handleMessage(int messageNum, const MessageParam &param, Entity *sender) {
	uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
	switch (messageNum) {
	case 0x2001:
		_x = _klayman->getX();
		_y = _klayman->getY() - 132;
		startAnimation(0x0422255A, 0, -1);
		setVisible(true);
		break;
	case 0x3002:
		stopAnimation();
		setVisible(false);
		break;
	}
	return messageResult;
}

Class427::Class427(NeverhoodEngine *vm, Scene *parentScene, uint32 fileHash1, uint32 fileHash2, int surfacePriority, uint32 soundFileHash)
	: StaticSprite(vm, 1100), _parentScene(parentScene), _countdown(0),
	_fileHash1(fileHash1), _fileHash2(fileHash2), _soundFileHash(soundFileHash) {

	SetUpdateHandler(&Class427::update);
	SetMessageHandler(&Class427::handleMessage);
	if (_soundFileHash == 0)
		_soundFileHash = 0x44141000;
	createSurface(1010, 61, 30);
	if (_fileHash1) {
		load(_fileHash1, true, true);
		StaticSprite::update();
	} else
		setVisible(false);
}

void Class427::update() {
	if (_countdown != 0 && (--_countdown == 0)) {
		sendMessage(_parentScene, 0x1022, 1010);
		if (_fileHash1) {
			load(_fileHash1, true, true);
			StaticSprite::update();
		} else
			setVisible(false);
	}
}	
	
uint32 Class427::handleMessage(int messageNum, const MessageParam &param, Entity *sender) {
	uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
	switch (messageNum) {
	case 0x480B:
		sendMessage(_parentScene, 0x480B, 0);
		setVisible(true);
		sendMessage(_parentScene, 0x1022, 990);
		load(_fileHash2, true, true);
		StaticSprite::update();
		_countdown = 16;
		playSound(0, _soundFileHash);
		break;
	}
	return messageResult;
}

Scene2101::Scene2101(NeverhoodEngine *vm, Module *parentModule, int which)
	: Scene(vm, parentModule, true) {
	
	_surfaceFlag = true;
	SetMessageHandler(&Scene2101::handleMessage);
	SetUpdateHandler(&Scene2101::update);
	
	setBackground(0x44242305);
	setPalette(0x44242305);
	insertMouse433(0x4230144A);

	insertStaticSprite(0x00502330, 1100);
	_sprite1 = insertStaticSprite(0x78492010, 1100);
	_class427 = insertSprite<Class427>(this, 0x72427010, 0x32423010, 200, 0);
	_asTape1 = insertSprite<AsScene1201Tape>(this, 18, 1100, 412, 443, 0x9148A011);
	_vm->_collisionMan->addSprite(_asTape1);
	_asTape2 = insertSprite<AsScene1201Tape>(this, 11, 1100, 441, 443, 0x9148A011);
	_vm->_collisionMan->addSprite(_asTape2);
	
	if (which < 0) {
		insertKlayman<KmScene2101>(380, 438);
		setMessageList(0x004B8E48);
		sendMessage(this, 0x2000, 0);
		_class538 = insertSprite<Class538>(false);
		_value1 = 1;
		_countdown1 = 0;
	} else if (which == 1) {
		insertKlayman<KmScene2101>(640, 438);
		setMessageList(0x004B8E50);
		sendMessage(this, 0x2000, 0);
		_class538 = insertSprite<Class538>(true);
		_value1 = 2;
		_countdown1 = 48;
	} else if (which == 2) {
		insertKlayman<KmScene2101>(115, 438);
		sendMessage(_klayman, 0x2000, 1);
		setMessageList(0x004B8F58);
		sendMessage(this, 0x2000, 1);
		_class538 = insertSprite<Class538>(false);
		_value1 = 1;
		_countdown1 = 0;
	} else if (which == 3) {
		insertKlayman<KmScene2101>(115, 438);
		sendMessage(_klayman, 0x2000, 1);
		setMessageList(0x004B8EB0);
		sendMessage(this, 0x2000, 1);
		_class538 = insertSprite<Class538>(false);
		_value1 = 1;
		_countdown1 = 0;
	} else {
		insertKlayman<KmScene2101>(115, 438);
		sendMessage(_klayman, 0x2000, 1);
		setMessageList(0x004B8EA0);
		sendMessage(this, 0x2000, 1);
		_class538 = insertSprite<Class538>(false);
		_value1 = 1;
		_countdown1 = 0;
	}
	
	_class539 = insertSprite<Class539>(_klayman);
	_klayman->setClipRect(0, 0, _sprite1->getDrawRect().x2(), 480);
	
}

void Scene2101::update() {
	if (_countdown1 != 0) {
		if (_value1 == 2) {
			if (--_countdown1 == 0) {
				sendMessage(_class538, 0x4809, 0);
				_value1 = 1;
			}
		} else {
			if (_klayman->getX() > 575)
				_messageListFlag  = false;
			if (--_countdown1 == 0) {
				if (_klayman->getX() < 480) {
					sendMessage(_class538, 0x4809, 0);
					_value1 = 1;
				} else if (_klayman->getX() >= 480 && _klayman->getX() <= 575) {
					_klayman->setDoDeltaX(0);
					setMessageList2(0x004B8F48);
					sendMessage(_class538, 0x4809, 0);
					sendMessage(_class539, 0x2001, 0);
					_value1 = 1;
				}
			}
		}
	} else if (_value1 == 1 && _messageValue >= 0 && _klayman->getX() > 470 /* TODO ! && _messageList2 != 0x004B8F48*/) {
		setMessageList2(0x004B8F50);
	}
	Scene::update();
}

uint32 Scene2101::handleMessage(int messageNum, const MessageParam &param, Entity *sender) {
	Scene::handleMessage(messageNum, param, sender);
	switch (messageNum) {
	case 0x100D:
		if (param.asInteger() == 0x02144CB1) {
			sendEntityMessage(_klayman, 0x1014, _class427);
		} else if (param.asInteger() == 0x21E64A00) {
			if (_value1 == 0) {
				setMessageList(0x004B8E80);
			} else {
				setMessageList(0x004B8EC8);
			}
		} else if (param.asInteger() == 0x41442820) {
			messageList402220();
		}
		break;
	case 0x2000:
		if (param.asInteger() != 0) {
			setRectList(0x004B9008);
			_klayman->setKlaymanIdleTable3();
		} else {
			setRectList(0x004B8FF8);
			_klayman->setKlaymanIdleTable1();
		}
		break;
	case 0x480B:
		if (sender == _class427 && _value1 == 1) {
			sendMessage(_class538, 0x4808, 0);
			_value1 = 0;
			_countdown1 = 90;
		}
		break;
	case 0x4826:
		if (sender == _asTape1 || sender == _asTape2) {
			if (_klayman->getX() >= 228 && _klayman->getX() <= 500) {
				sendEntityMessage(_klayman, 0x1014, sender);
				setMessageList(0x004B8F78);
			} else if (_klayman->getX() < 228) {
				setMessageList2(0x004B8F00);
			}
		}
		break;
	}
	return 0;
}

} // End of namespace Neverhood