Emergency 20 Dokumentation  4.2.0
VehicleCraneComponent.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 //[-------------------------------------------------------]
13 #include "em5/audio/AudioProxy.h"
14 
15 #include <qsf/job/JobProxy.h>
19 
20 
21 //[-------------------------------------------------------]
22 //[ Forward declarations ]
23 //[-------------------------------------------------------]
24 namespace qsf
25 {
26  class TransformComponent;
27  class LinkComponent;
28  class MeshAnimationChannel;
29  class MeshAnimationComponent;
30  namespace game
31  {
32  class BoneToBoneLinkComponent;
33  }
34 }
35 
36 
37 //[-------------------------------------------------------]
38 //[ Namespace ]
39 //[-------------------------------------------------------]
40 namespace em5
41 {
42 
43 
44  //[-------------------------------------------------------]
45  //[ Classes ]
46  //[-------------------------------------------------------]
52  {
53 
54 
55  //[-------------------------------------------------------]
56  //[ Public definitions ]
57  //[-------------------------------------------------------]
58  public:
59  static const uint32 COMPONENT_ID;
60  static const float YAW_EPSILON;
61  static const float ANIMATION_EPSILON;
62  static const float HOOK_DISTANCE_EPSILON;
63 
65  {
66  PAUSE = 0,
74  PITCH_AND_COCKPIT_MOVEMENT
75  };
76 
77  enum CraneType
78  {
81  HEAVY_CRANE
82  };
83 
85  {
92  STATE_STOP_ALL_ANIMATION
93  };
94 
96  {
105  SEQUENCE_LOAD_BOAT_LOAD_CARGO_ARM
106  };
107 
108 
109  //[-------------------------------------------------------]
110  //[ Public methods ]
111  //[-------------------------------------------------------]
112  public:
120  inline explicit VehicleCraneComponent(qsf::Prototype* prototype);
121 
126  inline virtual ~VehicleCraneComponent();
127 
135  bool checkTargetPosition(const glm::vec3& targetPosition, glm::vec3& correctionOffset);
136 
144  void alignArm(const glm::vec3& position);
145 
150  void foldArm();
151 
156  void loadCargoArm();
157 
167  void hookMove(const glm::vec3& targetPosition, float distancePercentage);
168 
176  void hookMoveBack(float distancePercentage = 0.0f);
177 
182  bool isAnimationPlaying() const;
183 
184  inline SequenceType getSequenceType() const;
185 
190  void setSequenceType(SequenceType type);
191 
196  void deleteSequence();
197 
202  void stopAllAnimation();
203 
208  void setVisibleStrap(bool visible);
209 
217  void linkTargetToHook(qsf::Entity& targetEntity);
218  void unlinkTargetFromHook();
219 
224  qsf::Entity* getHookEntity() const;
225 
230  glm::vec3 worldSpacePositionWithLocalOffset(const qsf::TransformComponent& transformComponent, const glm::vec3& localoffset);
231 
236  inline uint64 getCraneEntityId() const;
237  void setCraneEntityId(uint64 craneEntityId);
238 
243  inline float getMinLength() const;
244  inline void setMinLength(float minLength);
245 
246  inline float getMaxLength() const;
247  inline void setMaxLength(float maxLength);
248 
249  inline float getMinAngle() const;
250  inline void setMinAngle(float minAngle);
251 
252  inline float getMaxAngle() const;
253  inline void setMaxAngle(float maxAngle);
254 
255  inline float getCraneHeight() const;
256  inline void setCraneHeight(float craneHeight);
257 
258  inline float getArmRotateSpeed() const;
259  inline void setArmRotateSpeed(float armRotateSpeed);
260 
261  inline float getExtendSpeed() const;
262  inline void setExtendSpeed(float extendSpeed);
263 
264  inline float getLowToHighSpeed() const;
265  inline void setLowToHighSpeed(float lowToHighSpeed);
266 
267  inline float getHookSpeed() const;
268  inline void setHookSpeed(float hookSpeed);
269 
270  inline float getCockpitSpeed() const;
271  inline void setCockpitSpeed(float cockpitSpeed);
272 
273  inline float getTimeUltimatum() const;
274  inline void setTimeUltimatum(float timeUltimatum);
275 
276  inline CraneType getCraneType() const;
277  inline void setCraneType(CraneType craneType);
278 
279  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(AnimationCraneExtend, const qsf::AssetProxy&, mAnimationCraneExtend)
280  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(AnimationCraneLowToHigh, const qsf::AssetProxy&, mAnimationCraneLowToHigh)
281  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(AnimationCraneCockpit, const qsf::AssetProxy&, mAnimationCraneCockpit)
282  QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(AnimationCraneHook, const qsf::AssetProxy&, mAnimationCraneHook)
283 
284  inline AnimationState getLastAnimationState() const;
285  inline const glm::vec3& getTargetPosition() const;
286  inline bool isStrapVisible() const;
287  inline float getHookMoveDistancePercentage() const;
288  inline uint64 getEntityIdLinkedToHook() const;
289 
290 
291  //[-------------------------------------------------------]
292  //[ Public virtual qsf::Component methods ]
293  //[-------------------------------------------------------]
294  public:
295  virtual void serialize(qsf::BinarySerializer& serializer) override;
296 
297 
298  //[-------------------------------------------------------]
299  //[ Protected virtual qsf::Component methods ]
300  //[-------------------------------------------------------]
301  protected:
302  virtual void onShutdown() override;
303 
304 
305  //[-------------------------------------------------------]
306  //[ Private methods ]
307  //[-------------------------------------------------------]
308  private:
309  void startAnimation();
310  void clearAnimation();
311  void startHookAnimation();
312 
313  bool getComponentPointers();
314  bool isNotAligned();
315  void calculateAngleAndOffsets();
316  void alignStage();
317  bool getHookDummy();
318  bool isHookMoving();
319 
320  void updateAnimation(const qsf::JobArguments& jobArguments);
321  void updateHookAnimation(const qsf::JobArguments& jobArguments);
322 
323  qsf::AssetProxy getAnimationToUseForCraneExtend() const;
324  qsf::AssetProxy getAnimationToUseForCraneLowToHigh() const;
325  qsf::AssetProxy getAnimationToUseForCraneCockpit() const;
326  qsf::AssetProxy getAnimationToUseForCraneHook() const;
327 
328  qsf::Entity* getFirstChildEntity(qsf::Entity* entity) const;
329  qsf::Entity* getFirstChildEntityWithTag(qsf::Entity* entity, const std::string& tag) const;
330 
331 
332  //[-------------------------------------------------------]
333  //[ Private data ]
334  //[-------------------------------------------------------]
335  private:
336  uint64 mCraneEntityId;
337  glm::vec3 mTargetPosition;
338  float mDistancePercentage;
339  qsf::Time mTimePassed;
340  qsf::Time mPauseTimePassed;
341  qsf::Time mPauseTime;
342  std::vector<PivotMovement> mSequence;
343  std::vector<PivotMovement>::size_type mSequenceState;
344  SequenceType mSequenceType;
345  AnimationState mLastAnimationState;
346  bool mStrapVisible;
347  uint64 mEntityIdLinkedToHook;
348 
349  // Temporary used component pointers, use after getComponentPointers was called
350  qsf::Entity* mCraneEntity;
351  qsf::Entity* mJibEntity;
352  qsf::Entity* mCockpitEntity;
353  qsf::Entity* mHookDummy;
354  qsf::TransformComponent* mCraneTransformComponent;
355  qsf::LinkComponent* mCraneLinkComponent;
356  qsf::MeshAnimationComponent* mCraneMeshAnimationComponent;
357  qsf::MeshAnimationComponent* mJibMeshAnimationComponent;
358  qsf::MeshAnimationComponent* mCockpitMeshAnimationComponent;
359  qsf::game::BoneToBoneLinkComponent* mStageBoneToBoneLinkComponent;
360 
361  qsf::MeshAnimationChannel* mExtendAnimationChannel;
362  qsf::MeshAnimationChannel* mLowToHighAnimationChannel;
363  qsf::MeshAnimationChannel* mCockpitAnimationChannel;
364 
365  // Temporarily used variables, use after getComponentPointers was called
366  float mRotateYawAngle;
367  float mExtendAnimationOffset;
368  float mLowToHighAnimationOffset;
369  float mCockpitAnimationOffset;
370  float mDistance;
371  glm::vec3 mHookMoveTargetPosition;
372  glm::vec3 mHookPosition;
373  qsf::Time mCockpitWaitTime;
374 
375  // Job proxies and audio proxies
376  qsf::JobProxy mAnimationJobProxy;
377  qsf::JobProxy mHookAnimationJobProxy;
378  AudioProxy mAudioProxy;
379  AudioProxy mHookAudioProxy;
380  AudioProxy mCockpitAudioProxy;
381 
382  // Exported to CAMP
383  float mMinLength;
384  float mMaxLength;
385  float mMinAngle;
386  float mMaxAngle;
387  float mCraneHeight;
388  float mArmRotateSpeed;
389  float mExtendSpeed;
390  float mLowToHighSpeed;
391  float mHookSpeed;
392  float mCockpitSpeed;
393  float mTimeUltimatum;
394  CraneType mCraneType;
395 
396  qsf::AssetProxy mAnimationCraneExtend;
397  qsf::AssetProxy mAnimationCraneLowToHigh;
398  qsf::AssetProxy mAnimationCraneCockpit;
399  qsf::AssetProxy mAnimationCraneHook;
400 
401 
402  //[-------------------------------------------------------]
403  //[ CAMP reflection system ]
404  //[-------------------------------------------------------]
405  QSF_CAMP_RTTI() // Only adds the virtual method "campClassId()", nothing more
406 
407 
408  };
409 
410 
411 //[-------------------------------------------------------]
412 //[ Namespace ]
413 //[-------------------------------------------------------]
414 } // em5
415 
416 
417 //[-------------------------------------------------------]
418 //[ Implementation ]
419 //[-------------------------------------------------------]
420 #include "em5/component/vehicle/parts/VehicleCraneComponent-inl.h"
421 
422 
423 //[-------------------------------------------------------]
424 //[ CAMP reflection system ]
425 //[-------------------------------------------------------]
Definition: VehicleCraneComponent.h:71
Definition: ActionPriority.h:13
Definition: VehicleCraneComponent.h:86
Abstract component class.
Definition: Component.h:105
Entity class.
Definition: Entity.h:46
Definition: VehicleCraneComponent.h:91
Definition: VehicleCraneComponent.h:104
Definition: VehicleCraneComponent.h:68
unsigned int uint32
Definition: PlatformTypes.h:181
Transform component class.
Definition: TransformComponent.h:33
Definition: VehicleCraneComponent.h:72
SequenceType
Definition: VehicleCraneComponent.h:95
#define EM5_API_EXPORT
Definition: Export.h:28
static const float YAW_EPSILON
Epsilon to check if yaw orientation can be assumed equal.
Definition: VehicleCraneComponent.h:60
Definition: AreaConfiguration.h:58
EMERGENCY 5 vehicle crane component class.
Definition: VehicleCraneComponent.h:51
Definition: VehicleCraneComponent.h:102
Definition: VehicleCraneComponent.h:69
uint64_t uint64
Definition: PlatformTypes.h:184
CraneType
Definition: VehicleCraneComponent.h:77
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
Definition: VehicleCraneComponent.h:80
Definition: PickupPersonByParamedicAction.h:21
Definition: VehicleCraneComponent.h:89
Definition: VehicleCraneComponent.h:103
PivotMovement
Definition: VehicleCraneComponent.h:64
Asset proxy class.
Definition: AssetProxy.h:57
#define QSF_CAMP_RTTI()
Only adds the virtual method "campClassId()", nothing more.
Definition: CampClass.h:75
Extended audio proxy for easier multiplay usage.
Definition: AudioProxy.h:47
static const uint32 COMPONENT_ID
"em5::VehicleCraneComponent" unique component ID
Definition: VehicleCraneComponent.h:59
#define QSF_CAMP_TYPE_NONCOPYABLE(type)
See "CAMP_TYPE_NONCOPYABLE" for details.
Definition: CampClass.h:112
Definition: VehicleCraneComponent.h:88
static const float HOOK_DISTANCE_EPSILON
Epsilon to check if hook movement distance can be assumed equal.
Definition: VehicleCraneComponent.h:62
Definition: VehicleCraneComponent.h:70
AnimationState
Definition: VehicleCraneComponent.h:84
AnimationState
Definition: IngameMainEventSuccessWindow.h:26
Definition: VehicleCraneComponent.h:97
#define QSF_DEFINE_SIMPLE_GETTER_AND_SETTER(name, type, variable)
Definition: PropertyHelper.h:16
Prototype class.
Definition: Prototype.h:100
Definition: VehicleCraneComponent.h:79
Definition: VehicleCraneComponent.h:73
Definition: VehicleCraneComponent.h:90
Definition: VehicleCraneComponent.h:87
static const float ANIMATION_EPSILON
Epsilon to check if animation offset can be assumed equal.
Definition: VehicleCraneComponent.h:61
Definition: VehicleCraneComponent.h:67