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 "gnap/gnap.h"
24 #include "gnap/gamesys.h"
25 #include "gnap/resource.h"
26 #include "gnap/scenes/group4.h"
27 
28 namespace Gnap {
29 
Scene40(GnapEngine * vm)30 Scene40::Scene40(GnapEngine *vm) : Scene(vm) {
31 }
32 
init()33 int Scene40::init() {
34 	GameSys& gameSys = *_vm->_gameSys;
35 
36 	gameSys.setAnimation(0, 0, 0);
37 	gameSys.setAnimation(0, 0, 1);
38 	return _vm->isFlag(kGFUnk23) ? 0x01 : 0x00;
39 }
40 
updateHotspots()41 void Scene40::updateHotspots() {
42 	_vm->setHotspot(kHS40Platypus, 0, 0, 0, 0, SF_WALKABLE | SF_DISABLED | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
43 	_vm->setHotspot(kHS40ExitCave, 169, 510, 264, 600, SF_EXIT_D_CURSOR, 0, 8);
44 	_vm->setHotspot(kHS40ExitToyStand, 238, 297, 328, 376, SF_EXIT_L_CURSOR, 0, 8);
45 	_vm->setHotspot(kHS40ExitBBQ, 328, 220, 401, 306, SF_EXIT_L_CURSOR, 0, 8);
46 	_vm->setHotspot(kHS40ExitUfo, 421, 215, 501, 282, SF_EXIT_U_CURSOR, 0, 8);
47 	_vm->setHotspot(kHS40ExitKissinBooth, 476, 284, 556, 345, SF_EXIT_R_CURSOR, 0, 8);
48 	_vm->setHotspot(kHS40ExitDancefloor, 317, 455, 445, 600, SF_EXIT_D_CURSOR, 0, 8);
49 	_vm->setHotspot(kHS40ExitShoe, 455, 346, 549, 417, SF_EXIT_D_CURSOR, 0, 8);
50 	_vm->setDeviceHotspot(kHS40Device, -1, -1, -1, -1);
51 	_vm->_hotspotsCount = 9;
52 }
53 
run()54 void Scene40::run() {
55 	PlayerGnap& gnap = *_vm->_gnap;
56 	PlayerPlat& plat = *_vm->_plat;
57 
58 	_vm->queueInsertDeviceIcon();
59 	_vm->endSceneInit();
60 
61 	while (!_vm->_sceneDone) {
62 		if (!_vm->isSoundPlaying(0x1094B))
63 			_vm->playSound(0x1094B, true);
64 
65 		_vm->updateMouseCursor();
66 		_vm->updateCursorByHotspot();
67 
68 		_vm->testWalk(0, 0, -1, -1, -1, -1);
69 
70 		_vm->_sceneClickedHotspot = _vm->getClickedHotspotId();
71 		_vm->updateGrabCursorSprite(0, 0);
72 
73 		switch (_vm->_sceneClickedHotspot) {
74 		case kHS40Device:
75 			_vm->runMenu();
76 			updateHotspots();
77 			break;
78 
79 		case kHS40Platypus:
80 			if (gnap._actionStatus < 0) {
81 				if (_vm->_grabCursorSpriteIndex >= 0) {
82 					gnap.playImpossible(plat._pos);
83 				} else {
84 					switch (_vm->_verbCursor) {
85 					case LOOK_CURSOR:
86 						gnap.playMoan1(plat._pos);
87 						break;
88 					case GRAB_CURSOR:
89 						gnap.kissPlatypus(0);
90 						break;
91 					case TALK_CURSOR:
92 						gnap.playBrainPulsating(plat._pos);
93 						plat.playSequence(plat.getSequenceId());
94 						break;
95 					case PLAT_CURSOR:
96 						gnap.playImpossible(plat._pos);
97 						break;
98 					}
99 				}
100 			}
101 			break;
102 
103 		case kHS40ExitCave:
104 			if (gnap._actionStatus < 0) {
105 				_vm->_newSceneNum = 39;
106 				_vm->_sceneDone = true;
107 			}
108 			break;
109 
110 		case kHS40ExitToyStand:
111 			if (gnap._actionStatus < 0) {
112 				_vm->_newSceneNum = 41;
113 				_vm->_sceneDone = true;
114 			}
115 			break;
116 
117 		case kHS40ExitBBQ:
118 			if (gnap._actionStatus < 0) {
119 				_vm->_newSceneNum = 42;
120 				_vm->_sceneDone = true;
121 			}
122 			break;
123 
124 		case kHS40ExitUfo:
125 			if (gnap._actionStatus < 0) {
126 				_vm->_newSceneNum = 43;
127 				_vm->_sceneDone = true;
128 			}
129 			break;
130 
131 		case kHS40ExitKissinBooth:
132 			if (gnap._actionStatus < 0) {
133 				_vm->_newSceneNum = 44;
134 				_vm->_sceneDone = true;
135 			}
136 			break;
137 
138 		case kHS40ExitDancefloor:
139 			if (gnap._actionStatus < 0) {
140 				_vm->_newSceneNum = 45;
141 				_vm->_sceneDone = true;
142 			}
143 			break;
144 
145 		case kHS40ExitShoe:
146 			if (gnap._actionStatus < 0) {
147 				_vm->_newSceneNum = 46;
148 				_vm->_sceneDone = true;
149 			}
150 			break;
151 
152 		default:
153 			if (_vm->_mouseClickState._left && gnap._actionStatus < 0)
154 				_vm->_mouseClickState._left = false;
155 			break;
156 
157 		}
158 
159 		updateAnimations();
160 		_vm->checkGameKeys();
161 
162 		if (_vm->isKeyStatus1(Common::KEYCODE_BACKSPACE)) {
163 			_vm->clearKeyStatus1(Common::KEYCODE_BACKSPACE);
164 			_vm->runMenu();
165 			updateHotspots();
166 		}
167 
168 		_vm->gameUpdateTick();
169 	}
170 }
171 
updateAnimations()172 void Scene40::updateAnimations() {
173 	GameSys& gameSys = *_vm->_gameSys;
174 	PlayerGnap& gnap = *_vm->_gnap;
175 
176 	if (gameSys.getAnimationStatus(0) == 2) {
177 		gameSys.setAnimation(0, 0, 0);
178 		if (gnap._actionStatus)
179 			gnap._actionStatus = -1;
180 		else
181 			_vm->_sceneDone = true;
182 	}
183 }
184 
185 /*****************************************************************************/
186 
Scene41(GnapEngine * vm)187 Scene41::Scene41(GnapEngine *vm) : Scene(vm) {
188 	_currKidSequenceId = -1;
189 	_nextKidSequenceId = -1;
190 	_currToyVendorSequenceId = -1;
191 	_nextToyVendorSequenceId = -1;
192 }
193 
init()194 int Scene41::init() {
195 	GameSys& gameSys = *_vm->_gameSys;
196 
197 	gameSys.setAnimation(0, 0, 0);
198 	gameSys.setAnimation(0, 0, 1);
199 	gameSys.setAnimation(0, 0, 2);
200 	return 0x129;
201 }
202 
updateHotspots()203 void Scene41::updateHotspots() {
204 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
205 		_vm->setHotspot(kHS41Platypus, 0, 0, 0, 0, SF_DISABLED);
206 		_vm->setHotspot(kHS41UfoExitLeft, 0, 0, 10, 500, SF_EXIT_L_CURSOR | SF_DISABLED);
207 		_vm->setHotspot(kHS41UfoExitRight, 790, 0, 799, 500, SF_EXIT_R_CURSOR);
208 		_vm->setHotspot(kHS41UfoWalkArea1, 0, 0, 800, 470, SF_DISABLED);
209 		_vm->setDeviceHotspot(kHS41UfoDevice, -1, -1, -1, -1);
210 		_vm->_hotspotsCount = 5;
211 	} else {
212 		_vm->setHotspot(kHS41Platypus, 0, 0, 0, 0, SF_WALKABLE | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
213 		_vm->setHotspot(kHS41ExitCave, 150, 590, 650, 600, SF_EXIT_D_CURSOR | SF_WALKABLE, 5, 9);
214 		_vm->setHotspot(kHS41Exit, 0, 100, 10, 599, SF_EXIT_L_CURSOR | SF_DISABLED, 0, 8);
215 		_vm->setHotspot(kHS41ExitBBQ, 790, 100, 799, 599, SF_EXIT_R_CURSOR | SF_WALKABLE, 10, 8);
216 		_vm->setHotspot(kHS41ToyVendor, 320, 150, 430, 310, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
217 		_vm->setHotspot(kHS41Kid, 615, 340, 710, 460, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
218 		_vm->setHotspot(kHS41ToyUfo, 0, 0, 0, 0, SF_GRAB_CURSOR);
219 		_vm->setHotspot(kHS41WalkArea1, 0, 0, 800, 470);
220 		_vm->setDeviceHotspot(kHS41Device, -1, -1, -1, -1);
221 		_vm->_hotspotsCount = 9;
222 	}
223 }
224 
run()225 void Scene41::run() {
226 	GameSys& gameSys = *_vm->_gameSys;
227 	PlayerGnap& gnap = *_vm->_gnap;
228 	PlayerPlat& plat = *_vm->_plat;
229 
230 	_vm->queueInsertDeviceIcon();
231 
232 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
233 		_vm->_toyUfoX = 770;
234 		if (_vm->_toyUfoY < 0 || _vm->_toyUfoY > 300)
235 			_vm->_toyUfoY = 150;
236 		if (!_vm->_timers[9])
237 			gnap._actionStatus = kAS41GiveBackToyUfo;
238 	} else {
239 		if (!_vm->isFlag(kGFUnk16) && !_vm->isFlag(kGFJointTaken) && !_vm->isFlag(kGFUnk18) && !_vm->isFlag(kGFGroceryStoreHatTaken))
240 			_vm->toyUfoSetStatus(kGFUnk16);
241 		_vm->_toyUfoX = 600;
242 		_vm->_toyUfoY = 200;
243 	}
244 
245 	_vm->_toyUfoId = 0;
246 	_vm->_toyUfoActionStatus = -1;
247 	_vm->_toyUfoSequenceId = _vm->toyUfoGetSequenceId();
248 	_vm->_toyUfoNextSequenceId = _vm->_toyUfoSequenceId;
249 
250 	gameSys.setAnimation(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 2);
251 	gameSys.insertSequence(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 0, 0, kSeqNone, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
252 	gameSys.insertSequence(0x128, 0, 0, 0, kSeqLoop, 0, 0, 0);
253 
254 	if (_vm->isFlag(kGFGnapControlsToyUFO))
255 		_currKidSequenceId = 0x11B;
256 	else
257 		_currKidSequenceId = 0x11D;
258 
259 	_nextKidSequenceId = -1;
260 
261 	gameSys.setAnimation(_currKidSequenceId, 1, 4);
262 	gameSys.insertSequence(_currKidSequenceId, 1, 0, 0, kSeqNone, 0, 0, 0);
263 
264 	_currToyVendorSequenceId = 0x118;
265 	_nextToyVendorSequenceId = -1;
266 
267 	gameSys.setAnimation(0x118, 1, 3);
268 	gameSys.insertSequence(_currToyVendorSequenceId, 1, 0, 0, kSeqNone, 0, 0, 0);
269 	gameSys.insertSequence(0x127, 2, 0, 0, kSeqNone, 0, 0, 0);
270 
271 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
272 		gnap._sequenceId = 0x120;
273 		gnap._sequenceDatNum = 0;
274 		gnap._idleFacing = kDirUpRight;
275 		gnap._pos = Common::Point(7, 7);
276 		gnap._id = 140;
277 		gameSys.insertSequence(0x120, 140, 0, 0, kSeqNone, 0, 0, 0);
278 		gameSys.setAnimation(makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id, 0);
279 		plat.initPos(8, 10, kDirBottomLeft);
280 		_vm->endSceneInit();
281 	} else if (_vm->_prevSceneNum == 45) {
282 		gnap.initPos(-1, 8, kDirUpRight);
283 		plat.initPos(-2, 8, kDirUpLeft);
284 		_vm->endSceneInit();
285 		plat.walkTo(Common::Point(1, 8), -1, 0x107C2, 1);
286 		gnap.walkTo(Common::Point(2, 8), -1, 0x107B9, 1);
287 	} else if (_vm->_prevSceneNum == 42) {
288 		gnap.initPos(11, 8, kDirUpRight);
289 		plat.initPos(11, 9, kDirUpLeft);
290 		_vm->endSceneInit();
291 		gnap.walkTo(Common::Point(8, 8), -1, 0x107BA, 1);
292 		plat.walkTo(Common::Point(9, 8), -1, 0x107D2, 1);
293 	} else {
294 		gnap.initPos(5, 8, kDirBottomRight);
295 		plat.initPos(6, 8, kDirBottomLeft);
296 		_vm->endSceneInit();
297 	}
298 
299 	_vm->_timers[4] = _vm->getRandom(100) + 100;
300 	_vm->_timers[5] = _vm->getRandom(30) + 20;
301 
302 	while (!_vm->_sceneDone) {
303 		if (!_vm->isSoundPlaying(0x1094B))
304 			_vm->playSound(0x1094B, true);
305 
306 		if (!_vm->isFlag(kGFGnapControlsToyUFO))
307 			_vm->_hotspots[kHS41ToyUfo]._rect = Common::Rect(_vm->_toyUfoX - 25, _vm->_toyUfoY - 20, _vm->_toyUfoX + 25, _vm->_toyUfoY + 20);
308 
309 		_vm->updateMouseCursor();
310 		_vm->updateCursorByHotspot();
311 
312 		_vm->testWalk(0, 0, -1, -1, -1, -1);
313 
314 		_vm->_sceneClickedHotspot = _vm->getClickedHotspotId();
315 		_vm->updateGrabCursorSprite(0, 0);
316 
317 		if (_vm->isFlag(kGFGnapControlsToyUFO)) {
318 			switch (_vm->_sceneClickedHotspot) {
319 			case kHS41UfoExitLeft:
320 				if (_vm->_toyUfoActionStatus < 0) {
321 					_vm->_isLeavingScene = true;
322 					_vm->_toyUfoActionStatus = kAS41ToyUfoLeaveScene;
323 					_vm->_newSceneNum = 45;
324 					_vm->toyUfoFlyTo(-35, -1, -35, 799, 0, 300, 2);
325 				}
326 				break;
327 
328 			case kHS41UfoExitRight:
329 				if (_vm->_toyUfoActionStatus < 0) {
330 					_vm->_isLeavingScene = true;
331 					_vm->_toyUfoActionStatus = kAS41ToyUfoLeaveScene;
332 					_vm->_newSceneNum = 42;
333 					_vm->toyUfoFlyTo(835, -1, 0, 835, 0, 300, 2);
334 				}
335 				break;
336 
337 			case kHS41UfoDevice:
338 				_vm->runMenu();
339 				updateHotspots();
340 				_vm->_timers[4] = _vm->getRandom(100) + 100;
341 				_vm->_timers[5] = _vm->getRandom(30) + 20;
342 				break;
343 			}
344 		} else {
345 			switch (_vm->_sceneClickedHotspot) {
346 			case kHS41Device:
347 				_vm->runMenu();
348 				updateHotspots();
349 				_vm->_timers[4] = _vm->getRandom(100) + 100;
350 				_vm->_timers[5] = _vm->getRandom(30) + 20;
351 				break;
352 
353 			case kHS41Platypus:
354 				if (gnap._actionStatus < 0) {
355 					if (_vm->_grabCursorSpriteIndex >= 0) {
356 						gnap.playImpossible(plat._pos);
357 					} else {
358 						switch (_vm->_verbCursor) {
359 						case LOOK_CURSOR:
360 							gnap.playMoan1(plat._pos);
361 							break;
362 						case GRAB_CURSOR:
363 							gnap.kissPlatypus(0);
364 							break;
365 						case TALK_CURSOR:
366 							gnap.playBrainPulsating(plat._pos);
367 							plat.playSequence(plat.getSequenceId());
368 							break;
369 						case PLAT_CURSOR:
370 							gnap.playImpossible(plat._pos);
371 							break;
372 						}
373 					}
374 				}
375 				break;
376 
377 			case kHS41ExitCave:
378 				_vm->_isLeavingScene = true;
379 				gnap.walkTo(_vm->_hotspotsWalkPos[kHS41ExitCave], 0, 0x107AE, 1);
380 				gnap._actionStatus = kAS41LeaveScene;
381 				_vm->_newSceneNum = 40;
382 				break;
383 
384 			case kHS41Exit:
385 				_vm->_isLeavingScene = true;
386 				gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS41Exit].x, -1), 0, 0x107AF, 1);
387 				gnap._actionStatus = kAS41LeaveScene;
388 				plat.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS41Exit].x, -1), -1, 0x107CF, 1);
389 				_vm->_newSceneNum = 45;
390 				break;
391 
392 			case kHS41ExitBBQ:
393 				_vm->_isLeavingScene = true;
394 				gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS41ExitBBQ].x, -1), 0, 0x107AB, 1);
395 				gnap._actionStatus = kAS41LeaveScene;
396 				plat.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS41ExitBBQ].x, -1), -1, 0x107CD, 1);
397 				_vm->_newSceneNum = 42;
398 				break;
399 
400 			case kHS41ToyVendor:
401 				if (_vm->_grabCursorSpriteIndex == kItemDiceQuarterHole) {
402 					gnap._actionStatus = kAS41UseQuarterWithToyVendor;
403 					gnap.walkTo(Common::Point(4, 7), 0, 0x107BB, 9);
404 					gnap.playShowItem(_vm->_grabCursorSpriteIndex, 5, 0);
405 				} else if (_vm->_grabCursorSpriteIndex >= 0) {
406 					gnap.playShowCurrItem(Common::Point(4, 7), 5, 0);
407 				} else {
408 					switch (_vm->_verbCursor) {
409 					case LOOK_CURSOR:
410 						gnap.playMoan1(Common::Point(5, 0));
411 						break;
412 					case GRAB_CURSOR:
413 						gnap.playImpossible();
414 						break;
415 					case TALK_CURSOR:
416 						gnap._idleFacing = kDirUpRight;
417 						gnap.walkTo(Common::Point(4, 7), 0, gnap.getSequenceId(kGSBrainPulsating, Common::Point(0, 0)) | 0x10000, 1);
418 						gnap._actionStatus = kAS41TalkToyVendor;
419 						break;
420 					case PLAT_CURSOR:
421 						gnap.playImpossible();
422 						break;
423 					}
424 				}
425 				break;
426 
427 			case kHS41Kid:
428 				if (_vm->_grabCursorSpriteIndex == kItemChickenBucket) {
429 					gnap.walkTo(Common::Point(7, 7), 0, 0x107BB, 1);
430 					gnap._idleFacing = kDirUpRight;
431 					gnap._actionStatus = kAS41UseChickenBucketWithKid;
432 				} else if (_vm->_grabCursorSpriteIndex >= 0) {
433 					gnap.playShowCurrItem(Common::Point(7, 7), 8, 0);
434 				} else {
435 					switch (_vm->_verbCursor) {
436 					case LOOK_CURSOR:
437 						gnap.playScratchingHead(Common::Point(9, 0));
438 						break;
439 					case GRAB_CURSOR:
440 						gnap.walkTo(Common::Point(7, 7), 0, 0x107BB, 1);
441 						gnap._idleFacing = kDirUpRight;
442 						gnap._actionStatus = kAS41GrabKid;
443 						break;
444 					case TALK_CURSOR:
445 						gnap._idleFacing = kDirUpRight;
446 						gnap.walkTo(Common::Point(7, 7), 0, gnap.getSequenceId(kGSBrainPulsating, Common::Point(0, 0)) | 0x10000, 1);
447 						break;
448 					case PLAT_CURSOR:
449 						gnap.playImpossible();
450 						break;
451 					}
452 				}
453 				break;
454 
455 			case kHS41ToyUfo:
456 				if (_vm->_grabCursorSpriteIndex == kItemGum) {
457 					gnap.playPullOutDevice(Common::Point(9, 0));
458 					gameSys.setAnimation(makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id, 0);
459 					gnap._actionStatus = kAS41UseGumWithToyUfo;
460 				}
461 				break;
462 
463 			case kHS41WalkArea1:
464 				if (gnap._actionStatus < 0)
465 					gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
466 				break;
467 			}
468 		}
469 
470 		if (_vm->isFlag(kGFGnapControlsToyUFO)) {
471 			if (!_vm->_timers[9] && gnap._actionStatus < 0) {
472 				gnap._actionStatus = kAS41GiveBackToyUfo;
473 				if (gnap._sequenceId == 0x121 || gnap._sequenceId == 0x122) {
474 					gameSys.insertSequence(0x123, gnap._id, makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id, kSeqSyncWait, 0, 0, 0);
475 					gnap._sequenceId = 0x123;
476 					gnap._sequenceDatNum = 0;
477 					gameSys.setAnimation(0x123, gnap._id, 0);
478 				}
479 			}
480 		}
481 
482 		if (_vm->_mouseClickState._left && gnap._actionStatus < 0) {
483 			_vm->_mouseClickState._left = false;
484 			if (_vm->isFlag(kGFGnapControlsToyUFO)) {
485 				int sequenceId;
486 				if (_vm->_leftClickMouseX >= 400) {
487 					if (gnap._sequenceId == 0x11F || gnap._sequenceId == 0x120 || gnap._sequenceId == 0x123 || gnap._sequenceId == 0x126)
488 						sequenceId = 0x120;
489 					else if (_vm->_leftClickMouseX - _vm->_toyUfoX >= 400)
490 						sequenceId = 0x126;
491 					else
492 						sequenceId = 0x123;
493 				} else {
494 					if (gnap._sequenceId == 0x121 || gnap._sequenceId == 0x125 || gnap._sequenceId == 0x122)
495 						sequenceId = 0x122;
496 					else if (_vm->_toyUfoX - _vm->_leftClickMouseX >= 400)
497 						sequenceId = 0x125;
498 					else
499 						sequenceId = 0x121;
500 				}
501 				gameSys.insertSequence(sequenceId, gnap._id, makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id, kSeqSyncWait, 0, 0, 0);
502 				gnap._sequenceId = sequenceId;
503 				gnap._sequenceDatNum = 0;
504 				gameSys.setAnimation(sequenceId, gnap._id, 0);
505 				_vm->_toyUfoActionStatus = kAS41ToyUfoRefresh;
506 				_vm->toyUfoFlyTo(-1, -1, 0, 799, 0, 300, 2);
507 			} else {
508 				gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
509 			}
510 		}
511 
512 		updateAnimations();
513 
514 		if (!_vm->_isLeavingScene) {
515 			if (plat._actionStatus < 0)
516 				plat.updateIdleSequence();
517 			if (gnap._actionStatus < 0 && !_vm->isFlag(kGFGnapControlsToyUFO))
518 				gnap.updateIdleSequence();
519 			if (!_vm->_timers[4]) {
520 				_vm->_timers[4] = _vm->getRandom(100) + 100;
521 				if (gnap._actionStatus < 0 && plat._actionStatus < 0 && _vm->_toyUfoActionStatus == -1 && _nextToyVendorSequenceId == -1) {
522 					switch (_vm->getRandom(3)) {
523 					case 0:
524 						_nextToyVendorSequenceId = 0x113;
525 						break;
526 					case 1:
527 						_nextToyVendorSequenceId = 0x117;
528 						break;
529 					case 2:
530 						_nextToyVendorSequenceId = 0x119;
531 						break;
532 					}
533 					if (_nextToyVendorSequenceId == _currToyVendorSequenceId)
534 						_nextToyVendorSequenceId = -1;
535 				}
536 			}
537 			if (!_vm->_timers[5]) {
538 				_vm->_timers[5] = _vm->getRandom(30) + 20;
539 				if (gnap._actionStatus < 0 && plat._actionStatus < 0 && _vm->_toyUfoActionStatus == -1 && _nextKidSequenceId == -1) {
540 					if (_vm->isFlag(kGFGnapControlsToyUFO))
541 						_nextKidSequenceId = 0x11B;
542 					else if (_vm->getRandom(3) != 0)
543 						_nextKidSequenceId = 0x11D;
544 					else
545 						_nextKidSequenceId = 0x11E;
546 				}
547 			}
548 		}
549 
550 		_vm->checkGameKeys();
551 
552 		if (_vm->isKeyStatus1(Common::KEYCODE_BACKSPACE)) {
553 			_vm->clearKeyStatus1(Common::KEYCODE_BACKSPACE);
554 			_vm->runMenu();
555 			updateHotspots();
556 			_vm->_timers[4] = _vm->getRandom(100) + 100;
557 			_vm->_timers[5] = _vm->getRandom(30) + 20;
558 		}
559 		_vm->gameUpdateTick();
560 	}
561 }
562 
updateAnimations()563 void Scene41::updateAnimations() {
564 	GameSys& gameSys = *_vm->_gameSys;
565 	PlayerGnap& gnap = *_vm->_gnap;
566 
567 	if (gameSys.getAnimationStatus(0) == 2) {
568 		switch (gnap._actionStatus) {
569 		case kAS41LeaveScene:
570 			gameSys.setAnimation(0, 0, 0);
571 			_vm->_sceneDone = true;
572 			gnap._actionStatus = -1;
573 			break;
574 		case kAS41UseQuarterWithToyVendor:
575 			gameSys.setAnimation(0, 0, 0);
576 			_nextToyVendorSequenceId = 0x114;
577 			gnap._actionStatus = -1;
578 			break;
579 		case kAS41TalkToyVendor:
580 			gameSys.setAnimation(0, 0, 0);
581 			_nextToyVendorSequenceId = 0x116;
582 			gnap._actionStatus = -1;
583 			break;
584 		case kAS41UseGumWithToyUfo:
585 			gameSys.setAnimation(0, 0, 0);
586 			gnap.playUseDevice(Common::Point(9, 0));
587 			gnap._actionStatus = -1;
588 			_vm->setGrabCursorSprite(-1);
589 			_vm->invRemove(kItemGum);
590 			_vm->_toyUfoActionStatus = kAS41UfoGumAttached;
591 			break;
592 		case kAS41UseChickenBucketWithKid:
593 			if (gameSys.getAnimationStatus(4) == 2) {
594 				_vm->_timers[2] = _vm->getRandom(30) + 20;
595 				_vm->_timers[3] = _vm->getRandom(50) + 200;
596 				_vm->setGrabCursorSprite(-1);
597 				gameSys.insertSequence(0x11F, gnap._id, makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id, kSeqSyncWait, 0, 0, 0);
598 				gnap._sequenceId = 0x11F;
599 				gnap._sequenceDatNum = 0;
600 				gameSys.setAnimation(0x11F, gnap._id, 0);
601 				_nextKidSequenceId = 0x11A;
602 				gameSys.insertSequence(0x11A, 1, _currKidSequenceId, 1, kSeqSyncWait, 0, 0, 0);
603 				gameSys.setAnimation(_nextKidSequenceId, 1, 4);
604 				_currKidSequenceId = _nextKidSequenceId;
605 				_nextKidSequenceId = 0x11B;
606 				_vm->_timers[5] = _vm->getRandom(30) + 20;
607 				gnap._actionStatus = -1;
608 				_vm->setFlag(kGFGnapControlsToyUFO);
609 				updateHotspots();
610 				_vm->_timers[9] = 600;
611 			}
612 			break;
613 		case kAS41GrabKid:
614 			if (gameSys.getAnimationStatus(3) == 2 && gameSys.getAnimationStatus(4) == 2) {
615 				_vm->_timers[2] = _vm->getRandom(30) + 20;
616 				_vm->_timers[3] = _vm->getRandom(50) + 200;
617 				gameSys.insertSequence(0x110, gnap._id, makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id, kSeqSyncWait, 0, 0, 0);
618 				gnap._sequenceId = 0x110;
619 				gnap._sequenceDatNum = 0;
620 				gameSys.setAnimation(0x110, gnap._id, 0);
621 				_nextToyVendorSequenceId = 0x111;
622 				gameSys.insertSequence(0x111, 1, _currToyVendorSequenceId, 1, kSeqSyncWait, 0, 0, 0);
623 				gameSys.setAnimation(_nextToyVendorSequenceId, 1, 3);
624 				_currToyVendorSequenceId = _nextToyVendorSequenceId;
625 				_nextToyVendorSequenceId = -1;
626 				_vm->_timers[4] = _vm->getRandom(100) + 100;
627 				_nextKidSequenceId = 0x10F;
628 				gameSys.insertSequence(0x10F, 1, _currKidSequenceId, 1, kSeqSyncWait, 0, 0, 0);
629 				gameSys.setAnimation(_nextKidSequenceId, 1, 4);
630 				_currKidSequenceId = _nextKidSequenceId;
631 				_nextKidSequenceId = -1;
632 				_vm->_timers[5] = _vm->getRandom(30) + 20;
633 				gnap._actionStatus = -1;
634 			}
635 			break;
636 		case kAS41GiveBackToyUfo:
637 			if (gameSys.getAnimationStatus(3) == 2 && gameSys.getAnimationStatus(4) == 2) {
638 				_vm->_timers[2] = _vm->getRandom(30) + 20;
639 				_vm->_timers[3] = _vm->getRandom(50) + 200;
640 				gameSys.insertSequence(0x124, gnap._id,
641 					makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id,
642 					kSeqSyncWait, 0, 0, 0);
643 				gnap._sequenceId = 0x124;
644 				gnap._sequenceDatNum = 0;
645 				gameSys.setAnimation(0x124, gnap._id, 0);
646 				_nextToyVendorSequenceId = 0x112;
647 				gameSys.insertSequence(0x112, 1, _currToyVendorSequenceId, 1, kSeqSyncWait, 0, 0, 0);
648 				gameSys.setAnimation(_nextToyVendorSequenceId, 1, 3);
649 				_currToyVendorSequenceId = _nextToyVendorSequenceId;
650 				_nextToyVendorSequenceId = -1;
651 				_vm->_timers[4] = _vm->getRandom(100) + 100;
652 				_nextKidSequenceId = 0x11C;
653 				gameSys.insertSequence(0x11C, 1, _currKidSequenceId, 1, kSeqSyncWait, 0, 0, 0);
654 				gameSys.setAnimation(_nextKidSequenceId, 1, 4);
655 				_currKidSequenceId = _nextKidSequenceId;
656 				_nextKidSequenceId = -1;
657 				_vm->_timers[5] = _vm->getRandom(30) + 20;
658 				gnap._actionStatus = -1;
659 				_vm->clearFlag(kGFGnapControlsToyUFO);
660 				updateHotspots();
661 			}
662 			break;
663 		}
664 	}
665 
666 	if (gameSys.getAnimationStatus(2) == 2) {
667 		switch (_vm->_toyUfoActionStatus) {
668 		case kAS41ToyUfoLeaveScene:
669 			_vm->_sceneDone = true;
670 			break;
671 		case kAS41UfoGumAttached:
672 			_vm->_toyUfoNextSequenceId = 0x873;
673 			gameSys.insertSequence(0x10873, _vm->_toyUfoId, _vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId,
674 				kSeqSyncWait, 0, _vm->_toyUfoX - 365, _vm->_toyUfoY - 128);
675 			_vm->_toyUfoSequenceId = _vm->_toyUfoNextSequenceId;
676 			gameSys.setAnimation(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId, 2);
677 			_vm->toyUfoSetStatus(kGFJointTaken);
678 			break;
679 		default:
680 			_vm->_toyUfoNextSequenceId = _vm->toyUfoGetSequenceId();
681 			gameSys.insertSequence(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId + 1, _vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId,
682 				kSeqSyncWait, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
683 			_vm->_toyUfoSequenceId = _vm->_toyUfoNextSequenceId;
684 			++_vm->_toyUfoId;
685 			gameSys.setAnimation(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId, 2);
686 			break;
687 		}
688 		_vm->_toyUfoActionStatus = -1;
689 	}
690 
691 	if (gameSys.getAnimationStatus(3) == 2 && _nextToyVendorSequenceId != -1) {
692 		gameSys.insertSequence(_nextToyVendorSequenceId, 1, _currToyVendorSequenceId, 1, kSeqSyncWait, 0, 0, 0);
693 		gameSys.setAnimation(_nextToyVendorSequenceId, 1, 3);
694 		_currToyVendorSequenceId = _nextToyVendorSequenceId;
695 		_nextToyVendorSequenceId = -1;
696 		_vm->_timers[4] = _vm->getRandom(100) + 100;
697 	}
698 
699 	if (gameSys.getAnimationStatus(4) == 2 && _nextKidSequenceId != -1) {
700 		gameSys.insertSequence(_nextKidSequenceId, 1, _currKidSequenceId, 1, kSeqSyncWait, 0, 0, 0);
701 		gameSys.setAnimation(_nextKidSequenceId, 1, 4);
702 		_currKidSequenceId = _nextKidSequenceId;
703 		_nextKidSequenceId = -1;
704 		_vm->_timers[5] = _vm->getRandom(30) + 20;
705 		if (_currKidSequenceId == 0x11E) {
706 			_vm->_toyUfoActionStatus = kAS41ToyUfoRefresh;
707 			_vm->toyUfoFlyTo(_vm->getRandom(300) + 500, _vm->getRandom(225) + 75, 0, 799, 0, 300, 2);
708 		}
709 	}
710 }
711 
712 /*****************************************************************************/
713 
Scene42(GnapEngine * vm)714 Scene42::Scene42(GnapEngine *vm) : Scene(vm) {
715 	_currBBQVendorSequenceId = -1;
716 	_nextBBQVendorSequenceId = -1;
717 }
718 
init()719 int Scene42::init() {
720 	GameSys& gameSys = *_vm->_gameSys;
721 
722 	gameSys.setAnimation(0, 0, 0);
723 	gameSys.setAnimation(0, 0, 1);
724 	gameSys.setAnimation(0, 0, 2);
725 	if (_vm->isFlag(kGFPictureTaken) || (_vm->isFlag(kGFUnk18) && _vm->isFlag(kGFUnk23)))
726 		return 0x153;
727 	return 0x152;
728 }
729 
updateHotspots()730 void Scene42::updateHotspots() {
731 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
732 		_vm->setHotspot(kHS42Platypus, 0, 0, 0, 0, SF_DISABLED);
733 		_vm->setHotspot(kHS42UfoExitLeft, 0, 0, 10, 599, SF_EXIT_L_CURSOR);
734 		_vm->setHotspot(kHS42UfoExitRight, 790, 0, 799, 599, SF_EXIT_R_CURSOR);
735 		_vm->setHotspot(kHS42UfoHotSauce, 335, 110, 440, 175, SF_DISABLED);
736 		_vm->setDeviceHotspot(kHS42UfoDevice, -1, 534, -1, 599);
737 		if ((_vm->isFlag(kGFPictureTaken) || _vm->isFlag(kGFUnk18)) && _vm->isFlag(kGFUnk23) && !_vm->isFlag(kGFUnk24))
738 			_vm->_hotspots[kHS42UfoHotSauce]._flags = SF_GRAB_CURSOR;
739 		_vm->_hotspotsCount = 5;
740 	} else {
741 		_vm->setHotspot(kHS42Platypus, 0, 0, 0, 0, SF_WALKABLE | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
742 		_vm->setHotspot(kHS42ExitUfoParty, 150, 585, 650, 600, SF_EXIT_D_CURSOR | SF_WALKABLE, 5, 9);
743 		_vm->setHotspot(kHS42ExitToyStand, 0, 100, 10, 599, SF_EXIT_L_CURSOR, 0, 8);
744 		_vm->setHotspot(kHS42ExitUfo, 790, 100, 799, 599, SF_EXIT_R_CURSOR, 10, 8);
745 		_vm->setHotspot(kHS42BBQVendor, 410, 200, 520, 365, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR, 4, 8);
746 		_vm->setHotspot(kHS42ChickenLeg, 530, 340, 620, 430, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR, 8, 7);
747 		_vm->setHotspot(kHS42WalkArea1, 0, 0, 800, 445);
748 		_vm->setHotspot(kHS42WalkArea2, 240, 0, 550, 495);
749 		_vm->setDeviceHotspot(kHS42Device, -1, -1, -1, -1);
750 		_vm->_hotspotsCount = 9;
751 	}
752 }
753 
run()754 void Scene42::run() {
755 	GameSys& gameSys = *_vm->_gameSys;
756 	PlayerGnap& gnap = *_vm->_gnap;
757 	PlayerPlat& plat = *_vm->_plat;
758 
759 	_vm->queueInsertDeviceIcon();
760 
761 	_currBBQVendorSequenceId = 0x14A;
762 	_nextBBQVendorSequenceId = -1;
763 
764 	gameSys.setAnimation(0x14A, 1, 2);
765 	gameSys.insertSequence(_currBBQVendorSequenceId, 1, 0, 0, kSeqNone, 0, 0, 0);
766 
767 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
768 		_vm->_toyUfoId = 0;
769 		_vm->_toyUfoActionStatus = -1;
770 		if (_vm->_prevSceneNum == 43 && _vm->isFlag(kGFUnk18)) {
771 			_vm->_toyUfoSequenceId = 0x872;
772 			_vm->_toyUfoNextSequenceId = _vm->toyUfoGetSequenceId();
773 			gameSys.insertSequence(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 0, 0, kSeqNone, 0, 0, 0);
774 			_vm->_toyUfoX = 317;
775 			_vm->_toyUfoY = 61;
776 			_vm->toyUfoSetStatus(kGFJointTaken);
777 			_vm->setFlag(kGFPictureTaken);
778 			_vm->_timers[9] = 600;
779 		} else {
780 			_vm->_toyUfoSequenceId = _vm->toyUfoGetSequenceId();
781 			_vm->_toyUfoNextSequenceId = _vm->_toyUfoSequenceId;
782 			if (_vm->_prevSceneNum == 41)
783 				_vm->_toyUfoX = 30;
784 			else
785 				_vm->_toyUfoX = 770;
786 			gameSys.insertSequence(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 0, 0, kSeqNone, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
787 		}
788 		gameSys.setAnimation(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 3);
789 		_vm->endSceneInit();
790 		if (_vm->_toyUfoSequenceId == 0x872)
791 			_vm->setGrabCursorSprite(-1);
792 	} else if (_vm->_prevSceneNum == 41) {
793 		gnap.initPos(-1, 8, kDirUpRight);
794 		plat.initPos(-1, 9, kDirUpLeft);
795 		_vm->endSceneInit();
796 		gnap.walkTo(Common::Point(2, 8), -1, 0x107B9, 1);
797 		plat.walkTo(Common::Point(1, 8), -1, 0x107C2, 1);
798 	} else if (_vm->_prevSceneNum == 43) {
799 		gnap.initPos(11, 8, kDirUpRight);
800 		plat.initPos(11, 9, kDirUpLeft);
801 		_vm->endSceneInit();
802 		gnap.walkTo(Common::Point(8, 8), -1, 0x107BA, 1);
803 		plat.walkTo(Common::Point(9, 8), -1, 0x107D2, 1);
804 	} else {
805 		gnap.initPos(5, 11, kDirUpRight);
806 		plat.initPos(6, 11, kDirUpLeft);
807 		_vm->endSceneInit();
808 		gnap.walkTo(Common::Point(5, 8), -1, 0x107BA, 1);
809 		plat.walkTo(Common::Point(6, 8), -1, 0x107C2, 1);
810 	}
811 
812 	while (!_vm->_sceneDone) {
813 		if (!_vm->isSoundPlaying(0x1094B))
814 			_vm->playSound(0x1094B, true);
815 
816 		_vm->updateMouseCursor();
817 		_vm->updateCursorByHotspot();
818 
819 		_vm->testWalk(0, 0, -1, -1, -1, -1);
820 
821 		_vm->_sceneClickedHotspot = _vm->getClickedHotspotId();
822 		_vm->updateGrabCursorSprite(0, 0);
823 
824 		if (_vm->isFlag(kGFGnapControlsToyUFO)) {
825 			switch (_vm->_sceneClickedHotspot) {
826 			case kHS42UfoExitLeft:
827 				if (_vm->_toyUfoActionStatus < 0) {
828 					_vm->_isLeavingScene = true;
829 					_vm->_toyUfoActionStatus = kAS42ToyUfoLeaveScene;
830 					_vm->_newSceneNum = 41;
831 					_vm->toyUfoFlyTo(-35, -1, -35, 799, 0, 300, 3);
832 				}
833 				break;
834 
835 			case kHS42UfoExitRight:
836 				if (_vm->_toyUfoActionStatus < 0) {
837 					_vm->_isLeavingScene = true;
838 					_vm->_toyUfoActionStatus = kAS42ToyUfoLeaveScene;
839 					_vm->_newSceneNum = 43;
840 					_vm->toyUfoFlyTo(835, -1, 0, 835, 0, 300, 3);
841 				}
842 				break;
843 
844 			case kHS42UfoHotSauce:
845 				if (_vm->isFlag(kGFJointTaken)) {
846 					_vm->_toyUfoActionStatus = kAS42ToyUfoPickUpHotSauce;
847 					_vm->toyUfoFlyTo(384, 77, 0, 799, 0, 300, 3);
848 					_vm->_timers[9] = 600;
849 				} else {
850 					_vm->_toyUfoActionStatus = kAS42ToyUfoRefresh;
851 					_vm->toyUfoFlyTo(-1, -1, 0, 799, 0, 300, 3);
852 				}
853 				break;
854 
855 			case kHS42UfoDevice:
856 				_vm->runMenu();
857 				updateHotspots();
858 				break;
859 			}
860 		} else {
861 			switch (_vm->_sceneClickedHotspot) {
862 			case kHS42Device:
863 				_vm->runMenu();
864 				updateHotspots();
865 				_vm->_timers[4] = _vm->getRandom(20) + 30;
866 				break;
867 
868 			case kHS42Platypus:
869 				if (gnap._actionStatus < 0) {
870 					if (_vm->_grabCursorSpriteIndex >= 0) {
871 						gnap.playImpossible(plat._pos);
872 					} else {
873 						switch (_vm->_verbCursor) {
874 						case LOOK_CURSOR:
875 							gnap.playMoan1(plat._pos);
876 							break;
877 						case GRAB_CURSOR:
878 							gnap.kissPlatypus(0);
879 							break;
880 						case TALK_CURSOR:
881 							gnap.playBrainPulsating(plat._pos);
882 							plat.playSequence(plat.getSequenceId());
883 							break;
884 						case PLAT_CURSOR:
885 							gnap.playImpossible(plat._pos);
886 							break;
887 						}
888 					}
889 				}
890 				break;
891 
892 			case kHS42ExitUfoParty:
893 				_vm->_isLeavingScene = true;
894 				gnap.walkTo(Common::Point(gnap._pos.x, _vm->_hotspotsWalkPos[kHS42ExitUfoParty].y), 0, 0x107AE, 1);
895 				gnap._actionStatus = kAS42LeaveScene;
896 				plat.walkTo(Common::Point(plat._pos.x, _vm->_hotspotsWalkPos[kHS42ExitUfoParty].y), -1, 0x107C7, 1);
897 				_vm->_newSceneNum = 40;
898 				break;
899 
900 			case kHS42ExitToyStand:
901 				_vm->_isLeavingScene = true;
902 				gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS42ExitToyStand].x, gnap._pos.y), 0, 0x107AF, 1);
903 				gnap._actionStatus = kAS42LeaveScene;
904 				plat.walkTo(_vm->_hotspotsWalkPos[kHS42ExitToyStand], -1, 0x107CF, 1);
905 				_vm->_newSceneNum = 41;
906 				break;
907 
908 			case kHS42ExitUfo:
909 				_vm->_isLeavingScene = true;
910 				gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS42ExitUfo].x, gnap._pos.y), 0, 0x107AB, 1);
911 				gnap._actionStatus = kAS42LeaveScene;
912 				plat.walkTo(_vm->_hotspotsWalkPos[kHS42ExitUfo], -1, 0x107CD, 1);
913 				_vm->_newSceneNum = 43;
914 				break;
915 
916 			case kHS42BBQVendor:
917 				if (_vm->_grabCursorSpriteIndex == kItemDiceQuarterHole) {
918 					gnap.walkTo(_vm->_hotspotsWalkPos[kHS42BBQVendor], 0, 0x107BB, 1);
919 					gnap._actionStatus = kAS42UseQuarterWithBBQVendor;
920 					if (plat._pos.y < 9)
921 						plat.walkTo(Common::Point(plat._pos.x, 9), -1, -1, 1);
922 				} else if (_vm->_grabCursorSpriteIndex >= 0) {
923 					gnap.playShowCurrItem(_vm->_hotspotsWalkPos[kHS42BBQVendor], _vm->_hotspotsWalkPos[kHS42BBQVendor].x + 1, 0);
924 				} else {
925 					switch (_vm->_verbCursor) {
926 					case LOOK_CURSOR:
927 						gnap.playScratchingHead(Common::Point(_vm->_hotspotsWalkPos[kHS42BBQVendor].x - 1, 0));
928 						break;
929 					case TALK_CURSOR:
930 						gnap._idleFacing = kDirUpRight;
931 						gnap.walkTo(_vm->_hotspotsWalkPos[kHS42BBQVendor], 0, gnap.getSequenceId(kGSBrainPulsating, Common::Point(0, 0)) | 0x10000, 1);
932 						gnap._actionStatus = kAS42TalkBBQVendor;
933 						break;
934 					case GRAB_CURSOR:
935 					case PLAT_CURSOR:
936 						gnap.playImpossible();
937 						break;
938 					}
939 				}
940 				break;
941 
942 			case kHS42ChickenLeg:
943 				if (_vm->_grabCursorSpriteIndex >= 0) {
944 					gnap.playShowCurrItem(_vm->_hotspotsWalkPos[kHS42ChickenLeg], _vm->_hotspotsWalkPos[kHS42ChickenLeg].x - 1, 0);
945 				} else {
946 					switch (_vm->_verbCursor) {
947 					case LOOK_CURSOR:
948 						gnap.playScratchingHead(Common::Point(_vm->_hotspotsWalkPos[kHS42ChickenLeg].x - 1, 0));
949 						break;
950 					case GRAB_CURSOR:
951 						gnap.walkTo(_vm->_hotspotsWalkPos[kHS42ChickenLeg], 0, 0x107BC, 1);
952 						gnap._actionStatus = kAS42GrabChickenLeg;
953 						break;
954 					case TALK_CURSOR:
955 					case PLAT_CURSOR:
956 						gnap.playImpossible();
957 						break;
958 					}
959 				}
960 				break;
961 
962 			case kHS42WalkArea1:
963 			case kHS42WalkArea2:
964 				if (gnap._actionStatus < 0)
965 					gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
966 				break;
967 
968 			}
969 		}
970 
971 		if (_vm->_mouseClickState._left && gnap._actionStatus < 0) {
972 			_vm->_mouseClickState._left = false;
973 			if (_vm->isFlag(kGFGnapControlsToyUFO)) {
974 				_vm->_toyUfoActionStatus = kAS42ToyUfoRefresh;
975 				_vm->toyUfoFlyTo(-1, -1, 0, 799, 0, 300, 3);
976 			} else {
977 				gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
978 			}
979 		}
980 
981 		updateAnimations();
982 
983 		_vm->toyUfoCheckTimer();
984 
985 		if (!_vm->_isLeavingScene) {
986 			if (plat._actionStatus < 0 && !_vm->isFlag(kGFGnapControlsToyUFO))
987 				plat.updateIdleSequence();
988 			if (gnap._actionStatus < 0 && !_vm->isFlag(kGFGnapControlsToyUFO))
989 				gnap.updateIdleSequence();
990 			if (!_vm->_timers[4]) {
991 				_vm->_timers[4] = _vm->getRandom(20) + 30;
992 				if (gnap._actionStatus < 0 && plat._actionStatus < 0 && _nextBBQVendorSequenceId == -1) {
993 					switch (_vm->getRandom(8)) {
994 					case 0:
995 						_nextBBQVendorSequenceId = 0x14C;
996 						break;
997 					case 1:
998 					case 2:
999 						_nextBBQVendorSequenceId = 0x149;
1000 						break;
1001 					case 3:
1002 					case 4:
1003 					case 5:
1004 					case 6:
1005 						_nextBBQVendorSequenceId = 0x14D;
1006 						break;
1007 					case 7:
1008 						_nextBBQVendorSequenceId = 0x14A;
1009 						break;
1010 					}
1011 					if (_nextBBQVendorSequenceId == _currBBQVendorSequenceId && _nextBBQVendorSequenceId != 0x14D)
1012 						_nextBBQVendorSequenceId = -1;
1013 				}
1014 			}
1015 		}
1016 
1017 		_vm->checkGameKeys();
1018 
1019 		if (_vm->isKeyStatus1(Common::KEYCODE_BACKSPACE)) {
1020 			_vm->clearKeyStatus1(Common::KEYCODE_BACKSPACE);
1021 			_vm->runMenu();
1022 			updateHotspots();
1023 			_vm->_timers[4] = _vm->getRandom(20) + 30;
1024 		}
1025 
1026 		_vm->gameUpdateTick();
1027 	}
1028 }
1029 
updateAnimations()1030 void Scene42::updateAnimations() {
1031 	GameSys& gameSys = *_vm->_gameSys;
1032 	PlayerGnap& gnap = *_vm->_gnap;
1033 
1034 	if (gameSys.getAnimationStatus(0) == 2) {
1035 		switch (gnap._actionStatus) {
1036 		case kAS42LeaveScene:
1037 			gameSys.setAnimation(0, 0, 0);
1038 			gnap._actionStatus = -1;
1039 			_vm->_sceneDone = true;
1040 			break;
1041 		case kAS42TalkBBQVendor:
1042 			gameSys.setAnimation(0, 0, 0);
1043 			gnap._actionStatus = -1;
1044 			_nextBBQVendorSequenceId = 0x14B;
1045 			break;
1046 		case kAS42UseQuarterWithBBQVendor:
1047 		case kAS42GrabChickenLeg:
1048 			if (gameSys.getAnimationStatus(2) == 2) {
1049 				int sequenceId;
1050 				if (gnap._actionStatus == kAS42UseQuarterWithBBQVendor) {
1051 					_vm->invRemove(kItemDiceQuarterHole);
1052 					_vm->invAdd(kItemChickenBucket);
1053 					_vm->setGrabCursorSprite(-1);
1054 					sequenceId = 0x150;
1055 					_nextBBQVendorSequenceId = 0x148;
1056 				} else if (_vm->isFlag(kGFUnk27)) {
1057 					if (_vm->isFlag(kGFUnk28)) {
1058 						sequenceId = 0x7B7;
1059 						_nextBBQVendorSequenceId = 0x145;
1060 					} else {
1061 						_vm->setFlag(kGFUnk28);
1062 						sequenceId = 0x14F;
1063 						_nextBBQVendorSequenceId = 0x147;
1064 					}
1065 				} else {
1066 					_vm->setFlag(kGFUnk27);
1067 					sequenceId = 0x14E;
1068 					_nextBBQVendorSequenceId = 0x146;
1069 				}
1070 				if (sequenceId == 0x7B7) {
1071 					gameSys.insertSequence(0x107B7, gnap._id,
1072 						makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id,
1073 						kSeqSyncWait, _vm->getSequenceTotalDuration(_nextBBQVendorSequenceId),
1074 						75 * gnap._pos.x - gnap._gridX, 48 * gnap._pos.y - gnap._gridY);
1075 					gnap._sequenceDatNum = 1;
1076 				} else {
1077 					gameSys.insertSequence(sequenceId, gnap._id,
1078 						makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id,
1079 						kSeqSyncWait, 0, 0, 0);
1080 					gnap._sequenceDatNum = 0;
1081 				}
1082 				gnap._sequenceId = sequenceId;
1083 				gameSys.setAnimation(sequenceId | (gnap._sequenceDatNum << 16), gnap._id, 0);
1084 				if (gnap._actionStatus == kAS42UseQuarterWithBBQVendor)
1085 					gnap._actionStatus = kAS42UseQuarterWithBBQVendorDone;
1086 				else
1087 					gnap._actionStatus = -1;
1088 				gameSys.insertSequence(_nextBBQVendorSequenceId, 1, _currBBQVendorSequenceId, 1, kSeqSyncWait, 0, 0, 0);
1089 				gameSys.setAnimation(_nextBBQVendorSequenceId, 1, 2);
1090 				_currBBQVendorSequenceId = _nextBBQVendorSequenceId;
1091 				if (_nextBBQVendorSequenceId == 0x145)
1092 					_nextBBQVendorSequenceId = 0x14A;
1093 				else
1094 					_nextBBQVendorSequenceId = -1;
1095 				_vm->_timers[4] = _vm->getRandom(20) + 30;
1096 				_vm->_timers[2] = _vm->getRandom(30) + 20;
1097 				_vm->_timers[3] = _vm->getRandom(50) + 200;
1098 			}
1099 			break;
1100 		case kAS42UseQuarterWithBBQVendorDone:
1101 			gameSys.setAnimation(0, 0, 0);
1102 			_vm->setGrabCursorSprite(kItemChickenBucket);
1103 			gnap._actionStatus = -1;
1104 			break;
1105 		default:
1106 			gameSys.setAnimation(0, 0, 0);
1107 			gnap._actionStatus = -1;
1108 			break;
1109 		}
1110 	}
1111 
1112 	if (gameSys.getAnimationStatus(2) == 2 && _nextBBQVendorSequenceId != -1) {
1113 		gameSys.insertSequence(_nextBBQVendorSequenceId, 1, _currBBQVendorSequenceId, 1, kSeqSyncWait, 0, 0, 0);
1114 		gameSys.setAnimation(_nextBBQVendorSequenceId, 1, 2);
1115 		_currBBQVendorSequenceId = _nextBBQVendorSequenceId;
1116 		_nextBBQVendorSequenceId = -1;
1117 		_vm->_timers[4] = _vm->getRandom(20) + 30;
1118 	}
1119 
1120 	if (gameSys.getAnimationStatus(3) == 2) {
1121 		switch (_vm->_toyUfoActionStatus) {
1122 		case kAS42ToyUfoLeaveScene:
1123 			_vm->_sceneDone = true;
1124 			break;
1125 		case kAS42ToyUfoPickUpHotSauce:
1126 			gameSys.insertSequence(0x10870, _vm->_toyUfoId, _vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, kSeqSyncWait, 0, 0, 0);
1127 			_vm->setFlag(kGFUnk24);
1128 			updateHotspots();
1129 			_vm->toyUfoSetStatus(kGFGroceryStoreHatTaken);
1130 			_vm->_toyUfoSequenceId = 0x870;
1131 			gameSys.setAnimation(0x10870, _vm->_toyUfoId, 3);
1132 			_vm->_toyUfoActionStatus = -1;
1133 			_vm->_toyUfoX = 0x181;
1134 			_vm->_toyUfoY = 53;
1135 			break;
1136 		default:
1137 			if (_vm->_toyUfoSequenceId == 0x872) {
1138 				_vm->hideCursor();
1139 				_vm->addFullScreenSprite(0x13E, 255);
1140 				gameSys.setAnimation(0x151, 256, 0);
1141 				gameSys.insertSequence(0x151, 256, 0, 0, kSeqNone, 0, 0, 0);
1142 				while (gameSys.getAnimationStatus(0) != 2 && !_vm->_gameDone)
1143 					_vm->gameUpdateTick();
1144 				_vm->removeFullScreenSprite();
1145 				_vm->showCursor();
1146 			}
1147 			_vm->_toyUfoNextSequenceId = _vm->toyUfoGetSequenceId();
1148 			gameSys.setAnimation(_vm->_toyUfoNextSequenceId | 0x10000, (_vm->_toyUfoId + 1) % 10, 3);
1149 			gameSys.insertSequence(_vm->_toyUfoNextSequenceId | 0x10000, (_vm->_toyUfoId + 1) % 10,
1150 				_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId,
1151 				kSeqSyncWait, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
1152 			_vm->_toyUfoSequenceId = _vm->_toyUfoNextSequenceId;
1153 			_vm->_toyUfoId = (_vm->_toyUfoId + 1) % 10;
1154 			break;
1155 		}
1156 		_vm->_toyUfoActionStatus = -1;
1157 	}
1158 }
1159 
1160 /*****************************************************************************/
1161 
Scene43(GnapEngine * vm)1162 Scene43::Scene43(GnapEngine *vm) : Scene(vm) {
1163 	_currTwoHeadedGuySequenceId = -1;
1164 	_nextTwoHeadedGuySequenceId = -1;
1165 }
1166 
init()1167 int Scene43::init() {
1168 	GameSys& gameSys = *_vm->_gameSys;
1169 
1170 	gameSys.setAnimation(0, 0, 0);
1171 	gameSys.setAnimation(0, 0, 1);
1172 	gameSys.setAnimation(0, 0, 2);
1173 	return 0x13F;
1174 }
1175 
updateHotspots()1176 void Scene43::updateHotspots() {
1177 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
1178 		_vm->setHotspot(kHS43Platypus, 0, 0, 0, 0, SF_DISABLED);
1179 		_vm->setHotspot(kHS43UfoExitLeft, 0, 0, 10, 599, SF_EXIT_L_CURSOR);
1180 		_vm->setHotspot(kHS43UfoExitRight, 790, 0, 799, 599, SF_EXIT_R_CURSOR);
1181 		_vm->setHotspot(kHS43UfoKey, 140, 170, 185, 260, SF_GRAB_CURSOR);
1182 		_vm->setHotspot(kHS43UfoBucket, 475, 290, 545, 365, SF_DISABLED);
1183 		_vm->setDeviceHotspot(kHS43UfoDevice, -1, 534, -1, 599);
1184 		if (_vm->isFlag(kGFGroceryStoreHatTaken))
1185 			_vm->_hotspots[kHS43UfoBucket]._flags = SF_GRAB_CURSOR;
1186 		// NOTE Bug in the original. Key hotspot wasn't disabled.
1187 		if (_vm->isFlag(kGFUnk14))
1188 			_vm->_hotspots[kHS43UfoKey]._flags = SF_DISABLED;
1189 		_vm->_hotspotsCount = 6;
1190 	} else {
1191 		_vm->setHotspot(kHS43Platypus, 0, 0, 0, 0, SF_WALKABLE | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
1192 		_vm->setHotspot(kHS43ExitUfoParty, 150, 580, 650, 600, SF_EXIT_D_CURSOR | SF_WALKABLE, 5, 9);
1193 		_vm->setHotspot(kHS43ExitBBQ, 0, 100, 10, 599, SF_EXIT_L_CURSOR, 0, 8);
1194 		_vm->setHotspot(kHS43ExitKissinBooth, 790, 100, 799, 599, SF_EXIT_R_CURSOR, 10, 8);
1195 		_vm->setHotspot(kHS43TwoHeadedGuy, 470, 240, 700, 470, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
1196 		_vm->setHotspot(kHS43Key, 140, 170, 185, 260, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
1197 		_vm->setHotspot(kHS43Ufo, 110, 0, 690, 350, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
1198 		_vm->setHotspot(kHS43WalkArea1, 0, 0, 800, 445);
1199 		_vm->setHotspot(kHS43WalkArea2, 465, 0, 800, 493);
1200 		_vm->setDeviceHotspot(kHS43Device, -1, -1, -1, -1);
1201 		if (_vm->isFlag(kGFUnk14))
1202 			_vm->_hotspots[kHS43Key]._flags = SF_DISABLED;
1203 		_vm->_hotspotsCount = 10;
1204 	}
1205 }
1206 
run()1207 void Scene43::run() {
1208 	GameSys& gameSys = *_vm->_gameSys;
1209 	PlayerGnap& gnap = *_vm->_gnap;
1210 	PlayerPlat& plat = *_vm->_plat;
1211 
1212 	_vm->queueInsertDeviceIcon();
1213 
1214 	if (!_vm->isFlag(kGFUnk14))
1215 		gameSys.insertSequence(0x1086F, 1, 0, 0, kSeqNone, 0, 0, 0);
1216 
1217 	_currTwoHeadedGuySequenceId = 0x13C;
1218 	_nextTwoHeadedGuySequenceId = -1;
1219 
1220 	gameSys.setAnimation(0x13C, 1, 2);
1221 	gameSys.insertSequence(_currTwoHeadedGuySequenceId, 1, 0, 0, kSeqNone, 0, 0, 0);
1222 
1223 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
1224 		_vm->_toyUfoId = 0;
1225 		_vm->_toyUfoActionStatus = -1;
1226 		_vm->_toyUfoSequenceId = _vm->toyUfoGetSequenceId();
1227 		_vm->_toyUfoNextSequenceId = _vm->_toyUfoSequenceId;
1228 		if (_vm->_prevSceneNum == 42)
1229 			_vm->_toyUfoX = 30;
1230 		else
1231 			_vm->_toyUfoX = 770;
1232 		gameSys.setAnimation(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 3);
1233 		gameSys.insertSequence(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 0, 0, kSeqNone, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
1234 		_vm->endSceneInit();
1235 	} else {
1236 		switch (_vm->_prevSceneNum) {
1237 		case 42:
1238 			gnap.initPos(-1, 8, kDirUpRight);
1239 			plat.initPos(-1, 9, kDirUpLeft);
1240 			_vm->endSceneInit();
1241 			gnap.walkTo(Common::Point(2, 8), -1, 0x107B9, 1);
1242 			plat.walkTo(Common::Point(1, 8), -1, 0x107C2, 1);
1243 			break;
1244 		case 44:
1245 			gnap.initPos(11, 8, kDirUpRight);
1246 			plat.initPos(11, 9, kDirUpLeft);
1247 			_vm->endSceneInit();
1248 			gnap.walkTo(Common::Point(8, 8), -1, 0x107BA, 1);
1249 			plat.walkTo(Common::Point(9, 8), -1, 0x107D2, 1);
1250 			break;
1251 		case 54:
1252 			gnap.initPos(4, 7, kDirBottomLeft);
1253 			plat.initPos(11, 8, kDirUpLeft);
1254 			_vm->endSceneInit();
1255 			plat.walkTo(Common::Point(9, 8), -1, 0x107D2, 1);
1256 			break;
1257 		default:
1258 			gnap.initPos(5, 11, kDirUpRight);
1259 			plat.initPos(6, 11, kDirUpLeft);
1260 			_vm->endSceneInit();
1261 			gnap.walkTo(Common::Point(5, 8), -1, 0x107BA, 1);
1262 			plat.walkTo(Common::Point(6, 8), -1, 0x107C2, 1);
1263 			break;
1264 		}
1265 	}
1266 
1267 	while (!_vm->_sceneDone) {
1268 		if (!_vm->isSoundPlaying(0x1094B))
1269 			_vm->playSound(0x1094B, true);
1270 
1271 		_vm->updateMouseCursor();
1272 		_vm->updateCursorByHotspot();
1273 
1274 		_vm->testWalk(0, 0, -1, -1, -1, -1);
1275 
1276 		_vm->_sceneClickedHotspot = _vm->getClickedHotspotId();
1277 		_vm->updateGrabCursorSprite(0, 0);
1278 
1279 		if (_vm->isFlag(kGFGnapControlsToyUFO)) {
1280 			switch (_vm->_sceneClickedHotspot) {
1281 			case kHS43UfoDevice:
1282 				_vm->runMenu();
1283 				updateHotspots();
1284 				_vm->_timers[4] = _vm->getRandom(100) + 100;
1285 				break;
1286 
1287 			case kHS43UfoExitLeft:
1288 				if (_vm->_toyUfoActionStatus < 0) {
1289 					_vm->_isLeavingScene = true;
1290 					_vm->_toyUfoActionStatus = 4;
1291 					_vm->_newSceneNum = 42;
1292 					_vm->toyUfoFlyTo(-35, -1, -35, 799, 0, 300, 3);
1293 				}
1294 				break;
1295 
1296 			case kHS43UfoExitRight:
1297 				if (_vm->_toyUfoActionStatus < 0) {
1298 					_vm->_isLeavingScene = true;
1299 					_vm->_toyUfoActionStatus = 4;
1300 					_vm->_newSceneNum = 44;
1301 					_vm->toyUfoFlyTo(835, -1, 0, 835, 0, 300, 3);
1302 				}
1303 				break;
1304 
1305 			case kHS43UfoKey:
1306 				if (_vm->isFlag(kGFJointTaken)) {
1307 					_vm->_toyUfoActionStatus = 6;
1308 					_vm->toyUfoFlyTo(163, 145, 0, 799, 0, 300, 3);
1309 				} else {
1310 					_vm->_toyUfoActionStatus = 5;
1311 					_vm->toyUfoFlyTo(-1, -1, 0, 799, 0, 300, 3);
1312 				}
1313 				break;
1314 
1315 			case kHS43UfoBucket:
1316 				_vm->_toyUfoActionStatus = 7;
1317 				_vm->toyUfoFlyTo(497, 143, 0, 799, 0, 300, 3);
1318 				_vm->_timers[9] = 600;
1319 				break;
1320 			}
1321 		} else {
1322 			switch (_vm->_sceneClickedHotspot) {
1323 			case kHS43Device:
1324 				_vm->runMenu();
1325 				updateHotspots();
1326 				_vm->_timers[4] = _vm->getRandom(100) + 100;
1327 				break;
1328 
1329 			case kHS43Platypus:
1330 				if (gnap._actionStatus < 0) {
1331 					if (_vm->_grabCursorSpriteIndex >= 0) {
1332 						gnap.playImpossible(plat._pos);
1333 					} else {
1334 						switch (_vm->_verbCursor) {
1335 						case LOOK_CURSOR:
1336 							gnap.playMoan1(plat._pos);
1337 							break;
1338 						case GRAB_CURSOR:
1339 							gnap.kissPlatypus(0);
1340 							break;
1341 						case TALK_CURSOR:
1342 							gnap.playBrainPulsating(plat._pos);
1343 							plat.playSequence(plat.getSequenceId());
1344 							break;
1345 						case PLAT_CURSOR:
1346 							gnap.playImpossible(plat._pos);
1347 							break;
1348 						}
1349 					}
1350 				}
1351 				break;
1352 
1353 			case kHS43ExitUfoParty:
1354 				_vm->_isLeavingScene = true;
1355 				gnap.walkTo(_vm->_hotspotsWalkPos[kHS43ExitUfoParty], 0, 0x107AE, 1);
1356 				gnap._actionStatus = 0;
1357 				plat.walkTo(_vm->_hotspotsWalkPos[kHS43ExitUfoParty], -1, 0x107C7, 1);
1358 				_vm->_newSceneNum = 40;
1359 				break;
1360 
1361 			case kHS43ExitBBQ:
1362 				_vm->_isLeavingScene = true;
1363 				gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS43ExitBBQ].x, gnap._pos.y), 0, 0x107AF, 1);
1364 				gnap._actionStatus = 0;
1365 				plat.walkTo(_vm->_hotspotsWalkPos[kHS43ExitBBQ], -1, 0x107CF, 1);
1366 				_vm->_newSceneNum = 42;
1367 				break;
1368 
1369 			case kHS43ExitKissinBooth:
1370 				_vm->_isLeavingScene = true;
1371 				gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS43ExitKissinBooth].x, gnap._pos.y), 0, 0x107AB, 1);
1372 				gnap._actionStatus = 0;
1373 				plat.walkTo(_vm->_hotspotsWalkPos[kHS43ExitKissinBooth], -1, 0x107CD, 1);
1374 				_vm->_newSceneNum = 44;
1375 				break;
1376 
1377 			case kHS43TwoHeadedGuy:
1378 				if (_vm->_grabCursorSpriteIndex >= 0) {
1379 					gnap.playShowCurrItem(Common::Point(6, 8), 7, 0);
1380 				} else {
1381 					switch (_vm->_verbCursor) {
1382 					case LOOK_CURSOR:
1383 						gnap.playScratchingHead(Common::Point(7, 0));
1384 						break;
1385 					case TALK_CURSOR:
1386 							gnap._idleFacing = kDirUpRight;
1387 							gnap.walkTo(Common::Point(5, 8), 0, gnap.getSequenceId(kGSBrainPulsating, Common::Point(0, 0)) | 0x10000, 1);
1388 							gnap._actionStatus = 2;
1389 						break;
1390 					case GRAB_CURSOR:
1391 					case PLAT_CURSOR:
1392 						gnap.playImpossible();
1393 						break;
1394 					}
1395 				}
1396 				break;
1397 
1398 			case kHS43Key:
1399 			case kHS43Ufo:
1400 				if (_vm->_grabCursorSpriteIndex >= 0) {
1401 					gnap.playShowCurrItem(Common::Point(3, 7), 2, 0);
1402 				} else {
1403 					switch (_vm->_verbCursor) {
1404 					case LOOK_CURSOR:
1405 						gnap.playScratchingHead();
1406 						break;
1407 					case GRAB_CURSOR:
1408 						gnap._idleFacing = kDirUpRight;
1409 						gnap.walkTo(Common::Point(3, 7), 0, 67515, 1);
1410 						gnap._actionStatus = 1;
1411 						break;
1412 					case TALK_CURSOR:
1413 					case PLAT_CURSOR:
1414 						gnap.playImpossible();
1415 						break;
1416 					}
1417 				}
1418 				break;
1419 
1420 			case kHS43WalkArea1:
1421 			case kHS43WalkArea2:
1422 				if (gnap._actionStatus < 0)
1423 					gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
1424 				break;
1425 			}
1426 		}
1427 
1428 		if (_vm->_mouseClickState._left && gnap._actionStatus < 0) {
1429 			_vm->_mouseClickState._left = false;
1430 			if (_vm->isFlag(kGFGnapControlsToyUFO) && (_vm->_toyUfoActionStatus == 5 || _vm->_toyUfoActionStatus == -1)) {
1431 				_vm->_toyUfoActionStatus = 5;
1432 				_vm->toyUfoFlyTo(-1, -1, 0, 799, 0, 300, 3);
1433 			} else {
1434 				gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
1435 			}
1436 		}
1437 
1438 		updateAnimations();
1439 
1440 		_vm->toyUfoCheckTimer();
1441 
1442 		if (!_vm->_isLeavingScene) {
1443 			if (plat._actionStatus < 0 && !_vm->isFlag(kGFGnapControlsToyUFO))
1444 				plat.updateIdleSequence();
1445 			if (gnap._actionStatus < 0 && !_vm->isFlag(kGFGnapControlsToyUFO))
1446 				gnap.updateIdleSequence();
1447 			if (!_vm->_timers[4] && (!_vm->isFlag(kGFGnapControlsToyUFO) || !_vm->isFlag(kGFGroceryStoreHatTaken))) {
1448 				_vm->_timers[4] = _vm->getRandom(100) + 100;
1449 				if (gnap._actionStatus < 0 && plat._actionStatus < 0 && _nextTwoHeadedGuySequenceId == -1) {
1450 					switch (_vm->getRandom(5)) {
1451 					case 0:
1452 						_nextTwoHeadedGuySequenceId = 0x13C;
1453 						break;
1454 					case 1:
1455 						_nextTwoHeadedGuySequenceId = 0x134;
1456 						break;
1457 					case 2:
1458 						_nextTwoHeadedGuySequenceId = 0x135;
1459 						break;
1460 					case 3:
1461 						_nextTwoHeadedGuySequenceId = 0x136;
1462 						break;
1463 					case 4:
1464 						_nextTwoHeadedGuySequenceId = 0x13A;
1465 						break;
1466 					}
1467 					if (_nextTwoHeadedGuySequenceId == _currTwoHeadedGuySequenceId)
1468 						_nextTwoHeadedGuySequenceId = -1;
1469 				}
1470 			}
1471 		}
1472 
1473 		_vm->checkGameKeys();
1474 
1475 		if (_vm->isKeyStatus1(Common::KEYCODE_BACKSPACE)) {
1476 			_vm->clearKeyStatus1(Common::KEYCODE_BACKSPACE);
1477 			_vm->runMenu();
1478 			updateHotspots();
1479 			_vm->_timers[4] = _vm->getRandom(100) + 100;
1480 		}
1481 
1482 		_vm->gameUpdateTick();
1483 	}
1484 
1485 	if (_vm->_newSceneNum == 54)
1486 		_vm->clearFlag(kGFGnapControlsToyUFO);
1487 }
1488 
updateAnimations()1489 void Scene43::updateAnimations() {
1490 	GameSys& gameSys = *_vm->_gameSys;
1491 	PlayerGnap& gnap = *_vm->_gnap;
1492 
1493 	if (gameSys.getAnimationStatus(0) == 2) {
1494 		switch (gnap._actionStatus) {
1495 		case 0:
1496 			gameSys.setAnimation(0, 0, 0);
1497 			_vm->_sceneDone = true;
1498 			break;
1499 
1500 		case 1:
1501 			if (gameSys.getAnimationStatus(2) == 2) {
1502 				_vm->_timers[2] = _vm->getRandom(30) + 20;
1503 				_vm->_timers[3] = _vm->getRandom(50) + 200;
1504 				gameSys.insertSequence(0x13D, gnap._id, makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id, kSeqSyncWait, 0, 0, 0);
1505 				gnap._sequenceId = 0x13D;
1506 				gnap._sequenceDatNum = 0;
1507 				gameSys.setAnimation(0x13D, gnap._id, 0);
1508 				_nextTwoHeadedGuySequenceId = 0x13B;
1509 				gameSys.insertSequence(0x13B, 1, _currTwoHeadedGuySequenceId, 1, kSeqSyncWait, 0, 0, 0);
1510 				gameSys.setAnimation(_nextTwoHeadedGuySequenceId, 1, 2);
1511 				_currTwoHeadedGuySequenceId = _nextTwoHeadedGuySequenceId;
1512 				_nextTwoHeadedGuySequenceId = -1;
1513 				_vm->_timers[4] = _vm->getRandom(100) + 100;
1514 				gnap._actionStatus = -1;
1515 			}
1516 			break;
1517 
1518 		default:
1519 			gameSys.setAnimation(0, 0, 0);
1520 			gnap._actionStatus = -1;
1521 			break;
1522 		}
1523 	}
1524 
1525 	if (gameSys.getAnimationStatus(2) == 2) {
1526 		if (_currTwoHeadedGuySequenceId == 0x13A) {
1527 			if (_vm->isFlag(kGFGroceryStoreHatTaken)) {
1528 				_nextTwoHeadedGuySequenceId = 0x13E;
1529 				_vm->stopSound(0x108F6);
1530 			} else if (_vm->getRandom(2) != 0) {
1531 				_nextTwoHeadedGuySequenceId = 0x137;
1532 			} else {
1533 				_nextTwoHeadedGuySequenceId = 0x138;
1534 			}
1535 		} else if (_currTwoHeadedGuySequenceId == 0x13E) {
1536 			_vm->_sceneDone = true;
1537 			_vm->_newSceneNum = 54;
1538 		}
1539 		if (_nextTwoHeadedGuySequenceId != -1) {
1540 			gameSys.insertSequence(_nextTwoHeadedGuySequenceId, 1, _currTwoHeadedGuySequenceId, 1, kSeqSyncWait, 0, 0, 0);
1541 			gameSys.setAnimation(_nextTwoHeadedGuySequenceId, 1, 2);
1542 			_currTwoHeadedGuySequenceId = _nextTwoHeadedGuySequenceId;
1543 			_nextTwoHeadedGuySequenceId = -1;
1544 			_vm->_timers[4] = _vm->getRandom(100) + 100;
1545 		}
1546 	}
1547 
1548 	if (gameSys.getAnimationStatus(3) == 2) {
1549 		switch (_vm->_toyUfoActionStatus) {
1550 		case 4:
1551 			_vm->_sceneDone = true;
1552 			_vm->_toyUfoActionStatus = -1;
1553 			break;
1554 		case 6:
1555 			gameSys.insertSequence(0x10871, _vm->_toyUfoId, _vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, kSeqSyncWait, 0, 0, 0);
1556 			gameSys.removeSequence(0x1086F, 1, true);
1557 			_vm->setFlag(kGFUnk14);
1558 			updateHotspots();
1559 			_vm->toyUfoSetStatus(kGFUnk18);
1560 			_vm->_toyUfoSequenceId = 0x871;
1561 			gameSys.setAnimation(0x10871, _vm->_toyUfoId, 3);
1562 			_vm->_toyUfoActionStatus = -1;
1563 			_vm->_toyUfoX = 96;
1564 			_vm->_toyUfoY = 131;
1565 			break;
1566 		case 7:
1567 			gameSys.insertSequence(0x10874, _vm->_toyUfoId, _vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, kSeqSyncWait, 0, 0, 0);
1568 			_vm->_toyUfoSequenceId = 0x874;
1569 			gameSys.setAnimation(0x10874, _vm->_toyUfoId, 3);
1570 			_vm->_toyUfoActionStatus = 8;
1571 			_vm->setFlag(kGFJointTaken);
1572 			gnap._actionStatus = 3;
1573 			break;
1574 		case 8:
1575 			_nextTwoHeadedGuySequenceId = 0x13A;
1576 			_vm->_toyUfoX = 514;
1577 			_vm->_toyUfoY = 125;
1578 			_vm->toyUfoFlyTo(835, 125, 0, 835, 0, 300, 3);
1579 			_vm->_toyUfoActionStatus = 9;
1580 			break;
1581 		case 9:
1582 			// Nothing
1583 			break;
1584 		default:
1585 			_vm->_toyUfoNextSequenceId = _vm->toyUfoGetSequenceId();
1586 			gameSys.insertSequence(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId + 1,
1587 				_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId,
1588 				kSeqSyncWait, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
1589 			_vm->_toyUfoSequenceId = _vm->_toyUfoNextSequenceId;
1590 			++_vm->_toyUfoId;
1591 			gameSys.setAnimation(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId, 3);
1592 			_vm->_toyUfoActionStatus = -1;
1593 			break;
1594 		}
1595 	}
1596 }
1597 
1598 /*****************************************************************************/
1599 
Scene44(GnapEngine * vm)1600 Scene44::Scene44(GnapEngine *vm) : Scene(vm) {
1601 	_nextSpringGuySequenceId = -1;
1602 	_nextKissingLadySequenceId = -1;
1603 	_currSpringGuySequenceId = -1;
1604 	_currKissingLadySequenceId = -1;
1605 }
1606 
init()1607 int Scene44::init() {
1608 	GameSys& gameSys = *_vm->_gameSys;
1609 
1610 	gameSys.setAnimation(0, 0, 0);
1611 	gameSys.setAnimation(0, 0, 1);
1612 	gameSys.setAnimation(0, 0, 2);
1613 	gameSys.setAnimation(0, 0, 3);
1614 	return 0xFF;
1615 }
1616 
updateHotspots()1617 void Scene44::updateHotspots() {
1618 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
1619 		_vm->setHotspot(kHS44Platypus, 0, 0, 0, 0, SF_DISABLED);
1620 		_vm->setHotspot(kHS44UfoExitLeft, 0, 0, 10, 599, SF_EXIT_L_CURSOR);
1621 		_vm->setHotspot(kHS44UfoExitRight, 790, 0, 799, 599, SF_EXIT_R_CURSOR);
1622 		_vm->setDeviceHotspot(kHS44UfoDevice, -1, 534, -1, 599);
1623 		_vm->_hotspotsCount = 4;
1624 	} else {
1625 		_vm->setHotspot(kHS44Platypus, 0, 0, 0, 0, SF_WALKABLE | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
1626 		_vm->setHotspot(kHS44ExitUfoParty, 150, 580, 650, 600, SF_EXIT_D_CURSOR | SF_WALKABLE, 5, 9);
1627 		_vm->setHotspot(kHS44ExitUfo, 0, 100, 10, 599, SF_EXIT_L_CURSOR, 0, 8);
1628 		_vm->setHotspot(kHS44ExitShow, 790, 100, 799, 599, SF_EXIT_R_CURSOR, 10, 8);
1629 		_vm->setHotspot(kHS44KissingLady, 300, 160, 400, 315, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR, 5, 7);
1630 		_vm->setHotspot(kHS44Spring, 580, 310, 635, 375, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR, 7, 8);
1631 		_vm->setHotspot(kHS44SpringGuy, 610, 375, 690, 515, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR, 7, 8);
1632 		_vm->setHotspot(kHS44WalkArea1, 0, 0, 800, 445);
1633 		_vm->setHotspot(kHS44WalkArea2, 617, 0, 800, 600);
1634 		_vm->setDeviceHotspot(kHS44Device, -1, -1, -1, -1);
1635 		if (_vm->isFlag(kGFUnk13))
1636 			_vm->_hotspots[kHS44KissingLady]._flags = SF_DISABLED;
1637 		if (_vm->isFlag(kGFSpringTaken))
1638 			_vm->_hotspots[kHS44Spring]._flags = SF_DISABLED;
1639 		_vm->_hotspotsCount = 10;
1640 	}
1641 }
1642 
run()1643 void Scene44::run() {
1644 	GameSys& gameSys = *_vm->_gameSys;
1645 	PlayerGnap& gnap = *_vm->_gnap;
1646 	PlayerPlat& plat = *_vm->_plat;
1647 
1648 	_vm->queueInsertDeviceIcon();
1649 
1650 	gameSys.insertSequence(0xF7, 0, 0, 0, kSeqLoop, 0, 0, 0);
1651 	gameSys.insertSequence(0xFC, 256, 0, 0, kSeqNone, 0, 0, 0);
1652 
1653 	if (_vm->isFlag(kGFSpringTaken))
1654 		_currSpringGuySequenceId = 0xF8;
1655 	else
1656 		_currSpringGuySequenceId = 0xF9;
1657 
1658 	_nextSpringGuySequenceId = -1;
1659 	gameSys.setAnimation(_currSpringGuySequenceId, 1, 4);
1660 	gameSys.insertSequence(_currSpringGuySequenceId, 1, 0, 0, kSeqNone, 0, 0, 0);
1661 
1662 	if (_vm->isFlag(kGFUnk13)) {
1663 		if (_vm->_prevSceneNum != 50 || _vm->_sceneSavegameLoaded) {
1664 			_currKissingLadySequenceId = 0xF6;
1665 			_nextKissingLadySequenceId = -1;
1666 		} else {
1667 			_vm->setGrabCursorSprite(kItemGum);
1668 			_currKissingLadySequenceId = 0xF5;
1669 			_nextKissingLadySequenceId = 0xF6;
1670 			gameSys.setAnimation(0xF5, 1, 2);
1671 		}
1672 	} else {
1673 		_currKissingLadySequenceId = 0xEC;
1674 		_nextKissingLadySequenceId = -1;
1675 		gameSys.setAnimation(0xEC, 1, 2);
1676 	}
1677 
1678 	gameSys.insertSequence(_currKissingLadySequenceId, 1, 0, 0, kSeqNone, 0, 0, 0);
1679 
1680 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
1681 		_vm->_toyUfoId = 0;
1682 		_vm->_toyUfoActionStatus = -1;
1683 		_vm->_toyUfoSequenceId = _vm->toyUfoGetSequenceId();
1684 		_vm->_toyUfoNextSequenceId = _vm->_toyUfoSequenceId;
1685 		if (_vm->_prevSceneNum == 43)
1686 			_vm->_toyUfoX = 30;
1687 		else
1688 			_vm->_toyUfoX = 770;
1689 		gameSys.setAnimation(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 3);
1690 		gameSys.insertSequence(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 0, 0, kSeqNone, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
1691 		_vm->endSceneInit();
1692 	} else {
1693 		switch (_vm->_prevSceneNum) {
1694 		case 43:
1695 			gnap.initPos(-1, 8, kDirUpRight);
1696 			plat.initPos(-1, 7, kDirUpLeft);
1697 			_vm->endSceneInit();
1698 			gnap.walkTo(Common::Point(2, 8), -1, 0x107B9, 1);
1699 			plat.walkTo(Common::Point(1, 8), -1, 0x107C2, 1);
1700 			break;
1701 		case 46:
1702 			gnap.initPos(11, 8, kDirUpRight);
1703 			plat.initPos(11, 8, kDirUpLeft);
1704 			_vm->endSceneInit();
1705 			gnap.walkTo(Common::Point(6, 8), -1, 0x107BA, 1);
1706 			plat.walkTo(Common::Point(7, 8), -1, 0x107D2, 1);
1707 			break;
1708 		case 50:
1709 			gnap.initPos(4, 8, kDirBottomRight);
1710 			if (_vm->_sceneSavegameLoaded) {
1711 				plat.initPos(_vm->_hotspotsWalkPos[4].x, _vm->_hotspotsWalkPos[4].y, kDirIdleRight);
1712 			} else if (!_vm->isFlag(kGFUnk13)) {
1713 				_vm->_timers[0] = 50;
1714 				_vm->_timers[1] = 20;
1715 				plat._pos = Common::Point(5, 8);
1716 				plat._sequenceId = 0xFD;
1717 				plat._idleFacing = kDirIdleLeft;
1718 				plat._id = 160;
1719 				plat._sequenceDatNum = 0;
1720 				gameSys.insertSequence(0xFD, 160, 0, 0, kSeqNone, 0, 0, 0);
1721 			}
1722 			_vm->endSceneInit();
1723 			break;
1724 		default:
1725 			gnap.initPos(5, 11, kDirUpRight);
1726 			plat.initPos(6, 11, kDirUpLeft);
1727 			_vm->endSceneInit();
1728 			plat.walkTo(Common::Point(6, 8), -1, 0x107C2, 1);
1729 			gnap.walkTo(Common::Point(5, 8), -1, 0x107BA, 1);
1730 			break;
1731 		}
1732 	}
1733 
1734 	while (!_vm->_sceneDone) {
1735 		if (!_vm->isSoundPlaying(0x1094B))
1736 			_vm->playSound(0x1094B, true);
1737 
1738 		_vm->updateMouseCursor();
1739 		_vm->updateCursorByHotspot();
1740 
1741 		_vm->testWalk(0, 0, -1, -1, -1, -1);
1742 
1743 		_vm->_sceneClickedHotspot = _vm->getClickedHotspotId();
1744 		_vm->updateGrabCursorSprite(0, 0);
1745 
1746 		if (_vm->isFlag(kGFGnapControlsToyUFO)) {
1747 			switch (_vm->_sceneClickedHotspot) {
1748 			case kHS44UfoExitLeft:
1749 				if (_vm->_toyUfoActionStatus < 0) {
1750 					_vm->_isLeavingScene = true;
1751 					_vm->_toyUfoActionStatus = 6;
1752 					_vm->_newSceneNum = 43;
1753 					_vm->toyUfoFlyTo(-35, -1, -35, 799, 0, 300, 3);
1754 				}
1755 				break;
1756 
1757 			case kHS44UfoExitRight:
1758 				if (_vm->_toyUfoActionStatus < 0) {
1759 					_vm->_isLeavingScene = true;
1760 					_vm->_toyUfoActionStatus = 6;
1761 					_vm->_newSceneNum = 46;
1762 					_vm->toyUfoFlyTo(835, -1, 0, 835, 0, 300, 3);
1763 				}
1764 				break;
1765 
1766 			case kHS44UfoDevice:
1767 				_vm->runMenu();
1768 				updateHotspots();
1769 				_vm->_timers[4] = _vm->getRandom(20) + 20;
1770 				break;
1771 			}
1772 		} else if (_vm->_sceneClickedHotspot <= 9) {
1773 			switch (_vm->_sceneClickedHotspot) {
1774 			case kHS44Device:
1775 				_vm->runMenu();
1776 				updateHotspots();
1777 				_vm->_timers[4] = _vm->getRandom(20) + 20;
1778 				break;
1779 
1780 			case kHS44Platypus:
1781 				if (gnap._actionStatus < 0) {
1782 					if (_vm->_grabCursorSpriteIndex >= 0) {
1783 						gnap.playImpossible(plat._pos);
1784 					} else {
1785 						switch (_vm->_verbCursor) {
1786 						case LOOK_CURSOR:
1787 							gnap.playMoan1(plat._pos);
1788 							break;
1789 						case GRAB_CURSOR:
1790 							gnap.kissPlatypus(0);
1791 							break;
1792 						case TALK_CURSOR:
1793 							gnap.playBrainPulsating(plat._pos);
1794 							plat.playSequence(plat.getSequenceId());
1795 							break;
1796 						case PLAT_CURSOR:
1797 							gnap.playImpossible(plat._pos);
1798 							break;
1799 						}
1800 					}
1801 				}
1802 				break;
1803 
1804 			case kHS44ExitUfoParty:
1805 				_vm->_isLeavingScene = true;
1806 				gnap.walkTo(_vm->_hotspotsWalkPos[kHS44ExitUfoParty], 0, 0x107AE, 1);
1807 				gnap._actionStatus = 0;
1808 				_vm->_newSceneNum = 40;
1809 				break;
1810 
1811 			case kHS44ExitUfo:
1812 				_vm->_isLeavingScene = true;
1813 				gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS44ExitUfo].x, gnap._pos.y), 0, 0x107AF, 1);
1814 				gnap._actionStatus = 0;
1815 				plat.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS44ExitUfo].x, plat._pos.y), -1, 0x107CF, 1);
1816 				_vm->_newSceneNum = 43;
1817 				break;
1818 
1819 			case kHS44ExitShow:
1820 				_vm->_isLeavingScene = true;
1821 				gnap.walkTo(_vm->_hotspotsWalkPos[kHS44ExitShow], 0, 0x107AB, 1);
1822 				gnap._actionStatus = 0;
1823 				_vm->_newSceneNum = 46;
1824 				break;
1825 
1826 			case kHS44KissingLady:
1827 				if (_vm->_grabCursorSpriteIndex >= 0) {
1828 					gnap._actionStatus = 2;
1829 					gnap.walkTo(_vm->_hotspotsWalkPos[kHS44KissingLady], 0, -1, 9);
1830 					gnap.playShowItem(_vm->_grabCursorSpriteIndex, _vm->_hotspotsWalkPos[kHS44KissingLady].x - 1, _vm->_hotspotsWalkPos[kHS44KissingLady].y);
1831 				} else {
1832 					switch (_vm->_verbCursor) {
1833 					case LOOK_CURSOR:
1834 						gnap.playScratchingHead(Common::Point(4, 3));
1835 						break;
1836 					case GRAB_CURSOR:
1837 						gnap.playImpossible();
1838 						break;
1839 					case TALK_CURSOR:
1840 						gnap._idleFacing = kDirUpLeft;
1841 						gnap.walkTo(_vm->_hotspotsWalkPos[kHS44KissingLady], 0, gnap.getSequenceId(kGSBrainPulsating, Common::Point(0, 0)) | 0x10000, 1);
1842 						gnap._actionStatus = 1;
1843 						break;
1844 					case PLAT_CURSOR:
1845 						gnap.useDeviceOnPlatypus();
1846 						plat.walkTo(Common::Point(6, 7), 1, 0x107D2, 1);
1847 						if (gnap._pos == Common::Point(7, 7))
1848 							gnap.walkStep();
1849 						gnap.playIdle(Common::Point(5, 7));
1850 						plat._actionStatus = 4;
1851 						break;
1852 					}
1853 				}
1854 				break;
1855 
1856 			case kHS44Spring:
1857 				if (_vm->_grabCursorSpriteIndex >= 0) {
1858 					gnap.playShowCurrItem(_vm->_hotspotsWalkPos[kHS44Spring], 8, 0);
1859 				} else {
1860 					switch (_vm->_verbCursor) {
1861 					case LOOK_CURSOR:
1862 						gnap.playScratchingHead(Common::Point(8, 7));
1863 						break;
1864 					case GRAB_CURSOR:
1865 						gnap.playPullOutDevice(Common::Point(8, 0));
1866 						gnap.playUseDevice(Common::Point(8, 0));
1867 						_nextSpringGuySequenceId = 0xFB;
1868 						_vm->invAdd(kItemSpring);
1869 						_vm->setFlag(kGFSpringTaken);
1870 						updateHotspots();
1871 						break;
1872 					case TALK_CURSOR:
1873 						gnap.playImpossible();
1874 						break;
1875 					case PLAT_CURSOR:
1876 						gnap.playImpossible();
1877 						break;
1878 					}
1879 				}
1880 				break;
1881 
1882 			case kHS44SpringGuy:
1883 				if (_vm->_grabCursorSpriteIndex >= 0) {
1884 					gnap.playShowCurrItem(_vm->_hotspotsWalkPos[kHS44SpringGuy], 8, 0);
1885 				} else {
1886 					switch (_vm->_verbCursor) {
1887 					case LOOK_CURSOR:
1888 						if (_vm->isFlag(kGFSpringTaken))
1889 							gnap.playMoan1(Common::Point(8, 7));
1890 						else
1891 							gnap.playScratchingHead(Common::Point(8, 7));
1892 						break;
1893 					case TALK_CURSOR:
1894 						gnap._idleFacing = kDirUpRight;
1895 						gnap.walkTo(_vm->_hotspotsWalkPos[kHS44SpringGuy], -1, gnap.getSequenceId(kGSBrainPulsating, Common::Point(0, 0)) | 0x10000, 1);
1896 						break;
1897 					case GRAB_CURSOR:
1898 					case PLAT_CURSOR:
1899 						gnap.playImpossible();
1900 						break;
1901 					}
1902 				}
1903 				break;
1904 
1905 			case kHS44WalkArea1:
1906 			case kHS44WalkArea2:
1907 				if (gnap._actionStatus < 0)
1908 					gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
1909 				break;
1910 
1911 			}
1912 		}
1913 
1914 		if (_vm->_mouseClickState._left && gnap._actionStatus < 0) {
1915 			_vm->_mouseClickState._left = false;
1916 			if (_vm->isFlag(kGFGnapControlsToyUFO)) {
1917 				_vm->_toyUfoActionStatus = 7;
1918 				_vm->toyUfoFlyTo(-1, -1, 0, 799, 0, 300, 3);
1919 			} else {
1920 				gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
1921 			}
1922 		}
1923 
1924 		updateAnimations();
1925 		_vm->toyUfoCheckTimer();
1926 
1927 		if (!_vm->_isLeavingScene) {
1928 			if (plat._actionStatus < 0 && !_vm->isFlag(kGFGnapControlsToyUFO) && _currKissingLadySequenceId != 0xF5)
1929 				plat.updateIdleSequence();
1930 			if (gnap._actionStatus < 0 && !_vm->isFlag(kGFGnapControlsToyUFO))
1931 				gnap.updateIdleSequence();
1932 			if (!_vm->_timers[4]) {
1933 				_vm->_timers[4] = _vm->getRandom(20) + 20;
1934 				if (gnap._actionStatus < 0 && plat._actionStatus < 0 && _nextKissingLadySequenceId == -1) {
1935 					switch (_vm->getRandom(20)) {
1936 					case 0:
1937 						_nextKissingLadySequenceId = 0xED;
1938 						break;
1939 					case 1:
1940 						_nextKissingLadySequenceId = 0xEE;
1941 						break;
1942 					case 2:
1943 						_nextKissingLadySequenceId = 0xF0;
1944 						break;
1945 					case 3:
1946 						_nextKissingLadySequenceId = 0xF3;
1947 						break;
1948 					case 4:
1949 						_nextKissingLadySequenceId = 0xF4;
1950 						break;
1951 					default:
1952 						_nextKissingLadySequenceId = 0xEC;
1953 						break;
1954 					}
1955 					if (_nextKissingLadySequenceId != 0xEC && _nextKissingLadySequenceId == _currKissingLadySequenceId)
1956 						_nextKissingLadySequenceId = -1;
1957 				}
1958 			}
1959 			if (!_vm->_timers[5]) {
1960 				_vm->_timers[5] = _vm->getRandom(20) + 20;
1961 				if (gnap._actionStatus < 0 && plat._actionStatus < 0 && _nextSpringGuySequenceId == -1) {
1962 					if (_vm->getRandom(5) != 0) {
1963 						if (!_vm->isFlag(kGFSpringTaken))
1964 							_nextSpringGuySequenceId = 0xF9;
1965 					} else {
1966 						if (_vm->isFlag(kGFSpringTaken))
1967 							_nextSpringGuySequenceId = 0xF8;
1968 						else
1969 							_nextSpringGuySequenceId = 0xFA;
1970 					}
1971 				}
1972 			}
1973 		}
1974 
1975 		_vm->checkGameKeys();
1976 
1977 		if (_vm->isKeyStatus1(Common::KEYCODE_BACKSPACE)) {
1978 			_vm->clearKeyStatus1(Common::KEYCODE_BACKSPACE);
1979 			_vm->runMenu();
1980 			updateHotspots();
1981 			_vm->_timers[4] = _vm->getRandom(20) + 20;
1982 		}
1983 
1984 		_vm->gameUpdateTick();
1985 	}
1986 }
1987 
updateAnimations()1988 void Scene44::updateAnimations() {
1989 	GameSys& gameSys = *_vm->_gameSys;
1990 	PlayerGnap& gnap = *_vm->_gnap;
1991 	PlayerPlat& plat = *_vm->_plat;
1992 
1993 	if (gameSys.getAnimationStatus(0) == 2) 	{
1994 		gameSys.setAnimation(0, 0, 0);
1995 		switch (gnap._actionStatus) {
1996 		case 0:
1997 			_vm->_sceneDone = true;
1998 			break;
1999 		case 1:
2000 			_nextKissingLadySequenceId = 0xEF;
2001 			break;
2002 		case 2:
2003 			_nextKissingLadySequenceId = 0xF2;
2004 			break;
2005 		}
2006 		gnap._actionStatus = -1;
2007 	}
2008 
2009 	if (gameSys.getAnimationStatus(1) == 2) {
2010 		gameSys.setAnimation(0, 0, 1);
2011 		switch (plat._actionStatus) {
2012 		case 4:
2013 			if (gameSys.getAnimationStatus(2) == 2) {
2014 				gameSys.insertSequence(0xFE, plat._id, plat._sequenceId | (plat._sequenceDatNum << 16), plat._id, kSeqSyncWait, 0, 0, 0);
2015 				plat._sequenceId = 0xFE;
2016 				plat._sequenceDatNum = 0;
2017 				gameSys.setAnimation(0xFE, plat._id, 1);
2018 				gameSys.removeSequence(_currKissingLadySequenceId, 1, true);
2019 				plat._actionStatus = 5;
2020 			}
2021 			break;
2022 		case 5:
2023 			_vm->_sceneDone = true;
2024 			_vm->_newSceneNum = 50;
2025 			break;
2026 		default:
2027 			plat._actionStatus = -1;
2028 			break;
2029 		}
2030 	}
2031 
2032 	if (gameSys.getAnimationStatus(2) == 2) {
2033 		if (_nextKissingLadySequenceId == 0xF6) {
2034 			gameSys.insertSequence(_nextKissingLadySequenceId, 1, _currKissingLadySequenceId, 1, kSeqSyncWait, 0, 0, 0);
2035 			plat.initPos(5, 8, kDirIdleLeft);
2036 			_currKissingLadySequenceId = _nextKissingLadySequenceId;
2037 			_nextKissingLadySequenceId = -1;
2038 			gameSys.setAnimation(0, 0, 2);
2039 		} else if (_nextKissingLadySequenceId != -1) {
2040 			gameSys.insertSequence(_nextKissingLadySequenceId, 1, _currKissingLadySequenceId, 1, kSeqSyncWait, 0, 0, 0);
2041 			gameSys.setAnimation(_nextKissingLadySequenceId, 1, 2);
2042 			_currKissingLadySequenceId = _nextKissingLadySequenceId;
2043 			_nextKissingLadySequenceId = -1;
2044 			_vm->_timers[4] = _vm->getRandom(20) + 20;
2045 		}
2046 	}
2047 
2048 	if (gameSys.getAnimationStatus(4) == 2) {
2049 		if (_currSpringGuySequenceId == 0xFB) {
2050 			_vm->setGrabCursorSprite(kItemSpring);
2051 			_nextSpringGuySequenceId = 0xF8;
2052 		}
2053 		if (_nextSpringGuySequenceId != -1) {
2054 			gameSys.insertSequence(_nextSpringGuySequenceId, 1, _currSpringGuySequenceId, 1, kSeqSyncWait, 0, 0, 0);
2055 			gameSys.setAnimation(_nextSpringGuySequenceId, 1, 4);
2056 			_currSpringGuySequenceId = _nextSpringGuySequenceId;
2057 			_nextSpringGuySequenceId = -1;
2058 			_vm->_timers[5] = _vm->getRandom(20) + 20;
2059 		}
2060 	}
2061 
2062 	if (gameSys.getAnimationStatus(3) == 2) {
2063 		switch (_vm->_toyUfoActionStatus) {
2064 		case 6:
2065 			_vm->_sceneDone = true;
2066 			break;
2067 		default:
2068 			_vm->_toyUfoNextSequenceId = _vm->toyUfoGetSequenceId();
2069 			gameSys.insertSequence(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId + 1,
2070 				_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId,
2071 				kSeqSyncWait, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
2072 			_vm->_toyUfoSequenceId = _vm->_toyUfoNextSequenceId;
2073 			++_vm->_toyUfoId;
2074 			gameSys.setAnimation(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId, 3);
2075 			break;
2076 		}
2077 		_vm->_toyUfoActionStatus = -1;
2078 	}
2079 }
2080 
2081 /*****************************************************************************/
2082 
Scene45(GnapEngine * vm)2083 Scene45::Scene45(GnapEngine *vm) : Scene(vm) {
2084 	_currDancerSequenceId = -1;
2085 }
2086 
init()2087 int Scene45::init() {
2088 	GameSys& gameSys = *_vm->_gameSys;
2089 
2090 	gameSys.setAnimation(0, 0, 0);
2091 	gameSys.setAnimation(0, 0, 1);
2092 	gameSys.setAnimation(0, 0, 2);
2093 	gameSys.setAnimation(0, 0, 3);
2094 	gameSys.setAnimation(0, 0, 4);
2095 	gameSys.setAnimation(0, 0, 5);
2096 	return _vm->isFlag(kGFUnk23) ? 0xA2 : 0xA1;
2097 }
2098 
updateHotspots()2099 void Scene45::updateHotspots() {
2100 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
2101 		_vm->setHotspot(kHS45Platypus, 0, 0, 0, 0, SF_DISABLED);
2102 		_vm->setHotspot(kHS45UfoExitLeft, 0, 0, 10, 599, SF_EXIT_L_CURSOR);
2103 		_vm->setHotspot(kHS45UfoExitRight, 794, 0, 799, 599, SF_EXIT_R_CURSOR | SF_DISABLED);
2104 		_vm->setDeviceHotspot(kHS45UfoDevice, -1, 534, -1, 599);
2105 		_vm->_hotspotsCount = 4;
2106 	} else {
2107 		_vm->setHotspot(kHS45Platypus, 0, 0, 0, 0, SF_WALKABLE | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
2108 		_vm->setHotspot(kHS45ExitUfoParty, 150, 580, 650, 600, SF_EXIT_D_CURSOR | SF_WALKABLE, 5, 9);
2109 		_vm->setHotspot(kHS45ExitShoe, 0, 100, 10, 599, SF_EXIT_L_CURSOR, 0, 8);
2110 		_vm->setHotspot(kHS45ExitRight, 794, 100, 799, 599, SF_EXIT_R_CURSOR | SF_DISABLED, 10, 8);
2111 		_vm->setHotspot(kHS45ExitDiscoBall, 200, 0, 600, 10, SF_DISABLED);
2112 		_vm->setHotspot(kHS45DiscoBall, 370, 10, 470, 125, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR, 6, 7);
2113 		_vm->setHotspot(kHS45WalkArea1, 0, 0, 800, 472);
2114 		_vm->setDeviceHotspot(kHS45Device, -1, -1, -1, -1);
2115 		if (_vm->isFlag(kGFUnk22)) {
2116 			_vm->_hotspots[kHS45Platypus]._flags = SF_DISABLED;
2117 			_vm->_hotspots[kHS45ExitUfoParty]._flags = SF_DISABLED;
2118 			_vm->_hotspots[kHS45ExitShoe]._flags = SF_DISABLED;
2119 			_vm->_hotspots[kHS45ExitRight]._flags = SF_DISABLED;
2120 			_vm->_hotspots[kHS45ExitDiscoBall]._flags = SF_EXIT_U_CURSOR;
2121 		}
2122 		if (_vm->isFlag(kGFUnk23) || _vm->isFlag(kGFUnk22))
2123 			_vm->_hotspots[kHS45DiscoBall]._flags = SF_DISABLED;
2124 		_vm->_hotspotsCount = 8;
2125 	}
2126 }
2127 
run()2128 void Scene45::run() {
2129 	GameSys& gameSys = *_vm->_gameSys;
2130 	PlayerGnap& gnap = *_vm->_gnap;
2131 	PlayerPlat& plat = *_vm->_plat;
2132 
2133 	if (!_vm->isSoundPlaying(0x1094A))
2134 		_vm->playSound(0x1094A, true);
2135 
2136 	_vm->queueInsertDeviceIcon();
2137 
2138 	gameSys.insertSequence(0x96, 1, 0, 0, kSeqNone, 0, 0, 0);
2139 	gameSys.setAnimation(0x96, 1, 3);
2140 	gameSys.insertSequence(0x99, 1, 0, 0, kSeqNone, 0, 0, 0);
2141 	gameSys.setAnimation(0x99, 1, 4);
2142 	_currDancerSequenceId = 0x8F;
2143 	gameSys.setAnimation(_currDancerSequenceId, 1, 2);
2144 	gameSys.insertSequence(_currDancerSequenceId, 1, 0, 0, kSeqNone, 0, 0, 0);
2145 
2146 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
2147 		_vm->_toyUfoId = 0;
2148 		_vm->_toyUfoActionStatus = -1;
2149 		_vm->_toyUfoSequenceId = _vm->toyUfoGetSequenceId();
2150 		_vm->_toyUfoNextSequenceId = _vm->_toyUfoSequenceId;
2151 		if (_vm->_prevSceneNum == 46)
2152 			_vm->_toyUfoX = 30;
2153 		else
2154 			_vm->_toyUfoX = 770;
2155 		gameSys.setAnimation(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 5);
2156 		gameSys.insertSequence(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 0, 0, kSeqNone, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
2157 		_vm->endSceneInit();
2158 	} else if (_vm->isFlag(kGFUnk22)) {
2159 		gnap._sequenceId = 0x9E;
2160 		gnap._sequenceDatNum = 0;
2161 		gnap._id = 1;
2162 		gameSys.setAnimation(0x9E, 1, 0);
2163 		gnap._actionStatus = 1;
2164 		gameSys.insertSequence(gnap._sequenceId, gnap._id, 0, 0, kSeqNone, 0, 0, 0);
2165 		plat.initPos(4, 8, kDirIdleLeft);
2166 		_vm->endSceneInit();
2167 	} else if (_vm->_prevSceneNum == 46) {
2168 		gnap.initPos(-1, 8, kDirUpRight);
2169 		plat.initPos(-1, 9, kDirUpLeft);
2170 		_vm->endSceneInit();
2171 		plat.walkTo(Common::Point(4, 8), -1, 0x107C2, 1);
2172 		gnap.walkTo(Common::Point(2, 7), -1, 0x107B9, 1);
2173 	} else if (_vm->_prevSceneNum == 41) {
2174 		gnap.initPos(11, 8, kDirUpRight);
2175 		plat.initPos(11, 9, kDirUpLeft);
2176 		_vm->endSceneInit();
2177 		plat.walkTo(Common::Point(4, 8), -1, 0x107D2, 1);
2178 		gnap.walkTo(Common::Point(10, 9), -1, 0x107BA, 1);
2179 	} else {
2180 		gnap.initPos(2, 11, kDirUpRight);
2181 		plat.initPos(6, 11, kDirUpLeft);
2182 		_vm->endSceneInit();
2183 		plat.walkTo(Common::Point(4, 8), -1, 0x107C2, 1);
2184 		gnap.walkTo(Common::Point(2, 7), -1, 0x107B9, 1);
2185 	}
2186 
2187 	if (!_vm->isFlag(kGFUnk21) && !_vm->isFlag(kGFGnapControlsToyUFO)) {
2188 		_vm->setFlag(kGFUnk21);
2189 		_vm->setGrabCursorSprite(-1);
2190 		gameSys.setAnimation(0x9D, gnap._id, 0);
2191 		gameSys.insertSequence(0x9D, gnap._id, makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id, kSeqSyncWait, 0, 0, 0);
2192 		while (gameSys.getAnimationStatus(0) != 2 && !_vm->_gameDone) {
2193 			_vm->gameUpdateTick();
2194 			if (gameSys.getAnimationStatus(2) == 2) {
2195 				gameSys.setAnimation(0, 0, 2);
2196 				int newSeqId = _vm->getRandom(7) + 0x8F;
2197 				gameSys.insertSequence(newSeqId, 1, _currDancerSequenceId, 1, kSeqSyncWait, 0, 0, 0);
2198 				gameSys.setAnimation(newSeqId, 1, 2);
2199 				_currDancerSequenceId = newSeqId;
2200 			}
2201 			if (gameSys.getAnimationStatus(3) == 2 && gameSys.getAnimationStatus(4) == 2) {
2202 				gameSys.insertSequence(0x96, 1, 0x96, 1, kSeqSyncWait, 0, 0, 0);
2203 				gameSys.setAnimation(0x96, 1, 3);
2204 				gameSys.insertSequence(0x99, 1, 0x99, 1, kSeqSyncWait, 0, 0, 0);
2205 				gameSys.setAnimation(0x99, 1, 4);
2206 			}
2207 		}
2208 		gnap._sequenceId = 0x9D;
2209 		gnap._sequenceDatNum = 0;
2210 		_vm->hideCursor();
2211 		_vm->addFullScreenSprite(0x8A, 255);
2212 		gameSys.setAnimation(0xA0, 256, 0);
2213 		gameSys.insertSequence(0xA0, 256, 0, 0, kSeqNone, 0, 0, 0);
2214 		while (gameSys.getAnimationStatus(0) != 2 && !_vm->_gameDone)
2215 			_vm->gameUpdateTick();
2216 		gameSys.setAnimation(0x107BD, gnap._id, 0);
2217 		gameSys.insertSequence(0x107BD, gnap._id,
2218 			makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id,
2219 			kSeqSyncWait, 0, 75 * gnap._pos.x - gnap._gridX, 48 * gnap._pos.y - gnap._gridY);
2220 		_vm->removeFullScreenSprite();
2221 		_vm->showCursor();
2222 		gnap._sequenceId = 0x7BD;
2223 		gnap._sequenceDatNum = 1;
2224 	}
2225 
2226 	plat.playSequence(0x9A);
2227 	gameSys.setAnimation(plat._sequenceId, plat._id, 1);
2228 
2229 	while (!_vm->_sceneDone) {
2230 		if (!_vm->isSoundPlaying(0x1094A))
2231 			_vm->playSound(0x1094A, true);
2232 
2233 		_vm->updateMouseCursor();
2234 		_vm->updateCursorByHotspot();
2235 
2236 		_vm->testWalk(0, 0, -1, -1, -1, -1);
2237 
2238 		_vm->_sceneClickedHotspot = _vm->getClickedHotspotId();
2239 		_vm->updateGrabCursorSprite(0, 0);
2240 
2241 		if (_vm->isFlag(kGFGnapControlsToyUFO)) {
2242 			switch (_vm->_sceneClickedHotspot) {
2243 			case kHS45UfoExitLeft:
2244 				if (_vm->_toyUfoActionStatus < 0) {
2245 					_vm->_isLeavingScene = true;
2246 					_vm->_toyUfoActionStatus = 2;
2247 					_vm->_newSceneNum = 46;
2248 					_vm->toyUfoFlyTo(-35, -1, -35, 799, 0, 300, 5);
2249 				}
2250 				break;
2251 
2252 			case kHS45UfoExitRight:
2253 				if (_vm->_toyUfoActionStatus < 0) {
2254 					_vm->_isLeavingScene = true;
2255 					_vm->_toyUfoActionStatus = 2;
2256 					_vm->_newSceneNum = 41;
2257 					_vm->toyUfoFlyTo(835, -1, 0, 835, 0, 300, 5);
2258 				}
2259 				break;
2260 
2261 			case kHS45UfoDevice:
2262 				_vm->runMenu();
2263 				updateHotspots();
2264 				break;
2265 			}
2266 		} else {
2267 			switch (_vm->_sceneClickedHotspot) {
2268 			case kHS45Device:
2269 				_vm->runMenu();
2270 				updateHotspots();
2271 				break;
2272 
2273 			case kHS45Platypus:
2274 				if (gnap._actionStatus < 0) {
2275 					if (_vm->_grabCursorSpriteIndex >= 0) {
2276 						gnap.playImpossible(plat._pos);
2277 					} else {
2278 						switch (_vm->_verbCursor) {
2279 						case LOOK_CURSOR:
2280 							gnap.playMoan1(plat._pos);
2281 							break;
2282 						case GRAB_CURSOR:
2283 							gnap.kissPlatypus(0);
2284 							plat.playSequence(0x9A);
2285 							gameSys.setAnimation(plat._sequenceId, plat._id, 1);
2286 							break;
2287 						case TALK_CURSOR:
2288 							gnap.playBrainPulsating(plat._pos);
2289 							plat.playSequence(plat.getSequenceId());
2290 							break;
2291 						case PLAT_CURSOR:
2292 							gnap.playImpossible(plat._pos);
2293 							break;
2294 						}
2295 					}
2296 				}
2297 				break;
2298 
2299 			case kHS45ExitUfoParty:
2300 				if (gnap._actionStatus < 0) {
2301 					_vm->_isLeavingScene = true;
2302 					gnap.walkTo(Common::Point(gnap._pos.x, _vm->_hotspotsWalkPos[kHS45ExitUfoParty].y), 0, 0x107AE, 1);
2303 					gnap._actionStatus = 0;
2304 					_vm->_newSceneNum = 40;
2305 				}
2306 				break;
2307 
2308 			case kHS45ExitShoe:
2309 				if (gnap._actionStatus < 0) {
2310 					_vm->_isLeavingScene = true;
2311 					gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS45ExitShoe].x, gnap._pos.y), 0, 0x107AF, 1);
2312 					gnap._actionStatus = 0;
2313 					plat.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS45ExitShoe].x, plat._pos.y), -1, 0x107CF, 1);
2314 					_vm->_newSceneNum = 46;
2315 				}
2316 				break;
2317 
2318 			case kHS45ExitRight:
2319 				if (gnap._actionStatus < 0) {
2320 					_vm->_isLeavingScene = true;
2321 					gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS45ExitRight].x, gnap._pos.y), 0, 0x107AB, 1);
2322 					gnap._actionStatus = 0;
2323 					plat.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS45ExitRight].x, plat._pos.y), -1, 0x107CD, 1);
2324 					_vm->_newSceneNum = 41;
2325 				}
2326 				break;
2327 
2328 			case kHS45ExitDiscoBall:
2329 				_vm->clearFlag(kGFUnk22);
2330 				_vm->setFlag(kGFUnk23);
2331 				_vm->_sceneDone = true;
2332 				_vm->_newSceneNum = 54;
2333 				break;
2334 
2335 			case kHS45DiscoBall:
2336 				if (gnap._actionStatus < 0) {
2337 					if (_vm->_grabCursorSpriteIndex == kItemSpring) {
2338 						gnap.walkTo(_vm->_hotspotsWalkPos[kHS45DiscoBall], 0, 0x9F, 5);
2339 						gnap._actionStatus = 1;
2340 						_vm->setGrabCursorSprite(-1);
2341 						_vm->invRemove(kItemSpring);
2342 					} else if (_vm->_grabCursorSpriteIndex >= 0) {
2343 						gnap.playShowItem(_vm->_grabCursorSpriteIndex, 5, 0);
2344 					} else {
2345 						switch (_vm->_verbCursor) {
2346 						case LOOK_CURSOR:
2347 							gnap.playScratchingHead(Common::Point(5, 0));
2348 							break;
2349 						case GRAB_CURSOR:
2350 						case TALK_CURSOR:
2351 						case PLAT_CURSOR:
2352 							gnap.playImpossible();
2353 							break;
2354 						}
2355 					}
2356 				}
2357 				break;
2358 
2359 			case kHS45WalkArea1:
2360 				if (gnap._actionStatus < 0)
2361 					gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
2362 				break;
2363 			}
2364 		}
2365 
2366 		if (_vm->_mouseClickState._left && gnap._actionStatus < 0) {
2367 			_vm->_mouseClickState._left = false;
2368 			if (_vm->isFlag(kGFGnapControlsToyUFO)) {
2369 				_vm->_toyUfoActionStatus = 3;
2370 				_vm->toyUfoFlyTo(-1, -1, 0, 799, 0, 300, 5);
2371 			} else {
2372 				gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
2373 			}
2374 		}
2375 
2376 		updateAnimations();
2377 		_vm->toyUfoCheckTimer();
2378 
2379 		if (!_vm->_isLeavingScene && gnap._actionStatus < 0 && !_vm->isFlag(kGFGnapControlsToyUFO))
2380 			gnap.updateIdleSequence();
2381 
2382 		_vm->checkGameKeys();
2383 
2384 		if (_vm->isKeyStatus1(Common::KEYCODE_BACKSPACE)) {
2385 			_vm->clearKeyStatus1(Common::KEYCODE_BACKSPACE);
2386 			_vm->runMenu();
2387 			updateHotspots();
2388 		}
2389 
2390 		_vm->gameUpdateTick();
2391 	}
2392 
2393 	_vm->_sceneWaiting = false;
2394 }
2395 
updateAnimations()2396 void Scene45::updateAnimations() {
2397 	GameSys& gameSys = *_vm->_gameSys;
2398 	PlayerGnap& gnap = *_vm->_gnap;
2399 	PlayerPlat& plat = *_vm->_plat;
2400 
2401 	if (gameSys.getAnimationStatus(0) == 2) {
2402 		gameSys.setAnimation(0, 0, 0);
2403 		switch (gnap._actionStatus) {
2404 		case 0:
2405 			_vm->_sceneDone = true;
2406 			break;
2407 		case 1:
2408 			_vm->_sceneWaiting = true;
2409 			_vm->setFlag(kGFUnk22);
2410 			updateHotspots();
2411 			gameSys.insertSequence(0x9E, gnap._id, makeRid(gnap._sequenceDatNum, gnap._sequenceId), gnap._id, kSeqSyncWait, 0, 0, 0);
2412 			gnap._sequenceId = 0x9E;
2413 			gnap._sequenceDatNum = 0;
2414 			gameSys.setAnimation(0x9E, gnap._id, 0);
2415 			break;
2416 		default:
2417 			gnap._actionStatus = -1;
2418 			break;
2419 		}
2420 	}
2421 
2422 	if (gameSys.getAnimationStatus(1) == 2) {
2423 		gameSys.setAnimation(0, 0, 1);
2424 		if (_vm->getRandom(2) != 0)
2425 			plat.playSequence(0x9B);
2426 		else
2427 			plat.playSequence(0x9C);
2428 		gameSys.setAnimation(plat._sequenceId, plat._id, 1);
2429 	}
2430 
2431 	if (gameSys.getAnimationStatus(2) == 2) {
2432 		gameSys.setAnimation(0, 0, 2);
2433 		int newSeqId = _vm->getRandom(7) + 0x8F;
2434 		gameSys.insertSequence(newSeqId, 1, _currDancerSequenceId, 1, kSeqSyncWait, 0, 0, 0);
2435 		gameSys.setAnimation(newSeqId, 1, 2);
2436 		_currDancerSequenceId = newSeqId;
2437 	}
2438 
2439 	if (gameSys.getAnimationStatus(3) == 2 && gameSys.getAnimationStatus(4) == 2) {
2440 		gameSys.insertSequence(0x96, 1, 0x96, 1, kSeqSyncWait, 0, 0, 0);
2441 		gameSys.setAnimation(0x96, 1, 3);
2442 		gameSys.insertSequence(0x99, 1, 0x99, 1, kSeqSyncWait, 0, 0, 0);
2443 		gameSys.setAnimation(0x99, 1, 4);
2444 	}
2445 
2446 	if (gameSys.getAnimationStatus(5) == 2) {
2447 		switch (_vm->_toyUfoActionStatus) {
2448 		case 2:
2449 			_vm->_sceneDone = true;
2450 			break;
2451 		default:
2452 			_vm->_toyUfoNextSequenceId = _vm->toyUfoGetSequenceId();
2453 			gameSys.insertSequence(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId + 1,
2454 				_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId,
2455 				kSeqSyncWait, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
2456 			_vm->_toyUfoSequenceId = _vm->_toyUfoNextSequenceId;
2457 			++_vm->_toyUfoId;
2458 			gameSys.setAnimation(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId, 5);
2459 			break;
2460 		}
2461 		_vm->_toyUfoActionStatus = -1;
2462 	}
2463 }
2464 
2465 /*****************************************************************************/
2466 
Scene46(GnapEngine * vm)2467 Scene46::Scene46(GnapEngine *vm) : Scene(vm) {
2468 	_currSackGuySequenceId = -1;
2469 	_nextItchyGuySequenceId = -1;
2470 	_nextSackGuySequenceId = -1;
2471 	_currItchyGuySequenceId = -1;
2472 }
2473 
init()2474 int Scene46::init() {
2475 	GameSys& gameSys = *_vm->_gameSys;
2476 
2477 	gameSys.setAnimation(0, 0, 0);
2478 	gameSys.setAnimation(0, 0, 1);
2479 	gameSys.setAnimation(0, 0, 2);
2480 	gameSys.setAnimation(0, 0, 3);
2481 	gameSys.setAnimation(0, 0, 4);
2482 	return 0x4E;
2483 }
2484 
updateHotspots()2485 void Scene46::updateHotspots() {
2486 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
2487 		_vm->setHotspot(kHS46Platypus, 0, 0, 0, 0, SF_DISABLED);
2488 		_vm->setHotspot(kHS46UfoExitLeft, 0, 0, 10, 599, SF_EXIT_L_CURSOR);
2489 		_vm->setHotspot(kHS46UfoExitRight, 790, 0, 799, 599, SF_EXIT_R_CURSOR);
2490 		_vm->setDeviceHotspot(kHS46UfoDevice, -1, 534, -1, 599);
2491 		_vm->_hotspotsCount = 4;
2492 	} else {
2493 		_vm->setHotspot(kHS46Platypus, 0, 0, 0, 0, SF_WALKABLE | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR);
2494 		_vm->setHotspot(kHS46ExitUfoParty, 150, 580, 650, 600, SF_EXIT_D_CURSOR | SF_WALKABLE, 5, 9);
2495 		_vm->setHotspot(kHS46ExitKissinBooth, 0, 100, 10, 599, SF_EXIT_L_CURSOR, 0, 8);
2496 		_vm->setHotspot(kHS46ExitDisco, 790, 100, 799, 599, SF_EXIT_R_CURSOR, 10, 8);
2497 		_vm->setHotspot(kHS46SackGuy, 180, 370, 235, 490, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR, 3, 8);
2498 		_vm->setHotspot(kHS46ItchyGuy, 535, 210, 650, 480, SF_PLAT_CURSOR | SF_TALK_CURSOR | SF_GRAB_CURSOR | SF_LOOK_CURSOR, 6, 8);
2499 		_vm->setHotspot(kHS46WalkArea1, 0, 0, 800, 485);
2500 		_vm->setDeviceHotspot(kHS46Device, -1, -1, -1, -1);
2501 		_vm->_hotspotsCount = 8;
2502 	}
2503 }
2504 
run()2505 void Scene46::run() {
2506 	GameSys& gameSys = *_vm->_gameSys;
2507 	PlayerGnap& gnap = *_vm->_gnap;
2508 	PlayerPlat& plat = *_vm->_plat;
2509 
2510 	_vm->queueInsertDeviceIcon();
2511 	gameSys.insertSequence(0x4D, 0, 0, 0, kSeqLoop, 0, 0, 0);
2512 
2513 	_currSackGuySequenceId = 0x4B;
2514 	_nextSackGuySequenceId = -1;
2515 	gameSys.setAnimation(0x4B, 1, 3);
2516 	gameSys.insertSequence(_currSackGuySequenceId, 1, 0, 0, kSeqNone, 0, 0, 0);
2517 
2518 	_currItchyGuySequenceId = 0x47;
2519 	_nextItchyGuySequenceId = -1;
2520 	gameSys.setAnimation(0x47, 1, 4);
2521 	gameSys.insertSequence(_currItchyGuySequenceId, 1, 0, 0, kSeqNone, 0, 0, 0);
2522 
2523 	if (_vm->isFlag(kGFGnapControlsToyUFO)) {
2524 		_vm->_toyUfoId = 0;
2525 		_vm->_toyUfoActionStatus = -1;
2526 		_vm->_toyUfoSequenceId = _vm->toyUfoGetSequenceId();
2527 		_vm->_toyUfoNextSequenceId = _vm->_toyUfoSequenceId;
2528 		if (_vm->_prevSceneNum == 44)
2529 			_vm->_toyUfoX = 30;
2530 		else
2531 			_vm->_toyUfoX = 770;
2532 		gameSys.setAnimation(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 2);
2533 		gameSys.insertSequence(_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId, 0, 0, kSeqNone, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
2534 		_vm->endSceneInit();
2535 	} else if (_vm->_prevSceneNum == 44) {
2536 		gnap.initPos(-1, 8, kDirUpRight);
2537 		plat.initPos(-1, 8, kDirUpLeft);
2538 		_vm->endSceneInit();
2539 		plat.walkTo(Common::Point(1, 8), -1, 0x107C2, 1);
2540 		gnap.walkTo(Common::Point(2, 8), -1, 0x107B9, 1);
2541 	} else if (_vm->_prevSceneNum == 45) {
2542 		gnap.initPos(11, 8, kDirUpRight);
2543 		plat.initPos(12, 8, kDirUpLeft);
2544 		_vm->endSceneInit();
2545 		gnap.walkTo(Common::Point(8, 8), -1, 0x107BA, 1);
2546 		plat.walkTo(Common::Point(9, 8), -1, 0x107D2, 1);
2547 	} else {
2548 		gnap.initPos(5, 11, kDirUpRight);
2549 		plat.initPos(6, 11, kDirUpLeft);
2550 		_vm->endSceneInit();
2551 		plat.walkTo(Common::Point(5, 8), -1, 0x107C2, 1);
2552 		gnap.walkTo(Common::Point(6, 8), -1, 0x107BA, 1);
2553 	}
2554 
2555 	_vm->_timers[4] = _vm->getRandom(50) + 80;
2556 	_vm->_timers[5] = _vm->getRandom(50) + 80;
2557 
2558 	while (!_vm->_sceneDone) {
2559 		if (!_vm->isSoundPlaying(0x1094B))
2560 			_vm->playSound(0x1094B, true);
2561 
2562 		_vm->updateMouseCursor();
2563 		_vm->updateCursorByHotspot();
2564 
2565 		_vm->testWalk(0, 0, -1, -1, -1, -1);
2566 
2567 		_vm->_sceneClickedHotspot = _vm->getClickedHotspotId();
2568 		_vm->updateGrabCursorSprite(0, 0);
2569 
2570 		if (_vm->isFlag(kGFGnapControlsToyUFO)) {
2571 			switch (_vm->_sceneClickedHotspot) {
2572 			case kHS46UfoExitLeft:
2573 				if (_vm->_toyUfoActionStatus < 0) {
2574 					_vm->_isLeavingScene = true;
2575 					_vm->_toyUfoActionStatus = 3;
2576 					_vm->_newSceneNum = 44;
2577 					_vm->toyUfoFlyTo(-35, -1, -35, 799, 0, 300, 2);
2578 				}
2579 				break;
2580 
2581 			case kHS46UfoExitRight:
2582 				if (_vm->_toyUfoActionStatus < 0) {
2583 					_vm->_isLeavingScene = true;
2584 					_vm->_toyUfoActionStatus = 3;
2585 					_vm->_newSceneNum = 45;
2586 					_vm->toyUfoFlyTo(835, -1, 0, 835, 0, 300, 2);
2587 				}
2588 				break;
2589 
2590 			case kHS46UfoDevice:
2591 				_vm->runMenu();
2592 				updateHotspots();
2593 				break;
2594 			}
2595 		} else {
2596 			switch (_vm->_sceneClickedHotspot) {
2597 			case kHS46Device:
2598 				_vm->runMenu();
2599 				updateHotspots();
2600 				break;
2601 
2602 			case kHS46Platypus:
2603 				if (gnap._actionStatus < 0) {
2604 					if (_vm->_grabCursorSpriteIndex >= 0) {
2605 						gnap.playImpossible(plat._pos);
2606 					} else {
2607 						switch (_vm->_verbCursor) {
2608 						case LOOK_CURSOR:
2609 							gnap.playMoan1(plat._pos);
2610 							break;
2611 						case GRAB_CURSOR:
2612 							gnap.kissPlatypus(0);
2613 							break;
2614 						case TALK_CURSOR:
2615 							gnap.playBrainPulsating(plat._pos);
2616 							plat.playSequence(plat.getSequenceId());
2617 							break;
2618 						case PLAT_CURSOR:
2619 							gnap.playImpossible(plat._pos);
2620 							break;
2621 						}
2622 					}
2623 				}
2624 				break;
2625 
2626 			case kHS46SackGuy:
2627 				if (_vm->_grabCursorSpriteIndex >= 0) {
2628 					gnap.playShowCurrItem(_vm->_hotspotsWalkPos[kHS46SackGuy], 2, 0);
2629 				} else {
2630 					switch (_vm->_verbCursor) {
2631 					case LOOK_CURSOR:
2632 						gnap.playMoan1(Common::Point(_vm->_hotspotsWalkPos[kHS46SackGuy].x + 1, 0));
2633 						break;
2634 					case TALK_CURSOR:
2635 						gnap._idleFacing = kDirUpLeft;
2636 						gnap.walkTo(_vm->_hotspotsWalkPos[kHS46SackGuy], 0, gnap.getSequenceId(kGSBrainPulsating, Common::Point(0, 0)) | 0x10000, 1);
2637 						gnap._actionStatus = 2;
2638 						break;
2639 					case GRAB_CURSOR:
2640 					case PLAT_CURSOR:
2641 						gnap.playImpossible();
2642 						break;
2643 					}
2644 				}
2645 				break;
2646 
2647 			case kHS46ItchyGuy:
2648 				if (_vm->_grabCursorSpriteIndex >= 0) {
2649 					gnap.playShowCurrItem(_vm->_hotspotsWalkPos[kHS46ItchyGuy], 7, 0);
2650 				} else {
2651 					switch (_vm->_verbCursor) {
2652 					case LOOK_CURSOR:
2653 						gnap.playMoan1(Common::Point(_vm->_hotspotsWalkPos[kHS46ItchyGuy].x - 1, 0));
2654 						break;
2655 					case TALK_CURSOR:
2656 						gnap._idleFacing = kDirUpRight;
2657 						gnap.walkTo(_vm->_hotspotsWalkPos[kHS46ItchyGuy], 0, gnap.getSequenceId(kGSBrainPulsating, Common::Point(0, 0)) | 0x10000, 1);
2658 						gnap._actionStatus = 1;
2659 						break;
2660 					case GRAB_CURSOR:
2661 					case PLAT_CURSOR:
2662 						gnap.playImpossible();
2663 						break;
2664 					}
2665 				}
2666 				break;
2667 
2668 			case kHS46ExitUfoParty:
2669 				_vm->_isLeavingScene = true;
2670 				gnap.walkTo(Common::Point(gnap._pos.x, _vm->_hotspotsWalkPos[kHS46ExitUfoParty].y), 0, 0x107AE, 1);
2671 				gnap._actionStatus = 0;
2672 				_vm->_newSceneNum = 40;
2673 				break;
2674 
2675 			case kHS46ExitKissinBooth:
2676 				_vm->_isLeavingScene = true;
2677 				gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS46ExitKissinBooth].x, gnap._pos.y), 0, 0x107AF, 1);
2678 				gnap._actionStatus = 0;
2679 				plat.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS46ExitKissinBooth].x, plat._pos.y), -1, 0x107CF, 1);
2680 				_vm->_newSceneNum = 44;
2681 				break;
2682 
2683 			case kHS46ExitDisco:
2684 				_vm->_isLeavingScene = true;
2685 				gnap.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS46ExitDisco].x, gnap._pos.y), 0, 0x107AB, 1);
2686 				gnap._actionStatus = 0;
2687 				plat.walkTo(Common::Point(_vm->_hotspotsWalkPos[kHS46ExitDisco].x, plat._pos.y), -1, 0x107CD, 1);
2688 				_vm->_newSceneNum = 45;
2689 				break;
2690 
2691 			case kHS46WalkArea1:
2692 				if (gnap._actionStatus < 0)
2693 					gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
2694 				break;
2695 			}
2696 		}
2697 
2698 		if (_vm->_mouseClickState._left && gnap._actionStatus < 0) {
2699 			_vm->_mouseClickState._left = false;
2700 			if (_vm->isFlag(kGFGnapControlsToyUFO)) {
2701 				_vm->_toyUfoActionStatus = 4;
2702 				_vm->toyUfoFlyTo(-1, -1, 0, 799, 0, 300, 2);
2703 			} else {
2704 				gnap.walkTo(Common::Point(-1, -1), -1, -1, 1);
2705 			}
2706 		}
2707 
2708 		updateAnimations();
2709 		_vm->toyUfoCheckTimer();
2710 
2711 		if (!_vm->_isLeavingScene) {
2712 			if (plat._actionStatus < 0 && !_vm->isFlag(kGFGnapControlsToyUFO))
2713 				plat.updateIdleSequence();
2714 			if (gnap._actionStatus < 0 && !_vm->isFlag(kGFGnapControlsToyUFO))
2715 				gnap.updateIdleSequence();
2716 			if (!_vm->_timers[4]) {
2717 				_vm->_timers[4] = _vm->getRandom(50) + 80;
2718 				if (gnap._actionStatus < 0 && plat._actionStatus < 0 && _nextItchyGuySequenceId == -1) {
2719 					if (_vm->getRandom(2) != 0)
2720 						_nextItchyGuySequenceId = 0x49;
2721 					else
2722 						_nextItchyGuySequenceId = 0x48;
2723 				}
2724 			}
2725 			if (!_vm->_timers[5]) {
2726 				_vm->_timers[5] = _vm->getRandom(50) + 80;
2727 				if (gnap._actionStatus < 0 && plat._actionStatus < 0 && _nextSackGuySequenceId == -1)
2728 					_nextSackGuySequenceId = 0x4C;
2729 			}
2730 		}
2731 
2732 		_vm->checkGameKeys();
2733 
2734 		if (_vm->isKeyStatus1(Common::KEYCODE_BACKSPACE)) {
2735 			_vm->clearKeyStatus1(Common::KEYCODE_BACKSPACE);
2736 			_vm->runMenu();
2737 			updateHotspots();
2738 		}
2739 
2740 		_vm->gameUpdateTick();
2741 	}
2742 }
2743 
updateAnimations()2744 void Scene46::updateAnimations() {
2745 	GameSys& gameSys = *_vm->_gameSys;
2746 	PlayerGnap& gnap = *_vm->_gnap;
2747 
2748 	if (gameSys.getAnimationStatus(0) == 2) {
2749 		gameSys.setAnimation(0, 0, 0);
2750 		switch (gnap._actionStatus) {
2751 		case 0:
2752 			_vm->_sceneDone = true;
2753 			break;
2754 		case 1:
2755 			_nextItchyGuySequenceId = 0x46;
2756 			break;
2757 		case 2:
2758 			_nextSackGuySequenceId = 0x4A;
2759 			break;
2760 		}
2761 		gnap._actionStatus = -1;
2762 	}
2763 
2764 	if (gameSys.getAnimationStatus(3) == 2 && _nextSackGuySequenceId != -1) {
2765 		gameSys.insertSequence(_nextSackGuySequenceId, 1, _currSackGuySequenceId, 1, kSeqSyncWait, 0, 0, 0);
2766 		gameSys.setAnimation(_nextSackGuySequenceId, 1, 3);
2767 		_currSackGuySequenceId = _nextSackGuySequenceId;
2768 		_nextSackGuySequenceId = -1;
2769 		_vm->_timers[5] = _vm->getRandom(50) + 80;
2770 	}
2771 
2772 	if (gameSys.getAnimationStatus(4) == 2 && _nextItchyGuySequenceId != -1) {
2773 		gameSys.insertSequence(_nextItchyGuySequenceId, 1, _currItchyGuySequenceId, 1, kSeqSyncWait, 0, 0, 0);
2774 		gameSys.setAnimation(_nextItchyGuySequenceId, 1, 4);
2775 		_currItchyGuySequenceId = _nextItchyGuySequenceId;
2776 		_nextItchyGuySequenceId = -1;
2777 		_vm->_timers[4] = _vm->getRandom(50) + 80;
2778 	}
2779 
2780 	if (gameSys.getAnimationStatus(2) == 2) {
2781 		switch (_vm->_toyUfoActionStatus) {
2782 		case 3:
2783 			_vm->_sceneDone = true;
2784 			break;
2785 		default:
2786 			_vm->_toyUfoNextSequenceId = _vm->toyUfoGetSequenceId();
2787 			gameSys.insertSequence(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId + 1,
2788 				_vm->_toyUfoSequenceId | 0x10000, _vm->_toyUfoId,
2789 				kSeqSyncWait, 0, _vm->_toyUfoX - 274, _vm->_toyUfoY - 128);
2790 			_vm->_toyUfoSequenceId = _vm->_toyUfoNextSequenceId;
2791 			++_vm->_toyUfoId;
2792 			gameSys.setAnimation(_vm->_toyUfoNextSequenceId | 0x10000, _vm->_toyUfoId, 2);
2793 			break;
2794 		}
2795 		_vm->_toyUfoActionStatus = -1;
2796 	}
2797 }
2798 
2799 } // End of namespace Gnap
2800