aboutsummaryrefslogtreecommitdiff
path: root/engines/bladerunner/script/ai/howie_lee.cpp
blob: 87012302b2bfe7d99a41d2791b4b3fa2bb4cff90 (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
/* 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"

namespace BladeRunner {

AIScriptHowieLee::AIScriptHowieLee(BladeRunnerEngine *vm) : AIScriptBase(vm) {
	var_45DFB8 = 0;
}

void AIScriptHowieLee::Initialize() {
	_animationFrame = 0;
	_animationState = 0;
	_animationStateNext = 0;
	_animationNext = 0;
	var_45DFB8 = false;

	Actor_Put_In_Set(kActorHowieLee, kSetCT01_CT12);
	Actor_Set_At_Waypoint(kActorHowieLee, 67, 605); // in kSetCT01_CT12
	Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeDefault);
}

bool AIScriptHowieLee::Update() {

	if (_vm->_cutContent) {
		// keep Howie in Acts 2 and 3
		// Howie in Acts 2 and 3 will have a routine with existing waypoints/goals,
		// so no need to add new goals (> 100) for those Acts
		if (Actor_Query_Goal_Number(kActorHowieLee) < 100
		 && Global_Variable_Query(kVariableChapter) == 4
		) {
			Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeGoesToFreeSlotC);
		}

		if (Global_Variable_Query(kVariableChapter) > 3) {
			return true;
		}
	} else {
		if (Actor_Query_Goal_Number(kActorHowieLee) < 100
		 && Global_Variable_Query(kVariableChapter) == 2
		) {
			Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeGoesToFreeSlotC);
		}

		if (Global_Variable_Query(kVariableChapter) > 1) {
			return true;
		}
	}

	if (Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeDefault) {
		Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeMovesInDiner01);
	}

	// In the original code this is used (in Act 1) to get Howie back to the Diner
	// from goals kGoalHowieLeeGoesToCT04GarbageBin or kGoalHowieLeeGoesToFreeSlotH
	// It might cause a blink-in issue, depending when update() will be called for Howie
	// This is kept as a backup while similar code is placed in the CT01 and CT02 scenes InitializeScene()
	// that will handle Howie appearing there immediately (fix for blink in)
	if ( Game_Flag_Query(kFlagMcCoyInChinaTown)
	 && !Actor_Query_In_Set(kActorHowieLee, kSetCT01_CT12)
	 && Global_Variable_Query(kVariableChapter) == 1 // added condition - in cut content don't force Howie to return to CT01 here after Act 1
	) {
		AI_Movement_Track_Flush(kActorHowieLee);
		AI_Movement_Track_Append(kActorHowieLee, 67, 0); // in kSetCT01_CT12
		Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeDefault);
	}

#if BLADERUNNER_ORIGINAL_BUGS
	if ( Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeMovesInDiner01
	 &&  Game_Flag_Query(kFlagCT01BoughtHowieLeeFood)
	 && !Game_Flag_Query(kFlagMcCoyInChinaTown) ) {
		Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeGoesToCT04GarbageBin);
		return true;
	}
#else
	// Prevents possibility of Howie Lee from blinking in/out of existence
	// when the fly-out loop is playing and/or when McCoy enters and exits the Spinner with the spinner doors animation restored
	if ((Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeMovesInDiner01
	     || Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeMovesInDiner02
	     || Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeMovesInDiner03
	     || Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeMovesInDiner06
	     || Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeDefault)
	     &&  Game_Flag_Query(kFlagCT01BoughtHowieLeeFood)
	     && !Game_Flag_Query(kFlagMcCoyInChinaTown)
	     &&  Player_Query_Current_Scene() != kSceneCT01
	     &&  Player_Query_Current_Scene() != kSceneCT12
	) {
		Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeGoesToCT04GarbageBin);
		return true;
	}
#endif // BLADERUNNER_ORIGINAL_BUGS

	return false;
}

void AIScriptHowieLee::TimerExpired(int timer) {
	//return false;
}

void AIScriptHowieLee::CompletedMovementTrack() {
	if (Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeMovesInDiner01) {
		Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeMovesInDiner02);
		return; // true;
	}

	if (Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeMovesInDiner02) {
		Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeMovesInDiner03);
		return; // true;
	}

	if (Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeMovesInDiner03) {
		if (_vm->_cutContent) {
			//
			// *after Act 1* Howie will be going to the Garbage Bin "regularly"
			// if McCoy is not in scenes CT01 and CT12 (where Howie is visible working at the diner)
			// otherwise he'll do the short cycle (goals 0, 1, 2, 3)
			// This will result in Howie not being at the Diner sometimes even when McCoy is in Chinatown area
			// This won't happen in Act 1, since he is most useful during that Act
			if (Global_Variable_Query(kVariableChapter) > 1
			    && Player_Query_Current_Scene() != kSceneCT01
			    && Player_Query_Current_Scene() != kSceneCT12
			    && Player_Query_Current_Scene() != kSceneCT04
			) {
				Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeGoesToCT04GarbageBin);
				return; // true;
			} else {
				Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeDefault);
				return; // true;
			}
		} else {
			Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeDefault);
			return; // true;
		}
	}

#if BLADERUNNER_ORIGINAL_BUGS
	if (Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeMovesInDiner03) {
			Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeGoesToCT04GarbageBin);
			return; // true;
	}
#endif // BLADERUNNER_ORIGINAL_BUGS

	if (Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeGoesToCT04GarbageBin) {
		Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeGoesToFreeSlotH);
		return; // true;
	}

	if (Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeGoesToFreeSlotH) {
#if BLADERUNNER_ORIGINAL_BUGS
		Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeDefault);
		return; // true;
#else
		// don't blink-in and also only return to diner routine if McCoy is actually in Chinatown
		if (Game_Flag_Query(kFlagMcCoyInChinaTown)
		    && Player_Query_Current_Scene() != kSceneCT01
		    && Player_Query_Current_Scene() != kSceneCT12
		) {
			Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeDefault);
			return; // true;
		} else {
			// return to "garbage bin" goal instead of blinking in
			Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeGoesToCT04GarbageBin);
			return; // true;
		}
#endif // BLADERUNNER_ORIGINAL_BUGS
	}

	// return false;
}

void AIScriptHowieLee::ReceivedClue(int clueId, int fromActorId) {
	//return false;
}

void AIScriptHowieLee::ClickedByPlayer() {
	//return false;
}

void AIScriptHowieLee::EnteredScene(int sceneId) {
	if (Actor_Query_Goal_Number(kActorHowieLee) == kGoalHowieLeeGoesToCT04GarbageBin
	 && Actor_Query_In_Set(kActorHowieLee, kSetCT03_CT04)
	) {
		if ( Game_Flag_Query(kFlagCT04HomelessKilledByMcCoy)
		 && !Game_Flag_Query(kFlagCT04HomelessBodyInDumpster)
		 && !Game_Flag_Query(kFlagCT04HomelessBodyFound)
		) {
			Game_Flag_Set(kFlagCT04HomelessBodyFound);
			// return false;
		}

		if (Game_Flag_Query(kFlagCT04HomelessKilledByMcCoy)
		 &&  Game_Flag_Query(kFlagCT04HomelessBodyInDumpster)
		 && !Game_Flag_Query(kFlagCT04HomelessBodyFound)
		 &&  Random_Query(1, 10) == 1
		) {
			Game_Flag_Set(kFlagCT04HomelessBodyFound);
			// return true;
		}
		// return false;
	}
}

void AIScriptHowieLee::OtherAgentEnteredThisScene(int otherActorId) {
#if BLADERUNNER_ORIGINAL_BUGS
#else
	// prevent player from actually meeting hovering Howie half-body in kSetCT03_CT04
	if (otherActorId == kActorMcCoy
	    && Actor_Query_In_Set(kActorHowieLee, kSetCT03_CT04)
	) {
		AI_Movement_Track_Flush(kActorHowieLee);
		AI_Movement_Track_Append(kActorHowieLee, 67, 0); // in kSetCT01_CT12
		Actor_Set_Goal_Number(kActorHowieLee, kGoalHowieLeeDefault);
	}
#endif // BLADERUNNER_ORIGINAL_BUGS
	// return false;
}

void AIScriptHowieLee::OtherAgentExitedThisScene(int otherActorId) {
	// return false;
}

void AIScriptHowieLee::OtherAgentEnteredCombatMode(int otherActorId, int combatMode) {
	// return false;
}

void AIScriptHowieLee::ShotAtAndMissed() {
	// return false;
}

bool AIScriptHowieLee::ShotAtAndHit() {
	return false;
}

void AIScriptHowieLee::Retired(int byActorId) {
	// return false;
}

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

bool AIScriptHowieLee::GoalChanged(int currentGoalNumber, int newGoalNumber) {
	switch (newGoalNumber) {
	case kGoalHowieLeeMovesInDiner01:
		AI_Movement_Track_Flush(kActorHowieLee);
		if (Random_Query(1, 2) == 1) {
			AI_Movement_Track_Append_With_Facing(kActorHowieLee, 67, Random_Query(3, 10), 720); // in kSetCT01_CT12
		} else {
			AI_Movement_Track_Append_With_Facing(kActorHowieLee, 69, Random_Query(3, 10), 640); // in kSetCT01_CT12
		}
		AI_Movement_Track_Repeat(kActorHowieLee);
		return true;
	case kGoalHowieLeeMovesInDiner02:
		AI_Movement_Track_Flush(kActorHowieLee);
		if (Random_Query(1, 2) == 1) {
			AI_Movement_Track_Append_With_Facing(kActorHowieLee, 68, Random_Query(3, 10), 641); // in kSetCT01_CT12
		} else {
			AI_Movement_Track_Append_With_Facing(kActorHowieLee, 67, Random_Query(3, 10), 720); // in kSetCT01_CT12
		}
		AI_Movement_Track_Repeat(kActorHowieLee);
		return true;
	case kGoalHowieLeeMovesInDiner03:
		AI_Movement_Track_Flush(kActorHowieLee);
		if (Random_Query(1, 2) == 1) {
			AI_Movement_Track_Append_With_Facing(kActorHowieLee, 69, Random_Query(3, 10), 640); // in kSetCT01_CT12
		} else {
			AI_Movement_Track_Append_With_Facing(kActorHowieLee, 68, Random_Query(3, 10), 641); // in kSetCT01_CT12
		}
		AI_Movement_Track_Repeat(kActorHowieLee);
		return true;
	case kGoalHowieLeeGoesToCT04GarbageBin:
		AI_Movement_Track_Flush(kActorHowieLee);
		AI_Movement_Track_Append(kActorHowieLee, 66, 30);  // in kSetCT03_CT04
		AI_Movement_Track_Repeat(kActorHowieLee);
		return true;
	case kGoalHowieLeeGoesToFreeSlotH:
		AI_Movement_Track_Flush(kActorHowieLee);
		AI_Movement_Track_Append(kActorHowieLee, 40, 60);  // in kSetFreeSlotH
		AI_Movement_Track_Repeat(kActorHowieLee);
		return true;
	case kGoalHowieLeeMovesInDiner06: // Unused goal?
		AI_Movement_Track_Flush(kActorHowieLee);
		AI_Movement_Track_Append(kActorHowieLee, 67, 90); // in kSetCT01_CT12
		AI_Movement_Track_Repeat(kActorHowieLee);
		return true;
	case kGoalHowieLeeStopMoving:
		AI_Movement_Track_Flush(kActorHowieLee);
		return false;
	case kGoalHowieLeeGoesToFreeSlotC:
		AI_Movement_Track_Flush(kActorHowieLee);
		Actor_Put_In_Set(kActorHowieLee, kSetFreeSlotC);
		Actor_Set_At_Waypoint(kActorHowieLee, 35, 0); // in kSetFreeSlotC
		return false;
	}
	return false;
}

bool AIScriptHowieLee::UpdateAnimation(int *animation, int *frame) {
	switch (_animationState) {
	case 0:
		_animationFrame++;
		if (var_45DFB8) {
			*animation = 673;
			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(673)) {
				_animationFrame = 0;
				if (Random_Query(0, 2) > 0) {
					var_45DFB8 ^= 1;
				}
			}
		} else {
			*animation = 671;
			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(671)) {
				_animationFrame = 0;
				if (Random_Query(0, 1) > 0) {
					var_45DFB8 ^= 1;
				}
			}
		}
		break;
	case 1:
		*animation = 674;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(674)) {
			_animationFrame = 0;
			if (_animationState < 3 || _animationState > 8) {
				_animationState = 0;
				_animationFrame = 0;
				var_45DFB8 = Random_Query(0, 1);
			} else {
				Game_Flag_Set(kFlagHowieLeeAnimation1);
			}
			*animation = 673;
		}
		break;
	case 2:
		*animation = 672;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(672)) {
			_animationFrame = 0;
		}
		break;
	case 3:
		if (Game_Flag_Query(kFlagHowieLeeAnimation1)) {
			Game_Flag_Reset(kFlagHowieLeeAnimation1);
			_animationState = 0;
			_animationFrame = 0;
			var_45DFB8 = Random_Query(0, 1);
			*animation = 671;
		} else {
			_animationFrame++;
			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(676)) {
				_animationFrame = 0;
			}
			*animation = 676;
		}
		break;
	case 4:
		*animation = 677;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(677)) {
			_animationState = 3;
			_animationFrame = 0;
			*animation = 676;
		}
		break;
	case 5:
		*animation = 678;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(678)) {
			_animationState = 3;
			_animationFrame = 0;
			*animation = 676;
		}
		break;
	case 6:
		*animation = 679;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(679)) {
			_animationState = 3;
			_animationFrame = 0;
			*animation = 676;
		}
		break;
	case 7:
		*animation = 680;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(680)) {
			_animationState = 3;
			_animationFrame = 0;
			*animation = 676;
		}
		break;
	case 8:
		*animation = 681;
		_animationFrame++;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(681)) {
			_animationState = 3;
			_animationFrame = 0;
			*animation = 676;
		}
		break;
	default:
		*animation = 399;
		break;
	}
	*frame = _animationFrame;
	return true;
}

bool AIScriptHowieLee::ChangeAnimationMode(int mode) {
	switch (mode) {
	case kAnimationModeIdle:
		if (_animationState < 3 || _animationState > 8) {
			_animationState = 0;
			_animationFrame = 0;
			var_45DFB8 = Random_Query(0, 1);
		} else {
			Game_Flag_Set(kFlagHowieLeeAnimation1);
		}
		break;
	case kAnimationModeWalk:
		if (_animationState != 2) {
			_animationState = 2;
			_animationFrame = 0;
		}
		break;
	case kAnimationModeTalk:
		_animationState = 3;
		_animationFrame = 0;
		break;
	case 12:
		_animationState = 4;
		_animationFrame = 0;
		break;
	case 13:
		_animationState = 5;
		_animationFrame = 0;
		break;
	case 14:
		_animationState = 6;
		_animationFrame = 0;
		break;
	case 15:
		_animationState = 7;
		_animationFrame = 0;
		break;
	case 16:
		_animationState = 8;
		_animationFrame = 0;
		break;
	case 43:
		_animationState = 1;
		_animationFrame = 0;
		break;
	}
	return true;
}

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

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

bool AIScriptHowieLee::ReachedMovementTrackWaypoint(int waypointId) {
	if (waypointId == 67 && Random_Query(1, 2) == 2) {
		Actor_Face_Heading(kActorHowieLee, 850, 0);
		_animationFrame = 0;
		_animationState = 1;
	}
	return true;
}

void AIScriptHowieLee::FledCombat() {
	// return false;
}

} // End of namespace BladeRunner