afxMagicMissile.h
Engine/source/afx/afxMagicMissile.h
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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames 26// Copyright (C) 2015 Faust Logic, Inc. 27// 28// afxMagicMissile is a heavily modified variation of the stock Projectile class. In 29// addition to numerous AFX customizations, it also incorporates functionality based on 30// the following TGE resources: 31// 32// Guided or Seeker Projectiles by Derk Adams 33// http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6778 34// 35// Projectile Ballistic Coefficients (drag factors) by Mark Owen 36// http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5128 37// 38//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 39 40#ifndef _AFX_MAGIC_MISSILE_H_ 41#define _AFX_MAGIC_MISSILE_H_ 42 43//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 44 45#include "T3D/lightDescription.h" 46#include "T3D/fx/particleEmitter.h" 47 48#include "afx/afxConstraint.h" 49 50class SplashData; 51class ShapeBase; 52class TSShapeInstance; 53class PhysicsWorld; 54class SFXTrack; 55class SFXSource; 56 57//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 58// afxMagicMissileData 59 60class afxMagicMissileData : public GameBaseData 61{ 62 typedef GameBaseData Parent; 63 64protected: 65 bool onAdd(); 66 67public: 68 enum { MaxLifetimeTicks = 4095 }; 69 70public: 71 // variables set in datablock definition: 72 // Shape related 73 StringTableEntry projectileShapeName; 74 75 //bool hasLight; 76 //F32 lightRadius; 77 //LinearColorF lightColor; 78 79 //bool hasWaterLight; 80 //LinearColorF waterLightColor; 81 82 /* 83 /// Set to true if it is a billboard and want it to always face the viewer, false otherwise 84 bool faceViewer; 85 */ 86 Point3F scale; 87 88 /* 89 /// [0,1] scale of how much velocity should be inherited from the parent object 90 F32 velInheritFactor; 91 /// Speed of the projectile when fired 92 */ 93 F32 muzzleVelocity; 94 95 /// Should it arc? 96 bool isBallistic; 97 98 /* 99 /// How HIGH should it bounce (parallel to normal), [0,1] 100 F32 bounceElasticity; 101 /// How much momentum should be lost when it bounces (perpendicular to normal), [0,1] 102 F32 bounceFriction; 103 */ 104 105 /// Should this projectile fall/rise different than a default object? 106 F32 gravityMod; 107 108 /// How long the projectile should exist before deleting itself 109 U32 lifetime; // ticks 110 /* 111 /// How long it should not detonate on impact 112 S32 armingDelay; // the values are converted on initialization with 113 */ 114 S32 fadeDelay; // ticks 115 116 /* 117 ExplosionData* explosion; // Explosion Datablock 118 S32 explosionId; // Explosion ID 119 ExplosionData* waterExplosion; // Water Explosion Datablock 120 S32 waterExplosionId; // Water Explosion ID 121 */ 122 123 SplashData* splash; // Water Splash Datablock 124 S32 splashId; // Water splash ID 125 126 SFXTrack* sound; // Projectile Sound 127 128 LightDescription *lightDesc; 129 S32 lightDescId; 130 131 /* 132 enum DecalConstants { // Number of decals constant 133 NumDecals = 6, 134 }; 135 DecalData* decals[NumDecals]; // Decal Datablocks 136 S32 decalId[NumDecals]; // Decal IDs 137 U32 decalCount; // # of loaded Decal Datablocks 138 */ 139 140 // variables set on preload: 141 Resource<TSShape> projectileShape; 142 /* 143 S32 activateSeq; 144 S32 maintainSeq; 145 */ 146 147 ParticleEmitterData* particleEmitter; 148 S32 particleEmitterId; 149 ParticleEmitterData* particleWaterEmitter; 150 S32 particleWaterEmitterId; 151 152 U32 collision_mask; 153 154 Point3F starting_vel_vec; 155 156 // guidance behavior 157 bool isGuided; 158 F32 precision; 159 S32 trackDelay; 160 161 // simple physics 162 F32 ballisticCoefficient; 163 164 // terrain following 165 bool followTerrain; 166 F32 followTerrainHeight; 167 F32 followTerrainAdjustRate; 168 S32 followTerrainAdjustDelay; 169 170 F32 acceleration; 171 S32 accelDelay; 172 U32 accelLifetime; 173 174 StringTableEntry launch_node; 175 Point3F launch_offset; 176 Point3F launch_offset_server; 177 Point3F launch_offset_client; 178 Point3F launch_node_offset; 179 F32 launch_pitch; 180 F32 launch_pan; 181 bool echo_launch_offset; 182 183 StringTableEntry launch_cons_s_spec; 184 afxConstraintDef launch_cons_s_def; 185 StringTableEntry launch_cons_c_spec; 186 afxConstraintDef launch_cons_c_def; 187 188 // wiggle behavior 189 Vector<F32> wiggle_magnitudes; 190 Vector<F32> wiggle_speeds; 191 StringTableEntry wiggle_axis_string; 192 Point3F* wiggle_axis; 193 U32 wiggle_num_axis; 194 195 // hover behavior 196 F32 hover_altitude; 197 F32 hover_attack_distance; 198 F32 hover_attack_gradient; 199 U32 hover_time; 200 201 bool reverse_targeting; 202 203 U32 caster_safety_time; 204 205public: 206 /*C*/ afxMagicMissileData(); 207 /*D*/ ~afxMagicMissileData(); 208 209 void packData(BitStream*); 210 void unpackData(BitStream*); 211 212 bool preload(bool server, String &errorStr); 213 214 static void initPersistFields(); 215 216 DECLARE_CONOBJECT(afxMagicMissileData); 217 DECLARE_CATEGORY("AFX"); 218 219public: 220 /*C*/ afxMagicMissileData(const afxMagicMissileData&, bool = false); 221 222 afxMagicMissileData* cloneAndPerformSubstitutions(const SimObject*, S32 index=0); 223 virtual bool allowSubstitutions() const { return true; } 224 void gather_cons_defs(Vector<afxConstraintDef>& defs); 225}; 226 227//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 228// afxMagicMissile 229 230//class afxMagicSpell; 231class afxChoreographer; 232 233class afxMagicMissile : public GameBase, public ISceneLight 234{ 235 typedef GameBase Parent; 236 237public: 238 /* 239 // Initial conditions 240 enum ProjectileConstants { 241 SourceIdTimeoutTicks = 7, // = 231 ms 242 DeleteWaitTime = 500, ///< 500 ms delete timeout (for network transmission delays) 243 ExcessVelDirBits = 7, 244 MaxLivingTicks = 4095, 245 }; 246 */ 247 enum UpdateMasks { 248 /* 249 BounceMask = Parent::NextFreeMask, 250 ExplosionMask = Parent::NextFreeMask << 1, 251 */ 252 GuideMask = Parent::NextFreeMask << 0, 253 LaunchMask = Parent::NextFreeMask << 1, 254 ImpactMask = Parent::NextFreeMask << 2, 255 NextFreeMask = Parent::NextFreeMask << 3 256 }; 257protected: 258 PhysicsWorld *mPhysicsWorld; 259 260 afxMagicMissileData* mDataBlock; 261 262 ParticleEmitter* mParticleEmitter; 263 ParticleEmitter* mParticleWaterEmitter; 264 SFXSource* mSound; 265 266 Point3F mCurrPosition; 267 Point3F mCurrVelocity; 268 /* 269 S32 mSourceObjectId; 270 S32 mSourceObjectSlot; 271 */ 272 273 // Time related variables common to all projectiles, managed by processTick 274 275 U32 mCurrTick; ///< Current time in ticks 276 /* 277 SimObjectPtr<ShapeBase> mSourceObject; ///< Actual pointer to the source object, times out after SourceIdTimeoutTicks 278 */ 279 280 // Rendering related variables 281 TSShapeInstance* mProjectileShape; 282 /* 283 TSThread* mActivateThread; 284 TSThread* mMaintainThread; 285 286 Point3F mLastRenderPos; 287 */ 288 289 // ISceneLight 290 virtual void submitLights( LightManager *lm, bool staticLighting ); 291 virtual LightInfo* getLight() { return mLight; } 292 293 LightInfo *mLight; 294 LightState mLightState; 295 296 /* 297 bool mHidden; ///< set by the derived class, if true, projectile doesn't render 298 F32 mFadeValue; ///< set in processTick, interpolation between fadeDelay and lifetime 299 ///< in data block 300 */ 301 302 /* 303 // Warping and back delta variables. Only valid on the client 304 // 305 Point3F mWarpStart; 306 Point3F mWarpEnd; 307 U32 mWarpTicksRemaining; 308 */ 309 310 Point3F mCurrDeltaBase; 311 Point3F mCurrBackDelta; 312 313 /* 314 Point3F mExplosionPosition; 315 Point3F mExplosionNormal; 316 U32 mCollideHitType; 317 */ 318 319 bool onAdd(); 320 void onRemove(); 321 bool onNewDataBlock(GameBaseData *dptr, bool reload); 322 323 // Rendering 324 virtual void prepRenderImage(SceneRenderState*); 325 void prepBatchRender( SceneRenderState *state); 326 327 void processTick(const Move *move); 328 /* 329 void advanceTime(F32 dt); 330 */ 331 void interpolateTick(F32 delta); 332 333 /* 334 /// What to do once this projectile collides with something 335 virtual void onCollision(const Point3F& p, const Point3F& n, SceneObject*); 336 337 /// What to do when this projectile explodes 338 virtual void explode(const Point3F& p, const Point3F& n, const U32 collideType ); 339 340 /// Returns the velocity of the projectile 341 Point3F getVelocity() const; 342 */ 343 344 void emitParticles(const Point3F&, const Point3F&, const Point3F&, const U32); 345 void updateSound(); 346 347 // Rendering 348 /* 349 void prepModelView ( SceneRenderState *state); 350 */ 351 352 // These are stolen from the player class .. 353 bool pointInWater(const Point3F &point); 354 355 U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream); 356 void unpackUpdate(NetConnection *conn, BitStream *stream); 357 358 afxChoreographer* choreographer; 359 360 bool client_only; 361 bool server_only; 362 bool use_accel; 363 U32 collision_mask; 364 F32 prec_inc; 365 366 bool did_launch; 367 bool did_impact; 368 369 SceneObject* missile_target; 370 SceneObject* collide_exempt; 371 372 bool hover_attack_go; 373 U32 hover_attack_tick; 374 375 F32 starting_velocity; 376 Point3F starting_vel_vec; 377 378 SimObject* ss_object; 379 S32 ss_index; 380 381private: 382 void init(bool on_server, bool on_client); 383 void create_splash(const Point3F& pos); 384 SceneObject* get_default_launcher() const; 385 void get_launch_constraint_data(Point3F& pos, Point3F& vel); 386 void get_launch_data(Point3F& pos, Point3F& vel); 387 bool is_active() const { return (did_launch && !did_impact); } 388 389public: 390 /* 391 F32 getUpdatePriority(CameraScopeQuery *focusObject, U32 updateMask, S32 updateSkips); 392 */ 393 /*C*/ afxMagicMissile(); 394 /*C*/ afxMagicMissile(bool on_server, bool on_client); 395 /*D*/ ~afxMagicMissile(); 396 virtual void onDeleteNotify(SimObject*); 397 398 DECLARE_CONOBJECT(afxMagicMissile); 399 DECLARE_CATEGORY("AFX"); 400 401 static void initPersistFields(); 402 403 /* 404 virtual bool calculateImpact(float simTime, 405 Point3F& pointOfImpact, 406 float& impactTime); 407 408 static U32 smProjectileWarpTicks; 409 410protected: 411 static const U32 csmStaticCollisionMask; 412 static const U32 csmDynamicCollisionMask; 413 static const U32 csmDamageableMask; 414 */ 415 416 void launch(); 417 void setChoreographer(afxChoreographer*); 418 void setStartingVelocityVector(const Point3F& vel_vec); 419 void setStartingVelocity(const F32 vel); 420 void getStartingVelocityValues(F32& vel, Point3F& vel_vec); 421 void setSubstitutionData(SimObject* obj, S32 idx=0) { ss_object = obj; ss_index = idx; } 422}; 423 424//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 425// afxMagicMissileCallback 426 427class afxMagicMissileCallback 428{ 429public: 430 virtual void impactNotify(const Point3F& p, const Point3F& n, SceneObject*)=0; 431}; 432 433//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~// 434 435#endif // _AFX_MAGIC_MISSILE_H_ 436 437