Emergency 20 Dokumentation  4.2.0
Player.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
14 
15 #include <qsf/base/WeakPtr.h>
17 #include <qsf/job/JobProxy.h>
18 #include <qsf/math/Color4.h>
19 #include <qsf/math/EnumBitmask.h>
21 
22 #include <boost/noncopyable.hpp>
23 
24 
25 //[-------------------------------------------------------]
26 //[ Forward declarations ]
27 //[-------------------------------------------------------]
28 namespace qsf
29 {
30  class BinarySerializer;
31  class Map;
32  class Entity;
33  class Clock;
34  class FreeMoveInputHandler;
35 }
36 namespace em5
37 {
38  class UnitPool;
39  class IngameCameraInputHandler;
40 }
41 
42 
43 //[-------------------------------------------------------]
44 //[ Namespace ]
45 //[-------------------------------------------------------]
46 namespace em5
47 {
48 
49 
50  //[-------------------------------------------------------]
51  //[ Classes ]
52  //[-------------------------------------------------------]
57  class EM5_API_EXPORT Player : public boost::noncopyable
58  {
59 
60 
61  //[-------------------------------------------------------]
62  //[ Public definitions ]
63  //[-------------------------------------------------------]
64  public:
66 
67  enum class CameraType
68  {
69  UNKNOWN_CAMERA = 0,
70  INGAME_CAMERA,
71  FREE_CAMERA,
72  CUTSCENE_CAMERA
73  };
74 
75  struct BuyOption
76  {
77  std::string mUnitName;
78  std::string mAdditionalEventPools;
79  std::string mInfoText;
80  std::string mUpgrade;
81  std::string mIconName;
83  mutable bool mIsBought;
85 
86  BuyOption() : mCost(999), mIsBought(false), mIsPromotion(false) {}
87  };
88  typedef std::vector<const BuyOption*> BuyOptionPointerArray;
89 
90  enum DebugFlag
91  {
93  DEBUG_UNITPOOL
94  };
96 
97  typedef std::vector<uint64> EntityIdArray;
98 
99 
100  //[-------------------------------------------------------]
101  //[ Public methods ]
102  //[-------------------------------------------------------]
103  public:
108  Player(uint32 index, bool isLocal, VersionSwitch::Edition gameEdition);
109 
114  virtual ~Player();
115 
116  //[-------------------------------------------------------]
117  //[ Lifecycle ]
118  //[-------------------------------------------------------]
123  void startup();
124 
129  void shutdown();
130 
131  //[-------------------------------------------------------]
132  //[ Basic identification ]
133  //[-------------------------------------------------------]
138  inline const std::string& getName() const;
139 
144  inline void setName(const std::string& name);
145 
150  inline uint32 getPlayerIndex() const;
151 
156  inline void setPlayerIndex(uint32 playerIndex);
157 
162  inline uint16 getTeamId() const;
163 
168  inline void setTeamId(uint16 teamId);
169 
174  inline bool isPlayerLocal() const;
175 
180  inline VersionSwitch::Edition getGameEdition() const;
181 
182  // Player color
183  inline qsf::Color4 getPlayerColor() const;
184  inline void setPlayerColor(const qsf::Color4& color);
185 
186  // UserData
187  inline uint32 getUserData() const;
188  inline void setUserData(const uint32 userData);
189 
190  //[-------------------------------------------------------]
191  //[ Camera ]
192  //[-------------------------------------------------------]
197  qsf::Entity* getMainCameraEntity() const;
198 
203  inline qsf::CameraComponent* getMainCameraComponent() const;
204 
209  qsf::FreeMoveInputHandler* getMainCameraInputHandler() const;
210  inline CameraType getCameraType() const;
211  inline qsf::CameraComponent* getCameraComponent() const;
212  void setCameraType(CameraType cameraType, qsf::CameraComponent* cameraComponent = nullptr, bool inputChange = true);
213 
214  void resetCameraToStartTransform();
215  void setCameraToTransform(const qsf::Transform& transform);
216  void setCameraToEntityTransform(const qsf::Entity& cameraEntity);
217  void setCameraToEntityTransform(const std::string& cameraEntityEventTag);
218 
219  inline const glm::vec3& getViewPosition() const;
220  inline void setViewPosition(const glm::vec3& viewPosition);
221  void updateViewTransform();
222  qsf::Ray getCameraViewRay() const;
223  qsf::CameraComponent* getStartCameraInMap(qsf::Map& map) const;
224 
225  //[-------------------------------------------------------]
226  //[ Unit pool ]
227  //[-------------------------------------------------------]
232  inline UnitPool& getUnitPool() const;
233 
234  void unblockUnitPool();
235 
243  const std::vector<uint64>& getUnitGroupByIndex(uint32 index);
244 
245  void setUnitGroupByIndex(uint32 index, const std::vector<uint64>& savedIds);
246 
247  //[-------------------------------------------------------]
248  //[ Score, credits ]
249  //[-------------------------------------------------------]
257  inline uint32 getScore() const;
258 
269  void setScore(uint32 score);
270 
278  inline void addScore(int32 score);
279 
287  inline uint32 getCredits() const;
288 
299  void setCredits(uint32 credits);
300 
308  inline void addCredits(int32 credits);
309 
310  //[-------------------------------------------------------]
311  //[ Buy options ]
312  //[-------------------------------------------------------]
313  const BuyOptionPointerArray& getBuyOptions() const;
314  void clearBuyOptions();
315  void addBuyOption(const BuyOption& buyOption);
316  bool purchaseBuyOptionByIndex(uint32 index);
317  bool purchaseBuyOption(const BuyOption& buyOption);
318  bool hasUnboughtBuyOptions() const;
319 
320  //[-------------------------------------------------------]
321  //[ Debug ]
322  //[-------------------------------------------------------]
327  inline void toggleDebugFlag(DebugFlag flag);
328 
329  //[-------------------------------------------------------]
330  //[ Serialization ]
331  //[-------------------------------------------------------]
336  void serialize(qsf::BinarySerializer& serializer);
337 
338  //[-------------------------------------------------------]
339  //[ Internal ]
340  //[-------------------------------------------------------]
341  void updateViewPosition(const qsf::JobArguments&);
342  void updateDynamicPssmLambda(const qsf::JobArguments&);
343 
344 
345  //[-------------------------------------------------------]
346  //[ Private methods ]
347  //[-------------------------------------------------------]
348  private:
349  // Camera
350  void createMainCamera();
351  void setMainCamera(qsf::CameraComponent* cameraComponent, bool isFreeCamera, bool inputChange);
352  void switchToIngameCamera(bool inputChange = true);
353  void switchToFreeCamera(bool inputChange = true);
354  void switchToCutsceneCamera(qsf::CameraComponent* cameraComponent, bool inputChange = true);
355 
356  // Shadow
357  void setFixedPssmLambda();
358  void setDynamicPssmLambda();
359  void setPssmLambda(float pssmLambda);
360 
361  // Visualization
362  void setMapBorderVisualizationEnabled(bool enabled) const;
363 
364  // Debug
365  void updateDebugOutput(const qsf::JobArguments&);
366  void refreshDebug(const qsf::Clock* clock = nullptr);
367 
368 
369  //[-------------------------------------------------------]
370  //[ Private data ]
371  //[-------------------------------------------------------]
372  private:
373  // General player information
374  std::string mName;
375  uint32 mIndex;
376  uint16 mTeamId;
377  bool mIsLocal;
378  VersionSwitch::Edition mGameEdition;
379  qsf::Color4 mPlayerColor;
380  uint32 mUserData;
381 
382  // Unit pool
383  UnitPool* mUnitPool;
384  std::vector<EntityIdArray> mUnitGroups;
385 
386  // Score, money
387  uint32 mScore;
388  uint32 mCredits;
389 
390  // Buy options
391  BuyOptionPointerArray mBuyOptions;
392 
393  // Camera
394  CameraType mCameraType;
395  qsf::WeakPtr<qsf::CameraComponent> mCameraComponent;
396  qsf::WeakPtr<qsf::CameraComponent> mMainCameraComponent;
397  glm::vec3 mViewPosition;
398  IngameCameraInputHandler* mIngameCameraInputHandler;
399 
400  // Job update
401  qsf::JobProxy mUpdateJobProxy;
402  qsf::JobProxy mUpdateDynamicPssmLambdaJobProxy;
403 
404  // Debug
405  // -> Actually only for internal builds (additional check to find erroneous behavior), but we need to make sure end-user SDK is the same with or without ENDUSER define
406  qsf::JobProxy mDebugUpdateJobProxy;
407  DebugFlagSet mDebugFlags;
408  qsf::DebugDrawProxy mDebugDrawProxy;
409 
410  bool mIsSerialized;
411 
412 
413  };
414 
415 
416 //[-------------------------------------------------------]
417 //[ Namespace ]
418 //[-------------------------------------------------------]
419 } // em5
420 
421 
422 //[-------------------------------------------------------]
423 //[ Implementation ]
424 //[-------------------------------------------------------]
CameraType
Definition: Player.h:67
Definition: ActionPriority.h:13
Job proxy class.
Definition: JobProxy.h:51
std::string mInfoText
Definition: Player.h:79
Entity class.
Definition: Entity.h:46
std::vector< const BuyOption * > BuyOptionPointerArray
Definition: Player.h:88
Map class.
Definition: Map.h:93
Color class with red, green, blue and alpha component.
Definition: Color4.h:39
unsigned int uint32
Definition: PlatformTypes.h:181
Definition: Player.h:92
EMERGENCY 5 in-game camera input handler class.
Definition: IngameCameraInputHandler.h:51
Clock class.
Definition: Clock.h:33
#define EM5_API_EXPORT
Definition: Export.h:28
Class representing a 3D ray, defined by an origin point and a (usually normalized) direction...
Definition: Ray.h:32
Camera component class.
Definition: CameraComponent.h:50
Free movement input handler class.
Definition: FreeMoveInputHandler.h:52
EMERGENCY 5 player class.
Definition: Player.h:57
Job arguments class: holds data to be passed to the called job method by the job manager.
Definition: JobArguments.h:40
Definition: Player.h:75
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
3D transform class
Definition: Transform.h:45
Definition: PickupPersonByParamedicAction.h:21
Debug draw proxy class.
Definition: DebugDrawProxy.h:46
std::string mUnitName
Definition: Player.h:77
Keeps track of ordered units from the player and manages the ordering process for new units Spawning ...
Definition: UnitPool.h:55
std::string mUpgrade
Definition: Player.h:80
signed int int32
Definition: PlatformTypes.h:180
bool mIsPromotion
Definition: Player.h:84
Edition
Definition: VersionSwitch.h:41
unsigned short uint16
Definition: PlatformTypes.h:178
DebugFlag
Definition: Player.h:90
std::string mIconName
Definition: Player.h:81
std::string mAdditionalEventPools
Definition: Player.h:78
BuyOption()
Definition: Player.h:86
qsf::EnumBitmask< uint8, DebugFlag > DebugFlagSet
Definition: Player.h:95
uint32 mCost
Definition: Player.h:82
bool mIsBought
Definition: Player.h:83
Binary serializer class.
Definition: BinarySerializer.h:35
std::vector< uint64 > EntityIdArray
Definition: Player.h:97
static const uint32 MAIN_CAMERA_INPUT_HANDLER_ID
Definition: Player.h:65