aboutsummaryrefslogtreecommitdiff
path: root/engines/bladerunner/script/ai/maggie.cpp
blob: c1ff0e29dec1f972e536267296fc0f7138d42f37 (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
/* 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 "bladerunner/script/ai_script.h"
#include "bladerunner/vector.h"

namespace BladeRunner {

enum kMaggieStates {
	kMaggieStateIdle         = 0,
	kMaggieStateWalking      = 1,
	kMaggieStateJumping      = 2,
	kMaggieStateHappyA       = 3,
	kMaggieStateHappyB       = 4,
	kMaggieStateLayingDown   = 5,
	kMaggieStateLayingIdle   = 6,
	kMaggieStateStandingUp   = 7,
	kMaggieStateGoingToSleep = 8,
	kMaggieStateSleeping     = 9,
	kMaggieStateWakingUp     = 10,
	kMaggieStateBombIdle     = 11,
	kMaggieStateBombWalk     = 12,
	kMaggieStateBombJumping  = 13,
	kMaggieStateExploding    = 14,
	kMaggieStateDeadExploded = 15,
	kMaggieStateDead         = 16
};

AIScriptMaggie::AIScriptMaggie(BladeRunnerEngine *vm) : AIScriptBase(vm) {
	var_45F3F8 = 0;
	var_45F3FC = 0;
	var_45F400 = 0;
	var_45F404 = 0;
	var_45F408 = 0;
}

void AIScriptMaggie::Initialize() {
	_animationState = kMaggieStateIdle;
	_animationFrame = 0;
	_animationStateNext = 0;
	_animationNext = 0;
	var_45F3F8 = 0;
	var_45F3FC = 0;
	var_45F400 = 0;
	var_45F404 = 0;
	var_45F408 = 0;
	Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02Default);
}

bool AIScriptMaggie::Update() {
	int goal = Actor_Query_Goal_Number(kActorMaggie);

	if (Actor_Query_Which_Set_In(kActorMaggie) == kSetMA02_MA04
	 && Global_Variable_Query(kVariableChapter) == 4
	) {
		Actor_Put_In_Set(kActorMaggie, kSetFreeSlotG);
		Actor_Set_At_Waypoint(kActorMaggie, 39, 0);
	}

	if (goal == kGoalMaggieKP05WillExplode) {
		Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieKP05Explode);
	} else if (goal == kGoalMaggieKP05WalkToMcCoy
	        && Actor_Query_Inch_Distance_From_Actor(kActorMcCoy, kActorMaggie) < 60
	) {
		Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieKP05Explode);
	}

	if (Global_Variable_Query(kVariableChapter) == 5) {
		if (Actor_Query_Goal_Number(kActorMaggie) < 400) {
			Actor_Set_Goal_Number(kActorMaggie, 400);
		}
		return true;
	}
	return false;
}

void AIScriptMaggie::TimerExpired(int timer) {
	if (timer == 0) {
		int goal = Actor_Query_Goal_Number(kActorMaggie);
		if (goal == kGoalMaggieMA02Wait) {
			AI_Countdown_Timer_Reset(kActorMaggie, 0);
			if (Random_Query(0, 4)) {
				AI_Movement_Track_Flush(kActorMaggie);
				AI_Movement_Track_Append(kActorMaggie, randomWaypointMA02(), 0);
				AI_Movement_Track_Repeat(kActorMaggie);
			} else {
				Actor_Change_Animation_Mode(kActorMaggie, 54);
			}
			return; //true
		}

		if (goal == kGoalMaggieMA02SitDown) {
			AI_Countdown_Timer_Reset(kActorMaggie, 0);
			Actor_Change_Animation_Mode(kActorMaggie, 55);
			return; //true
		}
	}
	return; //false
}

void AIScriptMaggie::CompletedMovementTrack() {
	int goal = Actor_Query_Goal_Number(kActorMaggie);
	if (goal == 0 || goal > 9) {
		if (goal == kGoalMaggieKP05WalkToMcCoy) {
			Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieKP05WillExplode);
			return; //true
		}
	} else {
		if (goal == kGoalMaggieMA02WalkToEntrance) {
			Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02WalkToMcCoy);
			return; //true
		}

		if (goal == kGoalMaggieMA02Wait) {
			Actor_Face_Actor(kActorMaggie, kActorMcCoy, true);
			AI_Countdown_Timer_Reset(kActorMaggie, 0);
			AI_Countdown_Timer_Start(kActorMaggie, 0, Random_Query(1, 5));
			return; //true
		}

		if (goal == 9) {
			Actor_Face_Actor(kActorMaggie, kActorMcCoy, true);
			Actor_Change_Animation_Mode(kActorMaggie, 54);
			return; //true
		}
	}
	Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02Wait);
	return; //true
}

void AIScriptMaggie::ReceivedClue(int clueId, int fromActorId) {
}

void AIScriptMaggie::ClickedByPlayer() {
	if (!Game_Flag_Query(kFlagMcCoyIsHelpingReplicants)
	 &&  Global_Variable_Query(kVariableChapter) == 5
	) {
		if (Actor_Query_Goal_Number(kActorMaggie) == kGoalMaggieKP05WalkToMcCoy) {
			Actor_Set_Targetable(kActorMaggie, true);
			AI_Movement_Track_Flush(kActorMaggie);
			Actor_Face_Actor(kActorMcCoy, kActorMaggie, true);
			Actor_Says(kActorMcCoy, 2400, kAnimationModeFeeding);
		}
		return; // true
	}

	if (_animationState == kMaggieStateDead) {
		return; // false
	}

	Actor_Face_Actor(kActorMcCoy, kActorMaggie, true);

	float mccoy_x, mccoy_y, mccoy_z;
	Actor_Query_XYZ(kActorMcCoy, &mccoy_x, &mccoy_y, &mccoy_z);
	if (distanceToActor(kActorMaggie, mccoy_x, mccoy_y, mccoy_z) > 60.0f) {
		Actor_Says(0, 2430, 18);
		Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02WalkToMcCoy);
		return; // true
	}

	int v6 = Random_Query(0, 4);
	if (v6 == 1) {
		Actor_Says(kActorMcCoy, 2440, 18);
	}
	if (v6 == 0) {
		Actor_Says(kActorMcCoy, 2435, 13);
	}

	int goal = Actor_Query_Goal_Number(kActorMaggie);
	if (goal == kGoalMaggieMA02Wait) {
		if (Random_Query(0, 1)) {
			Actor_Face_Actor(kActorMaggie, kActorMcCoy, true);
			Actor_Change_Animation_Mode(kActorMaggie, 57);
		} else {
			Actor_Face_Actor(kActorMaggie, kActorMcCoy, true);
			Actor_Change_Animation_Mode(kActorMaggie, 56);
		}
		AI_Countdown_Timer_Reset(kActorMaggie, 0);
		AI_Countdown_Timer_Start(kActorMaggie, 0, Random_Query(3, 9));
		return; // true
	}

	if (goal == 10) {
		Actor_Change_Animation_Mode(kActorMaggie, kAnimationModeIdle);
		return; // true
	}

	if (goal == 11) {
		Actor_Change_Animation_Mode(kActorMaggie, 54);
		return; // true
	}

	Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02Wait);
	return; // true
}

void AIScriptMaggie::EnteredScene(int sceneId) {
}

void AIScriptMaggie::OtherAgentEnteredThisScene(int otherActorId) {
}

void AIScriptMaggie::OtherAgentExitedThisScene(int otherActorId) {
	if (otherActorId == kActorMcCoy
	 && Actor_Query_Which_Set_In(kActorMaggie) == kSetMA02_MA04
	 && Global_Variable_Query(kVariableChapter) < 4
	) {
		AI_Movement_Track_Flush(kActorMaggie);
		Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02Default);
	}
}

void AIScriptMaggie::OtherAgentEnteredCombatMode(int otherActorId, int combatMode) {
}

void AIScriptMaggie::ShotAtAndMissed() {
}

bool AIScriptMaggie::ShotAtAndHit() {
	AI_Movement_Track_Flush(kActorMaggie);
	Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieKP05WillExplode);
	Actor_Set_Targetable(kActorMaggie, false);
	return false;
}

void AIScriptMaggie::Retired(int byActorId) {
}

int AIScriptMaggie::GetFriendlinessModifierIfGetsClue(int otherActorId, int clueId) {
	return 0;
}

bool AIScriptMaggie::GoalChanged(int currentGoalNumber, int newGoalNumber) {
	if (currentGoalNumber == kGoalMaggieDead) {
		return true;
	}

	switch (newGoalNumber) {
	case kGoalMaggieMA02Default:
		Actor_Put_In_Set(kActorMaggie, kSetMA02_MA04);
		Actor_Set_At_Waypoint(kActorMaggie, 265, 780);
		return true;

	case kGoalMaggieMA02WalkToEntrance:
		Actor_Put_In_Set(kActorMaggie, kSetMA02_MA04);
		Actor_Set_At_Waypoint(kActorMaggie, randomWaypointMA02(), 512);
		AI_Movement_Track_Flush(kActorMaggie);
		AI_Movement_Track_Append(kActorMaggie, 264, 0);
		AI_Movement_Track_Repeat(kActorMaggie);
		return true;

	case kGoalMaggieMA02GetFed:
		Player_Loses_Control();
		AI_Movement_Track_Flush(kActorMaggie);
		Loop_Actor_Walk_To_Actor(kActorMaggie, kActorMcCoy, 48, false, false);
		Actor_Face_Actor(kActorMcCoy, kActorMaggie, true);
		Actor_Face_Actor(kActorMaggie, kActorMcCoy, false);
		Actor_Says(kActorMcCoy, 2400, kAnimationModeFeeding);
		Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02Wait);
		Player_Gains_Control();
		return true;

	case kGoalMaggieMA02WalkToMcCoy:
		AI_Countdown_Timer_Reset(kActorMaggie, 0);
		AI_Movement_Track_Flush(kActorMaggie);
		Loop_Actor_Walk_To_Actor(kActorMaggie, kActorMcCoy, 30, false, false);
		Actor_Face_Actor(kActorMaggie, kActorMcCoy, true);
		Actor_Change_Animation_Mode(kActorMaggie, 56);
		Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02Wait);
		return true;

	case kGoalMaggieMA02Wait:
		AI_Countdown_Timer_Reset(kActorMaggie, 0);
		AI_Countdown_Timer_Start(kActorMaggie, 0, Random_Query(3, 9));
		return true;

	case 9:
		if (Random_Query(0, 2) <= 0) {
			Actor_Face_Actor(kActorMaggie, kActorMcCoy, false);
			Actor_Change_Animation_Mode(kActorMaggie, 54);
		} else {
			AI_Movement_Track_Flush(kActorMaggie);
			if (Actor_Query_Which_Set_In(kActorMaggie) == kSetMA02_MA04) {
				AI_Movement_Track_Append(kActorMaggie, randomWaypointMA02(), 486);
			}
			AI_Movement_Track_Repeat(kActorMaggie);
		}
		return true;

	case kGoalMaggieMA02SitDown:
		Actor_Change_Animation_Mode(kActorMaggie, 54);
		_animationState = kMaggieStateLayingIdle;
		_animationFrame = 0;
		AI_Countdown_Timer_Reset(kActorMaggie, 0);
		AI_Countdown_Timer_Start(kActorMaggie, 0, Random_Query(2, 9));
		return true;

	case kGoalMaggieMA02Sleep:
		Actor_Change_Animation_Mode(kActorMaggie, 55);
		_animationState = kMaggieStateSleeping;
		_animationFrame = 0;
		return true;

	case 400:
		Actor_Set_Goal_Number(kActorMaggie, 410);
		break;

	case kGoalMaggieKP05Wait:
		AI_Movement_Track_Flush(kActorMaggie);
		Game_Flag_Set(kFlagMaggieHasBomb);
		Actor_Put_In_Set(kActorMaggie, kSetKP05_KP06);
		Actor_Set_At_XYZ(kActorMaggie, -672.0, 0.0, -428.0, 653);
		Actor_Change_Animation_Mode(kActorMaggie, kAnimationModeIdle);
		break;

	case kGoalMaggieKP05McCoyEntred:
		Scene_Exits_Disable();
		Loop_Actor_Walk_To_XYZ(kActorMaggie, -734.0, 0.0, -432.0, 0, false, false, 0);
		Actor_Face_Actor(kActorMaggie, kActorMcCoy, true);
		Actor_Change_Animation_Mode(kActorMaggie, 56);
		Actor_Face_Actor(kActorMcCoy, kActorMaggie, true);
		Actor_Says(kActorMcCoy, 2225, kAnimationModeTalk);
		Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieKP05WalkToMcCoy);
		break;

	case kGoalMaggieKP05WalkToMcCoy:
		if (Actor_Query_Is_In_Current_Set(kActorSteele)) {
			Actor_Says(kActorSteele, 3270, 59);
		}
		AI_Movement_Track_Flush(kActorMaggie);
		AI_Movement_Track_Append(kActorMaggie, 540, 0);
		AI_Movement_Track_Repeat(kActorMaggie);
		break;

	case kGoalMaggieKP05Explode:
		AI_Movement_Track_Flush(kActorMaggie);
		Actor_Face_Actor(kActorMcCoy, kActorMaggie, true);
		Sound_Play(494, 50, 0, 0, 100);
		Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieDead);
		Actor_Change_Animation_Mode(kActorMaggie, 51);
		if (Actor_Query_Inch_Distance_From_Actor(kActorMcCoy, kActorMaggie) < 144) {
			Player_Loses_Control();
			Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeDie);
			Actor_Retired_Here(kActorMcCoy, 6, 6, 1, -1);
		} else {
			Delay(3000);
			Scene_Exits_Disable();
			Actor_Says(kActorMcCoy, 2235, 12);
			if (Actor_Query_Is_In_Current_Set(kActorSteele)) {
				Actor_Says(kActorSteele, 1530, 58);
				Actor_Set_Goal_Number(kActorSteele, kGoalSteeleKP05Leave);
			}
			Delay(2000);
			Actor_Says(kActorMcCoy, 2390, 13);
			if (Actor_Query_Goal_Number(kActorSadik) == 411) {
				Actor_Set_Goal_Number(kActorSadik, 412);
			} else { // there is no way how Maggie can explode and Sadik's goal is not 411
				Actor_Set_Goal_Number(kActorClovis, kGoalClovisKP06TalkToMcCoy);
			}
		}
		break;

	}
	return false;
}

bool AIScriptMaggie::UpdateAnimation(int *animation, int *frame) {
	int goal;
	switch (_animationState) {
	case kMaggieStateDead:
		*animation = 871;
		_animationFrame = 0;
		break;

	case kMaggieStateDeadExploded:
		*animation = 874;
		_animationFrame = Slice_Animation_Query_Number_Of_Frames(874) - 1;
		break;

	case kMaggieStateExploding:
		*animation = 874;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(874) - 1) {
			_animationState = kMaggieStateDeadExploded;
			_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
			Actor_Put_In_Set(kActorMaggie, kSetFreeSlotI);
			Actor_Set_At_Waypoint(kActorMaggie, 41, 0);
		}
		break;

	case kMaggieStateBombJumping:
		*animation = 873;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(873)) {
			_animationState = kMaggieStateBombIdle;
			_animationFrame = 0;
			*animation = 875;
			Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieKP05WillExplode);
		}
		break;

	case kMaggieStateBombWalk:
		*animation = 872;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(872)) {
			_animationFrame = 0;
		}
		break;

	case kMaggieStateBombIdle:
		*animation = 875;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(875)) {
			_animationFrame = 0;
		}
		break;

	case kMaggieStateWakingUp:
		*animation = 876;
		_animationFrame--;
		if (_animationFrame > 0) {
			break;
		}
		_animationState = kMaggieStateLayingIdle;
		_animationFrame = 0;
		*animation = 867;
		goal = Actor_Query_Goal_Number(kActorMaggie);
		if (goal == kGoalMaggieMA02GetFed) {
			_animationState = kMaggieStateStandingUp;
			_animationFrame = 0;
			*animation = 868;
		} else if (goal == kGoalMaggieMA02WalkToMcCoy) {
			Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02SitDown);
			Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02WalkToMcCoy);
		} else {
			Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02SitDown);
		}
		break;

	case kMaggieStateSleeping:
		*animation = 876;
		_animationFrame = Slice_Animation_Query_Number_Of_Frames(876) - 1;
		break;

	case kMaggieStateGoingToSleep:
		*animation = 876;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(876) - 1) {
			_animationState = kMaggieStateSleeping;
			Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02Sleep);
		}
		break;

	case kMaggieStateStandingUp:
		*animation = 868;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(868)) {
			*animation = 864;
			_animationState = kMaggieStateIdle;
			_animationFrame = 0;
			if (Actor_Query_Goal_Number(kActorMaggie) == kGoalMaggieMA02SitDown) {
				Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02Wait);
			} else if (Actor_Query_Goal_Number(kActorMaggie) == kGoalMaggieMA02WalkToMcCoy) {
				Actor_Set_Goal_Number(kActorMaggie, 12); // this is never used
				Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02WalkToMcCoy);
			}
		}
		break;

	case kMaggieStateLayingIdle:
		*animation = 867;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(867)) {
			_animationFrame = 0;
		}
		break;

	case kMaggieStateLayingDown:
		*animation = 866;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(866)) {
			_animationState = kMaggieStateLayingIdle;
			_animationFrame = 0;
			*animation = 867;
			if (Actor_Query_Goal_Number(kActorMaggie) == 9) {
				Actor_Set_Goal_Number(kActorMaggie, kGoalMaggieMA02SitDown);
			}
		}
		break;

	case kMaggieStateHappyB:
		*animation = 865;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(865)) {
			_animationFrame = 0;
			var_45F3F8--;
			if (var_45F3F8 <= 0) {
				Actor_Change_Animation_Mode(kActorMaggie, kAnimationModeIdle);
				*animation = 864;
			}
		}
		break;

	case kMaggieStateHappyA:
		*animation = 870;
		if (_animationFrame == 1) {
			Sound_Play(Random_Query(263, 264), 50, 0, 0, 50);
		}
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
			var_45F3FC--;
			if (var_45F3FC <= 0) {
				Actor_Change_Animation_Mode(kActorMaggie, kAnimationModeIdle);
				*animation = 864;
				_animationState = kMaggieStateIdle;
			}
			_animationFrame = 0;
		}
		break;

	case kMaggieStateJumping:
		*animation = 869;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(869)) {
			Actor_Change_Animation_Mode(kActorMaggie, kAnimationModeIdle);
			*animation = 864;
			_animationState = kMaggieStateIdle;
			_animationFrame = 0;
		}
		break;

	case kMaggieStateWalking:
		*animation = 863;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(863)) {
			_animationFrame = 0;
		}
		break;

	case kMaggieStateIdle:
		*animation = 864;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(864)) {
			_animationFrame = 0;
		}
		break;
	}
	*frame = _animationFrame;
	return true;
}

bool AIScriptMaggie::ChangeAnimationMode(int mode) {
	if (mode == kAnimationModeWalk) {
		if (Game_Flag_Query(kFlagMaggieHasBomb)) {
			_animationState = kMaggieStateBombWalk;
			_animationFrame = 0;
		} else {
			_animationState = kMaggieStateWalking;
			_animationFrame = 0;
		}
		return true;
	}
	if (mode == kAnimationModeIdle) {
		if (Game_Flag_Query(kFlagMaggieHasBomb)) {
			_animationState = kMaggieStateBombIdle;
			_animationFrame = kMaggieStateIdle;
		} else {
			switch (_animationState) {
			case kMaggieStateGoingToSleep:
			case kMaggieStateSleeping:
				_animationState = kMaggieStateWakingUp;
				break;
			case kMaggieStateIdle:
				_animationState = kMaggieStateStandingUp;
				_animationFrame = 0;
				break;
			case kMaggieStateLayingDown:
				_animationState = kMaggieStateStandingUp;
				_animationFrame = 0;
				break;
			case kMaggieStateJumping:
			case kMaggieStateStandingUp:
			case kMaggieStateWakingUp:
				break;
			default:
				_animationState = kMaggieStateIdle;
				_animationFrame = 0;
				break;
			}
		}
		return true;
	}

	switch (mode) {
	case 51:
		_animationState = kMaggieStateExploding;
		_animationFrame = 0;
		Sound_Play(272, 50, 0, 0, 50);
		break;

	case kAnimationModeFeeding:
		if (Game_Flag_Query(kFlagMaggieHasBomb)) {
			_animationState = kMaggieStateBombJumping;
			_animationFrame = 0;
		} else {
			_animationState = kMaggieStateJumping;
			_animationFrame = 0;
		}
		break;

	case 54:
		if (_animationState <= kMaggieStateSleeping) {
			if (_animationState > 0) {
				if (_animationState == kMaggieStateSleeping) {
					_animationState = kMaggieStateWakingUp;
					_animationFrame = 0;
				}
			} else {
				_animationState = kMaggieStateLayingDown;
				_animationFrame = 0;
			}
		}
		break;

	case 55:
		if (_animationState == kMaggieStateLayingIdle) {
			_animationState = kMaggieStateGoingToSleep;
			_animationFrame = 0;
		}
		break;

	case 56:
		if (_animationState != 3) {
			_animationFrame = 0;
			_animationState = kMaggieStateHappyA;
		}
		var_45F3FC = Random_Query(2, 6);
		break;

	case 57:
		if (_animationState != kMaggieStateHappyB) {
			_animationFrame = 0;
			_animationState = kMaggieStateHappyB;
		}
		var_45F3F8 = Random_Query(2, 6);
		Sound_Play(276, 50, 0, 0, 50);
		break;

	case 88:
		_animationState = kMaggieStateDead;
		_animationFrame = 0;
		break;

	}
	return true;
}

void AIScriptMaggie::QueryAnimationState(int *animationState, int *animationFrame, int *animationStateNext, int *animationNext) {
	*animationState     = _animationState;
	*animationFrame     = _animationFrame;
	*animationStateNext = _animationStateNext;
	*animationNext      = _animationNext;
}

void AIScriptMaggie::SetAnimationState(int animationState, int animationFrame, int animationStateNext, int animationNext) {
	_animationState     = animationState;
	_animationFrame     = animationFrame;
	_animationStateNext = animationStateNext;
	_animationNext      = animationNext;
}

bool AIScriptMaggie::ReachedMovementTrackWaypoint(int waypointId) {
	return true;
}

void AIScriptMaggie::FledCombat() {
}

int AIScriptMaggie::randomWaypointMA02() {
	switch (Random_Query(0, 3)) {
	case 0:
		return 264;

	case 1:
		return 265;

	case 2:
		return 266;

	default:
		return 267;
	}
}

float AIScriptMaggie::distanceToActor(int actorId, float x, float y, float z) {
	float actorX, actorY, actorZ;
	Actor_Query_XYZ(actorId, &actorX, &actorY, &actorZ);
	return sqrt(static_cast<float>((z - actorZ) * (z - actorZ) + (y - actorY) * (y - actorY) + (x - actorX) * (x - actorX)));
}

} // End of namespace BladeRunner