forked from FrictionalGames/PenumbraOverture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.h
495 lines (341 loc) · 11.4 KB
/
Player.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
/*
* 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_PLAYER_H
#define GAME_PLAYER_H
#include "StdAfx.h"
using namespace hpl;
#include "GameTypes.h"
class cInit;
class iPlayerMoveState;
class iPlayerState;
class cPlayer;
class iPlayerWeaponCallback;
class cPlayerGroundRayCallback;
class cPlayerPickRayCallback;
class cPlayerHeadMove;
class cPlayerHealth;
class cPlayerEarRing;
class cPlayerLean;
class cPlayerDamage;
class cPlayerDeath;
class cPlayerFlashLight;
class cPlayerGlowStick;
class cPlayerFlare;
class cPlayerNoiseFilter;
class cPlayerFearFilter;
class cPlayerLookAt;
class cPlayerHidden;
class cPlayerAmbientLight;
class cPlayerBodyCallback;
class cHapticGameCamera;
typedef std::vector<iPlayerState*> tPlayerStateVec;
typedef tPlayerStateVec::iterator tPlayerStateVecIt;
typedef std::vector<iPlayerMoveState*> tPlayerMoveStateVec;
typedef tPlayerMoveStateVec::iterator tPlayerMoveStateVecIt;
class cInventoryItem;
class cPlayer_GlobalSave;
class cSavedWorld;
//---------------------------------------------
kSaveData_BaseClass(cPlayer)
{
kSaveData_ClassInit(cPlayer)
public:
int mlStat_NumOfSaves;
cContainerList<cSaveGame_cGameCollideScript> mlstCollideCallbacks;
virtual iSaveObject* CreateSaveObject(cSaveObjectHandler *apSaveObjectHandler,cGame *apGame);
virtual int GetSaveCreatePrio();
};
//---------------------------------------------
class iPlayerMoveState
{
public:
iPlayerMoveState(cPlayer *apPlayer, cInit *apInit);
void SetupBody();
void InitState(iPlayerMoveState* apPrevState);
void Update(float afTimeStep);
void Stop();
void Start();
virtual void EnterState(iPlayerMoveState* apPrevState){}
virtual void LeaveState(iPlayerMoveState* apNextState){}
virtual void OnUpdate(float afTimeStep){}
bool mbActive;
float mfForwardSpeed;
float mfBackwardSpeed;
float mfSidewaySpeed;
float mfForwardAcc;
float mfForwardDeacc;
float mfSidewayAcc;
float mfSidewayDeacc;
float mfMaxHeadMove;
float mfMinHeadMove;
float mfHeadMoveSpeed;
float mfHeadMoveBackSpeed;
float mfFootStepMul;
tString msStepType;
float mfSpeedMul;
float mfHeightAddCount;
float mfHeightAdd;
float mfHeightAddSpeed;
cPlayer *mpPlayer;
cPlayerHeadMove *mpHeadMove;
cInit *mpInit;
cConfigFile *mpGameConfig;
ePlayerMoveState mPrevMoveState;
ePlayerMoveState mType;
};
//---------------------------------------------
class cPlayer : public iUpdateable
{
friend class cSaveData_cPlayer;
public:
cPlayer(cInit *apInit);
~cPlayer();
////////////////////////////////////////
//Interaction
void MoveForwards(float afMul, float afTimeStep);
void MoveSideways(float afMul, float afTimeStep);
void AddYaw(float afVal);
void AddPitch(float afVal);
void Lean(float afMul, float afTimeStep);
void StartInteract();
void StopInteract();
void StartExamine();
void StopExamine();
void StartHolster();
void Jump();
void StartRun();
void StopRun();
void StartCrouch();
void StopCrouch();
void StartInteractMode();
void StartInventory();
void StartInventoryShortCut(int alNum);
void StartFlashLightButton();
void StartGlowStickButton();
////////////////////////////////
// Actions
void SetStartPos(const tString& asName);
void FootStep(float afMul, const tString &asType="", bool abSkipCount= false);
void ChangeState(ePlayerState aState);
void ChangeMoveState(ePlayerMoveState aState, bool abSetHeadHeightDirectly=false);
void AddCollideScript(eGameCollideScriptType aType,const tString &asFunc, const tString &asEntity);
void RemoveCollideScript(eGameCollideScriptType aType,const tString &asFunc);
void RemoveCollideScriptWithChildEntity(iGameEntity *apEntity);
void ClearCollideScripts();
void SetHealth(float afX);
void AddHealth(float afX);
float GetHealth(){ return mfHealth;}
void Damage(float afDamage, ePlayerDamageType aType);
void DestroyWorldObjects();
iSaveData* CreateSaveData();
/////////////////////////////////////////
// Events
void OnWorldLoad();
void OnWorldExit();
void OnStart();
void Update(float afTimeStep);
void Reset();
void OnDraw();
void OnPostSceneDraw();
/////////////////////////////////////////
//Saving
void AddSaveData(cSavedWorld* apSavedWorld);
void LoadSaveData(cSavedWorld* apSavedWorld);
void SaveToGlobal(cPlayer_GlobalSave *apSave);
void LoadFromGlobal(cPlayer_GlobalSave *apSave);
/////////////////////////////////////////
//Properties
bool IsDead();
void SetActive(bool abActive);
bool IsActive(){ return mbActive;}
void SetPushBody(iPhysicsBody *apBody){mpPushBody = apBody;}
iPhysicsBody *GetPushBody(){ return mpPushBody;}
float GetDefaultMass(){ return mfDefaultMass;}
float GetMass(){ return mfMass;}
void SetMass(float afX);
void SetPower(float afX);
void AddPower(float afX);
float GetPower(){ return mfPower;}
iCharacterBody* GetCharacterBody(){ return mpCharBody;}
cCamera3D* GetCamera(){ return mpCamera;}
cVector3f GetSize(){ return mvSize;}
float GetCrouchHeight(){ return mfCrouchHeight;}
float GetMaxPushDist(){ return mfMaxPushDist;}
float GetMaxPushSpeed(){ return mfMaxPushSpeed;}
cVector2f GetMaxPushHeadMovement(){ return mvMaxPushHeadMovement;}
cVector2f GetMinPushHeadMovement(){ return mvMinPushHeadMovement;}
float GetMaxMoveDist(){ return mfMaxMoveDist;}
float GetMaxGrabDist(){ return mfMaxGrabDist;}
float GetMaxUseItemDist(){ return mfMaxUseItemDist;}
void SetPrevMoveState(ePlayerMoveState aState);
iPlayerMoveState* GetMoveStateData(ePlayerMoveState aState){ return mvMoveStates[aState];}
ePlayerMoveState GetMoveState(){ return mMoveState;}
ePlayerState GetState(){ return mState;}
iPlayerState* GetStateData(ePlayerState aState){ return mvStates[aState];}
float GetSpeedMul(){ return mfSpeedMul;}
void SetSpeedMul(float afSpeedMul);
float GetHealthSpeedMul(){ return mfHealthSpeedMul;}
void SetHealthSpeedMul(float afHealthSpeedMul);
void SetHeadMoveSizeMul(float afX){ mfHeadMoveSizeMul = afX;}
void SetHeadMoveSpeedMul(float afX){ mfHeadMoveSpeedMul = afX;}
float GetHeadMoveSizeMul(){ return mfHeadMoveSizeMul;}
float GetHeadMoveSpeedMul(){ return mfHeadMoveSpeedMul;}
float GetLookSpeed(){ return mfLookSpeed;}
void SetCrossHairState(eCrossHairState aState){ mCrossHairState = aState;}
eCrossHairState GetCrossHairState(){ return mCrossHairState;}
iPhysicsBody* GetPickedBody();
void SetPickedBody(iPhysicsBody* apBody);
float GetPickedDist();
const cVector3f& GetPickedPos();
cPlayerPickRayCallback* GetPickRay();
float GetCameraHeightAdd(){ return mfCameraHeightAdd;}
bool IsMoving(){ return mbMoving;}
cPlayerFlashLight* GetFlashLight(){ return mpFlashLight;}
cPlayerHeadMove* GetHeadMove(){ return mpHeadMove;}
cPlayerEarRing* GetEarRing(){ return mpEarRing;}
cPlayerGlowStick* GetGlowStick(){ return mpGlowStick;}
cPlayerFlare* GetFlare(){ return mpFlare;}
cPlayerNoiseFilter* GetNoiseFilter(){ return mpNoiseFilter;}
cPlayerFearFilter* GetFearFilter(){ return mpFearFilter;}
cPlayerLookAt* GetLookAt(){ return mpLookAt;}
cPlayerHidden* GetHidden(){ return mpHidden;}
cHapticGameCamera* GetHapticCamera(){ return mpHapticCamera;}
float GetHeightAdd(){ return mfHeightAdd;}
void SetHeightAdd(float afX){ mfHeightAdd = afX;}
cInit * GetInit(){return mpInit;}
cVector2f GetInteractMoveBorder(){ return mvInteractMoveBorder;}
cVector2f GetCrossHairPos(){ return mvCrossHairPos;}
void SetCrossHairPos(const cVector2f& avPos) { mvCrossHairPos = avPos;}
bool AddCrossHairPos(const cVector2f& avPos);
void ResetCrossHairPos() { mvCrossHairPos = cVector2f(400, 300);}
void SetCurrentItem(cInventoryItem *apItem){ mpCurrentItem = apItem;}
cInventoryItem* GetCurrentItem(){ return mpCurrentItem;}
void SetItemFlash(bool abX){ mbItemFlash = abX;}
void SetWeaponCallback(iPlayerWeaponCallback *apCallback){ mpWeaponCallback = apCallback;}
iPlayerWeaponCallback* GetWeaponCallback(){ return mpWeaponCallback;}
bool GetLandedFromJump(){ return mbLandedFromJump;}
void SetLandedFromJump(bool abX){ mbLandedFromJump = abX;}
void SetJumpButtonDown(bool abX);
bool GetJumpButtonDown(){ return mbJumpButtonDown;}
float GetJumpCount(){ return mfJumpCount;}
float GetMaxJumpCount(){ return mfMaxJumpCount;}
/////////////////////////////////////////
//Stats
int mlStat_NumOfSaves;
/////////////////////////////////////////
//State properties
float mfForwardUpMul;
float mfForwardRightMul;
float mfUpMul;
float mfRightMul;
bool mbPickAtPoint;
bool mbRotateWithPlayer;
bool mbUseNormalMass;
float mfGrabMassMul;
bool mbCanBeThrown;
bool mbCanBePulled;
float mfCurrentMaxInteractDist;
//Haptic
bool mbGrabbingMoveBody;
bool mbProxyTouching;
float mfHapticTorqueMul;
bool mbDamageFromPos;
cVector3f mvDamagePos;
//Debug
cVector3f mvLineStart;
cVector3f mvLineEnd;
private:
cInit *mpInit;
cScene *mpScene;
cGraphics *mpGraphics;
cResources *mpResources;
cGraphicsDrawer *mpGfxDrawer;
iLowLevelHaptic *mpLowLevelHaptic;
iFontData *mpFont;
cNode3D mFeetNode;
bool mbActive;
cCamera3D *mpCamera;
float mfLookSpeed;
float mfCameraHeightAdd;
cHapticGameCamera* mpHapticCamera;
cVector3f mvSize;
float mfCrouchHeight;
bool mbJumpButtonDown;
float mfJumpCount;
float mfMaxJumpCount;
bool mbLandedFromJump;
cVector2f mvInteractMoveBorder;
float mfHeightAdd;
float mfMaxPushDist;
float mfMaxPushSpeed;
float mfMaxMoveDist;
float mfMaxGrabDist;
float mfMaxGrabForce;
float mfMaxUseItemDist;
float mfSpeedMul;
float mfHealthSpeedMul;
float mfHeadMoveSizeMul;
float mfHeadMoveSpeedMul;
iPhysicsBody *mpPushBody;
std::vector<cGfxObject*> mvCrossHairs;
iHapticForce *mpDamageForce;
iHapticForce *mpDamageDirForce;
cVector2f mvMaxPushHeadMovement;
cVector2f mvMinPushHeadMovement;
bool mbMoving;
int mlGroundCount;
iCharacterBody *mpCharBody;
cPlayerGroundRayCallback *mpGroundRayCallback;
cPlayerPickRayCallback *mpPickRayCallback;
cPlayerBodyCallback *mpBodyCallback;
cPlayerHeadMove* mpHeadMove;
cPlayerDamage *mpDamage;
cPlayerDeath *mpDeath;
cPlayerFlashLight *mpFlashLight;
cPlayerLean *mpLean;
cPlayerEarRing *mpEarRing;
cPlayerGlowStick *mpGlowStick;
cPlayerFlare *mpFlare;
cPlayerHealth *mpHealth;
cPlayerNoiseFilter *mpNoiseFilter;
cPlayerFearFilter *mpFearFilter;
cPlayerLookAt *mpLookAt;
cPlayerHidden *mpHidden;
iPlayerWeaponCallback *mpWeaponCallback;
ePlayerState mState;
tPlayerStateVec mvStates;
ePlayerMoveState mMoveState;
tPlayerMoveStateVec mvMoveStates;
eCrossHairState mCrossHairState;
cVector2f mvCrossHairPos;
cInventoryItem *mpCurrentItem;
cLinearOscillation mItemFlash;
bool mbItemFlash;
float mfHealth;
float mfPower;
float mfDefaultMass;
float mfMass;
bool mbUpdatingCollisionCallbacks;
tSoundEntityList mlstFootStepSounds;
//Debug
bool mbShowHealth;
bool mbShowSoundsPlaying;
tGameCollideScriptMap m_mapCollideCallbacks;
};
#endif // GAME_PLAYER_H