ScummVM API documentation
Player.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of Penumbra Overture.
26  */
27 
28 #ifndef GAME_PLAYER_H
29 #define GAME_PLAYER_H
30 
31 #include "hpl1/engine/engine.h"
32 
33 using namespace hpl;
34 
35 #include "hpl1/penumbra-overture/GameTypes.h"
36 
37 class cInit;
38 class iPlayerMoveState;
39 class iPlayerState;
40 class cPlayer;
41 
45 class cPlayerHeadMove;
46 class cPlayerHealth;
47 class cPlayerEarRing;
48 class cPlayerLean;
49 class cPlayerDamage;
50 class cPlayerDeath;
51 class cPlayerFlashLight;
52 class cPlayerGlowStick;
53 class cPlayerFlare;
54 class cPlayerNoiseFilter;
55 class cPlayerFearFilter;
56 class cPlayerLookAt;
57 class cPlayerHidden;
58 class cPlayerAmbientLight;
59 
61 
63 typedef tPlayerStateVec::iterator tPlayerStateVecIt;
64 
66 typedef tPlayerMoveStateVec::iterator tPlayerMoveStateVecIt;
67 
68 class cInventoryItem;
69 class cPlayer_GlobalSave;
70 class cSavedWorld;
71 
72 //---------------------------------------------
73 
74 kSaveData_BaseClass(cPlayer) {
75  kSaveData_ClassInit(cPlayer) public :
76 
77  int mlStat_NumOfSaves;
78 
80 
81  virtual iSaveObject *CreateSaveObject(cSaveObjectHandler * apSaveObjectHandler, cGame * apGame);
82  virtual int GetSaveCreatePrio();
83 };
84 
85 //---------------------------------------------
86 
88 public:
89  iPlayerMoveState(cPlayer *apPlayer, cInit *apInit);
90  virtual ~iPlayerMoveState() = default;
91 
92  void SetupBody();
93 
94  void InitState(iPlayerMoveState *apPrevState);
95 
96  void Update(float afTimeStep);
97 
98  void Stop();
99 
100  void Start();
101 
102  virtual void EnterState(iPlayerMoveState *apPrevState) {}
103  virtual void LeaveState(iPlayerMoveState *apNextState) {}
104 
105  virtual void OnUpdate(float afTimeStep) {}
106 
107  bool mbActive;
108 
109  float mfForwardSpeed;
110  float mfBackwardSpeed;
111  float mfSidewaySpeed;
112 
113  float mfForwardAcc;
114  float mfForwardDeacc;
115  float mfSidewayAcc;
116  float mfSidewayDeacc;
117 
118  float mfMaxHeadMove;
119  float mfMinHeadMove;
120  float mfHeadMoveSpeed;
121  float mfHeadMoveBackSpeed;
122 
123  float mfFootStepMul;
124 
125  tString msStepType;
126 
127  float mfSpeedMul;
128 
129  float mfHeightAddCount;
130  float mfHeightAdd;
131  float mfHeightAddSpeed;
132 
133  cPlayer *mpPlayer;
134  cPlayerHeadMove *mpHeadMove;
135 
136  cInit *mpInit;
137  cConfigFile *mpGameConfig;
138 
139  ePlayerMoveState mPrevMoveState;
140 
141  ePlayerMoveState mType;
142 };
143 //---------------------------------------------
144 
145 class cPlayer : public iUpdateable {
146  friend class cSaveData_cPlayer;
147 
148 public:
149  cPlayer(cInit *apInit);
150  ~cPlayer();
151 
153  // Interaction
154 
155  void MoveForwards(float afMul, float afTimeStep);
156  void MoveSideways(float afMul, float afTimeStep);
157  void AddYaw(float afVal);
158  void AddPitch(float afVal);
159  void Lean(float afMul, float afTimeStep);
160 
161  void StartInteract();
162  void StopInteract();
163  void StartExamine();
164  void StopExamine();
165  void StartHolster();
166 
167  void Jump();
168 
169  void StartRun();
170  void StopRun();
171 
172  void StartCrouch();
173  void StopCrouch();
174 
175  void StartInteractMode();
176 
177  void StartInventory();
178 
179  void StartInventoryShortCut(int alNum);
180 
181  void StartFlashLightButton();
182 
183  void StartGlowStickButton();
184 
186  // Actions
187  void SetStartPos(const tString &asName);
188 
189  void FootStep(float afMul, const tString &asType = "", bool abSkipCount = false);
190 
191  void ChangeState(ePlayerState aState);
192  void ChangeMoveState(ePlayerMoveState aState, bool abSetHeadHeightDirectly = false);
193 
194  void AddCollideScript(eGameCollideScriptType aType, const tString &asFunc, const tString &asEntity);
195  void RemoveCollideScript(eGameCollideScriptType aType, const tString &asFunc);
196  void RemoveCollideScriptWithChildEntity(iGameEntity *apEntity);
197  void ClearCollideScripts();
198 
199  void SetHealth(float afX);
200  void AddHealth(float afX);
201  float GetHealth() { return mfHealth; }
202  void Damage(float afDamage, ePlayerDamageType aType);
203 
204  void DestroyWorldObjects();
205 
206  iSaveData *CreateSaveData();
207 
209  // Events
210  void OnWorldLoad();
211  void OnWorldExit();
212  void OnStart();
213  void Update(float afTimeStep);
214  void Reset();
215  void OnDraw();
216  void OnPostSceneDraw();
217 
219  // Saving
220 
221  void AddSaveData(cSavedWorld *apSavedWorld);
222  void LoadSaveData(cSavedWorld *apSavedWorld);
223 
224  void SaveToGlobal(cPlayer_GlobalSave *apSave);
225  void LoadFromGlobal(cPlayer_GlobalSave *apSave);
226 
228  // Properties
229  bool IsDead();
230 
231  void SetActive(bool abActive);
232  bool IsActive() { return mbActive; }
233 
234  void SetPushBody(iPhysicsBody *apBody) { mpPushBody = apBody; }
235  iPhysicsBody *GetPushBody() { return mpPushBody; }
236 
237  float GetDefaultMass() { return mfDefaultMass; }
238 
239  float GetMass() { return mfMass; }
240  void SetMass(float afX);
241 
242  void SetPower(float afX);
243  void AddPower(float afX);
244  float GetPower() { return mfPower; }
245 
246  iCharacterBody *GetCharacterBody() { return mpCharBody; }
247  cCamera3D *GetCamera() { return mpCamera; }
248 
249  cVector3f GetSize() { return mvSize; }
250  float GetCrouchHeight() { return mfCrouchHeight; }
251 
252  float GetMaxPushDist() { return mfMaxPushDist; }
253  float GetMaxPushSpeed() { return mfMaxPushSpeed; }
254  cVector2f GetMaxPushHeadMovement() { return mvMaxPushHeadMovement; }
255  cVector2f GetMinPushHeadMovement() { return mvMinPushHeadMovement; }
256 
257  float GetMaxMoveDist() { return mfMaxMoveDist; }
258 
259  float GetMaxGrabDist() { return mfMaxGrabDist; }
260 
261  float GetMaxUseItemDist() { return mfMaxUseItemDist; }
262 
263  void SetPrevMoveState(ePlayerMoveState aState);
264  iPlayerMoveState *GetMoveStateData(ePlayerMoveState aState) { return mvMoveStates[aState]; }
265  ePlayerMoveState GetMoveState() { return mMoveState; }
266  ePlayerState GetState() { return mState; }
267 
268  iPlayerState *GetStateData(ePlayerState aState) { return mvStates[aState]; }
269 
270  float GetSpeedMul() { return mfSpeedMul; }
271  void SetSpeedMul(float afSpeedMul);
272 
273  float GetHealthSpeedMul() { return mfHealthSpeedMul; }
274  void SetHealthSpeedMul(float afHealthSpeedMul);
275 
276  void SetHeadMoveSizeMul(float afX) { mfHeadMoveSizeMul = afX; }
277  void SetHeadMoveSpeedMul(float afX) { mfHeadMoveSpeedMul = afX; }
278  float GetHeadMoveSizeMul() { return mfHeadMoveSizeMul; }
279  float GetHeadMoveSpeedMul() { return mfHeadMoveSpeedMul; }
280 
281  float GetLookSpeed() { return mfLookSpeed; }
282 
283  void SetCrossHairState(eCrossHairState aState) { mCrossHairState = aState; }
284  eCrossHairState GetCrossHairState() { return mCrossHairState; }
285 
286  iPhysicsBody *GetPickedBody();
287  void SetPickedBody(iPhysicsBody *apBody);
288  float GetPickedDist();
289  const cVector3f &GetPickedPos();
290  cPlayerPickRayCallback *GetPickRay();
291 
292  float GetCameraHeightAdd() { return mfCameraHeightAdd; }
293  bool IsMoving() { return mbMoving; }
294 
295  cPlayerFlashLight *GetFlashLight() { return mpFlashLight; }
296 
297  cPlayerHeadMove *GetHeadMove() { return mpHeadMove; }
298 
299  cPlayerEarRing *GetEarRing() { return mpEarRing; }
300 
301  cPlayerGlowStick *GetGlowStick() { return mpGlowStick; }
302 
303  cPlayerFlare *GetFlare() { return mpFlare; }
304 
305  cPlayerNoiseFilter *GetNoiseFilter() { return mpNoiseFilter; }
306 
307  cPlayerFearFilter *GetFearFilter() { return mpFearFilter; }
308 
309  cPlayerLookAt *GetLookAt() { return mpLookAt; }
310 
311  cPlayerHidden *GetHidden() { return mpHidden; }
312 
313  float GetHeightAdd() { return mfHeightAdd; }
314  void SetHeightAdd(float afX) { mfHeightAdd = afX; }
315 
316  cInit *GetInit() { return mpInit; }
317 
318  cVector2f GetInteractMoveBorder() { return mvInteractMoveBorder; }
319 
320  cVector2f GetCrossHairPos() { return mvCrossHairPos; }
321  void SetCrossHairPos(const cVector2f &avPos) { mvCrossHairPos = avPos; }
322  bool AddCrossHairPos(const cVector2f &avPos);
323  void ResetCrossHairPos() { mvCrossHairPos = cVector2f(400, 300); }
324 
325  void SetCurrentItem(cInventoryItem *apItem) { mpCurrentItem = apItem; }
326  cInventoryItem *GetCurrentItem() { return mpCurrentItem; }
327  void SetItemFlash(bool abX) { mbItemFlash = abX; }
328 
329  void SetWeaponCallback(iPlayerWeaponCallback *apCallback) { mpWeaponCallback = apCallback; }
330  iPlayerWeaponCallback *GetWeaponCallback() { return mpWeaponCallback; }
331 
332  bool GetLandedFromJump() { return mbLandedFromJump; }
333  void SetLandedFromJump(bool abX) { mbLandedFromJump = abX; }
334 
335  void SetJumpButtonDown(bool abX);
336  bool GetJumpButtonDown() { return mbJumpButtonDown; }
337  float GetJumpCount() { return mfJumpCount; }
338  float GetMaxJumpCount() { return mfMaxJumpCount; }
339 
341  // Stats
342  int mlStat_NumOfSaves;
343 
345  // State properties
346  float mfForwardUpMul;
347  float mfForwardRightMul;
348 
349  float mfUpMul;
350  float mfRightMul;
351 
352  bool mbPickAtPoint;
353  bool mbRotateWithPlayer;
354  bool mbUseNormalMass;
355 
356  float mfGrabMassMul;
357 
358  bool mbCanBeThrown;
359  bool mbCanBePulled;
360 
361  float mfCurrentMaxInteractDist;
362 
363  // Haptic
364  bool mbGrabbingMoveBody;
365  bool mbProxyTouching;
366  float mfHapticTorqueMul;
367 
368  bool mbDamageFromPos;
369  cVector3f mvDamagePos;
370 
371  // Debug
372  cVector3f mvLineStart;
373  cVector3f mvLineEnd;
374 
375 private:
376  cInit *mpInit;
377 
378  cScene *mpScene;
379  cGraphics *mpGraphics;
380  cResources *mpResources;
381  cGraphicsDrawer *mpGfxDrawer;
382 
383  FontData *mpFont;
384 
385  cNode3D mFeetNode;
386 
387  bool mbActive;
388 
389  cCamera3D *mpCamera;
390  float mfLookSpeed;
391  float mfCameraHeightAdd;
392 
393  cVector3f mvSize;
394  float mfCrouchHeight;
395 
396  bool mbJumpButtonDown;
397  float mfJumpCount;
398  float mfMaxJumpCount;
399 
400  bool mbLandedFromJump;
401 
402  cVector2f mvInteractMoveBorder;
403 
404  float mfHeightAdd;
405 
406  float mfMaxPushDist;
407  float mfMaxPushSpeed;
408 
409  float mfMaxMoveDist;
410 
411  float mfMaxGrabDist;
412  // float mfMaxGrabForce;
413 
414  float mfMaxUseItemDist;
415 
416  float mfSpeedMul;
417  float mfHealthSpeedMul;
418 
419  float mfHeadMoveSizeMul;
420  float mfHeadMoveSpeedMul;
421 
422  iPhysicsBody *mpPushBody;
423 
424  Common::Array<cGfxObject *> mvCrossHairs;
425 
426  cVector2f mvMaxPushHeadMovement;
427  cVector2f mvMinPushHeadMovement;
428 
429  bool mbMoving;
430 
431  int mlGroundCount;
432 
433  iCharacterBody *mpCharBody;
434 
435  cPlayerGroundRayCallback *mpGroundRayCallback;
436  cPlayerPickRayCallback *mpPickRayCallback;
437 
438  cPlayerBodyCallback *mpBodyCallback;
439 
440  cPlayerHeadMove *mpHeadMove;
441  cPlayerDamage *mpDamage;
442  cPlayerDeath *mpDeath;
443  cPlayerFlashLight *mpFlashLight;
444  cPlayerLean *mpLean;
445  cPlayerEarRing *mpEarRing;
446  cPlayerGlowStick *mpGlowStick;
447  cPlayerFlare *mpFlare;
448  cPlayerHealth *mpHealth;
449  cPlayerNoiseFilter *mpNoiseFilter;
450  cPlayerFearFilter *mpFearFilter;
451  cPlayerLookAt *mpLookAt;
452  cPlayerHidden *mpHidden;
453 
454  iPlayerWeaponCallback *mpWeaponCallback;
455 
456  ePlayerState mState;
457  tPlayerStateVec mvStates;
458 
459  ePlayerMoveState mMoveState;
460  tPlayerMoveStateVec mvMoveStates;
461 
462  eCrossHairState mCrossHairState;
463  cVector2f mvCrossHairPos;
464 
465  cInventoryItem *mpCurrentItem;
466  cLinearOscillation mItemFlash;
467  bool mbItemFlash;
468 
469  float mfHealth;
470 
471  float mfPower;
472 
473  float mfDefaultMass;
474  float mfMass;
475 
476  bool mbUpdatingCollisionCallbacks;
477 
478  tSoundEntityList mlstFootStepSounds;
479 
480  // Debug
481  bool mbShowHealth;
482  bool mbShowSoundsPlaying;
483 
484  tGameCollideScriptMap m_mapCollideCallbacks;
485 };
486 
487 #endif // GAME_PLAYER_H
Definition: AI.h:36
Definition: PlayerHelper.h:229
Definition: PlayerHelper.h:301
Definition: Game.h:91
Definition: str.h:59
Definition: PlayerHelper.h:487
Definition: PlayerHelper.h:42
Definition: font_data.h:67
Definition: PlayerState.h:45
Definition: PlayerHelper.h:345
Definition: list.h:44
Definition: PlayerHelper.h:572
Definition: PlayerHelper.h:102
T * iterator
Definition: array.h:54
Definition: ConfigFile.h:38
Definition: stablemap.h:43
Definition: Player.h:145
Definition: Player.h:87
Definition: SaveGame.h:130
Definition: GraphicsDrawer.h:77
Definition: PlayerHelper.h:140
Definition: PlayerHelper.h:262
Definition: PlayerHelper.h:72
Definition: Node3D.h:52
Definition: PhysicsBody.h:117
Definition: PlayerHelper.h:168
Definition: Inventory.h:123
Definition: SaveGame.h:111
Definition: SaveHandler.h:172
Definition: SaveHandler.h:239
Definition: PlayerHelper.h:192
Definition: Updateable.h:35
Definition: PlayerHelper.h:54
Definition: PlayerHelper.h:436
Definition: PlayerHelper.h:404
Definition: PlayerHelper.h:461
Definition: Resources.h:160
Definition: CharacterBody.h:153
Definition: Scene.h:61
Definition: MathTypes.h:61
Definition: PlayerHelper.h:369
Definition: GameEntity.h:126
Definition: SaveGame.h:183
Definition: Init.h:70
Definition: Graphics.h:46
Definition: Camera3D.h:53