Entity.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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_ENTITY_H__
  21. #define __GAME_ENTITY_H__
  22. /*
  23. ===============================================================================
  24. Game entity base class.
  25. ===============================================================================
  26. */
  27. static const int DELAY_DORMANT_TIME = 3000;
  28. extern const idEventDef EV_PostSpawn;
  29. extern const idEventDef EV_FindTargets;
  30. extern const idEventDef EV_Touch;
  31. extern const idEventDef EV_Use;
  32. extern const idEventDef EV_Activate;
  33. extern const idEventDef EV_ActivateTargets;
  34. extern const idEventDef EV_Hide;
  35. extern const idEventDef EV_Show;
  36. extern const idEventDef EV_GetShaderParm;
  37. extern const idEventDef EV_SetShaderParm;
  38. extern const idEventDef EV_SetOwner;
  39. extern const idEventDef EV_GetAngles;
  40. extern const idEventDef EV_SetAngles;
  41. extern const idEventDef EV_SetLinearVelocity;
  42. extern const idEventDef EV_SetAngularVelocity;
  43. extern const idEventDef EV_SetSkin;
  44. extern const idEventDef EV_StartSoundShader;
  45. extern const idEventDef EV_StopSound;
  46. extern const idEventDef EV_CacheSoundShader;
  47. // Think flags
  48. enum {
  49. TH_ALL = -1,
  50. TH_THINK = 1, // run think function each frame
  51. TH_PHYSICS = 2, // run physics each frame
  52. TH_ANIMATE = 4, // update animation each frame
  53. TH_UPDATEVISUALS = 8, // update renderEntity
  54. TH_UPDATEPARTICLES = 16
  55. };
  56. //
  57. // Signals
  58. // make sure to change script/doom_defs.script if you add any, or change their order
  59. //
  60. typedef enum {
  61. SIG_TOUCH, // object was touched
  62. SIG_USE, // object was used
  63. SIG_TRIGGER, // object was activated
  64. SIG_REMOVED, // object was removed from the game
  65. SIG_DAMAGE, // object was damaged
  66. SIG_BLOCKED, // object was blocked
  67. SIG_MOVER_POS1, // mover at position 1 (door closed)
  68. SIG_MOVER_POS2, // mover at position 2 (door open)
  69. SIG_MOVER_1TO2, // mover changing from position 1 to 2
  70. SIG_MOVER_2TO1, // mover changing from position 2 to 1
  71. NUM_SIGNALS
  72. } signalNum_t;
  73. // FIXME: At some point we may want to just limit it to one thread per signal, but
  74. // for now, I'm allowing multiple threads. We should reevaluate this later in the project
  75. #define MAX_SIGNAL_THREADS 16 // probably overkill, but idList uses a granularity of 16
  76. struct signal_t {
  77. int threadnum;
  78. const function_t *function;
  79. };
  80. class signalList_t {
  81. public:
  82. idList<signal_t, TAG_ENTITY> signal[ NUM_SIGNALS ];
  83. };
  84. /*
  85. ================================================
  86. idNetEvent
  87. Utility for detecting a bool state change:
  88. -server calls ::Set
  89. -client ::Get will return true (once only)
  90. Useful because:
  91. -Hides client from having to manually declare "last" state and manually checking against it
  92. -using int counter prevents problems w/ dropped snapshots
  93. (ie if we just serialized a bool to true for a single ss, if that ss is dropped,skipped,whatever
  94. the client would never handle it. By incrementing a wrapped counter, we are guaranteed to detect
  95. the state change no matter what happens at the net layer).
  96. ================================================
  97. */
  98. template < int max >
  99. struct idNetEvent {
  100. idNetEvent() : count(0), lastCount(0) { }
  101. void Set() { count = ( ( count + 1 ) % max ); }
  102. bool Get() {
  103. if ( count != lastCount ) {
  104. lastCount = count;
  105. return true;
  106. }
  107. return false;
  108. }
  109. void Serialize( idSerializer &ser ) {
  110. if ( count >= max ) {
  111. idLib::Warning("idNetEvent. count %d > max %d", count, max );
  112. }
  113. ser.SerializeUMax( count, max );
  114. }
  115. public:
  116. static const int Maximum = max;
  117. int count;
  118. int lastCount;
  119. };
  120. typedef idNetEvent< 7 > netBoolEvent_t;
  121. inline void WriteToBitMsg( const netBoolEvent_t & netEvent, idBitMsg & msg ) {
  122. msg.WriteBits( netEvent.count, idMath::BitsForInteger( netBoolEvent_t::Maximum ) );
  123. assert( netEvent.count <= netBoolEvent_t::Maximum );
  124. }
  125. inline void ReadFromBitMsg( netBoolEvent_t & netEvent, const idBitMsg & msg ) {
  126. netEvent.count = msg.ReadBits( idMath::BitsForInteger( netBoolEvent_t::Maximum ) );
  127. assert( netEvent.count <= netBoolEvent_t::Maximum );
  128. }
  129. class idEntity : public idClass {
  130. public:
  131. static const int MAX_PVS_AREAS = 4;
  132. static const uint32 INVALID_PREDICTION_KEY = 0xFFFFFFFF;
  133. int entityNumber; // index into the entity list
  134. int entityDefNumber; // index into the entity def list
  135. idLinkList<idEntity> spawnNode; // for being linked into spawnedEntities list
  136. idLinkList<idEntity> activeNode; // for being linked into activeEntities list
  137. idLinkList<idEntity> aimAssistNode; // linked into gameLocal.aimAssistEntities
  138. idLinkList<idEntity> snapshotNode; // for being linked into snapshotEntities list
  139. int snapshotChanged; // used to detect snapshot state changes
  140. int snapshotBits; // number of bits this entity occupied in the last snapshot
  141. bool snapshotStale; // Set to true if this entity is considered stale in the snapshot
  142. idStr name; // name of entity
  143. idDict spawnArgs; // key/value pairs used to spawn and initialize entity
  144. idScriptObject scriptObject; // contains all script defined data for this entity
  145. int thinkFlags; // TH_? flags
  146. int dormantStart; // time that the entity was first closed off from player
  147. bool cinematic; // during cinematics, entity will only think if cinematic is set
  148. renderView_t * renderView; // for camera views from this entity
  149. idEntity * cameraTarget; // any remoteRenderMap shaders will use this
  150. idList< idEntityPtr<idEntity>, TAG_ENTITY > targets; // when this entity is activated these entities entity are activated
  151. int health; // FIXME: do all objects really need health?
  152. struct entityFlags_s {
  153. bool notarget :1; // if true never attack or target this entity
  154. bool noknockback :1; // if true no knockback from hits
  155. bool takedamage :1; // if true this entity can be damaged
  156. bool hidden :1; // if true this entity is not visible
  157. bool bindOrientated :1; // if true both the master orientation is used for binding
  158. bool solidForTeam :1; // if true this entity is considered solid when a physics team mate pushes entities
  159. bool forcePhysicsUpdate :1; // if true always update from the physics whether the object moved or not
  160. bool selected :1; // if true the entity is selected for editing
  161. bool neverDormant :1; // if true the entity never goes dormant
  162. bool isDormant :1; // if true the entity is dormant
  163. bool hasAwakened :1; // before a monster has been awakened the first time, use full PVS for dormant instead of area-connected
  164. bool networkSync :1; // if true the entity is synchronized over the network
  165. bool grabbed :1; // if true object is currently being grabbed
  166. bool skipReplication :1; // don't replicate this entity over the network.
  167. } fl;
  168. int timeGroup;
  169. bool noGrab;
  170. renderEntity_t xrayEntity;
  171. qhandle_t xrayEntityHandle;
  172. const idDeclSkin * xraySkin;
  173. void DetermineTimeGroup( bool slowmo );
  174. void SetGrabbedState( bool grabbed );
  175. bool IsGrabbed();
  176. public:
  177. ABSTRACT_PROTOTYPE( idEntity );
  178. idEntity();
  179. ~idEntity();
  180. void Spawn();
  181. void Save( idSaveGame *savefile ) const;
  182. void Restore( idRestoreGame *savefile );
  183. const char * GetEntityDefName() const;
  184. void SetName( const char *name );
  185. const char * GetName() const;
  186. virtual void UpdateChangeableSpawnArgs( const idDict *source );
  187. int GetEntityNumber() const { return entityNumber; }
  188. // clients generate views based on all the player specific options,
  189. // cameras have custom code, and everything else just uses the axis orientation
  190. virtual renderView_t * GetRenderView();
  191. // thinking
  192. virtual void Think();
  193. bool CheckDormant(); // dormant == on the active list, but out of PVS
  194. virtual void DormantBegin(); // called when entity becomes dormant
  195. virtual void DormantEnd(); // called when entity wakes from being dormant
  196. bool IsActive() const;
  197. void BecomeActive( int flags );
  198. void BecomeInactive( int flags );
  199. void UpdatePVSAreas( const idVec3 &pos );
  200. void BecomeReplicated();
  201. // visuals
  202. virtual void Present();
  203. virtual renderEntity_t *GetRenderEntity();
  204. virtual int GetModelDefHandle();
  205. virtual void SetModel( const char *modelname );
  206. void SetSkin( const idDeclSkin *skin );
  207. const idDeclSkin * GetSkin() const;
  208. void SetShaderParm( int parmnum, float value );
  209. virtual void SetColor( float red, float green, float blue );
  210. virtual void SetColor( const idVec3 &color );
  211. virtual void GetColor( idVec3 &out ) const;
  212. virtual void SetColor( const idVec4 &color );
  213. virtual void GetColor( idVec4 &out ) const;
  214. virtual void FreeModelDef();
  215. virtual void FreeLightDef();
  216. virtual void Hide();
  217. virtual void Show();
  218. bool IsHidden() const;
  219. void UpdateVisuals();
  220. void UpdateModel();
  221. void UpdateModelTransform();
  222. virtual void ProjectOverlay( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
  223. int GetNumPVSAreas();
  224. const int * GetPVSAreas();
  225. void ClearPVSAreas();
  226. bool PhysicsTeamInPVS( pvsHandle_t pvsHandle );
  227. // animation
  228. virtual bool UpdateAnimationControllers();
  229. bool UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView );
  230. static bool ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView );
  231. virtual idAnimator * GetAnimator(); // returns animator object used by this entity
  232. // sound
  233. virtual bool CanPlayChatterSounds() const;
  234. bool StartSound( const char *soundName, const s_channelType channel, int soundShaderFlags, bool broadcast, int *length );
  235. bool StartSoundShader( const idSoundShader *shader, const s_channelType channel, int soundShaderFlags, bool broadcast, int *length );
  236. void StopSound( const s_channelType channel, bool broadcast ); // pass SND_CHANNEL_ANY to stop all sounds
  237. void SetSoundVolume( float volume );
  238. void UpdateSound();
  239. int GetListenerId() const;
  240. idSoundEmitter * GetSoundEmitter() const;
  241. void FreeSoundEmitter( bool immediate );
  242. // entity binding
  243. virtual void PreBind();
  244. virtual void PostBind();
  245. virtual void PreUnbind();
  246. virtual void PostUnbind();
  247. void JoinTeam( idEntity *teammember );
  248. void Bind( idEntity *master, bool orientated );
  249. void BindToJoint( idEntity *master, const char *jointname, bool orientated );
  250. void BindToJoint( idEntity *master, jointHandle_t jointnum, bool orientated );
  251. void BindToBody( idEntity *master, int bodyId, bool orientated );
  252. void Unbind();
  253. bool IsBound() const;
  254. bool IsBoundTo( idEntity *master ) const;
  255. idEntity * GetBindMaster() const;
  256. jointHandle_t GetBindJoint() const;
  257. int GetBindBody() const;
  258. idEntity * GetTeamMaster() const;
  259. idEntity * GetNextTeamEntity() const;
  260. void ConvertLocalToWorldTransform( idVec3 &offset, idMat3 &axis );
  261. idVec3 GetLocalVector( const idVec3 &vec ) const;
  262. idVec3 GetLocalCoordinates( const idVec3 &vec ) const;
  263. idVec3 GetWorldVector( const idVec3 &vec ) const;
  264. idVec3 GetWorldCoordinates( const idVec3 &vec ) const;
  265. bool GetMasterPosition( idVec3 &masterOrigin, idMat3 &masterAxis ) const;
  266. void GetWorldVelocities( idVec3 &linearVelocity, idVec3 &angularVelocity ) const;
  267. // physics
  268. // set a new physics object to be used by this entity
  269. void SetPhysics( idPhysics *phys );
  270. // get the physics object used by this entity
  271. idPhysics * GetPhysics() const;
  272. // restore physics pointer for save games
  273. void RestorePhysics( idPhysics *phys );
  274. // run the physics for this entity
  275. bool RunPhysics();
  276. // Interpolates the physics, used on MP clients.
  277. void InterpolatePhysics( const float fraction );
  278. // InterpolatePhysics actually calls evaluate, this version doesn't.
  279. void InterpolatePhysicsOnly( const float fraction, bool updateTeam = false );
  280. // set the origin of the physics object (relative to bindMaster if not NULL)
  281. void SetOrigin( const idVec3 &org );
  282. // set the axis of the physics object (relative to bindMaster if not NULL)
  283. void SetAxis( const idMat3 &axis );
  284. // use angles to set the axis of the physics object (relative to bindMaster if not NULL)
  285. void SetAngles( const idAngles &ang );
  286. // get the floor position underneath the physics object
  287. bool GetFloorPos( float max_dist, idVec3 &floorpos ) const;
  288. // retrieves the transformation going from the physics origin/axis to the visual origin/axis
  289. virtual bool GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
  290. // retrieves the transformation going from the physics origin/axis to the sound origin/axis
  291. virtual bool GetPhysicsToSoundTransform( idVec3 &origin, idMat3 &axis );
  292. // called from the physics object when colliding, should return true if the physics simulation should stop
  293. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  294. // retrieves impact information, 'ent' is the entity retrieving the info
  295. virtual void GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info );
  296. // apply an impulse to the physics object, 'ent' is the entity applying the impulse
  297. virtual void ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
  298. // add a force to the physics object, 'ent' is the entity adding the force
  299. virtual void AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
  300. // activate the physics object, 'ent' is the entity activating this entity
  301. virtual void ActivatePhysics( idEntity *ent );
  302. // returns true if the physics object is at rest
  303. virtual bool IsAtRest() const;
  304. // returns the time the physics object came to rest
  305. virtual int GetRestStartTime() const;
  306. // add a contact entity
  307. virtual void AddContactEntity( idEntity *ent );
  308. // remove a touching entity
  309. virtual void RemoveContactEntity( idEntity *ent );
  310. // damage
  311. // returns true if this entity can be damaged from the given origin
  312. virtual bool CanDamage( const idVec3 &origin, idVec3 &damagePoint ) const;
  313. // applies damage to this entity
  314. virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
  315. // adds a damage effect like overlays, blood, sparks, debris etc.
  316. virtual void AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName );
  317. // callback function for when another entity received damage from this entity. damage can be adjusted and returned to the caller.
  318. virtual void DamageFeedback( idEntity *victim, idEntity *inflictor, int &damage );
  319. // notifies this entity that it is in pain
  320. virtual bool Pain( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  321. // notifies this entity that is has been killed
  322. virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  323. // scripting
  324. virtual bool ShouldConstructScriptObjectAtSpawn() const;
  325. virtual idThread * ConstructScriptObject();
  326. virtual void DeconstructScriptObject();
  327. void SetSignal( signalNum_t signalnum, idThread *thread, const function_t *function );
  328. void ClearSignal( idThread *thread, signalNum_t signalnum );
  329. void ClearSignalThread( signalNum_t signalnum, idThread *thread );
  330. bool HasSignal( signalNum_t signalnum ) const;
  331. void Signal( signalNum_t signalnum );
  332. void SignalEvent( idThread *thread, signalNum_t signalnum );
  333. // gui
  334. void TriggerGuis();
  335. bool HandleGuiCommands( idEntity *entityGui, const char *cmds );
  336. virtual bool HandleSingleGuiCommand( idEntity *entityGui, idLexer *src );
  337. // targets
  338. void FindTargets();
  339. void RemoveNullTargets();
  340. void ActivateTargets( idEntity *activator ) const;
  341. // misc
  342. virtual void Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination );
  343. bool TouchTriggers() const;
  344. idCurve_Spline<idVec3> *GetSpline() const;
  345. virtual void ShowEditingDialog();
  346. enum {
  347. EVENT_STARTSOUNDSHADER,
  348. EVENT_STOPSOUNDSHADER,
  349. EVENT_MAXEVENTS
  350. };
  351. // Called on clients in an MP game, does the actual interpolation for the entity.
  352. // This function will eventually replace ClientPredictionThink completely.
  353. virtual void ClientThink( const int curTime, const float fraction, const bool predict );
  354. virtual void ClientPredictionThink();
  355. virtual void WriteToSnapshot( idBitMsg &msg ) const;
  356. void ReadFromSnapshot_Ex( const idBitMsg &msg );
  357. virtual void ReadFromSnapshot( const idBitMsg &msg );
  358. virtual bool ServerReceiveEvent( int event, int time, const idBitMsg &msg );
  359. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  360. void WriteBindToSnapshot( idBitMsg &msg ) const;
  361. void ReadBindFromSnapshot( const idBitMsg &msg );
  362. void WriteColorToSnapshot( idBitMsg &msg ) const;
  363. void ReadColorFromSnapshot( const idBitMsg &msg );
  364. void WriteGUIToSnapshot( idBitMsg &msg ) const;
  365. void ReadGUIFromSnapshot( const idBitMsg &msg );
  366. void ServerSendEvent( int eventId, const idBitMsg *msg, bool saveEvent, lobbyUserID_t excluding = lobbyUserID_t() ) const;
  367. void ClientSendEvent( int eventId, const idBitMsg *msg ) const;
  368. void SetUseClientInterpolation( bool use ) { useClientInterpolation = use; }
  369. void SetSkipReplication( const bool skip ) { fl.skipReplication = skip; }
  370. bool GetSkipReplication() const { return fl.skipReplication; }
  371. bool IsReplicated() const { return GetEntityNumber() < ENTITYNUM_FIRST_NON_REPLICATED; }
  372. void CreateDeltasFromOldOriginAndAxis( const idVec3 & oldOrigin, const idMat3 & oldAxis );
  373. void DecayOriginAndAxisDelta();
  374. uint32 GetPredictedKey() { return predictionKey; }
  375. void SetPredictedKey( uint32 key_ ) { predictionKey = key_; }
  376. void FlagNewSnapshot();
  377. idEntity* GetTeamChain() { return teamChain; }
  378. // It is only safe to interpolate if this entity has received two snapshots.
  379. enum interpolationBehavior_t {
  380. USE_NO_INTERPOLATION,
  381. USE_LATEST_SNAP_ONLY,
  382. USE_INTERPOLATION
  383. };
  384. interpolationBehavior_t GetInterpolationBehavior() const { return interpolationBehavior; }
  385. unsigned int GetNumSnapshotsReceived() const { return snapshotsReceived; }
  386. protected:
  387. renderEntity_t renderEntity; // used to present a model to the renderer
  388. int modelDefHandle; // handle to static renderer model
  389. refSound_t refSound; // used to present sound to the audio engine
  390. idVec3 GetOriginDelta() const { return originDelta; }
  391. idMat3 GetAxisDelta() const { return axisDelta; }
  392. private:
  393. idPhysics_Static defaultPhysicsObj; // default physics object
  394. idPhysics * physics; // physics used for this entity
  395. idEntity * bindMaster; // entity bound to if unequal NULL
  396. jointHandle_t bindJoint; // joint bound to if unequal INVALID_JOINT
  397. int bindBody; // body bound to if unequal -1
  398. idEntity * teamMaster; // master of the physics team
  399. idEntity * teamChain; // next entity in physics team
  400. bool useClientInterpolation; // disables interpolation for some objects (handy for weapon world models)
  401. int numPVSAreas; // number of renderer areas the entity covers
  402. int PVSAreas[MAX_PVS_AREAS]; // numbers of the renderer areas the entity covers
  403. signalList_t * signals;
  404. int mpGUIState; // local cache to avoid systematic SetStateInt
  405. uint32 predictionKey; // Unique key used to sync predicted ents (projectiles) in MP.
  406. // Delta values that are set when the server or client disagree on where the render model should be. If this happens,
  407. // they resolve it through DecayOriginAndAxisDelta()
  408. idVec3 originDelta;
  409. idMat3 axisDelta;
  410. interpolationBehavior_t interpolationBehavior;
  411. unsigned int snapshotsReceived;
  412. private:
  413. void FixupLocalizedStrings();
  414. bool DoDormantTests(); // dormant == on the active list, but out of PVS
  415. // physics
  416. // initialize the default physics
  417. void InitDefaultPhysics( const idVec3 &origin, const idMat3 &axis );
  418. // update visual position from the physics
  419. void UpdateFromPhysics( bool moveBack );
  420. // get physics timestep
  421. virtual int GetPhysicsTimeStep() const;
  422. // entity binding
  423. bool InitBind( idEntity *master ); // initialize an entity binding
  424. void FinishBind(); // finish an entity binding
  425. void RemoveBinds(); // deletes any entities bound to this object
  426. void QuitTeam(); // leave the current team
  427. void UpdatePVSAreas();
  428. // events
  429. void Event_GetName();
  430. void Event_SetName( const char *name );
  431. void Event_FindTargets();
  432. void Event_ActivateTargets( idEntity *activator );
  433. void Event_NumTargets();
  434. void Event_GetTarget( float index );
  435. void Event_RandomTarget( const char *ignore );
  436. void Event_Bind( idEntity *master );
  437. void Event_BindPosition( idEntity *master );
  438. void Event_BindToJoint( idEntity *master, const char *jointname, float orientated );
  439. void Event_Unbind();
  440. void Event_RemoveBinds();
  441. void Event_SpawnBind();
  442. void Event_SetOwner( idEntity *owner );
  443. void Event_SetModel( const char *modelname );
  444. void Event_SetSkin( const char *skinname );
  445. void Event_GetShaderParm( int parmnum );
  446. void Event_SetShaderParm( int parmnum, float value );
  447. void Event_SetShaderParms( float parm0, float parm1, float parm2, float parm3 );
  448. void Event_SetColor( float red, float green, float blue );
  449. void Event_GetColor();
  450. void Event_IsHidden();
  451. void Event_Hide();
  452. void Event_Show();
  453. void Event_CacheSoundShader( const char *soundName );
  454. void Event_StartSoundShader( const char *soundName, int channel );
  455. void Event_StopSound( int channel, int netSync );
  456. void Event_StartSound( const char *soundName, int channel, int netSync );
  457. void Event_FadeSound( int channel, float to, float over );
  458. void Event_GetWorldOrigin();
  459. void Event_SetWorldOrigin( idVec3 const &org );
  460. void Event_GetOrigin();
  461. void Event_SetOrigin( const idVec3 &org );
  462. void Event_GetAngles();
  463. void Event_SetAngles( const idAngles &ang );
  464. void Event_SetLinearVelocity( const idVec3 &velocity );
  465. void Event_GetLinearVelocity();
  466. void Event_SetAngularVelocity( const idVec3 &velocity );
  467. void Event_GetAngularVelocity();
  468. void Event_SetSize( const idVec3 &mins, const idVec3 &maxs );
  469. void Event_GetSize();
  470. void Event_GetMins();
  471. void Event_GetMaxs();
  472. void Event_Touches( idEntity *ent );
  473. void Event_SetGuiParm( const char *key, const char *val );
  474. void Event_SetGuiFloat( const char *key, float f );
  475. void Event_GetNextKey( const char *prefix, const char *lastMatch );
  476. void Event_SetKey( const char *key, const char *value );
  477. void Event_GetKey( const char *key );
  478. void Event_GetIntKey( const char *key );
  479. void Event_GetFloatKey( const char *key );
  480. void Event_GetVectorKey( const char *key );
  481. void Event_GetEntityKey( const char *key );
  482. void Event_RestorePosition();
  483. void Event_UpdateCameraTarget();
  484. void Event_DistanceTo( idEntity *ent );
  485. void Event_DistanceToPoint( const idVec3 &point );
  486. void Event_StartFx( const char *fx );
  487. void Event_WaitFrame();
  488. void Event_Wait( float time );
  489. void Event_HasFunction( const char *name );
  490. void Event_CallFunction( const char *name );
  491. void Event_SetNeverDormant( int enable );
  492. void Event_SetGui( int guiNum, const char *guiName);
  493. void Event_PrecacheGui( const char *guiName );
  494. void Event_GetGuiParm(int guiNum, const char *key);
  495. void Event_GetGuiParmFloat(int guiNum, const char *key);
  496. void Event_GuiNamedEvent(int guiNum, const char *event);
  497. };
  498. /*
  499. ===============================================================================
  500. Animated entity base class.
  501. ===============================================================================
  502. */
  503. typedef struct damageEffect_s {
  504. jointHandle_t jointNum;
  505. idVec3 localOrigin;
  506. idVec3 localNormal;
  507. int time;
  508. const idDeclParticle* type;
  509. struct damageEffect_s * next;
  510. } damageEffect_t;
  511. class idAnimatedEntity : public idEntity {
  512. public:
  513. CLASS_PROTOTYPE( idAnimatedEntity );
  514. idAnimatedEntity();
  515. ~idAnimatedEntity();
  516. void Save( idSaveGame *savefile ) const;
  517. void Restore( idRestoreGame *savefile );
  518. virtual void ClientPredictionThink();
  519. virtual void ClientThink( const int curTime, const float fraction, const bool predict );
  520. virtual void Think();
  521. void UpdateAnimation();
  522. virtual idAnimator * GetAnimator();
  523. virtual void SetModel( const char *modelname );
  524. bool GetJointWorldTransform( jointHandle_t jointHandle, int currentTime, idVec3 &offset, idMat3 &axis );
  525. bool GetJointTransformForAnim( jointHandle_t jointHandle, int animNum, int currentTime, idVec3 &offset, idMat3 &axis ) const;
  526. virtual int GetDefaultSurfaceType() const;
  527. virtual void AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName );
  528. void AddLocalDamageEffect( jointHandle_t jointNum, const idVec3 &localPoint, const idVec3 &localNormal, const idVec3 &localDir, const idDeclEntityDef *def, const idMaterial *collisionMaterial );
  529. void UpdateDamageEffects();
  530. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  531. enum {
  532. EVENT_ADD_DAMAGE_EFFECT = idEntity::EVENT_MAXEVENTS,
  533. EVENT_MAXEVENTS
  534. };
  535. protected:
  536. idAnimator animator;
  537. damageEffect_t * damageEffects;
  538. private:
  539. void Event_GetJointHandle( const char *jointname );
  540. void Event_ClearAllJoints();
  541. void Event_ClearJoint( jointHandle_t jointnum );
  542. void Event_SetJointPos( jointHandle_t jointnum, jointModTransform_t transform_type, const idVec3 &pos );
  543. void Event_SetJointAngle( jointHandle_t jointnum, jointModTransform_t transform_type, const idAngles &angles );
  544. void Event_GetJointPos( jointHandle_t jointnum );
  545. void Event_GetJointAngle( jointHandle_t jointnum );
  546. };
  547. class SetTimeState {
  548. bool activated;
  549. bool previousFast;
  550. bool fast;
  551. public:
  552. SetTimeState();
  553. SetTimeState( int timeGroup );
  554. ~SetTimeState();
  555. void PushState( int timeGroup );
  556. };
  557. ID_INLINE SetTimeState::SetTimeState() {
  558. activated = false;
  559. }
  560. ID_INLINE SetTimeState::SetTimeState( int timeGroup ) {
  561. activated = false;
  562. PushState( timeGroup );
  563. }
  564. ID_INLINE void SetTimeState::PushState( int timeGroup ) {
  565. // Don't mess with time in Multiplayer
  566. if ( !common->IsMultiplayer() ) {
  567. activated = true;
  568. // determine previous fast setting
  569. if ( gameLocal.time == gameLocal.slow.time ) {
  570. previousFast = false;
  571. } else {
  572. previousFast = true;
  573. }
  574. // determine new fast setting
  575. if ( timeGroup ) {
  576. fast = true;
  577. } else {
  578. fast = false;
  579. }
  580. // set correct time
  581. gameLocal.SelectTimeGroup( timeGroup );
  582. }
  583. }
  584. ID_INLINE SetTimeState::~SetTimeState() {
  585. if ( activated && !common->IsMultiplayer() ) {
  586. // set previous correct time
  587. gameLocal.SelectTimeGroup( previousFast );
  588. }
  589. }
  590. #endif /* !__GAME_ENTITY_H__ */