AFEntity.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition 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 BFG Edition 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();
  34. ~idMultiModelAF();
  35. virtual void Think();
  36. virtual void Present();
  37. protected:
  38. idPhysics_AF physicsObj;
  39. void SetModelForId( int id, const idStr &modelName );
  40. private:
  41. idList<idRenderModel *, TAG_AF> modelHandles;
  42. idList<int, TAG_AF> 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();
  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();
  66. virtual ~idAFAttachment();
  67. void Spawn();
  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();
  72. idEntity * GetBody() const;
  73. virtual void Think();
  74. virtual void Hide();
  75. virtual void Show();
  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();
  83. idClipModel * GetCombatModel() const;
  84. virtual void LinkCombat();
  85. virtual void UnlinkCombat();
  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();
  101. virtual ~idAFEntity_Base();
  102. void Spawn();
  103. void Save( idSaveGame *savefile ) const;
  104. void Restore( idRestoreGame *savefile );
  105. virtual void Think();
  106. virtual void AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName );
  107. virtual void GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info );
  108. virtual void ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
  109. virtual void AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
  110. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  111. virtual bool GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
  112. virtual bool UpdateAnimationControllers();
  113. virtual void FreeModelDef();
  114. virtual bool LoadAF();
  115. bool IsActiveAF() const { return af.IsActive(); }
  116. const char * GetAFName() const { return af.GetName(); }
  117. idPhysics_AF * GetAFPhysics() { return af.GetPhysics(); }
  118. void SetCombatModel();
  119. idClipModel * GetCombatModel() const;
  120. // contents of combatModel can be set to 0 or re-enabled (mp)
  121. void SetCombatContents( bool enable );
  122. virtual void LinkCombat();
  123. virtual void UnlinkCombat();
  124. int BodyForClipModelId( int id ) const;
  125. void SaveState( idDict &args ) const;
  126. void LoadState( const idDict &args );
  127. void AddBindConstraints();
  128. void RemoveBindConstraints();
  129. virtual void ShowEditingDialog();
  130. static void DropAFs( idEntity *ent, const char *type, idList<idEntity *> *list );
  131. protected:
  132. idAF af; // articulated figure
  133. idClipModel * combatModel; // render model for hit detection
  134. int combatModelContents;
  135. idVec3 spawnOrigin; // spawn origin
  136. idMat3 spawnAxis; // rotation axis used when spawned
  137. int nextSoundTime; // next time this can make a sound
  138. void Event_SetConstraintPosition( const char *name, const idVec3 &pos );
  139. };
  140. /*
  141. ===============================================================================
  142. idAFEntity_Gibbable
  143. ===============================================================================
  144. */
  145. extern const idEventDef EV_Gib;
  146. extern const idEventDef EV_Gibbed;
  147. class idAFEntity_Gibbable : public idAFEntity_Base {
  148. public:
  149. CLASS_PROTOTYPE( idAFEntity_Gibbable );
  150. idAFEntity_Gibbable();
  151. ~idAFEntity_Gibbable();
  152. void Spawn();
  153. void Save( idSaveGame *savefile ) const;
  154. void Restore( idRestoreGame *savefile );
  155. virtual void Present();
  156. virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
  157. void SetThrown( bool isThrown );
  158. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  159. virtual void SpawnGibs( const idVec3 &dir, const char *damageDefName );
  160. bool IsGibbed() { return gibbed; };
  161. protected:
  162. idRenderModel * skeletonModel;
  163. int skeletonModelDefHandle;
  164. bool gibbed;
  165. bool wasThrown;
  166. virtual void Gib( const idVec3 &dir, const char *damageDefName );
  167. void InitSkeletonModel();
  168. void Event_Gib( const char *damageDefName );
  169. };
  170. /*
  171. ===============================================================================
  172. idAFEntity_Generic
  173. ===============================================================================
  174. */
  175. class idAFEntity_Generic : public idAFEntity_Gibbable {
  176. public:
  177. CLASS_PROTOTYPE( idAFEntity_Generic );
  178. idAFEntity_Generic();
  179. ~idAFEntity_Generic();
  180. void Spawn();
  181. void Save( idSaveGame *savefile ) const;
  182. void Restore( idRestoreGame *savefile );
  183. virtual void Think();
  184. void KeepRunningPhysics() { keepRunningPhysics = true; }
  185. private:
  186. void Event_Activate( idEntity *activator );
  187. bool keepRunningPhysics;
  188. };
  189. /*
  190. ===============================================================================
  191. idAFEntity_WithAttachedHead
  192. ===============================================================================
  193. */
  194. class idAFEntity_WithAttachedHead : public idAFEntity_Gibbable {
  195. public:
  196. CLASS_PROTOTYPE( idAFEntity_WithAttachedHead );
  197. idAFEntity_WithAttachedHead();
  198. ~idAFEntity_WithAttachedHead();
  199. void Spawn();
  200. void Save( idSaveGame *savefile ) const;
  201. void Restore( idRestoreGame *savefile );
  202. void SetupHead();
  203. virtual void Think();
  204. virtual void Hide();
  205. virtual void Show();
  206. virtual void ProjectOverlay( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
  207. virtual void LinkCombat();
  208. virtual void UnlinkCombat();
  209. protected:
  210. virtual void Gib( const idVec3 &dir, const char *damageDefName );
  211. public:
  212. idEntityPtr<idAFAttachment> head;
  213. void Event_Gib( const char *damageDefName );
  214. void Event_Activate( idEntity *activator );
  215. };
  216. /*
  217. ===============================================================================
  218. idAFEntity_Vehicle
  219. ===============================================================================
  220. */
  221. class idAFEntity_Vehicle : public idAFEntity_Base {
  222. public:
  223. CLASS_PROTOTYPE( idAFEntity_Vehicle );
  224. idAFEntity_Vehicle();
  225. void Spawn();
  226. void Use( idPlayer *player );
  227. protected:
  228. idPlayer * player;
  229. jointHandle_t eyesJoint;
  230. jointHandle_t steeringWheelJoint;
  231. float wheelRadius;
  232. float steerAngle;
  233. float steerSpeed;
  234. const idDeclParticle * dustSmoke;
  235. float GetSteerAngle();
  236. };
  237. /*
  238. ===============================================================================
  239. idAFEntity_VehicleSimple
  240. ===============================================================================
  241. */
  242. class idAFEntity_VehicleSimple : public idAFEntity_Vehicle {
  243. public:
  244. CLASS_PROTOTYPE( idAFEntity_VehicleSimple );
  245. idAFEntity_VehicleSimple();
  246. ~idAFEntity_VehicleSimple();
  247. void Spawn();
  248. virtual void Think();
  249. protected:
  250. idClipModel * wheelModel;
  251. idAFConstraint_Suspension * suspension[4];
  252. jointHandle_t wheelJoints[4];
  253. float wheelAngles[4];
  254. };
  255. /*
  256. ===============================================================================
  257. idAFEntity_VehicleFourWheels
  258. ===============================================================================
  259. */
  260. class idAFEntity_VehicleFourWheels : public idAFEntity_Vehicle {
  261. public:
  262. CLASS_PROTOTYPE( idAFEntity_VehicleFourWheels );
  263. idAFEntity_VehicleFourWheels();
  264. void Spawn();
  265. virtual void Think();
  266. protected:
  267. idAFBody * wheels[4];
  268. idAFConstraint_Hinge * steering[2];
  269. jointHandle_t wheelJoints[4];
  270. float wheelAngles[4];
  271. };
  272. /*
  273. ===============================================================================
  274. idAFEntity_VehicleSixWheels
  275. ===============================================================================
  276. */
  277. class idAFEntity_VehicleSixWheels : public idAFEntity_Vehicle {
  278. public:
  279. CLASS_PROTOTYPE( idAFEntity_VehicleSixWheels );
  280. idAFEntity_VehicleSixWheels();
  281. void Spawn();
  282. virtual void Think();
  283. float force;
  284. float velocity;
  285. float steerAngle;
  286. private:
  287. idAFBody * wheels[6];
  288. idAFConstraint_Hinge * steering[4];
  289. jointHandle_t wheelJoints[6];
  290. float wheelAngles[6];
  291. };
  292. /*
  293. ===============================================================================
  294. idAFEntity_VehicleAutomated
  295. ===============================================================================
  296. */
  297. class idAFEntity_VehicleAutomated : public idAFEntity_VehicleSixWheels {
  298. public:
  299. CLASS_PROTOTYPE( idAFEntity_VehicleAutomated );
  300. void Spawn();
  301. void PostSpawn();
  302. virtual void Think();
  303. private:
  304. idEntity *waypoint;
  305. float steeringSpeed;
  306. float currentSteering;
  307. float idealSteering;
  308. float originHeight;
  309. void Event_SetVelocity( float _velocity );
  310. void Event_SetTorque( float _torque );
  311. void Event_SetSteeringSpeed( float _steeringSpeed );
  312. void Event_SetWayPoint( idEntity *_waypoint );
  313. };
  314. /*
  315. ===============================================================================
  316. idAFEntity_SteamPipe
  317. ===============================================================================
  318. */
  319. class idAFEntity_SteamPipe : public idAFEntity_Base {
  320. public:
  321. CLASS_PROTOTYPE( idAFEntity_SteamPipe );
  322. idAFEntity_SteamPipe();
  323. ~idAFEntity_SteamPipe();
  324. void Spawn();
  325. void Save( idSaveGame *savefile ) const;
  326. void Restore( idRestoreGame *savefile );
  327. virtual void Think();
  328. private:
  329. int steamBody;
  330. float steamForce;
  331. float steamUpForce;
  332. idForce_Constant force;
  333. renderEntity_t steamRenderEntity;
  334. qhandle_t steamModelDefHandle;
  335. void InitSteamRenderEntity();
  336. };
  337. /*
  338. ===============================================================================
  339. idAFEntity_ClawFourFingers
  340. ===============================================================================
  341. */
  342. class idAFEntity_ClawFourFingers : public idAFEntity_Base {
  343. public:
  344. CLASS_PROTOTYPE( idAFEntity_ClawFourFingers );
  345. idAFEntity_ClawFourFingers();
  346. void Spawn();
  347. void Save( idSaveGame *savefile ) const;
  348. void Restore( idRestoreGame *savefile );
  349. private:
  350. idAFConstraint_Hinge * fingers[4];
  351. void Event_SetFingerAngle( float angle );
  352. void Event_StopFingers();
  353. };
  354. /**
  355. * idHarvestable contains all of the code required to turn an entity into a harvestable
  356. * entity. The entity must create an instance of this class and call the appropriate
  357. * interface methods at the correct time.
  358. */
  359. class idHarvestable : public idEntity {
  360. public:
  361. CLASS_PROTOTYPE( idHarvestable );
  362. idHarvestable();
  363. ~idHarvestable();
  364. void Spawn();
  365. void Init(idEntity* parent);
  366. void Save( idSaveGame *savefile ) const;
  367. void Restore( idRestoreGame *savefile );
  368. void SetParent(idEntity* parent);
  369. void Think();
  370. void Gib();
  371. protected:
  372. idEntityPtr<idEntity> parentEnt;
  373. float triggersize;
  374. idClipModel * trigger;
  375. float giveDelay;
  376. float removeDelay;
  377. bool given;
  378. idEntityPtr<idPlayer> player;
  379. int startTime;
  380. bool fxFollowPlayer;
  381. idEntityPtr<idEntityFx> fx;
  382. idStr fxOrient;
  383. protected:
  384. void BeginBurn();
  385. void BeginFX();
  386. void CalcTriggerBounds( float size, idBounds &bounds );
  387. bool GetFxOrientationAxis(idMat3& mat);
  388. void Event_SpawnHarvestTrigger();
  389. void Event_Touch( idEntity *other, trace_t *trace );
  390. } ;
  391. /*
  392. ===============================================================================
  393. idAFEntity_Harvest
  394. ===============================================================================
  395. */
  396. class idAFEntity_Harvest : public idAFEntity_WithAttachedHead {
  397. public:
  398. CLASS_PROTOTYPE( idAFEntity_Harvest );
  399. idAFEntity_Harvest();
  400. ~idAFEntity_Harvest();
  401. void Spawn();
  402. void Save( idSaveGame *savefile ) const;
  403. void Restore( idRestoreGame *savefile );
  404. virtual void Think();
  405. virtual void Gib( const idVec3 &dir, const char *damageDefName );
  406. protected:
  407. idEntityPtr<idHarvestable> harvestEnt;
  408. protected:
  409. void Event_SpawnHarvestEntity();
  410. };
  411. #endif /* !__GAME_AFENTITY_H__ */