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