-
Notifications
You must be signed in to change notification settings - Fork 105
/
GameEnemy.h
540 lines (391 loc) · 12.9 KB
/
GameEnemy.h
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
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of Penumbra Overture.
*
* Penumbra Overture 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.
*
* Penumbra Overture 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 Penumbra Overture. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GAME_GAME_ENEMY_H
#define GAME_GAME_ENEMY_H
#include "StdAfx.h"
#include "GameEntity.h"
#include "CharacterMove.h"
using namespace hpl;
class cGameTrigger;
class cCharacterMove;
class iGameEntity;
//-----------------------------------------
#define STATE_IDLE 0
#define STATE_HUNT 1
#define STATE_ATTACK 2
#define STATE_FLEE 3
#define STATE_KNOCKDOWN 4
#define STATE_DEAD 5
#define STATE_PATROL 6
#define STATE_INVESTIGATE 7
#define STATE_BREAKDOOR 8
#define STATE_CALLBACKUP 9
#define STATE_MOVETO 10
#define STATE_EAT 11
#define STATE_ATTENTION 12
#define STATE_NUM 13
//-----------------------------------------
enum eEnemyMoveState
{
eEnemyMoveState_Backward,
eEnemyMoveState_Stopped,
eEnemyMoveState_Walking,
eEnemyMoveState_Running,
eEnemyMoveState_LastEnum
};
//-----------------------------------------
class cEnemyPatrolNode : public iSerializable
{
kSerializableClassInit(cEnemyPatrolNode)
public:
cEnemyPatrolNode(){}
cEnemyPatrolNode(const tString &asNode, float afTime, const tString& asAnim) :
msNodeName(asNode), mfWaitTime(afTime), msAnimation(asAnim){}
tString msNodeName;
float mfWaitTime;
tString msAnimation;
};
//-----------------------------------------
class cLineOfSightRayCallback : public iPhysicsRayCallback
{
public:
void Reset();
bool OnIntersect(iPhysicsBody *pBody,cPhysicsRayParams *apParams);
bool Intersected();
private:
bool mbIntersected;
iPhysicsBody *mpGrabBody;
};
//------------------------------------------
class cEnemyFindGround : public iPhysicsRayCallback
{
public:
bool GetGround( const cVector3f &avStartPos,const cVector3f &avDir,
cVector3f *apDestPosition, cVector3f *apDestNormal,
float afMaxDistance=10);
bool OnIntersect(iPhysicsBody *pBody,cPhysicsRayParams *apParams);
private:
bool mbIntersected;
float mfMinDist;
cVector3f mvPos;
cVector3f mvNormal;
float mfMaxDistance;
};
//------------------------------------------
class cEnemyCheckForDoor : public iPhysicsRayCallback
{
public:
bool CheckDoor(const cVector3f &avStart, const cVector3f &avEnd);
bool BeforeIntersect(iPhysicsBody *pBody);
bool OnIntersect(iPhysicsBody *pBody,cPhysicsRayParams *apParams);
private:
bool mbIntersected;
};
//------------------------------------------
class iGameEnemy_SaveData : public iGameEntity_SaveData
{
kSerializableClassInit(iGameEnemy_SaveData);
public:
bool mbHasBeenActivated;
cVector3f mvCharBodyPosition;
cVector3f mvCharBodyRotation;
int mlCurrentPatrolNode;
float mfDisappearTime;
bool mbDisappearActive;
bool mbHasDisappeared;
bool mbUsesTriggers;
cVector3f mvLastPlayerPos;
tString msOnDeathCallback;
tString msOnAttackCallback;
cContainerVec<cEnemyPatrolNode> mvPatrolNodes;
iGameEntity* CreateEntity();
};
//-----------------------------------------
class iGameEnemyState
{
public:
iGameEnemyState(int alId, cInit *apInit, iGameEnemy *apEnemy);
virtual void OnEnterState(iGameEnemyState *apPrevState)=0;
virtual void OnLeaveState(iGameEnemyState *apNextState)=0;
virtual void OnUpdate(float afTimeStep)=0;
virtual void OnDraw()=0;
virtual void OnPostSceneDraw()=0;
virtual void OnSeePlayer(const cVector3f &avPosition, float afChance)=0;
virtual bool OnHearNoise(const cVector3f &avPosition, float afVolume)=0;
virtual void OnTakeHit(float afDamage)=0;
virtual void OnDeath(float afDamage)=0;
virtual void OnAnimationOver(const tString& asAnimName)=0;
virtual void OnFlashlight(const cVector3f &avPosition)=0;
void SetPreviousState(int alX){ mlPreviousState = alX;}
int GetPreviousState(){ return mlPreviousState;}
int GetId(){ return mlId;}
protected:
int mlId;
cInit *mpInit;
cPlayer *mpPlayer;
iGameEnemy *mpEnemy;
cCharacterMove *mpMover;
int mlPreviousState;
};
//-----------------------------------------
class iGameEnemy : public iGameEntity
{
#ifdef __GNUC__
typedef iGameEntity __super;
#endif
friend class cEntityLoader_GameEnemy;
public:
iGameEnemy(cInit *apInit,const tString& asName,TiXmlElement *apGameElem);
virtual ~iGameEnemy(void);
//Special
void LoadBaseProperties(TiXmlElement *apGameElem);
//Actions
void OnPlayerInteract();
void OnPlayerPick();
void Setup(cWorld3D *apWorld);
void OnWorldLoad();
void OnPostLoadScripts();
void OnWorldExit();
void OnDraw();
void OnPostSceneDraw();
virtual void ExtraPostSceneDraw(){}
void Update(float afTimeStep);
bool IsLoading(){ return mbLoading;}
void OnDamage(float afX);
void OnDeath(float afX);
void OnFlashlight(const cVector3f &avPos);
virtual void OnSetActive(bool abX);
virtual bool MoveToPos(const cVector3f& avFeetPos)=0;
virtual void ShowPlayer(const cVector3f& avPlayerFeetPos){}
virtual bool IsFighting(){ return false;}
//Physics
void SetupBody();
//Properties
cVector3f GetPosition();
void SetFOV(float afAngle){ mfFOV = afAngle;}
const tString& GetHitPS(){ return msHitPS;}
const tString& GetEnemyType(){ return msEnemyType;}
const tString& GetCloseMusic(){ return msCloseMusic;}
int GetCloseMusicPrio(){ return mlCloseMusicPrio;}
float GetCloseMusicStartDist(){ return mfCloseMusicStartDist;}
float GetCloseMusicStopDist(){ return mfCloseMusicStopDist;}
const tString& GetAttackMusic(){ return msAttackMusic;}
int GetAttackMusicPrio(){ return mlAttackMusicPrio;}
//States
void AddState(iGameEnemyState *apState);
void ChangeState(int alId);
iGameEnemyState *GetState(int alId);
int GetCurrentStateId(){ return mlCurrentState;}
//Triggers
bool HandleTrigger(cGameTrigger *apTrigger);
eGameTriggerType GetTriggerTypes(){ return mTriggerTypes;}
float GetTriggerUpdateCount() { return mfTriggerUpdateCount;}
void SetTriggerUpdateCount(float afX) { mfTriggerUpdateCount = afX; }
float GetTriggerUpdateRate() { return mfTriggerUpdateRate;}
void SetSkipSoundTriggerCount(float afX){ mfSkipSoundTriggerCount = afX;}
//Content control
void PlayAnim( const tString &asName, bool abLoop, float afFadeTime,
bool abDependsOnSpeed=false, float afSpeedMul=1.0f,
bool abSyncWithPrevFrame=false,
bool abOverideMoveState=true);
void UseMoveStateAnimations();
cAnimationState* GetCurrentAnimation(){ return mpCurrentAnimation;}
void PlaySound(const tString &asName);
//Callabcks
void SetOnDeathCallback(const tString &asFunc){ msOnDeathCallback = asFunc;}
void SetOnAttackCallback(const tString &asFunc){ msOnAttackCallback = asFunc;}
tString GetOnAttackCallback(){ return msOnAttackCallback;}
//AI
bool CanSeePlayer();
cCharacterMove* GetMover(){ return mpMover;}
cVector3f GetLastPlayerPos(){ return mvLastPlayerPos;}
void SetLastPlayerPos(const cVector3f &avPos){ mvLastPlayerPos = avPos;}
void SetTempPosition(const cVector3f &avPos) {mvTempPosition = avPos;}
cVector3f GetTempPosition() { return mvTempPosition;}
void SetTempFloat(float afX) {mfTempFloat = afX;}
float GetTempFloat() { return mfTempFloat;}
cEnemyFindGround* GetGroundFinder(){ return &mFindGround;}
cEnemyCheckForDoor* GetDoorChecker() { return &mDoorCheck;}
bool CheckForDoor();
bool CheckForTeamMate(float afMaxDist, bool abCheckIfFighting);
bool IsAttracted(){ return mbIsAttracted;}
void SetAttracted(bool abX){ mbIsAttracted = abX;}
bool GetUsesTriggers(){ return mbUsesTriggers;}
void SetUsesTriggers(bool abX){ mbUsesTriggers = abX;}
//Patrolling
void AddPatrolNode(const tString& asNode, float afTime, const tString& asAnimation);
cEnemyPatrolNode* GetPatrolNode(int alIdx){return &mvPatrolNodes[alIdx];}
int GetPatrolNodeNum(){ return (int)mvPatrolNodes.size();}
cEnemyPatrolNode* CurrentPatrolNode(){return &mvPatrolNodes[mlCurrentPatrolNode];}
void ClearPatrolNodes();
int GetCurrentPatrolNode(){ return mlCurrentPatrolNode;}
float GetWaitTime(){ return mfWaitTime;}
float GetWaitTimeCount(){ return mfWaitTimeCount;}
void SetCurrentPatrolNode(int alX){ mlCurrentPatrolNode = alX;}
void IncCurrentPatrolNode()
{
mlCurrentPatrolNode++;
if(mlCurrentPatrolNode >= (int)mvPatrolNodes.size())
mlCurrentPatrolNode =0;
}
void SetWaitTime(float afX){ mfWaitTime = afX;}
void SetWaitTimeCount(float afX){ mfWaitTimeCount = afX;}
void AddWaitTimeCount(float afX){ mfWaitTimeCount += afX;}
float GetDoorBreakCount(){ return mfDoorBreakCount;}
void SetDoorBreakCount(float afX){ mfDoorBreakCount =afX;}
void AddDoorBreakCount(float afX){ mfDoorBreakCount +=afX;}
const cVector3f& GetModelOffsetAngles(){ return mvModelOffsetAngles;}
//Virtual
virtual void OnUpdate(float afTimeStep)=0;
virtual void OnLoad()=0;
//SaveObject implementation
iGameEntity_SaveData* CreateSaveData();
void SaveToSaveData(iGameEntity_SaveData *apSaveData);
void LoadFromSaveData(iGameEntity_SaveData *apSaveData);
protected:
void UpdateEnemyPose(float afTimeStep);
void UpdateAnimations(float afTimeStep);
void UpdateCheckForPlayer(float afTimeStep);
bool HandleSoundTrigger(cGameTrigger *apTrigger);
bool LineOfSight(const cVector3f &avPos, const cVector3f &avSize);
bool mbSetFeetAtGroundOnStart;
bool mbAttachMeshToBody;
bool mbRemoveAttackerOnDisable;
tVector3fVec mvRayStartPoses;
tVector3fVec mvRayEndPoses;
cEnemyFindGround mFindGround;
eGameTriggerType mTriggerTypes;
cCharacterMove *mpMover;
tString msEnemyType;
float mfTriggerUpdateCount;
float mfTriggerUpdateRate;
float mfSkipSoundTriggerCount;
cAStarHandler* mpAStarAir;
cAStarHandler* mpAStarGround;
cAINodeContainer* mpNodeContainerAir;
cAINodeContainer* mpNodeContainerGround;
cLineOfSightRayCallback mRayCallback;
std::vector<iGameEnemyState*> mvStates;
int mlCurrentState;
cEnemyCheckForDoor mDoorCheck;
cAnimationState *mpCurrentAnimation;
bool mbAnimationIsSpeedDependant;
float mfAnimationSpeedMul;
bool mbOverideMoveState;
eEnemyMoveState mMoveState;
cVector3f mvTempPosition;
float mfTempFloat;
tStringVec mvPreloadSounds;
bool mbLoading;
bool mbAlignToGroundNormal;
cMatrixf m_mtxStartPose;
cMatrixf m_mtxGoalPose;
float mfPoseCount;
bool mbHasBeenActivated;
bool mbUsesTriggers;
///////////////////////////////
//Variable Properties
cVector3f mvLastPlayerPos;
float mfCanSeePlayerCount;
float mfCheckForPlayerCount;
float mfCheckForPlayerRate;
bool mbCanSeePlayer;
int mlPlayerInLOSCount;
int mlMaxPlayerInLOSCount;
float mfCalcPlayerHiddenPosCount;
float mfDamageSoundTimer;
tString msOnDeathCallback;
tString msOnAttackCallback;
std::vector<cEnemyPatrolNode> mvPatrolNodes;
int mlCurrentPatrolNode;
float mfWaitTime;
float mfWaitTimeCount;
float mfDoorBreakCount;
bool mbIsAttracted;
/////////////////////////////////
//Properties to be implemented
bool mbDisappear;
float mfDisappearMinTime;
float mfDisappearMaxTime;
float mfDisappearMinDistance;
tString msDisappearPS;
tString msDisappearSound;
bool mbDisappearFreezesRagdoll;
float mfDisappearTime;
bool mbDisappearActive;
bool mbHasDisappeared;
tString msCloseMusic;
int mlCloseMusicPrio;
float mfCloseMusicStartDist;
float mfCloseMusicStopDist;
tString msAttackMusic;
int mlAttackMusicPrio;
bool mbShowDebug;
tString msGroundNodeType;
cVector3f mvBodySize;
float mfBodyMass;
float mfMaxForwardSpeed;
float mfMaxBackwardSpeed;
float mfAcceleration;
float mfDeacceleration;
float mfMaxTurnSpeed;
float mfAngleDistTurnMul;
float mfMinBreakAngle;
float mfBreakAngleMul;
float mfSpeedMoveAnimMul;
float mfTurnSpeedMoveAnimMul;
cMatrixf m_mtxModelOffset;
cVector3f mvModelOffsetAngles;
float mfIdleToMoveLimit;
float mfMoveToLideLimit;
float mfMaxPushMass;
float mfPushForce;
float mfMaxSeeDist;
float mfMinAttackDist;
float mfFOV;
float mfFOVXMul;
float mfMaxHealth;
float mfStoppedToWalkSpeed;
float mfWalkToStoppedSpeed;
float mfWalkToRunSpeed;
float mfRunToWalkSpeed;
float mfMoveAnimSpeedMul;
tString msBackwardAnim;
tString msStoppedAnim;
tString msWalkAnim;
tString msRunAnim;
float mfMinStunSpeed;
float mfMinStunImpulse;
float mfObjectCollideStun;
float mfStunDamageMul;
tString msHitPS;
};
//--------------------------------------
class cEntityLoader_GameEnemy : public cEntityLoader_Object
{
public:
cEntityLoader_GameEnemy(const tString &asName, cInit *apInit);
~cEntityLoader_GameEnemy();
private:
void BeforeLoad(TiXmlElement *apRootElem, const cMatrixf &a_mtxTransform,cWorld3D *apWorld);
void AfterLoad(TiXmlElement *apRootElem, const cMatrixf &a_mtxTransform,cWorld3D *apWorld);
cInit *mpInit;
};
//--------------------------------------
#endif // GAME_GAME_ENEMY_H