hoverVehicle.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _HOVERVEHICLE_H_
  23. #define _HOVERVEHICLE_H_
  24. #ifndef _VEHICLE_H_
  25. #include "T3D/vehicles/vehicle.h"
  26. #endif
  27. class ParticleEmitter;
  28. class ParticleEmitterData;
  29. // -------------------------------------------------------------------------
  30. class HoverVehicleData : public VehicleData
  31. {
  32. typedef VehicleData Parent;
  33. protected:
  34. bool onAdd() override;
  35. //-------------------------------------- Console set variables
  36. public:
  37. enum Sounds {
  38. JetSound,
  39. EngineSound,
  40. FloatSound,
  41. MaxSounds
  42. };
  43. DECLARE_SOUNDASSET_ARRAY(HoverVehicleData, HoverSounds, Sounds::MaxSounds);
  44. enum Jets {
  45. // These enums index into a static name list.
  46. ForwardJetEmitter, // Thrust forward
  47. BackwardJetEmitter, // Thrust backward
  48. DownwardJetEmitter, // Thrust down
  49. MaxJetEmitters,
  50. };
  51. ParticleEmitterData* jetEmitter[MaxJetEmitters];
  52. enum JetNodes {
  53. // These enums index into a static name list.
  54. ForwardJetNode,
  55. ForwardJetNode1,
  56. BackwardJetNode,
  57. BackwardJetNode1,
  58. DownwardJetNode,
  59. DownwardJetNode1,
  60. //
  61. MaxJetNodes,
  62. MaxDirectionJets = 2,
  63. ThrustJetStart = ForwardJetNode,
  64. MaxTrails = 4,
  65. };
  66. static const char *sJetNode[MaxJetNodes];
  67. S32 jetNode[MaxJetNodes];
  68. F32 floatingThrustFactor;
  69. F32 mainThrustForce;
  70. F32 reverseThrustForce;
  71. F32 strafeThrustForce;
  72. F32 turboFactor;
  73. F32 stabLenMin;
  74. F32 stabLenMax;
  75. F32 stabSpringConstant;
  76. F32 stabDampingConstant;
  77. F32 gyroDrag;
  78. F32 normalForce;
  79. F32 restorativeForce;
  80. F32 steeringForce;
  81. F32 rollForce;
  82. F32 pitchForce;
  83. F32 floatingGravMag;
  84. F32 brakingForce;
  85. F32 brakingActivationSpeed;
  86. ParticleEmitterData * dustTrailEmitter;
  87. S32 dustTrailID;
  88. Point3F dustTrailOffset;
  89. F32 triggerTrailHeight;
  90. F32 dustTrailFreqMod;
  91. //-------------------------------------- load set variables
  92. public:
  93. F32 maxThrustSpeed;
  94. public:
  95. HoverVehicleData();
  96. ~HoverVehicleData();
  97. void packData(BitStream*) override;
  98. void unpackData(BitStream*) override;
  99. bool preload(bool server, String &errorStr) override;
  100. DECLARE_CONOBJECT(HoverVehicleData);
  101. static void initPersistFields();
  102. };
  103. // -------------------------------------------------------------------------
  104. class HoverVehicle : public Vehicle
  105. {
  106. typedef Vehicle Parent;
  107. private:
  108. HoverVehicleData* mDataBlock;
  109. SimObjectPtr<ParticleEmitter> mDustTrailEmitter;
  110. protected:
  111. bool onAdd() override;
  112. void onRemove() override;
  113. bool onNewDataBlock(GameBaseData *dptr,bool reload) override;
  114. void updateDustTrail( F32 dt );
  115. // Vehicle overrides
  116. protected:
  117. void updateMove(const Move *move) override;
  118. // Physics
  119. protected:
  120. void updateForces(F32) override;
  121. F32 getBaseStabilizerLength() const;
  122. bool mFloating;
  123. F32 mThrustLevel;
  124. F32 mForwardThrust;
  125. F32 mReverseThrust;
  126. F32 mLeftThrust;
  127. F32 mRightThrust;
  128. SFXSource* mJetSound;
  129. SFXSource* mEngineSound;
  130. SFXSource* mFloatSound;
  131. enum ThrustDirection {
  132. // Enums index into sJetActivationTable
  133. ThrustForward,
  134. ThrustBackward,
  135. ThrustDown,
  136. NumThrustDirections,
  137. NumThrustBits = 3
  138. };
  139. ThrustDirection mThrustDirection;
  140. // Jet Threads
  141. enum Jets {
  142. // These enums index into a static name list.
  143. BackActivate,
  144. BackMaintain,
  145. JetAnimCount
  146. };
  147. static const char* sJetSequence[HoverVehicle::JetAnimCount];
  148. TSThread* mJetThread[JetAnimCount];
  149. S32 mJetSeq[JetAnimCount];
  150. bool mBackMaintainOn;
  151. // Jet Particles
  152. struct JetActivation {
  153. // Convert thrust direction into nodes & emitters
  154. S32 node;
  155. S32 emitter;
  156. };
  157. static JetActivation sJetActivation[NumThrustDirections];
  158. SimObjectPtr<ParticleEmitter> mJetEmitter[HoverVehicleData::MaxJetNodes];
  159. U32 getCollisionMask() override;
  160. void updateJet(F32 dt);
  161. void updateEmitter(bool active,F32 dt,ParticleEmitterData *emitter,S32 idx,S32 count);
  162. public:
  163. HoverVehicle();
  164. ~HoverVehicle();
  165. // Time/Move Management
  166. public:
  167. void advanceTime(F32 dt) override;
  168. DECLARE_CONOBJECT(HoverVehicle);
  169. DECLARE_CATEGORY("Actor \t Controllable");
  170. // static void initPersistFields();
  171. U32 packUpdate (NetConnection *conn, U32 mask, BitStream *stream) override;
  172. void unpackUpdate(NetConnection *conn, BitStream *stream) override;
  173. };
  174. #endif // _H_HOVERVEHICLE