Moveable.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __GAME_MOVEABLE_H__
  21. #define __GAME_MOVEABLE_H__
  22. /*
  23. ===============================================================================
  24. Entity using rigid body physics.
  25. ===============================================================================
  26. */
  27. extern const idEventDef EV_BecomeNonSolid;
  28. extern const idEventDef EV_IsAtRest;
  29. class idMoveable : public idEntity {
  30. public:
  31. CLASS_PROTOTYPE( idMoveable );
  32. idMoveable( void );
  33. ~idMoveable( void );
  34. void Spawn( void );
  35. void Save( idSaveGame *savefile ) const;
  36. void Restore( idRestoreGame *savefile );
  37. virtual void Think( void );
  38. virtual void Hide( void );
  39. virtual void Show( void );
  40. bool AllowStep( void ) const;
  41. void EnableDamage( bool enable, float duration );
  42. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  43. virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  44. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  45. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  46. #ifdef _D3XP
  47. void SetAttacker( idEntity *ent );
  48. #endif
  49. protected:
  50. idPhysics_RigidBody physicsObj; // physics object
  51. idStr brokenModel; // model set when health drops down to or below zero
  52. idStr damage; // if > 0 apply damage to hit entities
  53. #ifdef _D3XP
  54. idStr monsterDamage;
  55. idEntity *attacker;
  56. #endif
  57. idStr fxCollide; // fx system to start when collides with something
  58. int nextCollideFxTime; // next time it is ok to spawn collision fx
  59. float minDamageVelocity; // minimum velocity before moveable applies damage
  60. float maxDamageVelocity; // velocity at which the maximum damage is applied
  61. idCurve_Spline<idVec3> *initialSpline; // initial spline path the moveable follows
  62. idVec3 initialSplineDir; // initial relative direction along the spline path
  63. bool explode; // entity explodes when health drops down to or below zero
  64. bool unbindOnDeath; // unbind from master when health drops down to or below zero
  65. bool allowStep; // allow monsters to step on the object
  66. bool canDamage; // only apply damage when this is set
  67. int nextDamageTime; // next time the movable can hurt the player
  68. int nextSoundTime; // next time the moveable can make a sound
  69. const idMaterial * GetRenderModelMaterial( void ) const;
  70. void BecomeNonSolid( void );
  71. void InitInitialSpline( int startTime );
  72. bool FollowInitialSplinePath( void );
  73. void Event_Activate( idEntity *activator );
  74. void Event_BecomeNonSolid( void );
  75. void Event_SetOwnerFromSpawnArgs( void );
  76. void Event_IsAtRest( void );
  77. void Event_EnableDamage( float enable );
  78. };
  79. /*
  80. ===============================================================================
  81. A barrel using rigid body physics. The barrel has special handling of
  82. the view model orientation to make it look like it rolls instead of slides.
  83. ===============================================================================
  84. */
  85. class idBarrel : public idMoveable {
  86. public:
  87. CLASS_PROTOTYPE( idBarrel );
  88. idBarrel();
  89. void Spawn( void );
  90. void Save( idSaveGame *savefile ) const;
  91. void Restore( idRestoreGame *savefile );
  92. void BarrelThink( void );
  93. virtual void Think( void );
  94. virtual bool GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
  95. virtual void ClientPredictionThink( void );
  96. private:
  97. float radius; // radius of barrel
  98. int barrelAxis; // one of the coordinate axes the barrel cylinder is parallel to
  99. idVec3 lastOrigin; // origin of the barrel the last think frame
  100. idMat3 lastAxis; // axis of the barrel the last think frame
  101. float additionalRotation; // additional rotation of the barrel about it's axis
  102. idMat3 additionalAxis; // additional rotation axis
  103. };
  104. /*
  105. ===============================================================================
  106. A barrel using rigid body physics and special handling of the view model
  107. orientation to make it look like it rolls instead of slides. The barrel
  108. can burn and explode when damaged.
  109. ===============================================================================
  110. */
  111. class idExplodingBarrel : public idBarrel {
  112. public:
  113. CLASS_PROTOTYPE( idExplodingBarrel );
  114. idExplodingBarrel();
  115. ~idExplodingBarrel();
  116. void Spawn( void );
  117. void Save( idSaveGame *savefile ) const;
  118. void Restore( idRestoreGame *savefile );
  119. #ifdef _D3XP
  120. bool IsStable( void );
  121. void SetStability( bool stability );
  122. void StartBurning( void );
  123. void StopBurning( void );
  124. #endif
  125. virtual void Think( void );
  126. virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir,
  127. const char *damageDefName, const float damageScale, const int location );
  128. virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  129. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  130. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  131. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  132. enum {
  133. EVENT_EXPLODE = idEntity::EVENT_MAXEVENTS,
  134. EVENT_MAXEVENTS
  135. };
  136. private:
  137. typedef enum {
  138. NORMAL = 0,
  139. BURNING,
  140. BURNEXPIRED,
  141. EXPLODING
  142. } explode_state_t;
  143. explode_state_t state;
  144. idVec3 spawnOrigin;
  145. idMat3 spawnAxis;
  146. qhandle_t particleModelDefHandle;
  147. qhandle_t lightDefHandle;
  148. renderEntity_t particleRenderEntity;
  149. renderLight_t light;
  150. int particleTime;
  151. int lightTime;
  152. float time;
  153. #ifdef _D3XP
  154. bool isStable;
  155. #endif
  156. void AddParticles( const char *name, bool burn );
  157. void AddLight( const char *name , bool burn );
  158. void ExplodingEffects( void );
  159. void Event_Activate( idEntity *activator );
  160. void Event_Respawn();
  161. void Event_Explode();
  162. void Event_TriggerTargets();
  163. };
  164. #endif /* !__GAME_MOVEABLE_H__ */