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

  1.  
  2. #ifndef __GAME_ENTITY_H__
  3. #define __GAME_ENTITY_H__
  4.  
  5. /*
  6. ===============================================================================
  7.  
  8.     Game entity base class.
  9.  
  10. ===============================================================================
  11. */
  12.  
  13. static const int DELAY_DORMANT_TIME = 3000;
  14.  
  15. extern const idEventDef EV_PostSpawn;
  16. extern const idEventDef EV_FindTargets;
  17. extern const idEventDef EV_Touch;
  18. extern const idEventDef EV_Use;
  19. extern const idEventDef EV_Activate;
  20. extern const idEventDef EV_ActivateTargets;
  21. extern const idEventDef EV_Hide;
  22. extern const idEventDef EV_Show;
  23. extern const idEventDef EV_GetShaderParm;
  24. extern const idEventDef EV_SetShaderParm;
  25. extern const idEventDef EV_SetOwner;
  26. extern const idEventDef EV_GetAngles;
  27. extern const idEventDef EV_SetAngles;
  28. extern const idEventDef EV_SetLinearVelocity;
  29. extern const idEventDef EV_SetAngularVelocity;
  30. extern const idEventDef EV_SetSkin;
  31. extern const idEventDef EV_StartSoundShader;
  32. extern const idEventDef EV_StopSound;
  33. extern const idEventDef EV_CacheSoundShader;
  34.  
  35. // RAVEN BEGIN
  36. extern const idEventDef EV_CallFunction;
  37. extern const idEventDef EV_SetGuiParm;
  38. extern const idEventDef EV_SetGuiFloat;
  39. extern const idEventDef EV_ClearSkin;
  40. // bdube: more global events for idEntity
  41. extern const idEventDef EV_GetFloatKey;
  42. extern const idEventDef EV_HideSurface;
  43. extern const idEventDef EV_ShowSurface;
  44. extern const idEventDef EV_GuiEvent;
  45. extern const idEventDef EV_StopAllEffects;
  46. extern const idEventDef EV_PlayEffect;
  47. extern const idEventDef EV_Earthquake;
  48. extern const idEventDef EV_GuiEvent;
  49. extern const idEventDef EV_SetKey;
  50. // jscott:
  51. extern const idEventDef EV_PlaybackCallback;
  52. // jshepard:
  53. extern const idEventDef EV_UnbindTargets;
  54. // twhitaker:
  55. extern const idEventDef EV_ApplyImpulse;
  56. // RAVEN END
  57.  
  58. class idGuidedProjectile;
  59.  
  60. // Think flags
  61. enum {
  62.     TH_ALL                    = -1,
  63.     TH_THINK                = 1,        // run think function each frame
  64.     TH_PHYSICS                = 2,        // run physics each frame
  65.     TH_ANIMATE                = 4,        // update animation each frame
  66.     TH_UPDATEVISUALS        = 8,        // update renderEntity
  67. };
  68.  
  69. //
  70. // Signals
  71. // make sure to change script/doom_defs.script if you add any, or change their order
  72. //
  73. typedef enum {
  74.     SIG_TOUCH,                // object was touched
  75.     SIG_USE,                // object was used
  76.     SIG_TRIGGER,            // object was activated
  77.     SIG_REMOVED,            // object was removed from the game
  78.     SIG_DAMAGE,                // object was damaged
  79.     SIG_BLOCKED,            // object was blocked
  80.  
  81.     SIG_MOVER_POS1,            // mover at position 1 (door closed)
  82.     SIG_MOVER_POS2,            // mover at position 2 (door open)
  83.     SIG_MOVER_1TO2,            // mover changing from position 1 to 2
  84.     SIG_MOVER_2TO1,            // mover changing from position 2 to 1
  85.  
  86. // RAVEN BEGIN
  87. // kfuller: added signals
  88.     // WARNING: these entries are mirrored in scripts/defs.script so make sure if they move
  89.     //          here that they move there as well
  90.     SIG_REACHED,            // object reached it's rotation/motion destination
  91. // RAVEN END
  92.  
  93.     NUM_SIGNALS
  94. } signalNum_t;
  95.  
  96. // FIXME: At some point we may want to just limit it to one thread per signal, but
  97. // for now, I'm allowing multiple threads.  We should reevaluate this later in the project
  98. #define MAX_SIGNAL_THREADS 16        // probably overkill, but idList uses a granularity of 16
  99.  
  100. struct signal_t {
  101.     int                    threadnum;
  102.     const function_t    *function;
  103. };
  104.  
  105. class signalList_t {
  106. public:
  107.     idList<signal_t> signal[ NUM_SIGNALS ];
  108. };
  109.  
  110. class idEntity : public idClass {
  111. public:
  112.     static const int        MAX_PVS_AREAS = 4;
  113.  
  114.     int                        entityNumber;            // index into the entity list
  115.     int                        entityDefNumber;        // index into the entity def list
  116.  
  117.     idLinkList<idEntity>    spawnNode;                // for being linked into spawnedEntities list
  118.     idLinkList<idEntity>    activeNode;                // for being linked into activeEntities list
  119.  
  120.     idLinkList<idEntity>    snapshotNode;            // for being linked into snapshotEntities list
  121.     int                        snapshotSequence;        // last snapshot this entity was in
  122.     int                        snapshotBits;            // number of bits this entity occupied in the last snapshot
  123.  
  124.     idStr                    name;                    // name of entity
  125.     idDict                    spawnArgs;                // key/value pairs used to spawn and initialize entity
  126.     idScriptObject            scriptObject;            // contains all script defined data for this entity
  127.  
  128.     int                        thinkFlags;                // TH_? flags
  129.     int                        dormantStart;            // time that the entity was first closed off from player
  130.     bool                    cinematic;                // during cinematics, entity will only think if cinematic is set
  131.  
  132.     renderView_t *            renderView;                // for camera views from this entity
  133.     idEntity *                cameraTarget;            // any remoteRenderMap shaders will use this
  134.  
  135.     idList< idEntityPtr<idEntity> >    targets;        // when this entity is activated these entities entity are activated
  136.  
  137.     int                        health;                    // FIXME: do all objects really need health?
  138.  
  139. // RAVEN BEGIN
  140. // ddynerman: optional pre-prediction
  141.     int                        predictTime;
  142. // bdube: client entities
  143.     idLinkList<rvClientEntity>    clientEntities;
  144.  
  145. // rjohnson: will now draw entity info for long thinkers
  146.     int                        mLastLongThinkTime;
  147.     idVec4                    mLastLongThinkColor;
  148. // RAVEN END
  149.  
  150.     struct entityFlags_s {
  151.         bool                notarget            :1;    // if true never attack or target this entity
  152.         bool                noknockback            :1;    // if true no knockback from hits
  153.         bool                takedamage            :1;    // if true this entity can be damaged
  154.         bool                hidden                :1;    // if true this entity is not visible
  155.         bool                bindOrientated        :1;    // if true both the master orientation is used for binding
  156.         bool                solidForTeam        :1;    // if true this entity is considered solid when a physics team mate pushes entities
  157.         bool                forcePhysicsUpdate    :1;    // if true always update from the physics whether the object moved or not
  158.         bool                selected            :1;    // if true the entity is selected for editing
  159.         bool                neverDormant        :1;    // if true the entity never goes dormant
  160.         bool                isDormant            :1;    // if true the entity is dormant
  161.         bool                hasAwakened            :1;    // before a monster has been awakened the first time, use full PVS for dormant instead of area-connected
  162.         bool                networkSync            :1; // if true the entity is synchronized over the network
  163.  
  164. // RAVEN BEGIN
  165. // bdube: added            
  166.         bool                networkStale        :1; // was in the snapshot but isnt anymore
  167. // bgeisler: added block
  168.         bool                triggerAnim            :1;
  169.         bool                usable                :1;    // if true the entity is usable by the player
  170. // cdr: Obstacle Avoidance
  171.         bool                isAIObstacle        :1; // if true, this entity will add itself to the obstacles list in each aas area it touches
  172. // RAVEN END
  173.  
  174. // RAVEN BEGIN
  175. // ddynerman: exclude this entity from instance-purging
  176.     // twhitaker: moved variable to be within the bit flags
  177.         bool                persistAcrossInstances    :1;
  178. // twhitaker: exited vehicle already?
  179.         bool                exitedVehicle            :1;
  180. // twhitaker: blinking
  181.         bool                allowAutoBlink            :1;
  182. // RAVEN END
  183.     } fl;
  184.  
  185. public:
  186.     ABSTRACT_PROTOTYPE( idEntity );
  187.  
  188.                             idEntity();
  189.                             ~idEntity();
  190.  
  191.     void                    Spawn( void );
  192.  
  193.     void                    Save( idSaveGame *savefile ) const;
  194.     void                    Restore( idRestoreGame *savefile );
  195.  
  196.     const char *            GetEntityDefName( void ) const;
  197.     void                    SetName( const char *name );
  198.     const char *            GetName( void ) const;
  199.     virtual void            UpdateChangeableSpawnArgs( const idDict *source );
  200.  
  201.                             // clients generate views based on all the player specific options,
  202.                             // cameras have custom code, and everything else just uses the axis orientation
  203.     virtual renderView_t *    GetRenderView();
  204.  
  205.     // thinking
  206.     virtual void            Think( void );
  207.     bool                    CheckDormant( void );    // dormant == on the active list, but out of PVS
  208.     virtual    void            DormantBegin( void );    // called when entity becomes dormant
  209.     virtual    void            DormantEnd( void );        // called when entity wakes from being dormant
  210.     bool                    IsActive( void ) const;
  211.     void                    BecomeActive( int flags );
  212.     void                    BecomeInactive( int flags );
  213.     void                    UpdatePVSAreas( const idVec3 &pos );
  214.  
  215. // RAVEN BEGIN
  216. // abahr:
  217.     bool                    IsActive( int flags ) const { return (flags & thinkFlags) > 0; }
  218.     const char*                GetEntityDefClassName() const { return spawnArgs.GetString("classname"); }
  219.     bool                    IsEntityDefClass( const char* className ) const { return !idStr::Icmp(className, GetEntityDefClassName()); }
  220.     virtual void            GetPosition( idVec3& origin, idMat3& axis ) const;
  221. // kfuller: added methods
  222.     virtual void            GetLocalAngles(idAngles &localAng);
  223. // RAVEN END
  224.  
  225.     // visuals
  226.     virtual void            Present( void );
  227.     // instance visuals
  228.     virtual void            InstanceJoin( void );
  229.     virtual void            InstanceLeave( void );
  230. // RAVEN BEGIN
  231. // bdube: removed virtual so it could be inlined
  232.     renderEntity_t *        GetRenderEntity( void );
  233.     int                        GetModelDefHandle( void );
  234. // RAVEN END
  235.     virtual void            SetModel( const char *modelname );
  236.     void                    SetSkin( const idDeclSkin *skin );
  237.     const idDeclSkin *        GetSkin( void ) const;
  238.  
  239. // RAVEN BEGIN
  240. // bdube: surfaces
  241.     void                    HideSurface ( const char* surface );
  242.     void                    ShowSurface ( const char* surface );
  243.     void                    ClearSkin( void );
  244. // RAVEN END
  245.  
  246.     void                    SetShaderParm( int parmnum, float value );
  247.     virtual void            SetColor( float red, float green, float blue );
  248.     virtual void            SetColor( const idVec3 &color );
  249.     virtual void            GetColor( idVec3 &out ) const;
  250.     virtual void            SetColor( const idVec4 &color );
  251.     virtual void            GetColor( idVec4 &out ) const;
  252.     virtual void            FreeModelDef( void );
  253.     virtual void            FreeLightDef( void );
  254.     virtual void            Hide( void );
  255.     virtual void            Show( void );
  256.     bool                    IsHidden( void ) const;
  257.     void                    UpdateVisuals( void );
  258.     void                    UpdateModel( void );
  259. // RAVEN BEGIN
  260. // abahr: added virtual to UpdateModelTransform
  261.     virtual
  262.     void                    UpdateModelTransform( void );
  263.     virtual void            UpdateRenderEntityCallback();
  264.     virtual const idAnimator *    GetAnimator( void ) const { return NULL; }    // returns animator object used by this entity
  265. // RAVEN END
  266.     virtual void            ProjectOverlay( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
  267.     int                        GetNumPVSAreas( void );
  268.     const int *                GetPVSAreas( void );
  269.     void                    ClearPVSAreas( void );
  270.     bool                    PhysicsTeamInPVS( pvsHandle_t pvsHandle );
  271.  
  272.     // animation
  273.     virtual bool            UpdateAnimationControllers( void );
  274.     bool                    UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView );
  275.     static bool                ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView );
  276.     virtual idAnimator *    GetAnimator( void );    // returns animator object used by this entity
  277.  
  278.     // sound
  279.     virtual bool            CanPlayChatterSounds( void ) const;
  280.     bool                    StartSound( const char *soundName, const s_channelType channel, int soundShaderFlags, bool broadcast, int *length );
  281.     bool                    StartSoundShader( const idSoundShader *shader, const s_channelType channel, int soundShaderFlags, bool broadcast, int *length );
  282.     void                    StopSound( const s_channelType channel, bool broadcast );    // pass SND_CHANNEL_ANY to stop all sounds
  283.     void                    SetSoundVolume( float volume );
  284.     void                    UpdateSound( void );
  285.     int                        GetListenerId( void ) const;
  286. // RAVEN BEGIN
  287.     int                        GetSoundEmitter( void ) const;
  288. // RAVEN END
  289.     void                    FreeSoundEmitter( bool immediate );
  290.  
  291. // RAVEN BEGIN
  292. // bdube: added effect functions
  293.     // effects
  294.     rvClientEffect*            PlayEffect        ( const char* effectName, jointHandle_t joint, const idVec3& originOffset, const idMat3& axisOffset, bool loop = false, const idVec3& endOrigin = vec3_origin, bool broadcast = false, effectCategory_t category = EC_IGNORE, const idVec4& effectTint = vec4_one );
  295.     rvClientEffect*            PlayEffect        ( const idDecl *effect, jointHandle_t joint, const idVec3& originOffset, const idMat3& axisOffset, bool loop = false, const idVec3& endOrigin = vec3_origin, bool broadcast = false, effectCategory_t category = EC_IGNORE, const idVec4& effectTint = vec4_one );
  296.     rvClientEffect*            PlayEffect        ( const char* effectName, jointHandle_t joint, bool loop = false, const idVec3& endOrigin = vec3_origin, bool broadcast = false, effectCategory_t category = EC_IGNORE, const idVec4& effectTint = vec4_one );
  297.  
  298.     rvClientEffect*            PlayEffect        ( const char* effectName, const idVec3& origin, const idMat3& axis, bool loop = false, const idVec3& endOrigin = vec3_origin, bool broadcast = false, effectCategory_t category = EC_IGNORE, const idVec4& effectTint = vec4_one );
  299.     rvClientEffect*            PlayEffect        ( const idDecl *effect, const idVec3& origin, const idMat3& axis, bool loop = false, const idVec3& endOrigin = vec3_origin, bool broadcast = false, effectCategory_t category = EC_IGNORE, const idVec4& effectTint = vec4_one );
  300.     void                    StopEffect        ( const char* effectName, bool destroyParticles = false );
  301.     void                    StopEffect        ( const idDecl *effect, bool destroyParticles = false );
  302.     void                    StopAllEffects    ( bool destroyParticles = false );
  303.     void                    UpdateEffects    ( void );
  304.  
  305.     float                    DistanceTo        ( idEntity* ent );
  306.     float                    DistanceTo        ( const idVec3& pos ) const;
  307.     float                    DistanceTo2d    ( idEntity* ent );
  308.     float                    DistanceTo2d    ( const idVec3& pos ) const;
  309.  
  310.     virtual bool            CanTakeDamage    ( void ) const;
  311. // RAVEN END
  312.  
  313.     // entity binding
  314.     virtual void            PreBind( void );
  315.     virtual void            PostBind( void );
  316.     virtual void            PreUnbind( void );
  317.     virtual void            PostUnbind( void );
  318.     void                    JoinTeam( idEntity *teammember );
  319.     void                    Bind( idEntity *master, bool orientated );
  320.     void                    BindToJoint( idEntity *master, const char *jointname, bool orientated );
  321.     void                    BindToJoint( idEntity *master, jointHandle_t jointnum, bool orientated );
  322.     void                    BindToBody( idEntity *master, int bodyId, bool orientated );
  323.     void                    Unbind( void );
  324.     bool                    IsBound( void ) const;
  325. // RAVEN BEGIN
  326. // abahr: added const so it can be called from const functions
  327.     bool                    IsBoundTo( const idEntity *master ) const;
  328. // RAVEN END
  329.     idEntity *                GetBindMaster( void ) const;
  330.     jointHandle_t            GetBindJoint( void ) const;
  331.     int                        GetBindBody( void ) const;
  332.     idEntity *                GetTeamMaster( void ) const;
  333.     idEntity *                GetNextTeamEntity( void ) const;
  334. // RAVEN BEGIN
  335. // abahr: added virtual
  336.     virtual
  337.     void                    ConvertLocalToWorldTransform( idVec3 &offset, idMat3 &axis );
  338. // RAVEN END
  339.     idVec3                    GetLocalVector( const idVec3 &vec ) const;
  340.     idVec3                    GetLocalCoordinates( const idVec3 &vec ) const;
  341.     idVec3                    GetWorldVector( const idVec3 &vec ) const;
  342.     idVec3                    GetWorldCoordinates( const idVec3 &vec ) const;
  343. // RAVEN BEGIN
  344. // abahr: made virtual
  345.     virtual
  346. // RAVEN END
  347.     bool                    GetMasterPosition( idVec3 &masterOrigin, idMat3 &masterAxis ) const;
  348.     void                    GetWorldVelocities( idVec3 &linearVelocity, idVec3 &angularVelocity ) const;
  349.  
  350.     // physics
  351.                             // set a new physics object to be used by this entity
  352.     void                    SetPhysics( idPhysics *phys );
  353.                             // get the physics object used by this entity
  354.     idPhysics *                GetPhysics( void ) const;
  355.                             // restore physics pointer for save games
  356.     void                    RestorePhysics( idPhysics *phys );
  357.                             // run the physics for this entity
  358.     bool                    RunPhysics( void );
  359.                             // set the origin of the physics object (relative to bindMaster if not NULL)
  360.     void                    SetOrigin( const idVec3 &org );
  361.                             // set the axis of the physics object (relative to bindMaster if not NULL)
  362.     void                    SetAxis( const idMat3 &axis );
  363.                             // use angles to set the axis of the physics object (relative to bindMaster if not NULL)
  364.     void                    SetAngles( const idAngles &ang );
  365.                             // get the floor position underneath the physics object
  366.     bool                    GetFloorPos( float max_dist, idVec3 &floorpos ) const;
  367.                             // retrieves the transformation going from the physics origin/axis to the visual origin/axis
  368.     virtual bool            GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
  369.                             // retrieves the transformation going from the physics origin/axis to the sound origin/axis
  370.     virtual bool            GetPhysicsToSoundTransform( idVec3 &origin, idMat3 &axis );
  371.                             // called from the physics object when colliding, should return true if the physics simulation should stop
  372.     virtual bool            Collide( const trace_t &collision, const idVec3 &velocity );
  373.                             // retrieves impact information, 'ent' is the entity retrieving the info
  374.     virtual void            GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info );
  375.                             // apply an impulse to the physics object, 'ent' is the entity applying the impulse
  376.     virtual void            ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse, bool splash = false );
  377.                             // add a force to the physics object, 'ent' is the entity adding the force
  378.     virtual void            AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
  379.                             // activate the physics object, 'ent' is the entity activating this entity
  380.     virtual void            ActivatePhysics( idEntity *ent );
  381.                             // returns true if the physics object is at rest
  382.     virtual bool            IsAtRest( void ) const;
  383.                             // returns the time the physics object came to rest
  384.     virtual int                GetRestStartTime( void ) const;
  385.                             // add a contact entity
  386.     virtual void            AddContactEntity( idEntity *ent );
  387.                             // remove a touching entity
  388.     virtual void            RemoveContactEntity( idEntity *ent );
  389.  
  390. // RAVEN BEGIN
  391. // kfuller: added blocked methods
  392.     virtual void            LastBlockedBy(int blockedEntNum) {}
  393.     virtual int                GetLastBlocker(void) { return -1; }
  394. // rjohnson: moved entity info out of idGameLocal into its own function
  395.     virtual void            DrawDebugEntityInfo( idBounds *viewBounds = 0, idBounds *viewTextBounds = 0, idVec4 *overrideColor = 0 );
  396. // nmckenzie: Adding ability for non-Actors to be enemies for AI characters.  Rename this function at some point, most likely.
  397.     virtual idVec3            GetEyePosition( void ) const { return GetPhysics()->GetOrigin(); }
  398. // abahr:
  399.     virtual bool            SkipImpulse( idEntity *ent, int id );
  400.     virtual void            ApplyImpulse( idEntity* ent, int id, const idVec3& point, const idVec3& dir, const idDict* damageDef );
  401. // RAVEN END
  402.  
  403.     // damage
  404. // RAVEN BEGIN
  405.     // twhitaker:            // Sets the damage enitty 
  406.     void                    SetDamageEntity ( idEntity * forward ) { forwardDamageEnt = forward; }
  407.  
  408.     // bdube: added ignore entity
  409.                             // Returns the entity that should take damage for this entity
  410.     virtual idEntity*        GetDamageEntity ( void );
  411.  
  412.                             // returns true if this entity can be damaged from the given origin
  413.     virtual bool            CanDamage( const idVec3 &origin, idVec3 &damagePoint, idEntity* ignoreEnt = NULL ) const;
  414. // RAVEN END
  415.                             // applies damage to this entity
  416.     virtual    void            Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
  417.                             // adds a damage effect like overlays, blood, sparks, debris etc.
  418.     virtual void            AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName, idEntity* inflictor );
  419.     virtual bool            CanPlayImpactEffect ( idEntity* attacker, idEntity* target );
  420.                             // callback function for when another entity recieved damage from this entity.  damage can be adjusted and returned to the caller.
  421.     virtual void            DamageFeedback( idEntity *victim, idEntity *inflictor, int &damage );
  422.                             // notifies this entity that it is in pain
  423.     virtual bool            Pain( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  424.                             // notifies this entity that is has been killed
  425.     virtual void            Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  426.  
  427.     // scripting
  428.     virtual bool            ShouldConstructScriptObjectAtSpawn( void ) const;
  429.     virtual idThread *        ConstructScriptObject( void );
  430.     virtual void            DeconstructScriptObject( void );
  431.     void                    SetSignal( signalNum_t signalnum, idThread *thread, const function_t *function );
  432.     void                    ClearSignal( idThread *thread, signalNum_t signalnum );
  433.     void                    ClearSignalThread( signalNum_t signalnum, idThread *thread );
  434.     bool                    HasSignal( signalNum_t signalnum ) const;
  435.     void                    Signal( signalNum_t signalnum );
  436.     void                    SignalEvent( idThread *thread, signalNum_t signalnum );
  437.  
  438.     // gui
  439.     void                    TriggerGuis( void );
  440.     bool                    HandleGuiCommands( idEntity *entityGui, const char *cmds );
  441.     virtual bool            HandleSingleGuiCommand( idEntity *entityGui, idLexer *src );
  442.  
  443.     // targets
  444. // RAVEN BEGIN
  445. // abahr: made virtual
  446.     virtual
  447.     void                    FindTargets( void );
  448.     virtual
  449.     void                    RemoveNullTargets( void );
  450.     virtual
  451.     void                    ActivateTargets( idEntity *activator ) const;
  452. // jshepard: unbind targets
  453.     void                    UnbindTargets( idEntity *activator ) const;
  454. // RAVEN END
  455.  
  456. // RAVEN BEGIN
  457. // twhitaker: Add to the list of targets (usually from script)
  458.     int                        AppendTarget( idEntity *appendMe );
  459.     void                    RemoveTarget( idEntity *removeMe );
  460.     void                    RemoveTargets( bool destroyContents );
  461. // RAVEN END
  462.  
  463.     // misc
  464.     virtual void            Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination );
  465.     bool                    TouchTriggers( void ) const;
  466.     idCurve_Spline<idVec3> *GetSpline( void ) const;
  467.     virtual void            ShowEditingDialog( void );
  468.  
  469.     enum {
  470.         EVENT_STARTSOUNDSHADER,
  471.         EVENT_STOPSOUNDSHADER,
  472. // RAVEN BEGIN        
  473. // bdube: new events
  474.         EVENT_PLAYEFFECT,
  475.         EVENT_PLAYEFFECT_JOINT,
  476.         EVENT_STOPEFFECT,
  477. // RAVEN END
  478.         EVENT_MAXEVENTS
  479.     };
  480.  
  481.     virtual void            ClientPredictionThink( void );
  482.     virtual void            WriteToSnapshot( idBitMsgDelta &msg ) const;
  483.     virtual void            ReadFromSnapshot( const idBitMsgDelta &msg );
  484.     virtual bool            ServerReceiveEvent( int event, int time, const idBitMsg &msg );
  485.     virtual bool            ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  486. // RAVEN BEGIN
  487.     // the entity was not in the snapshot sent by server. means it either went out of PVS, or was deleted server side
  488.     // return true if the entity wishes to be deleted locally
  489.     // depending on the entity, understanding stale as just another state, or a removal is best
  490.     // ( by default, idEntity keeps the entity around after a little cleanup )
  491.     virtual bool            ClientStale( void );
  492.     virtual void            ClientUnstale( void );
  493. // RAVEN END
  494.  
  495.     void                    WriteBindToSnapshot( idBitMsgDelta &msg ) const;
  496.     void                    ReadBindFromSnapshot( const idBitMsgDelta &msg );
  497.     void                    WriteColorToSnapshot( idBitMsgDelta &msg ) const;
  498.     void                    ReadColorFromSnapshot( const idBitMsgDelta &msg );
  499.     void                    WriteGUIToSnapshot( idBitMsgDelta &msg ) const;
  500.     void                    ReadGUIFromSnapshot( const idBitMsgDelta &msg );
  501.  
  502.     void                    ServerSendEvent( int eventId, const idBitMsg *msg, bool saveEvent, int excludeClient ) const;
  503.     void                    ServerSendInstanceEvent( int eventId, const idBitMsg *msg, bool saveEvent, int excludeClient ) const;
  504.     void                    ClientSendEvent( int eventId, const idBitMsg *msg ) const;
  505.  
  506. // RAVEN BEGIN
  507. // bdube: debugging
  508.     virtual void            GetDebugInfo( debugInfoProc_t proc, void* userData );
  509. // mwhitlock: memory profiling
  510.     virtual size_t            Size( void ) const;
  511. // ddynerman: multiple arenas (for MP)
  512.     virtual void            SetInstance( int newInstance );
  513.     virtual int                GetInstance( void ) const;
  514. // ddynerman: multiple clip world support
  515.     virtual int                GetClipWorld( void ) const;
  516.     virtual void            SetClipWorld( int newCW );
  517. // scork: accessors so sound editor can indicate current-highlit ent
  518.     virtual int                GetRefSoundShaderFlags( void ) const;
  519.     virtual void            SetRefSoundShaderFlags( int iFlags );
  520. // twhitaker: guided projectiles
  521.     virtual void            GuidedProjectileIncoming( idGuidedProjectile * projectile ) { }
  522. // RAVEN END
  523.  
  524. protected:
  525.     renderEntity_t            renderEntity;                        // used to present a model to the renderer
  526.     int                        modelDefHandle;                        // handle to static renderer model
  527.     refSound_t                refSound;                            // used to present sound to the audio engine
  528.     idEntityPtr< idEntity >    forwardDamageEnt;                    // damage applied to the invoking object will be forwarded to this entity
  529. private:
  530.     idPhysics_Static        defaultPhysicsObj;                    // default physics object
  531.     idPhysics *                physics;                            // physics used for this entity
  532.     idEntity *                bindMaster;                            // entity bound to if unequal NULL
  533.     jointHandle_t            bindJoint;                            // joint bound to if unequal INVALID_JOINT
  534.     int                        bindBody;                            // body bound to if unequal -1
  535.     idEntity *                teamMaster;                            // master of the physics team
  536.     idEntity *                teamChain;                            // next entity in physics team
  537.  
  538.     int                        numPVSAreas;                        // number of renderer areas the entity covers
  539.     int                        PVSAreas[MAX_PVS_AREAS];            // numbers of the renderer areas the entity covers
  540.  
  541.     signalList_t *            signals;
  542.  
  543.     int                        mpGUIState;                            // local cache to avoid systematic SetStateInt
  544. // RAVEN BEGIN
  545. // abahr: changed to protected for access in children classes
  546. protected:
  547. // ddynerman: multiple game instances
  548.     int                        instance;
  549. // ddynerman: multiple collision worlds
  550.     int                        clipWorld;
  551. // RAVEN END
  552.  
  553. // RAVEN BEGIN
  554. // bdube: made virtual
  555.     virtual bool            DoDormantTests( void );                // dormant == on the active list, but out of PVS
  556. // RAVEN END
  557.  
  558.     // physics
  559.                             // initialize the default physics
  560.     void                    InitDefaultPhysics( const idVec3 &origin, const idMat3 &axis );
  561.                             // update visual position from the physics
  562.     void                    UpdateFromPhysics( bool moveBack );
  563.  
  564.     // entity binding
  565.     bool                    InitBind( idEntity *master );        // initialize an entity binding
  566.     void                    FinishBind( void );                    // finish an entity binding
  567.     void                    RemoveBinds( void );                // deletes any entities bound to this object
  568.     void                    QuitTeam( void );                    // leave the current team
  569.  
  570.     void                    UpdatePVSAreas( void );
  571.  
  572. // RAVEN BEGIN
  573. // bdube: client entities
  574.     void                    RemoveClientEntities ( void );        // deletes any client entities bound to this object
  575. // RAVEN END
  576.  
  577.     // events
  578.     void                    Event_GetName( void );
  579.     void                    Event_SetName( const char *name );
  580.     void                    Event_FindTargets( void );
  581.     void                    Event_ActivateTargets( idEntity *activator );
  582.     void                    Event_NumTargets( void );
  583.     void                    Event_GetTarget( float index );
  584.     void                    Event_RandomTarget( const char *ignore );
  585.     void                    Event_Bind( idEntity *master );
  586.     void                    Event_BindPosition( idEntity *master );
  587.     void                    Event_BindToJoint( idEntity *master, const char *jointname, float orientated );
  588.     void                    Event_Unbind( void );
  589.     void                    Event_RemoveBinds( void );
  590.     void                    Event_SpawnBind( void );
  591.     void                    Event_SetOwner( idEntity *owner );
  592.     void                    Event_SetModel( const char *modelname );
  593.     void                    Event_SetSkin( const char *skinname );
  594.     void                    Event_GetShaderParm( int parmnum );
  595.     void                    Event_SetShaderParm( int parmnum, float value );
  596.     void                    Event_SetShaderParms( float parm0, float parm1, float parm2, float parm3 );
  597.     void                    Event_SetColor( float red, float green, float blue );
  598.     void                    Event_GetColor( void );
  599.     void                    Event_IsHidden( void );
  600.     void                    Event_Hide( void );
  601.     void                    Event_Show( void );
  602.     void                    Event_CacheSoundShader( const char *soundName );
  603.     void                    Event_StartSoundShader( const char *soundName, int channel );
  604.     void                    Event_StopSound( int channel, int netSync );
  605.     void                    Event_StartSound( const char *soundName, int channel, int netSync );
  606.     void                    Event_FadeSound( int channel, float to, float over );
  607.     void                    Event_GetWorldOrigin( void );
  608.     void                    Event_SetWorldOrigin( idVec3 const &org );
  609.     void                    Event_GetOrigin( void );
  610.     void                    Event_SetOrigin( const idVec3 &org );
  611.     void                    Event_GetAngles( void );
  612.     void                    Event_SetAngles( const idAngles &ang );
  613.     void                    Event_SetLinearVelocity( const idVec3 &velocity );
  614.     void                    Event_GetLinearVelocity( void );
  615.     void                    Event_SetAngularVelocity( const idVec3 &velocity );
  616.     void                    Event_GetAngularVelocity( void );
  617.     void                    Event_SetSize( const idVec3 &mins, const idVec3 &maxs );
  618.     void                    Event_GetSize( void );
  619.     void                    Event_GetMins( void );
  620.     void                    Event_GetMaxs( void );
  621.     void                    Event_Touches( idEntity *ent );
  622.     void                    Event_SetGuiParm( const char *key, const char *val );
  623.     void                    Event_SetGuiFloat( const char *key, float f );
  624.     void                    Event_GetNextKey( const char *prefix, const char *lastMatch );
  625.     void                    Event_SetKey( const char *key, const char *value );
  626.     void                    Event_GetKey( const char *key );
  627.     void                    Event_GetIntKey( const char *key );
  628.     void                    Event_GetFloatKey( const char *key );
  629.     void                    Event_GetVectorKey( const char *key );
  630.     void                    Event_GetEntityKey( const char *key );
  631.     void                    Event_RestorePosition( void );
  632.     void                    Event_UpdateCameraTarget( void );
  633.     void                    Event_DistanceTo( idEntity *ent );
  634.     void                    Event_DistanceToPoint( const idVec3 &point );
  635.     void                    Event_StartFx( const char *fx );
  636.     void                    Event_WaitFrame( void );
  637.     void                    Event_Wait( float time );
  638.     void                    Event_HasFunction( const char *name );
  639.     void                    Event_CallFunction( const char *name );
  640.     void                    Event_SetNeverDormant( int enable );
  641.  
  642. // RAVEN BEGIN
  643. // kfuller: added events
  644.     void                    Event_SetContents                ( int contents );
  645.     void                    Event_GetLastBlocker            ( idThread *thread );
  646. // begisler: added
  647.     void                    Event_ClearSkin                    ( void );
  648. // bdube: effect events
  649.     void                    Event_PlayEffect                ( const char* effectName, const char* boneName, bool loop );
  650.     void                    Event_StopEffect                ( const char* effectName );
  651.     void                    Event_StopAllEffects            ( void );
  652.     void                    Event_GetHealth                    ( void );
  653. // bdube: mesh events
  654.     void                    Event_ShowSurface                ( const char* surface );
  655.     void                    Event_HideSurface                ( const char* surface );
  656. // bdube: gui events
  657.     void                    Event_GuiEvent                    ( const char* eventName );
  658. // jscott:
  659.     void                    Event_PlaybackCallback            ( int type, int changed, int impulse );
  660. // nmckenzie: get bind master
  661.     void                    Event_GetBindMaster                ( void );
  662.     void                    Event_ApplyImpulse                ( idEntity *source, const idVec3 &point, const idVec3 &impulse );
  663. // jshepard: unbind all targets
  664.     void                    Event_UnbindTargets                ( idEntity *activator);
  665. // abahr:
  666.     void                    Event_RemoveNullTargets            ();
  667.     void                    Event_IsA                        ( const char* entityDefName );
  668.     void                    Event_IsSameTypeAs                ( const idEntity* ent );
  669.     void                    Event_MatchPrefix                ( const char *prefix, const char* previousKey );
  670.     void                    Event_ClearTargetList            ( float destroyContents );
  671. // twhitaker: added - to add targets from script
  672.     void                    Event_AppendTarget                ( idEntity *appendMe );
  673.     void                    Event_RemoveTarget                ( idEntity *removeMe );
  674. // mekberg: added
  675.     void                    Event_SetHealth                    ( float newHealth );
  676. // RAVEN END
  677. };
  678.  
  679. // RAVEN BEGIN
  680. // bdube: added inlines
  681. ID_INLINE rvClientEffect* idEntity::PlayEffect ( const char* effectName, const idVec3& origin, const idMat3& axis, bool loop, const idVec3& endOrigin, 
  682.                                                  bool broadcast, effectCategory_t category, const idVec4& effectTint ) { 
  683.     return PlayEffect ( gameLocal.GetEffect( spawnArgs, effectName ), origin, axis, loop, endOrigin, broadcast, category, effectTint );
  684. }
  685.  
  686. ID_INLINE rvClientEffect* idEntity::PlayEffect ( const char* effectName, jointHandle_t jointHandle, bool loop, const idVec3& endOrigin, 
  687.                                                 bool broadcast, effectCategory_t category, const idVec4& effectTint ) { 
  688.     return PlayEffect ( gameLocal.GetEffect( spawnArgs, effectName ), jointHandle, vec3_origin, mat3_identity, loop, endOrigin, broadcast, category, effectTint );
  689. }
  690.  
  691. ID_INLINE rvClientEffect* idEntity::PlayEffect ( const char* effectName, jointHandle_t jointHandle, const idVec3& originOffset, const idMat3& axisOffset, bool loop, const idVec3& endOrigin, 
  692.                                                 bool broadcast, effectCategory_t category, const idVec4& effectTint ) { 
  693.     return PlayEffect ( gameLocal.GetEffect( spawnArgs, effectName ), jointHandle, originOffset, axisOffset, loop, endOrigin, broadcast, category, effectTint );
  694. }
  695.  
  696.  
  697. ID_INLINE idPhysics *idEntity::GetPhysics( void ) const {
  698.     return physics;
  699. }
  700.  
  701. ID_INLINE renderEntity_t *idEntity::GetRenderEntity( void ) {
  702.     return &renderEntity;
  703. }
  704.  
  705. ID_INLINE int idEntity::GetModelDefHandle( void ) {
  706.     return modelDefHandle;
  707. }
  708.  
  709. // scork: accessors so sound editor can indicate current-highlit ent
  710. ID_INLINE int idEntity::GetRefSoundShaderFlags( void ) const
  711. {
  712.     return refSound.parms.soundShaderFlags;
  713. }
  714.  
  715. ID_INLINE void idEntity::SetRefSoundShaderFlags( int iFlags )
  716. {
  717.     refSound.parms.soundShaderFlags = iFlags;
  718. }
  719.  
  720.  
  721. // RAVEN END
  722.  
  723. /*
  724. ===============================================================================
  725.  
  726.     Animated entity base class.
  727.  
  728. ===============================================================================
  729. */
  730.  
  731. typedef struct damageEffect_s {
  732.     jointHandle_t            jointNum;
  733.     idVec3                    localOrigin;
  734.     idVec3                    localNormal;
  735.     int                        time;
  736. // RAVEN BEGIN
  737. // jscott: not using
  738. //    const idDeclParticle*    type;
  739. // RAVEN END
  740.     struct damageEffect_s *    next;
  741. } damageEffect_t;
  742.  
  743. class idAnimatedEntity : public idEntity {
  744. public:
  745.     CLASS_PROTOTYPE( idAnimatedEntity );
  746.  
  747.                             idAnimatedEntity();
  748.                             ~idAnimatedEntity();
  749.  
  750.     void                    Save( idSaveGame *savefile ) const;
  751.     void                    Restore( idRestoreGame *savefile );
  752.  
  753.     virtual void            ClientPredictionThink( void );
  754.     virtual void            Think( void );
  755.  
  756.     void                    UpdateAnimation( void );
  757.  
  758.     virtual idAnimator *    GetAnimator( void );
  759.     virtual void            SetModel( const char *modelname );
  760.  
  761.     bool                    GetJointWorldTransform( jointHandle_t jointHandle, int currentTime, idVec3 &offset, idMat3 &axis );
  762.     bool                    GetJointTransformForAnim( jointHandle_t jointHandle, int animNum, int currentTime, idVec3 &offset, idMat3 &axis ) const;
  763.  
  764.     virtual int                GetDefaultSurfaceType( void ) const;
  765.     virtual void            AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName, idEntity* inflictor );
  766.  
  767.     virtual bool            ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  768.  
  769. // RAVEN BEGIN
  770. // abahr:
  771.     virtual const idAnimator *    GetAnimator( void ) const { return &animator; }
  772.     virtual void            UpdateRenderEntityCallback();
  773. // RAVEN BEGIN
  774.  
  775.     enum {
  776.         EVENT_ADD_DAMAGE_EFFECT = idEntity::EVENT_MAXEVENTS,
  777.         EVENT_MAXEVENTS
  778.     };
  779.  
  780. protected:
  781.     idAnimator                animator;
  782.     damageEffect_t *        damageEffects;
  783.  
  784. // RAVEN BEGIN
  785. // jshepard:
  786.     void                    Event_ClearAnims                ( void );
  787. // RAVEN END
  788.  
  789. private:
  790.     void                    Event_GetJointHandle( const char *jointname );
  791.     void                     Event_ClearAllJoints( void );
  792.     void                     Event_ClearJoint( jointHandle_t jointnum );
  793.     void                     Event_SetJointPos( jointHandle_t jointnum, jointModTransform_t transform_type, const idVec3 &pos );
  794.     void                     Event_SetJointAngle( jointHandle_t jointnum, jointModTransform_t transform_type, const idAngles &angles );
  795.     void                     Event_GetJointPos( jointHandle_t jointnum );
  796.     void                     Event_GetJointAngle( jointHandle_t jointnum );
  797.  
  798. // RAVEN BEGIN
  799. // bdube: programmer controlled joint events
  800.     void                    Event_SetJointAngularVelocity    ( const char* jointName, float pitch, float yaw, float roll, int blendTime );
  801.     void                    Event_CollapseJoints            ( const char* jointnames, const char* collapseTo );
  802.  
  803.  
  804.  
  805. // RAVEN END
  806. };
  807.  
  808. // RAVEN BEGIN
  809. void UpdateGuiParms( idUserInterface *gui, const idDict *args );
  810. // RAVEN END
  811.  
  812. ID_INLINE float idEntity::DistanceTo ( idEntity* ent ) {
  813.     return DistanceTo ( ent->GetPhysics()->GetOrigin() ); 
  814. }
  815.  
  816. ID_INLINE float idEntity::DistanceTo ( const idVec3& pos ) const {
  817.     return (pos - GetPhysics()->GetOrigin()).LengthFast ( ); 
  818. }
  819.  
  820. ID_INLINE float idEntity::DistanceTo2d ( idEntity* ent ) {
  821.     return DistanceTo2d ( ent->GetPhysics()->GetOrigin() ); 
  822. }
  823.  
  824. ID_INLINE bool idEntity::CanTakeDamage ( void ) const {
  825.     return fl.takedamage;
  826. }
  827.  
  828. // RAVEN BEGIN
  829. // ddynerman: MP arena stuff
  830. ID_INLINE int idEntity::GetInstance( void ) const {
  831.     return instance;
  832. }
  833.  
  834. // ddynerman: multiple collision worlds
  835. ID_INLINE int idEntity::GetClipWorld( void ) const {
  836.     return clipWorld;
  837. }
  838.  
  839. ID_INLINE void idEntity::SetClipWorld( int newCW ) {
  840.     clipWorld = newCW;
  841.     if( GetPhysics() ) {
  842.         GetPhysics()->UnlinkClip();
  843.         GetPhysics()->LinkClip();
  844.     }
  845. }
  846. // RAVEN END
  847. #endif /* !__GAME_ENTITY_H__ */
  848.