AFEntity.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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_AFENTITY_H__
  21. #define __GAME_AFENTITY_H__
  22. /*
  23. ===============================================================================
  24. idMultiModelAF
  25. Entity using multiple separate visual models animated with a single
  26. articulated figure. Only used for debugging!
  27. ===============================================================================
  28. */
  29. const int GIB_DELAY = 200; // only gib this often to keep performace hits when blowing up several mobs
  30. class idMultiModelAF : public idEntity {
  31. public:
  32. CLASS_PROTOTYPE( idMultiModelAF );
  33. void Spawn( void );
  34. ~idMultiModelAF( void );
  35. virtual void Think( void );
  36. virtual void Present( void );
  37. protected:
  38. idPhysics_AF physicsObj;
  39. void SetModelForId( int id, const idStr &modelName );
  40. private:
  41. idList<idRenderModel *> modelHandles;
  42. idList<int> modelDefHandles;
  43. };
  44. /*
  45. ===============================================================================
  46. idChain
  47. Chain hanging down from the ceiling. Only used for debugging!
  48. ===============================================================================
  49. */
  50. class idChain : public idMultiModelAF {
  51. public:
  52. CLASS_PROTOTYPE( idChain );
  53. void Spawn( void );
  54. protected:
  55. void BuildChain( const idStr &name, const idVec3 &origin, float linkLength, float linkWidth, float density, int numLinks, bool bindToWorld = true );
  56. };
  57. /*
  58. ===============================================================================
  59. idAFAttachment
  60. ===============================================================================
  61. */
  62. class idAFAttachment : public idAnimatedEntity {
  63. public:
  64. CLASS_PROTOTYPE( idAFAttachment );
  65. idAFAttachment( void );
  66. virtual ~idAFAttachment( void );
  67. void Spawn( void );
  68. void Save( idSaveGame *savefile ) const;
  69. void Restore( idRestoreGame *savefile );
  70. void SetBody( idEntity *bodyEnt, const char *headModel, jointHandle_t attachJoint );
  71. void ClearBody( void );
  72. idEntity * GetBody( void ) const;
  73. virtual void Think( void );
  74. virtual void Hide( void );
  75. virtual void Show( void );
  76. void PlayIdleAnim( int blendTime );
  77. virtual void GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info );
  78. virtual void ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
  79. virtual void AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
  80. virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
  81. virtual void AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName );
  82. void SetCombatModel( void );
  83. idClipModel * GetCombatModel( void ) const;
  84. virtual void LinkCombat( void );
  85. virtual void UnlinkCombat( void );
  86. protected:
  87. idEntity * body;
  88. idClipModel * combatModel; // render model for hit detection of head
  89. int idleAnim;
  90. jointHandle_t attachJoint;
  91. };
  92. /*
  93. ===============================================================================
  94. idAFEntity_Base
  95. ===============================================================================
  96. */
  97. class idAFEntity_Base : public idAnimatedEntity {
  98. public:
  99. CLASS_PROTOTYPE( idAFEntity_Base );
  100. idAFEntity_Base( void );
  101. virtual ~idAFEntity_Base( void );
  102. void Spawn( void );
  103. void Save( idSaveGame *savefile ) const;
  104. void Restore( idRestoreGame *savefile );
  105. virtual void Think( void );
  106. virtual void GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info );
  107. virtual void ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
  108. virtual void AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
  109. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  110. virtual bool GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
  111. virtual bool UpdateAnimationControllers( void );
  112. virtual void FreeModelDef( void );
  113. virtual bool LoadAF( void );
  114. bool IsActiveAF( void ) const { return af.IsActive(); }
  115. const char * GetAFName( void ) const { return af.GetName(); }
  116. idPhysics_AF * GetAFPhysics( void ) { return af.GetPhysics(); }
  117. void SetCombatModel( void );
  118. idClipModel * GetCombatModel( void ) const;
  119. // contents of combatModel can be set to 0 or re-enabled (mp)
  120. void SetCombatContents( bool enable );
  121. virtual void LinkCombat( void );
  122. virtual void UnlinkCombat( void );
  123. int BodyForClipModelId( int id ) const;
  124. void SaveState( idDict &args ) const;
  125. void LoadState( const idDict &args );
  126. void AddBindConstraints( void );
  127. void RemoveBindConstraints( void );
  128. virtual void ShowEditingDialog( void );
  129. static void DropAFs( idEntity *ent, const char *type, idList<idEntity *> *list );
  130. protected:
  131. idAF af; // articulated figure
  132. idClipModel * combatModel; // render model for hit detection
  133. int combatModelContents;
  134. idVec3 spawnOrigin; // spawn origin
  135. idMat3 spawnAxis; // rotation axis used when spawned
  136. int nextSoundTime; // next time this can make a sound
  137. void Event_SetConstraintPosition( const char *name, const idVec3 &pos );
  138. };
  139. /*
  140. ===============================================================================
  141. idAFEntity_Gibbable
  142. ===============================================================================
  143. */
  144. extern const idEventDef EV_Gib;
  145. extern const idEventDef EV_Gibbed;
  146. class idAFEntity_Gibbable : public idAFEntity_Base {
  147. public:
  148. CLASS_PROTOTYPE( idAFEntity_Gibbable );
  149. idAFEntity_Gibbable( void );
  150. ~idAFEntity_Gibbable( void );
  151. void Spawn( void );
  152. void Save( idSaveGame *savefile ) const;
  153. void Restore( idRestoreGame *savefile );
  154. virtual void Present( void );
  155. virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
  156. virtual void SpawnGibs( const idVec3 &dir, const char *damageDefName );
  157. protected:
  158. idRenderModel * skeletonModel;
  159. int skeletonModelDefHandle;
  160. bool gibbed;
  161. virtual void Gib( const idVec3 &dir, const char *damageDefName );
  162. void InitSkeletonModel( void );
  163. void Event_Gib( const char *damageDefName );
  164. };
  165. /*
  166. ===============================================================================
  167. idAFEntity_Generic
  168. ===============================================================================
  169. */
  170. class idAFEntity_Generic : public idAFEntity_Gibbable {
  171. public:
  172. CLASS_PROTOTYPE( idAFEntity_Generic );
  173. idAFEntity_Generic( void );
  174. ~idAFEntity_Generic( void );
  175. void Spawn( void );
  176. void Save( idSaveGame *savefile ) const;
  177. void Restore( idRestoreGame *savefile );
  178. virtual void Think( void );
  179. void KeepRunningPhysics( void ) { keepRunningPhysics = true; }
  180. private:
  181. void Event_Activate( idEntity *activator );
  182. bool keepRunningPhysics;
  183. };
  184. /*
  185. ===============================================================================
  186. idAFEntity_WithAttachedHead
  187. ===============================================================================
  188. */
  189. class idAFEntity_WithAttachedHead : public idAFEntity_Gibbable {
  190. public:
  191. CLASS_PROTOTYPE( idAFEntity_WithAttachedHead );
  192. idAFEntity_WithAttachedHead();
  193. ~idAFEntity_WithAttachedHead();
  194. void Spawn( void );
  195. void Save( idSaveGame *savefile ) const;
  196. void Restore( idRestoreGame *savefile );
  197. void SetupHead( void );
  198. virtual void Think( void );
  199. virtual void Hide( void );
  200. virtual void Show( void );
  201. virtual void ProjectOverlay( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
  202. virtual void LinkCombat( void );
  203. virtual void UnlinkCombat( void );
  204. protected:
  205. virtual void Gib( const idVec3 &dir, const char *damageDefName );
  206. private:
  207. idEntityPtr<idAFAttachment> head;
  208. void Event_Gib( const char *damageDefName );
  209. void Event_Activate( idEntity *activator );
  210. };
  211. /*
  212. ===============================================================================
  213. idAFEntity_Vehicle
  214. ===============================================================================
  215. */
  216. class idAFEntity_Vehicle : public idAFEntity_Base {
  217. public:
  218. CLASS_PROTOTYPE( idAFEntity_Vehicle );
  219. idAFEntity_Vehicle( void );
  220. void Spawn( void );
  221. void Use( idPlayer *player );
  222. protected:
  223. idPlayer * player;
  224. jointHandle_t eyesJoint;
  225. jointHandle_t steeringWheelJoint;
  226. float wheelRadius;
  227. float steerAngle;
  228. float steerSpeed;
  229. const idDeclParticle * dustSmoke;
  230. float GetSteerAngle( void );
  231. };
  232. /*
  233. ===============================================================================
  234. idAFEntity_VehicleSimple
  235. ===============================================================================
  236. */
  237. class idAFEntity_VehicleSimple : public idAFEntity_Vehicle {
  238. public:
  239. CLASS_PROTOTYPE( idAFEntity_VehicleSimple );
  240. idAFEntity_VehicleSimple( void );
  241. ~idAFEntity_VehicleSimple( void );
  242. void Spawn( void );
  243. virtual void Think( void );
  244. protected:
  245. idClipModel * wheelModel;
  246. idAFConstraint_Suspension * suspension[4];
  247. jointHandle_t wheelJoints[4];
  248. float wheelAngles[4];
  249. };
  250. /*
  251. ===============================================================================
  252. idAFEntity_VehicleFourWheels
  253. ===============================================================================
  254. */
  255. class idAFEntity_VehicleFourWheels : public idAFEntity_Vehicle {
  256. public:
  257. CLASS_PROTOTYPE( idAFEntity_VehicleFourWheels );
  258. idAFEntity_VehicleFourWheels( void );
  259. void Spawn( void );
  260. virtual void Think( void );
  261. protected:
  262. idAFBody * wheels[4];
  263. idAFConstraint_Hinge * steering[2];
  264. jointHandle_t wheelJoints[4];
  265. float wheelAngles[4];
  266. };
  267. /*
  268. ===============================================================================
  269. idAFEntity_VehicleSixWheels
  270. ===============================================================================
  271. */
  272. class idAFEntity_VehicleSixWheels : public idAFEntity_Vehicle {
  273. public:
  274. CLASS_PROTOTYPE( idAFEntity_VehicleSixWheels );
  275. idAFEntity_VehicleSixWheels( void );
  276. void Spawn( void );
  277. virtual void Think( void );
  278. private:
  279. idAFBody * wheels[6];
  280. idAFConstraint_Hinge * steering[4];
  281. jointHandle_t wheelJoints[6];
  282. float wheelAngles[6];
  283. };
  284. /*
  285. ===============================================================================
  286. idAFEntity_SteamPipe
  287. ===============================================================================
  288. */
  289. class idAFEntity_SteamPipe : public idAFEntity_Base {
  290. public:
  291. CLASS_PROTOTYPE( idAFEntity_SteamPipe );
  292. idAFEntity_SteamPipe( void );
  293. ~idAFEntity_SteamPipe( void );
  294. void Spawn( void );
  295. void Save( idSaveGame *savefile ) const;
  296. void Restore( idRestoreGame *savefile );
  297. virtual void Think( void );
  298. private:
  299. int steamBody;
  300. float steamForce;
  301. float steamUpForce;
  302. idForce_Constant force;
  303. renderEntity_t steamRenderEntity;
  304. qhandle_t steamModelDefHandle;
  305. void InitSteamRenderEntity( void );
  306. };
  307. /*
  308. ===============================================================================
  309. idAFEntity_ClawFourFingers
  310. ===============================================================================
  311. */
  312. class idAFEntity_ClawFourFingers : public idAFEntity_Base {
  313. public:
  314. CLASS_PROTOTYPE( idAFEntity_ClawFourFingers );
  315. idAFEntity_ClawFourFingers( void );
  316. void Spawn( void );
  317. void Save( idSaveGame *savefile ) const;
  318. void Restore( idRestoreGame *savefile );
  319. private:
  320. idAFConstraint_Hinge * fingers[4];
  321. void Event_SetFingerAngle( float angle );
  322. void Event_StopFingers( void );
  323. };
  324. #endif /* !__GAME_AFENTITY_H__ */