aboutsummaryrefslogtreecommitdiff
path: root/engines/bladerunner/script/ai_script.cpp
blob: c86f673679678381aefb36ca3f62611547e1dffc (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
/* 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"

#include "bladerunner/bladerunner.h"

#include "bladerunner/actor.h"

namespace BladeRunner {

AIScripts::AIScripts(BladeRunnerEngine *vm, int actorCount) {
	_vm = vm;
	_inScriptCounter = 0;
	_actorCount = actorCount;
	_actorUpdating = new bool[actorCount];
	_AIScripts = new AIScriptBase*[actorCount];
	for (int i = 0; i < actorCount; ++i) {
		_AIScripts[i] = nullptr;
		_actorUpdating[i] = false;
	}

	_AIScripts[kActorMcCoy] = new AIScriptMcCoy(_vm);                     //  0
	_AIScripts[kActorSteele] = new AIScriptSteele(_vm);                   //  1
	_AIScripts[kActorGordo] = new AIScriptGordo(_vm);                     //  2
	_AIScripts[kActorGuzza] = new AIScriptGuzza(_vm);                     //  4
	_AIScripts[kActorCrazylegs] = new AIScriptCrazylegs(_vm);             //  9
	_AIScripts[kActorGrigorian] = new AIScriptGrigorian(_vm);             // 11
	_AIScripts[kActorTransient] = new AIScriptTransient(_vm);             // 12
	_AIScripts[kActorLance] = new AIScriptLance(_vm);                     // 13
	_AIScripts[kActorRunciter] = new AIScriptRunciter(_vm);               // 15
	_AIScripts[kActorInsectDealer] = new AIScriptInsectDealer(_vm);       // 16
	_AIScripts[kActorTyrellGuard] = new AIScriptTyrellGuard(_vm);         // 17
	_AIScripts[kActorZuben] = new AIScriptZuben(_vm);                     // 19
	_AIScripts[kActorMarcus] = new AIScriptMarcus(_vm);                   // 21
	_AIScripts[kActorMia] = new AIScriptMia(_vm);                         // 22
	_AIScripts[kActorOfficerLeary] = new AIScriptOfficerLeary(_vm);       // 23
	_AIScripts[kActorBaker] = new AIScriptBaker(_vm);                     // 26
	_AIScripts[kActorDeskClerk] = new AIScriptDeskClerk(_vm);             // 27
	_AIScripts[kActorHowieLee] = new AIScriptHowieLee(_vm);               // 28
	_AIScripts[kActorFishDealer] = new AIScriptFishDealer(_vm);           // 29
	_AIScripts[kActorKlein] = new AIScriptKlein(_vm);                     // 30
	_AIScripts[kActorMurray] = new AIScriptMurray(_vm);                   // 31
	_AIScripts[kActorHawkersBarkeep] = new AIScriptHawkersBarkeep(_vm);   // 32
	_AIScripts[kActorSergeantWalls] = new AIScriptSergeantWalls(_vm);     // 34
	_AIScripts[kActorMoraji] = new AIScriptMoraji(_vm);                   // 35
	_AIScripts[kActorTheBard] = new AIScriptTheBard(_vm);                 // 36
	_AIScripts[kActorDispatcher] = new AIScriptDispatcher(_vm);           // 38
	_AIScripts[kActorAnsweringMachine] = new AIScriptAnsweringMachine(_vm);// 39
	_AIScripts[kActorRajif] = new AIScriptRajif(_vm);                     // 40
	_AIScripts[kActorGovernorKolvig] = new AIScriptGovernorKolvig(_vm);   // 41
	_AIScripts[kActorEarlyQBartender] = new AIScriptEarlyQBartender(_vm); // 42
	_AIScripts[kActorHawkersParrot] = new AIScriptHawkersParrot(_vm);     // 43
	_AIScripts[kActorTaffyPatron] = new AIScriptTaffyPatron(_vm);         // 44
	_AIScripts[kActorLockupGuard] = new AIScriptLockupGuard(_vm);         // 45
	_AIScripts[kActorTeenager] = new AIScriptTeenager(_vm);               // 46
	_AIScripts[kActorHysteriaPatron1] = new AIScriptHysteriaPatron1(_vm); // 47
	_AIScripts[kActorHysteriaPatron2] = new AIScriptHysteriaPatron2(_vm); // 48
	_AIScripts[kActorHysteriaPatron3] = new AIScriptHysteriaPatron3(_vm); // 49
	_AIScripts[kActorShoeshineMan] = new AIScriptShoeshineMan(_vm);       // 50
	_AIScripts[kActorTyrell] = new AIScriptTyrell(_vm);                   // 51
	_AIScripts[kActorChew] = new AIScriptChew(_vm);                       // 52
	_AIScripts[kActorGaff] = new AIScriptGaff(_vm);                       // 53
	_AIScripts[kActorBryant] = new AIScriptBryant(_vm);                   // 54
	_AIScripts[kActorTaffy] = new AIScriptTaffy(_vm);                     // 55
	_AIScripts[kActorSebastian] = new AIScriptSebastian(_vm);             // 56
	_AIScripts[kActorRachael] = new AIScriptRachael(_vm);                 // 57
	_AIScripts[kActorIsabella] = new AIScriptIsabella(_vm);               // 59
	_AIScripts[kActorBlimpGuy] = new AIScriptBlimpGuy(_vm);               // 60
	_AIScripts[kActorNewscaster] = new AIScriptNewscaster(_vm);           // 61
	_AIScripts[kActorLeon] = new AIScriptLeon(_vm);                       // 62
	_AIScripts[kActorMaleAnnouncer] = new AIScriptMaleAnnouncer(_vm);     // 63
	_AIScripts[kActorMaggie] = new AIScriptMaggie(_vm);                   // 66
	_AIScripts[kActorGenwalkerA] = new AIScriptGenericWalkerA(_vm);       // 67
	_AIScripts[kActorGenwalkerB] = new AIScriptGenericWalkerB(_vm);       // 68
	_AIScripts[kActorGenwalkerC] = new AIScriptGenericWalkerC(_vm);       // 69
}

AIScripts::~AIScripts() {
	for (int i = 0; i < _actorCount; ++i) {
		delete _AIScripts[i];
		_AIScripts[i] = nullptr;
	}
	delete[] _AIScripts;
	delete[] _actorUpdating;
}

void AIScripts::initialize(int actor) {
	if (actor >= _actorCount) {
		return;
	}

	if (_AIScripts[actor]) {
		_AIScripts[actor]->Initialize();
	}
}

void AIScripts::update(int actor) {
	if (actor >= _actorCount) {
		return;
	}

	if (!_actorUpdating[actor]) {
		_actorUpdating[actor] = true;
		++_inScriptCounter;
		if (_AIScripts[actor]) {
			_AIScripts[actor]->Update();
		}
		--_inScriptCounter;
		_actorUpdating[actor] = false;
	}
}

void AIScripts::timerExpired(int actor, int timer) {
	if (actor >= _actorCount) {
		return;
	}

	_inScriptCounter++;
	if (_AIScripts[actor]) {
		_AIScripts[actor]->TimerExpired(timer);
	}
	_inScriptCounter--;
}

void AIScripts::completedMovementTrack(int actor) {
	if (actor >= _actorCount) {
		return;
	}

	if (!_vm->_actors[actor]->inCombat()) {
		_inScriptCounter++;
		if (_AIScripts[actor]) {
			_AIScripts[actor]->CompletedMovementTrack();
		}
		_inScriptCounter--;
	}
}

void AIScripts::receivedClue(int actor, int clueId, int fromActorId) {
	if (actor >= _actorCount) {
		return;
	}

	_inScriptCounter++;
	if (_AIScripts[actor]) {
		_AIScripts[actor]->ReceivedClue(clueId, fromActorId);
	}
	_inScriptCounter--;
}

void AIScripts::clickedByPlayer(int actor) {
	if (actor >= _actorCount) {
		return;
	}


	if(_vm->_actors[actor]->inCombat()) {
		return;
	}

	_inScriptCounter++;
	if (_AIScripts[actor]) {
		_AIScripts[actor]->ClickedByPlayer();
	}
	_inScriptCounter--;
}

void AIScripts::enteredScene(int actor, int setId) {
	if (actor >= _actorCount) {
		return;
	}

	_inScriptCounter++;
	if (_AIScripts[actor]) {
		_AIScripts[actor]->EnteredScene(setId);
	}
	_inScriptCounter--;
}

void AIScripts::otherAgentEnteredThisScene(int actor, int otherActorId) {
	if (actor >= _actorCount) {
		return;
	}

	_inScriptCounter++;
	if (_AIScripts[actor]) {
		_AIScripts[actor]->OtherAgentEnteredThisScene(otherActorId);
	}
	_inScriptCounter--;
}

void AIScripts::otherAgentExitedThisScene(int actor, int otherActorId) {
	if (actor >= _actorCount) {
		return;
	}

	_inScriptCounter++;
	if (_AIScripts[actor]) {
		_AIScripts[actor]->OtherAgentExitedThisScene(otherActorId);
	}
	_inScriptCounter--;
}

void AIScripts::otherAgentEnteredCombatMode(int actorId, int otherActorId, int combatMode) {
	assert(actorId < _actorCount);
	_inScriptCounter++;
	if (_AIScripts[actorId]) {
		_AIScripts[actorId]->OtherAgentEnteredCombatMode(otherActorId, combatMode);
	}
	_inScriptCounter--;
}

void AIScripts::shotAtAndMissed(int actorId) {
	assert(actorId < _actorCount);
	_inScriptCounter++;
	if (_AIScripts[actorId]) {
		_AIScripts[actorId]->ShotAtAndMissed();
	}
	_inScriptCounter--;
}

bool AIScripts::shotAtAndHit(int actorId) {
	assert(actorId < _actorCount);
	bool result = true;
	_inScriptCounter++;
	if (_AIScripts[actorId]) {
		result = _AIScripts[actorId]->ShotAtAndHit();
	}
	_inScriptCounter--;
	return result;
}

void AIScripts::retired(int actor, int retiredByActorId) {
	if (actor >= _actorCount) {
		return;
	}

	_inScriptCounter++;
	if (_AIScripts[actor]) {
		_AIScripts[actor]->Retired(retiredByActorId);
	}
	_inScriptCounter--;
}

void AIScripts::goalChanged(int actor, int currentGoalNumber, int newGoalNumber) {
	if (actor >= _actorCount) {
		return;
	}

	_inScriptCounter++;
	if (_AIScripts[actor]) {
		_AIScripts[actor]->GoalChanged(currentGoalNumber, newGoalNumber);
	}
	_inScriptCounter--;
}

bool AIScripts::reachedMovementTrackWaypoint(int actor, int waypointId) {
	if (actor >= _actorCount) {
		return false;
	}

	bool result = false;
	if (!_vm->_actors[actor]->inCombat()) {
		_inScriptCounter++;
		if (_AIScripts[actor]) {
			result = _AIScripts[actor]->ReachedMovementTrackWaypoint(waypointId);
		}
		_inScriptCounter--;
	}
	return result;
}

void AIScripts::updateAnimation(int actor, int *animation, int *frame) {
	if (actor >= _actorCount) {
		return;
	}

	_inScriptCounter++;
	if (_AIScripts[actor]) {
		_AIScripts[actor]->UpdateAnimation(animation, frame);
	}
	_inScriptCounter--;
}

void AIScripts::changeAnimationMode(int actor, int mode) {
	if (actor >= _actorCount) {
		return;
	}

	_inScriptCounter++;
	if (_AIScripts[actor]) {
		_AIScripts[actor]->ChangeAnimationMode(mode);
	}
	_inScriptCounter--;
}

} // End of namespace BladeRunner