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 "bladerunner/script/ai_script.h"
24 
25 namespace BladeRunner {
26 
AIScriptGeneralDoll(BladeRunnerEngine * vm)27 AIScriptGeneralDoll::AIScriptGeneralDoll(BladeRunnerEngine *vm) : AIScriptBase(vm) {
28 	_resumeIdleAfterFramesetCompletesFlag = false;
29 }
30 
Initialize()31 void AIScriptGeneralDoll::Initialize() {
32 	_animationFrame = 0;
33 	_animationState = 0;
34 	_animationStateNext = 0;
35 	_animationNext = 0;
36 
37 	_resumeIdleAfterFramesetCompletesFlag = false;
38 
39 	Actor_Put_In_Set(kActorGeneralDoll, kSetFreeSlotG);
40 	Actor_Set_At_Waypoint(kActorGeneralDoll, 39, 0);
41 
42 	Actor_Set_Goal_Number(kActorGeneralDoll, 100);
43 }
44 
Update()45 bool AIScriptGeneralDoll::Update() {
46 	if (Global_Variable_Query(kVariableChapter) == 2
47 	 && Actor_Query_Goal_Number(kActorGeneralDoll) <= 101
48 	 && Player_Query_Current_Scene() == kSceneBB05
49 	) {
50 		Actor_Set_Goal_Number(kActorGeneralDoll, 101);
51 		return true;
52 	}
53 
54 	if (Global_Variable_Query(kVariableChapter) == 3
55 	 && Actor_Query_Goal_Number(kActorGeneralDoll) < 200
56 	) {
57 		return true;
58 	}
59 
60 	return false;
61 }
62 
TimerExpired(int timer)63 void AIScriptGeneralDoll::TimerExpired(int timer) {
64 	if (timer == kActorTimerAIScriptCustomTask2) {
65 		Actor_Change_Animation_Mode(kActorMcCoy, kAnimationModeDie);
66 		Actor_Change_Animation_Mode(kActorGeneralDoll, kAnimationModeDie);
67 		AI_Countdown_Timer_Reset(kActorGeneralDoll, kActorTimerAIScriptCustomTask2);
68 		return; //true;
69 	}
70 	return; //false;
71 }
72 
CompletedMovementTrack()73 void AIScriptGeneralDoll::CompletedMovementTrack() {
74 	switch (Actor_Query_Goal_Number(kActorGeneralDoll)) {
75 	case 101:
76 		if (Player_Query_Current_Scene() == kSceneBB05) {
77 			switch (Random_Query(0, 5)) {
78 			case 0:
79 				Ambient_Sounds_Play_Speech_Sound(kActorGeneralDoll, 0, 80, 0, 0, 0);
80 				break;
81 
82 			case 1:
83 				Ambient_Sounds_Play_Speech_Sound(kActorGeneralDoll, 10, 80, 0, 0, 0);
84 				break;
85 
86 			case 2:
87 				Ambient_Sounds_Play_Speech_Sound(kActorGeneralDoll, 20, 80, 0, 0, 0);
88 				break;
89 
90 			case 3:
91 				Ambient_Sounds_Play_Speech_Sound(kActorGeneralDoll, 30, 80, 0, 0, 0);
92 				break;
93 
94 			case 4:
95 				Ambient_Sounds_Play_Speech_Sound(kActorGeneralDoll, 40, 80, 0, 0, 0);
96 				break;
97 
98 			case 5:
99 				Ambient_Sounds_Play_Speech_Sound(kActorGeneralDoll, 50, 80, 0, 0, 0);
100 				break;
101 			}
102 			Actor_Set_Goal_Number(kActorGeneralDoll, 102);
103 		} else {
104 			Actor_Set_Goal_Number(kActorGeneralDoll, 103);
105 		}
106 		return; //true;
107 
108 	case 102:
109 		Actor_Set_Goal_Number(kActorGeneralDoll, 103);
110 		return; //true;
111 
112 	case 103:
113 		Actor_Set_Goal_Number(kActorGeneralDoll, 101);
114 		return; //true;
115 
116 	case 200:
117 		Actor_Set_Goal_Number(kActorGeneralDoll, 201);
118 		return; //true;
119 
120 	case 201:
121 		Actor_Set_Goal_Number(kActorGeneralDoll, 200);
122 		return; //true;
123 	}
124 
125 	return; //false
126 }
127 
ReceivedClue(int clueId,int fromActorId)128 void AIScriptGeneralDoll::ReceivedClue(int clueId, int fromActorId) {
129 	//return false;
130 }
131 
ClickedByPlayer()132 void AIScriptGeneralDoll::ClickedByPlayer() {
133 	Actor_Face_Actor(kActorMcCoy, kActorGeneralDoll, true);
134 	Actor_Voice_Over(30, kActorVoiceOver);
135 	Actor_Voice_Over(40, kActorVoiceOver);
136 }
137 
EnteredSet(int setId)138 void AIScriptGeneralDoll::EnteredSet(int setId) {
139 	// return false;
140 }
141 
OtherAgentEnteredThisSet(int otherActorId)142 void AIScriptGeneralDoll::OtherAgentEnteredThisSet(int otherActorId) {
143 	// return false;
144 }
145 
OtherAgentExitedThisSet(int otherActorId)146 void AIScriptGeneralDoll::OtherAgentExitedThisSet(int otherActorId) {
147 	// return false;
148 }
149 
OtherAgentEnteredCombatMode(int otherActorId,int combatMode)150 void AIScriptGeneralDoll::OtherAgentEnteredCombatMode(int otherActorId, int combatMode) {
151 	// return false;
152 }
153 
ShotAtAndMissed()154 void AIScriptGeneralDoll::ShotAtAndMissed() {
155 	// return false;
156 }
157 
ShotAtAndHit()158 bool AIScriptGeneralDoll::ShotAtAndHit() {
159 	AI_Movement_Track_Flush(kActorGeneralDoll);
160 	Global_Variable_Increment(kVariableGeneralDollShot, 1);
161 	if (!Game_Flag_Query(kFlagGeneralDollShot)
162 	 &&  Global_Variable_Query(kVariableGeneralDollShot) == 1
163 	) {
164 		Sound_Play(kSfxSERVOD1, 100, 0, 0, 50);
165 		Game_Flag_Set(kFlagGeneralDollShot);
166 		Actor_Set_Goal_Number(kActorGeneralDoll, 104);
167 		ChangeAnimationMode(kAnimationModeDie);
168 		Actor_Set_Targetable(kActorGeneralDoll, false);
169 	}
170 
171 	return false;
172 }
173 
Retired(int byActorId)174 void AIScriptGeneralDoll::Retired(int byActorId) {
175 	// return false;
176 }
177 
GetFriendlinessModifierIfGetsClue(int otherActorId,int clueId)178 int AIScriptGeneralDoll::GetFriendlinessModifierIfGetsClue(int otherActorId, int clueId) {
179 	return 0;
180 }
181 
GoalChanged(int currentGoalNumber,int newGoalNumber)182 bool AIScriptGeneralDoll::GoalChanged(int currentGoalNumber, int newGoalNumber) {
183 	switch (newGoalNumber) {
184 	case 100:
185 		AI_Movement_Track_Flush(kActorGeneralDoll);
186 		AI_Movement_Track_Append(kActorGeneralDoll, 39, 0);
187 		AI_Movement_Track_Repeat(kActorGeneralDoll);
188 		break;
189 
190 	case 101:
191 		AI_Movement_Track_Flush(kActorGeneralDoll);
192 		AI_Movement_Track_Append(kActorGeneralDoll, 196, 0);
193 		AI_Movement_Track_Repeat(kActorGeneralDoll);
194 		break;
195 
196 	case 102:
197 		AI_Movement_Track_Flush(kActorGeneralDoll);
198 		AI_Movement_Track_Append(kActorGeneralDoll, 197, 0);
199 		AI_Movement_Track_Repeat(kActorGeneralDoll);
200 		break;
201 
202 	case 103:
203 		AI_Movement_Track_Flush(kActorGeneralDoll);
204 		if (Random_Query(1, 2) == 1) {
205 			AI_Movement_Track_Append(kActorGeneralDoll, 198, 0);
206 			AI_Movement_Track_Append(kActorGeneralDoll, 329, 0);
207 			AI_Movement_Track_Append(kActorGeneralDoll, 328, 0);
208 			AI_Movement_Track_Append(kActorGeneralDoll, 330, 0);
209 			AI_Movement_Track_Append(kActorGeneralDoll, 331, 0);
210 			AI_Movement_Track_Append(kActorGeneralDoll, 335, 0);
211 			AI_Movement_Track_Append(kActorGeneralDoll, 139, 0);
212 			AI_Movement_Track_Append(kActorGeneralDoll, 138, 0);
213 			AI_Movement_Track_Append(kActorGeneralDoll, 137, 0);
214 			AI_Movement_Track_Append(kActorGeneralDoll, 136, 0);
215 			AI_Movement_Track_Append(kActorGeneralDoll, 135, 0);
216 			AI_Movement_Track_Append(kActorGeneralDoll, 134, 0);
217 			AI_Movement_Track_Append(kActorGeneralDoll, 326, 0);
218 			AI_Movement_Track_Append(kActorGeneralDoll, 327, 0);
219 		} else {
220 			AI_Movement_Track_Append(kActorGeneralDoll, 136, 0);
221 			AI_Movement_Track_Append(kActorGeneralDoll, 137, 0);
222 			AI_Movement_Track_Append(kActorGeneralDoll, 138, 0);
223 			AI_Movement_Track_Append(kActorGeneralDoll, 139, 0);
224 			AI_Movement_Track_Append(kActorGeneralDoll, 335, 0);
225 			AI_Movement_Track_Append(kActorGeneralDoll, 331, 0);
226 			AI_Movement_Track_Append(kActorGeneralDoll, 327, 0);
227 			AI_Movement_Track_Append(kActorGeneralDoll, 326, 0);
228 		}
229 		AI_Movement_Track_Repeat(kActorGeneralDoll);
230 		break;
231 
232 	case 104:
233 		AI_Movement_Track_Flush(kActorGeneralDoll);
234 		break;
235 
236 	case 106:
237 		AI_Movement_Track_Flush(kActorGeneralDoll);
238 		AI_Movement_Track_Append(kActorGeneralDoll, 196, 0);
239 		AI_Movement_Track_Append(kActorGeneralDoll, 197, 0);
240 		AI_Movement_Track_Repeat(kActorGeneralDoll);
241 		break;
242 
243 	case 200:
244 		AI_Movement_Track_Flush(kActorGeneralDoll);
245 		Actor_Put_In_Set(kActorGeneralDoll, kSetBB05);
246 		Actor_Set_At_Waypoint(kActorGeneralDoll, 134, 0);
247 		Actor_Set_Goal_Number(kActorGeneralDoll, 201);
248 		break;
249 
250 	case 201:
251 		AI_Movement_Track_Flush(kActorGeneralDoll);
252 		if (Random_Query(1, 2) == 1) {
253 			AI_Movement_Track_Append(kActorGeneralDoll, 198, 0);
254 			AI_Movement_Track_Append(kActorGeneralDoll, 329, 0);
255 			AI_Movement_Track_Append(kActorGeneralDoll, 328, 0);
256 			AI_Movement_Track_Append(kActorGeneralDoll, 330, 0);
257 			AI_Movement_Track_Append(kActorGeneralDoll, 331, 0);
258 			AI_Movement_Track_Append(kActorGeneralDoll, 335, 0);
259 			AI_Movement_Track_Append(kActorGeneralDoll, 139, 0);
260 			AI_Movement_Track_Append(kActorGeneralDoll, 138, 0);
261 			AI_Movement_Track_Append(kActorGeneralDoll, 137, 0);
262 			AI_Movement_Track_Append(kActorGeneralDoll, 136, 0);
263 			AI_Movement_Track_Append(kActorGeneralDoll, 135, 0);
264 			AI_Movement_Track_Append(kActorGeneralDoll, 134, 0);
265 			AI_Movement_Track_Append(kActorGeneralDoll, 326, 0);
266 			AI_Movement_Track_Append(kActorGeneralDoll, 327, 0);
267 		} else {
268 			AI_Movement_Track_Append(kActorGeneralDoll, 136, 0);
269 			AI_Movement_Track_Append(kActorGeneralDoll, 137, 0);
270 			AI_Movement_Track_Append(kActorGeneralDoll, 138, 0);
271 			AI_Movement_Track_Append(kActorGeneralDoll, 139, 0);
272 			AI_Movement_Track_Append(kActorGeneralDoll, 335, 0);
273 			AI_Movement_Track_Append(kActorGeneralDoll, 331, 0);
274 			AI_Movement_Track_Append(kActorGeneralDoll, 327, 0);
275 			AI_Movement_Track_Append(kActorGeneralDoll, 326, 0);
276 		}
277 		AI_Movement_Track_Repeat(kActorGeneralDoll);
278 		break;
279 
280 	case 299:
281 		AI_Movement_Track_Flush(kActorGeneralDoll);
282 		break;
283 
284 	default:
285 		return false;
286 	}
287 
288 	return true;
289 }
290 
UpdateAnimation(int * animation,int * frame)291 bool AIScriptGeneralDoll::UpdateAnimation(int *animation, int *frame) {
292 	switch (_animationState) {
293 	case 0:
294 		*animation = kModelGeneralDollIdle;
295 		++_animationFrame;
296 		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelGeneralDollIdle)) {
297 			_animationFrame = 0;
298 		}
299 		break;
300 
301 	case 1:
302 		*animation = kModelGeneralDollHaltSalute;
303 		if (_animationFrame == 0 && _resumeIdleAfterFramesetCompletesFlag) {
304 			*animation = kModelGeneralDollIdle;
305 			_animationFrame = 0;
306 			_animationState = 0;
307 		} else {
308 			++_animationFrame;
309 			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelGeneralDollHaltSalute)) {
310 				_animationFrame = 0;
311 			}
312 		}
313 		break;
314 
315 	case 2:
316 		*animation = kModelGeneralDollWalking;
317 		++_animationFrame;
318 		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelGeneralDollWalking)) {
319 			_animationFrame = 0;
320 		}
321 		break;
322 
323 	case 3:
324 		*animation = kModelGeneralDollGotHit;
325 		++_animationFrame;
326 		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelGeneralDollGotHit)) {
327 			*animation = kModelGeneralDollIdle;
328 			_animationFrame = 0;
329 			_animationState = 0;
330 		}
331 		break;
332 
333 	case 4:
334 		*animation = kModelGeneralDollShotDead;
335 		if (_animationFrame < Slice_Animation_Query_Number_Of_Frames(kModelGeneralDollShotDead) - 1) {
336 			++_animationFrame;
337 		}
338 		break;
339 
340 	default:
341 		break;
342 	}
343 	*frame = _animationFrame;
344 
345 	return true;
346 }
347 
ChangeAnimationMode(int mode)348 bool AIScriptGeneralDoll::ChangeAnimationMode(int mode) {
349 	switch (mode) {
350 	case 0:
351 		if (_animationState == 1) {
352 			_resumeIdleAfterFramesetCompletesFlag = true;
353 		} else {
354 			_animationState = 0;
355 			_animationFrame = 0;
356 		}
357 		break;
358 
359 	case 1:
360 		_animationState = 2;
361 		_animationFrame = 0;
362 		break;
363 
364 	case 3:
365 		_animationState = 1;
366 		_animationFrame = 0;
367 		_resumeIdleAfterFramesetCompletesFlag = false;
368 		break;
369 
370 	case 43:
371 		_animationState = 3;
372 		_animationFrame = 0;
373 		break;
374 
375 	case kAnimationModeDie:
376 		_animationState = 4;
377 		_animationFrame = 0;
378 		break;
379 	}
380 
381 	return true;
382 }
383 
QueryAnimationState(int * animationState,int * animationFrame,int * animationStateNext,int * animationNext)384 void AIScriptGeneralDoll::QueryAnimationState(int *animationState, int *animationFrame, int *animationStateNext, int *animationNext) {
385 	*animationState     = _animationState;
386 	*animationFrame     = _animationFrame;
387 	*animationStateNext = _animationStateNext;
388 	*animationNext      = _animationNext;
389 }
390 
SetAnimationState(int animationState,int animationFrame,int animationStateNext,int animationNext)391 void AIScriptGeneralDoll::SetAnimationState(int animationState, int animationFrame, int animationStateNext, int animationNext) {
392 	_animationState     = animationState;
393 	_animationFrame     = animationFrame;
394 	_animationStateNext = animationStateNext;
395 	_animationNext      = animationNext;
396 }
397 
ReachedMovementTrackWaypoint(int waypointId)398 bool AIScriptGeneralDoll::ReachedMovementTrackWaypoint(int waypointId) {
399 	return true;
400 }
401 
FledCombat()402 void AIScriptGeneralDoll::FledCombat() {
403 	// return false;
404 }
405 
406 } // End of namespace BladeRunner
407