aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/npcs/parrot.cpp
blob: dd033abbae0b137759c7bcec09402fec75e4f7c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "titanic/npcs/parrot.h"
#include "titanic/core/project_item.h"
#include "titanic/carry/carry.h"
#include "titanic/carry/chicken.h"
#include "titanic/game_manager.h"

namespace Titanic {

BEGIN_MESSAGE_MAP(CParrot, CTrueTalkNPC)
	ON_MESSAGE(ActMsg)
	ON_MESSAGE(MouseButtonDownMsg)
	ON_MESSAGE(MovieEndMsg)
	ON_MESSAGE(EnterViewMsg)
	ON_MESSAGE(TrueTalkTriggerActionMsg)
	ON_MESSAGE(MouseDragStartMsg)
	ON_MESSAGE(LeaveViewMsg)
	ON_MESSAGE(ParrotSpeakMsg)
	ON_MESSAGE(NPCPlayTalkingAnimationMsg)
	ON_MESSAGE(NPCPlayIdleAnimationMsg)
	ON_MESSAGE(FrameMsg)
	ON_MESSAGE(MovieFrameMsg)
	ON_MESSAGE(PutParrotBackMsg)
	ON_MESSAGE(PreEnterViewMsg)
	ON_MESSAGE(PanningAwayFromParrotMsg)
	ON_MESSAGE(LeaveRoomMsg)
	ON_MESSAGE(TrueTalkNotifySpeechEndedMsg)
END_MESSAGE_MAP()

bool CParrot::_eatingChicken;
bool CParrot::_takeOff;
bool CParrot::_unused;
ParrotState CParrot::_state;
bool CParrot::_coreReplaced;

CParrot::CParrot() : CTrueTalkNPC() {
	_unused1 = 0;
	_carryParrot = "CarryParrot";
	_canDrag = true;
	_unused2 = 25;
	_lastSpeakTime = 0;
	_newXp = 73;
	_newXc = 58;
	_triedEatChicken = false;
	_eatOffsetX = 0;
	_panTarget = nullptr;

	_assetName = "z454.dlg";
	_assetNumber = 0x13880;
}

void CParrot::save(SimpleFile *file, int indent) {
	file->writeNumberLine(1, indent);
	file->writeNumberLine(_assetNumber, indent);

	file->writeQuotedLine(_assetName, indent);
	file->writeNumberLine(_unused1, indent);
	file->writeNumberLine(_eatingChicken, indent);
	file->writeNumberLine(_takeOff, indent);
	file->writeNumberLine(_unused, indent);

	file->writeQuotedLine(_carryParrot, indent);
	file->writeNumberLine(_canDrag, indent);
	file->writeNumberLine(_unused2, indent);
	file->writeNumberLine(_lastSpeakTime, indent);
	file->writeNumberLine(_newXp, indent);
	file->writeNumberLine(_newXc, indent);
	file->writeNumberLine(_triedEatChicken, indent);
	file->writeNumberLine(_eatOffsetX, indent);
	file->writeNumberLine(_state, indent);
	file->writeNumberLine(_coreReplaced, indent);

	CTrueTalkNPC::save(file, indent);
}

void CParrot::load(SimpleFile *file) {
	file->readNumber();
	_assetNumber = file->readNumber();

	_assetName = file->readString();
	_unused1 = file->readNumber();
	_eatingChicken = file->readNumber();
	_takeOff = file->readNumber();
	_unused = file->readNumber();

	_carryParrot = file->readString();
	_canDrag = file->readNumber();
	_unused2 = file->readNumber();
	_lastSpeakTime = file->readNumber();
	_newXp = file->readNumber();
	_newXc = file->readNumber();
	_triedEatChicken = file->readNumber();
	_eatOffsetX = file->readNumber();
	_state = (ParrotState)file->readNumber();
	_coreReplaced = file->readNumber();

	CTrueTalkNPC::load(file);
}

bool CParrot::ActMsg(CActMsg *msg) {
	if (msg->_action == "Chicken") {
		// Nothing to do
	} else if (msg->_action == "CarryParrotLeftView") {
		if (!_takeOff)
			setEatingChicken(false);
	} else if (msg->_action == "StartChickenDrag") {
		if (_state == PARROT_IN_CAGE) {
			stopMovie();
			startTalking(this, 280275, findView());
			_triedEatChicken = false;
		}
	} else if (msg->_action == "EnteringFromTOW" &&
			(_state == PARROT_IN_CAGE || _state == PARROT_ESCAPED)) {
		if (_takeOff) {
			_state = PARROT_ESCAPED;
		} else {
			setVisible(true);
			CTreeItem *cageBar = getRoot()->findByName("CageBar");
			detach();
			attach(cageBar);

			_state = PARROT_IN_CAGE;
			CActMsg actMsg1("OpenNow");
			actMsg1.execute("ParrotCage");
			CActMsg actMsg2("GainParrot");
			actMsg2.execute("ParrotLobbyController");
		}
	}

	return true;
}

bool CParrot::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
	if (!(_npcFlags & NPCFLAG_TAKE_OFF) && _speechCounter == 0) {
		CTrueTalkTriggerActionMsg triggerMsg(280250, 280250, 1);
		triggerMsg.execute(this);
	}

	return true;
}

bool CParrot::MovieEndMsg(CMovieEndMsg *msg) {
	if ((_npcFlags & NPCFLAG_TAKE_OFF) && clipExistsByEnd("Take Off", msg->_endFrame)) {
		setVisible(false);
		moveUnder(findRoom());
		stopMovie();

		CActMsg actMsg1("LoseParrot");
		actMsg1.execute("ParrotLobbyController");

		if (_panTarget) {
			CActMsg actMsg2("PanAwayFromParrot");
			actMsg2.execute(_panTarget);
			_panTarget = nullptr;
		} else {
			CActMsg actMsg2("Shut");
			actMsg2.execute("ParrotCage");
		}

		_npcFlags &= ~NPCFLAG_TAKE_OFF;
		_state = PARROT_ESCAPED;
	} else if (_npcFlags & NPCFLAG_MOVING) {
		if (_npcFlags & NPCFLAG_MOVE_START) {
			// Parrot is about to loop
			_npcFlags = (_npcFlags & ~NPCFLAG_MOVE_START) | NPCFLAG_MOVE_LOOP;
			if (_npcFlags & NPCFLAG_MOVE_LEFT) {
				playClip("Walk Left Loop", MOVIE_NOTIFY_OBJECT);
				movieEvent(236);
			} else {
				playClip("Walk Right Loop", MOVIE_NOTIFY_OBJECT);
			}
		} else if (_npcFlags & NPCFLAG_MOVE_LOOP) {
			// In progress movement loop
			int xp = _bounds.left + _bounds.width() / 2;

			if (_npcFlags & NPCFLAG_MOVE_LEFT) {
				if ((xp - _newXc) > 32) {
					setPosition(Point(_bounds.left - 40, _bounds.top));
					playClip("Walk Left Loop", MOVIE_NOTIFY_OBJECT);
					movieEvent(236);
				} else {
					setPosition(Point(_bounds.left - 10, _bounds.top));
					playClip("Walk Left Outro", MOVIE_NOTIFY_OBJECT);
					_npcFlags = (_npcFlags & ~NPCFLAG_MOVE_LOOP) | NPCFLAG_MOVE_FINISH;
				}
			} else {
				if ((_newXc - xp) > 32) {
					playClip("Walk Right Loop", MOVIE_NOTIFY_OBJECT);
					movieEvent(244);
				} else {
					playClip("Walk Right Outro", MOVIE_NOTIFY_OBJECT);
					_npcFlags = (_npcFlags & ~NPCFLAG_MOVE_LOOP) | NPCFLAG_MOVE_FINISH;
				}
			}
		} else if (_npcFlags & NPCFLAG_MOVE_FINISH) {
			// Finishing movement
			loadFrame(0);
			if (_npcFlags & NPCFLAG_MOVE_LEFT)
				setPosition(Point(_bounds.left - 30, _bounds.top));
			else
				setPosition(Point(_bounds.left + 14, _bounds.top));

			_npcFlags &= ~(NPCFLAG_MOVING | NPCFLAG_MOVE_FINISH | NPCFLAG_MOVE_LEFT | NPCFLAG_MOVE_RIGHT);
			CTrueTalkNPC::MovieEndMsg(msg);
		}
	} else if (_npcFlags & NPCFLAG_CHICKEN_OUTSIDE_CAGE) {
		Point pt = getMousePos();
		if (pt.x > 70 || pt.y < 90 || pt.y > 280) {
			stopMovie();
			loadFrame(0);
			_npcFlags &= ~NPCFLAG_CHICKEN_OUTSIDE_CAGE;
		}

		if (clipExistsByEnd("Walk Left Loop", msg->_endFrame)) {
			playClip("Lean Over To Chicken", MOVIE_NOTIFY_OBJECT);
			setPosition(Point(_bounds.left - 55, _bounds.top));
			_eatOffsetX = (-100 - _bounds.left) / 5;
			movieEvent(261);
			movieEvent(262);
			movieEvent(265);
			movieEvent(268);
			movieEvent(271);
			return true;

		} else if (clipExistsByEnd("Lean Over To Chicken", msg->_endFrame)) {
			// WORKAROUND: Do what the original obviously intended but got
			// wrong.. only flag chicken as eaten if it's still being dragged
			CTreeItem *dragItem = getGameManager()->_dragItem;
			CCarry *chicken = dynamic_cast<CCarry *>(dragItem);

			if (chicken)
				playClip("Eat Chicken");
			playClip("Eat Chicken 2", MOVIE_NOTIFY_OBJECT);

			if (chicken) {
				setEatingChicken(true);

				CTrueTalkTriggerActionMsg actionMsg;
				actionMsg._action = 280266;
				actionMsg._param2 = 1;
				actionMsg.execute(this);

				CActMsg actMsg("Eaten");
				actMsg.execute(chicken);
			}

			_npcFlags &= ~NPCFLAG_CHICKEN_OUTSIDE_CAGE;
			return true;
		}
	}

	if (clipExistsByEnd("Eat Chicken 2", msg->_endFrame)) {
		// Parrot has finished eating Chicken
		setEatingChicken(false);

		if (_takeOff) {
			// Perch has been taken, so take off
			loadMovie("z168.avi", false);
			playClip("Take Off", MOVIE_NOTIFY_OBJECT);
			setPosition(Point(20, 10));
			_npcFlags |= NPCFLAG_TAKE_OFF;
		} else {
			// Resetting back to standing
			_npcFlags &= ~(NPCFLAG_MOVING | NPCFLAG_MOVE_START | NPCFLAG_MOVE_LOOP
				| NPCFLAG_MOVE_FINISH | NPCFLAG_MOVE_LEFT | NPCFLAG_MOVE_RIGHT);
			_npcFlags |= NPCFLAG_MOVE_END;
			stopMovie();
			loadFrame(0);
			setPosition(Point(-90, _bounds.top));
		}
	} else {
		return CTrueTalkNPC::MovieEndMsg(msg);
	}

	return true;
}

bool CParrot::EnterViewMsg(CEnterViewMsg *msg) {
	static const char *const NAMES[] = {
		"Talking0", "Talking1", "Talking2", "Talking3", "Talking4",
		"Talking5", "Talking6", "Talking7", nullptr
	};

	if (_state == PARROT_IN_CAGE) {
		setPosition(Point(_newXp, _bounds.top));
		_canDrag = true;
		_npcFlags &= ~(NPCFLAG_MOVING | NPCFLAG_MOVE_START | NPCFLAG_MOVE_LOOP
			| NPCFLAG_MOVE_FINISH | NPCFLAG_MOVE_LEFT | NPCFLAG_MOVE_RIGHT | NPCFLAG_MOVE_END);
		loadFrame(0);
		setTalking(this, true, findView());

		if (_speechCounter > 0) {
			playRandomClip(NAMES, MOVIE_NOTIFY_OBJECT);
		} else {
			startTalking(this, 280258, findView());
		}

		petSetArea(PET_CONVERSATION);
		_triedEatChicken = false;
		_npcFlags |= NPCFLAG_START_IDLING;
	}

	return true;
}

bool CParrot::TrueTalkTriggerActionMsg(CTrueTalkTriggerActionMsg *msg) {
	if (_state != PARROT_MAILED) {
		CViewItem *view = msg->_param2 ? findView() : nullptr;
		startTalking(this, msg->_action, view);
	}

	return true;
}

bool CParrot::MouseDragStartMsg(CMouseDragStartMsg *msg) {
	if (_canDrag && _state == PARROT_IN_CAGE && checkPoint(msg->_mousePos, false, true)) {
		setVisible(false);
		CRoomItem *room = findRoom();

		moveUnder(room);
		startTalking(this, 280129);
		performAction(true);

		CCarry *item = dynamic_cast<CCarry *>(getRoot()->findByName(_carryParrot));
		if (item) {
			item->_canTake = true;
			CPassOnDragStartMsg passMsg;
			passMsg._mousePos = msg->_mousePos;
			passMsg.execute(item);
			msg->_dragItem = item;

			CActMsg actMsg("LoseParrot");
			actMsg.execute("ParrotLobbyController");
			return true;
		}
	}

	return false;
}

bool CParrot::LeaveViewMsg(CLeaveViewMsg *msg) {
	performAction(true);
	_npcFlags &= ~NPCFLAG_START_IDLING;

	return true;
}

bool CParrot::ParrotSpeakMsg(CParrotSpeakMsg *msg) {
	static const char *const ROOM_NAMES[] = {
		"SGTState", "SGTLittleLift", "SecClassLittleLift", "SecClassState",
		"Lift", "ServiceElevator", "Dome", "Home", "MoonEmbLobby", nullptr
	};

	if (!stateGetParrotMet() || _state == PARROT_MAILED || compareViewNameTo("Titania.Node 18.N"))
		return true;

	// Check for rooms not to speak in
	for (const char *const *s = &ROOM_NAMES[0]; *s; ++s) {
		if (isEquals(*s))
			return true;
	}

	// Don't have the parrot speak too often
	if ((getTicksCount() - _lastSpeakTime) < 20000 || _speechCounter)
		return true;

	playSound("z#475.wav", 50);

	if (msg->_target == "Bomb") {
		startTalking("PerchedParrot", 280236);
	} else if (msg->_target == "Announcements") {
		startTalking("PerchedParrot", 280263);
	} else if (msg->_target == "Television") {
		startTalking("PerchedParrot", 280264);
	} else if (msg->_target == "Barbot") {
		if (msg->_action == "AskForDrink")
			startTalking("PerchedParrot", 280262);
	} else if (msg->_target == "SuccUBus") {
		if (msg->_action == "TurnOn")
			startTalking("PerchedParrot", 80161);
		else if (msg->_action == "EnterView")
			startTalking("PerchedParrot", 80159);
	} else if (msg->_target == "Cellpoints") {
		if (getRandomNumber(2) == 0) {
			switch (getRandomNumber(2)) {
			case 0:
				startTalking("PerchedParrot", 80193);
				break;
			case 1:
				startTalking("PerchedParrot", 80197);
				break;
			case 2:
				startTalking("PerchedParrot", 80198);
				break;
			default:
				break;
			}
		} else if (msg->_action == "DoorBot") {
			startTalking("PerchedParrot", 80195);
		} else if (msg->_action == "DeskBot") {
			startTalking("PerchedParrot", 80194);
		} else if (msg->_action == "BarBot") {
			startTalking("PerchedParrot", 80191);
		} else if (msg->_action == "BellBot") {
			startTalking("PerchedParrot", 80192);
		} else if (msg->_action == "LiftBot") {
			startTalking("PerchedParrot", 80196);
		}
	}

	_lastSpeakTime = getTicksCount();
	return true;
}

bool CParrot::NPCPlayTalkingAnimationMsg(CNPCPlayTalkingAnimationMsg *msg) {
	static const char *const NAMES[] = {
		"Talking0", "Talking1", "Talking2", "Talking3", "Talking4",
		"Talking5", "Talking6", "Talking7", nullptr
	};

	if (!(_npcFlags & (NPCFLAG_MOVING | NPCFLAG_MOVE_START | NPCFLAG_MOVE_LOOP | NPCFLAG_MOVE_FINISH 
			| NPCFLAG_MOVE_LEFT | NPCFLAG_MOVE_RIGHT | NPCFLAG_MOVE_END))
			&& _visible && _state == PARROT_IN_CAGE) {
		if (compareViewNameTo("ParrotLobby.Node 1.N"))
			msg->_names = NAMES;
	}

	return true;
}

bool CParrot::NPCPlayIdleAnimationMsg(CNPCPlayIdleAnimationMsg *msg) {
	static const char *const NAMES[] = {
		"Idle0", "Idle1", "Peck At Feet", "Peck At Feet Left"
		"Peck At Feet Right", nullptr
	};

	if (!(_npcFlags & (NPCFLAG_MOVING | NPCFLAG_MOVE_START | NPCFLAG_MOVE_LOOP | NPCFLAG_MOVE_FINISH 
			| NPCFLAG_MOVE_LEFT | NPCFLAG_MOVE_RIGHT | NPCFLAG_MOVE_END))
			&& _visible && _state == PARROT_IN_CAGE && compareViewNameTo("ParrotLobby.Node 1.N")) {
		CGameObject *dragItem = getDraggingObject();
		if (!dragItem || dragItem->getName() == "Chicken") {
			if (!_coreReplaced || getRandomNumber(3) != 0) {
				if (getRandomNumber(1)) {
					startTalking(this, 280267, findView());
				} else {
					msg->_names = NAMES;
				}
			} else {
				int id = -1;
				switch (getParrotResponse()) {
				case 0:
					id = 280107;
					break;
				case 1:
					id = 280106;
					break;
				case 2:
					id = 280115;
					break;
				case 3:
					id = 280114;
					break;
				case 4:
					id = 280113;
					break;
				case 5:
					id = 280112;
					break;
				case 6:
					id = 280111;
					break;
				case 7:
					id = 280110;
					break;
				case 8:
					id = 280109;
					break;
				case 9:
					id = 280108;
					break;
				case 10:
					id = 280105;
					break;
				case 11:
					id = 280000;
					break;
				default:
					break;
				}

				if (id != -1)
					startTalking(this, id, findView());

				CActMsg actMsg("FlashCore");
				actMsg.execute("PerchCoreHolder");
			}
		}
	}

	return true;
}

bool CParrot::FrameMsg(CFrameMsg *msg) {
	if (!compareViewNameTo("ParrotLobby.Node 1.N"))
		return false;
	if (_state != PARROT_IN_CAGE)
		return true;

	Point pt = getMousePos();
	CGameObject *dragObject = getDraggingObject();
	int xp = _bounds.left + _bounds.width() / 2;
	bool chickenFlag = false;

	if ((_npcFlags & NPCFLAG_MOVE_END) && !hasActiveMovie()) {
		_newXc =  _newXp + _bounds.width() / 2;
		int xDiff = ABS(xp - _newXc);

		if (xDiff < 64) {
			if (_panTarget) {
				CActMsg actMsg("PanAwayFromParrot");
				actMsg.execute(_panTarget);
				_panTarget = nullptr;
			}

			_npcFlags &= ~(NPCFLAG_MOVING | NPCFLAG_MOVE_START | NPCFLAG_MOVE_LOOP
				| NPCFLAG_MOVE_FINISH | NPCFLAG_MOVE_LEFT | NPCFLAG_MOVE_RIGHT | NPCFLAG_MOVE_END);
			return true;
		}
	} else {
		if (dragObject)
			chickenFlag = dragObject && dragObject->isEquals("Chicken");

		if (_npcFlags & NPCFLAG_CHICKEN_OUTSIDE_CAGE) {
			if (!chickenFlag || pt.x > 70 || pt.y < 90 || pt.y > 280) {
				// A start of eating the chicken outside the cage has to be
				// aborted because the chicken has been moved out of range
				stopMovie();
				loadFrame(0);
				setPosition(Point(-90, _bounds.top));
				_npcFlags &= ~NPCFLAG_CHICKEN_OUTSIDE_CAGE;
			}
		} else {
			if (!chickenFlag)
				return false;
		}

		_newXc = CLIP((int)pt.x, 230, 480);
	}

	if ((_npcFlags & NPCFLAG_MOVING) || hasActiveMovie())
		return true;

	if (ABS(_newXc - xp) > 64) {
		_npcFlags |= NPCFLAG_MOVING | NPCFLAG_MOVE_START;

		if (_newXc >= xp) {
			// WORKAROUND: Original did not properly reset the eating chicken
			// flag when the player turns away from the cage
			setEatingChicken(false);

			setPosition(Point(_bounds.left + 30, _bounds.top));
			_npcFlags |= NPCFLAG_MOVE_RIGHT;
			playClip("Walk Right Intro", MOVIE_NOTIFY_OBJECT);
		} else {
			_npcFlags |= NPCFLAG_MOVE_LEFT;
			playClip("Walk Left Intro", MOVIE_NOTIFY_OBJECT);
		}
	} else if (chickenFlag && pt.y >= 90 && pt.y <= 280 && !_triedEatChicken) {
		CParrotTriesChickenMsg triesMsg;
		triesMsg.execute(dragObject);

		CTrueTalkTriggerActionMsg triggerMsg;
		int &action = triggerMsg._action;
		switch (triesMsg._condiment) {
		case 1:
			action = triesMsg._isHot ? 280034 : 280056;
			break;
		case 2:
			action = triesMsg._isHot ? 280033 : 280055;
			break;
		case 3:
			action = triesMsg._isHot ? 280032 : 280054;
			break;
		default:
			action = triesMsg._isHot ? 280266 : 280053;
			break;
		}

		if (action == 280266) {
			if (pt.x < 75) {
				// Parrot needs to reach outside the cage
				_npcFlags |= NPCFLAG_CHICKEN_OUTSIDE_CAGE;
				playClip("Walk Left Intro", MOVIE_STOP_PREVIOUS);
				playClip("Walk Left Loop", MOVIE_NOTIFY_OBJECT);
				movieEvent(236);
				chickenFlag = false;
			} else if ((pt.x - xp) > 15) {
				_npcFlags |= NPCFLAG_PECKING;
				playClip("Peck At Feet Right", MOVIE_NOTIFY_OBJECT);
				movieEvent(170);
			} else if ((xp - pt.x) > 15) {
				_npcFlags |= NPCFLAG_PECKING;
				playClip("Peck At Feet Left", MOVIE_NOTIFY_OBJECT);
				movieEvent(142);
			} else {
				_npcFlags |= NPCFLAG_PECKING;
				playClip("Peck At Feet", MOVIE_NOTIFY_OBJECT);
				movieEvent(157);
			}
		}

		if (chickenFlag) {
			triggerMsg._param2 = 1;
			triggerMsg.execute(this);
			_triedEatChicken = true;
		}
	}

	return true;
}

bool CParrot::MovieFrameMsg(CMovieFrameMsg *msg) {
	if (_npcFlags & NPCFLAG_PECKING) {
		// Whoopsy, the Parrot got your chicken
		CCarry *chicken = dynamic_cast<CCarry *>(findUnder(getRoot(), "Chicken"));
		if (chicken) {
			CActMsg actMsg("Eaten");
			actMsg.execute(chicken);
		}

		_npcFlags &= ~NPCFLAG_PECKING;
	}

	switch (msg->_frameNumber) {
	case 244:
		setPosition(Point(_bounds.left + 45, _bounds.top));
		break;
	case 261:
	case 262:
	case 265:
	case 268:
	case 271:
		setPosition(Point(_bounds.left + _eatOffsetX, _bounds.top));
		break;
	default:
		break;
	}

	return true;
}

bool CParrot::PutParrotBackMsg(CPutParrotBackMsg *msg) {
	const char *const NAMES[] = {
		"Talking0", "Talking1", "Talking2", "Talking3", "Talking4",
		"Talking5", "Talking6", "Talking7", nullptr
	};

	int xp = CLIP(msg->_value, 230, 480);
	setVisible(true);
	moveToView();
	_state = PARROT_IN_CAGE;

	setPosition(Point(xp - _bounds.width() / 2, _bounds.top));
	playRandomClip(NAMES, MOVIE_NOTIFY_OBJECT);

	CActMsg actMsg("GainParrot");
	actMsg.execute("ParrotLobbyController");

	return true;
}

bool CParrot::PreEnterViewMsg(CPreEnterViewMsg *msg) {
	if (_state == PARROT_IN_CAGE) {
		loadMovie("z167.avi", false);
		loadFrame(0);
	}

	return true;
}

bool CParrot::PanningAwayFromParrotMsg(CPanningAwayFromParrotMsg *msg) {
	if (_state != PARROT_IN_CAGE) {
		CActMsg actMsg("PanAwayFromParrot");
		actMsg.execute(msg->_target);
		_panTarget = nullptr;
	} else if (_takeOff) {
		_panTarget = msg->_target;
		loadMovie("z168.avi", false);
		stopMovie();
		playClip("Take Off", MOVIE_NOTIFY_OBJECT);
		_npcFlags |= NPCFLAG_TAKE_OFF;
	} else {
		_npcFlags |= NPCFLAG_MOVE_END;
		_panTarget = msg->_target;
		stopMovie();
	}

	return true;
}

bool CParrot::LeaveRoomMsg(CLeaveRoomMsg *msg) {
	if (_state == PARROT_IN_CAGE)
		startTalking(this, 280259);

	return true;
}

bool CParrot::TrueTalkNotifySpeechEndedMsg(CTrueTalkNotifySpeechEndedMsg *msg) {
	if (msg->_dialogueId == 80022) {
		// WORKAROUND: End of parrot speech after having fixed Titania
		unlockMouse();
		changeView("Titania.Node 18.N", "");
	}

	return CTrueTalkNPC::TrueTalkNotifySpeechEndedMsg(msg);
}

void CParrot::setEatingChicken(bool eating) {
	_eatingChicken = eating;
	CStatusChangeMsg statusMsg;
	statusMsg._newStatus = eating ? 0 : 1;
	statusMsg.execute("PerchCoreHolder");
}

} // End of namespace Titanic