hoverVehicle.h

Engine/source/T3D/vehicles/hoverVehicle.h

More...

Classes:

Detailed Description

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