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