aboutsummaryrefslogtreecommitdiff
path: root/engines/bladerunner/script/ai/generic_walker_c.cpp
blob: f317d5ad49b1c4400e8014e366f24a80dc2b007f (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
/* 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 {
enum kGenericWalkerCStates {
	kGenericWalkerCStatesIdle = 0,
	kGenericWalkerCStatesWalk = 1,
	kGenericWalkerCStatesDie  = 2,
	kGenericWalkerCStatesGun  = 3
};

AIScriptGenericWalkerC::AIScriptGenericWalkerC(BladeRunnerEngine *vm) : AIScriptBase(vm) {
	isInside = false;
	deltaX = 0.0f;
	deltaZ = 0.0f;
}

void AIScriptGenericWalkerC::Initialize() {
	_animationState = kGenericWalkerCStatesIdle;
	_animationFrame = 0;
	_animationStateNext = 0;
	isInside = false;
	deltaX = 0.0f;
	deltaZ = 0.0f;
	Actor_Set_Goal_Number(kActorGenwalkerC, 0);
}

bool AIScriptGenericWalkerC::Update() {
	switch (Actor_Query_Goal_Number(kActorGenwalkerC)) {
		case 0:
			if (prepareWalker()) {
				return true;
			}
			break;
		case 1:
			if (deltaX != 0.0f || deltaZ != 0.0f) {
				movingUpdate();
			}
			break;
	}
	return false;
}

void AIScriptGenericWalkerC::TimerExpired(int timer) {
	if (timer == 2) {
		AI_Countdown_Timer_Reset(kActorGenwalkerC, 2);
		Game_Flag_Reset(kFlagGenericWalkerWaiting);
		return;// true;
	}
	//return false;
}

void AIScriptGenericWalkerC::CompletedMovementTrack() {
	if (Actor_Query_Goal_Number(kActorGenwalkerC) > 0) {
		Actor_Set_Goal_Number(kActorGenwalkerC, 0);
		if (!Game_Flag_Query(kFlagGenericWalkerWaiting)) {
			Game_Flag_Set(kFlagGenericWalkerWaiting);
			AI_Countdown_Timer_Reset(kActorGenwalkerC, 2);
			AI_Countdown_Timer_Start(kActorGenwalkerC, 2, Random_Query(6, 10));
		}
		// return true;
	}
	// return false;
}

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

void AIScriptGenericWalkerC::ClickedByPlayer() {
	Actor_Face_Actor(kActorMcCoy, kActorGenwalkerC, true);
	switch (Random_Query(1, 10)) {
	case 1:
		Actor_Says(kActorMcCoy, 365, 3);
		break;
	case 2:
		Actor_Says(kActorMcCoy, 755, 3);
		break;
	case 3:
		Actor_Says(kActorMcCoy, 940, 3);
		break;
	case 4:
		Actor_Says(kActorMcCoy, 4560, 3);
		break;
	case 5:
		Actor_Says(kActorMcCoy, 4870, 3);
		break;
	case 6:
		Actor_Says(kActorMcCoy, 5125, 3);
		break;
	case 7:
		Actor_Says(kActorMcCoy, 8450, 3);
		break;
	case 8:
		Actor_Says(kActorMcCoy, 1085, 3);
		break;
	case 9:
		Actor_Says(kActorMcCoy, 365, 3);
		break;
	case 10:
		Actor_Says(kActorMcCoy, 7415, 3);
		break;
	}
	//return false;
}

void AIScriptGenericWalkerC::EnteredScene(int sceneId) {
	//return false;
}

void AIScriptGenericWalkerC::OtherAgentEnteredThisScene(int otherActorId) {
	//return false;
}

void AIScriptGenericWalkerC::OtherAgentExitedThisScene(int otherActorId) {
	if (Actor_Query_Goal_Number(kActorGenwalkerC) && otherActorId == kActorMcCoy) {
		Actor_Set_Goal_Number(kActorGenwalkerC, 0);
	}
	//return false;
}

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

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

bool AIScriptGenericWalkerC::ShotAtAndHit() {
	if (Actor_Query_Goal_Number(kActorGenwalkerC)) {
		AI_Movement_Track_Flush(kActorGenwalkerC);
		_animationState = kGenericWalkerCStatesDie;
		_animationFrame = 0;
		Sound_Play(203, 100, 0, 0, 50);
		movingStart();
		return true;
	}
	return false;
}

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

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

bool AIScriptGenericWalkerC::GoalChanged(int currentGoalNumber, int newGoalNumber) {
	if (newGoalNumber == 0) {
		AI_Movement_Track_Flush(kActorGenwalkerC);
		Actor_Put_In_Set(kActorGenwalkerC, kSetFreeSlotH);
		Global_Variable_Set(kVariableGenericWalkerCModel, -1);
		return false;
	} else if (newGoalNumber == 1) {
		return true;
	}
	return false;
}

bool AIScriptGenericWalkerC::UpdateAnimation(int *animation, int *frame) {
	switch (_animationState) {
	case kGenericWalkerCStatesIdle:
		switch (Global_Variable_Query(kVariableGenericWalkerCModel)) {
		case 0:
			*animation = 426;
			break;
		case 1:
			*animation = 430;
			break;
		case 2:
			*animation = 437;
			break;
		case 3:
			*animation = 431;
			break;
		case 4:
			*animation = 427;
			break;
		case 5:
			*animation = 433;
			break;
		}
		_animationFrame = 0;
		break;
	case kGenericWalkerCStatesWalk:
		switch (Global_Variable_Query(kVariableGenericWalkerCModel)){
		case 0:
			*animation = 424;
			break;
		case 1:
			*animation = 428;
			break;
		case 2:
			*animation = 436;
			break;
		case 3:
			*animation = 429;
			break;
		case 4:
			*animation = 425;
			break;
		case 5:
			*animation = 432;
			break;
		}
		++_animationFrame;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
			_animationFrame = 0;
		}
		break;
	case kGenericWalkerCStatesDie:
		*animation = 874;
		++_animationFrame;
		if (++_animationFrame >= Slice_Animation_Query_Number_Of_Frames(874))
		{
			_animationFrame = 0;
			Actor_Set_Goal_Number(kActorGenwalkerC, 0);
			_animationState = kGenericWalkerCStatesIdle;
			deltaX = 0.0f;
			deltaZ = 0.0f;
		}
		break;
	}
	*frame = _animationFrame;
	return true;
}

bool AIScriptGenericWalkerC::ChangeAnimationMode(int mode) {
	switch (mode) {
	case kAnimationModeIdle:
		_animationState = kGenericWalkerCStatesIdle;
		_animationFrame = 0;
		break;
	case kAnimationModeWalk:
		_animationState = kGenericWalkerCStatesWalk;
		_animationFrame = 0;
		break;
	}
	return true;
}

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

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

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

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

void AIScriptGenericWalkerC::movingStart() {
	float mccoyX, mccoyY, mccoyZ;
	float walkerX, walkerY, walkerZ;

	Actor_Query_XYZ(kActorMcCoy, &mccoyX, &mccoyY, &mccoyZ);
	Actor_Query_XYZ(kActorGenwalkerC, &walkerX, &walkerY, &walkerZ);

	deltaX = walkerX - mccoyX;
	deltaZ = walkerZ - mccoyZ;

	float dist = sqrt(deltaX * deltaX + deltaZ * deltaZ);
	if (dist == 0.0f) {
		deltaZ = 0.0f;
		deltaX = 0.0f;
	} else {
		deltaX *= 10.0f / dist;
		deltaZ *= 10.0f / dist;
	}
}

void AIScriptGenericWalkerC::movingUpdate() {
	float walkerX, walkerY, walkerZ;

	Actor_Query_XYZ(kActorGenwalkerC, &walkerX, &walkerY, &walkerZ);
	int facing = Actor_Query_Facing_1024(kActorGenwalkerC);

	walkerX += deltaX;
	walkerZ += deltaZ;

	deltaX = deltaX * 0.97f;
	deltaZ = deltaZ * 0.97f;

	Actor_Set_At_XYZ(kActorGenwalkerC, walkerX, walkerY, walkerZ, facing);
}

bool AIScriptGenericWalkerC::prepareWalker() {
	if (Game_Flag_Query(kFlagGenericWalkerWaiting) || Global_Variable_Query(35) < 2 || !preparePath()) {
		return false;
	}

	int model = 0;
	do {
		if (isInside) {
			model = Random_Query(3, 5);
		} else {
			model = Random_Query(0, 5);
		}
	}
	// Here is probably bug in original code, because it not using kVariableGenericWalkerBModel but kVariableGenericWalkerCModel
	while (model == Global_Variable_Query(kVariableGenericWalkerAModel) || model == Global_Variable_Query(kVariableGenericWalkerBModel));


	Global_Variable_Set(kVariableGenericWalkerCModel, model);
	Game_Flag_Set(kFlagGenericWalkerWaiting);
	AI_Countdown_Timer_Reset(kActorGenwalkerC, 2);
	AI_Countdown_Timer_Start(kActorGenwalkerC, 2, Random_Query(4, 12));
	Actor_Set_Goal_Number(kActorGenwalkerC, 1);
	return true;
}

bool AIScriptGenericWalkerC::preparePath() {
	AI_Movement_Track_Flush(kActorGenwalkerC);
	int set = Player_Query_Current_Set();

	if (set == kSetAR01_AR02) {
		isInside = false;
		int waypointStart = Random_Query(155, 158);
		int waypointEnd = 0;
		AI_Movement_Track_Append(kActorGenwalkerC, waypointStart, 0);
		do {
			waypointEnd = Random_Query(155, 158);
		} while (waypointEnd == waypointStart);
		if ((waypointStart == 155 || waypointStart == 156) && (waypointEnd == 157 || waypointEnd == 158)) {
			AI_Movement_Track_Append(kActorGenwalkerC, 159, 0);
			AI_Movement_Track_Append(kActorGenwalkerC, 160, 0);
			if (Random_Query(0, 3) == 0) {
				AI_Movement_Track_Append_With_Facing(kActorGenwalkerC, 161, Random_Query(15, 30), 904);
			}
		} else if ((waypointEnd == 155 || waypointEnd == 156) && (waypointStart == 157 || waypointStart == 158)) {
			if (Random_Query(0, 3) == 0) {
				AI_Movement_Track_Append_With_Facing(kActorGenwalkerC, 161, Random_Query(15, 30), 904);
			}
			AI_Movement_Track_Append(kActorGenwalkerC, 160, 0);
			AI_Movement_Track_Append(kActorGenwalkerC, 159, 0);
		} else if ((waypointStart == 155 && waypointEnd == 156) || (waypointStart == 156 && waypointEnd == 155)) {
			AI_Movement_Track_Append(kActorGenwalkerC, 159, 0);
		}
		AI_Movement_Track_Append(kActorGenwalkerC, waypointEnd, 0);
		AI_Movement_Track_Repeat(kActorGenwalkerC);
		return true;
	}

	if (set == kSetCT01_CT12) {
		isInside = false;
		if (Random_Query(0, 1)) {
			AI_Movement_Track_Append(kActorGenwalkerC, 54, 1);
			if (Random_Query(1, 3) == 1) {
				AI_Movement_Track_Append(kActorGenwalkerC, 56, 0);
				AI_Movement_Track_Append(kActorGenwalkerC, 43, 1);
			} else {
				AI_Movement_Track_Append(kActorGenwalkerC, 53, 1);
			}
			AI_Movement_Track_Append(kActorGenwalkerC, 40, 1);
			AI_Movement_Track_Repeat(kActorGenwalkerC);
		} else {
			AI_Movement_Track_Append(kActorGenwalkerC, 53, 1);
			if (Random_Query(1, 3) == 1) {
				AI_Movement_Track_Append(kActorGenwalkerC, 43, 1);
			} else {
				AI_Movement_Track_Append(kActorGenwalkerC, 54, 1);
			}
			AI_Movement_Track_Append(kActorGenwalkerC, 40, 1);
			AI_Movement_Track_Repeat(kActorGenwalkerC);
		}
		return true;
	}

	if (set == kSetHC01_HC02_HC03_HC04) {
		isInside = true;
		if (Random_Query(0, 1)) {
			AI_Movement_Track_Append(kActorGenwalkerC, 164, 0);
			if (Random_Query(0, 1)) {
				AI_Movement_Track_Append(kActorGenwalkerC, 163, 0);
				AI_Movement_Track_Append(kActorGenwalkerC, 162, 0);
			} else if (Random_Query(0, 1)) {
				AI_Movement_Track_Append(kActorGenwalkerC, 163, 0);
				AI_Movement_Track_Append(kActorGenwalkerC, 162, 0);
			} else {
				AI_Movement_Track_Append(kActorGenwalkerC, 163, 0);
				AI_Movement_Track_Append(kActorGenwalkerC, 162, 0);
			}
		} else {
			AI_Movement_Track_Append(kActorGenwalkerC, 162, 0);
			if (Random_Query(0, 1)) {
				AI_Movement_Track_Append(kActorGenwalkerC, 163, 0);
				AI_Movement_Track_Append(kActorGenwalkerC, 164, 0);
			} else {
				if (Random_Query(0, 1)) {
					AI_Movement_Track_Append_With_Facing(kActorGenwalkerC, 166, 0, 30);
				}
				AI_Movement_Track_Append(kActorGenwalkerC, 163, 0);
				AI_Movement_Track_Append(kActorGenwalkerC, 164, 0);
			}
		}
		AI_Movement_Track_Repeat(kActorGenwalkerC);
		return true;
	}

	if (set == kSetRC03) {
		isInside = false;
		int waypointStart = 0;
		int waypointEnd = 0;
		do {
			waypointStart = Random_Query(167, 171);
		} while (waypointEnd == 168 || waypointEnd == 169);
		do {
			waypointEnd = Random_Query(167, 171);
		} while (waypointEnd == waypointStart || waypointEnd == 168 || waypointEnd == 169);
		AI_Movement_Track_Append(kActorGenwalkerC, waypointStart, 0);
		if (waypointStart == 170) {
			AI_Movement_Track_Append(kActorGenwalkerC, 169, 0);
			AI_Movement_Track_Append(kActorGenwalkerC, 168, 0);
		} else if (waypointEnd == 170) {
			AI_Movement_Track_Append(kActorGenwalkerC, 168, 0);
			AI_Movement_Track_Append(kActorGenwalkerC, 169, 0);
		}
		AI_Movement_Track_Append(kActorGenwalkerC, waypointEnd, 0);
		AI_Movement_Track_Repeat(kActorGenwalkerC);
		return true;
	}

	return false;
}

} // End of namespace BladeRunner