File: insect_dealer.cpp

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (367 lines) | stat: -rw-r--r-- 10,101 bytes parent folder | download | duplicates (2)
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
/* 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 */

#include "bladerunner/script/ai_script.h"

namespace BladeRunner {

AIScriptInsectDealer::AIScriptInsectDealer(BladeRunnerEngine *vm) : AIScriptBase(vm) {
	_resumeIdleAfterFramesetCompletesFlag = false;
	_state = 0;
	_frameDelta = 0;
	_var2 = 0; // is set on some occasions but is never checked. Unused.
	_counter = 0;
}

void AIScriptInsectDealer::Initialize() {
	_animationFrame = 0;
	_animationState = 0;
	_animationStateNext = 0;
	_animationNext = 0;

	_resumeIdleAfterFramesetCompletesFlag = false;
	_state = 0;
	_frameDelta = 1;
	_var2 = 6;
	_counter = 0;

	Actor_Put_In_Set(kActorInsectDealer, kSetAR01_AR02);
	Actor_Set_At_XYZ(kActorInsectDealer, -414.0f, 0.0f, -1199.0f, 371);
	Actor_Set_Goal_Number(kActorInsectDealer, 0);
}

bool AIScriptInsectDealer::Update() {
	if (Global_Variable_Query(kVariableChapter) == 5
	 && Actor_Query_Goal_Number(kActorInsectDealer) < 400
	)
		Actor_Set_Goal_Number(kActorInsectDealer, 400);

	return false;
}

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

void AIScriptInsectDealer::CompletedMovementTrack() {
	//return false;
}

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

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

void AIScriptInsectDealer::EnteredSet(int setId) {
	// return false;
}

void AIScriptInsectDealer::OtherAgentEnteredThisSet(int otherActorId) {
	// return false;
}

void AIScriptInsectDealer::OtherAgentExitedThisSet(int otherActorId) {
	// return false;
}

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

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

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

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

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

bool AIScriptInsectDealer::GoalChanged(int currentGoalNumber, int newGoalNumber) {
	if (newGoalNumber == 400) {
		Actor_Put_In_Set(kActorInsectDealer, kSetFreeSlotH);
		Actor_Set_At_Waypoint(kActorInsectDealer, 40, 0);

		if (!Game_Flag_Query(kFlagAR02DektoraBoughtScorpions)) {
			// TODO A bug? Does it not matter if Dektora is retired at this point?
			// Probably a safe inconsistency to allow (setting the flag), since in Act 5 (when Insect Dealer's goal becomes 400)
			// it no longer matters if Dektora purchased the scorpions or not.
			// But it still may confuse debugging and tracing of what actually happened looking at a save game.
			Game_Flag_Set(kFlagAR02DektoraBoughtScorpions);
#if BLADERUNNER_ORIGINAL_BUGS
			Item_Remove_From_World(kItemScorpions);
#else
			if (Game_Flag_Query(kFlagScorpionsInAR02)) {
				Game_Flag_Reset(kFlagScorpionsInAR02);
				Item_Remove_From_World(kItemScorpions);
			}
#endif
		}
	}

	return false;
}

bool AIScriptInsectDealer::UpdateAnimation(int *animation, int *frame) {
	switch (_animationState) {
	case 0:
		switch (_state) {
		case 0:
			*animation = kModelAnimationInsectDealerSittingIdle;
			if (_counter > 0) {
				--_counter;
				if (Random_Query(0, 6) == 0) {
					_frameDelta = -_frameDelta;
				}
			} else {
				_animationFrame += _frameDelta;
				if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(*animation)) {
					_animationFrame = 0;
					if (Random_Query(0, 2) == 0) {
						_state = 2 * Random_Query(0, 1);
					}
				}
				if (_animationFrame < 0) {
					_animationFrame = Slice_Animation_Query_Number_Of_Frames(*animation) - 1;
				}

				_counter = Random_Query(0, 1);
				if (_animationFrame == 0) {
					_state = Random_Query(0, 1);
				}
			}
			break;

		case 1:
			*animation = kModelAnimationInsectDealerSittingScratchEarIdle;
			++_animationFrame;

			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelAnimationInsectDealerSittingScratchEarIdle)) {
				*animation = kModelAnimationInsectDealerSittingIdle;
				_animationFrame = 0;
				_state = 0;
				_var2 = Random_Query(6, 14);
				_frameDelta = 2 * Random_Query(0, 1) - 1;
			}
			break;

		case 2:
			// TODO: test... actor will be stuck
			break;
		}
		break;

	case 1:
		if (_animationFrame == 0 && _resumeIdleAfterFramesetCompletesFlag) {
			*animation = kModelAnimationInsectDealerSittingIdle;
			_animationState = 0;
		} else {
			*animation = kModelAnimationInsectDealerSittingCalmTalk;
			++_animationFrame;
			if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelAnimationInsectDealerSittingCalmTalk)) {
				_animationFrame = 0;
				_animationState = 0;
			}
		}
		break;

	case 2:
		*animation = kModelAnimationInsectDealerSittingExplainTalk;
		++_animationFrame;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelAnimationInsectDealerSittingExplainTalk)) {
			*animation = kModelAnimationInsectDealerSittingCalmTalk;
			_animationFrame = 0;
			_animationState = 1;
		}
		break;

	case 3:
		*animation = kModelAnimationInsectDealerSittingPointingTalk;
		++_animationFrame;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelAnimationInsectDealerSittingPointingTalk)) {
			*animation = kModelAnimationInsectDealerSittingCalmTalk;
			_animationFrame = 0;
			_animationState = 1;
		}
		break;

	case 4:
		*animation = kModelAnimationInsectDealerSittingHeadMoveTalk;
		++_animationFrame;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelAnimationInsectDealerSittingHeadMoveTalk)) {
			*animation = kModelAnimationInsectDealerSittingCalmTalk;
			_animationFrame = 0;
			_animationState = 1;
		}
		break;

	case 5:
		*animation = kModelAnimationInsectDealerSittingSuggestTalk;
		++_animationFrame;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelAnimationInsectDealerSittingSuggestTalk)) {
			*animation = kModelAnimationInsectDealerSittingCalmTalk;
			_animationFrame = 0;
			_animationState = 1;
		}
		break;

	case 6:
		*animation = kModelAnimationInsectDealerSittingGossipTalk;
		++_animationFrame;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelAnimationInsectDealerSittingGossipTalk)) {
			*animation = kModelAnimationInsectDealerSittingCalmTalk;
			_animationFrame = 0;
			_animationState = 1;
		}
		break;

	case 7:
		*animation = kModelAnimationInsectDealerSittingDescriptiveTalk;
		++_animationFrame;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelAnimationInsectDealerSittingDescriptiveTalk)) {
			*animation = kModelAnimationInsectDealerSittingCalmTalk;
			_animationFrame = 0;
			_animationState = 1;
		}
		break;

	case 8:
		*animation = kModelAnimationInsectDealerSittingGestureGive;
		++_animationFrame;
		if (_animationFrame >= Slice_Animation_Query_Number_Of_Frames(kModelAnimationInsectDealerSittingGestureGive)) {
			*animation = kModelAnimationInsectDealerSittingIdle;
			_animationFrame = 0;
			_animationState = 0;
		}
		break;

	default:
		debugC(6, kDebugAnimation, "AIScriptInsectDealer::UpdateAnimation() - Current _animationState (%d) is not supported", _animationState);
		break;
	}

	*frame = _animationFrame;
	return true;
}

bool AIScriptInsectDealer::ChangeAnimationMode(int mode) {
	switch (mode) {
	case 0:
		if (_animationState > 0 && _animationState <= 7) {
			_resumeIdleAfterFramesetCompletesFlag = true;
		} else {
			_animationState = 0;
			_animationFrame = 0;
		}
		break;

	case 3:
		// fall through
	case 18:
		// fall through
	case 19:
		_animationState = 1;
		_animationFrame = 0;
		_resumeIdleAfterFramesetCompletesFlag = false;
		break;

	case 12:
		_animationState = 2;
		_animationFrame = 0;
		_resumeIdleAfterFramesetCompletesFlag = false;
		break;

	case 13:
		_animationState = 3;
		_animationFrame = 0;
		_resumeIdleAfterFramesetCompletesFlag = false;
		break;

	case 14:
		_animationState = 4;
		_animationFrame = 0;
		_resumeIdleAfterFramesetCompletesFlag = false;
		break;

	case 15:
		_animationState = 5;
		_animationFrame = 0;
		_resumeIdleAfterFramesetCompletesFlag = false;
		break;

	case 16:
		_animationState = 6;
		_animationFrame = 0;
		_resumeIdleAfterFramesetCompletesFlag = false;
		break;

	case 17:
		_animationState = 7;
		_animationFrame = 0;
		_resumeIdleAfterFramesetCompletesFlag = false;
		break;

	case 23:
		_animationState = 8;
		_animationFrame = 0;
		break;

	default:
		debugC(6, kDebugAnimation, "AIScriptInsectDealer::ChangeAnimationMode(%d) - Target mode is not supported", mode);
		break;
	}

	return true;
}

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

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

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

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

} // End of namespace BladeRunner