home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / game / Projectile.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  9KB  |  342 lines

  1. // RAVEN BEGIN
  2. // bdube: note that this file is no longer merged with Doom3 updates
  3. //
  4. // MERGE_DATE 09/30/2004
  5.  
  6. #ifndef __GAME_PROJECTILE_H__
  7. #define __GAME_PROJECTILE_H__
  8.  
  9. /*
  10. ===============================================================================
  11.  
  12.   idProjectile
  13.     
  14. ===============================================================================
  15. */
  16.  
  17. extern const idEventDef EV_Explode;
  18.  
  19. class idProjectile : public idEntity {
  20. public :
  21.     CLASS_PROTOTYPE( idProjectile );
  22.  
  23.                             idProjectile();
  24.     virtual                    ~idProjectile();
  25.  
  26.     void                    Spawn( void );
  27.  
  28.     void                    Save( idSaveGame *savefile ) const;
  29.     void                    Restore( idRestoreGame *savefile );
  30.  
  31.     void                    Create( idEntity *owner, const idVec3 &start, const idVec3 &dir, idEntity* ignore = NULL, idEntity* extraPassEntity = NULL );
  32.     virtual void            Launch( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity, const float timeSinceFire = 0.0f, const float dmgPower = 1.0f );
  33.  
  34.     virtual void            FreeLightDef( void );
  35.  
  36.     idEntity *                GetOwner( void ) const;
  37.  
  38.     virtual void            Think( void );
  39.     virtual void            Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  40.     virtual bool            GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
  41.  
  42.     virtual bool            Collide( const trace_t &collision, const idVec3 &velocity );
  43.     virtual void            Explode( const trace_t *collision, const bool showExplodeFX, idEntity *ignore = NULL, const char *sndExplode = "snd_explode" );
  44.     void                    Fizzle( void );
  45.  
  46.     static idVec3            GetVelocity( const idDict *projectile );
  47.     static idVec3            GetGravity( const idDict *projectile );
  48.  
  49.     void                    SetSpeed        ( float s, int accelTime = 0 );
  50.     float                    GetSpeed        ( void ) const;
  51.  
  52.     virtual void            UpdateVisualAngles();
  53.  
  54.     // information about what kind of projectile we are, used for death messages
  55.     int                        methodOfDeath;
  56.  
  57.     virtual void            ClientPredictionThink( void );
  58.     virtual void            WriteToSnapshot( idBitMsgDelta &msg ) const;
  59.     virtual void            ReadFromSnapshot( const idBitMsgDelta &msg );
  60.  
  61.     virtual bool            ClientStale( void );
  62.     
  63. protected:
  64.  
  65.     idEntityPtr<idEntity>    owner;
  66.  
  67.     struct projectileFlags_s {
  68.         bool                detonate_on_world            : 1;
  69.         bool                detonate_on_actor            : 1;
  70.         bool                detonate_on_bounce            : 1;        // Detonate if hit a bounce surface
  71.         bool                randomShaderSpin            : 1;
  72.         bool                isTracer                    : 1;
  73.     } projectileFlags;
  74.  
  75.     float                    damagePower;
  76.  
  77.     renderLight_t            renderLight;
  78.     qhandle_t                lightDefHandle;                // handle to renderer light def
  79.     idVec3                    lightOffset;
  80.     int                        lightStartTime;
  81.     int                        lightEndTime;
  82.     idVec3                    lightColor;
  83.  
  84.     rvPhysics_Particle        physicsObj;
  85.     idAngles                visualAngles;
  86.     idAngles                angularVelocity;
  87.     idInterpolate<float>    speed;
  88.     bool                    updateVelocity;
  89.  
  90.     rvSphericalInterpolate    rotation;
  91.  
  92.     rvClientEffectPtr        flyEffect;
  93.     float                    flyEffectAttenuateSpeed;
  94.  
  95.     int                        bounceCount;
  96. // RAVEN BEGIN
  97. // ddynerman: hit count for stats
  98.     int                        hitCount;
  99. // ddynerman: pre-prediction ( rocket jumping )
  100.     int                        prePredictTime;
  101. // RAVEN END
  102.     typedef enum {
  103.         SPAWNED = 0,
  104.         CREATED = 1,
  105.         LAUNCHED = 2,
  106.         FIZZLED = 3,
  107.         EXPLODED = 4
  108.     } projectileState_t;
  109.     
  110.     projectileState_t        state;
  111.  
  112.     void                    PlayPainEffect        ( idEntity* ent, int damage, const rvDeclMatType* materialType, const idVec3& origin, const idVec3& direction );
  113.     virtual void            PlayDetonateEffect    ( const idVec3& origin, const idMat3& axis );
  114.  
  115. private:
  116.     void                    DefaultDamageEffect    ( const trace_t &collision, const idVec3 &velocity, const char *damageDefName );
  117.  
  118.     void                    Event_Explode            ( void );
  119.     void                    Event_Fizzle            ( void );
  120.     void                    Event_RadiusDamage        ( idEntity *ignore );
  121.     void                    Event_ResidualDamage    ( idEntity *ignore );
  122.     void                    Event_Touch                ( idEntity *other, trace_t *trace );
  123.  
  124.     bool                    syncPhysics;
  125.  
  126.     // cheap linear client side projectiles
  127.     // transmitted in snapshot
  128.     int                        launchTime;
  129.     idVec3                    launchOrig;
  130.     idVec3                    launchDir;
  131.     // set from def file in :Launch on both client and server
  132.     float                    launchSpeed;
  133. };
  134.  
  135. ID_INLINE float idProjectile::GetSpeed ( void ) const {
  136.     return speed.GetCurrentValue( gameLocal.time );
  137. }
  138.  
  139. /*
  140. ===============================================================================
  141.  
  142. idGuidedProjectile
  143.  
  144. ===============================================================================
  145. */
  146.  
  147. extern const idEventDef EV_UpdateGuideTarget;
  148. extern const idEventDef EV_GuideToEntity;
  149. extern const idEventDef EV_GuideToPos;
  150.  
  151. class idGuidedProjectile : public idProjectile {
  152. public :
  153.     CLASS_PROTOTYPE( idGuidedProjectile );
  154.  
  155.                             idGuidedProjectile( void );
  156.                             ~idGuidedProjectile( void );
  157.  
  158.     enum {
  159.         GUIDE_NONE,
  160.         GUIDE_ENTITY,
  161.         GUIDE_POS,
  162.         GUIDE_DIR,
  163.         GUIDE_MAX
  164.     };
  165.  
  166.     void                    Save( idSaveGame *savefile ) const;
  167.     void                    Restore( idRestoreGame *savefile );
  168.  
  169.     virtual void            Think( void );
  170.     virtual void            Launch( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity, const float timeSinceFire = 0.0f, const float dmgPower = 1.0f );
  171.  
  172.     void                    GuideTo            ( const idVec3& post, const idVec3& dir );
  173.     void                    GuideTo            ( const idVec3& pos );
  174.     void                    GuideTo            ( idEntity* ent, jointHandle_t guideJoint=INVALID_JOINT, const idVec3 &offset=vec3_origin );
  175.     void                    CancelGuide        ( void );
  176.  
  177.     int                        GetGuideType    ( void ) const;
  178.  
  179.     virtual void            Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  180.  
  181. protected:
  182.  
  183.     int                        guideType;    
  184.     idEntityPtr<idEntity>    guideEnt;
  185.     idVec3                    guideDir;
  186.     idVec3                    guidePos;
  187.     jointHandle_t            guideJoint;
  188.     float                    guideMinDist;
  189.     
  190.     int                        driftTime;
  191.     int                        driftRate;
  192.     float                    driftRange;
  193.     float                    driftRadius;
  194.     float                    driftDiversity;
  195.     float                    driftAngle;
  196.     float                    driftAngleStep;
  197.     float                    driftProjectRange;
  198.     
  199.     virtual bool            GetGuideDir        ( idVec3 &outDir, float& outDist );
  200.  
  201. private:
  202.  
  203.     idInterpolate<float>    turn_max;
  204.     int                        launchTime;
  205.     int                        guideDelay;
  206.     int                        driftDelay;
  207. };
  208.  
  209. ID_INLINE int idGuidedProjectile::GetGuideType ( void ) const {
  210.     return guideType;
  211. }
  212.  
  213. ID_INLINE void idGuidedProjectile::GuideTo ( const idVec3& pos, const idVec3& dir ) {
  214.     guideType = GUIDE_DIR;
  215.     guidePos  = pos;
  216.     guideDir  = dir;
  217. }
  218.  
  219. ID_INLINE void idGuidedProjectile::GuideTo ( const idVec3& pos ) {
  220.     guideType = GUIDE_POS;
  221.     guidePos  = pos;
  222. }
  223.  
  224. ID_INLINE void idGuidedProjectile::GuideTo ( idEntity* ent, jointHandle_t joint, const idVec3 &offset ) {
  225.     guideType = GUIDE_ENTITY;
  226.     guideEnt  = ent;
  227.     guideJoint = joint;
  228.     guidePos = offset;
  229.  
  230.     if ( guideEnt.IsValid() ) {
  231.         guideEnt->GuidedProjectileIncoming( this );
  232.     }
  233. }
  234.  
  235. ID_INLINE void idGuidedProjectile::CancelGuide ( void ) {
  236.     guideType = GUIDE_NONE;
  237.  
  238.     // twhitaker: TEMP
  239.     if ( guideEnt.IsValid() ) {
  240.         guideEnt->GuidedProjectileIncoming( NULL );    
  241.     }
  242.     // </twhitaker>
  243. }
  244.  
  245. /*
  246. ===============================================================================
  247.  
  248. rvDriftingProjectile
  249.  
  250. ===============================================================================
  251. */
  252.  
  253. class rvDriftingProjectile : public idProjectile {
  254. public :
  255.     CLASS_PROTOTYPE( rvDriftingProjectile );
  256.  
  257.                             rvDriftingProjectile ( void );
  258.                             ~rvDriftingProjectile ( void );
  259.  
  260.     void                    Save            ( idSaveGame *savefile ) const;
  261.     void                    Restore            ( idRestoreGame *savefile );
  262.  
  263.     virtual void            Think            ( void );
  264.     virtual void            Launch            ( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity, const float timeSinceFire = 0.0f, const float dmgPower = 1.0f );
  265.  
  266. protected:
  267.  
  268.     virtual void            UpdateVisualAngles    ( void );
  269.  
  270.     idVec3                    startDir;
  271.     idVec3                    startOrigin;
  272.     idMat3                    startAxis;
  273.     float                    startSpeed;
  274.     
  275.     idInterpolateAccelDecelLinear<float>    driftOffset[2];
  276.     idInterpolateAccelDecelLinear<float>    driftSpeed;
  277.     float                                    driftOffsetMax;
  278.     float                                    driftSpeedMax;
  279.     float                                    driftTime;
  280. };
  281.  
  282. /*
  283. ===============================================================================
  284.  
  285. rvSpawnerProjectile
  286.  
  287. ===============================================================================
  288. */
  289.  
  290. class rvSpawner;
  291. class rvSpawnerProjectile : public idProjectile {
  292. public :
  293.     CLASS_PROTOTYPE( rvSpawnerProjectile );
  294.     
  295.                             rvSpawnerProjectile ( void );
  296.                             ~rvSpawnerProjectile ( void );
  297.  
  298.     void                    Spawn            ( void );
  299.     virtual void            Think            ( void );
  300.  
  301.     void                    SetSpawner        ( rvSpawner* spawner );
  302.  
  303. protected:
  304.  
  305.     idEntityPtr<rvSpawner>    spawner;
  306.  
  307.     enum {
  308.         STATE_NONE,
  309.         STATE_ADDED,
  310.     } spawnState;    
  311.     
  312. private:
  313.  
  314.     void                    Event_PostSpawn    ( void );
  315. };
  316.  
  317. /*
  318. ===============================================================================
  319.  
  320. rvMIRVProjectile
  321.  
  322. ===============================================================================
  323. */
  324.  
  325. class rvMIRVProjectile : public idProjectile {
  326.     CLASS_PROTOTYPE( rvMIRVProjectile );
  327.  
  328.                         rvMIRVProjectile ( void );
  329.                         ~rvMIRVProjectile (  void );
  330.  
  331.  
  332.     void                Spawn                ( void );
  333.  
  334. private:
  335.         
  336.     void                Event_LaunchWarheads ( void );
  337. };
  338.  
  339. #endif /* !__GAME_PROJECTILE_H__ */
  340.  
  341. // RAVEN END
  342.