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 #ifdef ENABLE_MADSV2
24 
25 #include "mads/mads.h"
26 #include "mads/conversations.h"
27 #include "mads/phantom/phantom_scenes.h"
28 #include "mads/phantom/phantom_scenes5.h"
29 
30 namespace MADS {
31 
32 namespace Phantom {
33 
setAAName()34 void Scene5xx::setAAName() {
35 	_game._aaName = Resources::formatAAName(1);
36 	_vm->_palette->setEntry(254, 43, 47, 51);
37 }
38 
sceneEntrySound()39 void Scene5xx::sceneEntrySound() {
40 	if (!_vm->_musicFlag)
41 		return;
42 
43 	if ((_globals[kCoffinStatus] == 2) && !_game._visitedScenes.exists(506) && (_globals[kFightStatus] == 0) && (_scene->_currentSceneId == 504))
44 		_vm->_sound->command(33);
45 	else if (_scene->_currentSceneId == 505)
46 		_vm->_sound->command((_vm->_gameConv->restoreRunning() == 20) ? 39 : 16);
47 	else
48 		_vm->_sound->command(16);
49 }
50 
setPlayerSpritesPrefix()51 void Scene5xx::setPlayerSpritesPrefix() {
52 	_vm->_sound->command(5);
53 
54 	Common::String oldName = _game._player._spritesPrefix;
55 	if (!_game._player._forcePrefix)
56 		_game._player._spritesPrefix = "RAL";
57 	if (oldName != _game._player._spritesPrefix)
58 		_game._player._spritesChanged = true;
59 
60 	_game._player._scalingVelocity = true;
61 }
62 
63 /*------------------------------------------------------------------------*/
64 
Scene501(MADSEngine * vm)65 Scene501::Scene501(MADSEngine *vm) : Scene5xx(vm) {
66 	_anim0ActvFl = false;
67 	_skipFl = false;
68 }
69 
synchronize(Common::Serializer & s)70 void Scene501::synchronize(Common::Serializer &s) {
71 	Scene5xx::synchronize(s);
72 
73 	s.syncAsByte(_anim0ActvFl);
74 	s.syncAsByte(_skipFl);
75 }
76 
setup()77 void Scene501::setup() {
78 	setPlayerSpritesPrefix();
79 	setAAName();
80 
81 	_scene->addActiveVocab(NOUN_CHRISTINE);
82 	_scene->addActiveVocab(VERB_LOOK_AT);
83 	_scene->addActiveVocab(VERB_WALK_TO);
84 }
85 
enter()86 void Scene501::enter() {
87 	_scene->_hotspots.activate(NOUN_CHRISTINE, false);
88 	_scene->_hotspots.activate(NOUN_BOAT, false);
89 
90 	if (_scene->_priorSceneId != RETURNING_FROM_LOADING) {
91 		_anim0ActvFl = false;
92 		_skipFl = false;
93 	}
94 
95 	_vm->_gameConv->load(26);
96 
97 	_globals._spriteIndexes[0] = _scene->_sprites.addSprites(formAnimName('x', 0));
98 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('x', 1));
99 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('x', 2));
100 	_globals._spriteIndexes[5] = _scene->_sprites.addSprites(formAnimName('a', 1));
101 	_globals._spriteIndexes[6] = _scene->_sprites.addSprites(formAnimName('a', 0));
102 	_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_6", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
103 	_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_9", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
104 	_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_8", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
105 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites("*RDRR_6");
106 
107 	_globals._sequenceIndexes[0] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[0], false, 6);
108 	_scene->_sequences.setDepth(_globals._sequenceIndexes[0], 14);
109 	_scene->_sequences.setAnimRange(_globals._sequenceIndexes[0], -1, -2);
110 
111 	if (_scene->_priorSceneId == RETURNING_FROM_LOADING) {
112 		if (_globals[kChristineIsInBoat]) {
113 			_anim0ActvFl = true;
114 			_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('b', 1), 100);
115 			_scene->setAnimFrame(_globals._animationIndexes[0], 124);
116 			_scene->_hotspots.activateAtPos(NOUN_CHRISTINE, true, Common::Point(113, 93));
117 			_scene->_hotspots.activate(NOUN_BOAT, true);
118 		}
119 
120 		_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 1);
121 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 4);
122 		_globals._sequenceIndexes[2] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[2], false, -1);
123 		_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 4);
124 	}
125 
126 	if (_scene->_priorSceneId == 506) {
127 		_game._player._playerPos = Common::Point(305, 112);
128 		_game._player._facing = FACING_WEST;
129 		_game._player._stepEnabled = false;
130 
131 		if (_globals[kChristineIsInBoat]) {
132 			_anim0ActvFl = true;
133 			_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('b', 1), 100);
134 			_scene->setAnimFrame(_globals._animationIndexes[0], 124);
135 			_scene->_hotspots.activateAtPos(NOUN_CHRISTINE, true, Common::Point(113, 93));
136 			_scene->_hotspots.activate(NOUN_BOAT, true);
137 			_game._player.walk(Common::Point(260, 112), FACING_SOUTHWEST);
138 			_game._player.setWalkTrigger(80);
139 			_game._player.setWalkTrigger(55);
140 		} else {
141 			_anim0ActvFl = true;
142 			_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('b', 1), 100);
143 			_globals[kChristineIsInBoat] = true;
144 			_scene->_hotspots.activate(NOUN_BOAT, true);
145 			_game._player.walk(Common::Point(260, 112), FACING_SOUTHWEST);
146 			_game._player.setWalkTrigger(80);
147 		}
148 
149 		_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 1);
150 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 4);
151 
152 		_globals._sequenceIndexes[2] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[2], false, -2);
153 		_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
154 	} else if ((_scene->_priorSceneId == 401) || (_scene->_priorSceneId == 408) || (_scene->_priorSceneId != RETURNING_FROM_LOADING)) {
155 		_game._player.firstWalk(Common::Point(-20, 109), FACING_EAST, Common::Point(24, 109), FACING_EAST, true);
156 		_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 1);
157 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 4);
158 
159 		_globals._sequenceIndexes[2] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[2], false, -1);
160 		_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 4);
161 	}
162 
163 	sceneEntrySound();
164 }
165 
step()166 void Scene501::step() {
167 	switch (_game._trigger) {
168 	case 55:
169 		_scene->deleteSequence(_globals._sequenceIndexes[2]);
170 		_globals._sequenceIndexes[2] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[2], false, 8, 1);
171 		_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 10);
172 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], -1, -2);
173 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 56);
174 		break;
175 
176 	case 56:
177 		_vm->_sound->command(25);
178 		_globals._sequenceIndexes[2] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[2], false, 1);
179 		_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 10);
180 		if (!_globals[kChrisWillTakeSeat])
181 			_game._player._stepEnabled = true;
182 
183 		_globals[kChrisWillTakeSeat] = false;
184 		break;
185 
186 	default:
187 		break;
188 	}
189 
190 
191 	switch (_game._trigger) {
192 	case 60:
193 		_globals._sequenceIndexes[1] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[1], false, 8, 1);
194 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 4);
195 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], -1, -2);
196 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[1], SEQUENCE_TRIGGER_EXPIRE, 0, 61);
197 		break;
198 
199 	case 61:
200 		_vm->_sound->command(25);
201 		_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, -1);
202 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 4);
203 		_game._player._stepEnabled = true;
204 		break;
205 
206 	case 80: {
207 		_game._player.walk(Common::Point(255, 118), FACING_NORTHWEST);
208 		_scene->setAnimFrame(_globals._animationIndexes[0], 2);
209 		int idx = _scene->_dynamicHotspots.add(NOUN_CHRISTINE, VERB_WALK_TO, SYNTAX_SINGULAR_FEM, EXT_NONE, Common::Rect(0, 0, 0, 0));
210 		_scene->setDynamicAnim(idx, _globals._animationIndexes[0], 0);
211 		_scene->setDynamicAnim(idx, _globals._animationIndexes[0], 1);
212 		_scene->setDynamicAnim(idx, _globals._animationIndexes[0], 2);
213 		_scene->setDynamicAnim(idx, _globals._animationIndexes[0], 3);
214 		}
215 		break;
216 
217 	case 90:
218 		_globals[kPlayerScore] += 5;
219 		_scene->_nextSceneId = 310;
220 		break;
221 
222 	case 100:
223 		_game._player._stepEnabled = false;
224 		_game._player._visible = false;
225 		_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 9, 1);
226 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], -1, -2);
227 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 90);
228 		break;
229 
230 	default:
231 		break;
232 	}
233 
234 	if (_anim0ActvFl) {
235 		if (_scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame() == 103)
236 			_scene->_hotspots.activateAtPos(NOUN_CHRISTINE, true, Common::Point(125, 94));
237 
238 		if ((_scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame() == 28) && !_skipFl) {
239 			_skipFl = true;
240 			_scene->_sequences.addTimer(1, 55);
241 		}
242 
243 		if (_scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame() == 124) {
244 			_scene->_hotspots.activateAtPos(NOUN_CHRISTINE, false, Common::Point(125, 94));
245 			_scene->_hotspots.activateAtPos(NOUN_CHRISTINE, true , Common::Point(113, 93));
246 		}
247 
248 		if (_scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame() == 125)
249 			_scene->setAnimFrame(_globals._animationIndexes[0], 124);
250 
251 		if (_scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame() == 1)
252 			_scene->setAnimFrame(_globals._animationIndexes[0], 0);
253 
254 		if (_scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame() == 84)
255 			_game._player._stepEnabled = true;
256 	}
257 }
258 
actions()259 void Scene501::actions() {
260 	if (_vm->_gameConv->activeConvId() == 26) {
261 		_action._inProgress = false;
262 		return;
263 	}
264 
265 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_ARCHWAY_TO_WEST) && (_globals[kChristineIsInBoat])) {
266 		_vm->_gameConv->run(26);
267 		_vm->_gameConv->exportValue(3);
268 		_action._inProgress = false;
269 		return;
270 	}
271 
272 	if (_action.isAction(VERB_TALK_TO, NOUN_CHRISTINE)) {
273 		_vm->_gameConv->run(26);
274 		_vm->_gameConv->exportValue(1);
275 		_action._inProgress = false;
276 		return;
277 	}
278 
279 	if (_action.isAction(VERB_CLIMB_INTO, NOUN_BOAT)) {
280 		if (_game._objects.isInInventory(OBJ_OAR))
281 			_anim0ActvFl = false;
282 		else
283 			_vm->_dialogs->show(50123);
284 
285 		_action._inProgress = false;
286 		return;
287 	}
288 
289 	if (_action.isAction(VERB_UNLOCK, NOUN_DOOR) || _action.isAction(VERB_LOCK, NOUN_DOOR)) {
290 		switch (_game._trigger) {
291 		case 0:
292 			_game._player._stepEnabled = false;
293 			_game._player._visible = false;
294 			_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 5, 1);
295 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 1, 4);
296 			_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], true);
297 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 1);
298 			break;
299 
300 		case 1: {
301 			int idx = _globals._sequenceIndexes[3];
302 			_globals._sequenceIndexes[3] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[3], false, 4);
303 			_game.syncTimers(SYNC_SEQ, _globals._sequenceIndexes[3], SYNC_SEQ, idx);
304 			_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], false);
305 			_scene->_sequences.addTimer(15, 2);
306 			_vm->_sound->command(74);
307 			}
308 			break;
309 
310 		case 2:
311 			_scene->deleteSequence(_globals._sequenceIndexes[3]);
312 			_globals._sequenceIndexes[3] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[3], false, 5, 1);
313 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 1, 4);
314 			_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], false);
315 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
316 			break;
317 
318 		case 3:
319 			_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[3]);
320 			_game._player._visible = true;
321 			_vm->_dialogs->show(50122);
322 			_game._player._stepEnabled = true;
323 			break;
324 
325 		default:
326 			break;
327 		}
328 		_action._inProgress = false;
329 		return;
330 	}
331 
332 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_DOOR) || _action.isAction(VERB_OPEN, NOUN_DOOR)) {
333 		if (_scene->_customDest.x < 287) {
334 			if (!_globals[kChristineIsInBoat]) {
335 				switch (_game._trigger) {
336 				case 0:
337 					_game._player._stepEnabled = false;
338 					_game._player._visible = false;
339 					_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 5, 1);
340 					_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 1, 4);
341 					_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], true);
342 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 1);
343 					break;
344 
345 				case 1: {
346 					int idx = _globals._sequenceIndexes[3];
347 					_globals._sequenceIndexes[3] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[3], false, 4);
348 					_game.syncTimers(SYNC_SEQ, _globals._sequenceIndexes[3], SYNC_SEQ, idx);
349 					_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], false);
350 					_scene->_sequences.addTimer(15, 2);
351 					_vm->_sound->command(74);
352 					}
353 					break;
354 
355 				case 2:
356 					_scene->deleteSequence(_globals._sequenceIndexes[3]);
357 					_globals._sequenceIndexes[3] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[3], false, 5, 1);
358 					_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 1, 4);
359 					_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], false);
360 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
361 					break;
362 
363 				case 3:
364 					_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[3]);
365 					_game._player._visible = true;
366 					_vm->_dialogs->show(50120);
367 					_game._player._stepEnabled = true;
368 					break;
369 
370 				default:
371 					break;
372 				}
373 			} else {
374 				switch (_game._trigger) {
375 				case (0):
376 					_game._player._stepEnabled = false;
377 					_game._player._visible = false;
378 					_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 5, 2);
379 					_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 1, 4);
380 					_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], true);
381 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_SPRITE, 4, 65);
382 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 67);
383 					break;
384 
385 				case 65:
386 					_scene->deleteSequence(_globals._sequenceIndexes[2]);
387 					_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 8, 1);
388 					_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 4);
389 					_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], -1, -2);
390 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 66);
391 					_vm->_sound->command(24);
392 					break;
393 
394 				case 66:
395 					_globals._sequenceIndexes[2] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[2], false, -2);
396 					_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
397 					_game._player.walk(Common::Point(305, 112), FACING_EAST);
398 					_game._player.setWalkTrigger(68);
399 					break;
400 
401 				case 67:
402 					_game._player._visible = true;
403 					break;
404 
405 				case 68:
406 					_vm->_gameConv->stop();
407 					_scene->_nextSceneId = 506;
408 					break;
409 
410 				default:
411 					break;
412 				}
413 			}
414 		} else {
415 			if (!_globals[kChristineIsInBoat]) {
416 				switch (_game._trigger) {
417 				case (0):
418 					_game._player._stepEnabled = false;
419 					_game._player._visible = false;
420 					_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 5, 2);
421 					_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 1, 4);
422 					_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], true);
423 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_SPRITE, 4, 65);
424 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 67);
425 					break;
426 
427 				case 65: {
428 					int idx = _globals._sequenceIndexes[1];
429 					_scene->deleteSequence(_globals._sequenceIndexes[1]);
430 					_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 8, 1);
431 					_game.syncTimers(SYNC_SEQ, _globals._sequenceIndexes[1], SYNC_SEQ, idx);
432 					_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 4);
433 					_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], -1, -2);
434 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[1], SEQUENCE_TRIGGER_EXPIRE, 0, 66);
435 					_vm->_sound->command(24);
436 					}
437 					break;
438 
439 				case 66:
440 					_game._player.walk(Common::Point(319, 116), FACING_NORTHWEST);
441 					_game._player.setWalkTrigger(68);
442 					break;
443 
444 				case 67:
445 					_game._player._visible = true;
446 					break;
447 
448 				case 68:
449 					_globals._sequenceIndexes[1] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[1], false, 8, 1);
450 					_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
451 					_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], -1, -2);
452 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[1], SEQUENCE_TRIGGER_EXPIRE, 0, 69);
453 					_vm->_sound->command(25);
454 					break;
455 
456 				case 69:
457 					_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 5);
458 					_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
459 					_scene->_nextSceneId = 502;
460 					break;
461 
462 				default:
463 					break;
464 				}
465 			} else {
466 				switch (_game._trigger) {
467 				case (0):
468 					_game._player._stepEnabled = false;
469 					_game._player._visible = false;
470 					_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 5, 1);
471 					_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 1, 4);
472 					_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], true);
473 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 1);
474 					break;
475 
476 				case 1: {
477 					int idx = _globals._sequenceIndexes[3];
478 					_globals._sequenceIndexes[3] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[3], false, 4);
479 					_game.syncTimers(SYNC_SEQ, _globals._sequenceIndexes[3], SYNC_SEQ, idx);
480 					_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], false);
481 					_scene->_sequences.addTimer(15, 2);
482 					_vm->_sound->command(73);
483 						}
484 						break;
485 
486 				case 2:
487 					_scene->deleteSequence(_globals._sequenceIndexes[3]);
488 					_globals._sequenceIndexes[3] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[3], false, 5, 1);
489 					_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 1, 4);
490 					_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[3], false);
491 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
492 					break;
493 
494 				case 3:
495 					_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[3]);
496 					_game._player._visible = true;
497 					_vm->_dialogs->show(50120);
498 					_game._player._stepEnabled = true;
499 					break;
500 
501 				default:
502 					break;
503 				}
504 			}
505 		}
506 		_action._inProgress = false;
507 		return;
508 	}
509 
510 	if (_action._lookFlag) {
511 		_vm->_dialogs->show(50110);
512 		_action._inProgress = false;
513 		return;
514 	}
515 
516 	if (_action.isAction(VERB_LOOK) || _action.isAction(VERB_LOOK_AT)) {
517 		if (_action.isObject(NOUN_FLOOR)) {
518 			_vm->_dialogs->show(50111);
519 			_action._inProgress = false;
520 			return;
521 		}
522 
523 		if (_action.isObject(NOUN_WALL)) {
524 			_vm->_dialogs->show(50112);
525 			_action._inProgress = false;
526 			return;
527 		}
528 
529 		if (_action.isObject(NOUN_CEILING)) {
530 			_vm->_dialogs->show(50113);
531 			_action._inProgress = false;
532 			return;
533 		}
534 
535 		if (_action.isObject(NOUN_LAKE)) {
536 			_vm->_dialogs->show(50114);
537 			_action._inProgress = false;
538 			return;
539 		}
540 
541 		if (_action.isObject(NOUN_BOAT)) {
542 			_vm->_dialogs->show(50126);
543 			_action._inProgress = false;
544 			return;
545 		}
546 
547 		if (_action.isObject(NOUN_TORCH)) {
548 			_vm->_dialogs->show(50117);
549 			_action._inProgress = false;
550 			return;
551 		}
552 
553 		if (_action.isObject(NOUN_ARCHWAY_TO_WEST)) {
554 			_vm->_dialogs->show(50118);
555 			_action._inProgress = false;
556 			return;
557 		}
558 
559 		if (_action.isObject(NOUN_DOOR)) {
560 			if (_scene->_customDest.x < 287) {
561 				if (_game._visitedScenes.exists(506))
562 					_vm->_dialogs->show(50127);
563 				else
564 					_vm->_dialogs->show(50119);
565 			} else {
566 				if (_game._visitedScenes.exists(506))
567 					_vm->_dialogs->show(50128);
568 				else
569 					_vm->_dialogs->show(50119);
570 			}
571 			_action._inProgress = false;
572 			return;
573 		}
574 
575 		if (_action.isObject(NOUN_COLUMN)) {
576 			_vm->_dialogs->show(50121);
577 			_action._inProgress = false;
578 			return;
579 		}
580 
581 		if (_action.isObject(NOUN_CHRISTINE)) {
582 			_vm->_dialogs->show(50124);
583 			_action._inProgress = false;
584 			return;
585 		}
586 	}
587 
588 	if (_action.isAction(VERB_TAKE, NOUN_TORCH)) {
589 		_vm->_dialogs->show(50125);
590 		_action._inProgress = false;
591 		return;
592 	}
593 
594 	if (_action.isAction(VERB_TAKE, NOUN_CHRISTINE)) {
595 		_vm->_dialogs->show(50129);
596 		_action._inProgress = false;
597 	}
598 }
599 
preActions()600 void Scene501::preActions() {
601 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_ARCHWAY_TO_WEST)) {
602 		if (_globals[kLanternStatus] == 0) {
603 			_game._player._needToWalk = false;
604 			_vm->_dialogs->show(30918);
605 			_game._player.cancelCommand();
606 		} else if (!_globals[kChristineIsInBoat])
607 			_game.enterCatacombs(0);
608 	}
609 
610 	if ((_action.isObject(NOUN_DOOR)) && (_action.isAction(VERB_LOCK) || _action.isAction(VERB_UNLOCK) || _action.isAction(VERB_OPEN))) {
611 		if (_scene->_customDest.x < 287)
612 			_game._player.walk(Common::Point(266, 112), FACING_EAST);
613 		else
614 			_game._player.walk(Common::Point(287, 118), FACING_EAST);
615 	}
616 
617 	if ((_action.isAction(VERB_WALK_THROUGH, NOUN_DOOR) || _action.isAction(VERB_OPEN, NOUN_DOOR)) && _game._visitedScenes.exists(506) && _scene->_customDest.x < 287) {
618 		switch (_game._trigger) {
619 		case 0:
620 			_game._player._readyToWalk = false;
621 			_game._player._needToWalk = false;
622 			_game._player._stepEnabled = false;
623 			_vm->_gameConv->run(26);
624 			_vm->_gameConv->exportValue(2);
625 			_scene->_sequences.addTimer(6, 1);
626 			break;
627 
628 		case 1:
629 			if (_vm->_gameConv->activeConvId() >= 0)
630 				_scene->_sequences.addTimer(6, 1);
631 			else {
632 				_game._player._stepEnabled = true;
633 				_action._inProgress = true;
634 				_game._player._needToWalk = true;
635 				_game._player._readyToWalk = true;
636 			}
637 			break;
638 
639 		default:
640 			break;
641 		}
642 	}
643 
644 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_ARCHWAY_TO_WEST) && _globals[kLanternStatus] && _globals[kRightDoorIsOpen504])
645 		_game._player.walk(Common::Point(24, 110), FACING_WEST);
646 }
647 
648 /*------------------------------------------------------------------------*/
649 
Scene502(MADSEngine * vm)650 Scene502::Scene502(MADSEngine *vm) : Scene5xx(vm) {
651 	_fire1ActiveFl = false;
652 	_fire2ActiveFl = false;
653 	_fire3ActiveFl = false;
654 	_fire4ActiveFl = false;
655 	_panelTurningFl = false;
656 	_trapDoorHotspotEnabled = false;
657 	_acceleratedFireActivationFl = false;
658 
659 	for (int i = 0; i < 16; i++) {
660 		_puzzlePictures[i] = -1;
661 		_puzzleSprites[i] = -1;
662 		_puzzleSequences[i] = -1;
663 	}
664 
665 	_panelPushedNum = -1;
666 	_messageLevel = -1;
667 	_cycleStage = -1;
668 
669 	_nextPos = Common::Point(-1, -1);
670 
671 	_lastFrameTime = 0;
672 	_timer = 0;
673 	_deathTimer = 0;
674 
675 	_cyclePointer = nullptr;
676 }
677 
~Scene502()678 Scene502::~Scene502() {
679 	if (_cyclePointer)
680 		delete(_cyclePointer);
681 }
682 
synchronize(Common::Serializer & s)683 void Scene502::synchronize(Common::Serializer &s) {
684 	Scene5xx::synchronize(s);
685 
686 	s.syncAsByte(_fire1ActiveFl);
687 	s.syncAsByte(_fire2ActiveFl);
688 	s.syncAsByte(_fire3ActiveFl);
689 	s.syncAsByte(_fire4ActiveFl);
690 	s.syncAsByte(_panelTurningFl);
691 	s.syncAsByte(_trapDoorHotspotEnabled);
692 	s.syncAsByte(_acceleratedFireActivationFl);
693 
694 	for (int i = 0; i < 16; i++) {
695 		s.syncAsSint16LE(_puzzlePictures[i]);
696 		s.syncAsSint16LE(_puzzleSprites[i]);
697 		s.syncAsSint16LE(_puzzleSequences[i]);
698 	}
699 
700 	s.syncAsSint16LE(_panelPushedNum);
701 	s.syncAsSint16LE(_messageLevel);
702 	s.syncAsSint16LE(_cycleStage);
703 
704 	s.syncAsSint16LE(_nextPos.x);
705 	s.syncAsSint16LE(_nextPos.y);
706 
707 	s.syncAsUint32LE(_lastFrameTime);
708 	s.syncAsUint32LE(_timer);
709 	s.syncAsUint32LE(_deathTimer);
710 
711 	warning("more syncing required");
712 }
713 
setup()714 void Scene502::setup() {
715 	setPlayerSpritesPrefix();
716 	setAAName();
717 }
718 
enter()719 void Scene502::enter() {
720 	loadCyclingInfo();
721 	_scene->loadSpeech(7);
722 
723 	_panelPushedNum = -1;
724 	_panelTurningFl = false;
725 	_fire1ActiveFl = false;
726 	_fire2ActiveFl = false;
727 	_fire3ActiveFl = false;
728 	_fire4ActiveFl = false;
729 
730 	if (_scene->_priorSceneId != RETURNING_FROM_LOADING) {
731 		_lastFrameTime = _scene->_frameStartTime;
732 		_cycleStage = 0;
733 		_timer = 0;
734 		_deathTimer = 0;
735 		_messageLevel = 1;
736 		_acceleratedFireActivationFl = true;
737 		_trapDoorHotspotEnabled = false;
738 	}
739 
740 	_scene->_hotspots.activate(NOUN_ROPE, false);
741 	_scene->_hotspots.activateAtPos(NOUN_TRAP_DOOR, false, Common::Point(225, 28));
742 
743 	_globals._spriteIndexes[0] = _scene->_sprites.addSprites(formAnimName('x', 2));
744 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('x', 3));
745 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('x', 4));
746 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('x', 5));
747 	_globals._spriteIndexes[4] = _scene->_sprites.addSprites(formAnimName('a', 2));
748 	_globals._spriteIndexes[5] = _scene->_sprites.addSprites(formAnimName('x', 0));
749 	_globals._spriteIndexes[6] = _scene->_sprites.addSprites(formAnimName('x', 1));
750 	_globals._spriteIndexes[7] = _scene->_sprites.addSprites(formAnimName('a', 1));
751 	_globals._spriteIndexes[8] = _scene->_sprites.addSprites(formAnimName('a', 3));
752 	_globals._spriteIndexes[9] = _scene->_sprites.addSprites(formAnimName('x', 6));
753 	_globals._spriteIndexes[10] = _scene->_sprites.addSprites(formAnimName('a', 0));
754 	_globals._spriteIndexes[11] = _scene->_sprites.addSprites(formAnimName('j', 0));
755 	_globals._spriteIndexes[12] = _scene->_sprites.addSprites(formAnimName('k', 0));
756 	_globals._spriteIndexes[13] = _scene->_sprites.addSprites(formAnimName('l', 0));
757 	_globals._spriteIndexes[14] = _scene->_sprites.addSprites(formAnimName('m', 0));
758 	_globals._spriteIndexes[16] = _scene->_sprites.addSprites(formAnimName('h', 0));
759 
760 	if (_scene->_priorSceneId != RETURNING_FROM_LOADING) {
761 		_globals._sequenceIndexes[5] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[5], false, 1);
762 		_scene->_sequences.setDepth(_globals._sequenceIndexes[5], 14);
763 	} else
764 		_scene->drawToBackground(_globals._spriteIndexes[5], -2, Common::Point(-32000, -32000), 0, 100);
765 
766 	if ((_scene->_priorSceneId == 501) || (_scene->_priorSceneId != RETURNING_FROM_LOADING)) {
767 		if (!_game._visitedScenes._sceneRevisited) {
768 			if (_game._objects.isInInventory(OBJ_ROPE))
769 				_globals[kCableHookWasSeparate] = true;
770 			else
771 				_globals[kCableHookWasSeparate] = false;
772 		} else if (_globals[kCableHookWasSeparate]) {
773 			_game._objects.addToInventory(OBJ_ROPE);
774 			_game._objects.addToInventory(OBJ_CABLE_HOOK);
775 			_game._objects.setRoom(OBJ_ROPE_WITH_HOOK, NOWHERE);
776 		} else {
777 			_game._objects.setRoom(OBJ_ROPE, NOWHERE);
778 			_game._objects.setRoom(OBJ_CABLE_HOOK, NOWHERE);
779 			_game._objects.addToInventory(OBJ_ROPE_WITH_HOOK);
780 		}
781 
782 		_game._player._playerPos = Common::Point(43, 154);
783 		_game._player._facing = FACING_EAST;
784 		_game._player._stepEnabled = false;
785 		_game._player.walk(Common::Point(87, 153), FACING_EAST);
786 		_game._player.setWalkTrigger(77);
787 	}
788 
789 	room_502_initialize_panels();
790 
791 	if (_trapDoorHotspotEnabled) {
792 		_globals._sequenceIndexes[6] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[6], false, 6);
793 		_scene->_sequences.setDepth(_globals._sequenceIndexes[6], 1);
794 		_scene->_hotspots.activate(NOUN_TRAP_DOOR, false);
795 		_scene->_hotspots.activateAtPos(NOUN_TRAP_DOOR, true, Common::Point(225, 28));
796 		if (!_game._objects.isInInventory(OBJ_ROPE_WITH_HOOK) && !_game._objects.isInInventory(OBJ_CABLE_HOOK)) {
797 			_globals._sequenceIndexes[9] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[9], false, -2);
798 			_scene->_sequences.setDepth(_globals._sequenceIndexes[9], 12);
799 			_scene->_hotspots.activate(NOUN_ROPE, true);
800 		}
801 	} else {
802 		_globals._sequenceIndexes[6] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[6], false, 1);
803 		_scene->_sequences.setDepth(_globals._sequenceIndexes[6], 14);
804 	}
805 
806 	sceneEntrySound();
807 }
808 
step()809 void Scene502::step() {
810 	if (_acceleratedFireActivationFl) {
811 		int32 diff = _scene->_frameStartTime - _lastFrameTime;
812 		if ((diff >= 0) && (diff <= 4)) {
813 			_timer += diff;
814 			_deathTimer += diff;
815 		} else {
816 			_timer += 1;
817 			_deathTimer += 1;
818 		}
819 		_lastFrameTime = _scene->_frameStartTime;
820 
821 		if (_timer >= 300) {
822 			_timer = 0;
823 			if (_cycleStage < 8)
824 				++_cycleStage;
825 		}
826 	}
827 
828 	if ((_deathTimer >= 7200) && !_panelTurningFl) {
829 		_vm->_dialogs->show(50215);
830 		_game._player.walk(Common::Point(160, 148), FACING_NORTH);
831 		_game._player.setWalkTrigger(71);
832 		_game._player._stepEnabled = false;
833 		_panelTurningFl = true;
834 		_deathTimer = 0;
835 	}
836 
837 	if ((_deathTimer > 900) && (_messageLevel == 1) && !_panelTurningFl) {
838 		_messageLevel = 2;
839 		_vm->_dialogs->show(50212);
840 	}
841 
842 	if ((_deathTimer > 3600) && (_messageLevel == 2) && !_panelTurningFl) {
843 		_messageLevel = 3;
844 		_vm->_dialogs->show(50213);
845 	}
846 
847 	if ((_deathTimer > 5400) && (_messageLevel == 3) && !_panelTurningFl) {
848 		_messageLevel = 4;
849 		_vm->_dialogs->show(50214);
850 	}
851 
852 	switch (_game._trigger) {
853 	case 71:
854 		_game._player._stepEnabled = false;
855 		_game._player._visible = false;
856 		_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 7, 1);
857 		_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 1);
858 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], -1, -2);
859 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 72);
860 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_SPRITE, 44, 73);
861 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_SPRITE, 51, 74);
862 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_SPRITE, 32, 75);
863 		break;
864 
865 	case 72:
866 		_globals._sequenceIndexes[4] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[4], false, -2);
867 		_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 1);
868 		_scene->_userInterface.noInventoryAnim();
869 		// CHECKME: Not sure about the next function call
870 		_scene->_userInterface.refresh();
871 		_scene->_sequences.addTimer(120, 76);
872 		break;
873 
874 	case 73:
875 		_vm->_sound->command(1);
876 		_vm->_sound->command(67);
877 		break;
878 
879 	case 74:
880 		_vm->_sound->command(27);
881 		break;
882 
883 	case 75:
884 		_scene->playSpeech(7);
885 		break;
886 
887 	case 76:
888 		_scene->_reloadSceneFlag = true;
889 		break;
890 
891 	case 77:
892 		_scene->deleteSequence(_globals._sequenceIndexes[5]);
893 		_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 7, 1);
894 		_scene->_sequences.setDepth(_globals._sequenceIndexes[5], 1);
895 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], -1, -2);
896 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 78);
897 		break;
898 
899 	case 78:
900 		_vm->_dialogs->show(50211);
901 		_scene->drawToBackground(_globals._spriteIndexes[5], -2, Common::Point(-32000, -32000), 0, 100);
902 		_game._player._stepEnabled = true;
903 		break;
904 
905 	default:
906 		break;
907 	}
908 
909 	if (!_trapDoorHotspotEnabled)
910 		animateFireBursts();
911 
912 	setPaletteCycle();
913 }
914 
actions()915 void Scene502::actions() {
916 	if (_game._trigger >= 110) {
917 		handlePanelAnimation();
918 		_action._inProgress = false;
919 		return;
920 	}
921 
922 	switch (_game._trigger) {
923 	case 80:
924 		_globals._sequenceIndexes[6] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[6], false, 6);
925 		_scene->_hotspots.activateAtPos(NOUN_ROPE, true, Common::Point(225, 28));
926 		_scene->_sequences.setDepth(_globals._sequenceIndexes[6], 1);
927 		_scene->_hotspots.activate(NOUN_TRAP_DOOR, false);
928 		_scene->_hotspots.activateAtPos(NOUN_TRAP_DOOR, true, Common::Point(225, 28));
929 		if (!_panelTurningFl)
930 			_vm->_dialogs->show(50216);
931 
932 		_action._inProgress = false;
933 		return;
934 
935 	case 90:
936 		_game._player._stepEnabled = false;
937 		_game._player._visible = false;
938 		_globals._sequenceIndexes[10] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[10], false, 7, 2);
939 		_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[10], true);
940 		_scene->_sequences.setDepth(_globals._sequenceIndexes[10], 1);
941 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[10], 14, 18);
942 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[10], SEQUENCE_TRIGGER_EXPIRE, 0, 91);
943 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[10], SEQUENCE_TRIGGER_SPRITE, 18, 110);
944 		_action._inProgress = false;
945 		return;
946 
947 	case 91:
948 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[10]);
949 		_game._player._visible = true;
950 		_game._player._stepEnabled = true;
951 		_scene->_sequences.addTimer(5, 102);
952 		_action._inProgress = false;
953 		return;
954 
955 	case 95:
956 		_game._player._stepEnabled = false;
957 		_game._player._visible = false;
958 		_globals._sequenceIndexes[10] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[10], false, 7, 2);
959 		_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[10], true);
960 		_scene->_sequences.setDepth(_globals._sequenceIndexes[10], 1);
961 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[10], 8, 13);
962 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[10], SEQUENCE_TRIGGER_EXPIRE, 0, 96);
963 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[10], SEQUENCE_TRIGGER_SPRITE, 13, 110);
964 		_action._inProgress = false;
965 		return;
966 
967 	case 96:
968 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[10]);
969 		_game._player._visible = true;
970 		_game._player._stepEnabled = true;
971 		_scene->_sequences.addTimer(5, 102);
972 		_action._inProgress = false;
973 		return;
974 
975 	case 100:
976 		_game._player._stepEnabled = false;
977 		_game._player._visible = false;
978 		_globals._sequenceIndexes[10] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[10], false, 9, 2);
979 		_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[10], true);
980 		_scene->_sequences.setDepth(_globals._sequenceIndexes[10], 1);
981 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[10], 5, 7);
982 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[10], SEQUENCE_TRIGGER_EXPIRE, 0, 101);
983 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[10], SEQUENCE_TRIGGER_SPRITE, 7, 110);
984 		_action._inProgress = false;
985 		return;
986 
987 	case 101:
988 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[10]);
989 		_game._player._visible = true;
990 		_scene->_sequences.addTimer(5, 102);
991 		_action._inProgress = false;
992 		return;
993 
994 	case 102:
995 		_panelTurningFl = false;
996 		_game._player._stepEnabled = true;
997 		_action._inProgress = false;
998 		return;
999 
1000 	case 105:
1001 		_game._player._stepEnabled = false;
1002 		_game._player._visible = false;
1003 		_globals._sequenceIndexes[10] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[10], false, 8, 2);
1004 		_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[10], true);
1005 		_scene->_sequences.setDepth(_globals._sequenceIndexes[10], 1);
1006 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[10], 1, 4);
1007 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[10], SEQUENCE_TRIGGER_EXPIRE, 0, 106);
1008 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[10], SEQUENCE_TRIGGER_SPRITE, 4, 110);
1009 		_action._inProgress = false;
1010 		return;
1011 
1012 	case 106:
1013 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[10]);
1014 		_game._player._visible = true;
1015 		_scene->_sequences.addTimer(5, 102);
1016 		_action._inProgress = false;
1017 		return;
1018 
1019 	default:
1020 		break;
1021 	}
1022 
1023 	if (_action.isAction(VERB_PUSH, NOUN_PANEL)) {
1024 		if (_panelTurningFl) {
1025 			_action._inProgress = false;
1026 			return;
1027 		}
1028 
1029 		Common::Point walkToPos;
1030 		getPanelInfo(&walkToPos, &_panelPushedNum, _scene->_customDest, &_nextPos);
1031 		_panelTurningFl = true;
1032 
1033 		switch (_panelPushedNum) {
1034 		case 0:
1035 		case 1:
1036 		case 2:
1037 		case 3:
1038 			_scene->_sequences.addTimer(1, 90);
1039 			break;
1040 
1041 		case 4:
1042 		case 5:
1043 		case 6:
1044 		case 7:
1045 			_scene->_sequences.addTimer(1, 95);
1046 			break;
1047 
1048 		case 8:
1049 		case 9:
1050 		case 10:
1051 		case 11:
1052 			_scene->_sequences.addTimer(1, 100);
1053 			break;
1054 
1055 		default:
1056 			_scene->_sequences.addTimer(1, 105);
1057 			break;
1058 		}
1059 		_action._inProgress = false;
1060 		return;
1061 	}
1062 
1063 	if (_action.isAction(VERB_THROW, NOUN_ROPE_WITH_HOOK, NOUN_TRAP_DOOR) || _action.isAction(VERB_GRAPPLE, NOUN_TRAP_DOOR)) {
1064 		if (_trapDoorHotspotEnabled) {
1065 			switch (_game._trigger) {
1066 			case 0:
1067 				_game._player._stepEnabled = false;
1068 				_game._player._visible = false;
1069 				_panelTurningFl = true;
1070 				_globals._sequenceIndexes[7] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[7], false, 6, 1);
1071 				_scene->_sequences.setDepth(_globals._sequenceIndexes[7], 13);
1072 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[7], -1, -2);
1073 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[7], SEQUENCE_TRIGGER_EXPIRE, 0, 82);
1074 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[7], SEQUENCE_TRIGGER_SPRITE, 10, 83);
1075 				_game._objects.setRoom(OBJ_ROPE_WITH_HOOK, NOWHERE);
1076 				break;
1077 
1078 			case 82:
1079 				_game._player._stepEnabled = true;
1080 				_game._player._visible = true;
1081 				_panelTurningFl = false;
1082 				_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[7]);
1083 				_globals._sequenceIndexes[9] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[9], false, -2);
1084 				_scene->_sequences.setDepth(_globals._sequenceIndexes[9], 13);
1085 				_scene->_hotspots.activate(NOUN_ROPE, true);
1086 				break;
1087 
1088 			case 83:
1089 				_vm->_sound->command(69);
1090 				break;
1091 
1092 			default:
1093 				break;
1094 			}
1095 		} else
1096 			_vm->_dialogs->show(50229);
1097 
1098 		_action._inProgress = false;
1099 		return;
1100 	}
1101 
1102 	if (_action.isAction(VERB_CLIMB_THROUGH, NOUN_TRAP_DOOR)
1103 	 && (_game._objects.isInInventory(OBJ_ROPE_WITH_HOOK) || _game._objects.isInInventory(OBJ_CABLE_HOOK))) {
1104 		_vm->_dialogs->show(50228);
1105 		_action._inProgress = false;
1106 		return;
1107 	}
1108 
1109 	if (_action.isAction(VERB_THROW, NOUN_ROPE, NOUN_TRAP_DOOR)) {
1110 		_vm->_dialogs->show(50226);
1111 		_action._inProgress = false;
1112 		return;
1113 	}
1114 
1115 	if (_action.isAction(VERB_THROW, NOUN_CABLE_HOOK, NOUN_TRAP_DOOR)) {
1116 		_vm->_dialogs->show(50227);
1117 		_action._inProgress = false;
1118 		return;
1119 	}
1120 
1121 	if (_action.isAction(VERB_CLIMB, NOUN_ROPE) || _action.isAction(VERB_CLIMB_THROUGH, NOUN_TRAP_DOOR)) {
1122 		switch (_game._trigger) {
1123 		case 0:
1124 			_globals[kPlayerScore] += 5;
1125 			_game._player._stepEnabled = false;
1126 			_game._player._visible = false;
1127 			_panelTurningFl = true;
1128 			_globals._sequenceIndexes[8] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[8], false, 6, 1);
1129 			_scene->_sequences.setDepth(_globals._sequenceIndexes[8], 10);
1130 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[8], -1, -2);
1131 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[8], SEQUENCE_TRIGGER_EXPIRE, 0, 82);
1132 			break;
1133 
1134 		case 82:
1135 			_scene->_nextSceneId = 504;
1136 			break;
1137 
1138 		default:
1139 			break;
1140 		}
1141 		_action._inProgress = false;
1142 		return;
1143 	}
1144 
1145 	if (_action._lookFlag) {
1146 		_vm->_dialogs->show(50210);
1147 		_action._inProgress = false;
1148 		return;
1149 	}
1150 
1151 	if (_action.isAction(VERB_LOOK) || _action.isAction(VERB_LOOK_AT)) {
1152 		if (_action.isObject(NOUN_FLOOR)) {
1153 			_vm->_dialogs->show(50217);
1154 			_action._inProgress = false;
1155 			return;
1156 		}
1157 
1158 		if (_action.isObject(NOUN_TRAP_DOOR)) {
1159 			_vm->_dialogs->show(_trapDoorHotspotEnabled ? 50220 : 50225);
1160 			_action._inProgress = false;
1161 			return;
1162 		}
1163 
1164 		if (_action.isObject(NOUN_WALL)) {
1165 			_vm->_dialogs->show(50219);
1166 			_action._inProgress = false;
1167 			return;
1168 		}
1169 
1170 		if (_action.isObject(NOUN_DOOR)) {
1171 			_vm->_dialogs->show(50221);
1172 			_action._inProgress = false;
1173 			return;
1174 		}
1175 
1176 		if (_action.isObject(NOUN_PANELS)) {
1177 			_vm->_dialogs->show(50222);
1178 			_action._inProgress = false;
1179 			return;
1180 		}
1181 
1182 		if (_action.isObject(NOUN_PANEL)) {
1183 			_vm->_dialogs->show(50223);
1184 			_action._inProgress = false;
1185 			return;
1186 		}
1187 
1188 		if (_action.isObject(NOUN_CEILING)) {
1189 			_vm->_dialogs->show(50224);
1190 			_action._inProgress = false;
1191 			return;
1192 		}
1193 
1194 		if (_action.isObject(NOUN_ROPE) && !_game._objects.isInInventory(OBJ_ROPE)
1195 		 && !_game._objects.isInInventory(OBJ_CABLE_HOOK) && !_game._objects.isInInventory(OBJ_ROPE_WITH_HOOK)) {
1196 			_vm->_dialogs->show(50233);
1197 			_action._inProgress = false;
1198 			return;
1199 		}
1200 	}
1201 
1202 	if (_action.isAction(VERB_OPEN, NOUN_TRAP_DOOR)) {
1203 		_vm->_dialogs->show(_trapDoorHotspotEnabled ? 50230 : 50228);
1204 		_action._inProgress = false;
1205 		return;
1206 	}
1207 
1208 	if (_action.isAction(VERB_CLOSE, NOUN_TRAP_DOOR)) {
1209 		_vm->_dialogs->show(_trapDoorHotspotEnabled ? 50228 : 50231);
1210 		_action._inProgress = false;
1211 		return;
1212 	}
1213 
1214 	if (_action.isAction(VERB_TAKE, NOUN_ROPE) && !_game._objects.isInInventory(OBJ_ROPE)
1215 	 && !_game._objects.isInInventory(OBJ_CABLE_HOOK) && !_game._objects.isInInventory(OBJ_ROPE_WITH_HOOK)) {
1216 		_vm->_dialogs->show(50234);
1217 		_action._inProgress = false;
1218 		return;
1219 	}
1220 
1221 	if (_action.isAction(VERB_LASSO, NOUN_TRAP_DOOR)) {
1222 		_vm->_dialogs->show(50232);
1223 		_action._inProgress = false;
1224 		return;
1225 	}
1226 }
1227 
preActions()1228 void Scene502::preActions() {
1229 	int panel;
1230 
1231 	if (_action.isAction(VERB_PUSH, NOUN_PANEL)) {
1232 		Common::Point walkToPos;
1233 		Common::Point tmpPos;
1234 		getPanelInfo(&walkToPos, &panel, _scene->_customDest, &tmpPos);
1235 		_game._player.walk(walkToPos, FACING_NORTH);
1236 	}
1237 
1238 	if (_trapDoorHotspotEnabled && (_action.isAction(VERB_CLIMB, NOUN_ROPE) || _action.isAction(VERB_CLIMB_THROUGH, NOUN_TRAP_DOOR)))
1239 		_game._player.walk(Common::Point(211, 149), FACING_NORTH);
1240 
1241 	if (_trapDoorHotspotEnabled && (_action.isAction(VERB_THROW, NOUN_ROPE_WITH_HOOK, NOUN_TRAP_DOOR) || _action.isAction(VERB_GRAPPLE, NOUN_TRAP_DOOR)))
1242 		_game._player.walk(Common::Point(200, 149), FACING_NORTH);
1243 }
1244 
room_502_initialize_panels()1245 void Scene502::room_502_initialize_panels() {
1246 	for (int i = 0, curPuzzleSprite = 2, count = 1; i < 16; i++) {
1247 		if (_scene->_priorSceneId != RETURNING_FROM_LOADING)
1248 			_puzzlePictures[i] = _vm->getRandomNumber(1, 4);
1249 
1250 		curPuzzleSprite += (_puzzlePictures[i] * 3) - 3;
1251 		_puzzleSprites[i] = curPuzzleSprite;
1252 
1253 		int sprIdx;
1254 
1255 		switch (i) {
1256 		case 0:
1257 		case 1:
1258 		case 2:
1259 		case 3:
1260 			sprIdx = _globals._spriteIndexes[11];
1261 			break;
1262 
1263 		case 4:
1264 		case 5:
1265 		case 6:
1266 		case 7:
1267 			sprIdx = _globals._spriteIndexes[12];
1268 			break;
1269 
1270 		case 8:
1271 		case 9:
1272 		case 10:
1273 		case 11:
1274 			sprIdx = _globals._spriteIndexes[13];
1275 			break;
1276 
1277 		default:
1278 			sprIdx = _globals._spriteIndexes[14];
1279 			break;
1280 		}
1281 
1282 		_globals._sequenceIndexes[15] = _scene->_sequences.addStampCycle(sprIdx, false, curPuzzleSprite);
1283 		_scene->_sequences.setDepth(_globals._sequenceIndexes[15], 14);
1284 		_puzzleSequences[i] = _globals._sequenceIndexes[15];
1285 
1286 		++count;
1287 		if (count >= 5)
1288 			count = 1;
1289 
1290 		switch (count) {
1291 		case 1:
1292 			curPuzzleSprite = 2;
1293 			break;
1294 
1295 		case 2:
1296 			curPuzzleSprite = 14;
1297 			break;
1298 
1299 		case 3:
1300 			curPuzzleSprite = 26;
1301 			break;
1302 
1303 		case 4:
1304 			curPuzzleSprite = 38;
1305 			break;
1306 
1307 		default:
1308 			break;
1309 		}
1310 	}
1311 }
1312 
loadCyclingInfo()1313 void Scene502::loadCyclingInfo() {
1314 	warning("TODO: loadCyclingInfo");
1315 }
1316 
animateFireBursts()1317 void Scene502::animateFireBursts() {
1318 	int rndTrigger;
1319 
1320 	if (_acceleratedFireActivationFl)
1321 		rndTrigger = _vm->getRandomNumber(1, 50);
1322 	else
1323 		rndTrigger = _vm->getRandomNumber(1, 400);
1324 
1325 	if (rndTrigger == 1) {
1326 		rndTrigger = _vm->getRandomNumber(1, 4);
1327 
1328 		switch (rndTrigger) {
1329 		case 1:
1330 			if (!_fire1ActiveFl) {
1331 				_scene->_sequences.addTimer(_vm->getRandomNumber(300, 600), 60);
1332 				_fire1ActiveFl = true;
1333 			}
1334 			break;
1335 
1336 		case 2:
1337 			if (!_fire2ActiveFl) {
1338 				_scene->_sequences.addTimer(_vm->getRandomNumber(300, 600), 63);
1339 				_fire2ActiveFl = true;
1340 			}
1341 			break;
1342 
1343 		case 3:
1344 			if (!_fire3ActiveFl) {
1345 				_scene->_sequences.addTimer(_vm->getRandomNumber(300, 600), 66);
1346 				_fire3ActiveFl = true;
1347 			}
1348 			break;
1349 
1350 		case 4:
1351 			if (!_fire4ActiveFl) {
1352 				_scene->_sequences.addTimer(_vm->getRandomNumber(300, 600), 69);
1353 				_fire4ActiveFl = true;
1354 			}
1355 			break;
1356 
1357 		default:
1358 			break;
1359 		}
1360 	}
1361 
1362 	switch (_game._trigger) {
1363 	case 60:
1364 		if ((_game._player._playerPos.x < 198) || (_game._player._playerPos.y > 150)) {
1365 			_globals._sequenceIndexes[0] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[0], false, 5, 1);
1366 			_scene->_sequences.setDepth(_globals._sequenceIndexes[0], 14);
1367 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[0], 1, 10);
1368 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[0], SEQUENCE_TRIGGER_EXPIRE, 0, 61);
1369 		}
1370 		break;
1371 
1372 	case 61:
1373 		_fire1ActiveFl = false;
1374 		break;
1375 
1376 	case 63:
1377 		if ((_game._player._playerPos.x > 127) || (_game._player._playerPos.y < 150)) {
1378 			_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 5, 1);
1379 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
1380 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], 1, 10);
1381 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[1], SEQUENCE_TRIGGER_EXPIRE, 0, 64);
1382 		}
1383 		break;
1384 
1385 	case 64:
1386 		_fire2ActiveFl = false;
1387 		break;
1388 
1389 	case 66:
1390 		if (_game._player._playerPos.x < 198) {
1391 			_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 5, 1);
1392 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
1393 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 1, 10);
1394 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 67);
1395 		}
1396 		break;
1397 
1398 	case 67:
1399 		_fire3ActiveFl = false;
1400 		break;
1401 
1402 	case 69:
1403 		if ((_game._player._playerPos.x > 110) || (_game._player._playerPos.y > 150)) {
1404 			_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 5, 1);
1405 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 14);
1406 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 1, 10);
1407 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 70);
1408 		}
1409 		break;
1410 
1411 	case 70:
1412 		_fire4ActiveFl = false;
1413 		break;
1414 
1415 	default:
1416 		break;
1417 	}
1418 }
1419 
setPaletteCycle()1420 void Scene502::setPaletteCycle() {
1421 	warning("TODO: setPaletteCycle");
1422 }
1423 
getPanelInfo(Common::Point * walkToPos,int * panel,Common::Point mousePos,Common::Point * interimPos)1424 void Scene502::getPanelInfo(Common::Point *walkToPos, int *panel, Common::Point mousePos, Common::Point *interimPos) {
1425 	walkToPos->y = 148;
1426 
1427 	if ((mousePos.x < 120) || (mousePos.y < 75) || (mousePos.y > 137))
1428 		return;
1429 
1430 	if (mousePos.x <= 139) {
1431 		interimPos->x = 129;
1432 		if (mousePos.y <= 90) {
1433 			*panel = 0;
1434 			interimPos->y = 90;
1435 			walkToPos->x = 107;
1436 		} else if (mousePos.y <= 106) {
1437 			*panel = 4;
1438 			interimPos->y = 106;
1439 			walkToPos->x = 107;
1440 		} else if (mousePos.y <= 122) {
1441 			*panel = 8;
1442 			interimPos->y = 122;
1443 			walkToPos->x = 107;
1444 		} else {
1445 			*panel = 12;
1446 			interimPos->y = 138;
1447 			walkToPos->x = 107;
1448 		}
1449 	} else if (mousePos.x <= 159) {
1450 		interimPos->x = 149;
1451 		if (mousePos.y <= 90) {
1452 			*panel = 1;
1453 			interimPos->y = 90;
1454 			walkToPos->x = 127;
1455 		} else if (mousePos.y <= 106) {
1456 			*panel = 5;
1457 			interimPos->y = 106;
1458 			walkToPos->x = 127;
1459 		} else if (mousePos.y <= 122) {
1460 			*panel = 9;
1461 			interimPos->y = 122;
1462 			walkToPos->x = 127;
1463 		} else {
1464 			*panel = 13;
1465 			interimPos->y = 138;
1466 			walkToPos->x = 127;
1467 		}
1468 	} else if (mousePos.x <= 179) {
1469 		interimPos->x = 169;
1470 		if (mousePos.y <= 90) {
1471 			*panel = 2;
1472 			interimPos->y = 90;
1473 			walkToPos->x = 147;
1474 		} else if (mousePos.y <= 106) {
1475 			*panel = 6;
1476 			interimPos->y = 106;
1477 			walkToPos->x = 147;
1478 		} else if (mousePos.y <= 122) {
1479 			*panel = 10;
1480 			interimPos->y = 122;
1481 			walkToPos->x = 147;
1482 		} else {
1483 			*panel = 14;
1484 			interimPos->y = 138;
1485 			walkToPos->x = 147;
1486 		}
1487 	} else if (mousePos.x <= 199) {
1488 		interimPos->x = 189;
1489 		if (mousePos.y <= 90) {
1490 			*panel = 3;
1491 			interimPos->y = 90;
1492 			walkToPos->x = 167;
1493 		} else if (mousePos.y <= 106) {
1494 			*panel = 7;
1495 			interimPos->y = 106;
1496 			walkToPos->x = 167;
1497 		} else if (mousePos.y <= 122) {
1498 			*panel = 11;
1499 			interimPos->y = 122;
1500 			walkToPos->x = 167;
1501 		} else {
1502 			*panel = 15;
1503 			interimPos->y = 138;
1504 			walkToPos->x = 167;
1505 		}
1506 	}
1507 }
1508 
handlePanelAnimation()1509 void Scene502::handlePanelAnimation() {
1510 	switch (_game._trigger) {
1511 	case 110:
1512 		_vm->_sound->command(65);
1513 		_scene->deleteSequence(_puzzleSequences[_panelPushedNum]);
1514 		switch (_panelPushedNum) {
1515 		case 0:
1516 		case 1:
1517 		case 2:
1518 		case 3:
1519 			_globals._sequenceIndexes[11] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[11], false, _puzzleSprites[_panelPushedNum] - 1);
1520 			_scene->_sequences.setDepth(_globals._sequenceIndexes[11], 14);
1521 			_scene->_sequences.addTimer(5, 111);
1522 			break;
1523 
1524 		case 4:
1525 		case 5:
1526 		case 6:
1527 		case 7:
1528 			_globals._sequenceIndexes[12] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[12], false, _puzzleSprites[_panelPushedNum] - 1);
1529 			_scene->_sequences.setDepth(_globals._sequenceIndexes[12], 14);
1530 			_scene->_sequences.addTimer(5, 111);
1531 			break;
1532 
1533 		case 8:
1534 		case 9:
1535 		case 10:
1536 		case 11:
1537 			_globals._sequenceIndexes[13] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[13], false, _puzzleSprites[_panelPushedNum] - 1);
1538 			_scene->_sequences.setDepth(_globals._sequenceIndexes[13], 14);
1539 			_scene->_sequences.addTimer(5, 111);
1540 			break;
1541 
1542 		default:
1543 			_globals._sequenceIndexes[14] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[14], false, _puzzleSprites[_panelPushedNum] - 1);
1544 			_scene->_sequences.setDepth(_globals._sequenceIndexes[14], 14);
1545 			_scene->_sequences.addTimer(5, 111);
1546 			break;
1547 		}
1548 		break;
1549 
1550 	case 111:
1551 		switch (_panelPushedNum) {
1552 		case 0:
1553 		case 1:
1554 		case 2:
1555 		case 3:
1556 			_scene->deleteSequence(_globals._sequenceIndexes[11]);
1557 			break;
1558 
1559 		case 4:
1560 		case 5:
1561 		case 6:
1562 		case 7:
1563 			_scene->deleteSequence(_globals._sequenceIndexes[12]);
1564 			break;
1565 
1566 		case 8:
1567 		case 9:
1568 		case 10:
1569 		case 11:
1570 			_scene->deleteSequence(_globals._sequenceIndexes[13]);
1571 			break;
1572 
1573 		default:
1574 			_scene->deleteSequence(_globals._sequenceIndexes[14]);
1575 			break;
1576 		}
1577 
1578 		_globals._sequenceIndexes[16] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[16], false, 5, 1);
1579 		_scene->_sequences.setDepth(_globals._sequenceIndexes[16], 14);
1580 		_scene->_sequences.setPosition(_globals._sequenceIndexes[16], _nextPos);
1581 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[16], -1, -2);
1582 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[16], SEQUENCE_TRIGGER_EXPIRE, 0, 112);
1583 		break;
1584 
1585 	case 112: {
1586 		int idx = _globals._sequenceIndexes[16];
1587 		int newSprId = _puzzleSprites[_panelPushedNum] + 4;
1588 
1589 		switch (_panelPushedNum) {
1590 		case 0:
1591 		case 4:
1592 		case 8:
1593 		case 12:
1594 			if (newSprId > 12)
1595 				newSprId = 3;
1596 			break;
1597 
1598 		case 1:
1599 		case 5:
1600 		case 9:
1601 		case 13:
1602 			if (newSprId > 24)
1603 				newSprId = 15;
1604 			break;
1605 
1606 		case 2:
1607 		case 6:
1608 		case 10:
1609 		case 14:
1610 			if (newSprId > 36)
1611 				newSprId = 27;
1612 			break;
1613 
1614 		default:
1615 			if (newSprId > 48)
1616 				newSprId = 39;
1617 			break;
1618 		}
1619 
1620 		switch (_panelPushedNum) {
1621 		case 0:
1622 		case 1:
1623 		case 2:
1624 		case 3:
1625 			_globals._sequenceIndexes[11] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[11], false, newSprId);
1626 			_scene->_sequences.setDepth(_globals._sequenceIndexes[11], 14);
1627 			_game.syncTimers(SYNC_SEQ, _globals._sequenceIndexes[11], SYNC_SEQ, idx);
1628 			_scene->_sequences.addTimer(5, 113);
1629 			break;
1630 
1631 		case 4:
1632 		case 5:
1633 		case 6:
1634 		case 7:
1635 			_globals._sequenceIndexes[12] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[12], false, newSprId);
1636 			_scene->_sequences.setDepth(_globals._sequenceIndexes[12], 14);
1637 			_game.syncTimers(SYNC_SEQ, _globals._sequenceIndexes[12], SYNC_SEQ, idx);
1638 			_scene->_sequences.addTimer(5, 113);
1639 			break;
1640 
1641 		case 8:
1642 		case 9:
1643 		case 10:
1644 		case 11:
1645 			_globals._sequenceIndexes[13] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[13], false, newSprId);
1646 			_scene->_sequences.setDepth(_globals._sequenceIndexes[13], 14);
1647 			_game.syncTimers(SYNC_SEQ, _globals._sequenceIndexes[13], SYNC_SEQ, idx);
1648 			_scene->_sequences.addTimer(5, 113);
1649 			break;
1650 
1651 		default:
1652 			_globals._sequenceIndexes[14] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[14], false, newSprId);
1653 			_scene->_sequences.setDepth(_globals._sequenceIndexes[14], 14);
1654 			_game.syncTimers(SYNC_SEQ, _globals._sequenceIndexes[14], SYNC_SEQ, idx);
1655 			_scene->_sequences.addTimer(5, 113);
1656 			break;
1657 		}
1658 		}
1659 		break;
1660 
1661 	case 113: {
1662 		switch (_panelPushedNum) {
1663 		case 0:
1664 		case 1:
1665 		case 2:
1666 		case 3:
1667 			_scene->deleteSequence(_globals._sequenceIndexes[11]);
1668 			break;
1669 
1670 		case 4:
1671 		case 5:
1672 		case 6:
1673 		case 7:
1674 			_scene->deleteSequence(_globals._sequenceIndexes[12]);
1675 			break;
1676 
1677 		case 8:
1678 		case 9:
1679 		case 10:
1680 		case 11:
1681 			_scene->deleteSequence(_globals._sequenceIndexes[13]);
1682 			break;
1683 
1684 		default:
1685 			_scene->deleteSequence(_globals._sequenceIndexes[14]);
1686 			break;
1687 		}
1688 
1689 		int newSprId = _puzzleSprites[_panelPushedNum] + 3;
1690 
1691 		switch (_panelPushedNum) {
1692 		case 0:
1693 		case 4:
1694 		case 8:
1695 		case 12:
1696 			if (newSprId > 12)
1697 				newSprId = 2;
1698 			break;
1699 
1700 		case 1:
1701 		case 5:
1702 		case 9:
1703 		case 13:
1704 			if (newSprId > 24)
1705 				newSprId = 14;
1706 			break;
1707 
1708 		case 2:
1709 		case 6:
1710 		case 10:
1711 		case 14:
1712 			if (newSprId > 36)
1713 				newSprId = 26;
1714 			break;
1715 
1716 		default:
1717 			if (newSprId > 48)
1718 				newSprId = 38;
1719 			break;
1720 		}
1721 		_puzzleSprites[_panelPushedNum] = newSprId;
1722 		++_puzzlePictures[_panelPushedNum];
1723 		if (_puzzlePictures[_panelPushedNum] >= 5)
1724 			_puzzlePictures[_panelPushedNum] = 1;
1725 
1726 		switch (_panelPushedNum) {
1727 		case 0:
1728 		case 1:
1729 		case 2:
1730 		case 3:
1731 			_globals._sequenceIndexes[11] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[11], false, newSprId);
1732 			_scene->_sequences.setDepth(_globals._sequenceIndexes[11], 14);
1733 			_puzzleSequences[_panelPushedNum] = _globals._sequenceIndexes[11];
1734 			break;
1735 
1736 		case 4:
1737 		case 5:
1738 		case 6:
1739 		case 7:
1740 			_globals._sequenceIndexes[12] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[12], false, newSprId);
1741 			_scene->_sequences.setDepth(_globals._sequenceIndexes[12], 14);
1742 			_puzzleSequences[_panelPushedNum] = _globals._sequenceIndexes[12];
1743 			break;
1744 
1745 		case 8:
1746 		case 9:
1747 		case 10:
1748 		case 11:
1749 			_globals._sequenceIndexes[13] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[13], false, newSprId);
1750 			_scene->_sequences.setDepth(_globals._sequenceIndexes[13], 14);
1751 			_puzzleSequences[_panelPushedNum] = _globals._sequenceIndexes[13];
1752 			break;
1753 
1754 		default:
1755 			_globals._sequenceIndexes[14] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[14], false, newSprId);
1756 			_scene->_sequences.setDepth(_globals._sequenceIndexes[14], 14);
1757 			_puzzleSequences[_panelPushedNum] = _globals._sequenceIndexes[14];
1758 			break;
1759 		}
1760 
1761 		int puzzleSolvedFl = true;
1762 		for (int i = 0; i < 16; i++) {
1763 			if (_puzzlePictures[i] != 1)
1764 				puzzleSolvedFl = false;
1765 		}
1766 
1767 		if (puzzleSolvedFl && !_trapDoorHotspotEnabled) {
1768 			_trapDoorHotspotEnabled = true;
1769 			_scene->deleteSequence(_globals._sequenceIndexes[6]);
1770 			_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('t', 1), 80);
1771 		}
1772 		}
1773 		break;
1774 
1775 	default:
1776 		break;
1777 	}
1778 }
1779 
1780 /*------------------------------------------------------------------------*/
1781 
Scene504(MADSEngine * vm)1782 Scene504::Scene504(MADSEngine *vm) : Scene5xx(vm) {
1783 	_anim0ActvFl = false;
1784 	_anim1ActvFl = false;
1785 	_anim2ActvFl = false;
1786 	_anim3ActvFl = false;
1787 	_anim4ActvFl = false;
1788 	_anim5ActvFl = false;
1789 	_playingMusicFl = false;
1790 	_chairDialogDoneFl = false;
1791 	_fireBreathFl = false;
1792 
1793 	_songNum = -1;
1794 	_input3Count = -1;
1795 	_playCount = -1;
1796 	_listenStatus = -1;
1797 	_listenFrame = -1;
1798 	_chairStatus = -1;
1799 	_chairFrame = -1;
1800 	_playStatus = -1;
1801 	_playFrame = -1;
1802 	_phantomStatus = -1;
1803 	_phantomFrame = -1;
1804 	_christineTalkCount = -1;
1805 	_deathCounter = -1;
1806 }
1807 
synchronize(Common::Serializer & s)1808 void Scene504::synchronize(Common::Serializer &s) {
1809 	Scene5xx::synchronize(s);
1810 
1811 	s.syncAsByte(_anim0ActvFl);
1812 	s.syncAsByte(_anim1ActvFl);
1813 	s.syncAsByte(_anim2ActvFl);
1814 	s.syncAsByte(_anim3ActvFl);
1815 	s.syncAsByte(_anim4ActvFl);
1816 	s.syncAsByte(_anim5ActvFl);
1817 	s.syncAsByte(_playingMusicFl);
1818 	s.syncAsByte(_chairDialogDoneFl);
1819 	s.syncAsByte(_fireBreathFl);
1820 
1821 	s.syncAsSint16LE(_songNum);
1822 	s.syncAsSint16LE(_input3Count);
1823 	s.syncAsSint16LE(_playCount);
1824 	s.syncAsSint16LE(_listenStatus);
1825 	s.syncAsSint16LE(_listenFrame);
1826 	s.syncAsSint16LE(_chairStatus);
1827 	s.syncAsSint16LE(_chairFrame);
1828 	s.syncAsSint16LE(_playStatus);
1829 	s.syncAsSint16LE(_playFrame);
1830 	s.syncAsSint16LE(_phantomStatus);
1831 	s.syncAsSint16LE(_phantomFrame);
1832 	s.syncAsSint16LE(_christineTalkCount);
1833 	s.syncAsSint16LE(_deathCounter);
1834 }
1835 
setup()1836 void Scene504::setup() {
1837 	setPlayerSpritesPrefix();
1838 	setAAName();
1839 
1840 	_scene->addActiveVocab(NOUN_PHANTOM);
1841 	_scene->addActiveVocab(NOUN_CHRISTINE);
1842 }
1843 
enter()1844 void Scene504::enter() {
1845 	_vm->_disableFastwalk = true;
1846 
1847 	_input3Count = 0;
1848 	_deathCounter = 0;
1849 	_anim2ActvFl = false;
1850 
1851 	if (_scene->_priorSceneId != RETURNING_FROM_LOADING) {
1852 		_playCount = 0;
1853 		_anim0ActvFl = false;
1854 		_anim1ActvFl = false;
1855 		_anim3ActvFl = false;
1856 		_anim4ActvFl = false;
1857 		_anim5ActvFl = false;
1858 		_playingMusicFl = false;
1859 		_fireBreathFl = false;
1860 		_chairDialogDoneFl = false;
1861 		_songNum = 0;
1862 		_phantomStatus = 0;
1863 	}
1864 
1865 	_scene->_hotspots.activate(NOUN_CHRISTINE, false);
1866 
1867 	if (!_globals[kRightDoorIsOpen504]) {
1868 		_vm->_gameConv->load(19);
1869 		_vm->_gameConv->load(27);
1870 	} else
1871 		_vm->_gameConv->load(21);
1872 
1873 	_vm->_gameConv->load(26);
1874 
1875 	_globals._spriteIndexes[14] = _scene->_sprites.addSprites("*RDR_9");
1876 	_globals._spriteIndexes[15] = _scene->_sprites.addSprites(formAnimName('x', 8));
1877 
1878 	if (!_game._objects.isInRoom(OBJ_MUSIC_SCORE)) {
1879 		_globals._sequenceIndexes[15] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[15], false, 1);
1880 		_scene->_sequences.setDepth(_globals._sequenceIndexes[15], 14);
1881 		_scene->_hotspots.activate(NOUN_MUSIC_SCORE, false);
1882 	}
1883 
1884 	_globals._spriteIndexes[0] = _scene->_sprites.addSprites(formAnimName('x', 2));
1885 	_globals._spriteIndexes[13] = _scene->_sprites.addSprites(formAnimName('x', 7), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1886 
1887 	if (_globals[kFightStatus] == 0)
1888 		_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('x', 1));
1889 
1890 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('x', 3));
1891 
1892 	if ((_scene->_priorSceneId == 505) || ((_scene->_priorSceneId == 504) && _globals[kRightDoorIsOpen504])) {
1893 		if ((_globals[kFightStatus] == 0) && (_globals[kCoffinStatus] == 2)) {
1894 			_scene->_hotspots.activate(NOUN_CHRISTINE, true);
1895 			_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
1896 
1897 			_globals._spriteIndexes[13] = _scene->_sprites.addSprites(formAnimName('x', 7), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1898 			_globals._spriteIndexes[6] = _scene->_sprites.addSprites(formAnimName('b', 0));
1899 
1900 			_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_6", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1901 			_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACERAL", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1902 			_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACEXDFR", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1903 			_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACEPHN", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1904 
1905 			_globals._spriteIndexes[11] = _scene->_sprites.addSprites(formAnimName('a', 5));
1906 			_globals._spriteIndexes[10] = _scene->_sprites.addSprites(formAnimName('a', 3), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1907 			_globals._spriteIndexes[7] = _scene->_sprites.addSprites(formAnimName('a', 6), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1908 			_globals._spriteIndexes[8] = _scene->_sprites.addSprites(formAnimName('a', 7), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1909 			_globals._spriteIndexes[9] = _scene->_sprites.addSprites(formAnimName('a', 0), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1910 
1911 			_globals._animationIndexes[3] = _scene->loadAnimation(formAnimName('p', 1), 0);
1912 			int hotspotIdx = _scene->_dynamicHotspots.add(NOUN_PHANTOM, VERB_LOOK_AT, SYNTAX_MASC_NOT_PROPER, EXT_NONE, Common::Rect(0, 0, 0, 0));
1913 			_scene->_dynamicHotspots[hotspotIdx]._articleNumber = PREP_ON;
1914 			_scene->_dynamicHotspots.setPosition(hotspotIdx, Common::Point(-2, -2), FACING_NONE);
1915 
1916 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 4);
1917 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 8);
1918 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 13);
1919 
1920 			_phantomStatus = 0;
1921 			_game._player._stepEnabled = false;
1922 			_game._player._visible = false;
1923 			_anim3ActvFl = true;
1924 		} else {
1925 			if (_globals[kFightStatus])
1926 				_scene->drawToBackground(_globals._spriteIndexes[13], 1, Common::Point(-32000, -32000), 0, 100);
1927 
1928 			if (_globals[kCoffinStatus] != 2) {
1929 				_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 1);
1930 				_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 14);
1931 			}
1932 
1933 			_game._player._playerPos = Common::Point(317, 115);
1934 			_game._player._facing = FACING_SOUTHWEST;
1935 			_game._player.walk(Common::Point(279, 121), FACING_SOUTHWEST);
1936 
1937 			_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
1938 
1939 			if (!_game._visitedScenes.exists(506) && (_globals[kCoffinStatus] == 2)) {
1940 				_scene->changeVariant(1);
1941 
1942 				_scene->drawToBackground(_globals._spriteIndexes[13], 1, Common::Point(-32000, -32000), 0, 100);
1943 				_anim5ActvFl = true;
1944 
1945 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_2");
1946 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACERAL", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1947 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACEXDFR",PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1948 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACEPHN", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
1949 
1950 				_globals._animationIndexes[3] = _scene->loadAnimation(formAnimName('p', 3), 0);
1951 				int hotspotIdx = _scene->_dynamicHotspots.add(NOUN_CHRISTINE, VERB_WALK_TO, SYNTAX_SINGULAR_FEM, EXT_NONE, Common::Rect(0, 0, 0, 0));
1952 				_phantomStatus = 5;
1953 				_scene->_dynamicHotspots[hotspotIdx]._articleNumber = PREP_ON;
1954 				_scene->setAnimFrame(_globals._animationIndexes[3], 79);
1955 				_scene->_dynamicHotspots.setPosition(hotspotIdx, Common::Point(66, 119), FACING_NORTHWEST);
1956 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 0);
1957 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 1);
1958 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 2);
1959 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 3);
1960 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 4);
1961 			}
1962 		}
1963 	} else if (_scene->_priorSceneId == 506) {
1964 		_game._player._playerPos = Common::Point(0, 109);
1965 		_game._player._facing = FACING_SOUTHEAST;
1966 		_game._player.walk(Common::Point(39, 118), FACING_SOUTHEAST);
1967 		_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
1968 		_scene->drawToBackground(_globals._spriteIndexes[13], 1, Common::Point(-32000, -32000), 0, 100);
1969 	} else if (_scene->_priorSceneId == 504) {
1970 		_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 1);
1971 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 14);
1972 
1973 		_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('x', 0));
1974 		_globals._sequenceIndexes[2] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[2], false, 1);
1975 		_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 14);
1976 		_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
1977 
1978 		_game._player._playerPos = Common::Point(147, 131);
1979 		_game._player._facing = FACING_EAST;
1980 	} else if ((_scene->_priorSceneId == 502) || (_scene->_priorSceneId != RETURNING_FROM_LOADING)) {
1981 		_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 1);
1982 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 14);
1983 
1984 		_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('x', 0));
1985 		_globals._sequenceIndexes[2] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[2], false, 1);
1986 		_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 14);
1987 
1988 		_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('t', 1), 60);
1989 		_game._player._stepEnabled = false;
1990 		_game._player._visible = false;
1991 		_game._player._playerPos = Common::Point(147, 131);
1992 		_game._player._facing = FACING_EAST;
1993 	}
1994 
1995 	if (_scene->_priorSceneId == RETURNING_FROM_LOADING) {
1996 		if (!_globals[kRightDoorIsOpen504]) {
1997 			_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('x', 0));
1998 			_globals._sequenceIndexes[2] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[2], false, 1);
1999 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 14);
2000 		}
2001 
2002 		if (_vm->_gameConv->restoreRunning() == 19) {
2003 			_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
2004 			_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 1);
2005 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 14);
2006 
2007 			_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('l', 1), 67);
2008 			_anim0ActvFl = true;
2009 			_game._player._visible = false;
2010 			_game._player._stepEnabled = false;
2011 			_game._player._playerPos = Common::Point(286, 120);
2012 			_game._player._facing = FACING_EAST;
2013 			_listenStatus = 0;
2014 			_scene->setAnimFrame(_globals._animationIndexes[0], 8);
2015 			_vm->_gameConv->run(19);
2016 			_vm->_gameConv->exportValue(_game._difficulty);
2017 		} else if (_vm->_gameConv->restoreRunning() == 27) {
2018 			_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
2019 			_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 1);
2020 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 14);
2021 
2022 			_globals._spriteIndexes[4] = _scene->_sprites.addSprites(formAnimName('x', 4), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2023 			_globals._spriteIndexes[5] = _scene->_sprites.addSprites(formAnimName('x', 5), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2024 			_globals._animationIndexes[1] = _scene->loadAnimation(formAnimName('o', 1), 100);
2025 
2026 			_scene->setAnimFrame(_globals._animationIndexes[1], 22);
2027 			_game._player._stepEnabled = false;
2028 			_game._player._visible = false;
2029 			_playingMusicFl = false;
2030 			_anim1ActvFl = true;
2031 			_playStatus = 0;
2032 			_vm->_gameConv->run(27);
2033 		} else if ((_globals[kFightStatus] <= 1) && (_globals[kCoffinStatus] == 2)) {
2034 			if ((_phantomStatus == 1) || (_phantomStatus == 2)) {
2035 				_scene->_hotspots.activate(NOUN_CHRISTINE, true);
2036 				_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
2037 
2038 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites(formAnimName('b', 0));
2039 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_6", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2040 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACERAL", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2041 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACEXDFR", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2042 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACEPHN", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2043 
2044 				_globals._spriteIndexes[11] = _scene->_sprites.addSprites(formAnimName('a', 5));
2045 				_globals._spriteIndexes[10] = _scene->_sprites.addSprites(formAnimName('a', 3), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2046 				_globals._spriteIndexes[7] = _scene->_sprites.addSprites(formAnimName('a', 6), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2047 				_globals._spriteIndexes[8] = _scene->_sprites.addSprites(formAnimName('a', 7), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2048 				_globals._spriteIndexes[9] = _scene->_sprites.addSprites(formAnimName('a', 0), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2049 
2050 				_globals._animationIndexes[3] = _scene->loadAnimation(formAnimName('p', 1), 0);
2051 				int hotspotIdx = _scene->_dynamicHotspots.add(NOUN_PHANTOM, VERB_LOOK_AT, SYNTAX_MASC_NOT_PROPER, EXT_NONE, Common::Rect(0, 0, 0, 0));
2052 				_scene->_dynamicHotspots[hotspotIdx]._articleNumber = PREP_ON;
2053 				_scene->_dynamicHotspots.setPosition(hotspotIdx, Common::Point(-2, -2), FACING_NONE);
2054 
2055 				if (_phantomStatus == 1)
2056 					_scene->setAnimFrame(_globals._animationIndexes[3], _vm->getRandomNumber(109, 112));
2057 				else if (_phantomStatus == 2) {
2058 					_scene->setAnimFrame(_globals._animationIndexes[3], _vm->getRandomNumber(148, 150));
2059 					_scene->drawToBackground(_globals._spriteIndexes[13], 1, Common::Point(-32000, -32000), 0, 100);
2060 				}
2061 
2062 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 4);
2063 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 8);
2064 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 13);
2065 
2066 				_game._player._visible = false;
2067 				_anim3ActvFl = true;
2068 
2069 				if (_vm->_gameConv->restoreRunning() == 21) {
2070 					_game._player._stepEnabled = false;
2071 					_vm->_gameConv->run(21);
2072 					_vm->_gameConv->exportValue(_game._objects.isInInventory(OBJ_MUSIC_SCORE));
2073 				}
2074 			} else if (_phantomStatus == 4) {
2075 				_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
2076 				_scene->drawToBackground(_globals._spriteIndexes[13], 1, Common::Point(-32000, -32000), 0, 100);
2077 
2078 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_3");
2079 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACERAL", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2080 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACEXDFR", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2081 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACEPHN", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2082 				_globals._spriteIndexes[12] = _scene->_sprites.addSprites(formAnimName('a', 8), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2083 
2084 				_globals._animationIndexes[3] = _scene->loadAnimation(formAnimName('p', 2), 130);
2085 				_scene->setAnimFrame(_globals._animationIndexes[3], 159);
2086 
2087 				_game._player._playerPos = Common::Point(130, 135);
2088 				_game._player._facing = FACING_NORTHEAST;
2089 				_game._player._visible = true;
2090 				_anim4ActvFl = true;
2091 
2092 				_game._player._stepEnabled = false;
2093 				_vm->_gameConv->run(21);
2094 				_vm->_gameConv->exportValue(_game._objects.isInInventory(OBJ_MUSIC_SCORE));
2095 			}
2096 		} else if (_globals[kFightStatus] == 2) {
2097 			if (!_game._visitedScenes.exists(506)) {
2098 				_scene->changeVariant(1);
2099 
2100 				_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
2101 				_scene->drawToBackground(_globals._spriteIndexes[13], 1, Common::Point(-32000, -32000), 0, 100);
2102 				_anim5ActvFl = true;
2103 
2104 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_3");
2105 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACERAL", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2106 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACEXDFR",PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2107 				_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*FACEPHN", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2108 
2109 				_globals._animationIndexes[3] = _scene->loadAnimation(formAnimName('p', 3), 0);
2110 				int hotspotIdx = _scene->_dynamicHotspots.add(NOUN_CHRISTINE, VERB_WALK_TO, SYNTAX_SINGULAR_FEM, EXT_NONE, Common::Rect(0, 0, 0, 0));
2111 				_phantomStatus = 5;
2112 				_scene->_dynamicHotspots[hotspotIdx]._articleNumber = PREP_ON;
2113 				_scene->setAnimFrame(_globals._animationIndexes[3], 79);
2114 				_scene->_dynamicHotspots.setPosition(hotspotIdx, Common::Point(66, 119), FACING_NORTHWEST);
2115 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 0);
2116 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 1);
2117 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 2);
2118 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 3);
2119 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 4);
2120 			} else {
2121 				_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
2122 				_scene->drawToBackground(_globals._spriteIndexes[13], 1, Common::Point(-32000, -32000), 0, 100);
2123 			}
2124 		} else {
2125 			_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
2126 			_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 1);
2127 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 14);
2128 			_globals._sequenceIndexes[1] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[1], false, 1);
2129 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 14);
2130 			if (!_globals[kHeListened])
2131 				_scene->_sequences.addTimer(30, 62);
2132 		}
2133 	}
2134 
2135 	sceneEntrySound();
2136 }
2137 
step()2138 void Scene504::step() {
2139 	if (_anim0ActvFl)
2140 		handleListenAnimation();
2141 
2142 	if (_anim1ActvFl)
2143 		handleOrganAnimation();
2144 
2145 	if (_anim2ActvFl)
2146 		handleChairAnimation();
2147 
2148 	if (_anim3ActvFl)
2149 		handlePhantomAnimation1();
2150 
2151 	if (_anim4ActvFl)
2152 		handlePhantomAnimation2();
2153 
2154 	if (_anim5ActvFl)
2155 		handlePhantomAnimation3();
2156 
2157 	if (_game._trigger == 120) {
2158 		_game._player._stepEnabled = false;
2159 		_vm->_gameConv->run(21);
2160 		_vm->_gameConv->exportValue(_game._objects.isInInventory(OBJ_MUSIC_SCORE));
2161 		_vm->_gameConv->exportValue(1);
2162 		_globals[kFightStatus] = 1;
2163 	}
2164 
2165 	if (_game._trigger == 60) {
2166 		_game._player._visible = true;
2167 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[0]);
2168 		_scene->drawToBackground(_globals._spriteIndexes[0], 1, Common::Point(-32000, -32000), 0, 100);
2169 		_scene->_sequences.addTimer(30, 61);
2170 	}
2171 
2172 	if (_game._trigger == 61) {
2173 		_game._player._stepEnabled = true;
2174 		_scene->_sequences.addTimer(60, 62);
2175 	}
2176 
2177 	if (_game._trigger == 62) {
2178 		_globals[kHeListened] = true;
2179 		_game._player._stepEnabled = false;
2180 		_vm->_gameConv->run(19);
2181 		_vm->_gameConv->exportValue(_game._difficulty);
2182 	}
2183 
2184 	if (_game._trigger == 80) {
2185 		_vm->_sound->command(73);
2186 		_globals[kRightDoorIsOpen504] = true;
2187 		_scene->deleteSequence(_globals._sequenceIndexes[2]);
2188 		_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 6, 1);
2189 		_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
2190 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], -1, -2);
2191 
2192 		_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 6, 1);
2193 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 1);
2194 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], -1, -2);
2195 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 90);
2196 	}
2197 
2198 	if (_game._trigger == 90) {
2199 		_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 6, 1);
2200 		_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 1);
2201 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], -1, -2);
2202 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 91);
2203 	}
2204 
2205 	if (_game._trigger == 91) {
2206 		_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 6, 1);
2207 		_scene->_sequences.setDepth(_globals._sequenceIndexes[5], 1);
2208 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], -1, -2);
2209 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 92);
2210 	}
2211 
2212 	if (_game._trigger == 92)
2213 		_fireBreathFl = true;
2214 
2215 	if (_fireBreathFl) {
2216 		_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 6, 1);
2217 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 1);
2218 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], -1, -2);
2219 		_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 6, 1);
2220 		_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 1);
2221 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], -1, -2);
2222 		_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 6, 1);
2223 		_scene->_sequences.setDepth(_globals._sequenceIndexes[5], 1);
2224 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], -1, -2);
2225 		_fireBreathFl = false;
2226 	}
2227 
2228 	if (_game._trigger == 130) {
2229 		_scene->freeAnimation(_globals._animationIndexes[3]);
2230 		_scene->_sprites.remove(_globals._spriteIndexes[12]);
2231 
2232 		_anim4ActvFl = false;
2233 		_anim5ActvFl = true;
2234 
2235 		_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_2", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2236 		_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_3", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2237 
2238 		_scene->changeVariant(1);
2239 
2240 		_globals._animationIndexes[3] = _scene->loadAnimation(formAnimName('p', 3), 0);
2241 		int hotspotIdx = _scene->_dynamicHotspots.add(NOUN_CHRISTINE, VERB_WALK_TO, SYNTAX_SINGULAR_FEM, EXT_NONE, Common::Rect(0, 0, 0, 0));
2242 		_scene->_dynamicHotspots[hotspotIdx]._articleNumber = PREP_ON;
2243 		_scene->_dynamicHotspots.setPosition(hotspotIdx, Common::Point(66, 119), FACING_NORTHWEST);
2244 		_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 0);
2245 		_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 1);
2246 		_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 2);
2247 		_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 3);
2248 		_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[3], 4);
2249 	}
2250 
2251 	if (_game._trigger == 67) {
2252 		_game._player._stepEnabled = true;
2253 		_game._player._visible = true;
2254 		_anim0ActvFl = false;
2255 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[0]);
2256 	}
2257 
2258 	if (_game._trigger == 136)
2259 		_scene->_nextSceneId = 506;
2260 
2261 	if (_game._trigger == 100) {
2262 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[1]);
2263 		_game._player._playerPos = Common::Point(156, 114);
2264 		_game._player._visible = true;
2265 		_anim1ActvFl = false;
2266 		_game._player.resetFacing(FACING_EAST);
2267 		_scene->_sequences.addTimer(10, 101);
2268 	}
2269 
2270 	if (_game._trigger == 101) {
2271 		_game._player._stepEnabled = true;
2272 		_scene->_sprites.remove(_globals._spriteIndexes[5]);
2273 		_scene->_sprites.remove(_globals._spriteIndexes[4]);
2274 	}
2275 }
2276 
actions()2277 void Scene504::actions() {
2278 	if (_vm->_gameConv->activeConvId() == 26) {
2279 		_action._inProgress = false;
2280 		return;
2281 	}
2282 
2283 	if (_action.isAction(VERB_SIT_IN, NOUN_LARGE_CHAIR)) {
2284 		if (!_anim2ActvFl) {
2285 			_chairStatus = 0;
2286 			_game._player._stepEnabled = false;
2287 			_game._player._visible = false;
2288 			_anim2ActvFl = true;
2289 			_globals._animationIndexes[2] = _scene->loadAnimation(formAnimName('c', 1), 0);
2290 			_game.syncTimers(SYNC_ANIM, _globals._animationIndexes[0], SYNC_PLAYER, 0);
2291 		} else
2292 			_vm->_dialogs->show(50436);
2293 		_action._inProgress = false;
2294 		return;
2295 	}
2296 
2297 	if (_game._trigger == 95) {
2298 		_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('l', 1), 67);
2299 		_listenStatus = 0;
2300 		_game._player._stepEnabled = false;
2301 		_game._player._visible = false;
2302 		_anim0ActvFl = true;
2303 		_globals[kHeListened] = true;
2304 		_vm->_gameConv->run(19);
2305 		_vm->_gameConv->exportValue(_game._difficulty);
2306 		_action._inProgress = false;
2307 		return;
2308 	}
2309 
2310 	if (_game._trigger == 67) {
2311 		_game._player._stepEnabled = true;
2312 		_game._player._visible = true;
2313 		_anim0ActvFl = false;
2314 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[0]);
2315 		_action._inProgress = false;
2316 		return;
2317 	}
2318 
2319 	if (_vm->_gameConv->activeConvId() == 19) {
2320 		handleListenConversation();
2321 		_action._inProgress = false;
2322 		return;
2323 	}
2324 
2325 	if (_vm->_gameConv->activeConvId() == 27) {
2326 		handlePlayConversation();
2327 		_action._inProgress = false;
2328 		return;
2329 	}
2330 
2331 	if (_vm->_gameConv->activeConvId() == 21) {
2332 		handleFightConversation();
2333 		_action._inProgress = false;
2334 		return;
2335 	}
2336 
2337 	if (_game._trigger == 100) {
2338 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[1]);
2339 		_game._player._playerPos = Common::Point(156, 114);
2340 		_game._player._visible = true;
2341 		_anim1ActvFl = false;
2342 		_game._player.resetFacing(FACING_EAST);
2343 		_scene->_sequences.addTimer(10, 101);
2344 		_action._inProgress = false;
2345 		return;
2346 	}
2347 
2348 	if (_game._trigger == 101) {
2349 		_game._player._stepEnabled = true;
2350 		_scene->_sprites.remove(_globals._spriteIndexes[5]);
2351 		_scene->_sprites.remove(_globals._spriteIndexes[4]);
2352 		_action._inProgress = false;
2353 		return;
2354 	}
2355 
2356 	if (_action.isAction(VERB_SIT_ON, NOUN_ORGAN_BENCH)) {
2357 		if (_globals[kRightDoorIsOpen504])
2358 			_vm->_dialogs->show(50427);
2359 		else {
2360 			_globals._spriteIndexes[4] = _scene->_sprites.addSprites(formAnimName('x', 4), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2361 			_globals._spriteIndexes[5] = _scene->_sprites.addSprites(formAnimName('x', 5), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2362 			_globals._animationIndexes[1] = _scene->loadAnimation(formAnimName('o', 1), 100);
2363 			_game._player._stepEnabled = false;
2364 			_game._player._visible = false;
2365 			_playingMusicFl = false;
2366 			_anim1ActvFl = true;
2367 			_playStatus = 0;
2368 		}
2369 		_action._inProgress = false;
2370 		return;
2371 	}
2372 
2373 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_RIGHT_DOOR) || _action.isAction(VERB_OPEN, NOUN_RIGHT_DOOR)) {
2374 		if (_globals[kRightDoorIsOpen504]) {
2375 			if (_vm->_gameConv->activeConvId() == 26)
2376 				_vm->_gameConv->stop();
2377 
2378 			_scene->_nextSceneId = 505;
2379 		} else
2380 			_vm->_dialogs->show(50418);
2381 
2382 		_action._inProgress = false;
2383 		return;
2384 	}
2385 
2386 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_LEFT_DOOR) || _action.isAction(VERB_OPEN, NOUN_LEFT_DOOR)) {
2387 		if (_globals[kFightStatus]) {
2388 			if (_game._visitedScenes.exists(506))
2389 				_scene->_nextSceneId = 506;
2390 			else if (!_game._objects.isInInventory(OBJ_MUSIC_SCORE))
2391 				_vm->_dialogs->show(50425);
2392 			else {
2393 				_phantomStatus = 6;
2394 				_game._player._stepEnabled = false;
2395 			}
2396 		} else
2397 			_vm->_dialogs->show(50418);
2398 
2399 		_action._inProgress = false;
2400 		return;
2401 	}
2402 
2403 	if (_action.isAction(VERB_TAKE, NOUN_MUSIC_SCORE)) {
2404 		switch (_game._trigger) {
2405 		case (0):
2406 			if (_game._objects.isInRoom(OBJ_MUSIC_SCORE)) {
2407 				_globals[kPlayerScore] += 5;
2408 				_game._player._stepEnabled = false;
2409 				_game._player._visible = false;
2410 				_globals._sequenceIndexes[14] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[14], false, 5, 2);
2411 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[14], 1, 4);
2412 				_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[14], true);
2413 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[14], SEQUENCE_TRIGGER_SPRITE, 4, 1);
2414 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[14], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
2415 				_action._inProgress = false;
2416 				return;
2417 			}
2418 			break;
2419 
2420 		case 1:
2421 			_globals._sequenceIndexes[15] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[15], false, 1);
2422 			_scene->_sequences.setDepth(_globals._sequenceIndexes[15], 14);
2423 			_scene->_hotspots.activate(NOUN_MUSIC_SCORE, false);
2424 			_game._objects.addToInventory(OBJ_MUSIC_SCORE);
2425 			_vm->_sound->command(26);
2426 			_action._inProgress = false;
2427 			return;
2428 			break;
2429 
2430 		case 2:
2431 			_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[14]);
2432 			_game._player._visible = true;
2433 			_scene->_sequences.addTimer(20, 3);
2434 			_action._inProgress = false;
2435 			return;
2436 			break;
2437 
2438 		case 3:
2439 			_vm->_dialogs->showItem(OBJ_MUSIC_SCORE, 820, 0);
2440 			_game._player._stepEnabled = true;
2441 			_action._inProgress = false;
2442 			return;
2443 			break;
2444 
2445 		default:
2446 			break;
2447 		}
2448 	}
2449 
2450 	if (_action._lookFlag) {
2451 		_vm->_dialogs->show(50410);
2452 		_action._inProgress = false;
2453 		return;
2454 	}
2455 
2456 	if (_action.isAction(VERB_LOOK) || _action.isAction(VERB_LOOK_AT)) {
2457 		if (_action.isObject(NOUN_FLOOR)) {
2458 			_vm->_dialogs->show(50411);
2459 			_action._inProgress = false;
2460 			return;
2461 		}
2462 
2463 		if (_action.isObject(NOUN_WALL)) {
2464 			_vm->_dialogs->show(50412);
2465 			_action._inProgress = false;
2466 			return;
2467 		}
2468 
2469 		if (_action.isObject(NOUN_ORGAN)) {
2470 			_vm->_dialogs->show(50413);
2471 			_action._inProgress = false;
2472 			return;
2473 		}
2474 
2475 		if (_action.isObject(NOUN_ORGAN_BENCH)) {
2476 			_vm->_dialogs->show(50414);
2477 			_action._inProgress = false;
2478 			return;
2479 		}
2480 
2481 		if (_action.isObject(NOUN_MUSIC_SCORE) && _game._objects.isInRoom(OBJ_MUSIC_SCORE)) {
2482 			_vm->_dialogs->show(50415);
2483 			_action._inProgress = false;
2484 			return;
2485 		}
2486 
2487 		if (_action.isObject(NOUN_LEFT_DOOR)) {
2488 			_vm->_dialogs->show(50416);
2489 			_action._inProgress = false;
2490 			return;
2491 		}
2492 
2493 		if (_action.isObject(NOUN_RIGHT_DOOR)) {
2494 			_vm->_dialogs->show(_globals[kRightDoorIsOpen504] ? 50434 : 50417);
2495 			_action._inProgress = false;
2496 			return;
2497 		}
2498 
2499 		if (_action.isObject(NOUN_TABLE)) {
2500 			_vm->_dialogs->show(50419);
2501 			_action._inProgress = false;
2502 			return;
2503 		}
2504 
2505 		if (_action.isObject(NOUN_TRAP_DOOR)) {
2506 			_vm->_dialogs->show(50420);
2507 			_action._inProgress = false;
2508 			return;
2509 		}
2510 
2511 		if (_action.isObject(NOUN_LARGE_CHAIR)) {
2512 			_vm->_dialogs->show(50422);
2513 			_action._inProgress = false;
2514 			return;
2515 		}
2516 
2517 		if (_action.isObject(NOUN_CHRISTINE)) {
2518 			_vm->_dialogs->show(_globals[kFightStatus] ? 50426 : 50429);
2519 			_action._inProgress = false;
2520 			return;
2521 		}
2522 
2523 		if (_action.isObject(NOUN_PHANTOM)) {
2524 			_vm->_dialogs->show(50428);
2525 			_action._inProgress = false;
2526 			return;
2527 		}
2528 	}
2529 
2530 	if (_action.isAction(VERB_OPEN, NOUN_TRAP_DOOR)) {
2531 		_vm->_dialogs->show(50421);
2532 		_action._inProgress = false;
2533 		return;
2534 	}
2535 
2536 	if (_action.isAction(VERB_CLOSE) && _action.isObject(NOUN_RIGHT_DOOR) && !_globals[kRightDoorIsOpen504]) {
2537 		_vm->_dialogs->show(50433);
2538 		_action._inProgress = false;
2539 		return;
2540 	}
2541 
2542 	if (_action.isAction(VERB_CLOSE) && _action.isObject(NOUN_LEFT_DOOR) && !_globals[kFightStatus] && !_game._visitedScenes.exists(506)) {
2543 		_vm->_dialogs->show(50433);
2544 		_action._inProgress = false;
2545 		return;
2546 	}
2547 
2548 	if (_anim3ActvFl && (_action.isAction(VERB_TAKE, NOUN_SWORD) || _action.isAction(VERB_ATTACK, NOUN_PHANTOM))) {
2549 		_game._player._stepEnabled = false;
2550 		_input3Count = 0;
2551 		_phantomStatus = 4;
2552 		_action._inProgress = false;
2553 		return;
2554 	}
2555 
2556 	if (_action.isAction(VERB_TALK_TO, NOUN_CHRISTINE)) {
2557 		_vm->_gameConv->run(21);
2558 		_vm->_gameConv->exportValue(_game._objects.isInInventory(OBJ_MUSIC_SCORE));
2559 		_vm->_gameConv->exportValue(0);
2560 		_phantomStatus = 7;
2561 		_christineTalkCount = 0;
2562 		_action._inProgress = false;
2563 		return;
2564 	}
2565 
2566 	if (_action.isAction(VERB_TALK_TO, NOUN_PHANTOM)) {
2567 		_vm->_dialogs->show(50431);
2568 		_action._inProgress = false;
2569 		return;
2570 	}
2571 
2572 	if (_action.isAction(VERB_TAKE, NOUN_CHRISTINE)) {
2573 		_vm->_dialogs->show(50435);
2574 		_action._inProgress = false;
2575 		return;
2576 	}
2577 }
2578 
preActions()2579 void Scene504::preActions() {
2580 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_RIGHT_DOOR) || _action.isAction(VERB_OPEN, NOUN_RIGHT_DOOR)) {
2581 		if (_globals[kRightDoorIsOpen504]) {
2582 			if ((_globals[kFightStatus] == 2) && !_game._visitedScenes.exists(506)) {
2583 				switch (_game._trigger) {
2584 				case 0:
2585 					_game._player.walk(Common::Point(317, 115), FACING_NORTHEAST);
2586 					_game._player._readyToWalk = false;
2587 					_game._player._needToWalk = false;
2588 					_game._player._stepEnabled = false;
2589 					_vm->_gameConv->run(26);
2590 					_vm->_gameConv->exportValue(2);
2591 					_scene->_sequences.addTimer(6, 1);
2592 					break;
2593 
2594 				case 1:
2595 					if (_vm->_gameConv->activeConvId() >= 0)
2596 						_scene->_sequences.addTimer(6, 1);
2597 					else {
2598 						_game._player._stepEnabled = true;
2599 						_action._inProgress = true;
2600 						_game._player._needToWalk = true;
2601 						_game._player._readyToWalk = true;
2602 					}
2603 					break;
2604 
2605 				default:
2606 					break;
2607 				}
2608 			} else
2609 				_game._player.walk(Common::Point(317, 115), FACING_NORTHEAST);
2610 		} else if (_globals[kHeListened] || (_globals[kFightStatus] == 0))
2611 			_game._player.walk(Common::Point(286, 120), FACING_NORTHEAST);
2612 	}
2613 
2614 	if (_anim2ActvFl && !_action.isAction(VERB_SIT_IN) && _game._player._needToWalk) {
2615 		_chairStatus = 1;
2616 		_game._player._stepEnabled = false;
2617 		_game._player._readyToWalk = false;
2618 	}
2619 
2620 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_LEFT_DOOR) || _action.isAction(VERB_OPEN, NOUN_LEFT_DOOR)) {
2621 		if ((_globals[kFightStatus] == 0) && (_globals[kCoffinStatus] == 2) && !_game._visitedScenes.exists(506)) {
2622 			_vm->_dialogs->show(50432);
2623 			_game._player.cancelCommand();
2624 			return;
2625 		} else if (_game._visitedScenes.exists(506))
2626 			_game._player.walk(Common::Point(0, 109), FACING_NORTHWEST);
2627 		else if (!_game._objects.isInInventory(OBJ_MUSIC_SCORE) || (_globals[kFightStatus] == 0))
2628 			_game._player.walk(Common::Point(33, 116), FACING_NORTHWEST);
2629 	}
2630 
2631 	if ((_globals[kFightStatus] == 0) && (_globals[kCoffinStatus] == 2) && !_game._visitedScenes.exists(506)
2632 	 && !_action.isAction(VERB_LOOK) && !_action.isAction(VERB_LOOK_AT) && !_action.isAction(VERB_ATTACK)
2633 	 && !_action.isAction(VERB_TAKE, NOUN_SWORD) && !_action.isAction(VERB_TALK_TO, NOUN_PHANTOM)) {
2634 		_vm->_dialogs->show(50430);
2635 		_game._player.cancelCommand();
2636 	}
2637 }
2638 
handleListenAnimation()2639 void Scene504::handleListenAnimation() {
2640 	int curFrame = _scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame();
2641 	if (curFrame == _listenFrame)
2642 		return;
2643 
2644 	_listenFrame = curFrame;
2645 	int resetFrame = -1;
2646 
2647 	switch (_listenFrame) {
2648 	case 8:
2649 		_vm->_gameConv->release();
2650 		break;
2651 
2652 	case 9:
2653 		resetFrame = (_listenStatus == 0) ? 8 : 9;
2654 		break;
2655 
2656 	default:
2657 		break;
2658 	}
2659 
2660 	if (resetFrame >= 0) {
2661 		_scene->setAnimFrame(_globals._animationIndexes[0], resetFrame);
2662 		_listenFrame = resetFrame;
2663 	}
2664 }
2665 
handleOrganAnimation()2666 void Scene504::handleOrganAnimation() {
2667 	int curFrame = _scene->_animation[_globals._animationIndexes[1]]->getCurrentFrame();
2668 	if (curFrame == _playFrame)
2669 		return;
2670 
2671 	_playFrame = curFrame;
2672 	int resetFrame = -1;
2673 
2674 	switch (_playFrame) {
2675 	case 22:
2676 		_game._player._stepEnabled = true;
2677 		_vm->_gameConv->run(27);
2678 		break;
2679 
2680 	case 23:
2681 		if (_playStatus == 0)
2682 			resetFrame = 22;
2683 		else {
2684 			_game._player._stepEnabled = false;
2685 			if (_songNum == 5) {
2686 				_playingMusicFl = false;
2687 				_fireBreathFl = false;
2688 				resetFrame = 104;
2689 			}
2690 		}
2691 		break;
2692 
2693 	case 28:
2694 		if (!_playingMusicFl) {
2695 			_playingMusicFl = true;
2696 			_fireBreathFl = true;
2697 			_game._player._stepEnabled = false;
2698 
2699 			switch (_songNum) {
2700 			case 1:
2701 				_vm->_sound->command(34);
2702 				break;
2703 
2704 			case 2:
2705 				_vm->_sound->command(37);
2706 				break;
2707 
2708 			case 3:
2709 				_vm->_sound->command(35);
2710 				break;
2711 
2712 			case 4:
2713 				_vm->_sound->command(36);
2714 				break;
2715 
2716 			default:
2717 				break;
2718 			}
2719 		}
2720 		break;
2721 
2722 	case 69:
2723 		if ((_globals[kRightDoorIsOpen504]) && (_playCount >= 2)) {
2724 			_playCount = 0;
2725 			resetFrame = 102;
2726 			_vm->_sound->command(2);
2727 			_vm->_sound->command(16);
2728 		} else if (_songNum != _globals[kMusicSelected]) {
2729 			_vm->_sound->command(2);
2730 			_fireBreathFl = true;
2731 			resetFrame = 75;
2732 		} else {
2733 			resetFrame = 25;
2734 			++_playCount;
2735 			if (!_globals[kRightDoorIsOpen504]) {
2736 				_scene->_sequences.addTimer(1, 80);
2737 				_globals[kPlayerScore] += 5;
2738 			}
2739 		}
2740 		break;
2741 
2742 	case 76:
2743 		_scene->playSpeech(7);
2744 		break;
2745 
2746 	case 90:
2747 		_vm->_sound->command(27);
2748 		break;
2749 
2750 	case 102:
2751 		++_deathCounter;
2752 		if (_deathCounter >= 17)
2753 			_scene->_reloadSceneFlag = true;
2754 		else
2755 			resetFrame = 101;
2756 		break;
2757 
2758 	default:
2759 		break;
2760 	}
2761 
2762 	if (resetFrame >= 0) {
2763 		_scene->setAnimFrame(_globals._animationIndexes[1], resetFrame);
2764 		_playFrame = resetFrame;
2765 	}
2766 }
2767 
handlePhantomAnimation1()2768 void Scene504::handlePhantomAnimation1() {
2769 	int curFrame = _scene->_animation[_globals._animationIndexes[3]]->getCurrentFrame();
2770 	if (curFrame == _phantomFrame)
2771 		return;
2772 
2773 	_phantomFrame = curFrame;
2774 	int resetFrame = -1;
2775 
2776 	switch (_phantomFrame) {
2777 	case 41:
2778 		_vm->_gameConv->run(21);
2779 		_vm->_gameConv->exportValue(_game._objects.isInInventory(OBJ_MUSIC_SCORE));
2780 		_vm->_gameConv->exportValue(0);
2781 		break;
2782 
2783 	case 52:
2784 	case 53:
2785 	case 54:
2786 	case 55:
2787 		resetFrame = (_phantomStatus == 0) ? _vm->getRandomNumber(51, 54) : 55;
2788 		break;
2789 
2790 	case 78:
2791 		_vm->_gameConv->release();
2792 		break;
2793 
2794 	case 110:
2795 	case 111:
2796 	case 112:
2797 	case 113:
2798 		resetFrame = (_phantomStatus == 1) ? _vm->getRandomNumber(109, 112) : 113;
2799 		break;
2800 
2801 	case 142:
2802 		_scene->drawToBackground(_globals._spriteIndexes[13], 1, Common::Point(-32000, -32000), 0, 100);
2803 		break;
2804 
2805 	case 143:
2806 		_game._player._stepEnabled = true;
2807 		break;
2808 
2809 	case 149:
2810 	case 150:
2811 	case 151:
2812 		++_input3Count;
2813 
2814 		if (_phantomStatus == 4) {
2815 			_game._player._stepEnabled = false;
2816 			resetFrame = 200;
2817 		} else if (_input3Count >= 9) {
2818 			_game._player._stepEnabled = false;
2819 			resetFrame = 151;
2820 		} else if (_phantomStatus == 2)
2821 			resetFrame = _vm->getRandomNumber(148, 150);
2822 		break;
2823 
2824 	case 169:
2825 		_vm->_sound->command(1);
2826 		_scene->playSpeech(7);
2827 		break;
2828 
2829 	case 180:
2830 		_vm->_sound->command(27);
2831 		break;
2832 
2833 	case 187:
2834 		_deathCounter = 0;
2835 		break;
2836 
2837 	case 189:
2838 		++_deathCounter;
2839 		if (_deathCounter >= 29)
2840 			_scene->_reloadSceneFlag = true;
2841 		else
2842 			resetFrame = 188;
2843 		break;
2844 
2845 	case 227:
2846 
2847 		_scene->freeAnimation(_globals._animationIndexes[3]);
2848 		_scene->_sprites.remove(_globals._spriteIndexes[9]);
2849 		_scene->_sprites.remove(_globals._spriteIndexes[8]);
2850 		_scene->_sprites.remove(_globals._spriteIndexes[7]);
2851 		_scene->_sprites.remove(_globals._spriteIndexes[10]);
2852 		_scene->_sprites.remove(_globals._spriteIndexes[11]);
2853 
2854 		_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_3", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2855 		_globals._spriteIndexes[12] = _scene->_sprites.addSprites(formAnimName('a', 8), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
2856 		_globals._animationIndexes[3] = _scene->loadAnimation(formAnimName('p', 2), 130);
2857 
2858 		_scene->setAnimFrame(_globals._animationIndexes[3], 27);
2859 		resetFrame = -1;
2860 		_anim3ActvFl = false;
2861 		_anim4ActvFl = true;
2862 		break;
2863 
2864 	default:
2865 		break;
2866 	}
2867 
2868 	if (resetFrame >= 0) {
2869 		_scene->setAnimFrame(_globals._animationIndexes[3], resetFrame);
2870 		_phantomFrame = resetFrame;
2871 	}
2872 }
2873 
handlePhantomAnimation2()2874 void Scene504::handlePhantomAnimation2() {
2875 	int curFrame = _scene->_animation[_globals._animationIndexes[3]]->getCurrentFrame();
2876 	if (curFrame == _phantomFrame)
2877 		return;
2878 
2879 	_phantomFrame = curFrame;
2880 	int resetFrame = -1;
2881 
2882 	switch (_phantomFrame) {
2883 	case 78:
2884 		_scene->playSpeech(9);
2885 		break;
2886 
2887 	case 119:
2888 		_game._player._playerPos = Common::Point(114, 137);
2889 		_game._player._facing = FACING_WEST;
2890 		_game._player._visible = true;
2891 		_globals[kPlayerScore] += 5;
2892 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[3]);
2893 		_game._player.walk(Common::Point(130, 135), FACING_NORTHEAST);
2894 		_scene->_hotspots.activate(NOUN_CHRISTINE, false);
2895 		_game._player.setWalkTrigger(120);
2896 		_vm->_sound->command(1);
2897 		break;
2898 
2899 	case 150:
2900 		_vm->_sound->command(16);
2901 		break;
2902 
2903 	case 160:
2904 		switch (_playStatus) {
2905 		case 5:
2906 			resetFrame = 164;
2907 			break;
2908 
2909 		case 7:
2910 			resetFrame = 160;
2911 			break;
2912 
2913 		default:
2914 			resetFrame = 159;
2915 			break;
2916 		}
2917 		break;
2918 
2919 	case 161:
2920 	case 162:
2921 	case 163:
2922 	case 164:
2923 		resetFrame = (_phantomStatus == 5) ? 159 : _vm->getRandomNumber(160, 162);
2924 
2925 		++_christineTalkCount;
2926 		if (_christineTalkCount > 10) {
2927 			resetFrame = 159;
2928 			if (_phantomStatus != 5)
2929 				_phantomStatus = 4;
2930 		}
2931 		break;
2932 
2933 	default:
2934 		break;
2935 	}
2936 
2937 	if (resetFrame >= 0) {
2938 		_scene->setAnimFrame(_globals._animationIndexes[3], resetFrame);
2939 		_phantomFrame = resetFrame;
2940 	}
2941 }
2942 
handlePhantomAnimation3()2943 void Scene504::handlePhantomAnimation3() {
2944 	int curFrame = _scene->_animation[_globals._animationIndexes[3]]->getCurrentFrame();
2945 	if (curFrame == _phantomFrame)
2946 		return;
2947 
2948 	_phantomFrame = curFrame;
2949 	int resetFrame = -1;
2950 
2951 	switch (_phantomFrame) {
2952 	case 58:
2953 		_game._player._stepEnabled = true;
2954 		break;
2955 
2956 	case 80:
2957 		if (_phantomStatus == 7)
2958 			resetFrame = 116;
2959 		else if (_phantomStatus != 6)
2960 			resetFrame = 79;
2961 		break;
2962 
2963 	case 115:
2964 		_game._player.walk(Common::Point(0, 109), FACING_NORTHWEST);
2965 		_game._player.setWalkTrigger(136);
2966 		break;
2967 
2968 	case 116:
2969 		resetFrame = 115;
2970 		break;
2971 
2972 	case 117:
2973 	case 118:
2974 	case 119:
2975 		resetFrame = _vm->getRandomNumber(116, 118);
2976 		++_christineTalkCount;
2977 		if (_christineTalkCount > 10) {
2978 			resetFrame = 79;
2979 			if (_phantomStatus != 6)
2980 				_phantomStatus = 5;
2981 		}
2982 		break;
2983 
2984 	default:
2985 		break;
2986 	}
2987 
2988 	if (resetFrame >= 0) {
2989 		_scene->setAnimFrame(_globals._animationIndexes[3], resetFrame);
2990 		_phantomFrame = resetFrame;
2991 	}
2992 }
2993 
handleChairAnimation()2994 void Scene504::handleChairAnimation() {
2995 	int curFrame = _scene->_animation[_globals._animationIndexes[2]]->getCurrentFrame();
2996 	if (curFrame == _chairFrame)
2997 		return;
2998 
2999 	_chairFrame = curFrame;
3000 	int resetFrame = -1;
3001 
3002 	switch (_chairFrame) {
3003 	case 24:
3004 		_game._player._stepEnabled = true;
3005 		break;
3006 
3007 	case 25:
3008 	case 26:
3009 	case 30:
3010 	case 31:
3011 		if (!_chairDialogDoneFl) {
3012 			_chairDialogDoneFl = true;
3013 			_vm->_dialogs->show(50424);
3014 		}
3015 
3016 		if (_chairStatus == 0) {
3017 			if (_vm->getRandomNumber(1,5) == 1)
3018 				resetFrame = _vm->getRandomNumber(24, 30);
3019 			else
3020 				resetFrame = _chairFrame - 1;
3021 		} else
3022 			resetFrame = 31;
3023 		break;
3024 
3025 	case 47:
3026 		resetFrame = -1;
3027 		_game._player._stepEnabled = true;
3028 		_game._player._visible = true;
3029 		_game._player._readyToWalk = true;
3030 		_anim2ActvFl = false;
3031 		_chairDialogDoneFl = false;
3032 		_scene->freeAnimation(_globals._animationIndexes[2]);
3033 		break;
3034 
3035 	default:
3036 		break;
3037 	}
3038 
3039 	if (resetFrame >= 0) {
3040 		_scene->setAnimFrame(_globals._animationIndexes[2], resetFrame);
3041 		_chairFrame = resetFrame;
3042 	}
3043 }
3044 
handleListenConversation()3045 void Scene504::handleListenConversation() {
3046 	if ((_action._activeAction._verbId == 2) && !_game._trigger) {
3047 		_game._player.walk(Common::Point(286, 120), FACING_EAST);
3048 		_game._player.setWalkTrigger(95);
3049 	}
3050 
3051 	if (_action._activeAction._verbId == 12)
3052 		_listenStatus = 1;
3053 }
3054 
handlePlayConversation()3055 void Scene504::handlePlayConversation() {
3056 	switch (_action._activeAction._verbId) {
3057 	case 2:
3058 		_vm->_gameConv->setStartNode(1);
3059 		_vm->_gameConv->stop();
3060 		_playStatus = 1;
3061 		_songNum = 1;
3062 		break;
3063 
3064 	case 3:
3065 		_vm->_gameConv->setStartNode(1);
3066 		_vm->_gameConv->stop();
3067 		_playStatus = 1;
3068 		_songNum = 2;
3069 		break;
3070 
3071 	case 4:
3072 		_vm->_gameConv->setStartNode(1);
3073 		_vm->_gameConv->stop();
3074 		_playStatus = 1;
3075 		_songNum = 3;
3076 		break;
3077 
3078 	case 5:
3079 		_vm->_gameConv->setStartNode(1);
3080 		_vm->_gameConv->stop();
3081 		_playStatus = 1;
3082 		_songNum = 4;
3083 		break;
3084 
3085 	case 6:
3086 		_vm->_gameConv->setStartNode(1);
3087 		_vm->_gameConv->stop();
3088 		_playStatus = 1;
3089 		_songNum = 5;
3090 		break;
3091 
3092 	case 8:
3093 		_vm->_gameConv->setStartNode(1);
3094 		_vm->_gameConv->stop();
3095 		_playStatus = 1;
3096 		break;
3097 
3098 	default:
3099 		break;
3100 	}
3101 }
3102 
handleFightConversation()3103 void Scene504::handleFightConversation() {
3104 	switch (_action._activeAction._verbId) {
3105 	case 3:
3106 		_vm->_gameConv->hold();
3107 		_phantomStatus = 1;
3108 		break;
3109 
3110 	case 8:
3111 		_phantomStatus = 2;
3112 		break;
3113 
3114 	case 10:
3115 	case 11:
3116 	case 12:
3117 	case 15:
3118 		_vm->_gameConv->setInterlocutorTrigger(145);
3119 		break;
3120 
3121 	case 14:
3122 	case 17:
3123 		_phantomStatus = 5;
3124 		_globals[kFightStatus] = 2;
3125 		break;
3126 
3127 	default:
3128 		break;
3129 	}
3130 
3131 	if ((_game._trigger == 145) && (_phantomStatus != 5)) {
3132 		_phantomStatus = 7;
3133 		_christineTalkCount = 0;
3134 	}
3135 }
3136 
3137 /*------------------------------------------------------------------------*/
3138 
Scene505(MADSEngine * vm)3139 Scene505::Scene505(MADSEngine *vm) : Scene5xx(vm) {
3140 	_anim0ActvFl = false;
3141 	_anim1ActvFl = false;
3142 	_anim2ActvFl = false;
3143 	_checkFrame106 = false;
3144 	_leaveRoomFl = false;
3145 	_partedFl = false;
3146 
3147 	_raoulStatus = -1;
3148 	_raoulFrame = -1;
3149 	_raoulCount = -1;
3150 	_bothStatus = -1;
3151 	_bothFrame = -1;
3152 	_bothCount = -1;
3153 	_partStatus = -1;
3154 	_partFrame = -1;
3155 	_partCount = -1;
3156 }
3157 
synchronize(Common::Serializer & s)3158 void Scene505::synchronize(Common::Serializer &s) {
3159 	Scene5xx::synchronize(s);
3160 
3161 	s.syncAsByte(_anim0ActvFl);
3162 	s.syncAsByte(_anim1ActvFl);
3163 	s.syncAsByte(_anim2ActvFl);
3164 	s.syncAsByte(_checkFrame106);
3165 	s.syncAsByte(_leaveRoomFl);
3166 	s.syncAsByte(_partedFl);
3167 
3168 	s.syncAsSint16LE(_raoulStatus);
3169 	s.syncAsSint16LE(_raoulFrame);
3170 	s.syncAsSint16LE(_raoulCount);
3171 	s.syncAsSint16LE(_bothStatus);
3172 	s.syncAsSint16LE(_bothFrame);
3173 	s.syncAsSint16LE(_bothCount);
3174 	s.syncAsSint16LE(_partStatus);
3175 	s.syncAsSint16LE(_partFrame);
3176 	s.syncAsSint16LE(_partCount);
3177 }
3178 
setup()3179 void Scene505::setup() {
3180 	setPlayerSpritesPrefix();
3181 	setAAName();
3182 
3183 	if ((_globals[kCoffinStatus] == 2) && (!_globals[kChrisLeft505]))
3184 		_scene->_variant = 1;
3185 
3186 	_scene->addActiveVocab(NOUN_CHRISTINE);
3187 }
3188 
enter()3189 void Scene505::enter() {
3190 	_vm->_disableFastwalk = true;
3191 
3192 	if (_scene->_priorSceneId != RETURNING_FROM_LOADING) {
3193 		_partedFl = false;
3194 		_leaveRoomFl = false;
3195 		_anim0ActvFl = false;
3196 		_anim1ActvFl = false;
3197 		_anim2ActvFl = false;
3198 		_checkFrame106 = false;
3199 	}
3200 
3201 	_vm->_gameConv->load(20);
3202 	_scene->_hotspots.activateAtPos(NOUN_LID, false, Common::Point(216, 44));
3203 	_scene->_hotspots.activate(NOUN_CHRISTINE, false);
3204 
3205 	_globals._spriteIndexes[7] = _scene->_sprites.addSprites(formAnimName('x', 6));
3206 	_globals._spriteIndexes[0] = _scene->_sprites.addSprites(formAnimName('a', 1));
3207 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('x', 0));
3208 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('x', 1));
3209 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('x', 2));
3210 	_globals._spriteIndexes[4] = _scene->_sprites.addSprites(formAnimName('x', 3));
3211 	_globals._spriteIndexes[5] = _scene->_sprites.addSprites(formAnimName('x', 4));
3212 	_globals._spriteIndexes[6] = _scene->_sprites.addSprites(formAnimName('x', 5));
3213 	_globals._spriteIndexes[8] = _scene->_sprites.addSprites(formAnimName('a', 4));
3214 
3215 	if (_scene->_priorSceneId == RETURNING_FROM_LOADING) {
3216 		if (_vm->_gameConv->restoreRunning() == 20) {
3217 			_scene->_hotspots.activate(NOUN_LID, false);
3218 			_scene->_hotspots.activateAtPos(NOUN_LID, true, Common::Point(216, 44));
3219 			_globals._sequenceIndexes[7] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[7], false, 12);
3220 			_scene->_sequences.setDepth(_globals._sequenceIndexes[7], 1);
3221 
3222 			_globals._animationIndexes[1] = _scene->loadAnimation(formAnimName('c', 1), 65);
3223 			_scene->setAnimFrame(_globals._animationIndexes[1], 109);
3224 			_anim1ActvFl = true;
3225 			_game._player._visible = false;
3226 			_game._player._stepEnabled = false;
3227 			_bothStatus = 3;
3228 
3229 			_vm->_gameConv->run(20);
3230 			_vm->_gameConv->exportPointer(&_globals[kPlayerScore]);
3231 		} else if (_partedFl && (_globals[kFightStatus] == 0)) {
3232 			_scene->_hotspots.activate(NOUN_LID, false);
3233 			_scene->_hotspots.activateAtPos(NOUN_LID, true, Common::Point(216, 44));
3234 			_globals._sequenceIndexes[7] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[7], false, 12);
3235 			_scene->_sequences.setDepth(_globals._sequenceIndexes[7], 1);
3236 
3237 			_anim2ActvFl = true;
3238 			_bothStatus = 3;
3239 			_globals._animationIndexes[2] = _scene->loadAnimation(formAnimName('b', 1), 0);
3240 			int hotspotIdx = _scene->_dynamicHotspots.add(NOUN_CHRISTINE, VERB_WALK_TO, SYNTAX_SINGULAR_FEM, EXT_NONE, Common::Rect(0, 0, 0, 0));
3241 			_scene->_dynamicHotspots[hotspotIdx]._articleNumber = PREP_ON;
3242 			_scene->_dynamicHotspots.setPosition(hotspotIdx, Common::Point(91, 108), FACING_NORTHWEST);
3243 			_scene->setAnimFrame(_globals._animationIndexes[2], 89);
3244 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[2], 3);
3245 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[2], 4);
3246 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[2], 5);
3247 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[2], 6);
3248 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[2], 7);
3249 		} else if (_globals[kFightStatus]) {
3250 			_scene->_hotspots.activate(NOUN_LID, false);
3251 			_scene->_hotspots.activateAtPos(NOUN_LID, true, Common::Point(216, 44));
3252 			_globals._sequenceIndexes[7] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[7], false, 12);
3253 			_scene->_sequences.setDepth(_globals._sequenceIndexes[7], 1);
3254 		} else {
3255 			_globals._animationIndexes[1] = _scene->loadAnimation(formAnimName('c', 1), 65);
3256 			_anim1ActvFl = true;
3257 			_bothStatus = 0;
3258 			_scene->_hotspots.activate(NOUN_CHRISTINE, true);
3259 		}
3260 	}
3261 
3262 	if ((_scene->_priorSceneId == 504) || (_scene->_priorSceneId != RETURNING_FROM_LOADING)) {
3263 		_game._player._playerPos = Common::Point(5, 87);
3264 		_game._player._facing = FACING_EAST;
3265 		_game._player._stepEnabled = false;
3266 		_game._player.walk(Common::Point(58, 104), FACING_SOUTHEAST);
3267 		if (_globals[kCoffinStatus] != 2) {
3268 			_game._player.setWalkTrigger(70);
3269 			_anim1ActvFl = true;
3270 			_bothStatus = 0;
3271 			_scene->_hotspots.activate(NOUN_CHRISTINE, true);
3272 			_globals._animationIndexes[1] = _scene->loadAnimation(formAnimName('c', 1), 65);
3273 		} else {
3274 			_scene->_hotspots.activate(NOUN_LID, false);
3275 			_scene->_hotspots.activateAtPos(NOUN_LID, true, Common::Point(216, 44));
3276 			_globals._sequenceIndexes[7] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[7], false, 12);
3277 			_scene->_sequences.setDepth(_globals._sequenceIndexes[7], 1);
3278 			_game._player._stepEnabled = true;
3279 		}
3280 	}
3281 
3282 	sceneEntrySound();
3283 }
3284 
step()3285 void Scene505::step() {
3286 	if (_anim0ActvFl)
3287 		handleRaoulAnimation();
3288 
3289 	if (_anim1ActvFl)
3290 		handleBothanimation();
3291 
3292 	if (_anim2ActvFl)
3293 		handlePartedAnimation();
3294 
3295 	if (_game._trigger == 65) {
3296 		_scene->freeAnimation(_globals._animationIndexes[1]);
3297 		_vm->_sound->command(1);
3298 		_partedFl = true;
3299 		_anim2ActvFl = true;
3300 		_anim1ActvFl = false;
3301 		_globals._animationIndexes[2] = _scene->loadAnimation(formAnimName('b', 1), 0);
3302 
3303 		int hotspotIDx = _scene->_dynamicHotspots.add(NOUN_CHRISTINE, VERB_WALK_TO, SYNTAX_SINGULAR_FEM, EXT_NONE, Common::Rect(0, 0, 0, 0));
3304 		_scene->_dynamicHotspots.setPosition(hotspotIDx, Common::Point(91, 108), FACING_NORTHWEST);
3305 		_scene->_dynamicHotspots[hotspotIDx]._articleNumber = PREP_ON;
3306 		_scene->setDynamicAnim(hotspotIDx, _globals._animationIndexes[2], 3);
3307 		_scene->setDynamicAnim(hotspotIDx, _globals._animationIndexes[2], 4);
3308 		_scene->setDynamicAnim(hotspotIDx, _globals._animationIndexes[2], 5);
3309 		_scene->setDynamicAnim(hotspotIDx, _globals._animationIndexes[2], 6);
3310 		_scene->setDynamicAnim(hotspotIDx, _globals._animationIndexes[2], 7);
3311 	}
3312 
3313 	if (_game._trigger == 70) {
3314 		_game._player._stepEnabled = true;
3315 		if (!_game._visitedScenes._sceneRevisited) {
3316 			_vm->_gameConv->run(20);
3317 			_vm->_gameConv->exportPointer(&_globals[kPlayerScore]);
3318 		}
3319 	}
3320 }
3321 
actions()3322 void Scene505::actions() {
3323 	if (_game._trigger == 80) {
3324 		_bothStatus = 2;
3325 		_action._inProgress = false;
3326 		return;
3327 	}
3328 
3329 	if (_vm->_gameConv->activeConvId() == 20) {
3330 		handleCoffinDialog();
3331 		_action._inProgress = false;
3332 		return;
3333 	}
3334 
3335 	if (_action.isAction(VERB_TALK_TO, NOUN_CHRISTINE)) {
3336 		if (_globals[kCoffinStatus] != 2)
3337 			_vm->_dialogs->show(50536);
3338 		else {
3339 			_vm->_gameConv->run(20);
3340 			_vm->_gameConv->exportPointer(&_globals[kPlayerScore]);
3341 			_partStatus = 10;
3342 			_partCount = 0;
3343 		}
3344 		_action._inProgress = false;
3345 		return;
3346 	}
3347 
3348 	if ((_action.isAction(VERB_UNLOCK, NOUN_SARCOPHAGUS) || _action.isAction(VERB_UNLOCK, NOUN_LID)) && !_globals[kLookedAtSkullFace]) {
3349 		_vm->_dialogs->show(50539);
3350 		_action._inProgress = false;
3351 		return;
3352 	}
3353 
3354 	if ((_action.isAction(VERB_UNLOCK, NOUN_SKULL_FACE) || _action.isAction(VERB_PUT, NOUN_KEY, NOUN_SKULL_FACE)) || ((_action.isAction(VERB_UNLOCK, NOUN_SARCOPHAGUS) || _action.isAction(VERB_UNLOCK, NOUN_LID)) && _globals[kLookedAtSkullFace])) {
3355 		if (_globals[kCoffinStatus] == 0) {
3356 			switch (_game._trigger) {
3357 			case (0):
3358 				_game._player._stepEnabled = false;
3359 				_game._player._visible = false;
3360 				_globals._sequenceIndexes[8] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[8], false, 5, 2);
3361 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[8], -1, -2);
3362 				_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[8], true);
3363 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[8], SEQUENCE_TRIGGER_SPRITE, 9, 95);
3364 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[8], SEQUENCE_TRIGGER_EXPIRE, 0, 96);
3365 				_action._inProgress = false;
3366 				return;
3367 
3368 			case 95:
3369 				_vm->_sound->command(76);
3370 				_vm->_dialogs->show(50528);
3371 				_action._inProgress = false;
3372 				return;
3373 
3374 			case 96:
3375 				_game._player._visible = true;
3376 				_game._player._stepEnabled = true;
3377 				_globals[kCoffinStatus] = 1;
3378 				_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[8]);
3379 				_action._inProgress = false;
3380 				return;
3381 
3382 			default:
3383 				break;
3384 			}
3385 		} else {
3386 			_vm->_dialogs->show(50534);
3387 			_action._inProgress = false;
3388 			return;
3389 		}
3390 	}
3391 
3392 	if (_action.isAction(VERB_PUSH, NOUN_SKULL) && (_scene->_customDest.x >= 19)) {
3393 		switch (_game._trigger) {
3394 		case 0:
3395 			_game._player._stepEnabled = false;
3396 			_game._player._visible = false;
3397 			_globals._sequenceIndexes[0] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[0], false, 5, 2);
3398 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[0], -1, -2);
3399 			_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[0], true);
3400 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[0], SEQUENCE_TRIGGER_SPRITE, 6, 1);
3401 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[0], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
3402 			break;
3403 
3404 		case 1: {
3405 			int sprIdx;
3406 			_vm->_sound->command(77);
3407 			if (_scene->_customDest.x <= 44)
3408 				sprIdx = _globals._spriteIndexes[4];
3409 			else if (_scene->_customDest.x <= 58)
3410 				sprIdx = _globals._spriteIndexes[3];
3411 			else if (_scene->_customDest.x <= 71)
3412 				sprIdx = _globals._spriteIndexes[2];
3413 			else if (_scene->_customDest.x <= 84) {
3414 				sprIdx = _globals._spriteIndexes[1];
3415 				if (_globals[kCoffinStatus] == 1) {
3416 					_bothStatus = 1;
3417 					_scene->_hotspots.activate(NOUN_LID, false);
3418 					_scene->_hotspots.activate(NOUN_CHRISTINE, false);
3419 					_scene->_hotspots.activateAtPos(NOUN_LID, true, Common::Point(216, 44));
3420 					_scene->changeVariant(1);
3421 				}
3422 			} else if (_scene->_customDest.x <= 100)
3423 				sprIdx = _globals._spriteIndexes[5];
3424 			else
3425 				sprIdx = _globals._spriteIndexes[6];
3426 
3427 			int skullSeqIdx = _scene->_sequences.startPingPongCycle(sprIdx, false, 5, 2);
3428 			_scene->_sequences.setAnimRange(skullSeqIdx, -1, -2);
3429 			_scene->_sequences.setDepth(skullSeqIdx, 1);
3430 				}
3431 				break;
3432 
3433 		case 2:
3434 			_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[0]);
3435 			_game._player._visible = true;
3436 			_game._player._stepEnabled = true;
3437 			if (_bothStatus == 1) {
3438 				_game._player.walk(Common::Point(136, 126), FACING_EAST);
3439 				_game._player.setWalkTrigger(80);
3440 				_game._player._stepEnabled = false;
3441 			}
3442 			break;
3443 
3444 		default:
3445 			break;
3446 		}
3447 		_action._inProgress = false;
3448 		return;
3449 	}
3450 
3451 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_DOOR)) {
3452 		if (_anim2ActvFl) {
3453 			_leaveRoomFl = true;
3454 			_game._player._stepEnabled = false;
3455 		} else {
3456 			_globals[kChrisLeft505] = true;
3457 			_scene->_nextSceneId = 504;
3458 		}
3459 		_action._inProgress = false;
3460 		return;
3461 	}
3462 
3463 	if (_action._lookFlag) {
3464 		_vm->_dialogs->show(50510);
3465 		_action._inProgress = false;
3466 		return;
3467 	}
3468 
3469 	if (_action.isAction(VERB_LOOK) || _action.isAction(VERB_LOOK_AT)) {
3470 		if (_action.isObject(NOUN_FLOOR)) {
3471 			_vm->_dialogs->show(50511);
3472 			_action._inProgress = false;
3473 			return;
3474 		}
3475 
3476 		if (_action.isObject(NOUN_WALL)) {
3477 			_vm->_dialogs->show(50512);
3478 			_action._inProgress = false;
3479 			return;
3480 		}
3481 
3482 		if (_action.isObject(NOUN_SARCOPHAGUS)) {
3483 			_vm->_dialogs->show((_globals[kCoffinStatus] <= 1) ? 50513 : 50514);
3484 			_action._inProgress = false;
3485 			return;
3486 		}
3487 
3488 		if (_action.isObject(NOUN_SKULL_FACE)) {
3489 			_globals[kLookedAtSkullFace] = true;
3490 			_vm->_dialogs->show(50529);
3491 			_action._inProgress = false;
3492 			return;
3493 		}
3494 
3495 		if (_action.isObject(NOUN_DOOR)) {
3496 			_vm->_dialogs->show(50519);
3497 			_action._inProgress = false;
3498 			return;
3499 		}
3500 
3501 		if (_action.isObject(NOUN_SKULL)) {
3502 			_vm->_dialogs->show((_scene->_customDest.x < 19) ? 50521 : 50520);
3503 			_action._inProgress = false;
3504 			return;
3505 		}
3506 
3507 		if (_action.isObject(NOUN_SKULLS)) {
3508 			_vm->_dialogs->show(50521);
3509 			_action._inProgress = false;
3510 			return;
3511 		}
3512 
3513 		if (_action.isObject(NOUN_TOTEM)) {
3514 			_vm->_dialogs->show(50522);
3515 			_action._inProgress = false;
3516 			return;
3517 		}
3518 
3519 		if (_action.isObject(NOUN_DESK)) {
3520 			_vm->_dialogs->show(50523);
3521 			_action._inProgress = false;
3522 			return;
3523 		}
3524 
3525 		if (_action.isObject(NOUN_POLE)) {
3526 			_vm->_dialogs->show(50524);
3527 			_action._inProgress = false;
3528 			return;
3529 		}
3530 
3531 		if (_action.isObject(NOUN_CURTAIN)) {
3532 			_vm->_dialogs->show(50525);
3533 			_action._inProgress = false;
3534 			return;
3535 		}
3536 
3537 		if (_action.isObject(NOUN_CHRISTINE)) {
3538 			_vm->_dialogs->show((_globals[kCoffinStatus] == 2) ? 50530 : 50537);
3539 			_action._inProgress = false;
3540 			return;
3541 		}
3542 
3543 		if (_action.isObject(NOUN_LID)) {
3544 			_vm->_dialogs->show((_globals[kCoffinStatus] == 2) ? 50531 : 50532);
3545 			_action._inProgress = false;
3546 			return;
3547 		}
3548 	}
3549 
3550 	if (_action.isAction(VERB_LOCK, NOUN_SARCOPHAGUS) || _action.isAction(VERB_LOCK, NOUN_LID) || _action.isAction(VERB_LOCK, NOUN_SKULL_FACE)) {
3551 		_vm->_dialogs->show(50535);
3552 		_action._inProgress = false;
3553 		return;
3554 	}
3555 
3556 	if (_action.isAction(VERB_OPEN, NOUN_SARCOPHAGUS) || _action.isAction(VERB_OPEN, NOUN_LID)) {
3557 		if (_globals[kCoffinStatus] == 2)
3558 			_vm->_dialogs->show(50533);
3559 		else if (_globals[kCoffinStatus] == 1)
3560 			_vm->_dialogs->show(50518);
3561 		else
3562 			_vm->_dialogs->show(50515);
3563 		_action._inProgress = false;
3564 		return;
3565 	}
3566 
3567 	if (_action.isAction(VERB_TAKE, NOUN_CHRISTINE) && (_globals[kCoffinStatus] != 2)) {
3568 		_vm->_dialogs->show(50538);
3569 		_action._inProgress = false;
3570 		return;
3571 	}
3572 
3573 	if (_action.isAction(VERB_TAKE, NOUN_CHRISTINE)) {
3574 		_vm->_dialogs->show((_globals[kCoffinStatus] <= 1) ? 50538 : 50540);
3575 		_action._inProgress = false;
3576 	}
3577 }
3578 
preActions()3579 void Scene505::preActions() {
3580 	if ((_globals[kCoffinStatus] == 0) && (_action.isAction(VERB_UNLOCK, NOUN_SKULL_FACE) || _action.isAction(VERB_UNLOCK, NOUN_SARCOPHAGUS) || _action.isAction(VERB_PUT, NOUN_KEY, NOUN_SKULL_FACE) || _action.isAction(VERB_UNLOCK, NOUN_LID))) {
3581 		if (_action.isObject(NOUN_SKULL_FACE) || _globals[kLookedAtSkullFace])
3582 			_game._player.walk(Common::Point(279, 150), FACING_SOUTHWEST);
3583 	}
3584 
3585 	if (_action.isObject(NOUN_SKULL_FACE) && (_action.isAction(VERB_LOOK) || _action.isAction(VERB_LOOK_AT)))
3586 		_game._player.walk(Common::Point(279, 150), FACING_SOUTHWEST);
3587 
3588 	if (_action.isObject(NOUN_CURTAIN) && (_action.isAction(VERB_LOOK) || _action.isAction(VERB_LOOK_AT)))
3589 		_game._player._needToWalk = true;
3590 
3591 	if (_action.isObject(NOUN_SKULL) && (_action.isAction(VERB_LOOK) || _action.isAction(VERB_LOOK_AT)))
3592 		_game._player._needToWalk = true;
3593 }
3594 
handleCoffinDialog()3595 void Scene505::handleCoffinDialog() {
3596 	int interlocutorFl = false;
3597 	int heroFl = false;
3598 
3599 	switch (_action._activeAction._verbId) {
3600 	case 8:
3601 		heroFl = true;
3602 		interlocutorFl = true;
3603 		_bothStatus = 6;
3604 		break;
3605 
3606 	case 14:
3607 		heroFl = true;
3608 		interlocutorFl = true;
3609 		if (!_checkFrame106)
3610 			_vm->_gameConv->hold();
3611 		break;
3612 
3613 	case 17:
3614 		heroFl = true;
3615 		interlocutorFl = true;
3616 		if (!_game._trigger) {
3617 			_vm->_gameConv->hold();
3618 			_raoulStatus = 2;
3619 		}
3620 		break;
3621 
3622 	case 20:
3623 		heroFl = true;
3624 		interlocutorFl = true;
3625 		if (!_game._trigger) {
3626 			_vm->_gameConv->hold();
3627 			_game._player.walk(Common::Point(244, 130), FACING_SOUTHWEST);
3628 			_game._player.setWalkTrigger(71);
3629 		}
3630 		break;
3631 
3632 	case 22:
3633 		heroFl = true;
3634 		interlocutorFl = true;
3635 		if (!_game._trigger) {
3636 			_vm->_gameConv->hold();
3637 			_bothStatus = 7;
3638 		}
3639 		break;
3640 
3641 	default:
3642 		break;
3643 	}
3644 
3645 	switch (_game._trigger) {
3646 	case 70:
3647 	case 76:
3648 		_vm->_gameConv->release();
3649 		break;
3650 
3651 	case 71:
3652 		_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('r', 1), 75);
3653 		_anim0ActvFl = true;
3654 		_raoulStatus = 0;
3655 		_raoulCount = 0;
3656 		_game._player._visible = false;
3657 		break;
3658 
3659 	case 75:
3660 		_game._player._visible = true;
3661 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[0]);
3662 		_scene->_sequences.addTimer(10, 76);
3663 		break;
3664 
3665 	case 85:
3666 		if ((_bothStatus != 6) && (_bothStatus != 0))
3667 			_bothStatus = 5;
3668 		break;
3669 
3670 	case 90:
3671 		if ((_bothStatus != 6) && (_bothStatus != 0))
3672 			_bothStatus = 4;
3673 		break;
3674 
3675 	default:
3676 		break;
3677 	}
3678 
3679 	if (!heroFl)
3680 		_vm->_gameConv->setHeroTrigger(85);
3681 
3682 	if (!interlocutorFl)
3683 		_vm->_gameConv->setInterlocutorTrigger(90);
3684 
3685 	_bothCount = 0;
3686 }
3687 
handleRaoulAnimation()3688 void Scene505::handleRaoulAnimation() {
3689 	int curFrame = _scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame();
3690 	if (curFrame == _raoulFrame)
3691 		return;
3692 
3693 	_raoulFrame = curFrame;
3694 	int resetFrame = -1;
3695 
3696 	switch (_raoulFrame) {
3697 	case 3:
3698 		_vm->_gameConv->release();
3699 		break;
3700 
3701 	case 4:
3702 	case 5:
3703 	case 6:
3704 		if (_raoulStatus == 0) {
3705 			resetFrame = _vm->getRandomNumber(3, 5);
3706 			++_raoulCount;
3707 			if (_raoulCount > 20) {
3708 				_raoulStatus = 1;
3709 				resetFrame = 3;
3710 			}
3711 			break;
3712 		}
3713 
3714 		if (_raoulStatus == 1)
3715 			resetFrame = 3;
3716 
3717 		if (_raoulStatus == 2)
3718 			resetFrame = 6;
3719 		break;
3720 
3721 	default:
3722 		break;
3723 	}
3724 
3725 	if (resetFrame >= 0) {
3726 		_scene->setAnimFrame(_globals._animationIndexes[0], resetFrame);
3727 		_raoulFrame = resetFrame;
3728 	}
3729 }
3730 
handleBothanimation()3731 void Scene505::handleBothanimation() {
3732 	int curFrame = _scene->_animation[_globals._animationIndexes[1]]->getCurrentFrame();
3733 	if (curFrame == _bothFrame)
3734 		return;
3735 
3736 	_bothFrame = curFrame;
3737 	int resetFrame = -1;
3738 
3739 	switch (_bothFrame) {
3740 	case 1:
3741 	case 20:
3742 	case 39:
3743 		if (_bothStatus == 0) {
3744 			if (_vm->getRandomNumber(1, 35) == 1) {
3745 				if (_vm->getRandomNumber(1, 2) == 1)
3746 					resetFrame = 1;
3747 				else
3748 					resetFrame = 20;
3749 			} else
3750 				resetFrame = 0;
3751 		} else if (_bothStatus == 1)
3752 			resetFrame = 39;
3753 		else
3754 			resetFrame = 0;
3755 		break;
3756 
3757 	case 14:
3758 		if (_vm->getRandomNumber(1, 3) == 1)
3759 			resetFrame = 8;
3760 		break;
3761 
3762 	case 32:
3763 		if (_vm->getRandomNumber(1, 2) == 1)
3764 			resetFrame = 28;
3765 		break;
3766 
3767 	case 41:
3768 		_vm->_sound->command(39);
3769 		break;
3770 
3771 	case 51:
3772 		_globals._sequenceIndexes[7] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[7], false, 12);
3773 		_scene->_sequences.setDepth(_globals._sequenceIndexes[7], 1);
3774 		_globals[kCoffinStatus] = 2;
3775 		break;
3776 
3777 	case 66:
3778 		_game._player._stepEnabled = false;
3779 		_vm->_gameConv->run(20);
3780 		_vm->_gameConv->exportPointer(&_globals[kPlayerScore]);
3781 		break;
3782 
3783 	case 67:
3784 		if (_bothStatus == 1)
3785 			resetFrame = 66;
3786 		break;
3787 
3788 	case 68:
3789 		_game._player._visible = false;
3790 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[1]);
3791 		break;
3792 
3793 	case 106:
3794 		_checkFrame106 = true;
3795 		_vm->_gameConv->release();
3796 		break;
3797 
3798 	case 109:
3799 	case 130:
3800 		_vm->_gameConv->release();
3801 		break;
3802 
3803 	case 110:
3804 	case 111:
3805 	case 112:
3806 	case 113:
3807 	case 114:
3808 	case 115:
3809 	case 131:
3810 		switch (_bothStatus) {
3811 		case 4:
3812 			resetFrame = _vm->getRandomNumber(112, 114);
3813 			++_bothCount;
3814 			if (_bothCount > 20) {
3815 				_bothStatus = 3;
3816 				resetFrame = 109;
3817 			}
3818 			break;
3819 
3820 		case 5:
3821 			resetFrame = _vm->getRandomNumber(109, 111);
3822 			++_bothCount;
3823 			if (_bothCount > 20) {
3824 				_bothStatus = 3;
3825 				resetFrame = 109;
3826 			}
3827 			break;
3828 
3829 		case 6:
3830 			resetFrame = 131;
3831 			_bothStatus = 8;
3832 			_game._player._stepEnabled = false;
3833 			break;
3834 
3835 		case 7:
3836 			resetFrame = 115;
3837 			_bothStatus = 3;
3838 			break;
3839 
3840 		default:
3841 			resetFrame = 109;
3842 			break;
3843 		}
3844 		break;
3845 
3846 	case 127:
3847 		_vm->_sound->command(26);
3848 		_game._objects.addToInventory(OBJ_WEDDING_RING);
3849 		_vm->_dialogs->showItem(OBJ_WEDDING_RING, 821, 0);
3850 		break;
3851 
3852 	default:
3853 		break;
3854 	}
3855 
3856 	if (resetFrame >= 0) {
3857 		_scene->setAnimFrame(_globals._animationIndexes[1], resetFrame);
3858 		_bothFrame = resetFrame;
3859 	}
3860 }
3861 
handlePartedAnimation()3862 void Scene505::handlePartedAnimation() {
3863 	int curFrame = _scene->_animation[_globals._animationIndexes[2]]->getCurrentFrame();
3864 	if (curFrame == _partFrame)
3865 		return;
3866 
3867 	_partFrame = curFrame;
3868 	int resetFrame = -1;
3869 
3870 	switch (_partFrame) {
3871 	case 20:
3872 		_vm->_sound->command(16);
3873 		break;
3874 
3875 	case 25:
3876 		_game._player._playerPos = Common::Point(93, 133);
3877 		_game._player.resetFacing(FACING_WEST);
3878 		_game._player._visible = true;
3879 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[2]);
3880 		break;
3881 
3882 	case 70:
3883 		_game._player._stepEnabled = true;
3884 		break;
3885 
3886 	case 90:
3887 		if (_partStatus == 10)
3888 			resetFrame = 146;
3889 		else if (!_leaveRoomFl)
3890 			resetFrame = 89;
3891 		break;
3892 
3893 	case 145:
3894 		_scene->_nextSceneId = 504;
3895 		break;
3896 
3897 	case 147:
3898 	case 148:
3899 	case 149:
3900 		resetFrame = _vm->getRandomNumber(146, 148);
3901 		++_partCount;
3902 		if (_partCount > 10) {
3903 			resetFrame = 89;
3904 			_partStatus = 8;
3905 		}
3906 		break;
3907 
3908 	default:
3909 		break;
3910 	}
3911 
3912 	if (resetFrame >= 0) {
3913 		_scene->setAnimFrame(_globals._animationIndexes[2], resetFrame);
3914 		_partFrame = resetFrame;
3915 	}
3916 }
3917 
3918 /*------------------------------------------------------------------------*/
3919 
Scene506(MADSEngine * vm)3920 Scene506::Scene506(MADSEngine *vm) : Scene5xx(vm) {
3921 	_anim0ActvFl = false;
3922 	_skipFl = false;
3923 	_ascendingFl = false;
3924 }
3925 
synchronize(Common::Serializer & s)3926 void Scene506::synchronize(Common::Serializer &s) {
3927 	Scene5xx::synchronize(s);
3928 
3929 	s.syncAsByte(_anim0ActvFl);
3930 	s.syncAsByte(_skipFl);
3931 	s.syncAsByte(_ascendingFl);
3932 }
3933 
setup()3934 void Scene506::setup() {
3935 	setPlayerSpritesPrefix();
3936 	setAAName();
3937 
3938 	_scene->addActiveVocab(NOUN_CHRISTINE);
3939 	_scene->addActiveVocab(VERB_LOOK_AT);
3940 
3941 	if (!_globals[kChristineIsInBoat])
3942 		_scene->_variant = 1;
3943 }
3944 
enter()3945 void Scene506::enter() {
3946 	_vm->_disableFastwalk = true;
3947 
3948 	if (_scene->_priorSceneId != RETURNING_FROM_LOADING) {
3949 		_anim0ActvFl = false;
3950 		_skipFl = false;
3951 		_ascendingFl = false;
3952 	}
3953 
3954 	_vm->_gameConv->load(26);
3955 
3956 	_globals._spriteIndexes[0] = _scene->_sprites.addSprites(formAnimName('x', 0));
3957 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('x', 1));
3958 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('x', 2));
3959 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('x', 3));
3960 	_globals._spriteIndexes[5] = _scene->_sprites.addSprites(formAnimName('p', 0));
3961 	_globals._spriteIndexes[7] = _scene->_sprites.addSprites(formAnimName('a', 1));
3962 	_globals._spriteIndexes[8] = _scene->_sprites.addSprites(formAnimName('a', 0));
3963 	_globals._spriteIndexes[6] = _scene->_sprites.addSprites(formAnimName('b', 0), PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
3964 	_globals._spriteIndexes[4] = _scene->_sprites.addSprites("*RDR_9");
3965 	_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_6", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
3966 	_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_3", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
3967 	_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*CHR_2", PALFLAG_ALL_TO_CLOSEST | PALFLAG_ANY_TO_CLOSEST);
3968 
3969 	if (_game._objects.isInRoom(OBJ_OAR)) {
3970 		_globals._sequenceIndexes[5] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[5], false, 1);
3971 		_scene->_sequences.setDepth(_globals._sequenceIndexes[5], 14);
3972 	} else
3973 		_scene->_hotspots.activate(NOUN_OAR, false);
3974 
3975 	_globals._sequenceIndexes[0] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[0], false, 6, 0);
3976 	_scene->_sequences.setDepth(_globals._sequenceIndexes[0], 14);
3977 	_scene->_sequences.setAnimRange(_globals._sequenceIndexes[0], -1, -2);
3978 
3979 	_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 6, 0);
3980 	_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 14);
3981 	_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], -1, -2);
3982 
3983 	_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 6, 0);
3984 	_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 14);
3985 	_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], -1, -2);
3986 
3987 	if (_scene->_priorSceneId == RETURNING_FROM_LOADING) {
3988 		_globals._sequenceIndexes[3] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[3], false, 1);
3989 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 14);
3990 		if (!_globals[kChristineIsInBoat]) {
3991 			_anim0ActvFl = true;
3992 			_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('r', 1), 0);
3993 			_scene->setAnimFrame(_globals._animationIndexes[0], 239);
3994 			int hotspotIdx = _scene->_dynamicHotspots.add(NOUN_CHRISTINE, VERB_WALK_TO, SYNTAX_SINGULAR_FEM, EXT_NONE, Common::Rect(0, 0, 0, 0));
3995 			_scene->_dynamicHotspots[hotspotIdx]._articleNumber = PREP_ON;
3996 			_scene->_dynamicHotspots.setPosition(hotspotIdx, Common::Point(79, 133), FACING_SOUTHWEST);
3997 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[0], 6);
3998 		}
3999 	} else if (_scene->_priorSceneId == 504) {
4000 		_globals._sequenceIndexes[3] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[3], false, 1);
4001 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 14);
4002 
4003 		if (_game._visitedScenes._sceneRevisited) {
4004 			_game._player._playerPos = Common::Point(189, 123);
4005 			_game._player._facing = FACING_SOUTHWEST;
4006 			_game._player._stepEnabled = false;
4007 			_game._player._visible = false;
4008 
4009 			if (!_globals[kChristineIsInBoat]) {
4010 				_anim0ActvFl = true;
4011 				_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('r', 1), 0);
4012 				_scene->setAnimFrame(_globals._animationIndexes[0], 239);
4013 				int hotspotIdx = _scene->_dynamicHotspots.add(NOUN_CHRISTINE, VERB_WALK_TO, SYNTAX_SINGULAR_FEM, EXT_NONE, Common::Rect(0, 0, 0, 0));
4014 				_scene->_dynamicHotspots[hotspotIdx]._articleNumber = PREP_ON;
4015 				_scene->_dynamicHotspots.setPosition(hotspotIdx, Common::Point(79, 133), FACING_SOUTHWEST);
4016 				_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[0], 6);
4017 			}
4018 			_globals._animationIndexes[1] = _scene->loadAnimation(formAnimName('r', 2), 95);
4019 		} else {
4020 			_game._player._playerPos = Common::Point(186, 122);
4021 			_game._player._facing = FACING_SOUTHWEST;
4022 			_game._player._stepEnabled = false;
4023 			_game._player._visible = false;
4024 			_anim0ActvFl = true;
4025 			_globals._animationIndexes[0] = _scene->loadAnimation(formAnimName('r', 1), 0);
4026 			int hotspotIdx = _scene->_dynamicHotspots.add(NOUN_CHRISTINE, VERB_WALK_TO, SYNTAX_SINGULAR_FEM, EXT_NONE, Common::Rect(0, 0, 0, 0));
4027 			_scene->_dynamicHotspots[hotspotIdx]._articleNumber = PREP_ON;
4028 			_scene->_dynamicHotspots.setPosition(hotspotIdx, Common::Point(79, 133), FACING_SOUTHWEST);
4029 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[0], 2);
4030 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[0], 3);
4031 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[0], 4);
4032 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[0], 5);
4033 			_scene->setDynamicAnim(hotspotIdx, _globals._animationIndexes[0], 6);
4034 		}
4035 	} else if ((_scene->_priorSceneId == 501) || (_scene->_priorSceneId != RETURNING_FROM_LOADING)) {
4036 		_game._player._playerPos = Common::Point(0, 142);
4037 		_game._player._facing = FACING_EAST;
4038 		_game._player._stepEnabled = false;
4039 		_game._player.walk(Common::Point(23, 145), FACING_EAST);
4040 		_game._player.setWalkTrigger(60);
4041 	}
4042 
4043 	sceneEntrySound();
4044 }
4045 
step()4046 void Scene506::step() {
4047 	switch (_game._trigger) {
4048 	case 60:
4049 		_globals._sequenceIndexes[3] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[3], false, 6, 1);
4050 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 14);
4051 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], -1, -2);
4052 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 61);
4053 		break;
4054 
4055 	case 61:
4056 		_globals._sequenceIndexes[3] = _scene->_sequences.addStampCycle(_globals._spriteIndexes[3], false, 1);
4057 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 14);
4058 		_game._player._stepEnabled = true;
4059 		break;
4060 
4061 	case 95:
4062 		_game._player._visible = true;
4063 		_game._player._stepEnabled = true;
4064 		_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[1]);
4065 		break;
4066 
4067 	default:
4068 		break;
4069 	}
4070 
4071 	if (_anim0ActvFl) {
4072 		int curFrame = _scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame();
4073 		if ((curFrame == 141) && !_skipFl) {
4074 			_game._player._visible = true;
4075 			_skipFl = true;
4076 			_game.syncTimers(SYNC_PLAYER, 0, SYNC_ANIM, _globals._animationIndexes[0]);
4077 		}
4078 
4079 		if (curFrame == 240)
4080 			_scene->setAnimFrame(_globals._animationIndexes[0], 239);
4081 
4082 		if (curFrame == 300)
4083 			_scene->setAnimFrame(_globals._animationIndexes[0], 239);
4084 
4085 		if (curFrame == 168)
4086 			_game._player._stepEnabled = true;
4087 
4088 		if (curFrame == 289)
4089 			_scene->_nextSceneId = 501;
4090 	}
4091 
4092 	if (_ascendingFl && (_vm->_gameConv->activeConvId() != 26)) {
4093 		_ascendingFl = false;
4094 		_game._player._stepEnabled = false;
4095 	}
4096 }
4097 
actions()4098 void Scene506::actions() {
4099 	if (_action.isAction(VERB_TALK_TO, NOUN_CHRISTINE)) {
4100 		_vm->_gameConv->run(26);
4101 		_vm->_gameConv->exportValue(1);
4102 		_scene->setAnimFrame(_globals._animationIndexes[0], 290);
4103 		_action._inProgress = false;
4104 		return;
4105 	}
4106 
4107 	if (_action.isAction(VERB_TAKE, NOUN_OAR)) {
4108 		switch (_game._trigger) {
4109 		case (0):
4110 			if (_game._objects.isInRoom(OBJ_OAR)) {
4111 				_game._player._stepEnabled = false;
4112 				_game._player._visible = false;
4113 				_globals._sequenceIndexes[4] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[4], true, 5, 2);
4114 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], 1, 4);
4115 				_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[4], true);
4116 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_SPRITE, 4, 1);
4117 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4118 			}
4119 			break;
4120 
4121 		case 1:
4122 			_scene->deleteSequence(_globals._sequenceIndexes[5]);
4123 			_scene->_hotspots.activate(NOUN_OAR, false);
4124 			_game._objects.addToInventory(OBJ_OAR);
4125 			_vm->_sound->command(26);
4126 			break;
4127 
4128 		case 2:
4129 			_game.syncTimers(SYNC_PLAYER, 0, SYNC_SEQ, _globals._sequenceIndexes[4]);
4130 			_game._player._visible = true;
4131 			_scene->_sequences.addTimer(20, 3);
4132 			break;
4133 
4134 		case 3:
4135 			_vm->_dialogs->showItem(OBJ_OAR, 824, 0);
4136 			_game._player._stepEnabled = true;
4137 			break;
4138 
4139 		default:
4140 			break;
4141 		}
4142 		_action._inProgress = false;
4143 		return;
4144 	}
4145 
4146 
4147 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_DOOR) || _action.isAction(VERB_OPEN, NOUN_DOOR)) {
4148 		if (_scene->_customDest.x < 150) {
4149 			switch (_game._trigger) {
4150 			case (0):
4151 				_game._player._stepEnabled = false;
4152 				_game._player._visible = false;
4153 				_globals._sequenceIndexes[4] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[4], true, 5, 2);
4154 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], 1, 4);
4155 				_scene->_sequences.setSeqPlayer(_globals._sequenceIndexes[4], true);
4156 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_SPRITE, 4, 65);
4157 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 67);
4158 				break;
4159 
4160 			case 65:
4161 				_scene->deleteSequence(_globals._sequenceIndexes[3]);
4162 				_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 8, 1);
4163 				_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 14);
4164 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], -1, -2);
4165 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 66);
4166 				_vm->_sound->command(24);
4167 				break;
4168 
4169 			case 66:
4170 				_game._player.walk(Common::Point(0, 142), FACING_WEST);
4171 				_game._player.setWalkTrigger(68);
4172 				break;
4173 
4174 			case 67:
4175 				_game._player._visible = true;
4176 				break;
4177 
4178 			case 68:
4179 				if (_globals[kChristineIsInBoat])
4180 					_scene->_nextSceneId = 501;
4181 				else
4182 					_scene->setAnimFrame(_globals._animationIndexes[0], 241);
4183 				break;
4184 
4185 			default:
4186 				break;
4187 			}
4188 		} else {
4189 			switch (_game._trigger) {
4190 			case (0):
4191 				if (!_globals[kChristineIsInBoat]) {
4192 					_vm->_gameConv->run(26);
4193 					_vm->_gameConv->exportValue(2);
4194 					int curFrame = _scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame();
4195 					if (curFrame == 240 || curFrame == 239)
4196 						_scene->setAnimFrame(_globals._animationIndexes[0], 290);
4197 					_ascendingFl = true;
4198 				}
4199 				_game._player._stepEnabled = false;
4200 				_game._player._visible = false;
4201 				_globals._sequenceIndexes[7] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[7], false, 5, 1);
4202 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[7], -1, -2);
4203 				_game.syncTimers(SYNC_SEQ, _globals._sequenceIndexes[7], SYNC_PLAYER, 0);
4204 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[7], SEQUENCE_TRIGGER_EXPIRE, 0, 90);
4205 				break;
4206 
4207 			case 90:
4208 				_vm->_gameConv->stop();
4209 				_scene->_nextSceneId = 504;
4210 				break;
4211 
4212 			default:
4213 				break;
4214 			}
4215 		}
4216 		_action._inProgress = false;
4217 		return;
4218 	}
4219 
4220 	if (_vm->_gameConv->activeConvId() == 26) {
4221 		_action._inProgress = false;
4222 		return;
4223 	}
4224 
4225 	if (_action._lookFlag) {
4226 		_vm->_dialogs->show(50610);
4227 		_action._inProgress = false;
4228 		return;
4229 	}
4230 
4231 	if (_action.isAction(VERB_LOOK) || _action.isAction(VERB_LOOK_AT)) {
4232 		if (_action.isObject(NOUN_FLOOR)) {
4233 			_vm->_dialogs->show(50611);
4234 			_action._inProgress = false;
4235 			return;
4236 		}
4237 
4238 		if (_action.isObject(NOUN_WALL)) {
4239 			_vm->_dialogs->show(50612);
4240 			_action._inProgress = false;
4241 			return;
4242 		}
4243 
4244 		if (_action.isObject(NOUN_TORCH)) {
4245 			_vm->_dialogs->show(50613);
4246 			_action._inProgress = false;
4247 			return;
4248 		}
4249 
4250 		if (_action.isObject(NOUN_COLUMN)) {
4251 			_vm->_dialogs->show(50614);
4252 			_action._inProgress = false;
4253 			return;
4254 		}
4255 
4256 		if (_action.isObject(NOUN_CEILING)) {
4257 			_vm->_dialogs->show(50615);
4258 			_action._inProgress = false;
4259 			return;
4260 		}
4261 
4262 		if (_action.isObject(NOUN_RAMP)) {
4263 			_vm->_dialogs->show(50616);
4264 			_action._inProgress = false;
4265 			return;
4266 		}
4267 
4268 		if (_action.isObject(NOUN_DOOR)) {
4269 			if (_scene->_customDest.x < 150)
4270 				_vm->_dialogs->show(50617);
4271 			else
4272 				_vm->_dialogs->show(50618);
4273 			_action._inProgress = false;
4274 			return;
4275 		}
4276 
4277 		if (_action.isObject(NOUN_OAR) && _game._objects.isInRoom(OBJ_OAR)) {
4278 			_vm->_dialogs->show(50619);
4279 			_action._inProgress = false;
4280 			return;
4281 		}
4282 
4283 		if (_action.isObject(NOUN_CHRISTINE)) {
4284 			if (_scene->_animation[_globals._animationIndexes[0]]->getCurrentFrame() < 235)
4285 				_vm->_dialogs->show(50621);
4286 			else
4287 				_vm->_dialogs->show(50620);
4288 			_action._inProgress = false;
4289 			return;
4290 		}
4291 	}
4292 
4293 	if (_action.isAction(VERB_TAKE, NOUN_TORCH)) {
4294 		_vm->_dialogs->show(50613);
4295 		_action._inProgress = false;
4296 		return;
4297 	}
4298 
4299 	if (_action.isAction(VERB_TAKE, NOUN_CHRISTINE)) {
4300 		_vm->_dialogs->show(50622);
4301 		_action._inProgress = false;
4302 	}
4303 }
4304 
preActions()4305 void Scene506::preActions() {
4306 	if (_action.isAction(VERB_UNLOCK, NOUN_DOOR) || _action.isAction(VERB_LOCK, NOUN_DOOR))
4307 		_game._player.walk(Common::Point(33, 142), FACING_NORTHWEST);
4308 
4309 	if (_action.isAction(VERB_OPEN, NOUN_DOOR)) {
4310 		if (_scene->_customDest.x < 150)
4311 			_game._player.walk(Common::Point(33, 142), FACING_NORTHWEST);
4312 		else
4313 			_game._player.walk(Common::Point(191, 118), FACING_EAST);
4314 	}
4315 }
4316 
4317 /*------------------------------------------------------------------------*/
4318 
4319 } // End of namespace Phantom
4320 } // End of namespace MADS
4321 
4322 #endif
4323