-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaibasbhv.cpp
730 lines (563 loc) · 18.5 KB
/
aibasbhv.cpp
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
/*
@Copyright Looking Glass Studios, Inc.
1996,1997,1998,1999,2000 Unpublished Work.
*/
///////////////////////////////////////////////////////////////////////////////
// $Header: r:/t2repos/thief2/src/ai/aibasbhv.cpp,v 1.56 2000/01/24 20:14:22 adurant Exp $
//
//
//
#include <lg.h>
#include <ai.h>
#include <aibasabl.h>
#include <aibasact.h>
#include <aibasbhv.h>
#include <aibascmp.h>
#include <aibasctm.h>
#include <aibasmrg.h>
#include <aibassns.h>
#include <aiactfol.h>
#include <aiactfrb.h>
#include <aiactinv.h>
#include <aiactloc.h>
#include <aiactlch.h>
#include <aiactmot.h>
#include <aiactmov.h>
#include <aiactori.h>
#include <aiactps.h>
#include <aiactsnd.h>
#include <aiacttyp.h>
#include <aiactwnd.h>
#include <aiactwt.h>
#include <aiactjr.h>
#include <aiactjs.h>
#include <aiactjsc.h>
#include <aicbhtoh.h>
//#include <aicbrngd.h>
#include <aicbrnew.h>
#include <aicombat.h>
#include <aidbgcmp.h>
#include <aideath.h>
#include <aidefend.h>
#include <aifollow.h>
#include <aigests.h>
#include <aimove.h>
#include <aiidle.h>
#include <aiinvest.h>
#include <aipatrol.h>
#include <aiscrabl.h>
#include <aisound.h>
#include <aistdmrg.h>
#include <aitest.h>
#include <aicdummy.h>
#include <aistun.h>
#include <aidetect.h>
#include <aiflee.h>
#include <aifreeze.h>
#include <aiwatch.h>
#include <ailisten.h>
#include <aithreat.h>
#include <aialtrsp.h>
#include <aimplyr.h>
#include <aimttest.h>
#include <aidoormr.h>
#include <aincbdmg.h>
#include <aiinform.h>
#include <aicbtrsp.h>
#include <aicnvabl.h>
#include <aipthfnd.h>
#include <ainet.h>
#include <aibdyrsp.h>
#include <aisusrsp.h>
#include <aiproxy.h>
// Must be last header
#include <dbmem.h>
//#define TEST_ABILITY 1
///////////////////////////////////////////////////////////////////////////////
//
// Gestures to Motions Table
//
struct sAIGestureMotionEntry
{
sAIGestureMotionEntry(eAIGestureType _type, const char * _pszName, const char * _tags)
: type(_type), pszName(_pszName), tags(_tags) {}
eAIGestureType type;
const char * pszName;
cTagSet tags;
};
////////////////////////////////////
#define GESTMOT(e, string) { sAIGestureMotionEntry(e, #e, string) }
static sAIGestureMotionEntry g_AIGestureMotionTable[] =
{
GESTMOT( kAIGT_None, "" ),
GESTMOT( kAIGT_Calibration, "" ),
GESTMOT( kAIGT_Rest, "" ),
GESTMOT( kAIGT_Fidget, "IdleGesture 0" )
};
///////////////////////////////////////////////////////////////////////////////
//
// CLASS: cAIBehaviorSet
//
////////////////////////////////////
cAIBehaviorSet::cAIBehaviorSet()
{
}
////////////////////////////////////
cAIBehaviorSet::~cAIBehaviorSet()
{
}
////////////////////////////////////
//
// Find out the behavior set name
//
STDMETHODIMP_(const char *) cAIBehaviorSet::GetName()
{
return "Default";
}
////////////////////////////////////
//
// Create an AI object for the creature type
//
STDMETHODIMP_(cAI *) cAIBehaviorSet::CreateAI(ObjID id)
{
cAI * pAI = new cAI;
if (pAI->Init(id, this) != S_OK)
SafeRelease(pAI);
return pAI;
}
////////////////////////////////////
void cAIBehaviorSet::CreateNonAbilityComponents(cAIComponentPtrs * pComponents)
{
// Debugging/development tools
#ifndef SHIP
pComponents->Append(new cAIFlowDebugger);
#endif
#ifdef TEST_ABILITY
pComponents->Append(new cAITest);
#endif
// Enactors
pComponents->Append(new cAIMoveEnactor);
pComponents->Append(new cAISoundEnactor);
// Pathfinder
pComponents->Append(new cAIPathfinder);
// Movement regulators
pComponents->Append(new cAIObjectsMovReg);
pComponents->Append(new cAIWallsCliffsMovReg);
pComponents->Append(new cAIDoorMovReg);
pComponents->Append(new cAILVLMovReg);
// Senses
pComponents->Append(new cAISenses);
// Defend point watcher
pComponents->Append(new cAIDefend);
#ifdef NEW_NETWORK_ENABLED
// Networking interface
pComponents->Append(new cAINetwork);
#endif
}
////////////////////////////////////
void cAIBehaviorSet::CreateGenericAbilities(cAIComponentPtrs * pComponents)
{
pComponents->Append(new cAIDeath);
pComponents->Append(new cAIBasicScript);
pComponents->Append(new cAIStun);
pComponents->Append(new cAIDetect);
}
////////////////////////////////////
void cAIBehaviorSet::CreateNonCombatAbilities(cAIComponentPtrs * pComponents)
{
pComponents->Append(new cAIInvestigate);
pComponents->Append(new cAIPatrol);
pComponents->Append(new cAIIdle);
pComponents->Append(new cAIFlee);
pComponents->Append(new cAINonCombatDamageResponse);
pComponents->Append(new cAIFollow);
pComponents->Append(new cAISignalResponse);
pComponents->Append(new cAIAlertResponse);
pComponents->Append(new cAIBodyResponse);
pComponents->Append(new cAIThreatResponse);
pComponents->Append(new cAIWatch);
pComponents->Append(new cAIConverse);
pComponents->Append(new cAIInform);
pComponents->Append(new cAISenseCombatResponse);
pComponents->Append(new cAISuspiciousResponse);
pComponents->Append(new cAIFreeze);
}
////////////////////////////////////
void cAIBehaviorSet::CreateCombatAbilities(cAIComponentPtrs * pComponents)
{
pComponents->Append(new cAICombatHtoH);
#if 0
pComponents->Append(new cAICombatRanged);
pComponents->Append(new cAICombatDummy);
#endif
}
////////////////////////////////////
//
// Create the set of components that define the AIs potential
//
STDMETHODIMP cAIBehaviorSet::CreateComponents(cAIComponentPtrs * pComponents)
{
CreateNonAbilityComponents(pComponents);
#ifndef TEST_ABILITY
CreateGenericAbilities(pComponents);
CreateNonCombatAbilities(pComponents);
CreateCombatAbilities(pComponents);
#endif
return S_OK;
}
////////////////////////////////////
//
// Create a stock action object of a specified type
//
STDMETHODIMP_(cAIMoveAction *) cAIBehaviorSet::CreateMoveAction(IAIActor * pOwner, DWORD data)
{
return new cAIMoveAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAILocoAction *) cAIBehaviorSet::CreateLocoAction(IAIActor * pOwner, DWORD data)
{
return new cAILocoAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIMotionAction *) cAIBehaviorSet::CreateMotionAction(IAIActor * pOwner, DWORD data)
{
return new cAIMotionAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAISoundAction *) cAIBehaviorSet::CreateSoundAction(IAIActor * pOwner, DWORD data)
{
return new cAISoundAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIOrientAction *) cAIBehaviorSet::CreateOrientAction(IAIActor * pOwner, DWORD data)
{
return new cAIOrientAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIFrobAction *) cAIBehaviorSet::CreateFrobAction(IAIActor * pOwner, DWORD data)
{
return new cAIFrobAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIFollowAction *) cAIBehaviorSet::CreateFollowAction(IAIActor * pOwner, DWORD data)
{
return new cAIFollowAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIInvestAction *) cAIBehaviorSet::CreateInvestAction(IAIActor * pOwner, DWORD data)
{
return new cAIInvestAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIWanderAction *) cAIBehaviorSet::CreateWanderAction(IAIActor * pOwner, DWORD data)
{
return new cAIWanderAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIPsdScrAction *) cAIBehaviorSet::CreatePsdScrAction(IAIActor * pOwner, DWORD data)
{
return new cAIPsdScrAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIWaitAction *) cAIBehaviorSet::CreateWaitAction(IAIActor * pOwner, DWORD data)
{
return new cAIWaitAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAILaunchAction *) cAIBehaviorSet::CreateLaunchAction(IAIActor * pOwner, DWORD data)
{
return new cAILaunchAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIJointRotateAction *) cAIBehaviorSet::CreateJointRotateAction(IAIActor * pOwner, DWORD data)
{
return new cAIJointRotateAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIJointSlideAction *) cAIBehaviorSet::CreateJointSlideAction(IAIActor * pOwner, DWORD data)
{
return new cAIJointSlideAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIJointScanAction *) cAIBehaviorSet::CreateJointScanAction(IAIActor * pOwner, DWORD data)
{
return new cAIJointScanAction(pOwner, data);
}
////////////////////////////////////
STDMETHODIMP_(cAIAction *) cAIBehaviorSet::CreateGestureAction(eAIGestureType gesture, IAIActor * pOwner, DWORD data)
{
IInternalAI * pAI = pOwner->AccessOuterAI();
IAIMoveEnactor * pEnactor = pAI->AccessMoveEnactor();
if (pEnactor)
{
if (pEnactor->SupportsMotionActions())
{
for (int i = 0; i < sizeof(g_AIGestureMotionTable); i++)
{
if (g_AIGestureMotionTable[i].type == gesture)
{
cAIMotionAction * pAction = CreateMotionAction(pOwner, data);
pAction->AddTags(g_AIGestureMotionTable[i].tags);
return pAction;
}
}
}
else
{
}
}
return new cAINullAction(pOwner, data);
}
////////////////////////////////////
//
// Create a game-specific action object
//
STDMETHODIMP_(cAIAction *) cAIBehaviorSet::CreateCustomAction(tAIActionType type, IAIActor * pOwner, DWORD data)
{
CriticalMsg("There are no default custom actions");
return new cAINullAction(pOwner, data);
}
/////////////////////////////////////
//
// Factories for actions that may have proxies in network games.
//
STDMETHODIMP_(void) cAIBehaviorSet::EnactProxyLaunchAction(IAI *pAI, void *netmsg)
{
cAILaunchAction::EnactFire(pAI, netmsg);
}
////////////////////////////////////
STDMETHODIMP_(void) cAIBehaviorSet::EnactProxyJointRotateAction(IAI *pAI, void *netmsg)
{
new cAIJointRotateAction(pAI, netmsg);
}
////////////////////////////////////
STDMETHODIMP_(void) cAIBehaviorSet::EnactProxyJointSlideAction(IAI *pAI, void *netmsg)
{
new cAIJointSlideAction(pAI, netmsg);
}
////////////////////////////////////
STDMETHODIMP_(void) cAIBehaviorSet::EnactProxyJointScanAction(IAI *pAI, void *netmsg)
{
cAIJointScanAction::HandleNetMessage(pAI, netmsg);
}
////////////////////////////////////
STDMETHODIMP_(void) cAIBehaviorSet::EnactProxyCustomAction(tAIActionType type, IAI *pAI,
void *netmsg)
{
CriticalMsg("There are no default custom proxy actions");
}
//////////////////////////////////////
//
// Create an action of the given type.
//
cAIAction *cAIBehaviorSet::CreateAnyAction(tAIActionType type, IAIActor *pOwner, DWORD data)
{
switch (type)
{
case kAIAT_Null: return NULL;
case kAIAT_Wait: return CreateWaitAction(pOwner, data);
case kAIAT_Move: return CreateMoveAction(pOwner, data);
case kAIAT_Locomote: return CreateLocoAction(pOwner, data);
case kAIAT_Motion: return CreateMotionAction(pOwner, data);
case kAIAT_Sound: return CreateSoundAction(pOwner, data);
case kAIAT_Orient: return CreateOrientAction(pOwner, data);
case kAIAT_Stand: return NULL;
case kAIAT_Sequence: return NULL;
case kAIAT_Frob: return CreateFrobAction(pOwner, data);
case kAIAT_Follow: return CreateFollowAction(pOwner, data);
case kAIAT_Investigate: return CreateInvestAction(pOwner, data);
case kAIAT_Wander: return CreateWanderAction(pOwner, data);
case kAIAT_MoveToMarker: return NULL;
case kAIAT_PsuedoScript: return CreatePsdScrAction(pOwner, data);
case kAIAT_AttackRanged: return NULL;
case kAIAT_Launch: return NULL;
default:
if (type >= kAIAT_CustomBase)
{
return NULL; // @TBD (toml 11-04-98): CreateCustomAction(type, pOwner, data);
}
else
{
// Warning(("CreateAnyAction: Unknown action type %d\n", type));
Warning(("CreateAnyAction: Unknown action type %s\n", AIGetActTypeName(type)));
return NULL; //new cAINullAction(pOwner, data);
}
}
}
/////////////////////////////////
STDMETHODIMP_(void) cAIBehaviorSet::SaveAction(ITagFile * pTagFile, IAIAction *pAction)
{
tAIActionType actionType = pAction->GetType();
AITagMove(pTagFile, &actionType);
DWORD data = pAction->GetData();
AITagMove(pTagFile, &data);
pAction->Save(pTagFile);
}
/////////////////////////////////
STDMETHODIMP_(cAIAction *) cAIBehaviorSet::LoadAndCreateAction(ITagFile *pTagFile, IAIActor *pOwner)
{
tAIActionType actionType;
DWORD data;
AITagMove(pTagFile, &actionType);
AITagMove(pTagFile, &data);
// Create an action of this type
cAIAction *pAction = CreateAnyAction(actionType, pOwner, data);
// Load it (then delete it if it failed to load).
if (pAction && !pAction->Load(pTagFile))
SafeRelease(pAction);
return pAction;
}
///////////////////////////////////////////////////////////////////////////////
//
// CLASS: cAIMotionTestBehaviorSet
//
cAIMotionTestBehaviorSet::cAIMotionTestBehaviorSet()
{
}
////////////////////////////////////
cAIMotionTestBehaviorSet::~cAIMotionTestBehaviorSet()
{
}
////////////////////////////////////
STDMETHODIMP_(const char *) cAIMotionTestBehaviorSet::GetName()
{
return "MotionTest";
}
////////////////////////////////////
void cAIMotionTestBehaviorSet::CreateGenericAbilities(cAIComponentPtrs * pComponents)
{
pComponents->Append(new cAITestMotionPlayer);
}
////////////////////////////////////
void cAIMotionTestBehaviorSet::CreateNonCombatAbilities(cAIComponentPtrs * pComponents)
{
}
////////////////////////////////////
void cAIMotionTestBehaviorSet::CreateCombatAbilities(cAIComponentPtrs * pComponents)
{
}
///////////////////////////////////////////////////////////////////////////////
//
// CLASS: cAIMotionTagsTestBehaviorSet
//
cAIMotionTagsTestBehaviorSet::cAIMotionTagsTestBehaviorSet()
{
}
////////////////////////////////////
cAIMotionTagsTestBehaviorSet::~cAIMotionTagsTestBehaviorSet()
{
}
////////////////////////////////////
STDMETHODIMP_(const char *) cAIMotionTagsTestBehaviorSet::GetName()
{
return "MotionTagsTest";
}
////////////////////////////////////
void cAIMotionTagsTestBehaviorSet::CreateGenericAbilities(cAIComponentPtrs * pComponents)
{
pComponents->Append(new cAIMotionTagsTester);
}
////////////////////////////////////
void cAIMotionTagsTestBehaviorSet::CreateNonCombatAbilities(cAIComponentPtrs * pComponents)
{
}
////////////////////////////////////
void cAIMotionTagsTestBehaviorSet::CreateCombatAbilities(cAIComponentPtrs * pComponents)
{
}
///////////////////////////////////////////////////////////////////////////////
//
// CLASS: cAIRangedBehaviorSet
//
STDMETHODIMP_(const char *) cAIRangedBehaviorSet::GetName()
{
return "Ranged combatant";
}
///////////////////////////////////////
void cAIRangedBehaviorSet::CreateCombatAbilities(cAIComponentPtrs * pComponents)
{
// pComponents->Append(new cAICombatRanged);
pComponents->Append(new cAICombatNewRanged);
}
///////////////////////////////////////////////////////////////////////////////
//
// CLASS: cAISimpleBehaviorSet
//
STDMETHODIMP_(const char *) cAISimpleBehaviorSet::GetName()
{
return "SimpleNC";
}
///////////////////////////////////////
void cAISimpleBehaviorSet::CreateCombatAbilities(cAIComponentPtrs * pComponents)
{
}
///////////////////////////////////////////////////////////////////////////////
//
// CLASS: cAINetProxyBehaviorSet
//
////////////////////////////////////
STDMETHODIMP_(const char *) cAINetProxyBehaviorSet::GetName()
{
return "NetProxy";
}
////////////////////////////////////
STDMETHODIMP_(cAI *) cAINetProxyBehaviorSet::CreateAI(ObjID id)
{
cAI * pAI = new cAIProxy;
if (pAI->Init(id, this) != S_OK)
SafeRelease(pAI);
return pAI;
}
////////////////////////////////////
STDMETHODIMP cAINetProxyBehaviorSet::CreateComponents(cAIComponentPtrs * pComponents)
{
// The only components needed by a proxy are the motion enactor, and the hand-to-hand
// combat enactor (which won't be used if it isn't appropriate for this ai). Most other
// components are for higher level decision making not done on the proxy machine.
// The sound actions are broadcast at a lower level, so don't need the sound enactor.
// Proxies no longer need any real intelligence, and positively shouldn't
// have a move enactor, since it conflicts with the ghost system...
// pComponents->Append(new cAIMoveEnactor);
// pComponents->Append(new cAICombatHtoH);
// Pathfinder
// pComponents->Append(new cAIPathfinder);
// Debugging/development tools
#ifndef SHIP
pComponents->Append(new cAIFlowDebugger);
#endif
pComponents->Append(new cAISenses);
return S_OK;
}
///////////////////////////////////////////////////////////////////////////////
//
// CLASS: cAIWatcherBehaviorSet
//
STDMETHODIMP_(const char *) cAIWatcherBehaviorSet::GetName()
{
return "Watcher";
}
////////////////////////////////////
void cAIWatcherBehaviorSet::CreateNonAbilityComponents(cAIComponentPtrs * pComponents)
{
// Debugging/development tools
#ifndef SHIP
pComponents->Append(new cAIFlowDebugger);
#endif
// Senses
pComponents->Append(new cAISenses);
}
////////////////////////////////////
void cAIWatcherBehaviorSet::CreateGenericAbilities(cAIComponentPtrs * pComponents)
{
}
////////////////////////////////////
void cAIWatcherBehaviorSet::CreateNonCombatAbilities(cAIComponentPtrs * pComponents)
{
pComponents->Append(new cAIAlertResponse);
pComponents->Append(new cAIWatch);
pComponents->Append(new cAISenseCombatResponse);
}
////////////////////////////////////
void cAIWatcherBehaviorSet::CreateCombatAbilities(cAIComponentPtrs * pComponents)
{
}