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/scene.h"
26 #include "mads/nebular/nebular_scenes.h"
27 #include "mads/nebular/nebular_scenes3.h"
28 
29 namespace MADS {
30 
31 namespace Nebular {
32 
setAAName()33 void Scene3xx::setAAName() {
34 	_game._aaName = Resources::formatAAName(4);
35 }
36 
setPlayerSpritesPrefix()37 void Scene3xx::setPlayerSpritesPrefix() {
38 	_vm->_sound->command(5);
39 
40 	Common::String oldName = _game._player._spritesPrefix;
41 
42 	if (_globals[kSexOfRex] == REX_MALE)
43 		_game._player._spritesPrefix = "RXM";
44 	else
45 		_game._player._spritesPrefix = "ROX";
46 
47 	if ((_scene->_nextSceneId == 313) || (_scene->_nextSceneId == 366)
48 	|| ((_scene->_nextSceneId >= 301) && (_scene->_nextSceneId <= 303))
49 	|| ((_scene->_nextSceneId == 304) && (_scene->_currentSceneId == 303))
50 	|| ((_scene->_nextSceneId == 311) && (_scene->_currentSceneId == 304))
51 	|| ((_scene->_nextSceneId >= 308) && (_scene->_nextSceneId <= 310))
52 	|| ((_scene->_nextSceneId >= 319) && (_scene->_nextSceneId <= 322))
53 	|| ((_scene->_nextSceneId >= 387) && (_scene->_nextSceneId <= 391))) {
54 		_game._player._spritesPrefix = "";
55 		_game._player._spritesChanged = true;
56 	}
57 
58 	_game._player._scalingVelocity = true;
59 	if (oldName != _game._player._spritesPrefix)
60 		_game._player._spritesChanged = true;
61 
62 	_vm->_palette->setEntry(16, 10, 63, 63);
63 	_vm->_palette->setEntry(17, 10, 45, 45);
64 }
65 
sceneEntrySound()66 void Scene3xx::sceneEntrySound() {
67 	if (!_vm->_musicFlag) {
68 		_vm->_sound->command(2);
69 		return;
70 	}
71 
72 	switch (_scene->_nextSceneId) {
73 	case 301:
74 	case 302:
75 	case 303:
76 	case 304:
77 	case 308:
78 	case 309:
79 	case 310:
80 		_vm->_sound->command(11);
81 		break;
82 
83 	case 311:
84 		if (_scene->_priorSceneId == 304)
85 			_vm->_sound->command(11);
86 		else
87 			_vm->_sound->command(10);
88 		break;
89 
90 	case 313:
91 	case 316:
92 	case 320:
93 	case 322:
94 	case 357:
95 	case 358:
96 	case 359:
97 	case 360:
98 	case 361:
99 	case 387:
100 	case 388:
101 	case 389:
102 	case 390:
103 	case 391:
104 	case 399:
105 		_vm->_sound->command(10);
106 		break;
107 
108 	case 318:
109 		if ((_scene->_priorSceneId == 357) || (_scene->_priorSceneId == 407))
110 			_vm->_sound->command(10);
111 		else if (_scene->_priorSceneId == 319)
112 			_vm->_sound->command(16);
113 		else
114 			_vm->_sound->command(3);
115 
116 		_vm->_sound->command(50);
117 		break;
118 
119 	case 319:
120 		_vm->_sound->command(16);
121 		break;
122 
123 	case 321:
124 		_vm->_sound->command(18);
125 		break;
126 
127 	default:
128 		break;
129 	}
130 }
131 
initForceField(ForceField * force,bool flag)132 void Scene3xx::initForceField(ForceField *force, bool flag) {
133 	force->_flag = flag;
134 	force->_vertical = 0;
135 	force->_horizontal = 0;
136 	force->_timer = 0;
137 
138 	for (int count = 0; count < 40; count++)
139 		force->_seqId[count] = -1;
140 
141 	if (force->_flag)
142 		_vm->_sound->command(24);
143 }
144 
computeScale(int low,int high,int id)145 int Scene3xx::computeScale(int low, int high, int id) {
146 	int diff = high - (low + 2);
147 	int quotient = diff / 20;
148 	int remainder = diff % 20;
149 	int value = low + 2 + (quotient * id) + (remainder / (id + 1));
150 
151 	return (value);
152 }
153 
handleForceField(ForceField * force,int * sprites)154 void Scene3xx::handleForceField(ForceField *force, int *sprites) {
155 	if (_game._trigger >= 150) {
156 		int id = _game._trigger - 150;
157 		if (id < 40) {
158 			if (id < 20)
159 				force->_vertical--;
160 			else
161 				force->_horizontal--;
162 
163 			force->_seqId[id] = -1;
164 		}
165 		return;
166 	}
167 
168 	if (!force->_flag || (_scene->_frameStartTime < force->_timer) || (force->_vertical + force->_horizontal >= 5))
169 		return;
170 
171 	if (_vm->getRandomNumber(1, 1000) <= (200 + ((40 - (force->_vertical + force->_horizontal)) << 5))) {
172 		int id = -1;
173 		for (int i = 0; i < 100; i++) {
174 			int randIdx = _vm->getRandomNumber(0, 39);
175 			if (force->_seqId[randIdx] < 0) {
176 				id = randIdx;
177 				break;
178 			}
179 		}
180 
181 		if (id < 0) {
182 			for (int i = 0; i < 40; i++) {
183 				if (force->_seqId[i] < 0) {
184 					id = i;
185 					break;
186 				}
187 			}
188 		}
189 
190 		int speedX, speedY;
191 		int posX, posY;
192 		int randVal = _vm->getRandomNumber(1, 100);
193 		int spriteId;
194 		bool mirror;
195 
196 		if (id >= 20) {
197 			spriteId = 2;
198 			mirror = (randVal <= 50);
199 			posX = mirror ? 315 : 5;
200 			posY = computeScale(15, 119, id - 20);
201 			speedX = 1000 * (mirror ? -1 : 1);
202 			speedY = 0;
203 		} else if (randVal <= 50) {
204 			spriteId = 1;
205 			mirror = false;
206 			posX = computeScale(21, 258, id);
207 			posY = 0;
208 			speedX = 0;
209 			speedY = 600;
210 		} else {
211 			spriteId = 0;
212 			mirror = false;
213 			posX = computeScale(21, 258, id);
214 			posY = 155;
215 			speedX = 0;
216 			speedY = -600;
217 		}
218 
219 		if (id >= 0) {
220 			force->_seqId[id] = _scene->_sequences.addSpriteCycle(sprites[spriteId], mirror, 2, 0, 0, 0);
221 			_scene->_sequences.setDepth(force->_seqId[id], 8);
222 			_scene->_sequences.setPosition(force->_seqId[id], Common::Point(posX, posY));
223 			_scene->_sequences.setMotion(force->_seqId[id], 2, speedX, speedY);
224 			_scene->_sequences.addSubEntry(force->_seqId[id], SEQUENCE_TRIGGER_EXPIRE, 0, 150 + id);
225 			if (spriteId == 2)
226 				force->_horizontal++;
227 			else
228 				force->_vertical++;
229 		}
230 	}
231 
232 	force->_timer = _scene->_frameStartTime + 4;
233 }
234 
235 /*------------------------------------------------------------------------*/
236 
preActions()237 void Scene300s::preActions() {
238 	_game._player._needToWalk = false;
239 }
240 
241 /*------------------------------------------------------------------------*/
242 
setup()243 void Scene301::setup() {
244 	setPlayerSpritesPrefix();
245 	setAAName();
246 }
247 
enter()248 void Scene301::enter() {
249 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('x', 0));
250 	_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 9, 0, 0, 0);
251 
252 	_globals[kMeteorologistStatus] = METEOROLOGIST_GONE;
253 	_globals[kTeleporterCommand] = TELEPORTER_NONE;
254 
255 	_game._player._stepEnabled = false;
256 	_game._player._visible = false;
257 	_scene->loadAnimation(formAnimName('a', -1), 60);
258 
259 	sceneEntrySound();
260 }
261 
step()262 void Scene301::step() {
263 	if (_game._trigger == 60)
264 		_scene->_nextSceneId = 302;
265 }
266 
267 /*------------------------------------------------------------------------*/
268 
Scene302(MADSEngine * vm)269 Scene302::Scene302(MADSEngine *vm) : Scene3xx(vm) {
270 	_oldFrame = 0;
271 }
272 
synchronize(Common::Serializer & s)273 void Scene302::synchronize(Common::Serializer &s) {
274 	Scene3xx::synchronize(s);
275 
276 	s.syncAsSint32LE(_oldFrame);
277 }
278 
setup()279 void Scene302::setup() {
280 	setPlayerSpritesPrefix();
281 	setAAName();
282 }
283 
enter()284 void Scene302::enter() {
285 	_game._player._stepEnabled = false;
286 	_game._player._visible = false;
287 
288 	_scene->loadAnimation(formAnimName('a', -1), 71);
289 	sceneEntrySound();
290 }
291 
step()292 void Scene302::step() {
293 	if (_game._trigger == 71)
294 		_scene->_nextSceneId = 303;
295 
296 	if ((_scene->_animation[0] != nullptr) && (_scene->_animation[0]->getCurrentFrame() != _oldFrame)) {
297 		_oldFrame = _scene->_animation[0]->getCurrentFrame();
298 		if (_oldFrame == 147) {
299 			_game._objects.setRoom(OBJ_POISON_DARTS, 1);
300 			_game._objects.setRoom(OBJ_BLOWGUN, 1);
301 			_game._objects.setRoom(OBJ_REBREATHER, 1);
302 			_game._objects.setRoom(OBJ_STUFFED_FISH, 1);
303 			_game._objects.setRoom(OBJ_DEAD_FISH, 1);
304 			_game._objects.setRoom(OBJ_BURGER, 1);
305 
306 			int count = (int)_game._objects.size();
307 			for (int idx = 0; idx < count; idx++) {
308 				if (_game._objects.isInInventory(idx))
309 					_game._objects.setRoom(idx, 50);
310 			}
311 		}
312 	}
313 }
314 
315 /*------------------------------------------------------------------------*/
316 
setup()317 void Scene303::setup() {
318 	setPlayerSpritesPrefix();
319 	setAAName();
320 }
321 
enter()322 void Scene303::enter() {
323 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('b', 0));
324 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('b', 1));
325 
326 	_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 10, 0, 50, 120);
327 	_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
328 	_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 10, 0, 0, 0);
329 
330 	_game._player._visible = false;
331 	_game._player._stepEnabled = false;
332 	_scene->loadAnimation(formAnimName('a', -1), 60);
333 
334 	sceneEntrySound();
335 }
336 
step()337 void Scene303::step() {
338 	if (_game._trigger == 60)
339 		_scene->_nextSceneId = 304;
340 }
341 
342 /*------------------------------------------------------------------------*/
343 
Scene304(MADSEngine * vm)344 Scene304::Scene304(MADSEngine *vm) : Scene3xx(vm) {
345 	_explosionSpriteId = -1;
346 }
347 
synchronize(Common::Serializer & s)348 void Scene304::synchronize(Common::Serializer &s) {
349 	Scene3xx::synchronize(s);
350 
351 	s.syncAsSint32LE(_explosionSpriteId);
352 }
353 
setup()354 void Scene304::setup() {
355 	setPlayerSpritesPrefix();
356 	setAAName();
357 }
358 
enter()359 void Scene304::enter() {
360 	if (_scene->_priorSceneId == 303) {
361 		_game._player._visible = false;
362 		_game._player._stepEnabled = false;
363 		_scene->loadAnimation(formAnimName('a', -1), 60);
364 	} else {
365 		if (_globals[kSexOfRex] == REX_MALE)
366 			_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('a', 0));
367 		else
368 			_globals._spriteIndexes[4] = _scene->_sprites.addSprites(formAnimName('a', 2));
369 
370 		_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('a', 1));
371 		_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('b', 0));
372 
373 		_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 150, 0, 3, 0);
374 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 2);
375 		_vm->_palette->setEntry(252, 45, 63, 45);
376 		_vm->_palette->setEntry(253, 20, 45, 20);
377 
378 		if (_globals[kSexOfRex] == REX_MALE)
379 			_game._player._playerPos = Common::Point(111, 117);
380 		else
381 			_game._player._playerPos = Common::Point(113, 116);
382 
383 		_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 11, 0, 0, 0);
384 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], -1, -1);
385 		_scene->_sequences.addTimer(48, 70);
386 	}
387 
388 	sceneEntrySound();
389 	_game.loadQuoteSet(0xEB, 0xEC, 0);
390 }
391 
step()392 void Scene304::step() {
393 	if (_game._trigger == 60)
394 		_scene->_nextSceneId = 311;
395 
396 	if (_game._trigger >= 70) {
397 		switch (_game._trigger) {
398 		case 70: {
399 			_game._player._visible = false;
400 			_scene->_sequences.remove(_globals._sequenceIndexes[2]);
401 			_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 8, 1, 0, 0);
402 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 2, 4);
403 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
404 			if (_globals[kSexOfRex] == REX_MALE)
405 				_explosionSpriteId = _globals._spriteIndexes[1];
406 			else
407 				_explosionSpriteId = _globals._spriteIndexes[4];
408 
409 			int sprIdx = _scene->_sequences.addSpriteCycle(_explosionSpriteId, false, 8, 1, 0, 0);
410 			_scene->_sequences.setAnimRange(sprIdx, -1, 4);
411 			_scene->_sequences.setDepth(sprIdx, 1);
412 			_scene->_sequences.addSubEntry(sprIdx, SEQUENCE_TRIGGER_EXPIRE, 0, 71);
413 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 74);
414 			}
415 			break;
416 
417 		case 71:
418 			_scene->_kernelMessages.reset();
419 			_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 0, 60, _game.getQuote(0xEB));
420 			_scene->_sequences.addTimer(1, 72);
421 			break;
422 
423 		case 72: {
424 			_vm->_sound->command(43);
425 			int sprIdx = _scene->_sequences.addSpriteCycle(_explosionSpriteId, false, 8, 1, 0, 0);
426 			_scene->_sequences.setAnimRange(sprIdx, 5, -2);
427 			_scene->_sequences.setDepth(sprIdx, 1);
428 			_scene->_sequences.addSubEntry(sprIdx, SEQUENCE_TRIGGER_EXPIRE, 0, 73);
429 			if (_game._storyMode == STORYMODE_NICE)
430 				_scene->_sequences.addSubEntry(sprIdx, SEQUENCE_TRIGGER_SPRITE, 8, 78);
431 			}
432 			break;
433 
434 		case 73: {
435 			int sprIdx = _scene->_sequences.addSpriteCycle(_explosionSpriteId, false, 8, 0, 0, 0);
436 			_scene->_sequences.setAnimRange(sprIdx, -2, -2);
437 			_scene->_sequences.setDepth(sprIdx, 1);
438 			}
439 			break;
440 
441 		case 74:
442 			_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 8, 1, 0, 0);
443 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 5, -2);
444 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
445 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 75);
446 			break;
447 
448 		case 75:
449 			_globals._sequenceIndexes[2] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[2], false, 8, 1, 0, 0);
450 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 2, -2);
451 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
452 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 76);
453 			break;
454 
455 		case 76:
456 			_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 8, 0, 0, 0);
457 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
458 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 2, 2);
459 			_scene->_sequences.addTimer(48, 77);
460 			break;
461 
462 		case 77:
463 			_scene->_kernelMessages.reset();
464 			_scene->_kernelMessages.add(Common::Point(211, 45), 0xFDFC, 32, 0, 180, _game.getQuote(0xEC));
465 			_scene->_sequences.addTimer(120, 78);
466 			break;
467 
468 		case 78:
469 			_scene->_nextSceneId = 316;
470 			break;
471 
472 		default:
473 			break;
474 		}
475 	}
476 }
477 
478 /*------------------------------------------------------------------------*/
479 
Scene307(MADSEngine * vm)480 Scene307::Scene307(MADSEngine *vm) : Scene3xx(vm) {
481 	_afterPeeingFl = false;
482 	_duringPeeingFl = false;
483 	_grateOpenedFl = false;
484 	_activePrisonerFl = false;
485 
486 	_animationMode = -1;
487 	_prisonerMessageId = -1;
488 	_fieldCollisionCounter = -1;
489 
490 	_lastFrameTime = 0;
491 	_guardTime = 0;
492 	_prisonerTimer = 0;
493 
494 	_subQuote2 = "";
495 
496 	_forceField.init();
497 }
498 
synchronize(Common::Serializer & s)499 void Scene307::synchronize(Common::Serializer &s) {
500 	Scene3xx::synchronize(s);
501 
502 	_forceField.synchronize(s);
503 
504 	s.syncAsByte(_afterPeeingFl);
505 	s.syncAsByte(_duringPeeingFl);
506 	s.syncAsByte(_grateOpenedFl);
507 	s.syncAsByte(_activePrisonerFl);
508 
509 	s.syncAsSint32LE(_animationMode);
510 	s.syncAsSint32LE(_prisonerMessageId);
511 	s.syncAsSint32LE(_fieldCollisionCounter);
512 
513 	s.syncAsUint32LE(_lastFrameTime);
514 	s.syncAsUint32LE(_guardTime);
515 	s.syncAsUint32LE(_prisonerTimer);
516 
517 	s.syncString(_subQuote2);
518 }
519 
setup()520 void Scene307::setup() {
521 	setPlayerSpritesPrefix();
522 	setAAName();
523 	_scene->addActiveVocab(NOUN_AIR_VENT);
524 	_scene->addActiveVocab(VERB_CLIMB_INTO);
525 }
526 
handleRexDialog(int quote)527 void Scene307::handleRexDialog(int quote) {
528 	Common::String curQuote = _game.getQuote(quote);
529 	if (_vm->_font->getWidth(curQuote, _scene->_textSpacing) > 200) {
530 		Common::String subQuote1;
531 		_game.splitQuote(curQuote, subQuote1, _subQuote2);
532 		_scene->_kernelMessages.add(Common::Point(0, -14), 0x1110, 34, 0, 240, subQuote1);
533 		_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 1, 180, _subQuote2);
534 	} else
535 		_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 1, 120, curQuote);
536 }
537 
handlePrisonerEncounter()538 void Scene307::handlePrisonerEncounter() {
539 	switch (_action._activeAction._verbId) {
540 	case 275:
541 		setDialogNode(5);
542 		break;
543 
544 	case 277:
545 		setDialogNode(4);
546 		break;
547 
548 	case 276:
549 		setDialogNode(6);
550 		break;
551 
552 	default:
553 		break;
554 	}
555 }
556 
handlePrisonerSpeech(int firstQuoteId,int number,uint32 timeout)557 void Scene307::handlePrisonerSpeech(int firstQuoteId, int number, uint32 timeout) {
558 	int height = number * 14;
559 	int posY;
560 
561 	if (height < 60)
562 		posY = 65 - height;
563 	else
564 		posY = 78 - (height / 2);
565 
566 	_scene->_kernelMessages.reset();
567 	_activePrisonerFl = true;
568 
569 	int quoteId = firstQuoteId;
570 	for (int count = 0; count < number; count++) {
571 		_game._triggerSetupMode = SEQUENCE_TRIGGER_DAEMON;
572 		_scene->_kernelMessages.add(Common::Point(5, posY), 0xFDFC, 0, 81, timeout, _game.getQuote(quoteId));
573 		posY += 14;
574 		quoteId++;
575 	}
576 }
577 
setDialogNode(int node)578 void Scene307::setDialogNode(int node) {
579 	switch (node) {
580 	case 0:
581 		handlePrisonerSpeech(0x153, 2, 120);
582 		_scene->_userInterface.setup(kInputBuildingSentences);
583 		break;
584 
585 	case 1:
586 		_globals[kMetBuddyBeast] = true;
587 		handlePrisonerSpeech(0x10F, 2, INDEFINITE_TIMEOUT);
588 		_dialog1.start();
589 		break;
590 
591 	case 2:
592 		_globals[kMetBuddyBeast] = true;
593 		handlePrisonerSpeech(0x111, 2, INDEFINITE_TIMEOUT);
594 		_dialog1.start();
595 		break;
596 
597 	case 4:
598 		handlePrisonerSpeech(0x116, 1, 120);
599 		_scene->_userInterface.setup(kInputBuildingSentences);
600 		break;
601 
602 	case 5:
603 		_globals[kKnowsBuddyBeast] = true;
604 		handlePrisonerSpeech(0x117, 2, INDEFINITE_TIMEOUT);
605 		_dialog2.start();
606 		break;
607 
608 	case 6:
609 		handlePrisonerSpeech(0x123, 1, 120);
610 		_scene->_userInterface.setup(kInputBuildingSentences);
611 		break;
612 
613 	case 7:
614 		_globals[kKnowsBuddyBeast] = true;
615 		handlePrisonerSpeech(0x124, 10, INDEFINITE_TIMEOUT);
616 		_dialog2.write(0x11A, false);
617 		_dialog2.write(0x11B, true);
618 		_dialog2.write(0x120, true);
619 		_dialog2.start();
620 		break;
621 
622 	case 8:
623 		handlePrisonerSpeech(0x12E, 6, INDEFINITE_TIMEOUT);
624 		_dialog2.write(0x11A, false);
625 		_dialog2.write(0x11B, false);
626 		_dialog2.write(0x11C, true);
627 		_dialog2.write(0x11D, true);
628 		_dialog2.write(0x11F, true);
629 		_dialog2.start();
630 		break;
631 
632 	case 9:
633 		handlePrisonerSpeech(0x134, 4, INDEFINITE_TIMEOUT);
634 		_dialog2.write(0x11D, false);
635 		_dialog2.start();
636 		break;
637 
638 	case 10:
639 		handlePrisonerSpeech(0x138, 6, INDEFINITE_TIMEOUT);
640 		_dialog2.write(0x11E, false);
641 		_dialog2.start();
642 		break;
643 
644 	case 11:
645 		handlePrisonerSpeech(0x13E, 6, INDEFINITE_TIMEOUT);
646 		_dialog2.write(0x11F, false);
647 		_dialog2.write(0x121, true);
648 		_dialog2.start();
649 		break;
650 
651 	case 12:
652 		handlePrisonerSpeech(0x144, 4, INDEFINITE_TIMEOUT);
653 		_dialog2.write(0x11C, false);
654 		_dialog2.start();
655 		break;
656 
657 	case 13:
658 		handlePrisonerSpeech(0x148, 7, INDEFINITE_TIMEOUT);
659 		_dialog2.write(0x120, false);
660 		_dialog2.start();
661 		break;
662 
663 	case 14:
664 		handlePrisonerSpeech(0x14F, 3, INDEFINITE_TIMEOUT);
665 		_dialog2.write(0x121, false);
666 		_dialog2.start();
667 		break;
668 
669 	case 15:
670 		handlePrisonerSpeech(0x152, 1, 120);
671 		_scene->_userInterface.setup(kInputBuildingSentences);
672 		break;
673 
674 	case 16:
675 		_globals[kKnowsBuddyBeast] = true;
676 		handlePrisonerSpeech(0x10C, 1, INDEFINITE_TIMEOUT);
677 		_dialog2.start();
678 		break;
679 
680 	default:
681 		break;
682 	}
683 }
684 
handlePrisonerDialog()685 void Scene307::handlePrisonerDialog() {
686 	switch (_action._activeAction._verbId) {
687 	case 0x11A:
688 		setDialogNode(7);
689 		break;
690 
691 	case 0x11B:
692 		setDialogNode(8);
693 		break;
694 
695 	case 0x11C:
696 		setDialogNode(12);
697 		break;
698 
699 	case 0x11D:
700 		setDialogNode(9);
701 		break;
702 
703 	case 0x11E:
704 		setDialogNode(10);
705 		break;
706 
707 	case 0x11F:
708 		setDialogNode(11);
709 		break;
710 
711 	case 0x120:
712 		setDialogNode(13);
713 		break;
714 
715 	case 0x121:
716 		setDialogNode(14);
717 		break;
718 
719 	case 0x122:
720 		setDialogNode(15);
721 		break;
722 
723 	default:
724 		break;
725 	}
726 }
727 
handleDialog()728 void Scene307::handleDialog() {
729 	if (_game._trigger == 0) {
730 		_scene->_kernelMessages.reset();
731 		_game._player._stepEnabled = false;
732 		handleRexDialog(_action._activeAction._verbId);
733 	} else {
734 		_game._player._stepEnabled = true;
735 
736 		if (!_globals[kKnowsBuddyBeast]) {
737 			handlePrisonerEncounter();
738 		} else {
739 			handlePrisonerDialog();
740 		}
741 	}
742 }
743 
enter()744 void Scene307::enter() {
745 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites("*SC003x0");
746 	_globals._spriteIndexes[0] = _scene->_sprites.addSprites("*SC003x1");
747 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites("*SC003x2");
748 	_globals._spriteIndexes[4] = _scene->_sprites.addSprites(formAnimName('x', 0));
749 
750 	initForceField(&_forceField, true);
751 
752 	_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 1);
753 	_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(127, 78));
754 	_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 15);
755 
756 	_animationMode = 0;
757 	_fieldCollisionCounter = 0;
758 
759 	_scene->changeVariant(1);
760 
761 	_game.loadQuoteSet(0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0x10C, 0x104, 0x106, 0x107, 0x108, 0x105,
762 		0x109, 0x10A, 0x10B, 0x10D, 0x10E, 0x10F, 0x110, 0x111, 0x112, 0x113, 0x114, 0x115, 0x116, 0x117,
763 		0x118, 0x119, 0x11A, 0x11B, 0x11C, 0x11D, 0x11E, 0x11F, 0x120, 0x121, 0x122, 0x123, 0x124, 0x125,
764 		0x126, 0x127, 0x128, 0x129, 0x12A, 0x12B, 0x12C, 0x12D, 0x12E, 0x12F, 0x130, 0x131, 0x132, 0x133,
765 		0x134, 0x135, 0x136, 0x137, 0x138, 0x139, 0x13A, 0x13B, 0x13C, 0x13D, 0x13E, 0x13F, 0x140, 0x141,
766 		0x142, 0x143, 0x144, 0x145, 0x146, 0x147, 0x148, 0x149, 0x14A, 0x14B, 0x14C, 0x14D, 0x14E, 0x14F,
767 		0x150, 0x151, 0x152, 0x153, 0);
768 
769 	_dialog1.setup(0x3F, 0x113, 0x114, 0x115, -1);
770 	_dialog2.setup(0x40, 0x11A, 0x11B, 0x11C, 0x11D, 0x11E, 0x11F, 0x120, 0x121, 0x122, 0);
771 
772 	if (!_game._visitedScenes._sceneRevisited)
773 		_dialog2.set(0x11A, 0x122, 0);
774 	else if (_scene->_priorSceneId == 318)
775 		_dialog2.write(0x11E, true);
776 
777 
778 	if (_scene->_priorSceneId == RETURNING_FROM_DIALOG) {
779 		if (_grateOpenedFl)
780 			_vm->_sound->command(10);
781 		else
782 			_vm->_sound->command(3);
783 	} else {
784 		_afterPeeingFl = false;
785 		_duringPeeingFl = false;
786 		_guardTime = 0;
787 		_grateOpenedFl = false;
788 		_activePrisonerFl = false;
789 		_prisonerTimer = 0;
790 		_prisonerMessageId = 0x104;
791 
792 		if (_scene->_priorSceneId == 308) {
793 			_game._player._visible = false;
794 			_game._player._stepEnabled = false;
795 			_game._player._playerPos = Common::Point(156, 113);
796 			_game._player._facing = FACING_NORTH;
797 			_animationMode = 1;
798 			_vm->_sound->command(11);
799 			_scene->loadAnimation(formAnimName('a', -1), 60);
800 		} else if (_scene->_priorSceneId == 387) {
801 			_game._player._playerPos = Common::Point(129, 108);
802 			_game._player._facing = FACING_NORTH;
803 			_vm->_sound->command(3);
804 			_grateOpenedFl = true;
805 		} else {
806 			_game._player._playerPos = Common::Point(159, 109);
807 			_game._player._facing = FACING_SOUTH;
808 			_vm->_sound->command(3);
809 		}
810 	}
811 
812 	if (_grateOpenedFl) {
813 		_scene->_hotspots.activate(17, false);
814 
815 		int idx = _scene->_dynamicHotspots.add(17, VERB_CLIMB_INTO, -1, Common::Rect(117, 67, 117 + 19, 67 + 13));
816 		int hotspotId = _scene->_dynamicHotspots.setPosition(idx, Common::Point(129, 104), FACING_NORTH);
817 		_scene->_dynamicHotspots.setCursor(hotspotId, CURSOR_GO_UP);
818 
819 		_scene->_sequences.remove(_globals._sequenceIndexes[4]);
820 		_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 2);
821 		_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(127, 78));
822 		_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 15);
823 	}
824 
825 	_vm->_palette->setEntry(252, 63, 30, 20);
826 	_vm->_palette->setEntry(253, 45, 15, 12);
827 
828 	sceneEntrySound();
829 
830 	if ((_scene->_priorSceneId == 318) || (_scene->_priorSceneId == 387))
831 		_scene->_kernelMessages.addQuote(0xF3, 0, 120);
832 }
833 
step()834 void Scene307::step() {
835 	handleForceField(&_forceField, &_globals._spriteIndexes[0]);
836 
837 	if ((_animationMode == 1) && (_scene->_animation[0] != nullptr)) {
838 		if (_scene->_animation[0]->getCurrentFrame() == 126) {
839 			_forceField._flag = false;
840 			_vm->_sound->command(5);
841 		}
842 
843 		if (_scene->_animation[0]->getCurrentFrame() == 194) {
844 			_forceField._flag = true;
845 			_vm->_sound->command(24);
846 		}
847 	}
848 
849 	if ((_animationMode == 2) && (_scene->_animation[0] != nullptr)) {
850 		if (_scene->_animation[0]->getCurrentFrame() == 54)
851 			_forceField._flag = false;
852 
853 		if (_scene->_animation[0]->getCurrentFrame() == 150) {
854 			_game._player._visible = false;
855 			_game._player._priorTimer = _scene->_frameStartTime - _game._player._ticksAmount;
856 		}
857 	}
858 
859 	if (_game._trigger == 60) {
860 		_game._player._visible = true;
861 		_game._player._stepEnabled = true;
862 		_game._player._priorTimer = _scene->_frameStartTime - _game._player._ticksAmount;
863 		_animationMode = 0;
864 		_vm->_sound->command(9);
865 	}
866 
867 	if ((_lastFrameTime != _scene->_frameStartTime) && !_duringPeeingFl) {
868 		int32 elapsedTime = _lastFrameTime - _scene->_frameStartTime;
869 		if ((elapsedTime > 0) && (elapsedTime <= 4)) {
870 			_guardTime += elapsedTime;
871 			_prisonerTimer += elapsedTime;
872 		} else {
873 			_guardTime++;
874 			_prisonerTimer++;
875 		}
876 		_lastFrameTime = _scene->_frameStartTime;
877 
878 		if ((_guardTime > 3000) && !_duringPeeingFl && (_scene->_animation[0] == nullptr)
879 		&& (_game._screenObjects._inputMode != kInputConversation) && _globals[kMetBuddyBeast] && !_activePrisonerFl) {
880 			if (!_game._objects.isInInventory(OBJ_SCALPEL) && !_grateOpenedFl) {
881 				_game._player._stepEnabled = false;
882 				_game._player.walk(Common::Point(151, 119), FACING_SOUTHEAST);
883 				_animationMode = 2;
884 				_vm->_sound->command(11);
885 				_scene->loadAnimation(formAnimName('b', -1), 70);
886 			}
887 			_guardTime = 0;
888 		} else if ((_prisonerTimer > 300) && (_game._screenObjects._inputMode != kInputConversation) && (_scene->_animation[0] == nullptr) && !_activePrisonerFl) {
889 			if (!_globals[kMetBuddyBeast]) {
890 				if (_prisonerMessageId == -1)
891 					_prisonerMessageId = 0x104;
892 
893 				int idx = _scene->_kernelMessages.add(Common::Point(5, 51), 0xFDFC, 0, 81, 120, _game.getQuote(_prisonerMessageId));
894 				_scene->_kernelMessages.setQuoted(idx, 4, true);
895 				_prisonerMessageId++;
896 				if (_prisonerMessageId > 0x10A)
897 					_prisonerMessageId = 0x104;
898 			} else if (_globals[kKnowsBuddyBeast] && (_dialog2.read(0) > 1) && (_vm->getRandomNumber(1, 3) == 1)) {
899 				int idx = _scene->_kernelMessages.add(Common::Point(5, 51), 0xFDFC, 0, 81, 120, _game.getQuote(267));
900 				_scene->_kernelMessages.setQuoted(idx, 4, true);
901 			}
902 			_prisonerTimer = 0;
903 		}
904 	}
905 
906 	if (_game._trigger == 70)
907 		_scene->_nextSceneId = 318;
908 
909 	if (_game._trigger == 81) {
910 		_prisonerTimer = 0;
911 		if (_activePrisonerFl && (_guardTime > 2600))
912 			_guardTime = 3000 - _vm->getRandomNumber(1, 800);
913 
914 		_activePrisonerFl = false;
915 	}
916 }
917 
actions()918 void Scene307::actions() {
919 	if (_action._lookFlag)
920 		_vm->_dialogs->show(30715);
921 	else if (_game._screenObjects._inputMode == kInputConversation)
922 		handleDialog();
923 	else if (_action.isAction(VERB_TALKTO, NOUN_CELL_WALL) || _action.isAction(VERB_TALKTO, NOUN_WALL) || _action.isAction(VERB_TALKTO, NOUN_TOILET)) {
924 		int node, say;
925 		if (_globals[kKnowsBuddyBeast]) {
926 			say = 0x10E;
927 			node = 16;
928 		} else if (_globals[kMetBuddyBeast]) {
929 			say = 0x10E;
930 			node = 2;
931 		} else {
932 			say = 0x10D;
933 			node = 1;
934 		}
935 
936 		switch (_game._trigger) {
937 		case 0:
938 			handleRexDialog(say);
939 			break;
940 
941 		case 1:
942 			setDialogNode(node);
943 			break;
944 
945 		default:
946 			break;
947 		}
948 	} else if (_action.isAction(VERB_PRY, NOUN_SCALPEL, NOUN_AIR_VENT)) {
949 		switch (_game._trigger) {
950 		case 0:
951 			_game._player._stepEnabled = false;
952 			_scene->_kernelMessages.reset();
953 			_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 0, 120, _game.getQuote(239));
954 			_scene->_sequences.addTimer(120, 1);
955 			break;
956 
957 		case 1:
958 			_globals._spriteIndexes[5] = _scene->_sprites.addSprites("*RXCL_8");
959 			_game._player._visible = false;
960 			_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 12, 1, 0, 0);
961 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], -1, 3);
962 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
963 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
964 			break;
965 
966 		case 2: {
967 			int oldIdx = _globals._sequenceIndexes[5];
968 			_globals._sequenceIndexes[5] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[5], false, 12, 6, 0, 0);
969 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
970 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], 2, 3);
971 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[5], oldIdx);
972 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
973 			}
974 			break;
975 
976 		case 3: {
977 			int oldIdx = _globals._sequenceIndexes[5];
978 			_globals._sequenceIndexes[5] = _scene->_sequences.startCycle(_globals._spriteIndexes[5], false, 1);
979 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
980 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[5], oldIdx);
981 			_scene->_sequences.addTimer(48, 4);
982 			}
983 			break;
984 
985 		case 4:
986 			_vm->_sound->command(26);
987 			_scene->_sequences.remove(_globals._sequenceIndexes[4]);
988 			_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 2);
989 			_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(127, 78));
990 			_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 15);
991 			_scene->_sequences.addTimer(90, 5);
992 			break;
993 
994 		case 5:
995 			_vm->_sound->command(10);
996 			_scene->_kernelMessages.reset();
997 			_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 0, 120, _game.getQuote(241));
998 			_scene->_sequences.addTimer(120, 6);
999 			break;
1000 
1001 		case 6: {
1002 			_game._player._visible = true;
1003 			_game._player._priorTimer = _scene->_frameStartTime - _game._player._ticksAmount;
1004 			_scene->_sequences.remove(_globals._sequenceIndexes[5]);
1005 			_grateOpenedFl = true;
1006 			_scene->_hotspots.activate(17, false);
1007 			int idx = _scene->_dynamicHotspots.add(17, VERB_CLIMB_INTO, -1, Common::Rect(117, 67, 117 + 19, 67 + 13));
1008 			int hotspotId = _scene->_dynamicHotspots.setPosition(idx, Common::Point(129, 104), FACING_NORTH);
1009 			_scene->_dynamicHotspots.setCursor(hotspotId, CURSOR_GO_UP);
1010 			_game._objects.removeFromInventory(OBJ_SCALPEL, NOWHERE);
1011 			_scene->_kernelMessages.addQuote(0xF2, 7, 120);
1012 			}
1013 			break;
1014 
1015 		case 7:
1016 			_scene->_sprites.remove(_globals._spriteIndexes[5]);
1017 			_game._player._stepEnabled = true;
1018 			break;
1019 
1020 		default:
1021 			break;
1022 		}
1023 	}else if (_action.isAction(VERB_CLIMB_INTO, NOUN_AIR_VENT)) {
1024 		if (_grateOpenedFl) {
1025 			switch (_game._trigger) {
1026 			case 0:
1027 				_globals._spriteIndexes[5] = _scene->_sprites.addSprites("*RXCL_8");
1028 				_game._player._stepEnabled = false;
1029 				_game._player._visible = false;
1030 				_scene->_sequences.remove(_globals._sequenceIndexes[4]);
1031 				_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 60, 1, 0, 0);
1032 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], 3, -2);
1033 				_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(127, 78));
1034 				_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 15);
1035 				_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 18, 1, 0, 0);
1036 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], -1, 4);
1037 				_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
1038 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 1);
1039 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
1040 				break;
1041 
1042 			case 1:
1043 				_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, -2);
1044 				_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(127, 78));
1045 				_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 15);
1046 				break;
1047 
1048 			case 2: {
1049 				int oldIdx = _globals._sequenceIndexes[5];
1050 				_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 12, 1, 0, 0);
1051 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], 4, 10);
1052 				_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
1053 				_scene->_sequences.updateTimeout(_globals._sequenceIndexes[5], oldIdx);
1054 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
1055 				}
1056 				break;
1057 
1058 			case 3:
1059 				_scene->_sequences.remove(_globals._sequenceIndexes[4]);
1060 				_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 3);
1061 				_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(127, 78));
1062 				_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 1);
1063 				_globals._sequenceIndexes[5] = _scene->_sequences.startCycle(_globals._spriteIndexes[5], false, 11);
1064 				_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
1065 				_scene->_sequences.setPosition(_globals._sequenceIndexes[5], Common::Point(129, 102));
1066 				_scene->_sequences.addTimer(48, 4);
1067 				break;
1068 
1069 			case 4:
1070 				_scene->_sequences.remove(_globals._sequenceIndexes[4]);
1071 				_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 2);
1072 				_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(127, 78));
1073 				_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 1);
1074 				_scene->_sequences.remove(_globals._sequenceIndexes[5]);
1075 				_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 12, 1, 0, 0);
1076 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], 12, 14);
1077 				_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
1078 				_scene->_sequences.setPosition(_globals._sequenceIndexes[5], Common::Point(129, 102));
1079 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 5);
1080 				break;
1081 
1082 			case 5:
1083 				_globals._sequenceIndexes[5] = _scene->_sequences.startCycle(_globals._spriteIndexes[5], false, 15);
1084 				_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
1085 				_scene->_sequences.setPosition(_globals._sequenceIndexes[5], Common::Point(129, 102));
1086 				_scene->_sequences.addTimer(48, 6);
1087 				break;
1088 
1089 			case 6:
1090 				_scene->_sequences.remove(_globals._sequenceIndexes[5]);
1091 				_scene->_sequences.remove(_globals._sequenceIndexes[4]);
1092 				_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 1);
1093 				_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(127, 78));
1094 				_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 1);
1095 				_scene->_sequences.addTimer(48, 7);
1096 				break;
1097 
1098 			case 7:
1099 				_scene->_nextSceneId = 313;
1100 				break;
1101 
1102 			default:
1103 				break;
1104 			}
1105 		}
1106 	} else if (_action.isAction(VERB_USE, NOUN_TOILET) && (_game._storyMode != STORYMODE_NAUGHTY))
1107 		_vm->_dialogs->show(30723);
1108 	else if (_action.isAction(VERB_USE, NOUN_TOILET)) {
1109 		if (!_afterPeeingFl) {
1110 			switch (_game._trigger) {
1111 			case 0:
1112 				_vm->_sound->command(25);
1113 				_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('a', 0));
1114 				_duringPeeingFl = true;
1115 				_game._player._stepEnabled = false;
1116 				_game._player._visible = false;
1117 				_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 9, 1, 0, 0);
1118 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], -1, 2);
1119 				_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 9);
1120 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 1);
1121 				break;
1122 
1123 			case 1:
1124 				_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 9, 5, 0, 0);
1125 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 3, -2);
1126 				_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 9);
1127 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
1128 				break;
1129 
1130 			case 2:
1131 				_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[3]);
1132 				_game._player._visible = true;
1133 				_scene->_sequences.addTimer(48, 3);
1134 				break;
1135 
1136 			case 3: {
1137 				_scene->_sprites.remove(_globals._spriteIndexes[3]);
1138 				_scene->_kernelMessages.reset();
1139 				int idx = _scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 4, 120, _game.getQuote(237));
1140 				_scene->_kernelMessages.setQuoted(idx, 4, true);
1141 				}
1142 				break;
1143 
1144 			case 4:
1145 				_game._player._stepEnabled = true;
1146 				_duringPeeingFl = false;
1147 				_afterPeeingFl = true;
1148 				break;
1149 
1150 			default:
1151 				break;
1152 			}
1153 		} else {
1154 			_scene->_kernelMessages.reset();
1155 			int idx = _scene->_kernelMessages.add(Common::Point(85, 39), 0x1110, 0, 0, 180, _game.getQuote(238));
1156 			_scene->_kernelMessages.setQuoted(idx, 4, true);
1157 		}
1158 	} else if (_action.isAction(VERB_LOOK, NOUN_AIR_VENT)) {
1159 		if (!_grateOpenedFl)
1160 			_vm->_dialogs->show(30710);
1161 		else
1162 			_vm->_dialogs->show(30711);
1163 	} else if (_action.isAction(VERB_LOOK, NOUN_BED))
1164 		_vm->_dialogs->show(30712);
1165 	else if (_action.isAction(VERB_LOOK, NOUN_SINK))
1166 		_vm->_dialogs->show(30713);
1167 	else if (_action.isAction(VERB_LOOK, NOUN_TOILET))
1168 		_vm->_dialogs->show(30714);
1169 	else if (_action.isAction(VERB_SHARPEN, NOUN_SCALPEL))
1170 		_vm->_dialogs->show(30716);
1171 	else if (_action.isAction(VERB_LOOK, NOUN_CELL_WALL))
1172 		_vm->_dialogs->show(30717);
1173 	else if (_action.isAction(VERB_LOOK, NOUN_LIGHT))
1174 		_vm->_dialogs->show(30718);
1175 	else if (_action.isAction(VERB_WALK_INTO, NOUN_CORRIDOR)) {
1176 		switch (_fieldCollisionCounter) {
1177 		case 0:
1178 			_vm->_dialogs->show(30719);
1179 			_fieldCollisionCounter = 1;
1180 			break;
1181 
1182 		case 1:
1183 			_vm->_dialogs->show(30720);
1184 			_fieldCollisionCounter = 2;
1185 			break;
1186 
1187 		case 2:
1188 			_vm->_dialogs->show(30721);
1189 			_fieldCollisionCounter = 3;
1190 			break;
1191 
1192 		case 3:
1193 			_vm->_dialogs->show(30722);
1194 			break;
1195 
1196 		default:
1197 			break;
1198 		}
1199 	} else
1200 		return;
1201 
1202 	_action._inProgress = false;
1203 }
1204 
1205 /*------------------------------------------------------------------------*/
1206 
Scene308(MADSEngine * vm)1207 Scene308::Scene308(MADSEngine *vm) : Scene3xx(vm) {
1208 	_forceField.init();
1209 }
1210 
synchronize(Common::Serializer & s)1211 void Scene308::synchronize(Common::Serializer &s) {
1212 	Scene3xx::synchronize(s);
1213 
1214 	_forceField.synchronize(s);
1215 }
1216 
1217 
setup()1218 void Scene308::setup() {
1219 	setPlayerSpritesPrefix();
1220 	setAAName();
1221 }
1222 
enter()1223 void Scene308::enter() {
1224 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites("*SC003x0");
1225 	_globals._spriteIndexes[0] = _scene->_sprites.addSprites("*SC003x1");
1226 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites("*SC003x2");
1227 
1228 	initForceField(&_forceField, true);
1229 
1230 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('b', 0));
1231 	_globals._spriteIndexes[4] = _scene->_sprites.addSprites(Resources::formatName(307, 'X', 0, EXT_SS, ""));
1232 
1233 	_vm->_palette->setEntry(252, 63, 30, 20);
1234 	_vm->_palette->setEntry(253, 45, 15, 12);
1235 
1236 	_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 1);
1237 	_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(127, 78));
1238 	_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 15);
1239 	_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 1);
1240 	_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 9);
1241 	_scene->_sequences.addTimer(48, 70);
1242 
1243 	_game._player._visible = false;
1244 	_game._player._stepEnabled = false;
1245 	_scene->loadAnimation(formAnimName('a', -1), 60);
1246 
1247 	sceneEntrySound();
1248 	_game.loadQuoteSet(0xF4, 0xF5, 0xF6, 0);
1249 }
1250 
step()1251 void Scene308::step() {
1252 	handleForceField(&_forceField, &_globals._spriteIndexes[0]);
1253 
1254 	if (_game._trigger == 60)
1255 		_scene->_nextSceneId = 307;
1256 
1257 	if (_game._trigger < 70)
1258 		return;
1259 
1260 	switch (_game._trigger) {
1261 	case 70: {
1262 		_scene->_sequences.remove(_globals._sequenceIndexes[3]);
1263 		_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 18, 9, 0, 0);
1264 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 2, 3);
1265 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 9);
1266 		_scene->_kernelMessages.reset();
1267 		int idx = _scene->_kernelMessages.add(Common::Point(171, 21), 0xFDFC, 0, 0, 120, _game.getQuote(244));
1268 		_scene->_kernelMessages.setQuoted(idx, 2, true);
1269 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 71);
1270 		}
1271 		break;
1272 
1273 	case 71: {
1274 		int seqIdx = _globals._sequenceIndexes[3];
1275 		_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 4);
1276 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 9);
1277 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], seqIdx);
1278 		_scene->_sequences.addTimer(48, 72);
1279 		}
1280 		break;
1281 
1282 	case 72:
1283 		_scene->_sequences.remove(_globals._sequenceIndexes[3]);
1284 		_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 20, 5, 0, 0);
1285 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 3, 4);
1286 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 9);
1287 		_scene->_kernelMessages.reset();
1288 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 73);
1289 		break;
1290 
1291 	case 73: {
1292 		int seqIdx = _globals._sequenceIndexes[3];
1293 		_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 5);
1294 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 9);
1295 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], seqIdx);
1296 		_scene->_sequences.addTimer(48, 74);
1297 		}
1298 		break;
1299 
1300 	case 74: {
1301 		_scene->_sequences.remove(_globals._sequenceIndexes[3]);
1302 		_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 20, 8, 0, 0);
1303 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 6, 7);
1304 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 9);
1305 		_scene->_kernelMessages.reset();
1306 		int idx = _scene->_kernelMessages.add(Common::Point(171, 21), 0xFDFC, 0, 0, 120, _game.getQuote(245));
1307 		_scene->_kernelMessages.setQuoted(idx, 2, true);
1308 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 75);
1309 		}
1310 		break;
1311 
1312 	case 75: {
1313 		int seqIdx = _globals._sequenceIndexes[3];
1314 		_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 23, 5, 0, 0);
1315 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 8, 10);
1316 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 9);
1317 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], seqIdx);
1318 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 76);
1319 		}
1320 		break;
1321 
1322 	case 76: {
1323 		int seqIdx = _globals._sequenceIndexes[3];
1324 		_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 26, 0, 0, 0);
1325 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 2, 3);
1326 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 9);
1327 		_scene->_kernelMessages.reset();
1328 		int idx = _scene->_kernelMessages.add(Common::Point(171, 21), 0xFDFC, 0, 0, 120, _game.getQuote(246));
1329 		_scene->_kernelMessages.setQuoted(idx, 2, true);
1330 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], seqIdx);
1331 		}
1332 		break;
1333 
1334 	default:
1335 		break;
1336 	}
1337 }
1338 
1339 /*------------------------------------------------------------------------*/
1340 
Scene309(MADSEngine * vm)1341 Scene309::Scene309(MADSEngine *vm) : Scene3xx(vm) {
1342 	for (int i = 0; i < 3; i++) {
1343 		_characterSpriteIndexes[i] = -1;
1344 		_messagesIndexes[i] = -1;
1345 	}
1346 
1347 	_lastFrame = -1;
1348 	_forceField.init();
1349 }
1350 
synchronize(Common::Serializer & s)1351 void Scene309::synchronize(Common::Serializer &s) {
1352 	Scene3xx::synchronize(s);
1353 
1354 	_forceField.synchronize(s);
1355 
1356 	for (int i = 0; i < 3; ++i)
1357 		s.syncAsSint32LE(_characterSpriteIndexes[i]);
1358 	for (int i = 0; i < 3; ++i)
1359 		s.syncAsSint32LE(_messagesIndexes[i]);
1360 	s.syncAsSint32LE(_lastFrame);
1361 }
1362 
setup()1363 void Scene309::setup() {
1364 	setPlayerSpritesPrefix();
1365 	setAAName();
1366 }
1367 
enter()1368 void Scene309::enter() {
1369 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites("*SC003x0");
1370 	_globals._spriteIndexes[0] = _scene->_sprites.addSprites("*SC003x1");
1371 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites("*SC003x2");
1372 
1373 	initForceField(&_forceField, true);
1374 
1375 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('x', 0));
1376 	_globals._spriteIndexes[4] = _scene->_sprites.addSprites(Resources::formatName(307, 'X', 0, EXT_SS, ""));
1377 
1378 	_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 1);
1379 	_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(127, 78));
1380 	_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 15);
1381 
1382 	_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 7, 1, 0, 0);
1383 	_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], -1, 3);
1384 	_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 11);
1385 	_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_SPRITE, 3, 70);
1386 
1387 	_vm->_palette->setEntry(252, 63, 37, 26);
1388 	_vm->_palette->setEntry(253, 45, 24, 17);
1389 	_vm->_palette->setEntry(16, 63, 63, 63);
1390 	_vm->_palette->setEntry(17, 45, 45, 45);
1391 	_vm->_palette->setEntry(250, 63, 20, 20);
1392 	_vm->_palette->setEntry(251, 45, 10, 10);
1393 
1394 	_game._player._visible = false;
1395 	_game._player._stepEnabled = false;
1396 	_scene->loadAnimation(formAnimName('a', -1), 60);
1397 
1398 	_characterSpriteIndexes[0] = _scene->_animation[0]->_spriteListIndexes[2];
1399 	_characterSpriteIndexes[1] = _scene->_animation[0]->_spriteListIndexes[2];
1400 	_characterSpriteIndexes[2] = _scene->_animation[0]->_spriteListIndexes[1];
1401 
1402 	_messagesIndexes[0] = -1;
1403 	_messagesIndexes[1] = -1;
1404 	_messagesIndexes[2] = -1;
1405 
1406 	sceneEntrySound();
1407 
1408 	_game.loadQuoteSet(0xF7, 0xF8, 0xF9, 0x15C, 0x15D, 0x15E, 0);
1409 }
1410 
step()1411 void Scene309::step() {
1412 	handleForceField(&_forceField, &_globals._spriteIndexes[0]);
1413 
1414 	if (_game._trigger == 61) {
1415 		_messagesIndexes[0] = -1;
1416 		_messagesIndexes[1] = -1;
1417 	}
1418 
1419 	if (_game._trigger == 62)
1420 		_messagesIndexes[2] = -1;
1421 
1422 	if (_scene->_animation[0] != nullptr) {
1423 		if (_lastFrame != _scene->_animation[0]->getCurrentFrame()) {
1424 			_lastFrame = _scene->_animation[0]->getCurrentFrame();
1425 			if (_lastFrame == 39) {
1426 				_messagesIndexes[0] = _scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 32, 61, 210, _game.getQuote(348));
1427 				_messagesIndexes[1] = _scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 32, 0, 210, _game.getQuote(349));
1428 			}
1429 
1430 			if (_lastFrame == 97)
1431 				_messagesIndexes[2] = _scene->_kernelMessages.add(Common::Point(0, 0), 0xFBFA, 32, 62, 180, _game.getQuote(350));
1432 
1433 			for (int charIdx = 0; charIdx < 3; charIdx++) {
1434 				if (_messagesIndexes[charIdx] >= 0) {
1435 					bool match = false;
1436 					int j = -1;
1437 					for (j = _scene->_animation[0]->_oldFrameEntry; j < _scene->_animation[0]->_header._frameEntriesCount; j++) {
1438 						if (_scene->_animation[0]->_frameEntries[j]._spriteSlot._spritesIndex == _characterSpriteIndexes[charIdx]) {
1439 							match = true;
1440 							break;
1441 						}
1442 					}
1443 
1444 					if (match) {
1445 						SpriteSlotSubset *curSpriteSlot = &_scene->_animation[0]->_frameEntries[j]._spriteSlot;
1446 						_scene->_kernelMessages._entries[_messagesIndexes[charIdx]]._position.x = curSpriteSlot->_position.x;
1447 						_scene->_kernelMessages._entries[_messagesIndexes[charIdx]]._position.y = curSpriteSlot->_position.y - (50 + (14 * ((charIdx == 0) ? 2 : 1)));
1448 					}
1449 				}
1450 			}
1451 		}
1452 	}
1453 
1454 	if (_game._trigger >= 70) {
1455 		switch (_game._trigger) {
1456 		case 70: {
1457 			int idx = _scene->_dynamicHotspots.add(689, 690, _globals._sequenceIndexes[3], Common::Rect(0, 0, 0, 0));
1458 			_scene->_dynamicHotspots.setPosition(idx, Common::Point(142, 146), FACING_NORTHEAST);
1459 			_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 7, 4, 0, 0);
1460 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 2, 3);
1461 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 11);
1462 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 71);
1463 			}
1464 			break;
1465 
1466 		case 71: {
1467 			int _oldIdx = _globals._sequenceIndexes[3];
1468 			_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 7, 1, 0, 0);
1469 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 4, 7);
1470 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 11);
1471 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], _oldIdx);
1472 			int idx = _scene->_kernelMessages.add(Common::Point(85, 37), 0xFDFC, 0, 0, 120, _game.getQuote(248));
1473 			_scene->_kernelMessages.setQuoted(idx, 2, true);
1474 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 72);
1475 			}
1476 			break;
1477 
1478 		case 72: {
1479 			int _oldIdx = _globals._sequenceIndexes[3];
1480 			_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 7, 8, 0, 0);
1481 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 8, 11);
1482 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 11);
1483 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], _oldIdx);
1484 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 73);
1485 			}
1486 			break;
1487 
1488 		case 73: {
1489 			int _oldIdx = _globals._sequenceIndexes[3];
1490 			_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 7, 1, 0, 0);
1491 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 12, 20);
1492 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 11);
1493 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], _oldIdx);
1494 			int idx = _scene->_kernelMessages.add(Common::Point(170, 49), 0xFDFC, 0, 0, 120, _game.getQuote(249));
1495 			_scene->_kernelMessages.setQuoted(idx, 2, true);
1496 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 74);
1497 			}
1498 			break;
1499 
1500 		case 74: {
1501 			int _oldIdx = _globals._sequenceIndexes[3];
1502 			_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 7, 6, 0, 0);
1503 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 21, 23);
1504 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 11);
1505 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], _oldIdx);
1506 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 75);
1507 			}
1508 			break;
1509 
1510 		case 75: {
1511 			int _oldIdx = _globals._sequenceIndexes[3];
1512 			_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 12, 6, 0, 0);
1513 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 24, 25);
1514 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], _oldIdx);
1515 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 11);
1516 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 76);
1517 			}
1518 			break;
1519 
1520 		case 76: {
1521 			int _oldIdx = _globals._sequenceIndexes[3];
1522 			_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 12, 1, 0, 0);
1523 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 26, 28);
1524 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], _oldIdx);
1525 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 11);
1526 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 77);
1527 			}
1528 			break;
1529 
1530 		case 77: {
1531 			_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 90, 0, 0, 0);
1532 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 29, 30);
1533 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 11);
1534 			int idx = _scene->_kernelMessages.add(Common::Point(15, 46), 0xFDFC, 0, 0, 120, _game.getQuote(247));
1535 			_scene->_kernelMessages.setQuoted(idx, 2, true);
1536 			_scene->_sequences.addTimer(120, 78);
1537 			}
1538 			break;
1539 
1540 		default:
1541 			break;
1542 		}
1543 	}
1544 
1545 	if (_game._trigger == 60)
1546 		_scene->_nextSceneId = 308;
1547 }
1548 
1549 /*------------------------------------------------------------------------*/
1550 
Scene310(MADSEngine * vm)1551 Scene310::Scene310(MADSEngine *vm) : Scene3xx(vm) {
1552 	_forceField.init();
1553 }
1554 
synchronize(Common::Serializer & s)1555 void Scene310::synchronize(Common::Serializer &s) {
1556 	Scene3xx::synchronize(s);
1557 
1558 	_forceField.synchronize(s);
1559 }
1560 
setup()1561 void Scene310::setup() {
1562 	setPlayerSpritesPrefix();
1563 	setAAName();
1564 }
1565 
enter()1566 void Scene310::enter() {
1567 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites("*SC003x0");
1568 	_globals._spriteIndexes[0] = _scene->_sprites.addSprites("*SC003x1");
1569 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites("*SC003x2");
1570 
1571 	initForceField(&_forceField, true);
1572 
1573 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(Resources::formatName(307, 'X', 0, EXT_SS, ""));
1574 	_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 1);
1575 	_scene->_sequences.setPosition(_globals._sequenceIndexes[3], Common::Point(127, 78));
1576 	_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 15);
1577 
1578 	_game._player._visible = false;
1579 	_game._player._stepEnabled = false;
1580 	_scene->loadAnimation(formAnimName('a', -1), 70);
1581 
1582 	sceneEntrySound();
1583 }
1584 
step()1585 void Scene310::step() {
1586 	handleForceField(&_forceField, &_globals._spriteIndexes[0]);
1587 
1588 	if (_game._trigger == 70)
1589 		_scene->_nextSceneId = 309;
1590 }
1591 
1592 /*------------------------------------------------------------------------*/
1593 
Scene311(MADSEngine * vm)1594 Scene311::Scene311(MADSEngine *vm) : Scene3xx(vm) {
1595 	_checkGuardFl = false;
1596 }
1597 
synchronize(Common::Serializer & s)1598 void Scene311::synchronize(Common::Serializer &s) {
1599 	Scene3xx::synchronize(s);
1600 
1601 	s.syncAsByte(_checkGuardFl);
1602 }
1603 
setup()1604 void Scene311::setup() {
1605 	if (_scene->_currentSceneId == 391)
1606 		_globals[kSexOfRex] = REX_MALE;
1607 
1608 	setPlayerSpritesPrefix();
1609 	setAAName();
1610 
1611 	if (_scene->_currentSceneId == 304)
1612 		_game._player._spritesPrefix = "";
1613 }
1614 
enter()1615 void Scene311::enter() {
1616 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(Resources::formatName(307, 'X', 0, EXT_SS, ""));
1617 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites("*RXCL_8");
1618 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites("*RXCL_2");
1619 
1620 	_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
1621 	_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
1622 	_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
1623 
1624 	_checkGuardFl = false;
1625 	_game.loadQuoteSet(0xFA, 0);
1626 
1627 	if (_scene->_priorSceneId == 391) {
1628 		_globals[kSexOfRex] = REX_MALE;
1629 		_game._player._stepEnabled = false;
1630 		_game._player._visible = false;
1631 		_game._player._facing = FACING_SOUTH;
1632 		_game._player._playerPos = Common::Point(166, 101);
1633 		_scene->_sequences.addTimer(120, 71);
1634 	} else if (_scene->_priorSceneId == 310)
1635 		_game._player._playerPos = Common::Point(302, 145);
1636 	else if (_scene->_priorSceneId == 320) {
1637 		_game._player._playerPos = Common::Point(129, 113);
1638 		_game._player._facing = FACING_SOUTH;
1639 	} else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG) {
1640 		_game._player._visible = false;
1641 		_game._player._stepEnabled = false;
1642 		_scene->loadAnimation(formAnimName('a', -1), 70);
1643 	}
1644 
1645 	sceneEntrySound();
1646 }
1647 
step()1648 void Scene311::step() {
1649 	if (_game._trigger == 70)
1650 		_scene->_nextSceneId = 310;
1651 
1652 	if (_game._trigger >= 71) {
1653 		switch (_game._trigger) {
1654 		case 71:
1655 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
1656 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 2);
1657 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
1658 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
1659 
1660 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 1);
1661 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
1662 			_scene->_sequences.addTimer(15, 72);
1663 			break;
1664 
1665 		case 72:
1666 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
1667 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 2);
1668 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
1669 			_scene->_sequences.addTimer(15, 73);
1670 			break;
1671 
1672 		case 73:
1673 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
1674 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 3);
1675 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
1676 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
1677 
1678 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
1679 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 3);
1680 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
1681 			_scene->_sequences.addTimer(15, 74);
1682 			break;
1683 
1684 		case 74:
1685 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
1686 			_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 12, 1, 0, 0);
1687 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 4, 5);
1688 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
1689 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 75);
1690 			break;
1691 
1692 		case 75: {
1693 			int oldIdx = _globals._sequenceIndexes[3];
1694 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 6);
1695 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
1696 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], oldIdx);
1697 			_scene->_sequences.addTimer(15, 76);
1698 			}
1699 			break;
1700 
1701 		case 76:
1702 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
1703 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 7);
1704 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
1705 			_scene->_sequences.addTimer(15, 77);
1706 			break;
1707 
1708 		case 77:
1709 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
1710 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 2);
1711 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
1712 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
1713 
1714 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
1715 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 8);
1716 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
1717 			_scene->_sequences.addTimer(15, 78);
1718 			break;
1719 
1720 		case 78:
1721 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
1722 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
1723 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
1724 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
1725 
1726 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
1727 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 9);
1728 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
1729 			_scene->_sequences.addTimer(15, 79);
1730 			break;
1731 
1732 		case 79:
1733 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
1734 			_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 12, 1, 0, 0);
1735 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 10, -2);
1736 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
1737 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 80);
1738 			break;
1739 
1740 		case 80:
1741 			_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[3]);
1742 			_game._player._stepEnabled = true;
1743 			_game._player._visible = true;
1744 			break;
1745 
1746 		default:
1747 			break;
1748 		}
1749 	}
1750 
1751 	if (_game._player._moving && (_scene->_rails.getNext() > 0)) {
1752 		int x = _game._player._prepareWalkPos.x;
1753 		if (x < 75)
1754 			x = 75;
1755 		if (x > 207)
1756 			x = 207;
1757 
1758 		_checkGuardFl = true;
1759 		_game._player.startWalking(Common::Point(x, 122), FACING_SOUTH);
1760 		_scene->_rails.resetNext();
1761 	}
1762 }
1763 
actions()1764 void Scene311::actions() {
1765 	if (_action._lookFlag)
1766 		_vm->_dialogs->show(31119);
1767 	else if (_checkGuardFl) {
1768 		_checkGuardFl = false;
1769 		_scene->_kernelMessages.reset();
1770 		_scene->_kernelMessages.addQuote(250, 0, 240);
1771 	} else if (_action.isAction(VERB_SIT_AT, NOUN_DESK))
1772 		_scene->_nextSceneId = 320;
1773 	else if (_action.isAction(VERB_CLIMB_INTO, NOUN_AIR_VENT)) {
1774 		switch (_game._trigger) {
1775 		case 0:
1776 			_game._player._stepEnabled = false;
1777 			_game._player._visible = false;
1778 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
1779 			_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 50, 1, 0, 0);
1780 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], 3, -2);
1781 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
1782 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
1783 
1784 			_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 15, 1, 0, 0);
1785 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], -1, 4);
1786 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
1787 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[1], SEQUENCE_TRIGGER_EXPIRE, 0, 1);
1788 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
1789 			break;
1790 
1791 		case 1: {
1792 			int oldIdx = _globals._sequenceIndexes[1];
1793 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, -2);
1794 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
1795 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
1796 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[1], oldIdx);
1797 			}
1798 			break;
1799 
1800 		case 2: {
1801 			int oldIdx = _globals._sequenceIndexes[2];
1802 			_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 12, 1, 0, 0);
1803 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 4, 10);
1804 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
1805 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[2], oldIdx);
1806 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
1807 			}
1808 			break;
1809 
1810 		case 3: {
1811 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
1812 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 3);
1813 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
1814 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
1815 
1816 			int oldIdx = _globals._sequenceIndexes[2];
1817 			_globals._sequenceIndexes[2] = _scene->_sequences.startCycle(_globals._spriteIndexes[2], false, 11);
1818 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
1819 			_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(167, 100));
1820 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[2], oldIdx);
1821 			_scene->_sequences.addTimer(15, 4);
1822 			}
1823 			break;
1824 
1825 		case 4:
1826 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
1827 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 2);
1828 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
1829 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
1830 
1831 			_scene->_sequences.remove(_globals._sequenceIndexes[2]);
1832 			_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 12, 1, 0, 0);
1833 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 12, 14);
1834 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
1835 			_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(167, 100));
1836 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 5);
1837 			break;
1838 
1839 		case 5: {
1840 			int oldIdx = _globals._sequenceIndexes[2];
1841 			_globals._sequenceIndexes[2] = _scene->_sequences.startCycle(_globals._spriteIndexes[2], false, 15);
1842 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
1843 			_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(167, 100));
1844 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[2], oldIdx);
1845 			_scene->_sequences.addTimer(15, 6);
1846 			}
1847 			break;
1848 
1849 		case 6:
1850 			_scene->_sequences.remove(_globals._sequenceIndexes[2]);
1851 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
1852 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
1853 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
1854 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
1855 			_scene->_sequences.addTimer(15, 7);
1856 			break;
1857 
1858 		case 7:
1859 			_scene->_nextSceneId = 313;
1860 			break;
1861 
1862 		default:
1863 			break;
1864 		}
1865 	} else if (_action.isAction(VERB_LOOK, NOUN_DESK))
1866 		_vm->_dialogs->show(31110);
1867 	else if (_action.isAction(VERB_LOOK, NOUN_WALL))
1868 		_vm->_dialogs->show(31111);
1869 	else if (_action.isAction(VERB_LOOK, NOUN_LIGHTING_FIXTURE) || _action.isAction(VERB_STARE_AT, NOUN_LIGHTING_FIXTURE))
1870 		_vm->_dialogs->show(31112);
1871 	else if (_action.isAction(VERB_LOOK, NOUN_LIGHTS) || _action.isAction(VERB_STARE_AT, NOUN_LIGHTS))
1872 		_vm->_dialogs->show(31113);
1873 	else if (_action.isAction(VERB_TAKE, NOUN_LIGHTS))
1874 		_vm->_dialogs->show(31114);
1875 	else if (_action.isAction(VERB_LOOK, NOUN_LIGHT) || _action.isAction(VERB_STARE_AT, NOUN_LIGHT))
1876 		_vm->_dialogs->show(31115);
1877 	else if (_action.isAction(VERB_TAKE, NOUN_LIGHT))
1878 		_vm->_dialogs->show(31116);
1879 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_WEST))
1880 		_vm->_dialogs->show(31117);
1881 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_EAST))
1882 		_vm->_dialogs->show(31118);
1883 	else if (_action.isAction(VERB_LOOK, NOUN_AIR_VENT))
1884 		_vm->_dialogs->show(31120);
1885 	else
1886 		return;
1887 
1888 	_action._inProgress = false;
1889 }
1890 
1891 /*------------------------------------------------------------------------*/
1892 
setup()1893 void Scene313::setup() {
1894 	setPlayerSpritesPrefix();
1895 	_game._player._spritesPrefix = "RM313A";
1896 	setAAName();
1897 }
1898 
enter()1899 void Scene313::enter() {
1900 	_scene->_userInterface.setup(kInputLimitedSentences);
1901 
1902 	if ((_scene->_priorSceneId == 366) || (_scene->_priorSceneId == 316)) {
1903 		_game._player._playerPos = Common::Point(30, 80);
1904 		_game._player._facing = FACING_NORTH;
1905 	} else if ((_scene->_priorSceneId == 311) || (_scene->_priorSceneId == 361) || (_scene->_priorSceneId == 391)) {
1906 		_game._player._playerPos = Common::Point(90, 70);
1907 		_game._player._facing = FACING_EAST;
1908 	} else if (_scene->_priorSceneId == 390) {
1909 		_game._player._playerPos = Common::Point(126, 70);
1910 		_game._player._facing = FACING_EAST;
1911 	} else if ((_scene->_priorSceneId == 389) || (_scene->_priorSceneId == 399)) {
1912 		_game._player._playerPos = Common::Point(163, 70);
1913 		_game._player._facing = FACING_WEST;
1914 	} else if (_scene->_priorSceneId == 388) {
1915 		_game._player._playerPos = Common::Point(199, 70);
1916 		_game._player._facing = FACING_WEST;
1917 	} else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG) {
1918 		_game._player._playerPos = Common::Point(234, 70);
1919 		_game._player._facing = FACING_WEST;
1920 	}
1921 
1922 	if (_globals[kAfterHavoc]) {
1923 		for (uint16 i = 0; i < _scene->_paletteCycles.size(); i++) {
1924 			int palIdx = _scene->_paletteCycles[i]._firstColorIndex;
1925 			int size = _scene->_paletteCycles[i]._colorCount * 3;
1926 			memset(&_vm->_palette->_cyclingPalette[palIdx], 0, size);
1927 			memset(&_vm->_palette->_mainPalette[palIdx], 0, size);
1928 		}
1929 	}
1930 
1931 	sceneEntrySound();
1932 }
1933 
actions()1934 void Scene313::actions() {
1935 	if (_action.isAction(VERB_CRAWL_TO, NOUN_FOURTH_CELL))
1936 		_scene->_nextSceneId = 387;
1937 	else if (_action.isAction(VERB_CRAWL_TO, NOUN_THIRD_CELL))
1938 		_scene->_nextSceneId = 388;
1939 	else if (_action.isAction(VERB_CRAWL_TO, NOUN_SECOND_CELL)) {
1940 		if (_globals[kAfterHavoc])
1941 			_scene->_nextSceneId = 399;
1942 		else
1943 			_scene->_nextSceneId = 389;
1944 	} else if (_action.isAction(VERB_CRAWL_TO, NOUN_FIRST_CELL))
1945 		_scene->_nextSceneId = 390;
1946 	else if (_action.isAction(VERB_CRAWL_TO, NOUN_SECURITY_STATION)) {
1947 		if (_globals[kSexOfRex] == REX_FEMALE) {
1948 			_globals[kSexOfRex] = REX_MALE;
1949 			_vm->_dialogs->show(31301);
1950 		}
1951 		_scene->_nextSceneId = 391;
1952 	} else if (_action.isAction(VERB_CRAWL_TO, NOUN_EQUIPMENT_ROOM)) {
1953 		if (_globals[kSexOfRex] == REX_FEMALE) {
1954 			_globals[kSexOfRex] = REX_MALE;
1955 			_vm->_dialogs->show(31301);
1956 		}
1957 		_scene->_nextSceneId = 366;
1958 	} else if (!_action.isAction(VERB_CRAWL_DOWN, NOUN_AIR_SHAFT))
1959 		return;
1960 
1961 	_action._inProgress = false;
1962 }
1963 
1964 /*------------------------------------------------------------------------*/
1965 
setup()1966 void Scene316::setup() {
1967 	if (_scene->_currentSceneId == 366)
1968 		_globals[kSexOfRex] = REX_MALE;
1969 
1970 	setPlayerSpritesPrefix();
1971 	setAAName();
1972 }
1973 
handleRexInGrate()1974 void Scene316::handleRexInGrate() {
1975 	switch (_game._trigger) {
1976 	case 0:
1977 		_game._player._stepEnabled = false;
1978 		_game._player._visible = false;
1979 		_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 1);
1980 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
1981 		_scene->_sequences.addTimer(15, 1);
1982 		break;
1983 
1984 	case 1:
1985 		_scene->_sequences.setDone(_globals._sequenceIndexes[4]);
1986 		_globals._sequenceIndexes[4] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[4], false, 12, 3, 0, 0);
1987 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], 2, 3);
1988 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
1989 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
1990 		break;
1991 
1992 	case 2: {
1993 		int oldIdx = _globals._sequenceIndexes[4];
1994 		_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 12, 1, 0, 0);
1995 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], 4, 8);
1996 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
1997 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[4], oldIdx);
1998 
1999 		_scene->_sequences.remove(_globals._sequenceIndexes[3]);
2000 		_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 12, 1, 0, 0);
2001 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 2, -2);
2002 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 12);
2003 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
2004 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 4);
2005 		}
2006 		break;
2007 
2008 	case 3: {
2009 		int oldIdx = _globals._sequenceIndexes[3];
2010 		_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, -2);
2011 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 12);
2012 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], oldIdx);
2013 		}
2014 		break;
2015 
2016 	case 4: {
2017 		int oldIdx = _globals._sequenceIndexes[4];
2018 		_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 12, 1, 0, 0);
2019 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], 10, 11);
2020 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
2021 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[4], oldIdx);
2022 
2023 		_scene->_sequences.remove(_globals._sequenceIndexes[3]);
2024 		_globals._sequenceIndexes[3] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[3], false, 12, 1, 0, 0);
2025 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 5, -2);
2026 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2027 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 5);
2028 		}
2029 		break;
2030 
2031 	case 5: {
2032 		int oldIdx = _globals._sequenceIndexes[3];
2033 		_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 3);
2034 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2035 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], oldIdx);
2036 
2037 		oldIdx = _globals._sequenceIndexes[4];
2038 		_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 12);
2039 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
2040 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[4], oldIdx);
2041 		_scene->_sequences.addTimer(15, 6);
2042 		}
2043 		break;
2044 
2045 	case 6:
2046 		_scene->_sequences.setDone(_globals._sequenceIndexes[4]);
2047 		_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 12, 1, 0, 0);
2048 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], 13, 14);
2049 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
2050 
2051 		_scene->_sequences.remove(_globals._sequenceIndexes[3]);
2052 		_globals._sequenceIndexes[3] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[3], false, 12, 1, 0, 0);
2053 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 2, 3);
2054 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2055 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 7);
2056 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 8);
2057 		break;
2058 
2059 	case 7:
2060 		_scene->_sequences.setDone(_globals._sequenceIndexes[4]);
2061 		_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 15);
2062 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
2063 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[4], -1);
2064 		break;
2065 
2066 	case 8: {
2067 		int oldIdx = _globals._sequenceIndexes[3];
2068 		_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 2);
2069 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2070 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], oldIdx);
2071 		_scene->_sequences.addTimer(15, 9);
2072 		}
2073 		break;
2074 
2075 	case 9:
2076 		_scene->_sequences.setDone(_globals._sequenceIndexes[4]);
2077 		_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 1);
2078 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2079 		_scene->_sequences.addTimer(48, 10);
2080 		break;
2081 
2082 	case 10:
2083 		_scene->_nextSceneId = 313;
2084 		break;
2085 
2086 	default:
2087 		break;
2088 	}
2089 }
2090 
handleRoxInGrate()2091 void Scene316::handleRoxInGrate() {
2092 	int temp;
2093 	int temp1;
2094 
2095 	switch (_game._trigger) {
2096 	case 0:
2097 		_game._player._stepEnabled = false;
2098 		_game._player._visible = false;
2099 		_globals._sequenceIndexes[5] = _scene->_sequences.startCycle(_globals._spriteIndexes[5], false, 1);
2100 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
2101 		_scene->_sequences.addTimer(15, 1);
2102 		break;
2103 
2104 	case 1:
2105 		_scene->_sequences.setDone(_globals._sequenceIndexes[5]);
2106 		_globals._sequenceIndexes[5] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[5], false, 17, 3, 0, 0);
2107 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], 2, 3);
2108 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
2109 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
2110 		break;
2111 
2112 	case 2:
2113 		_scene->_sequences.remove(_globals._sequenceIndexes[3]);
2114 		_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 17, 1, 0, 0);
2115 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 2, -2);
2116 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 12);
2117 
2118 		temp = _globals._sequenceIndexes[5];
2119 		_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 17, 1, 0, 0);
2120 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], 4, 8);
2121 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
2122 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[5], temp);
2123 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
2124 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 4);
2125 		break;
2126 
2127 	case 3:
2128 		temp1 = _globals._sequenceIndexes[3];
2129 		_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, -2);
2130 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 12);
2131 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], temp1);
2132 		break;
2133 
2134 	case 4:
2135 		temp = _globals._sequenceIndexes[5];
2136 		_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 17, 1, 0, 0);
2137 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], 10, 11);
2138 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
2139 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[5], temp);
2140 
2141 		_scene->_sequences.remove(_globals._sequenceIndexes[3]);
2142 		_globals._sequenceIndexes[3] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[3], false, 17, 1, 0, 0);
2143 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 5, -2);
2144 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2145 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 5);
2146 		break;
2147 
2148 	case 5:
2149 		temp = _globals._sequenceIndexes[3];
2150 		_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 3);
2151 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2152 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], temp);
2153 
2154 		temp = _globals._sequenceIndexes[5];
2155 		_globals._sequenceIndexes[5] = _scene->_sequences.startCycle(_globals._spriteIndexes[5], false, 12);
2156 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
2157 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[5], temp);
2158 		_scene->_sequences.addTimer(20, 6);
2159 		break;
2160 
2161 	case 6:
2162 		_scene->_sequences.setDone(_globals._sequenceIndexes[5]);
2163 		_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 17, 1, 0, 0);
2164 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[5], 13, 15);
2165 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
2166 
2167 		_scene->_sequences.remove(_globals._sequenceIndexes[3]);
2168 		_globals._sequenceIndexes[3] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[3], false, 17, 1, 0, 0);
2169 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 2, 3);
2170 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2171 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[5], SEQUENCE_TRIGGER_EXPIRE, 0, 7);
2172 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 8);
2173 		break;
2174 
2175 	case 7:
2176 		_scene->_sequences.setDone(_globals._sequenceIndexes[5]);
2177 		_globals._sequenceIndexes[5] = _scene->_sequences.startCycle(_globals._spriteIndexes[5], false, 16);
2178 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[5]);
2179 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[5], -1);
2180 		break;
2181 
2182 	case 8:
2183 		temp = _globals._sequenceIndexes[3];
2184 		_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 2);
2185 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2186 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], temp);
2187 		_scene->_sequences.addTimer(20, 9);
2188 		break;
2189 
2190 	case 9:
2191 		_scene->_sequences.setDone(_globals._sequenceIndexes[5]);
2192 		_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 1);
2193 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2194 		_scene->_sequences.addTimer(48, 10);
2195 		break;
2196 
2197 	case 10:
2198 		_scene->_nextSceneId = 313;
2199 		break;
2200 
2201 	default:
2202 		break;
2203 	}
2204 }
2205 
enter()2206 void Scene316::enter() {
2207 	if (_globals[kSexOfRex] == REX_MALE) {
2208 		_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('g', -1));
2209 		_globals._spriteIndexes[4] = _scene->_sprites.addSprites("*RXCL_8");
2210 		_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*RXCL_2");
2211 	} else {
2212 		_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('g', 0));
2213 		_globals._spriteIndexes[5] = _scene->_sprites.addSprites("*ROXCL_8");
2214 	}
2215 
2216 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('v', 0));
2217 	_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 1);
2218 	_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 12);
2219 
2220 	if (_scene->_priorSceneId == 366) {
2221 		_game._player._stepEnabled = false;
2222 		_game._player._visible = false;
2223 		_game._player._playerPos = Common::Point(78, 87);
2224 		_game._player._facing = FACING_SOUTH;
2225 		_scene->_sequences.addTimer(48, 70);
2226 	} else if (_scene->_priorSceneId == 321) {
2227 		_game._player._playerPos = Common::Point(153, 102);
2228 		_game._player._facing = FACING_SOUTH;
2229 		_game._player._stepEnabled = false;
2230 		_game._player._visible = false;
2231 		_vm->_sound->command(44);
2232 		int spriteIdx = (_globals[kSexOfRex] == REX_MALE) ? 1 : 2;
2233 		_globals._sequenceIndexes[1] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[spriteIdx], false, 6, 1, 0, 0);
2234 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 2);
2235 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[1], SEQUENCE_TRIGGER_EXPIRE, 0, 60);
2236 	} else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG)
2237 		_game._player._playerPos = Common::Point(291, 126);
2238 
2239 	sceneEntrySound();
2240 	_game.loadQuoteSet(0xFD, 0);
2241 }
2242 
step()2243 void Scene316::step() {
2244 	if (_game._trigger == 60) {
2245 		_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[1]);
2246 		_game._player._visible = true;
2247 		_game._player._stepEnabled = true;
2248 	}
2249 
2250 	if (_game._trigger >= 70) {
2251 		switch (_game._trigger) {
2252 		case 70:
2253 			_scene->_sequences.remove(_globals._sequenceIndexes[3]);
2254 			_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 12, 1, 0, 0);
2255 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 2, 6);
2256 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2257 
2258 			_globals._sequenceIndexes[6] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[6], false, 12, 1, 0, 0);
2259 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[6], 1, 5);
2260 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[6]);
2261 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 71);
2262 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[6], SEQUENCE_TRIGGER_EXPIRE, 0, 72);
2263 			break;
2264 
2265 		case 71: {
2266 			int synxIdx = _globals._sequenceIndexes[3];
2267 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, -2);
2268 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 3);
2269 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], synxIdx);
2270 			}
2271 			break;
2272 
2273 		case 72: {
2274 			int synxIdx = _globals._sequenceIndexes[6];
2275 			_globals._sequenceIndexes[6] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[6], false, 12, 1, 0, 0);
2276 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[6], 6, 9);
2277 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[6]);
2278 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[6], synxIdx);
2279 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[6], SEQUENCE_TRIGGER_EXPIRE, 0, 73);
2280 			}
2281 			break;
2282 
2283 		case 73:
2284 			_scene->_sequences.remove(_globals._sequenceIndexes[3]);
2285 			_globals._sequenceIndexes[3] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[3], false, 12, 1, 0, 0);
2286 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 1, 5);
2287 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 12);
2288 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[6]);
2289 
2290 			_globals._sequenceIndexes[6] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[6], false, 12, 1, 0, 0);
2291 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[6], 10, -2);
2292 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[6]);
2293 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 74);
2294 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[6], SEQUENCE_TRIGGER_EXPIRE, 0, 75);
2295 			break;
2296 
2297 		case 74: {
2298 			int synxIdx = _globals._sequenceIndexes[3];
2299 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 1);
2300 			_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 12);
2301 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], synxIdx);
2302 			}
2303 			break;
2304 
2305 		case 75:
2306 			_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[6]);
2307 			_game._player._stepEnabled = true;
2308 			_game._player._visible = true;
2309 			break;
2310 
2311 		default:
2312 			break;
2313 		}
2314 	}
2315 }
2316 
preActions()2317 void Scene316::preActions() {
2318 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_EAST)) {
2319 		if (_globals[kAfterHavoc])
2320 			_game._player._walkOffScreenSceneId = 354;
2321 		else
2322 			_game._player._walkOffScreenSceneId = 304;
2323 	}
2324 }
2325 
actions()2326 void Scene316::actions() {
2327 	if (_action.isAction(VERB_CLIMB_INTO, NOUN_AIR_VENT)) {
2328 		if (_globals[kSexOfRex] == REX_FEMALE)
2329 			handleRoxInGrate();
2330 		else
2331 			handleRexInGrate();
2332 	} else if (_action.isAction(VERB_WALK_UP, NOUN_RAMP) || _action.isAction(VERB_WALK_ONTO, NOUN_PLATFORM)) {
2333 		switch (_game._trigger) {
2334 		case 0:
2335 			if (_globals[kCityFlooded]) {
2336 				_vm->_dialogs->show(31623);
2337 			} else {
2338 				_vm->_sound->command(45);
2339 				_game._player._stepEnabled = false;
2340 				_game._player._visible = false;
2341 				if (_globals[kSexOfRex] == REX_MALE) {
2342 					_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 7, 1, 0, 0);
2343 					_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], -1, 7);
2344 					_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 2);
2345 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[1], SEQUENCE_TRIGGER_EXPIRE, 0, 1);
2346 				} else {
2347 					_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 7, 1, 0, 0);
2348 					_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 2);
2349 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
2350 				}
2351 			}
2352 			break;
2353 
2354 		case 1:
2355 			_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 7, 1, 0, 0);
2356 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], 8, -2);
2357 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 2);
2358 			_scene->_kernelMessages.reset();
2359 			if (!_game._visitedScenes.exists(321))
2360 				_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 0, 120, _game.getQuote(253));
2361 
2362 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[1], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
2363 			break;
2364 
2365 		case 2:
2366 			_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 7, 0, 0, 0);
2367 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], -2, -2);
2368 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 2);
2369 			_scene->_sequences.addTimer(48, 4);
2370 			break;
2371 
2372 		case 3:
2373 			_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 7, 0, 0, 0);
2374 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], -2, -2);
2375 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 2);
2376 			_scene->_sequences.addTimer(48, 4);
2377 			break;
2378 
2379 		case 4:
2380 			_scene->_nextSceneId = 321;
2381 			break;
2382 
2383 		default:
2384 			break;
2385 		}
2386 	} else if (_action.isAction(VERB_LOOK, NOUN_PLATFORM))
2387 		_vm->_dialogs->show(31610);
2388 	else if (_action.isAction(VERB_LOOK, NOUN_STRANGE_DEVICE)) {
2389 		if (_game._visitedScenes.exists(321))
2390 			_vm->_dialogs->show(31612);
2391 		else
2392 			_vm->_dialogs->show(31611);
2393 	} else if (_action.isAction(VERB_LOOK, NOUN_CONTROLS))
2394 		_vm->_dialogs->show(31613);
2395 	else if (_action.isAction(VERB_LOOK, NOUN_EQUIPMENT))
2396 		_vm->_dialogs->show(31614);
2397 	else if (_action.isAction(VERB_LOOK, NOUN_PANEL))
2398 		_vm->_dialogs->show(31615);
2399 	else if (_action.isAction(VERB_LOOK, NOUN_MONITOR))
2400 		_vm->_dialogs->show(31616);
2401 	else if (_action.isAction(VERB_LOOK, NOUN_RAMP))
2402 		_vm->_dialogs->show(31617);
2403 	else if (_action.isAction(VERB_LOOK, NOUN_AIR_VENT))
2404 		_vm->_dialogs->show(31618);
2405 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_EAST)) {
2406 		if (!_globals[kAfterHavoc]) {
2407 			if (_game._difficulty != DIFFICULTY_EASY)
2408 				_vm->_dialogs->show(31620);
2409 			else
2410 				_vm->_dialogs->show(31619);
2411 		}
2412 	} else if (_action.isAction(VERB_LOOK, NOUN_FLOOR))
2413 		_vm->_dialogs->show(31621);
2414 	else if (_action.isAction(VERB_LOOK, NOUN_SUPPORT))
2415 		_vm->_dialogs->show(31622);
2416 	else
2417 		return;
2418 
2419 	_action._inProgress = false;
2420 }
2421 
2422 
2423 /*------------------------------------------------------------------------*/
2424 
Scene318(MADSEngine * vm)2425 Scene318::Scene318(MADSEngine *vm) : Scene3xx(vm) {
2426 	_dropTimer = 0;
2427 
2428 	_lastFrame = -1;
2429 	_animMode = -1;
2430 	_internCounter = -1;
2431 	_counter = -1;
2432 
2433 	_dialogFl = false;
2434 	_internTalkingFl = false;
2435 	_internWalkingFl = false;
2436 	_internVisibleFl = false;
2437 	_explosionFl = false;
2438 
2439 	_lastFrameCounter = 0;
2440 
2441 	_subQuote2 = "";
2442 }
2443 
synchronize(Common::Serializer & s)2444 void Scene318::synchronize(Common::Serializer &s) {
2445 	Scene3xx::synchronize(s);
2446 
2447 	s.syncAsUint32LE(_dropTimer);
2448 
2449 	s.syncAsSint32LE(_lastFrame);
2450 	s.syncAsSint32LE(_animMode);
2451 	s.syncAsSint32LE(_internCounter);
2452 	s.syncAsSint32LE(_counter);
2453 
2454 	s.syncAsByte(_dialogFl);
2455 	s.syncAsByte(_internTalkingFl);
2456 	s.syncAsByte(_internWalkingFl);
2457 	s.syncAsByte(_internVisibleFl);
2458 	s.syncAsByte(_explosionFl);
2459 
2460 	s.syncAsUint32LE(_lastFrameCounter);
2461 
2462 	s.syncString(_subQuote2);
2463 }
2464 
setup()2465 void Scene318::setup() {
2466 	setPlayerSpritesPrefix();
2467 	setAAName();
2468 }
2469 
handleDialog()2470 void Scene318::handleDialog() {
2471 	if (!_game._trigger) {
2472 		_game._player._stepEnabled = false;
2473 		handleRexDialogs(_action._activeAction._verbId);
2474 	} else if (_game._trigger == 2) {
2475 		int synxIdx = _globals._sequenceIndexes[2];
2476 		_globals._sequenceIndexes[2] = _scene->_sequences.startCycle(_globals._spriteIndexes[2], false, 1);
2477 		_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
2478 		_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(142, 121));
2479 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[2], synxIdx);
2480 		_vm->_sound->command(3);
2481 		_scene->_userInterface.setup(kInputBuildingSentences);
2482 		_game._player._stepEnabled = true;
2483 	} else {
2484 		if (_action._activeAction._verbId < 0x19C)
2485 			_dialog1.write(_action._activeAction._verbId, false);
2486 
2487 		switch (_action._activeAction._verbId) {
2488 		case 0x191:
2489 			handleInternDialog(0x19E, 2, INDEFINITE_TIMEOUT);
2490 			_dialog1.write(0x192, true);
2491 			break;
2492 
2493 		case 0x192:
2494 			handleInternDialog(0x1A0, 5, INDEFINITE_TIMEOUT);
2495 			_dialog1.write(0x193, true);
2496 			break;
2497 
2498 		case 0x193:
2499 			handleInternDialog(0x1A5, 4, INDEFINITE_TIMEOUT);
2500 			_dialog1.write(0x194, true);
2501 			break;
2502 
2503 		case 0x194:
2504 			handleInternDialog(0x1A9, 6, INDEFINITE_TIMEOUT);
2505 			_dialog1.write(0x195, true);
2506 			_dialog1.write(0x196, true);
2507 			_dialog1.write(0x19D, false);
2508 			break;
2509 
2510 		case 0x195:
2511 			handleInternDialog(0x1AF, 7, INDEFINITE_TIMEOUT);
2512 			if (!_dialog1.read(0x196))
2513 				_dialog1.write(0x197, true);
2514 			break;
2515 
2516 		case 0x196:
2517 			handleInternDialog(0x1B6, 5, INDEFINITE_TIMEOUT);
2518 			if (!_dialog1.read(0x195))
2519 				_dialog1.write(0x197, true);
2520 			break;
2521 
2522 		case 0x197:
2523 			handleInternDialog(0x1BB, 5, INDEFINITE_TIMEOUT);
2524 			break;
2525 
2526 		case 0x198:
2527 			handleInternDialog(0x1C0, 5, INDEFINITE_TIMEOUT);
2528 			_dialog1.write(0x19A, true);
2529 			break;
2530 
2531 		case 0x199:
2532 			handleInternDialog(0x1C5, 3, INDEFINITE_TIMEOUT);
2533 			break;
2534 
2535 		case 0x19A:
2536 			handleInternDialog(0x1C8, 5, INDEFINITE_TIMEOUT);
2537 			_dialog1.write(0x19B, true);
2538 			break;
2539 
2540 		case 0x19B:
2541 			handleInternDialog(0x1CD, 3, INDEFINITE_TIMEOUT);
2542 			break;
2543 
2544 		case 0x19C:
2545 		case 0x19D:
2546 			_scene->_sequences.remove(_globals._sequenceIndexes[2]);
2547 			_globals._sequenceIndexes[2] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[2], false, 8, 1, 0, 0);
2548 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
2549 			_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(142, 121));
2550 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 6, 8);
2551 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
2552 
2553 			_dialogFl = false;
2554 			handleInternDialog(0x1D0, 1, 120);
2555 			if (_dialog1.read(0) || (_action._activeAction._verbId == 0x19D)) {
2556 				_explosionFl = true;
2557 				_internCounter = 3420;
2558 			}
2559 			break;
2560 
2561 		default:
2562 			break;
2563 		}
2564 
2565 		if (_action._activeAction._verbId < 0x19C) {
2566 			_dialog1.start();
2567 			_game._player._stepEnabled = true;
2568 		}
2569 
2570 	}
2571 }
2572 
handleRexDialogs(int quote)2573 void Scene318::handleRexDialogs(int quote) {
2574 	_scene->_kernelMessages.reset();
2575 
2576 	Common::String curQuote = _game.getQuote(quote);
2577 	if (_vm->_font->getWidth(curQuote, _scene->_textSpacing) > 200) {
2578 		Common::String subQuote1;
2579 		_game.splitQuote(curQuote, subQuote1, _subQuote2);
2580 		_scene->_kernelMessages.add(Common::Point(138, 59), 0x1110, 32, 0, 240, subQuote1);
2581 		_scene->_kernelMessages.add(Common::Point(138, 73), 0x1110, 32, 1, 180, _subQuote2);
2582 	} else
2583 		_scene->_kernelMessages.add(Common::Point(138, 73), 0x1110, 32, 1, 120, curQuote);
2584 }
2585 
handleInternDialog(int quoteId,int quoteNum,uint32 timeout)2586 void Scene318::handleInternDialog(int quoteId, int quoteNum, uint32 timeout) {
2587 	int height = quoteNum * 14;
2588 	int posY;
2589 	if (height < 85)
2590 		posY = 87 - height;
2591 	else
2592 		posY = 2;
2593 
2594 	int curQuoteId= quoteId;
2595 
2596 	int maxWidth = 0;
2597 	for (int i = 0; i < quoteNum; i++) {
2598 		maxWidth = MAX(maxWidth, _vm->_font->getWidth(_game.getQuote(curQuoteId), -1));
2599 		curQuoteId++;
2600 	}
2601 
2602 	int posX = MIN(319 - maxWidth, 178 - (maxWidth >> 1));
2603 	curQuoteId = quoteId;
2604 
2605 	_scene->_kernelMessages.reset();
2606 	_internTalkingFl = true;
2607 
2608 	// WORKAROUND: In case the player launches multiple talk selections with the
2609 	// intern before previous ones have finished, take care of removing any
2610 	int seqIndex;
2611 	while ((seqIndex = _scene->_sequences.findByTrigger(63)) != -1)
2612 		_scene->_sequences.remove(seqIndex);
2613 
2614 	for (int i = 0; i < quoteNum; i++) {
2615 		_game._triggerSetupMode = SEQUENCE_TRIGGER_DAEMON;
2616 		_scene->_sequences.addTimer(180, 63);
2617 		_scene->_kernelMessages.add(Common::Point(posX, posY), 0xFDFC, 0, 0, timeout, _game.getQuote(curQuoteId));
2618 		posY += 14;
2619 		curQuoteId++;
2620 	}
2621 }
2622 
enter()2623 void Scene318::enter() {
2624 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('x', 0));
2625 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('k', -1));
2626 
2627 	if (_globals[kAfterHavoc]) {
2628 		_scene->loadAnimation(formAnimName('f', -1));
2629 		_scene->_animation[0]->_resetFlag = true;
2630 	} else if (!_globals[kHasSeenProfPyro]) {
2631 		_scene->_hotspots.activate(NOUN_PROFESSORS_GURNEY, false);
2632 		_scene->_hotspots.activate(NOUN_PROFESSOR, false);
2633 		_scene->_hotspots.activate(NOUN_TAPE_PLAYER, false);
2634 	}
2635 
2636 	if (_game._objects.isInRoom(OBJ_SCALPEL)) {
2637 		_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 6, 0, 0, 120);
2638 		_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 4);
2639 		_scene->_dynamicHotspots.add(NOUN_SCALPEL, VERB_TAKE, _globals._sequenceIndexes[3], Common::Rect(0, 0, 0, 0));
2640 	}
2641 
2642 	if (_scene->_priorSceneId == 357)
2643 		_game._player._playerPos = Common::Point(15, 110);
2644 	else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG)
2645 		_game._player._playerPos = Common::Point(214, 152);
2646 
2647 	_dialog1.setup(0x47, 0x191, 0x192, 0x193, 0x194, 0x195, 0x196, 0x197, 0x198, 0x199, 0x19A, 0x19B, 0x19C, 0x19D, 0);
2648 
2649 	if (!_game._visitedScenes._sceneRevisited) {
2650 		_dialog1.set(0x191, 0x198, 0x199, 0x19C, 0);
2651 		if (_game._widepipeCtr >= 2)
2652 			_dialog1.write(0x19D, true);
2653 	}
2654 
2655 	if (_scene->_priorSceneId == 307) {
2656 		_game._player._visible = false;
2657 		_game._player._stepEnabled = false;
2658 		_scene->loadAnimation(formAnimName('a', -1), 60);
2659 		_animMode = 1;
2660 	}
2661 
2662 	_lastFrame = 0;
2663 	_scene->_hotspots.activate(NOUN_INTERN, false);
2664 
2665 	if (_scene->_priorSceneId != RETURNING_FROM_DIALOG) {
2666 		_dialogFl = false;
2667 		_internWalkingFl = false;
2668 		_counter= 0;
2669 		_internCounter= 0;
2670 		_internVisibleFl = true;
2671 		_explosionFl = false;
2672 	}
2673 
2674 	_game.loadQuoteSet(0x18C, 0x18D, 0x18E, 0x18F, 0x191, 0x192, 0x193, 0x194, 0x195, 0x196,
2675 		0x197, 0x198, 0x199, 0x19A, 0x19B, 0x19C, 0x19E, 0x19E, 0x1A0, 0x1A1, 0x1A2, 0x1A3,
2676 		0x1A4, 0x1A5, 0x1A6, 0x1A7, 0x1A8, 0x1A9, 0x1AA, 0x1AB, 0x1AC, 0x1AD, 0x1AE, 0x1AF,
2677 		0x1B0, 0x1B1, 0x1B2, 0x1B3, 0x1B4, 0x1B5, 0x1B6, 0x1B7, 0x1B8, 0x1B9, 0x1BA, 0x1BB,
2678 		0x1BC, 0x1BD, 0x1BE, 0x1BF, 0x1C0, 0x1C1, 0x1C2, 0x1C3, 0x1C4, 0x1C5, 0x1C6, 0x1C7,
2679 		0x1C8, 0x1C9, 0x1CA, 0x1CB, 0x1CC, 0x1CD, 0x1CE, 0x1CF, 0x1D0, 0x1D1, 0x1D2, 0x1D3,
2680 		0x190, 0x19D, 0);
2681 
2682 	if ((_scene->_priorSceneId == RETURNING_FROM_DIALOG) || (((_scene->_priorSceneId == 318) ||
2683 			(_scene->_priorSceneId == RETURNING_FROM_LOADING)) && (!_globals[kAfterHavoc]))) {
2684 		if (!_globals[kAfterHavoc]) {
2685 			_game._player._visible = false;
2686 			_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('g', -1));
2687 			_animMode = 2;
2688 
2689 			if (_game._visitedScenes.exists(319) || !_internVisibleFl) {
2690 				_internVisibleFl = false;
2691 				_dialogFl = false;
2692 			} else {
2693 				_scene->loadAnimation(formAnimName('b', -1), 61);
2694 				_scene->_hotspots.activate(NOUN_INTERN, true);
2695 			}
2696 
2697 			if (_dialogFl) {
2698 				_dialog1.start();
2699 				_globals._sequenceIndexes[2] = _scene->_sequences.startCycle(_globals._spriteIndexes[2], false, 8);
2700 			} else
2701 				_globals._sequenceIndexes[2] = _scene->_sequences.startCycle(_globals._spriteIndexes[2], false, 1);
2702 
2703 			_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(142, 121));
2704 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
2705 		}
2706 	}
2707 
2708 	if (_scene->_priorSceneId == 319) {
2709 		_game._player._stepEnabled = false;
2710 		_game._player._visible = false;
2711 		_animMode = 4;
2712 		if (!_globals[kHasSeenProfPyro]) {
2713 			_scene->loadAnimation(formAnimName('d', -1), 64);
2714 			_globals[kHasSeenProfPyro] = true;
2715 		} else {
2716 			_scene->loadAnimation(formAnimName('e', -1), 64);
2717 		}
2718 	}
2719 
2720 	_internTalkingFl = false;
2721 	_vm->_palette->setEntry(252, 63, 63, 10);
2722 	_vm->_palette->setEntry(253, 45, 45, 05);
2723 
2724 	_dropTimer = _vm->_game->_scene._frameStartTime;
2725 	sceneEntrySound();
2726 
2727 	if (_dialogFl)
2728 		_vm->_sound->command(15);
2729 }
2730 
step()2731 void Scene318::step() {
2732 	if ((_scene->_animation[0] != nullptr) && (_animMode == 2)) {
2733 		if (_lastFrame != _scene->_animation[0]->getCurrentFrame()) {
2734 			_lastFrame = _scene->_animation[0]->getCurrentFrame();
2735 			int nextFrame = -1;
2736 
2737 			switch (_lastFrame) {
2738 			case 20:
2739 			case 30:
2740 			case 40:
2741 			case 50:
2742 			case 60:
2743 			case 70:
2744 			case 80:
2745 			case 90:
2746 			case 100:
2747 			case 110:
2748 			case 120:
2749 			case 130:
2750 			case 140:
2751 			case 149:
2752 				if (_internWalkingFl) {
2753 					nextFrame = 149;
2754 				} else if (_internTalkingFl) {
2755 					nextFrame = 149;
2756 				} else if (_lastFrame == 149) {
2757 					nextFrame = 4;
2758 				}
2759 				break;
2760 
2761 			case 151:
2762 				if (_internWalkingFl)
2763 					nextFrame = 183;
2764 				break;
2765 
2766 			case 167:
2767 			case 184:
2768 				if (_internWalkingFl) {
2769 					nextFrame = 184;
2770 				} else if (!_internTalkingFl) {
2771 					nextFrame = 0;
2772 				} else if (_vm->getRandomNumber(1, 100) <= 50) {
2773 					nextFrame = 151;
2774 				} else {
2775 					nextFrame = 167;
2776 				}
2777 
2778 				if (nextFrame == 184) {
2779 					handleInternDialog(0x1D1, 3, 240);
2780 					_scene->_hotspots.activate(NOUN_INTERN, false);
2781 					_internVisibleFl = false;
2782 				}
2783 				break;
2784 
2785 			default:
2786 				break;
2787 			}
2788 
2789 			if ((nextFrame >= 0) && (nextFrame != _scene->_animation[0]->getCurrentFrame())) {
2790 				_scene->_animation[0]->setCurrentFrame(nextFrame);
2791 				_lastFrame = nextFrame;
2792 			}
2793 		}
2794 	}
2795 
2796 	switch (_game._trigger) {
2797 	case 60:
2798 		_vm->_sound->command(3);
2799 		_animMode = 2;
2800 		_scene->_reloadSceneFlag = true;
2801 		break;
2802 
2803 	case 61:
2804 		_counter = 0;
2805 		break;
2806 
2807 	case 62:
2808 		_scene->_nextSceneId = 319;
2809 		break;
2810 
2811 	case 63:
2812 		_internTalkingFl = false;
2813 		break;
2814 
2815 	case 64:
2816 		_vm->_sound->command(3);
2817 		_scene->_nextSceneId = 307;
2818 		break;
2819 
2820 	default:
2821 		break;
2822 	}
2823 
2824 	uint32 tmpFrame = _vm->_events->getFrameCounter();
2825 	long diffFrame = tmpFrame - _lastFrameCounter;
2826 	_lastFrameCounter = tmpFrame;
2827 
2828 	if ((_animMode == 2) && !_internVisibleFl && _game._player._stepEnabled) {
2829 		if ((diffFrame >= 0) && (diffFrame <= 4))
2830 			_counter += diffFrame;
2831 		else
2832 			_counter++;
2833 
2834 		int extraCounter = _game._objects.isInInventory(OBJ_SCALPEL) ? 900 : 0;
2835 
2836 		if (_counter + extraCounter >= 1800) {
2837 			_scene->freeAnimation();
2838 			_game._player._stepEnabled = false;
2839 			_scene->loadAnimation(formAnimName('c', -1), 62);
2840 			_animMode = 3;
2841 		}
2842 	} else if ((_animMode == 2) && _explosionFl && _internVisibleFl && !_dialogFl
2843 			&& !_internWalkingFl && (_game._screenObjects._inputMode != kInputConversation)) {
2844 		if ((diffFrame >= 0) && (diffFrame <= 4))
2845 			_internCounter += diffFrame;
2846 		else
2847 			_internCounter++;
2848 
2849 		if (_internCounter >= 3600) {
2850 			_vm->_sound->command(59);
2851 			_vm->_screen->_shakeCountdown = 20;
2852 			_internWalkingFl = true;
2853 		}
2854 	}
2855 
2856 	if ((_vm->_game->_scene._frameStartTime - _dropTimer) > 600) {
2857 		_vm->_sound->command(51);
2858 		_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 14, 1, 0, 0);
2859 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 10);
2860 		_dropTimer = _vm->_game->_scene._frameStartTime;
2861 	}
2862 }
2863 
preActions()2864 void Scene318::preActions() {
2865 	if (_game._player._needToWalk)
2866 		_game._player._needToWalk = _game._player._visible;
2867 
2868 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_WEST))
2869 		_game._player._walkOffScreenSceneId = 357;
2870 }
2871 
actions()2872 void Scene318::actions() {
2873 	if (_game._screenObjects._inputMode == kInputConversation) {
2874 		handleDialog();
2875 		_action._inProgress = false;
2876 		return;
2877 	}
2878 
2879 	if (_action.isAction(VERB_TALKTO, NOUN_INTERN)) {
2880 		switch (_game._trigger) {
2881 		case 0: {
2882 			_dialogFl = true;
2883 			_vm->_sound->command(15);
2884 			_game._player._stepEnabled = false;
2885 			handleRexDialogs(_vm->getRandomNumber(0x18C, 0x18E));
2886 
2887 			_scene->_sequences.remove(_globals._sequenceIndexes[2]);
2888 			_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 8, 1, 0, 80);
2889 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
2890 			_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(142, 121));
2891 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 6, 8);
2892 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
2893 			}
2894 			break;
2895 
2896 		case 1:
2897 			_game._player._stepEnabled = true;
2898 			handleInternDialog(0x18F, 1, INDEFINITE_TIMEOUT);
2899 			_dialog1.start();
2900 			break;
2901 
2902 		case 2: {
2903 			int oldIdx = _globals._sequenceIndexes[2];
2904 			_globals._sequenceIndexes[2] = _scene->_sequences.startCycle(_globals._spriteIndexes[2], false, 8);
2905 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
2906 			_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(142, 121));
2907 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[2], oldIdx);
2908 			}
2909 			break;
2910 
2911 		default:
2912 			break;
2913 		}
2914 		_action._inProgress = false;
2915 		return;
2916 	}
2917 
2918 	if (_action.isAction(VERB_TAKE, NOUN_SCALPEL) && (_game._objects.isInRoom(OBJ_SCALPEL) || _game._trigger)) {
2919 		switch (_game._trigger) {
2920 		case 0:
2921 			_game._player._stepEnabled = false;
2922 			_scene->_sequences.remove(_globals._sequenceIndexes[2]);
2923 			_globals._sequenceIndexes[2] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[2], false, 8, 2, 0, 80);
2924 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
2925 			_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(142, 121));
2926 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 2, 5);
2927 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_SPRITE, 5, 1);
2928 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
2929 			break;
2930 
2931 		case 1:
2932 			if (_internVisibleFl)
2933 				handleInternDialog(0x190, 1, 120);
2934 			else {
2935 				_game._objects.addToInventory(OBJ_SCALPEL);
2936 				_vm->_dialogs->showItem(OBJ_SCALPEL, 0x7C5D);
2937 				_scene->_sequences.remove(_globals._sequenceIndexes[3]);
2938 			}
2939 			break;
2940 
2941 		case 2: {
2942 			int oldIdx = _globals._sequenceIndexes[2];
2943 			_globals._sequenceIndexes[2] = _scene->_sequences.startCycle(_globals._spriteIndexes[2], false, 1);
2944 			_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 1);
2945 			_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(142, 121));
2946 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[2], oldIdx);
2947 			_scene->_sequences.addTimer(60, 3);
2948 			}
2949 			break;
2950 
2951 		case 3:
2952 			_game._player._stepEnabled = true;
2953 			break;
2954 
2955 		default:
2956 			break;
2957 		}
2958 		_action._inProgress = false;
2959 		return;
2960 	}
2961 
2962 	if (_game._player._visible) {
2963 		if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_SOUTH)) {
2964 			_scene->_nextSceneId = 407;
2965 			_action._inProgress = false;
2966 			return;
2967 		}
2968 
2969 		if (_action.isAction(VERB_TAKE, NOUN_TAPE_PLAYER)) {
2970 			if (_game._objects.isInRoom(OBJ_AUDIO_TAPE)) {
2971 				_vm->_dialogs->showItem(OBJ_AUDIO_TAPE, 0x7C5B);
2972 				_game._objects.addToInventory(OBJ_AUDIO_TAPE);
2973 			} else
2974 				_vm->_dialogs->show(31834);
2975 
2976 			_action._inProgress = false;
2977 			return;
2978 		}
2979 
2980 		if (_action.isAction(VERB_LOOK, NOUN_TAPE_PLAYER)) {
2981 			if (_game._objects.isInRoom(OBJ_AUDIO_TAPE))
2982 				_vm->_dialogs->show(31833);
2983 			else
2984 				_vm->_dialogs->show(31834);
2985 
2986 			_action._inProgress = false;
2987 			return;
2988 		}
2989 
2990 		if (_action.isAction(VERB_WALK_INTO, NOUN_DOCTORS_OFFICE)) {
2991 			_vm->_dialogs->show(31831);
2992 			_action._inProgress = false;
2993 			return;
2994 		}
2995 
2996 		if (_action.isAction(VERB_LOOK, NOUN_GURNEY)) {
2997 			_vm->_dialogs->show(31823);
2998 			_action._inProgress = false;
2999 			return;
3000 		}
3001 
3002 		if (_action.isAction(VERB_LOOK, NOUN_INSTRUMENT_TABLE)) {
3003 			_vm->_dialogs->show(31825);
3004 			_action._inProgress = false;
3005 			return;
3006 		}
3007 	} else { // Not visible
3008 		if (_action.isAction(VERB_LOOK, NOUN_GURNEY)) {
3009 			_vm->_dialogs->show(31822);
3010 			_action._inProgress = false;
3011 			return;
3012 		}
3013 
3014 		if (_action.isAction(VERB_LOOK, NOUN_INSTRUMENT_TABLE)) {
3015 			_vm->_dialogs->show(31824);
3016 			_action._inProgress = false;
3017 			return;
3018 		}
3019 	}
3020 
3021 	if (_action.isAction(VERB_LOOK, NOUN_WALL))
3022 		_vm->_dialogs->show(31810);
3023 	else if (_action.isAction(VERB_LOOK, NOUN_FLOOR))
3024 		_vm->_dialogs->show(31811);
3025 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_WEST))
3026 		_vm->_dialogs->show(31812);
3027 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_SOUTH))
3028 		_vm->_dialogs->show(31813);
3029 	else if (_action.isAction(VERB_LOOK, NOUN_FAUCET))
3030 		_vm->_dialogs->show(31814);
3031 	else if (_action.isAction(VERB_LOOK, NOUN_SINK))
3032 		_vm->_dialogs->show(31815);
3033 	else if (_action.isAction(VERB_LOOK, NOUN_CONVEYOR_BELT))
3034 		_vm->_dialogs->show(31816);
3035 	else if (_action.isAction(VERB_LOOK, NOUN_LARGE_BLADE))
3036 		_vm->_dialogs->show(31817);
3037 	else if (_action.isAction(VERB_LOOK, NOUN_MONITOR))
3038 		_vm->_dialogs->show(31818);
3039 	else if (_action.isAction(VERB_LOOK, NOUN_CABINETS))
3040 		_vm->_dialogs->show(31819);
3041 	else if (_action.isAction(VERB_LOOK, NOUN_EQUIPMENT))
3042 		_vm->_dialogs->show(31820);
3043 	else if (_action.isAction(VERB_LOOK, NOUN_SHELF))
3044 		_vm->_dialogs->show(31821);
3045 	else if (_action.isAction(VERB_OPEN, NOUN_CABINETS))
3046 		_vm->_dialogs->show(31829);
3047 	else if (_action.isAction(VERB_LOOK, NOUN_INTERN))
3048 		_vm->_dialogs->show(31830);
3049 	else if (_action.isAction(VERB_LOOK, NOUN_PROFESSOR))
3050 		_vm->_dialogs->show(31832);
3051 	else if (_action.isAction(VERB_LOOK, NOUN_PROFESSORS_GURNEY))
3052 		_vm->_dialogs->show(31836);
3053 	else if (_action._lookFlag) {
3054 		if (_game._player._visible || _game._objects.isInInventory(OBJ_SCALPEL))
3055 			_vm->_dialogs->show(31828);
3056 		else if (_internVisibleFl)
3057 			_vm->_dialogs->show(31826);
3058 		else
3059 			_vm->_dialogs->show(31827);
3060 	} else
3061 		return;
3062 
3063 	_action._inProgress = false;
3064 }
3065 
3066 /*------------------------------------------------------------------------*/
3067 
Scene319(MADSEngine * vm)3068 Scene319::Scene319(MADSEngine *vm) : Scene3xx(vm) {
3069 	_animMode = -1;
3070 	_animFrame = -1;
3071 	_nextAction1 = -1;
3072 	_nextAction2 = -1;
3073 	_slacheMode = -1;
3074 	_slacheTopic = -1;
3075 	_slachePosY = -1;
3076 
3077 	_slacheTalkingFl = false;
3078 	_slacheReady = false;
3079 	_slacheInitFl = false;
3080 
3081 	_subQuote2 = "";
3082 }
3083 
synchronize(Common::Serializer & s)3084 void Scene319::synchronize(Common::Serializer &s) {
3085 	Scene3xx::synchronize(s);
3086 
3087 	s.syncAsUint32LE(_animMode);
3088 	s.syncAsUint32LE(_animFrame);
3089 	s.syncAsUint32LE(_nextAction1);
3090 	s.syncAsUint32LE(_nextAction2);
3091 	s.syncAsUint32LE(_slacheMode);
3092 	s.syncAsUint32LE(_slacheTopic);
3093 	s.syncAsUint32LE(_slachePosY);
3094 
3095 	s.syncAsByte(_slacheTalkingFl);
3096 	s.syncAsByte(_slacheReady);
3097 	s.syncAsByte(_slacheInitFl);
3098 
3099 	s.syncString(_subQuote2);
3100 }
3101 
setup()3102 void Scene319::setup() {
3103 	setPlayerSpritesPrefix();
3104 	setAAName();
3105 }
3106 
handleRexDialogues(int quote)3107 void Scene319::handleRexDialogues(int quote) {
3108 	_scene->_kernelMessages.reset();
3109 
3110 	Common::String curQuote = _game.getQuote(quote);
3111 	if (_vm->_font->getWidth(curQuote, _scene->_textSpacing) > 200) {
3112 		Common::String subQuote1;
3113 		_game.splitQuote(curQuote, subQuote1, _subQuote2);
3114 		_scene->_kernelMessages.add(Common::Point(160, 106), 0x1110, 32, 0, 120, subQuote1);
3115 		_scene->_kernelMessages.add(Common::Point(160, 120), 0x1110, 32, 1, 120, _subQuote2);
3116 	} else
3117 		_scene->_kernelMessages.add(Common::Point(160, 120), 0x1110, 32, 1, 120, curQuote);
3118 }
3119 
handleSlacheDialogs(int quoteId,int counter,uint32 timer)3120 void Scene319::handleSlacheDialogs(int quoteId, int counter, uint32 timer) {
3121 	int curQuote = quoteId;
3122 	int posY = 5 + (_slachePosY * 14);
3123 
3124 	for (int count = 0; count < counter; count++, curQuote++) {
3125 		_scene->_kernelMessages.add(Common::Point(8, posY), 0xFDFC, 0, 0, timer, _game.getQuote(curQuote));
3126 		posY += 14;
3127 	}
3128 }
3129 
enter()3130 void Scene319::enter() {
3131 	_globals._spriteIndexes[5] = _scene->_sprites.addSprites(formAnimName('e', 0));
3132 	_globals._spriteIndexes[0] = _scene->_sprites.addSprites(formAnimName('a', 0));
3133 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('a', 1));
3134 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('a', 2));
3135 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(formAnimName('a', 3));
3136 	_globals._spriteIndexes[4] = _scene->_sprites.addSprites(formAnimName('k', -1));
3137 
3138 	if (!_game._objects.isInInventory(OBJ_SCALPEL)) {
3139 		_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 1);
3140 		_scene->_sequences.setDepth(_globals._sequenceIndexes[4], 1);
3141 	}
3142 
3143 	_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 18, 0, 0, 300);
3144 	_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 67, 0, 0, 377);
3145 	_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 173, 0, 0, 233);
3146 	_scene->_sequences.setDepth(_globals._sequenceIndexes[2], 14);
3147 	_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 14);
3148 
3149 	_globals._sequenceIndexes[0] = _scene->_sequences.startCycle(_globals._spriteIndexes[0], false, 1);
3150 	_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
3151 
3152 	_dialog1.setup(0x43, 0x165, 0x166, 0x167, 0x168, 0x169, 0x16A, 0);
3153 	_dialog2.setup(0x44, 0x171, 0x172, 0x173, 0x174, 0x175, 0x176, 0);
3154 	_dialog3.setup(0x45, 0x17D, 0x17E, 0x17F, 0x180, 0x181, 0x182, 0x183, 0);
3155 
3156 	if (_scene->_priorSceneId != RETURNING_FROM_DIALOG) {
3157 		_dialog1.set(0x165, 0x166, 0x167, 0x168, 0);
3158 		_dialog2.set(0x171, 0x172, 0x173, 0x174, 0);
3159 		_dialog3.set(0x17D, 0x17E, 0x17F, 0x180, 0);
3160 	}
3161 
3162 	_game.loadQuoteSet(0x15F, 0x160, 0x161, 0x162, 0x163, 0x164, 0x16B, 0x16C, 0x16D,
3163 		0x16E, 0x16F, 0x170, 0x177, 0x178, 0x178, 0x17A, 0x17B, 0x17C, 0x165, 0x166,
3164 		0x167, 0x168, 0x169, 0x16A, 0x171, 0x172, 0x173, 0x174, 0x175, 0x176, 0x17D,
3165 		0x17E, 0x17F, 0x180, 0x181, 0x182, 0x183, 0x184, 0x185, 0x186, 0x187, 0x188,
3166 		0x189, 0x18A, 0x18B, 0);
3167 
3168 	_vm->_palette->setEntry(252, 63, 30, 2);
3169 	_vm->_palette->setEntry(253, 45, 15, 1);
3170 
3171 	_slachePosY = 0;
3172 	_slacheInitFl = false;
3173 	_slacheTalkingFl = false;
3174 	_slacheReady = false;
3175 	_animFrame = 0;
3176 
3177 	_scene->loadAnimation(formAnimName('b', 0));
3178 
3179 	if (_scene->_priorSceneId != RETURNING_FROM_DIALOG) {
3180 		_animMode = 1;
3181 		_nextAction1 = 2;
3182 		_nextAction2 = 2;
3183 		_slacheMode = 1;
3184 		_slacheTopic = 1;
3185 		_slacheInitFl = true;
3186 
3187 		if (_globals[kRexHasMetSlache]) {
3188 			handleSlacheDialogs(VERB_WALK_OUTSIDE, 2, INDEFINITE_TIMEOUT);
3189 			_slachePosY = 3;
3190 		} else {
3191 			handleSlacheDialogs(0x186, 4, INDEFINITE_TIMEOUT);
3192 			_slachePosY = 5;
3193 		}
3194 	}
3195 
3196 	switch (_slacheTopic) {
3197 	case 1:
3198 		handleSlacheDialogs(0x15F, 2, INDEFINITE_TIMEOUT);
3199 		_dialog1.start();
3200 		break;
3201 
3202 	case 2:
3203 		handleSlacheDialogs(0x16B, 2, INDEFINITE_TIMEOUT);
3204 		_dialog2.start();
3205 		break;
3206 
3207 	case 3:
3208 		handleSlacheDialogs(0x177, 2, INDEFINITE_TIMEOUT);
3209 		_dialog3.start();
3210 		break;
3211 
3212 	default:
3213 		break;
3214 	}
3215 
3216 	_slachePosY = 0;
3217 	sceneEntrySound();
3218 }
3219 
step()3220 void Scene319::step() {
3221 	if (_scene->_animation[0] == nullptr)
3222 		return;
3223 
3224 	if (_animFrame != _scene->_animation[0]->getCurrentFrame()) {
3225 		_animFrame = _scene->_animation[0]->getCurrentFrame();
3226 		int nextFrame = -1;
3227 		if (_animMode == 1) {
3228 			switch (_animFrame) {
3229 			case 6:
3230 				_slacheTalkingFl = true;
3231 				break;
3232 
3233 			case 29:
3234 				_slacheReady = true;
3235 				break;
3236 
3237 			case 39:
3238 				if (_slacheInitFl) {
3239 					_slacheInitFl = false;
3240 					if (_nextAction1 == 2)
3241 						nextFrame = 0;
3242 				} else if (_nextAction1 == 2)
3243 					_nextAction1 = 1;
3244 				break;
3245 
3246 			case 50:
3247 			case 60:
3248 			case 70:
3249 			case 85:
3250 				if (_nextAction1 == 2)
3251 					nextFrame = 0;
3252 				else if (_nextAction1 == 3) {
3253 					nextFrame = 85;
3254 					_slacheTalkingFl = true;
3255 				} else if (_animFrame == 85) {
3256 					if (!_game._player._stepEnabled)
3257 						_slacheTalkingFl = true;
3258 					nextFrame = 40;
3259 				}
3260 				break;
3261 
3262 			case 115:
3263 				_slacheReady = true;
3264 				break;
3265 
3266 			case 129:
3267 				if (_nextAction1 == 3) {
3268 					nextFrame = 115;
3269 					if (!_game._player._stepEnabled)
3270 						_slacheTalkingFl = true;
3271 				}
3272 				break;
3273 
3274 			case 145:
3275 				nextFrame = 40;
3276 				break;
3277 
3278 			default:
3279 				break;
3280 			}
3281 
3282 			if ((_animFrame > 40) && (_animFrame < 85) && (nextFrame < 0)) {
3283 				switch (_nextAction1) {
3284 				case 4:
3285 					_animFrame = 0;
3286 					_scene->freeAnimation();
3287 					_animMode = 2;
3288 					_scene->loadAnimation(formAnimName('b', 3), 70);
3289 					break;
3290 
3291 				case 5:
3292 					_animFrame = 0;
3293 					_scene->freeAnimation();
3294 					_animMode = 3;
3295 					_scene->loadAnimation(formAnimName('b', 4), 71);
3296 					break;
3297 
3298 				case 6:
3299 					_animFrame = 0;
3300 					_scene->freeAnimation();
3301 					_animMode = 4;
3302 					_scene->loadAnimation(formAnimName('b', 5), 72);
3303 					break;
3304 
3305 				default:
3306 					break;
3307 				}
3308 
3309 				if (!_animFrame) {
3310 					_scene->_sequences.remove(_globals._sequenceIndexes[0]);
3311 					_scene->_sequences.remove(_globals._sequenceIndexes[1]);
3312 
3313 					for (int i = 0; i <= 1; i++) {
3314 						_globals._sequenceIndexes[i] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[i], false, 8, 1, 0, 0);
3315 						_scene->_sequences.setAnimRange(_globals._sequenceIndexes[i], 1, 7);
3316 					}
3317 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[0], SEQUENCE_TRIGGER_EXPIRE, 0, 73);
3318 				}
3319 			}
3320 		}
3321 
3322 		if (_animMode == 2) {
3323 			if (_animFrame == 13)
3324 				_vm->_screen->_shakeCountdown = 40;
3325 
3326 			if (_animFrame == 16)
3327 				_vm->_screen->_shakeCountdown = 1;
3328 		}
3329 
3330 		if (_animMode == 3) {
3331 			if (_animFrame == 11)
3332 				_vm->_screen->_shakeCountdown = 60;
3333 
3334 			if (_animFrame == 18)
3335 				_vm->_screen->_shakeCountdown = 1;
3336 		}
3337 
3338 		if ((_animMode == 4) && (_animFrame == 16))
3339 			_vm->_screen->_shakeCountdown = 80;
3340 
3341 		if ((nextFrame >= 0) && (nextFrame != _scene->_animation[0]->getCurrentFrame())) {
3342 			_scene->_animation[0]->setCurrentFrame(nextFrame);
3343 			_animFrame = nextFrame;
3344 		}
3345 	}
3346 
3347 	switch (_game._trigger) {
3348 	case 70:
3349 	case 71: {
3350 		_animMode = 1;
3351 		_nextAction1 = _nextAction2;
3352 		_animFrame = 0;
3353 		_scene->freeAnimation();
3354 		_scene->loadAnimation(formAnimName('b', 0));
3355 		if (_nextAction1 == 3)
3356 			_scene->_animation[0]->setCurrentFrame(85);
3357 		else if (_nextAction1 == 1)
3358 			_scene->_animation[0]->setCurrentFrame(40);
3359 
3360 		_animFrame = _scene->_animation[0]->getCurrentFrame();
3361 		_slacheTalkingFl = true;
3362 		_vm->_screen->_shakeCountdown = 1;
3363 
3364 		for (int i = 0; i <= 1; i++) {
3365 			int oldIdx = _globals._sequenceIndexes[i];
3366 			_scene->_sequences.remove(_globals._sequenceIndexes[i]);
3367 			_globals._sequenceIndexes[i] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[i], false, 8, 1, 0, 0);
3368 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[i], 8, 13);
3369 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[i], oldIdx);
3370 		}
3371 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[0], SEQUENCE_TRIGGER_EXPIRE, 0, 74);
3372 
3373 		// WORKAROUND: This fixes the game sometimes going into an endless waiting
3374 		// loop even after the doctor has finished hitting Rex. Note sure if it's due
3375 		// to a bug in room script or in the engine, but this at least fixes it
3376 		int seqIndex = _scene->_sequences.findByTrigger(2);
3377 		_scene->_sequences[seqIndex]._doneFlag = false;
3378 		break;
3379 	}
3380 
3381 	case 72:
3382 		_vm->_palette->setColorFlags(0xFF, 0, 0);
3383 		_vm->_palette->setColorValues(0, 0, 0);
3384 		_vm->_palette->fadeOut(_vm->_palette->_mainPalette, nullptr, 18, 228,
3385 			248, 0, 1, 16);
3386 		_vm->_screen->_shakeCountdown = 1;
3387 		_scene->_reloadSceneFlag = true;
3388 		break;
3389 
3390 	case 73:
3391 		for (int i = 0; i <= 1; i++) {
3392 			int oldIdx = _globals._sequenceIndexes[i];
3393 			_scene->_sequences.remove(_globals._sequenceIndexes[i]);
3394 			_globals._sequenceIndexes[i] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[i], false, 8, 0, 0, 0);
3395 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[i], 6, 7);
3396 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[i], oldIdx);
3397 		}
3398 		break;
3399 
3400 	case 74:
3401 		for (int i = 0; i <= 1; i++) {
3402 			int oldIdx = _globals._sequenceIndexes[i];
3403 			_scene->_sequences.remove(_globals._sequenceIndexes[i]);
3404 			_globals._sequenceIndexes[i] = _scene->_sequences.startCycle(_globals._spriteIndexes[i], false, 1);
3405 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[i], oldIdx);
3406 		}
3407 		break;
3408 
3409 	default:
3410 		break;
3411 	}
3412 }
3413 
actions()3414 void Scene319::actions() {
3415 	if (_game._trigger == 0) {
3416 		_game._player._stepEnabled = false;
3417 		handleRexDialogues(_action._activeAction._verbId);
3418 	} else {
3419 		if ((_action._activeAction._verbId == 0x165) || (_action._activeAction._verbId == 0x166)) {
3420 			if (_game._trigger == 1) {
3421 				_nextAction1 = 3;
3422 				_slacheTalkingFl = false;
3423 				_slacheMode = 1;
3424 				_slacheTopic = 2;
3425 			}
3426 
3427 			if (!_slacheTalkingFl) {
3428 				_scene->_sequences.addTimer(4, 2);
3429 			} else {
3430 				handleSlacheDialogs(0x16B, 2, INDEFINITE_TIMEOUT);
3431 				_dialog2.start();
3432 				_game._player._stepEnabled = true;
3433 			}
3434 		}
3435 
3436 		if ((_action._activeAction._verbId == 0x171) || (_action._activeAction._verbId == 0x172)) {
3437 			if (_game._trigger == 1) {
3438 				_nextAction1 = 2;
3439 				_slacheTalkingFl = false;
3440 				_slacheMode = 1;
3441 				_slacheTopic = 3;
3442 			}
3443 
3444 			if (!_slacheTalkingFl) {
3445 				_scene->_sequences.addTimer(4, 2);
3446 			} else {
3447 				handleSlacheDialogs(0x177, 2, INDEFINITE_TIMEOUT);
3448 				_dialog3.start();
3449 				_game._player._stepEnabled = true;
3450 			}
3451 		}
3452 
3453 		if ((_action._activeAction._verbId == 0x17D) || (_action._activeAction._verbId == 0x17E)) {
3454 			if (_game._trigger == 1) {
3455 				_nextAction1 = 3;
3456 				_slacheTalkingFl = false;
3457 				_slacheReady = false;
3458 				_slacheMode = 1;
3459 				_slacheTopic = 1;
3460 			}
3461 
3462 			if (!_slacheTalkingFl) {
3463 				_scene->_sequences.addTimer(4, 2);
3464 			} else {
3465 				if (_game._trigger == 2)
3466 					handleSlacheDialogs(0x184, 2, 180);
3467 
3468 				if (!_slacheReady) {
3469 					_scene->_sequences.addTimer(120, 3);
3470 				} else {
3471 					_globals[kRexHasMetSlache] = true;
3472 					_scene->_nextSceneId = 318;
3473 				}
3474 			}
3475 		}
3476 
3477 		if ((_action._activeAction._verbId == 0x168) || (_action._activeAction._verbId == 0x174) ||
3478 			(_action._activeAction._verbId == 0x180) || (_action._activeAction._verbId == 0x169) ||
3479 			(_action._activeAction._verbId == 0x175) || (_action._activeAction._verbId == 0x181) ||
3480 			(_action._activeAction._verbId == 0x16A) || (_action._activeAction._verbId == 0x176) ||
3481 			(_action._activeAction._verbId == 0x182) || (_action._activeAction._verbId == 0x183) ||
3482 			(_action._activeAction._verbId == 0x167) || (_action._activeAction._verbId == 0x173) ||
3483 			(_action._activeAction._verbId == 0x17F)) {
3484 
3485 			bool addDialogLine = !((_action._activeAction._verbId == 0x167) || (_action._activeAction._verbId == 0x173) ||
3486 					(_action._activeAction._verbId == 0x17F) || (_action._activeAction._verbId == 0x16A) ||
3487 					(_action._activeAction._verbId == 0x176) || (_action._activeAction._verbId == 0x182) ||
3488 					(_action._activeAction._verbId == 0x183));
3489 
3490 			int addVerbId = _action._activeAction._verbId + 1;
3491 			if ((addVerbId == 0x182) && (_game._storyMode != STORYMODE_NAUGHTY))
3492 				addVerbId = 0x183;
3493 
3494 			if (_slacheMode == 1) {
3495 				if (_game._trigger == 1) {
3496 					_nextAction2 = _nextAction1;
3497 					_nextAction1 = 4;
3498 				}
3499 
3500 				if (_nextAction1 != _nextAction2) {
3501 					_scene->_sequences.addTimer(4, 2);
3502 				} else {
3503 					Conversation *curDialog;
3504 					int nextDocQuote;
3505 					if ((_action._activeAction._verbId == 0x168) || (_action._activeAction._verbId == 0x167)) {
3506 						curDialog = &_dialog1;
3507 						nextDocQuote = 0x161;
3508 					} else if ((_action._activeAction._verbId == 0x174) || (_action._activeAction._verbId == 0x1753)) {
3509 						nextDocQuote = 0x16D;
3510 						curDialog = &_dialog2;
3511 					} else {
3512 						nextDocQuote = 0x179;
3513 						curDialog = &_dialog3;
3514 					}
3515 
3516 					handleSlacheDialogs(nextDocQuote, 2, INDEFINITE_TIMEOUT);
3517 					if (addDialogLine) {
3518 						curDialog->write(_action._activeAction._verbId, false);
3519 						curDialog->write(addVerbId, true);
3520 					}
3521 
3522 					curDialog->start();
3523 					_game._player._stepEnabled = true;
3524 					_slacheMode = 2;
3525 				}
3526 			} else if (_slacheMode == 2) {
3527 				if (_game._trigger == 1) {
3528 					_nextAction2 = _nextAction1;
3529 					_nextAction1 = 5;
3530 				}
3531 
3532 				if (_nextAction1 != _nextAction2) {
3533 					_scene->_sequences.addTimer(4, 2);
3534 				} else {
3535 					Conversation *curDialog;
3536 					int nextDocQuote;
3537 					if ((_action._activeAction._verbId == 0x168) || (_action._activeAction._verbId == 0x169) || (_action._activeAction._verbId == 0x167)) {
3538 						curDialog = &_dialog1;
3539 						nextDocQuote = 0x163;
3540 					} else if ((_action._activeAction._verbId == 0x174) || (_action._activeAction._verbId == 0x175) || (_action._activeAction._verbId == 0x173)) {
3541 						nextDocQuote = 0x16F;
3542 						curDialog = &_dialog2;
3543 					} else {
3544 						nextDocQuote = 0x17B;
3545 						curDialog = &_dialog3;
3546 					}
3547 
3548 					handleSlacheDialogs(nextDocQuote, 2, INDEFINITE_TIMEOUT);
3549 					if (addDialogLine) {
3550 						curDialog->write(_action._activeAction._verbId, false);
3551 						curDialog->write(addVerbId, true);
3552 					}
3553 
3554 					curDialog->start();
3555 					_game._player._stepEnabled = true;
3556 					_slacheMode = 3;
3557 				}
3558 			} else {
3559 				_nextAction2 = _nextAction1;
3560 				_nextAction1 = 6;
3561 			}
3562 		}
3563 	}
3564 
3565 	_action._inProgress = false;
3566 }
3567 
3568 /*------------------------------------------------------------------------*/
3569 
Scene320(MADSEngine * vm)3570 Scene320::Scene320(MADSEngine *vm) : Scene300s(vm) {
3571 	_blinkFl = false;
3572 	_flippedFl = false;
3573 
3574 	_buttonId = -1;
3575 	_lastFrame = -1;
3576 	_leftItemId = -1;
3577 	_posX = -1;
3578 	_rightItemId = -1;
3579 }
3580 
synchronize(Common::Serializer & s)3581 void Scene320::synchronize(Common::Serializer &s) {
3582 	Scene3xx::synchronize(s);
3583 
3584 	s.syncAsByte(_blinkFl);
3585 	s.syncAsByte(_flippedFl);
3586 
3587 	s.syncAsSint32LE(_buttonId);
3588 	s.syncAsSint32LE(_lastFrame);
3589 	s.syncAsSint32LE(_leftItemId);
3590 	s.syncAsSint32LE(_posX);
3591 	s.syncAsSint32LE(_rightItemId);
3592 }
3593 
setup()3594 void Scene320::setup() {
3595 	setPlayerSpritesPrefix();
3596 	setAAName();
3597 }
3598 
setRightView(int view)3599 void Scene320::setRightView(int view) {
3600 	if (_rightItemId < 8) _scene->_sequences.remove(_globals._sequenceIndexes[10]);
3601 
3602 	int spriteNum;
3603 	switch (view) {
3604 	case 0:
3605 		spriteNum = 16;
3606 		break;
3607 
3608 	case 1:
3609 		spriteNum = 14;
3610 		break;
3611 
3612 	case 2:
3613 		spriteNum = 17;
3614 		break;
3615 
3616 	case 3:
3617 		spriteNum = 15;
3618 		break;
3619 
3620 	default:
3621 		spriteNum = view + 6;
3622 		break;
3623 	}
3624 
3625 	if (view != 8) {
3626 		_globals._sequenceIndexes[10] = _scene->_sequences.startCycle(_globals._spriteIndexes[spriteNum], false, 1);
3627 		_scene->_sequences.setDepth(_globals._sequenceIndexes[10], 0);
3628 	}
3629 
3630 	_globals[kRightView320] = _rightItemId = view;
3631 }
3632 
setLeftView(int view)3633 void Scene320::setLeftView(int view) {
3634 	if (_leftItemId < 10)
3635 		_scene->_sequences.remove(_globals._sequenceIndexes[0]);
3636 
3637 	if (view != 10) {
3638 		_globals._sequenceIndexes[0] = _scene->_sequences.addReverseSpriteCycle(_globals._spriteIndexes[view], false, 6, 0, 0, 18);
3639 		_scene->_sequences.setDepth(_globals._sequenceIndexes[0], 0);
3640 		if (!_blinkFl)
3641 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[0], 2, 2);
3642 	}
3643 
3644 	_leftItemId = view;
3645 }
3646 
handleButtons()3647 void Scene320::handleButtons() {
3648 	switch(_action._activeAction._objectNameId) {
3649 	case 0x2DD:
3650 		_buttonId = 5;
3651 		break;
3652 
3653 	case 0x2DE:
3654 		_buttonId = 4;
3655 		break;
3656 
3657 	case 0x2E0:
3658 		_buttonId = 6;
3659 		break;
3660 
3661 	case 0x2E1:
3662 		_buttonId = 7;
3663 		break;
3664 
3665 	case 0x2E2:
3666 		_buttonId = 8;
3667 		break;
3668 
3669 	case 0x2E3:
3670 		_buttonId = 9;
3671 		break;
3672 
3673 	case 0x2E4:
3674 		_buttonId = 10;
3675 		break;
3676 
3677 	case 0x2E5:
3678 		_buttonId = 11;
3679 		break;
3680 
3681 	case 0x2E6:
3682 		_buttonId = 12;
3683 		break;
3684 
3685 	case 0x2E7:
3686 		_buttonId = 13;
3687 		break;
3688 
3689 	case 0x2E8:
3690 		_buttonId = 0;
3691 		break;
3692 
3693 	case 0x2E9:
3694 		_buttonId = 1;
3695 		break;
3696 
3697 	case 0x2EA:
3698 		_buttonId = 2;
3699 		break;
3700 
3701 	case 0x2EB:
3702 		_buttonId = 3;
3703 		break;
3704 
3705 	default:
3706 		break;
3707 	}
3708 
3709 	if (_buttonId <= 3) {
3710 		_posX = (8 * _buttonId) - 2;
3711 		_flippedFl = true;
3712 	} else if (_buttonId <= 5) {
3713 		_posX = (13 * _buttonId) - 14;
3714 		_flippedFl = true;
3715 	} else {
3716 		_posX = (8 * _buttonId) + 98;
3717 		_flippedFl = false;
3718 	}
3719 }
3720 
enter()3721 void Scene320::enter() {
3722 	_blinkFl = true;
3723 	_rightItemId = 8;
3724 	_leftItemId = 10;
3725 	_lastFrame = 0;
3726 
3727 	for (int i = 0; i < 10; i++)
3728 		_globals._spriteIndexes[i] = _scene->_sprites.addSprites(formAnimName('M', i));
3729 
3730 	for (int i = 0; i < 8; i++)
3731 		_globals._spriteIndexes[10 + i] = _scene->_sprites.addSprites(formAnimName('N', i));
3732 
3733 	_globals._spriteIndexes[18] = _scene->_sprites.addSprites("*REXHAND");
3734 	_game._player._visible = false;
3735 
3736 	setRightView(_globals[kRightView320]);
3737 	setLeftView(0);
3738 
3739 	_vm->_palette->setEntry(252, 63, 30, 20);
3740 	_vm->_palette->setEntry(253, 45, 15, 10);
3741 
3742 	sceneEntrySound();
3743 }
3744 
step()3745 void Scene320::step() {
3746 	if (_scene->_animation[0] != nullptr) {
3747 		if (_lastFrame != _scene->_animation[0]->getCurrentFrame()) {
3748 			_lastFrame = _scene->_animation[0]->getCurrentFrame();
3749 			switch (_lastFrame) {
3750 			case 95:
3751 				_blinkFl = true;
3752 				setLeftView(9);
3753 				_vm->_sound->command(41);
3754 				break;
3755 
3756 			case 139:
3757 				_blinkFl = false;
3758 				setLeftView(9);
3759 				break;
3760 
3761 			case 191:
3762 				_scene->_kernelMessages.add(Common::Point(1, 1), 0xFDFC, 0, 0, 60, _game.getQuote(0xFE));
3763 				break;
3764 
3765 			case 417:
3766 			case 457:
3767 				_vm->_screen->_shakeCountdown = 40;
3768 				_vm->_sound->command(59);
3769 				break;
3770 
3771 			case 430:
3772 				_blinkFl = true;
3773 				setLeftView(4);
3774 				break;
3775 
3776 			default:
3777 				break;
3778 			}
3779 		}
3780 	}
3781 
3782 	if (_game._trigger == 70) {
3783 		_globals[kAfterHavoc] = true;
3784 		_globals[kTeleporterRoom + 1] = 351;
3785 		_scene->_nextSceneId = 361;
3786 	}
3787 }
3788 
actions()3789 void Scene320::actions() {
3790 	if (_action._lookFlag)
3791 		_vm->_dialogs->show(32011);
3792 	else if ((_action.isAction(VERB_PRESS) || _action.isAction(VERB_PUSH)) &&
3793 		(_action.isObject(NOUN_LEFT_1_KEY) || _action.isObject(NOUN_LEFT_2_KEY) || _action.isObject(NOUN_LEFT_3_KEY) || _action.isObject(NOUN_LEFT_4_KEY) ||
3794 		 _action.isObject(NOUN_GREEN_BUTTON) || _action.isObject(NOUN_RED_BUTTON) || _action.isObject(NOUN_RIGHT_1_KEY) || _action.isObject(NOUN_RIGHT_2_KEY) ||
3795 		 _action.isObject(NOUN_RIGHT_3_KEY) || _action.isObject(NOUN_RIGHT_4_KEY) || _action.isObject(NOUN_RIGHT_5_KEY) || _action.isObject(NOUN_RIGHT_6_KEY) ||
3796 		 _action.isObject(NOUN_RIGHT_7_KEY) || _action.isObject(NOUN_RIGHT_8_KEY)
3797 		)) {
3798 		switch (_game._trigger) {
3799 		case 0:
3800 			_game._player._stepEnabled = false;
3801 			handleButtons();
3802 			_globals._sequenceIndexes[18] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[18], _flippedFl, 4, 2, 0, 0);
3803 			_scene->_sequences.setScale(_globals._sequenceIndexes[18], 60);
3804 			_scene->_sequences.setPosition(_globals._sequenceIndexes[18], Common::Point(_posX, 170));
3805 			_scene->_sequences.setDepth(_globals._sequenceIndexes[18], 0);
3806 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[18], SEQUENCE_TRIGGER_LOOP, 0, 1);
3807 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[18], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
3808 			break;
3809 
3810 		case 1:
3811 			if (_buttonId >= 6) {
3812 				_vm->_sound->command(60);
3813 				setRightView(_buttonId - 6);
3814 			}
3815 			if (_buttonId == 4) {
3816 				_vm->_sound->command(38);
3817 				if (_leftItemId == 3)
3818 					setLeftView(0);
3819 				else
3820 					setLeftView(3);
3821 			}
3822 			if (_buttonId == 5) {
3823 				_vm->_sound->command(38);
3824 				if (_leftItemId == 1)
3825 					setLeftView(2);
3826 				else
3827 					setLeftView(1);
3828 			}
3829 			if (_buttonId <= 3) {
3830 				_vm->_sound->command(60);
3831 				setLeftView(_buttonId + 5);
3832 			}
3833 			break;
3834 
3835 		case 2:
3836 			_game._player._stepEnabled = true;
3837 			if (_buttonId == 5) {
3838 				if (_leftItemId == 2) {
3839 					_game._player._stepEnabled = false;
3840 					setRightView(8);
3841 					setLeftView(10);
3842 					_scene->_kernelMessages.reset();
3843 					_scene->resetScene();
3844 					_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('m', 2));
3845 					_globals._spriteIndexes[4] = _scene->_sprites.addSprites(formAnimName('m', 4));
3846 					_globals._spriteIndexes[9] = _scene->_sprites.addSprites(formAnimName('m', 9));
3847 					_blinkFl = false;
3848 					setLeftView(2);
3849 					_game.loadQuoteSet(0xFE, 0);
3850 					_game._triggerSetupMode = SEQUENCE_TRIGGER_DAEMON;
3851 					_scene->loadAnimation(formAnimName('a', -1), 70);
3852 					_vm->_sound->command(17);
3853 				}
3854 			}
3855 			break;
3856 
3857 		default:
3858 			break;
3859 		}
3860 	} else if (_action.isAction(VERB_LEAVE, NOUN_SECURITY_STATION))
3861 		_scene->_nextSceneId = 311;
3862 	else if (_action.isAction(VERB_LOOK, NOUN_RIGHT_MONITOR))
3863 		_vm->_dialogs->show(32001);
3864 	else if (_action.isAction(VERB_LOOK, NOUN_LEFT_MONITOR))
3865 		_vm->_dialogs->show(32002);
3866 	else if (_action.isAction(VERB_LOOK, NOUN_DESK))
3867 		_vm->_dialogs->show(32003);
3868 	else if (_action.isAction(VERB_LOOK, NOUN_SECURITY_STATION))
3869 		_vm->_dialogs->show(32004);
3870 	else if (_action.isAction(VERB_LOOK, NOUN_MUG))
3871 		_vm->_dialogs->show(32005);
3872 	else if (_action.isAction(VERB_LOOK, NOUN_DOUGHNUT))
3873 		_vm->_dialogs->show(32006);
3874 	else if (_action.isAction(VERB_LOOK, NOUN_MAGAZINE))
3875 		_vm->_dialogs->show(32007);
3876 	else if (_action.isAction(VERB_LOOK, NOUN_PAPER_FOOTBALL))
3877 		_vm->_dialogs->show(32008);
3878 	else if (_action.isAction(VERB_LOOK, NOUN_NEWSPAPER))
3879 		_vm->_dialogs->show(32009);
3880 	else if (_action.isAction(VERB_LOOK, NOUN_CLIPBOARD))
3881 		_vm->_dialogs->show(32010);
3882 	else if (_action.isAction(VERB_TAKE, NOUN_MUG))
3883 		_vm->_dialogs->show(32012);
3884 	else if (_action.isAction(VERB_TAKE, NOUN_CLIPBOARD))
3885 		_vm->_dialogs->show(32013);
3886 	else if (_action.isAction(VERB_TAKE, NOUN_DOUGHNUT) || _action.isAction(VERB_EAT, NOUN_DOUGHNUT))
3887 		_vm->_dialogs->show(32014);
3888 	else if (_action.isAction(VERB_TAKE, NOUN_PAPER_FOOTBALL))
3889 		_vm->_dialogs->show(32015);
3890 	else if (_action.isAction(VERB_TAKE, NOUN_MAGAZINE))
3891 		_vm->_dialogs->show(32016);
3892 	else if (_action.isAction(VERB_TAKE, NOUN_NEWSPAPER))
3893 		_vm->_dialogs->show(32017);
3894 	else
3895 		return;
3896 
3897 	_action._inProgress = false;
3898 }
3899 
3900 /*------------------------------------------------------------------------*/
3901 
setup()3902 void Scene321::setup() {
3903 	setPlayerSpritesPrefix();
3904 	setAAName();
3905 }
3906 
enter()3907 void Scene321::enter() {
3908 	_game._player._visible = false;
3909 	_game._player._stepEnabled = false;
3910 
3911 	_scene->_userInterface.emptyConversationList();
3912 	_scene->_userInterface.setup(kInputConversation);
3913 
3914 	int suffixNum;
3915 	if (_globals[kSexOfRex] == REX_FEMALE) {
3916 		_globals[kSexOfRex] = REX_MALE;
3917 		suffixNum = 1;
3918 	} else {
3919 		_globals[kSexOfRex] = REX_FEMALE;
3920 		suffixNum = _game._visitedScenes._sceneRevisited ? 2 : 0;
3921 	}
3922 
3923 	_scene->loadAnimation(formAnimName('g', suffixNum), 60);
3924 	sceneEntrySound();
3925 }
3926 
step()3927 void Scene321::step() {
3928 	if (_scene->_animation[0] != nullptr) {
3929 		if ((_scene->_animation[0]->getCurrentFrame() >= 260) && (_globals[kSexOfRex] == REX_MALE) && (_game._storyMode >= STORYMODE_NICE))
3930 			_scene->_nextSceneId = 316;
3931 	}
3932 
3933 	if (_game._trigger == 60)
3934 		_scene->_nextSceneId = 316;
3935 }
3936 
3937 /*------------------------------------------------------------------------*/
3938 
setup()3939 void Scene322::setup() {
3940 	_game._player._spritesPrefix = "";
3941 	// The original is calling scene3xx_setAAName()
3942 	_game._aaName = Resources::formatAAName(4);
3943 }
3944 
enter()3945 void Scene322::enter() {
3946 	if (_globals[kSexOfRex] == REX_MALE)
3947 		_handSpriteId = _scene->_sprites.addSprites("*REXHAND");
3948 	else
3949 		_handSpriteId = _scene->_sprites.addSprites("*ROXHAND");
3950 
3951 	teleporterEnter();
3952 
3953 	// The original is using scene3xx_sceneEntrySound()
3954 	if (!_vm->_musicFlag)
3955 		_vm->_sound->command(2);
3956 	else
3957 		_vm->_sound->command(10);
3958 }
3959 
step()3960 void Scene322::step() {
3961 	teleporterStep();
3962 }
3963 
actions()3964 void Scene322::actions() {
3965 	if (_action._lookFlag) {
3966 		_vm->_dialogs->show(32214);
3967 		_action._inProgress = false;
3968 		return;
3969 	}
3970 
3971 	if (teleporterActions()) {
3972 		_action._inProgress = false;
3973 		return;
3974 	}
3975 
3976 	if (_action.isAction(VERB_LOOK, NOUN_VIEWPORT) || _action.isAction(VERB_PEER_THROUGH, NOUN_VIEWPORT))
3977 		_vm->_dialogs->show(32210);
3978 	else if (_action.isAction(VERB_LOOK, NOUN_KEYPAD))
3979 		_vm->_dialogs->show(32211);
3980 	else if (_action.isAction(VERB_LOOK, NOUN_DISPLAY))
3981 		_vm->_dialogs->show(32212);
3982 	else if (_action.isAction(VERB_LOOK, NOUN_0_KEY) || _action.isAction(VERB_LOOK, NOUN_1_KEY)
3983 	 || _action.isAction(VERB_LOOK, NOUN_2_KEY) || _action.isAction(VERB_LOOK, NOUN_3_KEY)
3984 	 || _action.isAction(VERB_LOOK, NOUN_4_KEY) || _action.isAction(VERB_LOOK, NOUN_5_KEY)
3985 	 || _action.isAction(VERB_LOOK, NOUN_6_KEY) || _action.isAction(VERB_LOOK, NOUN_7_KEY)
3986 	 || _action.isAction(VERB_LOOK, NOUN_8_KEY) || _action.isAction(VERB_LOOK, NOUN_9_KEY)
3987 	 || _action.isAction(VERB_LOOK, NOUN_SMILE_KEY) || _action.isAction(VERB_LOOK, NOUN_ENTER_KEY)
3988 	 || _action.isAction(VERB_LOOK, NOUN_FROWN_KEY))
3989 		_vm->_dialogs->show(32213);
3990 	else if (_action.isAction(VERB_LOOK, NOUN_DEVICE))
3991 		_vm->_dialogs->show(32214);
3992 	else
3993 		return;
3994 
3995 	_action._inProgress = false;
3996 }
3997 
3998 /*------------------------------------------------------------------------*/
3999 
setup()4000 void Scene351::setup() {
4001 	if (_scene->_currentSceneId == 391)
4002 		_globals[kSexOfRex] = REX_MALE;
4003 
4004 	setPlayerSpritesPrefix();
4005 	setAAName();
4006 	_scene->addActiveVocab(VERB_WALKTO);
4007 }
4008 
enter()4009 void Scene351::enter() {
4010 	_globals[kAfterHavoc] = -1;
4011 	_globals[kTeleporterRoom + 1] = 351;
4012 
4013 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('c', -1));
4014 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites("*ROXRC_7");
4015 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites("*RXRD_7");
4016 
4017 	if (_game._objects.isInRoom(OBJ_CREDIT_CHIP)) {
4018 		_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 6, 0, 0, 0);
4019 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 4);
4020 	} else
4021 		_scene->_hotspots.activate(NOUN_CREDIT_CHIP, false);
4022 
4023 	if (_scene->_priorSceneId == 352)
4024 		_game._player._playerPos = Common::Point(148, 152);
4025 	else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG) {
4026 		_game._player._playerPos = Common::Point(207, 81);
4027 		_game._player._facing = FACING_NORTH;
4028 	}
4029 
4030 	if (_globals[kTeleporterCommand]) {
4031 		_game._player._visible = false;
4032 		_game._player._stepEnabled = false;
4033 
4034 		char sepChar = 'a';
4035 		if (_globals[kSexOfRex] != REX_MALE)
4036 			sepChar = 'b';
4037 
4038 		int suffixNum = -1;
4039 		int trigger = 0;
4040 
4041 		switch (_globals[kTeleporterCommand]) {
4042 		case 1:
4043 			suffixNum = 0;
4044 			trigger = 60;
4045 			_globals[kTeleporterCommand] = true;
4046 			break;
4047 
4048 		case 2:
4049 			suffixNum = 1;
4050 			trigger = 61;
4051 			break;
4052 
4053 		case 3:
4054 		case 4:
4055 			_game._player._visible = true;
4056 			_game._player._stepEnabled = true;
4057 			_game._player._turnToFacing = FACING_SOUTH;
4058 			suffixNum = -1;
4059 			break;
4060 
4061 		default:
4062 			break;
4063 		}
4064 
4065 		_globals[kTeleporterCommand] = 0;
4066 
4067 		if (suffixNum >= 0)
4068 			_scene->loadAnimation(formAnimName(sepChar, suffixNum), trigger);
4069 	}
4070 
4071 	sceneEntrySound();
4072 }
4073 
step()4074 void Scene351::step() {
4075 	if (_game._trigger == 60) {
4076 		_game._player._stepEnabled = true;
4077 		_game._player._visible = true;
4078 		_game._player._priorTimer = _scene->_frameStartTime - _game._player._ticksAmount;
4079 		_game._player._turnToFacing = FACING_SOUTH;
4080 	}
4081 
4082 	if (_game._trigger == 61) {
4083 		_globals[kTeleporterCommand] = 1;
4084 		_scene->_nextSceneId = _globals[kTeleporterDestination];
4085 		_scene->_reloadSceneFlag = true;
4086 	}
4087 }
4088 
actions()4089 void Scene351::actions() {
4090 	if (_action._lookFlag)
4091 		_vm->_dialogs->show(35121);
4092 	else if (_action.isAction(VERB_STEP_INTO, NOUN_TELEPORTER))
4093 		_scene->_nextSceneId = 322;
4094 	else if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_SOUTH))
4095 		_scene->_nextSceneId = 352;
4096 	else if (_action.isAction(VERB_TAKE, NOUN_CREDIT_CHIP)) {
4097 		if (_game._trigger || !_game._objects.isInInventory(OBJ_CREDIT_CHIP)) {
4098 			switch (_game._trigger) {
4099 			case 0:
4100 				_game._player._stepEnabled = false;
4101 				_game._player._visible = false;
4102 				if (_globals[kSexOfRex] == REX_FEMALE) {
4103 					_globals._sequenceIndexes[2] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[2], false, 5, 2, 0, 0);
4104 					_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
4105 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_SPRITE, 5, 1);
4106 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4107 				} else {
4108 					_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 5, 2, 0, 0);
4109 					_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
4110 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_SPRITE, 6, 1);
4111 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4112 				}
4113 				break;
4114 
4115 			case 1:
4116 				_scene->_hotspots.activate(NOUN_CREDIT_CHIP, false);
4117 				_scene->_sequences.remove(_globals._sequenceIndexes[1]);
4118 				_game._objects.addToInventory(OBJ_CREDIT_CHIP);
4119 				break;
4120 
4121 			case 2:
4122 				_game._player._visible = true;
4123 				_game._player._stepEnabled = true;
4124 				_vm->_dialogs->showItem(OBJ_CREDIT_CHIP, 0x32F);
4125 				break;
4126 
4127 			default:
4128 				break;
4129 			}
4130 		}
4131 	} else if (_action.isAction(VERB_LOOK, NOUN_VIEW_SCREEN))
4132 		_vm->_dialogs->show(35110);
4133 	else if (_action.isAction(VERB_LOOK, NOUN_RIP_IN_FLOOR))
4134 		_vm->_dialogs->show(35111);
4135 	else if (_action.isAction(VERB_LOOK, NOUN_FIRE_HYDRANT))
4136 		_vm->_dialogs->show(35112);
4137 	else if (_action.isAction(VERB_LOOK, NOUN_GUARD)) {
4138 		if (_game._objects[0xF]._roomNumber == 351)
4139 			_vm->_dialogs->show(35114);
4140 		else
4141 			_vm->_dialogs->show(35113);
4142 	} else if (_action.isAction(VERB_LOOK, NOUN_EQUIPMENT))
4143 		_vm->_dialogs->show(35115);
4144 	else if (_action.isAction(VERB_LOOK, NOUN_DESK))
4145 		_vm->_dialogs->show(35116);
4146 	else if (_action.isAction(VERB_LOOK, NOUN_MACHINE))
4147 		_vm->_dialogs->show(35117);
4148 	else if (_action.isAction(VERB_LOOK, NOUN_TELEPORTER))
4149 		_vm->_dialogs->show(35118);
4150 	else if (_action.isAction(VERB_LOOK, NOUN_CONTROL_PANEL))
4151 		_vm->_dialogs->show(35119);
4152 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_SOUTH))
4153 		_vm->_dialogs->show(35120);
4154 	else if (_action.isAction(VERB_LOOK, NOUN_POLE))
4155 		_vm->_dialogs->show(35122);
4156 	else
4157 		return;
4158 
4159 	_action._inProgress = false;
4160 }
4161 
4162 /*------------------------------------------------------------------------*/
4163 
Scene352(MADSEngine * vm)4164 Scene352::Scene352(MADSEngine *vm) : Scene3xx(vm) {
4165 	_vaultOpenFl = false;
4166 	_mustPutArmDownFl = false;
4167 	_leaveRoomFl = false;
4168 
4169 	_tapePlayerHotspotIdx = -1;
4170 	_hotspot1Idx = -1;
4171 	_hotspot2Idx = -1;
4172 	_lampHostpotIdx = -1;
4173 	_commonSequenceIdx = -1;
4174 	_commonSpriteIndex = -1;
4175 }
4176 
synchronize(Common::Serializer & s)4177 void Scene352::synchronize(Common::Serializer &s) {
4178 	Scene3xx::synchronize(s);
4179 
4180 	s.syncAsByte(_vaultOpenFl);
4181 	s.syncAsByte(_mustPutArmDownFl);
4182 	s.syncAsByte(_leaveRoomFl);
4183 
4184 	s.syncAsSint32LE(_tapePlayerHotspotIdx);
4185 	s.syncAsSint32LE(_hotspot1Idx);
4186 	s.syncAsSint32LE(_hotspot2Idx);
4187 	s.syncAsSint32LE(_lampHostpotIdx);
4188 	s.syncAsSint32LE(_commonSequenceIdx);
4189 	s.syncAsSint32LE(_commonSpriteIndex);
4190 }
4191 
setup()4192 void Scene352::setup() {
4193 	setPlayerSpritesPrefix();
4194 	setAAName();
4195 
4196 	_scene->addActiveVocab(VERB_WALKTO);
4197 	_scene->addActiveVocab(NOUN_YOUR_STUFF);
4198 	_scene->addActiveVocab(NOUN_OTHER_STUFF);
4199 	_scene->addActiveVocab(NOUN_LAMP);
4200 }
4201 
putArmDown(bool corridorExit,bool doorwayExit)4202 void Scene352::putArmDown(bool corridorExit, bool doorwayExit) {
4203 	switch (_game._trigger) {
4204 	case 0:
4205 		_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 0, 120, _game.getQuote(0xFF));
4206 		_scene->_sequences.addTimer(48, 1);
4207 		break;
4208 
4209 	case 1:
4210 		_game._player._stepEnabled = false;
4211 		_game._player._visible = false;
4212 		if (_globals[kSexOfRex] == REX_FEMALE) {
4213 			_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 5, 2, 0, 0);
4214 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
4215 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_SPRITE, 5, 2);
4216 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
4217 		} else {
4218 			_globals._sequenceIndexes[4] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[4], false, 5, 2, 0, 0);
4219 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
4220 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_SPRITE, 6, 2);
4221 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
4222 		}
4223 		break;
4224 
4225 	case 2: {
4226 		_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 6, 0, 0, 0);
4227 		int idx = _scene->_dynamicHotspots.add(NOUN_GUARDS_ARM2, VERB_WALKTO, _globals._sequenceIndexes[2], Common::Rect(0, 0, 0, 0));
4228 		_scene->_dynamicHotspots.setPosition(idx, Common::Point(230, 117), FACING_NORTHWEST);
4229 		_scene->changeVariant(0);
4230 		}
4231 		break;
4232 
4233 	case 3:
4234 		_scene->_kernelMessages.reset();
4235 		_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 0, 120, _game.getQuote(0x100));
4236 		_game._objects.setRoom(OBJ_GUARDS_ARM, _scene->_currentSceneId);
4237 		_game._player._visible = true;
4238 		if (corridorExit)
4239 			_scene->_sequences.addTimer(48, 6);
4240 		else if (doorwayExit)
4241 			_scene->_sequences.addTimer(48, 4);
4242 		else {
4243 			_mustPutArmDownFl = false;
4244 			_game._player._stepEnabled = true;
4245 		}
4246 		break;
4247 
4248 	case 4:
4249 		_game._player.walk(Common::Point(116, 107), FACING_NORTH);
4250 		_mustPutArmDownFl = false;
4251 		_scene->_sequences.addTimer(180, 5);
4252 		_leaveRoomFl = true;
4253 		break;
4254 
4255 	case 5:
4256 		if (_leaveRoomFl)
4257 			_scene->_nextSceneId = 351;
4258 
4259 		break;
4260 
4261 	case 6:
4262 		_game._player.walk(Common::Point(171, 152), FACING_SOUTH);
4263 		_game._player._stepEnabled = true;
4264 		_mustPutArmDownFl = false;
4265 		_scene->_sequences.addTimer(180, 7);
4266 		_leaveRoomFl = true;
4267 		break;
4268 
4269 	case 7:
4270 		if (_leaveRoomFl)
4271 			_scene->_nextSceneId = 353;
4272 
4273 		break;
4274 
4275 	default:
4276 		break;
4277 	}
4278 }
4279 
enter()4280 void Scene352::enter() {
4281 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites("*RM302x0");
4282 	_globals._spriteIndexes[13] = _scene->_sprites.addSprites("*RM302x2");
4283 	_globals._spriteIndexes[12] = _scene->_sprites.addSprites("*RM302x3");
4284 	_globals._spriteIndexes[2] = _scene->_sprites.addSprites(formAnimName('g', -1));
4285 	_globals._spriteIndexes[5] = _scene->_sprites.addSprites(formAnimName('b', -1));
4286 
4287 
4288 	if (_globals[kSexOfRex] == REX_FEMALE) {
4289 		_globals._spriteIndexes[3] = _scene->_sprites.addSprites("*ROXRC_7");
4290 		_globals._spriteIndexes[7] = _scene->_sprites.addSprites("*ROXRC_6");
4291 		_globals._spriteIndexes[15] = _scene->_sprites.addSprites("*ROXRC_9");
4292 		_globals._spriteIndexes[11] = _scene->_sprites.addSprites(formAnimName('a', 3));
4293 		_globals._spriteIndexes[9] = _scene->_sprites.addSprites(formAnimName('a', 2));
4294 	} else {
4295 		_globals._spriteIndexes[4] = _scene->_sprites.addSprites("*RXRD_7");
4296 		_globals._spriteIndexes[6] = _scene->_sprites.addSprites("*RXRC_6");
4297 		_globals._spriteIndexes[14] = _scene->_sprites.addSprites("*RXMRC_9");
4298 		_globals._spriteIndexes[10] = _scene->_sprites.addSprites(formAnimName('a', 1));
4299 		_globals._spriteIndexes[8] = _scene->_sprites.addSprites(formAnimName('a', 0));
4300 	}
4301 
4302 	_leaveRoomFl = false;
4303 
4304 	if (_game._objects.isInRoom(OBJ_TAPE_PLAYER)) {
4305 		_globals._sequenceIndexes[5] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[5], false, 12, 0, 0, 0);
4306 		_scene->_sequences.setDepth(_globals._sequenceIndexes[5], 5);
4307 		int idx = _scene->_dynamicHotspots.add(NOUN_TAPE_PLAYER, VERB_WALKTO, _globals._sequenceIndexes[5], Common::Rect(0, 0, 0, 0));
4308 		_tapePlayerHotspotIdx = _scene->_dynamicHotspots.setPosition(idx, Common::Point(84, 145), FACING_WEST);
4309 	}
4310 
4311 	_vaultOpenFl = false;
4312 
4313 	if (_scene->_priorSceneId != RETURNING_FROM_DIALOG) {
4314 		_mustPutArmDownFl = false;
4315 		if (!_game._visitedScenes._sceneRevisited)
4316 			_globals[kHaveYourStuff] = false;
4317 	}
4318 
4319 	if (_game._objects.isInRoom(OBJ_GUARDS_ARM)) {
4320 		_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 6, 0, 0, 0);
4321 		int idx = _scene->_dynamicHotspots.add(NOUN_GUARDS_ARM2, VERB_WALKTO, _globals._sequenceIndexes[2], Common::Rect(0, 0, 0, 0));
4322 		_scene->_dynamicHotspots.setPosition(idx, Common::Point(230, 117), FACING_NORTHWEST);
4323 	} else
4324 		_mustPutArmDownFl = true;
4325 
4326 	if (_scene->_priorSceneId == 353)
4327 		_game._player._playerPos = Common::Point(171, 155);
4328 	else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG)
4329 		_game._player._playerPos = Common::Point(116, 107);
4330 
4331 	sceneEntrySound();
4332 
4333 	_game.loadQuoteSet(0xFF, 0x100, 0x101, 0x102, 0x103, 0);
4334 }
4335 
preActions()4336 void Scene352::preActions() {
4337 	_leaveRoomFl = false;
4338 
4339 	if (_action.isAction(VERB_OPEN, NOUN_VAULT))
4340 		_game._player.walk(Common::Point(266, 111), FACING_NORTHEAST);
4341 
4342 	if (_vaultOpenFl && !_action.isObject(NOUN_VAULT) && !_action.isObject(NOUN_LAMP) && !_action.isObject(NOUN_OTHER_STUFF) && !_action.isObject(NOUN_YOUR_STUFF)) {
4343 		if (_globals[kHaveYourStuff]) {
4344 			_commonSpriteIndex = _globals._spriteIndexes[13];
4345 			_commonSequenceIdx = _globals._sequenceIndexes[13];
4346 		} else {
4347 			_commonSpriteIndex = _globals._spriteIndexes[1];
4348 			_commonSequenceIdx = _globals._sequenceIndexes[1];
4349 		}
4350 
4351 		switch (_game._trigger) {
4352 		case 0:
4353 			if (_game._player._needToWalk) {
4354 				_game._player._stepEnabled = false;
4355 				_scene->_sequences.remove(_commonSequenceIdx);
4356 				_vm->_sound->command(20);
4357 				_commonSequenceIdx = _scene->_sequences.addReverseSpriteCycle(_commonSpriteIndex, false, 6, 1, 0, 0);
4358 				_scene->_sequences.addSubEntry(_commonSequenceIdx, SEQUENCE_TRIGGER_EXPIRE, 0, 1);
4359 				_scene->_sequences.setDepth(_commonSequenceIdx, 15);
4360 			}
4361 			break;
4362 
4363 		case 1:
4364 			if (!_globals[kHaveYourStuff])
4365 				_scene->_dynamicHotspots.remove(_hotspot2Idx);
4366 
4367 			_scene->_dynamicHotspots.remove(_hotspot1Idx);
4368 			_scene->_dynamicHotspots.remove(_lampHostpotIdx);
4369 			_vaultOpenFl = false;
4370 			_game._player._stepEnabled = true;
4371 			break;
4372 
4373 		default:
4374 			break;
4375 		}
4376 	}
4377 
4378 	if (_action.isAction(VERB_PUT, NOUN_GUARDS_ARM2, NOUN_SCANNER)) {
4379 		if (_globals[kSexOfRex] == REX_MALE)
4380 			_game._player.walk(Common::Point(269, 111), FACING_NORTHEAST);
4381 		else
4382 			_game._player.walk(Common::Point(271, 111), FACING_NORTHEAST);
4383 	}
4384 
4385 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_DOORWAY) || _action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_SOUTH) || _action.isAction(VERB_PUT, NOUN_GUARDS_ARM2, NOUN_FLOOR)) {
4386 		if (_game._objects.isInInventory(OBJ_GUARDS_ARM))
4387 			_game._player.walk(Common::Point(230, 117), FACING_NORTHWEST);
4388 	}
4389 }
4390 
actions()4391 void Scene352::actions() {
4392 	if (_action._lookFlag) {
4393 		_vm->_dialogs->show(35225);
4394 		_action._inProgress = false;
4395 		return;
4396 	}
4397 
4398 	if (_action.isAction(VERB_OPEN, NOUN_VAULT)) {
4399 		if (!_vaultOpenFl) {
4400 			switch (_game._trigger) {
4401 			case 0:
4402 				_game._player._stepEnabled = false;
4403 				_game._player._visible = false;
4404 				if (_globals[kSexOfRex] == REX_FEMALE)
4405 					_commonSpriteIndex = _globals._spriteIndexes[9];
4406 				else
4407 					_commonSpriteIndex = _globals._spriteIndexes[8];
4408 
4409 				_commonSequenceIdx = _scene->_sequences.addSpriteCycle(_commonSpriteIndex, false, 8, 1, 0, 0);
4410 				_scene->_sequences.updateTimeout(_commonSequenceIdx, -1);
4411 				_scene->_sequences.addSubEntry(_commonSequenceIdx, SEQUENCE_TRIGGER_EXPIRE, 0, 1);
4412 				break;
4413 
4414 			case 1: {
4415 				_vm->_sound->command(21);
4416 				_globals._sequenceIndexes[12] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[12], false, 7, 2, 20, 0);
4417 				_scene->_sequences.setDepth(_globals._sequenceIndexes[12], FACING_NORTH);
4418 				int oldIdx = _commonSequenceIdx;
4419 				_commonSequenceIdx = _scene->_sequences.startCycle(_commonSpriteIndex, false, -2);
4420 				_scene->_sequences.updateTimeout(_commonSequenceIdx, oldIdx);
4421 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[12], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4422 				}
4423 				break;
4424 
4425 			case 2:
4426 				_vm->_sound->command(22);
4427 				_scene->_sequences.remove(_commonSequenceIdx);
4428 				_commonSequenceIdx = _scene->_sequences.startPingPongCycle(_commonSpriteIndex, false, 8, 1, 0, 0);
4429 				_scene->_sequences.setAnimRange(_commonSequenceIdx, 1, 3);
4430 				_scene->_sequences.addSubEntry(_commonSequenceIdx, SEQUENCE_TRIGGER_EXPIRE, 0, 3);
4431 				break;
4432 
4433 			case 3:
4434 				_scene->_sequences.updateTimeout(-1, _commonSequenceIdx);
4435 				_game._player._visible = true;
4436 				_scene->_sequences.addTimer(60, 4);
4437 				break;
4438 
4439 			case 4:
4440 				_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 0, 120, _game.getQuote(0x101));
4441 				_game._player._stepEnabled = true;
4442 				break;
4443 
4444 			default:
4445 				break;
4446 			}
4447 		}
4448 		_action._inProgress = false;
4449 		return;
4450 	}
4451 
4452 	if (_game._objects.isInInventory(OBJ_GUARDS_ARM)) {
4453 		_mustPutArmDownFl = true;
4454 	}
4455 
4456 	bool exit_corridor = false;
4457 	bool exit_doorway = false;
4458 
4459 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_SOUTH)) {
4460 		exit_corridor = true;
4461 	}
4462 
4463 	if (_action.isAction(VERB_WALK_THROUGH, NOUN_DOORWAY)) {
4464 		exit_doorway = true;
4465 	}
4466 
4467 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_SOUTH) || _action.isAction(VERB_WALK_THROUGH, NOUN_DOORWAY) || _action.isAction(VERB_PUT, NOUN_GUARDS_ARM2, NOUN_FLOOR)) {
4468 		if (_mustPutArmDownFl)
4469 			putArmDown(exit_corridor, exit_doorway);
4470 		else if (exit_corridor)
4471 			_scene->_nextSceneId = 353;
4472 		else
4473 			_scene->_nextSceneId = 351;
4474 
4475 		_action._inProgress = false;
4476 		return;
4477 	}
4478 
4479 	if (_action.isAction(VERB_TAKE, NOUN_GUARDS_ARM2)) {
4480 		if (_game._trigger || !_game._objects.isInInventory(OBJ_GUARDS_ARM)) {
4481 			switch (_game._trigger) {
4482 			case 0:
4483 				_game._player._stepEnabled = false;
4484 				_game._player._visible = false;
4485 				if (_globals[kSexOfRex] == REX_FEMALE) {
4486 					_globals._sequenceIndexes[3] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[3], false, 5, 2, 0, 0);
4487 					_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
4488 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_SPRITE, 5, 1);
4489 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4490 				} else {
4491 					_globals._sequenceIndexes[4] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[4], false, 5, 2, 0, 0);
4492 					_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
4493 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_SPRITE, 6, 1);
4494 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4495 				}
4496 				break;
4497 
4498 			case 1:
4499 				_scene->_sequences.remove(_globals._sequenceIndexes[2]);
4500 				_game._objects.addToInventory(OBJ_GUARDS_ARM);
4501 				_scene->changeVariant(1);
4502 				break;
4503 
4504 			case 2:
4505 				_game._player._visible = true;
4506 				_game._player._stepEnabled = true;
4507 				_vm->_dialogs->showItem(OBJ_GUARDS_ARM, 0x899C);
4508 				break;
4509 
4510 			default:
4511 				break;
4512 			}
4513 			_action._inProgress = false;
4514 			return;
4515 		}
4516 	}
4517 
4518 	if (_action.isAction(VERB_PUT, NOUN_GUARDS_ARM2, NOUN_SCANNER)) {
4519 		if (!_vaultOpenFl) {
4520 			switch (_game._trigger) {
4521 			case 0:
4522 				_game._player._stepEnabled = false;
4523 				_game._player._visible = false;
4524 				if (_globals[kSexOfRex] == REX_FEMALE)
4525 					_commonSpriteIndex = _globals._spriteIndexes[11];
4526 				else
4527 					_commonSpriteIndex = _globals._spriteIndexes[10];
4528 
4529 				_commonSequenceIdx = _scene->_sequences.addSpriteCycle(_commonSpriteIndex, false, 8, 1, 0, 0);
4530 				_scene->_sequences.updateTimeout(_commonSequenceIdx, -1);
4531 				_scene->_sequences.addSubEntry(_commonSequenceIdx, SEQUENCE_TRIGGER_EXPIRE, 0, 1);
4532 				break;
4533 
4534 			case 1: {
4535 				_vm->_sound->command(21);
4536 				_globals._sequenceIndexes[12] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[12], false, 7, 2, 20, 0);
4537 				_scene->_sequences.setDepth(_globals._sequenceIndexes[12], 8);
4538 				int oldIdx = _commonSequenceIdx;
4539 				_commonSequenceIdx = _scene->_sequences.startCycle(_commonSpriteIndex, false, -2);
4540 				_scene->_sequences.updateTimeout(_commonSequenceIdx, oldIdx);
4541 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[12], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4542 				}
4543 				break;
4544 
4545 			case 2:
4546 				_vm->_sound->command(23);
4547 				_scene->_sequences.remove(_commonSequenceIdx);
4548 				_commonSequenceIdx = _scene->_sequences.addReverseSpriteCycle(_commonSpriteIndex, false, 8, 1, 0, 0);
4549 				_scene->_sequences.setAnimRange(_commonSequenceIdx, 1, 4);
4550 				_scene->_sequences.addSubEntry(_commonSequenceIdx, SEQUENCE_TRIGGER_EXPIRE, 0, 3);
4551 				break;
4552 
4553 
4554 			case 3:
4555 				_scene->_sequences.updateTimeout(-1, _commonSequenceIdx);
4556 				_game._player._visible = true;
4557 				if (_globals[kHaveYourStuff])
4558 					_commonSpriteIndex = _globals._spriteIndexes[13];
4559 				else
4560 					_commonSpriteIndex = _globals._spriteIndexes[1];
4561 
4562 				_vm->_sound->command(20);
4563 				_commonSequenceIdx = _scene->_sequences.addSpriteCycle(_commonSpriteIndex, false, 6, 1, 0, 0);
4564 				_scene->_sequences.setDepth(_commonSequenceIdx, 15);
4565 				_scene->_sequences.addSubEntry(_commonSequenceIdx, SEQUENCE_TRIGGER_EXPIRE, 0, 4);
4566 				break;
4567 
4568 			case 4:
4569 				_commonSequenceIdx = _scene->_sequences.addSpriteCycle(_commonSpriteIndex, false, 6, 0, 0, 0);
4570 				_scene->_sequences.setAnimRange(_commonSequenceIdx, -2, -2);
4571 				_scene->_sequences.setDepth(_commonSequenceIdx, 15);
4572 				_scene->_sequences.addTimer(60, 5);
4573 				break;
4574 
4575 			case 5: {
4576 				_vaultOpenFl = true;
4577 				int idx;
4578 				if (!_globals[kHaveYourStuff]) {
4579 					idx = _scene->_dynamicHotspots.add(NOUN_YOUR_STUFF, VERB_WALKTO, -1, Common::Rect(282, 87, 282 + 13, 87 + 7));
4580 					_hotspot2Idx = _scene->_dynamicHotspots.setPosition(idx, Common::Point(280, 111), FACING_NORTHEAST);
4581 					_globals._sequenceIndexes[1] = _commonSequenceIdx;
4582 					_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 0, 120, _game.getQuote(0x102));
4583 				} else {
4584 					_globals._sequenceIndexes[13] = _commonSequenceIdx;
4585 					_scene->_kernelMessages.add(Common::Point(0, 0), 0x1110, 34, 0, 120, _game.getQuote(0x103));
4586 				}
4587 
4588 				idx = _scene->_dynamicHotspots.add(NOUN_OTHER_STUFF, VERB_WALKTO, -1, Common::Rect(282, 48, 282 + 36, 48 + 27));
4589 				_hotspot1Idx = _scene->_dynamicHotspots.setPosition(idx, Common::Point(287, 115), FACING_NORTHEAST);
4590 				idx = _scene->_dynamicHotspots.add(NOUN_LAMP, VERB_WALKTO, -1, Common::Rect(296, 76, 296 + 11, 76 + 17));
4591 				_lampHostpotIdx = _scene->_dynamicHotspots.setPosition(idx, Common::Point(287, 115), FACING_NORTHEAST);
4592 				_game._player._stepEnabled = true;
4593 				}
4594 				break;
4595 
4596 			default:
4597 				break;
4598 			}
4599 		}
4600 	} else if (_action.isAction(VERB_TAKE, NOUN_YOUR_STUFF)) {
4601 		switch (_game._trigger) {
4602 		case 0:
4603 			_game._player._stepEnabled = false;
4604 			_game._player._visible = false;
4605 			if (_globals[kSexOfRex] == REX_MALE) {
4606 				_globals._sequenceIndexes[14] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[14], false, 8, 1, 0, 0);
4607 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[14], 1, 2);
4608 				_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[14]);
4609 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[14], SEQUENCE_TRIGGER_SPRITE, 2, 1);
4610 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[14], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4611 			} else {
4612 				_globals._sequenceIndexes[15] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[15], false, 8, 1, 0, 0);
4613 				_scene->_sequences.setAnimRange(_globals._sequenceIndexes[15], 1, 2);
4614 				_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[15]);
4615 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[15], SEQUENCE_TRIGGER_SPRITE, 2, 1);
4616 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[15], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4617 			}
4618 			break;
4619 
4620 		case 1:
4621 			_scene->_dynamicHotspots.remove(_hotspot2Idx);
4622 			_globals[kHaveYourStuff] = true;
4623 
4624 			for (uint16 i = 0; i < _game._objects.size(); i++) {
4625 				if (_game._objects[i]._roomNumber == 50)
4626 					_game._objects.addToInventory(i);
4627 			}
4628 
4629 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
4630 			_globals._sequenceIndexes[13] = _scene->_sequences.startCycle(_globals._spriteIndexes[13], false, -2);
4631 			_scene->_sequences.setDepth(_globals._sequenceIndexes[13], 15);
4632 			break;
4633 
4634 		case 2:
4635 			if (_globals[kSexOfRex] == REX_MALE)
4636 				_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[14]);
4637 			else
4638 				_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[15]);
4639 
4640 			_game._player._visible = true;
4641 			_game._player._stepEnabled = true;
4642 			break;
4643 
4644 		default:
4645 			break;
4646 		}
4647 	} else if (_action.isAction(VERB_TAKE, NOUN_TAPE_PLAYER) && !_game._objects.isInInventory(OBJ_TAPE_PLAYER)) {
4648 		switch (_game._trigger) {
4649 		case 0:
4650 			_game._player._stepEnabled = false;
4651 			_game._player._visible = false;
4652 			if (_globals[kSexOfRex] == REX_MALE) {
4653 				_globals._sequenceIndexes[6] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[6], true, 6, 2, 0, 0);
4654 				_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[6]);
4655 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[6], SEQUENCE_TRIGGER_SPRITE, 6, 1);
4656 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[6], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4657 			} else {
4658 				_globals._sequenceIndexes[7] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[7], true, 6, 2, 0, 0);
4659 				_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[7]);
4660 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[7], SEQUENCE_TRIGGER_SPRITE, 6, 1);
4661 				_scene->_sequences.addSubEntry(_globals._sequenceIndexes[7], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
4662 			}
4663 			break;
4664 
4665 		case 1:
4666 			_scene->_sequences.remove(_globals._sequenceIndexes[5]);
4667 			_scene->_dynamicHotspots.remove(_tapePlayerHotspotIdx);
4668 			break;
4669 
4670 		case 2:
4671 			_game._objects.addToInventory(OBJ_TAPE_PLAYER);
4672 			if (_globals[kSexOfRex] == REX_MALE)
4673 				_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[6]);
4674 			else
4675 				_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[7]);
4676 
4677 			_game._player._visible = true;
4678 			_game._player._stepEnabled = true;
4679 			_vm->_dialogs->showItem(OBJ_TAPE_PLAYER, 35227);
4680 			break;
4681 
4682 		default:
4683 			break;
4684 		}
4685 	} else if (_action.isAction(VERB_LOOK, NOUN_SCANNER))
4686 		_vm->_dialogs->show(35210);
4687 	else if (_action.isAction(VERB_LOOK, NOUN_MONITOR)) {
4688 		if (_game._storyMode == STORYMODE_NAUGHTY)
4689 			_vm->_dialogs->show(35211);
4690 		else
4691 			_vm->_dialogs->show(35212);
4692 	} else if (_action.isAction(VERB_LOOK, NOUN_DISPLAY))
4693 		_vm->_dialogs->show(35213);
4694 	else if (_action.isAction(VERB_LOOK, NOUN_STATUE))
4695 		_vm->_dialogs->show(35214);
4696 	else if (_action.isAction(VERB_LOOK, NOUN_TAPE_PLAYER) && (_action._savedFields._mainObjectSource == 4))
4697 		_vm->_dialogs->show(35215);
4698 	else if (_action.isAction(VERB_LOOK, NOUN_AIR_VENT))
4699 		_vm->_dialogs->show(35216);
4700 	else if (_action.isAction(VERB_LOOK, NOUN_GUARDS_ARM2) && (_action._savedFields._mainObjectSource == 4))
4701 		_vm->_dialogs->show(35217);
4702 	else if (_action.isAction(VERB_LOOK, NOUN_IRONING_BOARD))
4703 		_vm->_dialogs->show(35218);
4704 	else if (_action.isAction(VERB_LOOK, NOUN_CLOCK))
4705 		_vm->_dialogs->show(35219);
4706 	else if (_action.isAction(VERB_LOOK, NOUN_GAUGE))
4707 		_vm->_dialogs->show(35220);
4708 	else if (_action.isAction(VERB_LOOK, NOUN_VAULT)) {
4709 		if (!_vaultOpenFl)
4710 			_vm->_dialogs->show(35221);
4711 	} else if (_action.isAction(VERB_LOOK, NOUN_YOUR_STUFF))
4712 		_vm->_dialogs->show(35222);
4713 	else if (_action.isAction(VERB_LOOK, NOUN_OTHER_STUFF))
4714 		_vm->_dialogs->show(35223);
4715 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_SOUTH))
4716 		_vm->_dialogs->show(35224);
4717 	else if (_action.isAction(VERB_TAKE, NOUN_OTHER_STUFF))
4718 		_vm->_dialogs->show(35226);
4719 	else if (_action.isAction(VERB_LOOK, NOUN_DESK))
4720 		_vm->_dialogs->show(35229);
4721 	else if (_action.isAction(VERB_LOOK, NOUN_GUARD))
4722 		_vm->_dialogs->show(35230);
4723 	else if (_action.isAction(VERB_LOOK, NOUN_DOORWAY))
4724 		_vm->_dialogs->show(35231);
4725 	else if (_action.isAction(VERB_LOOK, NOUN_TABLE))
4726 		_vm->_dialogs->show(35232);
4727 	else if (_action.isAction(VERB_LOOK, NOUN_PROJECTOR))
4728 		_vm->_dialogs->show(35233);
4729 	else if (_action.isAction(VERB_LOOK, NOUN_SUPPORT))
4730 		_vm->_dialogs->show(35234);
4731 	else if (_action.isAction(VERB_LOOK, NOUN_SECURITY_MONITOR))
4732 		_vm->_dialogs->show(35235);
4733 	else
4734 		return;
4735 
4736 	_action._inProgress = false;
4737 }
4738 
4739 /*------------------------------------------------------------------------*/
4740 
setup()4741 void Scene353::setup() {
4742 	setPlayerSpritesPrefix();
4743 	setAAName();
4744 }
4745 
enter()4746 void Scene353::enter() {
4747 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(Resources::formatName(303, 'B', 0, EXT_SS, ""));
4748 	_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 5, 0, 5, 0);
4749 	_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
4750 
4751 	if (_scene->_priorSceneId == 352)
4752 		_game._player._playerPos = Common::Point(144, 95);
4753 	else
4754 		_game._player._playerPos = Common::Point(139, 155);
4755 
4756 	sceneEntrySound();
4757 }
4758 
actions()4759 void Scene353::actions() {
4760 	if (_action._lookFlag)
4761 		_vm->_dialogs->show(35315);
4762 	else if (_action.isAction(VERB_WALK_THROUGH, NOUN_DOORWAY))
4763 		_scene->_nextSceneId = 352;
4764 	else if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_SOUTH))
4765 		_scene->_nextSceneId = 354;
4766 	else if (_action.isAction(VERB_LOOK, NOUN_ROCK_CHUNK))
4767 		_vm->_dialogs->show(35310);
4768 	else if (_action.isAction(VERB_LOOK, NOUN_PIPES) || _action.isAction(VERB_LOOK, NOUN_PIPE))
4769 		_vm->_dialogs->show(35311);
4770 	else if (_action.isAction(VERB_LOOK, NOUN_BROKEN_BEAM))
4771 		_vm->_dialogs->show(35312);
4772 	else if (_action.isAction(VERB_LOOK, NOUN_DOORWAY))
4773 		_vm->_dialogs->show(35313);
4774 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_SOUTH))
4775 		_vm->_dialogs->show(35314);
4776 	else if (_action.isAction(VERB_LOOK, NOUN_FLOOR))
4777 		_vm->_dialogs->show(35316);
4778 	else if (_action.isAction(VERB_LOOK, NOUN_CEILING))
4779 		_vm->_dialogs->show(35317);
4780 	else if (_action.isAction(VERB_LOOK, NOUN_WALL))
4781 		_vm->_dialogs->show(35318);
4782 	else
4783 		return;
4784 
4785 	_action._inProgress = false;
4786 }
4787 
4788 /*------------------------------------------------------------------------*/
4789 
setup()4790 void Scene354::setup() {
4791 	setPlayerSpritesPrefix();
4792 	setAAName();
4793 }
4794 
enter()4795 void Scene354::enter() {
4796 	_globals[kAfterHavoc] = true;
4797 	_globals[kTeleporterRoom + 1] = 351;
4798 
4799 	if (_scene->_priorSceneId == 361)
4800 		_game._player._playerPos = Common::Point(231, 110);
4801 	else if (_scene->_priorSceneId == 401) {
4802 		_game._player._playerPos = Common::Point(106, 152);
4803 		_game._player._facing = FACING_NORTH;
4804 	} else if (_scene->_priorSceneId == 316)
4805 		_game._player._playerPos = Common::Point(71, 107);
4806 	else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG)
4807 		_game._player._playerPos = Common::Point(167, 57);
4808 
4809 	sceneEntrySound();
4810 }
4811 
preActions()4812 void Scene354::preActions() {
4813 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_SOUTH))
4814 		_game._player._walkOffScreenSceneId = 401;
4815 }
4816 
actions()4817 void Scene354::actions() {
4818 	if (_action._lookFlag)
4819 		_vm->_dialogs->show(35414);
4820 	else if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_NORTH)) {
4821 		_game._player.startWalking(Common::Point(208, 0), FACING_NORTHEAST);
4822 		_game._player._walkOffScreenSceneId = 353;
4823 	} else if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_EAST))
4824 		_scene->_nextSceneId = 361;
4825 	else if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_WEST))
4826 		_scene->_nextSceneId = 316;
4827 	else if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_SOUTH))
4828 		_scene->_nextSceneId = 401;
4829 	else if (_action.isAction(VERB_LOOK, NOUN_CONTROLS))
4830 		_vm->_dialogs->show(35410);
4831 	else if (_action.isAction(VERB_LOOK, NOUN_SIGNAL))
4832 		_vm->_dialogs->show(35411);
4833 	else if (_action.isAction(VERB_LOOK, NOUN_CATWALK))
4834 		_vm->_dialogs->show(35412);
4835 	else if (_action.isAction(VERB_LOOK, NOUN_AIR_DUCT))
4836 		_vm->_dialogs->show(35413);
4837 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_NORTH))
4838 		_vm->_dialogs->show(35415);
4839 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_SOUTH))
4840 		_vm->_dialogs->show(35416);
4841 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_EAST))
4842 		_vm->_dialogs->show(35417);
4843 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_WEST))
4844 		_vm->_dialogs->show(35418);
4845 	else if (_action.isAction(VERB_LOOK, NOUN_DEBRIS))
4846 		_vm->_dialogs->show(35419);
4847 	else if (_action.isAction(VERB_LOOK, NOUN_GUARD))
4848 		_vm->_dialogs->show(35420);
4849 	else
4850 		return;
4851 
4852 	_action._inProgress = false;
4853 }
4854 
4855 /*------------------------------------------------------------------------*/
4856 
setup()4857 void Scene357::setup() {
4858 	setPlayerSpritesPrefix();
4859 	setAAName();
4860 }
4861 
enter()4862 void Scene357::enter() {
4863 	_globals[kAfterHavoc] = true;
4864 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(Resources::formatName(307, 'X', 0, EXT_SS, ""));
4865 	_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
4866 	_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(127, 78));
4867 	_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
4868 
4869 	if (_scene->_priorSceneId == 318)
4870 		_game._player._playerPos = Common::Point(298, 142);
4871 	else if (_scene->_priorSceneId == 313)
4872 		_game._player._playerPos = Common::Point(127, 101);
4873 	else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG)
4874 		_game._player._playerPos = Common::Point(15, 148);
4875 
4876 	sceneEntrySound();
4877 }
4878 
preActions()4879 void Scene357::preActions() {
4880 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_EAST))
4881 		_game._player._walkOffScreenSceneId = 318;
4882 
4883 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_WEST))
4884 		_game._player._walkOffScreenSceneId = 358;
4885 }
4886 
actions()4887 void Scene357::actions() {
4888 	if (_action._lookFlag)
4889 		_vm->_dialogs->show(35715);
4890 	else if (_action.isAction(VERB_LOOK, NOUN_AIR_VENT))
4891 		_vm->_dialogs->show(35710);
4892 	else if (_action.isAction(VERB_CLIMB_INTO, NOUN_AIR_VENT))
4893 		_vm->_dialogs->show(35711);
4894 	else if (_action.isAction(VERB_LOOK, NOUN_BED))
4895 		_vm->_dialogs->show(35712);
4896 	else if (_action.isAction(VERB_LOOK, NOUN_SINK))
4897 		_vm->_dialogs->show(35713);
4898 	else if (_action.isAction(VERB_LOOK, NOUN_TOILET))
4899 		_vm->_dialogs->show(35714);
4900 	else if (_action.isAction(VERB_LOOK, NOUN_CELL_WALL))
4901 		_vm->_dialogs->show(35716);
4902 	else if (_action.isAction(VERB_LOOK, NOUN_LIGHT))
4903 		_vm->_dialogs->show(35717);
4904 	else if (_action.isAction(VERB_LOOK, NOUN_RIP_IN_FLOOR))
4905 		_vm->_dialogs->show(35718);
4906 	else if (_action.isAction(VERB_LOOK, NOUN_DEBRIS))
4907 		_vm->_dialogs->show(35719);
4908 	else if (_action.isAction(VERB_TAKE, NOUN_DEBRIS))
4909 		_vm->_dialogs->show(35720);
4910 	else if (_action.isAction(VERB_LOOK, NOUN_WALL))
4911 		_vm->_dialogs->show(35721);
4912 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_EAST))
4913 		_vm->_dialogs->show(35722);
4914 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_WEST))
4915 		_vm->_dialogs->show(35723);
4916 	else
4917 		return;
4918 
4919 	_action._inProgress = false;
4920 }
4921 
4922 /*------------------------------------------------------------------------*/
4923 
setup()4924 void Scene358::setup() {
4925 	setPlayerSpritesPrefix();
4926 	setAAName();
4927 }
4928 
enter()4929 void Scene358::enter() {
4930 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(Resources::formatName(307, 'X', 0, EXT_SS, ""));
4931 	_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
4932 	_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(127, 78));
4933 	_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
4934 
4935 	if (_scene->_priorSceneId == 357)
4936 		_game._player._playerPos = Common::Point(305, 142);
4937 	else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG)
4938 		_game._player._playerPos = Common::Point(12, 141);
4939 
4940 	sceneEntrySound();
4941 }
4942 
preActions()4943 void Scene358::preActions() {
4944 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_EAST))
4945 		_game._player._walkOffScreenSceneId = 357;
4946 
4947 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_WEST))
4948 		_game._player._walkOffScreenSceneId = 359;
4949 }
4950 
actions()4951 void Scene358::actions() {
4952 	if (_action._lookFlag)
4953 		_vm->_dialogs->show(35815);
4954 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_WEST))
4955 		_vm->_dialogs->show(35810);
4956 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_EAST))
4957 		_vm->_dialogs->show(35811);
4958 	else if (_action.isAction(VERB_LOOK, NOUN_BED))
4959 		_vm->_dialogs->show(35812);
4960 	else if (_action.isAction(VERB_LOOK, NOUN_SINK))
4961 		_vm->_dialogs->show(35813);
4962 	else if (_action.isAction(VERB_LOOK, NOUN_TOILET))
4963 		_vm->_dialogs->show(35814);
4964 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR) || _action.isAction(VERB_LOOK, NOUN_WALL))
4965 		_vm->_dialogs->show(35816);
4966 	else if (_action.isAction(VERB_LOOK, NOUN_AIR_VENT))
4967 		_vm->_dialogs->show(35817);
4968 	else
4969 		return;
4970 
4971 	_action._inProgress = false;
4972 }
4973 
4974 /*------------------------------------------------------------------------*/
4975 
Scene359(MADSEngine * vm)4976 Scene359::Scene359(MADSEngine *vm) : Scene3xx(vm) {
4977 	_cardHotspotId = -1;
4978 }
4979 
synchronize(Common::Serializer & s)4980 void Scene359::synchronize(Common::Serializer &s) {
4981 	Scene3xx::synchronize(s);
4982 
4983 	s.syncAsSint32LE(_cardHotspotId);
4984 }
4985 
setup()4986 void Scene359::setup() {
4987 	setPlayerSpritesPrefix();
4988 	setAAName();
4989 	_scene->addActiveVocab(VERB_WALKTO);
4990 }
4991 
enter()4992 void Scene359::enter() {
4993 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(formAnimName('b', -1));
4994 	_globals._spriteIndexes[3] = _scene->_sprites.addSprites(Resources::formatName(307, 'X', 0, EXT_SS, ""));
4995 
4996 	if (_globals[kSexOfRex] == REX_MALE)
4997 		_globals._spriteIndexes[2] = _scene->_sprites.addSprites("*RXMBD_2");
4998 	else
4999 		_globals._spriteIndexes[4] = _scene->_sprites.addSprites("*ROXBD_2");
5000 
5001 	_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 1);
5002 	_scene->_sequences.setPosition(_globals._sequenceIndexes[3], Common::Point(127, 78));
5003 	_scene->_sequences.setDepth(_globals._sequenceIndexes[3], 15);
5004 
5005 	if (_game._objects.isInRoom(OBJ_SECURITY_CARD)) {
5006 		_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 9, 0, 0, 0);
5007 		_cardHotspotId = _scene->_dynamicHotspots.add(NOUN_SECURITY_CARD, VERB_WALKTO, _globals._sequenceIndexes[1], Common::Rect(0, 0, 0, 0));
5008 		_scene->_dynamicHotspots.setPosition(_cardHotspotId, Common::Point(107, 107), FACING_SOUTH);
5009 	}
5010 
5011 	if (_scene->_priorSceneId == 358)
5012 		_game._player._playerPos = Common::Point(301, 141);
5013 	else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG)
5014 		_game._player._playerPos = Common::Point(15, 148);
5015 
5016 	sceneEntrySound();
5017 }
5018 
preActions()5019 void Scene359::preActions() {
5020 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_EAST))
5021 		_game._player._walkOffScreenSceneId = 358;
5022 
5023 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_WEST))
5024 		_game._player._walkOffScreenSceneId = 360;
5025 }
5026 
actions()5027 void Scene359::actions() {
5028 	if (_action._lookFlag) {
5029 		if ((_game._difficulty != DIFFICULTY_HARD) && (_game._objects[OBJ_SECURITY_CARD]._roomNumber == 359))
5030 			_vm->_dialogs->show(35914);
5031 		else
5032 			_vm->_dialogs->show(35915);
5033 	} else if (_action.isAction(VERB_TAKE, NOUN_SECURITY_CARD)) {
5034 		if (_game._trigger || !_game._objects.isInInventory(OBJ_SECURITY_CARD)) {
5035 			switch (_game._trigger) {
5036 			case 0:
5037 				_game._player._stepEnabled = false;
5038 				_game._player._visible = false;
5039 				_vm->_dialogs->show(35920);
5040 				if (_globals[kSexOfRex] == REX_MALE) {
5041 					_globals._sequenceIndexes[2] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[2], false, 4, 2, 0, 0);
5042 					_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
5043 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_SPRITE, 6, 1);
5044 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
5045 				} else {
5046 					_globals._sequenceIndexes[4] = _scene->_sequences.startPingPongCycle(_globals._spriteIndexes[4], true, 7, 2, 0, 0);
5047 					_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
5048 					_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(106, 110));
5049 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_SPRITE, 6, 1);
5050 					_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
5051 				}
5052 				break;
5053 
5054 			case 1:
5055 				_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5056 				_scene->_dynamicHotspots.remove(_cardHotspotId);
5057 				_vm->_sound->command(57);
5058 				_game._objects.addToInventory(OBJ_SECURITY_CARD);
5059 				_vm->_dialogs->showItem(OBJ_SECURITY_CARD, 0x330);
5060 				_scene->changeVariant(1);
5061 				break;
5062 
5063 			case 2:
5064 				if (_globals[kSexOfRex] == REX_MALE)
5065 					_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[2]);
5066 				else
5067 					_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[4]);
5068 
5069 				_game._player._visible = true;
5070 				_game._player._stepEnabled = true;
5071 				break;
5072 
5073 			default:
5074 				break;
5075 			}
5076 		}
5077 	} else if (_action.isAction(VERB_LOOK, NOUN_BLOODY_CELL_WALL))
5078 		_vm->_dialogs->show(35910);
5079 	else if (_action.isAction(VERB_LOOK, NOUN_BED))
5080 		_vm->_dialogs->show(35911);
5081 	else if (_action.isAction(VERB_LOOK, NOUN_SINK))
5082 		_vm->_dialogs->show(35912);
5083 	else if (_action.isAction(VERB_LOOK, NOUN_TOILET))
5084 		_vm->_dialogs->show(35913);
5085 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_EAST))
5086 		_vm->_dialogs->show(35916);
5087 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_WEST))
5088 		_vm->_dialogs->show(35917);
5089 	else if (_action.isAction(VERB_LOOK, NOUN_LIMB))
5090 		_vm->_dialogs->show(35918);
5091 	else if (_action.isAction(VERB_TAKE, NOUN_LIMB))
5092 		_vm->_dialogs->show(35919);
5093 	else if (_action.isAction(VERB_LOOK, NOUN_SECURITY_CARD) && (_action._mainObjectSource == CAT_HOTSPOT))
5094 		_vm->_dialogs->show(35921);
5095 	else if (_action.isAction(VERB_LOOK, NOUN_BLOOD_STAIN)) {
5096 		if ((_game._difficulty != DIFFICULTY_HARD) && (_game._objects[OBJ_SECURITY_CARD]._roomNumber == 359))
5097 			_vm->_dialogs->show(35922);
5098 		else
5099 			_vm->_dialogs->show(35923);
5100 	} else if (_action.isAction(VERB_LOOK, NOUN_WALL_BOARD))
5101 		_vm->_dialogs->show(35924);
5102 	else if (_action.isAction(VERB_TAKE, NOUN_WALL_BOARD))
5103 		_vm->_dialogs->show(35925);
5104 	else if (_action.isAction(VERB_LOOK, NOUN_RIP_IN_FLOOR))
5105 		_vm->_dialogs->show(35926);
5106 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR))
5107 		_vm->_dialogs->show(35927);
5108 	else if (_action.isAction(VERB_LOOK, NOUN_FLOOR)) {
5109 		if ((_game._difficulty != DIFFICULTY_HARD) && (_game._objects[OBJ_SECURITY_CARD]._roomNumber == 359))
5110 			_vm->_dialogs->show(35928);
5111 		else
5112 			_vm->_dialogs->show(35929);
5113 	} else if (_action.isAction(VERB_OPEN, NOUN_AIR_VENT) || _action.isAction(VERB_LOOK, NOUN_AIR_VENT))
5114 		_vm->_dialogs->show(36016);
5115 	else
5116 		return;
5117 
5118 	_action._inProgress = false;
5119 }
5120 
5121 /*------------------------------------------------------------------------*/
5122 
setup()5123 void Scene360::setup() {
5124 	setPlayerSpritesPrefix();
5125 	setAAName();
5126 }
5127 
enter()5128 void Scene360::enter() {
5129 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(Resources::formatName(307, 'X', 0, EXT_SS, ""));
5130 	_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
5131 	_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(127, 78));
5132 	_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
5133 
5134 	if (_scene->_priorSceneId == 359)
5135 		_game._player._playerPos = Common::Point(304, 143);
5136 	else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG)
5137 		_game._player._playerPos = Common::Point(13, 141);
5138 
5139 	sceneEntrySound();
5140 }
5141 
preActions()5142 void Scene360::preActions() {
5143 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_EAST))
5144 		_game._player._walkOffScreenSceneId = 359;
5145 
5146 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_WEST))
5147 		_game._player._walkOffScreenSceneId = 361;
5148 }
5149 
actions()5150 void Scene360::actions() {
5151 	if (_action._lookFlag)
5152 		_vm->_dialogs->show(36015);
5153 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_WEST))
5154 		_vm->_dialogs->show(36010);
5155 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_EAST))
5156 		_vm->_dialogs->show(36011);
5157 	else if (_action.isAction(VERB_LOOK, NOUN_BED))
5158 		_vm->_dialogs->show(36012);
5159 	else if (_action.isAction(VERB_LOOK, NOUN_SINK))
5160 		_vm->_dialogs->show(36013);
5161 	else if (_action.isAction(VERB_LOOK, NOUN_TOILET))
5162 		_vm->_dialogs->show(36014);
5163 	else if (_action.isAction(VERB_LOOK, NOUN_AIR_VENT))
5164 		_vm->_dialogs->show(36016);
5165 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR))
5166 		_vm->_dialogs->show(36017);
5167 	else if (_action.isAction(VERB_LOOK, NOUN_WALL))
5168 		_vm->_dialogs->show(36018);
5169 	else
5170 		return;
5171 
5172 	_action._inProgress = false;
5173 }
5174 
5175 /*------------------------------------------------------------------------*/
5176 
setup()5177 void Scene361::setup() {
5178 	if (_scene->_currentSceneId == 391)
5179 		_globals[kSexOfRex] = REX_MALE;
5180 
5181 	setPlayerSpritesPrefix();
5182 	setAAName();
5183 }
5184 
handleRexAction()5185 void Scene361::handleRexAction() {
5186 	switch (_game._trigger) {
5187 	case 0:
5188 		_game._player._stepEnabled = false;
5189 		_game._player._visible = false;
5190 		_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5191 		_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 50, 1, 0, 0);
5192 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], 3, -2);
5193 		_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5194 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
5195 
5196 		_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 15, 1, 0, 0);
5197 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], -1, 4);
5198 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
5199 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[1], SEQUENCE_TRIGGER_EXPIRE, 0, 1);
5200 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
5201 		break;
5202 
5203 	case 1: {
5204 		int seqIdx = _globals._sequenceIndexes[1];
5205 		_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 4);
5206 		_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5207 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
5208 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[1], seqIdx);
5209 		}
5210 		break;
5211 
5212 	case 2: {
5213 		int seqIdx = _globals._sequenceIndexes[2];
5214 		_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 12, 1, 0, 0);
5215 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 4, 10);
5216 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
5217 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[2], seqIdx);
5218 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
5219 		}
5220 		break;
5221 
5222 	case 3: {
5223 		_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5224 		_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 3);
5225 		_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5226 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
5227 
5228 		int seqIdx = _globals._sequenceIndexes[2];
5229 		_globals._sequenceIndexes[2] = _scene->_sequences.startCycle(_globals._spriteIndexes[2], false, 11);
5230 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
5231 		_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(167, 100));
5232 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[2], seqIdx);
5233 		_scene->_sequences.addTimer(15, 4);
5234 		}
5235 		break;
5236 
5237 	case 4:
5238 		_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5239 		_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 2);
5240 		_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5241 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
5242 
5243 		_scene->_sequences.setDone(_globals._sequenceIndexes[2]);
5244 		_globals._sequenceIndexes[2] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[2], false, 12, 1, 0, 0);
5245 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[2], 12, 14);
5246 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
5247 		_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(167, 100));
5248 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[2], SEQUENCE_TRIGGER_EXPIRE, 0, 5);
5249 		break;
5250 
5251 	case 5: {
5252 		int seqIdx = _globals._sequenceIndexes[2];
5253 		_globals._sequenceIndexes[2] = _scene->_sequences.startCycle(_globals._spriteIndexes[2], false, 15);
5254 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[2]);
5255 		_scene->_sequences.setPosition(_globals._sequenceIndexes[2], Common::Point(167, 100));
5256 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[2], seqIdx);
5257 		_scene->_sequences.addTimer(15, 6);
5258 		}
5259 		break;
5260 
5261 	case 6:
5262 		_scene->_sequences.setDone(_globals._sequenceIndexes[2]);
5263 		_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5264 		_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
5265 		_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5266 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
5267 		_scene->_sequences.addTimer(48, 7);
5268 		break;
5269 
5270 	case 7:
5271 		_scene->_nextSceneId = 313;
5272 		break;
5273 
5274 	default:
5275 		break;
5276 	}
5277 }
5278 
handleRoxAction()5279 void Scene361::handleRoxAction() {
5280 	switch (_game._trigger) {
5281 	case 0:
5282 		_game._player._stepEnabled = false;
5283 		_game._player._visible = false;
5284 		_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5285 		_globals._sequenceIndexes[1] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[1], false, 18, 1, 0, 0);
5286 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[1], 2, 4);
5287 		_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5288 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
5289 
5290 		_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 18, 1, 0, 0);
5291 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], -1, 3);
5292 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
5293 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[1], SEQUENCE_TRIGGER_EXPIRE, 0, 1);
5294 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 2);
5295 		break;
5296 
5297 	case 1: {
5298 		int tmpIdx = _globals._sequenceIndexes[1];
5299 		_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 4);
5300 		_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5301 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
5302 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[1], tmpIdx);
5303 		}
5304 		break;
5305 
5306 	case 2: {
5307 		int tmpIdx = _globals._sequenceIndexes[4];
5308 		_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 12, 1, 0, 0);
5309 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], 4, 8);
5310 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
5311 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[4], tmpIdx);
5312 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 3);
5313 		}
5314 		break;
5315 
5316 	case 3: {
5317 		_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5318 		_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 3);
5319 		_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5320 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
5321 
5322 		int tmpIdx = _globals._sequenceIndexes[4];
5323 		_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 12, 1, 0, 0);
5324 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], 9, 10);
5325 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
5326 		_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(167, 100));
5327 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[4], tmpIdx);
5328 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 4);
5329 		}
5330 		break;
5331 
5332 	case 4: {
5333 		_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5334 		_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 2);
5335 		_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5336 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
5337 
5338 		int tmpIdx = _globals._sequenceIndexes[4];
5339 		_globals._sequenceIndexes[4] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[4], false, 12, 1, 0, 0);
5340 		_scene->_sequences.setAnimRange(_globals._sequenceIndexes[4], 11, 15);
5341 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
5342 		_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(167, 100));
5343 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[4], tmpIdx);
5344 		_scene->_sequences.addSubEntry(_globals._sequenceIndexes[4], SEQUENCE_TRIGGER_EXPIRE, 0, 5);
5345 		}
5346 		break;
5347 
5348 	case 5: {
5349 		int tmpIdx = _globals._sequenceIndexes[4];
5350 		_globals._sequenceIndexes[4] = _scene->_sequences.startCycle(_globals._spriteIndexes[4], false, 16);
5351 		_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[4]);
5352 		_scene->_sequences.setPosition(_globals._sequenceIndexes[4], Common::Point(167, 100));
5353 		_scene->_sequences.updateTimeout(_globals._sequenceIndexes[4], tmpIdx);
5354 		_scene->_sequences.addTimer(48, 6);
5355 		}
5356 		break;
5357 
5358 	case 6:
5359 		_scene->_sequences.setDone(_globals._sequenceIndexes[4]);
5360 
5361 		_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5362 		_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
5363 		_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5364 		_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
5365 		_scene->_sequences.addTimer(48, 7);
5366 		break;
5367 
5368 	case 7:
5369 		_scene->_nextSceneId = 313;
5370 		break;
5371 
5372 	default:
5373 		break;
5374 	}
5375 }
5376 
enter()5377 void Scene361::enter() {
5378 	_globals._spriteIndexes[1] = _scene->_sprites.addSprites(Resources::formatName(307, 'X', 0, EXT_SS, ""));
5379 
5380 	if (_globals[kSexOfRex] == REX_MALE) {
5381 		_globals._spriteIndexes[2] = _scene->_sprites.addSprites("*RXCL_8");
5382 		_globals._spriteIndexes[3] = _scene->_sprites.addSprites("*RXCL_2");
5383 	} else
5384 		_globals._spriteIndexes[4] = _scene->_sprites.addSprites("*ROXCL_8");
5385 
5386 	_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
5387 	_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5388 	_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
5389 
5390 	if (_scene->_priorSceneId == 391) {
5391 		_globals[kSexOfRex] = REX_MALE;
5392 		_game._player._stepEnabled = false;
5393 		_game._player._visible = false;
5394 		_game._player._facing = FACING_SOUTH;
5395 		_game._player._playerPos = Common::Point(166, 101);
5396 		_scene->_sequences.addTimer(120, 70);
5397 	} else if (_scene->_priorSceneId == 360)
5398 		_game._player._playerPos = Common::Point(302, 145);
5399 	else if (_scene->_priorSceneId == 320) {
5400 		_game._player._playerPos = Common::Point(129, 113);
5401 		_game._player._facing = FACING_SOUTH;
5402 	} else if (_scene->_priorSceneId != RETURNING_FROM_DIALOG)
5403 		_game._player._playerPos = Common::Point(13, 145);
5404 
5405 	_game.loadQuoteSet(0xFB, 0xFC, 0);
5406 
5407 	if (_scene->_priorSceneId == 320)
5408 		_scene->_kernelMessages.setQuoted(_scene->_kernelMessages.addQuote(0xFB, 0, 0x78), 4, true);
5409 
5410 	sceneEntrySound();
5411 }
5412 
step()5413 void Scene361::step() {
5414 	if (_game._trigger >= 70) {
5415 		switch (_game._trigger) {
5416 		case 70:
5417 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5418 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 2);
5419 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5420 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
5421 
5422 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 1);
5423 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
5424 			_scene->_sequences.addTimer(15, 71);
5425 			break;
5426 
5427 		case 71:
5428 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
5429 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 2);
5430 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
5431 			_scene->_sequences.addTimer(15, 72);
5432 			break;
5433 
5434 		case 72:
5435 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5436 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 3);
5437 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5438 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
5439 
5440 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
5441 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 3);
5442 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
5443 			_scene->_sequences.addTimer(15, 73);
5444 			break;
5445 
5446 		case 73:
5447 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
5448 			_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 12, 1, 0, 0);
5449 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 4, 5);
5450 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
5451 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 74);
5452 			break;
5453 
5454 		case 74: {
5455 			int seqIdx = _globals._sequenceIndexes[3];
5456 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 6);
5457 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
5458 			_scene->_sequences.updateTimeout(_globals._sequenceIndexes[3], seqIdx);
5459 			_scene->_sequences.addTimer(15, 75);
5460 			}
5461 			break;
5462 
5463 		case 75:
5464 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
5465 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 7);
5466 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
5467 			_scene->_sequences.addTimer(15, 76);
5468 			break;
5469 
5470 		case 76:
5471 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5472 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 2);
5473 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5474 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 1);
5475 
5476 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
5477 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 8);
5478 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
5479 			_scene->_sequences.addTimer(15, 77);
5480 			break;
5481 
5482 		case 77:
5483 			_scene->_sequences.remove(_globals._sequenceIndexes[1]);
5484 			_globals._sequenceIndexes[1] = _scene->_sequences.startCycle(_globals._spriteIndexes[1], false, 1);
5485 			_scene->_sequences.setPosition(_globals._sequenceIndexes[1], Common::Point(165, 76));
5486 			_scene->_sequences.setDepth(_globals._sequenceIndexes[1], 15);
5487 
5488 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
5489 			_globals._sequenceIndexes[3] = _scene->_sequences.startCycle(_globals._spriteIndexes[3], false, 9);
5490 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
5491 			_scene->_sequences.addTimer(15, 78);
5492 			break;
5493 
5494 		case 78:
5495 			_scene->_sequences.setDone(_globals._sequenceIndexes[3]);
5496 			_globals._sequenceIndexes[3] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[3], false, 12, 1, 0, 0);
5497 			_scene->_sequences.setAnimRange(_globals._sequenceIndexes[3], 10, -2);
5498 			_scene->_sequences.setMsgLayout(_globals._sequenceIndexes[3]);
5499 			_scene->_sequences.addSubEntry(_globals._sequenceIndexes[3], SEQUENCE_TRIGGER_EXPIRE, 0, 79);
5500 			break;
5501 
5502 		case 79:
5503 			_scene->_sequences.updateTimeout(-1, _globals._sequenceIndexes[3]);
5504 			_game._player._stepEnabled = true;
5505 			_game._player._visible = true;
5506 			break;
5507 
5508 		default:
5509 			break;
5510 		}
5511 	}
5512 }
5513 
preActions()5514 void Scene361::preActions() {
5515 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_EAST))
5516 		_game._player._walkOffScreenSceneId = 360;
5517 
5518 	if (_action.isAction(VERB_WALK_DOWN, NOUN_CORRIDOR_TO_WEST))
5519 		_game._player._walkOffScreenSceneId = 354;
5520 }
5521 
actions()5522 void Scene361::actions() {
5523 	if (_action._lookFlag)
5524 		_vm->_dialogs->show(36119);
5525 	else if (_action.isAction(VERB_SIT_AT, NOUN_DESK)) {
5526 		_scene->_kernelMessages.reset();
5527 		_scene->_kernelMessages.addQuote(252, 0, 120);
5528 	} else if (_action.isAction(VERB_CLIMB_INTO, NOUN_AIR_VENT)) {
5529 		if (_globals[kSexOfRex] == REX_FEMALE)
5530 			handleRoxAction();
5531 		else
5532 			handleRexAction();
5533 	} else if (_action.isAction(VERB_LOOK, NOUN_DESK))
5534 		_vm->_dialogs->show(36110);
5535 	else if (_action.isAction(VERB_LOOK, NOUN_WALL))
5536 		_vm->_dialogs->show(36111);
5537 	else if (_action.isAction(VERB_LOOK, NOUN_LIGHTING_FIXTURE) || _action.isAction(VERB_STARE_AT, NOUN_LIGHTING_FIXTURE))
5538 		_vm->_dialogs->show(36112);
5539 	else if (_action.isAction(VERB_LOOK, NOUN_LIGHTS) || _action.isAction(VERB_STARE_AT, NOUN_LIGHTS))
5540 		_vm->_dialogs->show(36113);
5541 	else if (_action.isAction(VERB_TAKE, NOUN_LIGHTS))
5542 		_vm->_dialogs->show(36114);
5543 	else if (_action.isAction(VERB_LOOK, NOUN_LIGHT_BULB) || _action.isAction(VERB_STARE_AT, NOUN_LIGHT_BULB))
5544 		_vm->_dialogs->show(36115);
5545 	else if (_action.isAction(VERB_TAKE, NOUN_LIGHT_BULB))
5546 		_vm->_dialogs->show(36116);
5547 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_WEST))
5548 		_vm->_dialogs->show(36117);
5549 	else if (_action.isAction(VERB_LOOK, NOUN_CORRIDOR_TO_EAST))
5550 		_vm->_dialogs->show(36118);
5551 	else if (_action.isAction(VERB_LOOK, NOUN_AIR_VENT))
5552 		_vm->_dialogs->show(36120);
5553 	else
5554 		return;
5555 
5556 	_action._inProgress = false;
5557 }
5558 
5559 /*------------------------------------------------------------------------*/
5560 
setup()5561 void Scene366::setup() {
5562 	setPlayerSpritesPrefix();
5563 	setAAName();
5564 }
5565 
enter()5566 void Scene366::enter() {
5567 	_scene->_userInterface.setup(kInputLimitedSentences);
5568 	_game._player._visible = false;
5569 	sceneEntrySound();
5570 }
5571 
actions()5572 void Scene366::actions() {
5573 	if (_action.isAction(VERB_RETURN_TO, NOUN_AIR_SHAFT))
5574 		_scene->_nextSceneId = 302;
5575 	else if (_action.isAction(VERB_OPEN, NOUN_GRATE)) {
5576 		if (_game._visitedScenes.exists(316))
5577 			_vm->_dialogs->show(36612);
5578 		else
5579 			_vm->_dialogs->show(36613);
5580 		_scene->_nextSceneId = 316;
5581 	} else if (_action.isAction(VERB_LOOK_THROUGH, NOUN_GRATE)) {
5582 		if (_game._visitedScenes.exists(321))
5583 			_vm->_dialogs->show(36611);
5584 		else
5585 			_vm->_dialogs->show(36610);
5586 	} else {
5587 		return;
5588 	}
5589 
5590 	_action._inProgress = false;
5591 }
5592 
5593 /*------------------------------------------------------------------------*/
5594 
setup()5595 void Scene387::setup() {
5596 	setPlayerSpritesPrefix();
5597 	setAAName();
5598 }
5599 
enter()5600 void Scene387::enter() {
5601 	_scene->_userInterface.setup(kInputLimitedSentences);
5602 	_game._player._visible = false;
5603 
5604 	sceneEntrySound();
5605 }
5606 
actions()5607 void Scene387::actions() {
5608 	if (_action.isAction(VERB_RETURN_TO, NOUN_AIR_SHAFT))
5609 		_scene->_nextSceneId = 313;
5610 	else if (_action.isAction(VERB_LOOK_THROUGH, NOUN_GRATE))
5611 		_vm->_dialogs->show(38710);
5612 	else if (_action.isAction(VERB_OPEN, NOUN_GRATE))
5613 		_vm->_dialogs->show(38711);
5614 	else
5615 		return;
5616 
5617 	_action._inProgress = false;
5618 }
5619 
5620 /*------------------------------------------------------------------------*/
5621 
setup()5622 void Scene388::setup() {
5623 	setPlayerSpritesPrefix();
5624 	setAAName();
5625 }
5626 
enter()5627 void Scene388::enter() {
5628 	_scene->_userInterface.setup(kInputLimitedSentences);
5629 
5630 	if (_globals[kAfterHavoc])
5631 		_scene->_hotspots.activate(NOUN_SAUROPOD, false);
5632 	else {
5633 		_globals._spriteIndexes[0] = _scene->_sprites.addSprites(formAnimName('b', 0));
5634 		_globals._sequenceIndexes[0] = _scene->_sequences.startCycle(_globals._spriteIndexes[0], false, 1);
5635 	}
5636 
5637 	_game._player._visible = false;
5638 	_vm->_palette->setEntry(252, 63, 30, 20);
5639 	_vm->_palette->setEntry(253, 45, 15, 12);
5640 	_game.loadQuoteSet(0x154, 0x155, 0x156, 0x157, 0x158, 0);
5641 
5642 	sceneEntrySound();
5643 }
5644 
actions()5645 void Scene388::actions() {
5646 	if (_action.isAction(VERB_RETURN_TO, NOUN_AIR_SHAFT))
5647 		_scene->_nextSceneId = 313;
5648 	else if (_action.isAction(VERB_TALKTO, NOUN_SAUROPOD)) {
5649 		switch (_game._trigger) {
5650 		case 0:
5651 			_game._player._stepEnabled = false;
5652 			_scene->_kernelMessages.reset();
5653 			_scene->_kernelMessages.add(Common::Point(160, 136), 0x1110, 32, 1, 120, _game.getQuote(0x154));
5654 			break;
5655 
5656 		case 1:
5657 			_scene->_kernelMessages.add(Common::Point(82, 38), 0xFDFC, 0, 0, 300, _game.getQuote(0x156));
5658 			_scene->_kernelMessages.add(Common::Point(82, 52), 0xFDFC, 0, 0, 300, _game.getQuote(0x157));
5659 			_scene->_kernelMessages.add(Common::Point(82, 66), 0xFDFC, 0, 2, 300, _game.getQuote(0x158));
5660 			break;
5661 
5662 		case 2:
5663 			_game._player._stepEnabled = true;
5664 			_scene->_kernelMessages.add(Common::Point(160, 136), 0x1110, 32, 0, 120, _game.getQuote(0x155));
5665 			break;
5666 
5667 		default:
5668 			break;
5669 		}
5670 	} else if (_action.isAction(VERB_LOOK_THROUGH, NOUN_GRATE)) {
5671 		if (_globals[kAfterHavoc])
5672 			_vm->_dialogs->show(38811);
5673 		else
5674 			_vm->_dialogs->show(38810);
5675 	} else if (_action.isAction(VERB_OPEN, NOUN_GRATE))
5676 		_vm->_dialogs->show(38812);
5677 	else
5678 		return;
5679 
5680 	_action._inProgress = false;
5681 }
5682 
5683 /*------------------------------------------------------------------------*/
5684 
Scene389(MADSEngine * vm)5685 Scene389::Scene389(MADSEngine *vm) : Scene300s(vm) {
5686 	_monsterTime = 0;
5687 	_circularQuoteId = -1;
5688 }
5689 
synchronize(Common::Serializer & s)5690 void Scene389::synchronize(Common::Serializer &s) {
5691 	Scene3xx::synchronize(s);
5692 
5693 	s.syncAsUint32LE(_monsterTime);
5694 	s.syncAsSint32LE(_circularQuoteId);
5695 }
5696 
setup()5697 void Scene389::setup() {
5698 	setPlayerSpritesPrefix();
5699 	setAAName();
5700 }
5701 
enter()5702 void Scene389::enter() {
5703 	_scene->_userInterface.setup(kInputLimitedSentences);
5704 	_monsterTime = 0;
5705 	_circularQuoteId = 0x159;
5706 
5707 	if (_globals[kAfterHavoc])
5708 		_scene->_hotspots.activate(NOUN_MONSTER, false);
5709 	else {
5710 		_globals._spriteIndexes[0] = _scene->_sprites.addSprites(formAnimName('m', -1));
5711 		_globals._sequenceIndexes[0] = _scene->_sequences.addSpriteCycle(_globals._spriteIndexes[0], false, 6, 0, 0, 0);
5712 		_scene->_kernelMessages.initRandomMessages(1,
5713 			Common::Rect(88, 19, 177, 77), 13, 2, 0xFDFC, 60,
5714 			247, 248, 249, 0);
5715 	}
5716 
5717 	_vm->_palette->setEntry(252, 63, 37, 26);
5718 	_vm->_palette->setEntry(253, 45, 24, 17);
5719 	_game._player._visible = false;
5720 	_game.loadQuoteSet(0xF7, 0xF8, 0xF9, 0x159, 0x15A, 0x15B, 0);
5721 
5722 	sceneEntrySound();
5723 }
5724 
step()5725 void Scene389::step() {
5726 	_scene->_kernelMessages.randomServer();
5727 	if (_scene->_frameStartTime >= _monsterTime) {
5728 		int chanceMinor = _scene->_kernelMessages.checkRandom() * 4 + 1;
5729 		_scene->_kernelMessages.generateRandom(20, chanceMinor);
5730 		_monsterTime = _scene->_frameStartTime + 2;
5731 	}
5732 }
5733 
actions()5734 void Scene389::actions() {
5735 	if (_action.isAction(VERB_RETURN_TO, NOUN_AIR_SHAFT))
5736 		_scene->_nextSceneId = 313;
5737 	else if (_action.isAction(VERB_TALKTO, NOUN_MONSTER)) {
5738 		switch (_game._trigger) {
5739 		case 0:
5740 			_game._player._stepEnabled = false;
5741 			_scene->_kernelMessages.add(Common::Point(160, 136), 0x1110, 32, 1, 120, _game.getQuote(_circularQuoteId));
5742 			_circularQuoteId++;
5743 			if (_circularQuoteId > 0x15B)
5744 				_circularQuoteId = 0x159;
5745 
5746 			break;
5747 
5748 		case 1:
5749 			_game._player._stepEnabled = true;
5750 			break;
5751 
5752 		default:
5753 			break;
5754 		}
5755 	} else if (_action.isAction(VERB_LOOK_THROUGH, NOUN_GRATE)) {
5756 		if (_globals[kAfterHavoc]) {
5757 			if ((_game._difficulty != DIFFICULTY_HARD) && (_game._objects[OBJ_SECURITY_CARD]._roomNumber == 359))
5758 				_vm->_dialogs->show(38911);
5759 			else
5760 				_vm->_dialogs->show(38912);
5761 		} else
5762 			_vm->_dialogs->show(38910);
5763 	} else if (_action.isAction(VERB_OPEN, NOUN_GRATE)) {
5764 		if (_globals[kAfterHavoc])
5765 			_vm->_dialogs->show(38914);
5766 		else
5767 			_vm->_dialogs->show(38913);
5768 	} else
5769 		return;
5770 
5771 	_action._inProgress = false;
5772 }
5773 
5774 /*------------------------------------------------------------------------*/
5775 
setup()5776 void Scene390::setup() {
5777 	setPlayerSpritesPrefix();
5778 	setAAName();
5779 }
5780 
enter()5781 void Scene390::enter() {
5782 	_scene->_userInterface.setup(kInputLimitedSentences);
5783 	_game._player._visible = false;
5784 
5785 	sceneEntrySound();
5786 }
5787 
actions()5788 void Scene390::actions() {
5789 	if (_action.isAction(VERB_RETURN_TO, NOUN_AIR_SHAFT))
5790 		_scene->_nextSceneId = 313;
5791 	else if (_action.isAction(VERB_LOOK_THROUGH, NOUN_GRATE))
5792 		_vm->_dialogs->show(39010);
5793 	else if (_action.isAction(VERB_OPEN, NOUN_GRATE))
5794 		_vm->_dialogs->show(39011);
5795 	else
5796 		return;
5797 
5798 	_action._inProgress = false;
5799 }
5800 
5801 /*------------------------------------------------------------------------*/
5802 
setup()5803 void Scene391::setup() {
5804 	setPlayerSpritesPrefix();
5805 	setAAName();
5806 }
5807 
enter()5808 void Scene391::enter() {
5809 	_scene->_userInterface.setup(kInputLimitedSentences);
5810 	_game._player._visible = false;
5811 	sceneEntrySound();
5812 }
5813 
actions()5814 void Scene391::actions() {
5815 	if (_action.isAction(VERB_RETURN_TO, NOUN_AIR_SHAFT))
5816 		_scene->_nextSceneId = 313;
5817 	else if (_action.isAction(VERB_OPEN, NOUN_GRATE)) {
5818 		if (_globals[kKickedIn391Grate])
5819 			_vm->_dialogs->show(39113);
5820 		else {
5821 			_vm->_dialogs->show(39112);
5822 			_globals[kKickedIn391Grate] = true;
5823 		}
5824 
5825 		if (_globals[kAfterHavoc])
5826 			_scene->_nextSceneId = 361;
5827 		else
5828 			_scene->_nextSceneId = 311;
5829 	} else if (_action.isAction(VERB_LOOK_THROUGH, NOUN_GRATE)) {
5830 		if (_globals[kAfterHavoc])
5831 			_vm->_dialogs->show(39111);
5832 		else
5833 			_vm->_dialogs->show(39110);
5834 	} else
5835 		return;
5836 
5837 	_action._inProgress = false;
5838 }
5839 
5840 /*------------------------------------------------------------------------*/
5841 
setup()5842 void Scene399::setup() {
5843 	setPlayerSpritesPrefix();
5844 	setAAName();
5845 }
5846 
enter()5847 void Scene399::enter() {
5848 	_scene->_userInterface.setup(kInputLimitedSentences);
5849 	_game._player._visible = false;
5850 	sceneEntrySound();
5851 }
5852 
actions()5853 void Scene399::actions() {
5854 	if (_action.isAction(VERB_RETURN_TO, NOUN_AIR_SHAFT))
5855 		_scene->_nextSceneId = 313;
5856 	else if (_action.isAction(VERB_LOOK_THROUGH, NOUN_GRATE)) {
5857 		if (_globals[kAfterHavoc]) {
5858 			if ((_game._difficulty != DIFFICULTY_HARD) && (_game._objects[OBJ_SECURITY_CARD]._roomNumber == 359))
5859 				_vm->_dialogs->show(38911);
5860 			else
5861 				_vm->_dialogs->show(38912);
5862 		} else
5863 			_vm->_dialogs->show(38910);
5864 	} else if (_action.isAction(VERB_OPEN, NOUN_GRATE)) {
5865 		if (_globals[kAfterHavoc])
5866 			_vm->_dialogs->show(38914);
5867 		else
5868 			_vm->_dialogs->show(38913);
5869 	} else
5870 		return;
5871 
5872 	_action._inProgress = false;
5873 }
5874 
5875 /*------------------------------------------------------------------------*/
5876 
5877 } // End of namespace Nebular
5878 } // End of namespace MADS
5879