Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
8.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef SCRIPTED_H
  7. #define SCRIPTED_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #ifndef SCRIPTEVENT_H
  12. #include "scriptevent.h"
  13. #endif
  14. #include "ai_basenpc.h"
  15. //
  16. // The number of unique outputs that a script can fire from animation events.
  17. // These are fired via SCRIPT_EVENT_FIREEVENT in CAI_BaseNPC::HandleAnimEvent.
  18. //
  19. #define MAX_SCRIPT_EVENTS 8
  20. #define SF_SCRIPT_WAITTILLSEEN 1
  21. #define SF_SCRIPT_EXITAGITATED 2
  22. #define SF_SCRIPT_REPEATABLE 4 // Whether the script can be played more than once.
  23. #define SF_SCRIPT_LEAVECORPSE 8
  24. #define SF_SCRIPT_START_ON_SPAWN 16
  25. #define SF_SCRIPT_NOINTERRUPT 32
  26. #define SF_SCRIPT_OVERRIDESTATE 64
  27. #define SF_SCRIPT_DONT_TELEPORT_AT_END 128 // Don't fixup end position with a teleport when the SS is finished
  28. #define SF_SCRIPT_LOOP_IN_POST_IDLE 256 // Loop in the post idle animation after playing the action animation.
  29. #define SF_SCRIPT_HIGH_PRIORITY 512 // If set, we don't allow other scripts to steal our spot in the queue.
  30. #define SF_SCRIPT_SEARCH_CYCLICALLY 1024 // Start search from last entity found.
  31. #define SF_SCRIPT_NO_COMPLAINTS 2048 // doesn't bitch if it can't find anything
  32. #define SF_SCRIPT_ALLOW_DEATH 4096 // the actor using this scripted sequence may die without interrupting the scene (used for scripted deaths)
  33. enum script_moveto_t
  34. {
  35. CINE_MOVETO_WAIT = 0,
  36. CINE_MOVETO_WALK = 1,
  37. CINE_MOVETO_RUN = 2,
  38. CINE_MOVETO_CUSTOM = 3,
  39. CINE_MOVETO_TELEPORT = 4,
  40. CINE_MOVETO_WAIT_FACING = 5,
  41. };
  42. enum SCRIPT_PLAYER_DEATH
  43. {
  44. SCRIPT_DO_NOTHING = 0,
  45. SCRIPT_CANCEL = 1,
  46. };
  47. //
  48. // Interrupt levels for grabbing NPCs to act out scripted events. These indicate
  49. // how important it is to get a specific NPC, and can affect how they respond.
  50. //
  51. enum SS_INTERRUPT
  52. {
  53. SS_INTERRUPT_BY_CLASS = 0, // Indicates that we are asking for this NPC by class
  54. SS_INTERRUPT_BY_NAME, // Indicates that we are asking for this NPC by name
  55. };
  56. // when a NPC finishes an AI scripted sequence, we can choose
  57. // a schedule to place them in. These defines are the aliases to
  58. // resolve worldcraft input to real schedules (sjb)
  59. #define SCRIPT_FINISHSCHED_DEFAULT 0
  60. #define SCRIPT_FINISHSCHED_AMBUSH 1
  61. class CAI_ScriptedSequence : public CBaseEntity
  62. {
  63. DECLARE_CLASS( CAI_ScriptedSequence, CBaseEntity );
  64. public:
  65. void Spawn( void );
  66. virtual void Blocked( CBaseEntity *pOther );
  67. virtual void Touch( CBaseEntity *pOther );
  68. virtual int ObjectCaps( void ) { return (BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION); }
  69. virtual void Activate( void );
  70. virtual void UpdateOnRemove( void );
  71. void StartThink();
  72. void ScriptThink( void );
  73. void StopThink();
  74. DECLARE_DATADESC();
  75. void Pain( void );
  76. void Die( void );
  77. void DelayStart( bool bDelay );
  78. bool FindEntity( void );
  79. void StartScript( void );
  80. void FireScriptEvent( int nEvent );
  81. void OnBeginSequence( void );
  82. void SetTarget( CBaseEntity *pTarget ) { m_hTargetEnt = pTarget; };
  83. CBaseEntity *GetTarget( void ) { return m_hTargetEnt; };
  84. // Input handlers
  85. void InputBeginSequence( inputdata_t &inputdata );
  86. void InputCancelSequence( inputdata_t &inputdata );
  87. void InputMoveToPosition( inputdata_t &inputdata );
  88. bool IsTimeToStart( void );
  89. bool IsWaitingForBegin( void );
  90. void ReleaseEntity( CAI_BaseNPC *pEntity );
  91. void CancelScript( void );
  92. bool StartSequence( CAI_BaseNPC *pTarget, string_t iszSeq, bool completeOnEmpty );
  93. void SynchronizeSequence( CAI_BaseNPC *pNPC );
  94. bool FCanOverrideState ( void );
  95. void SequenceDone( CAI_BaseNPC *pNPC );
  96. void PostIdleDone( CAI_BaseNPC *pNPC );
  97. void FixScriptNPCSchedule( CAI_BaseNPC *pNPC, int iSavedCineFlags );
  98. void FixFlyFlag( CAI_BaseNPC *pNPC, int iSavedCineFlags );
  99. bool CanInterrupt( void );
  100. void AllowInterrupt( bool fAllow );
  101. void RemoveIgnoredConditions( void );
  102. bool PlayedSequence( void ) { return m_sequenceStarted; }
  103. bool CanEnqueueAfter( void );
  104. // Entry & Action loops
  105. bool IsPlayingEntry( void ) { return m_bIsPlayingEntry; }
  106. bool IsPlayingAction( void ) { return ( m_sequenceStarted && !m_bIsPlayingEntry ); }
  107. bool FinishedActionSequence( CAI_BaseNPC *pNPC );
  108. void SetLoopActionSequence( bool bLoop ) { m_bLoopActionSequence = bLoop; }
  109. bool ShouldLoopActionSequence( void ) { return m_bLoopActionSequence; }
  110. void StopActionLoop( bool bStopSynchronizedScenes );
  111. void SetSynchPostIdles( bool bSynch ) { m_bSynchPostIdles = bSynch; }
  112. void SynchNewSequence( CAI_BaseNPC::SCRIPTSTATE newState, string_t iszSequence, bool bSynchOtherScenes );
  113. // Dynamic scripted sequence spawning
  114. void ForceSetTargetEntity( CAI_BaseNPC *pTarget, bool bDontCancelOtherSequences );
  115. // Dynamic interactions
  116. void SetupInteractionPosition( CBaseEntity *pRelativeEntity, VMatrix &matDesiredLocalToWorld );
  117. void ModifyScriptedAutoMovement( Vector *vecNewPos );
  118. bool IsTeleportingDueToMoveTo( void ) { return m_bIsTeleportingDueToMoveTo; }
  119. // Debug
  120. virtual int DrawDebugTextOverlays( void );
  121. virtual void DrawDebugGeometryOverlays( void );
  122. void InputScriptPlayerDeath( inputdata_t &inputdata );
  123. private:
  124. friend class CAI_BaseNPC; // should probably try to eliminate this relationship
  125. string_t m_iszEntry; // String index for animation that must be played before entering the main action anim
  126. string_t m_iszPreIdle; // String index for idle animation to play before playing the action anim (only played while waiting for the script to begin)
  127. string_t m_iszPlay; // String index for scripted action animation
  128. string_t m_iszPostIdle; // String index for idle animation to play before playing the action anim
  129. string_t m_iszCustomMove; // String index for custom movement animation
  130. string_t m_iszNextScript; // Name of the script to run immediately after this one.
  131. string_t m_iszEntity; // Entity that is wanted for this script
  132. int m_fMoveTo;
  133. bool m_bIsPlayingEntry;
  134. bool m_bLoopActionSequence;
  135. bool m_bSynchPostIdles;
  136. bool m_bIgnoreGravity;
  137. bool m_bDisableNPCCollisions; // Used when characters must interpenetrate while riding on elevators, trains, etc.
  138. float m_flRadius; // Range to search for an NPC to possess.
  139. float m_flRepeat; // Repeat rate
  140. int m_iDelay; // A counter indicating how many scripts are NOT ready to start.
  141. bool m_bDelayed; // This moderately hacky hack ensures that we don't calls to DelayStart(true) or DelayStart(false)
  142. // twice in succession. This is necessary because we didn't want to remove the call to DelayStart(true)
  143. // from StartScript, even though DelayStart(true) is called from TASK_PRE_SCRIPT.
  144. // All of this is necessary in case the NPCs schedule gets cleared during the script and then they
  145. // reselect the schedule to play the script. Without this you can get NPCs stuck with m_iDelay = -1
  146. float m_startTime; // Time when script actually started, used for synchronization
  147. bool m_bWaitForBeginSequence; // Set to true when we are told to MoveToPosition. Holds the actor in the pre-action idle until BeginSequence is called.
  148. int m_saved_effects;
  149. int m_savedFlags;
  150. int m_savedCollisionGroup;
  151. bool m_interruptable;
  152. bool m_sequenceStarted;
  153. EHANDLE m_hTargetEnt;
  154. EHANDLE m_hNextCine; // The script to hand the NPC off to when we finish with them.
  155. bool m_bThinking;
  156. bool m_bInitiatedSelfDelete;
  157. bool m_bIsTeleportingDueToMoveTo;
  158. CAI_BaseNPC *FindScriptEntity( void );
  159. EHANDLE m_hLastFoundEntity;
  160. // Code forced us to use a specific NPC
  161. EHANDLE m_hForcedTarget;
  162. bool m_bDontCancelOtherSequences;
  163. bool m_bForceSynch;
  164. bool m_bTargetWasAsleep;
  165. COutputEvent m_OnBeginSequence;
  166. COutputEvent m_OnEndSequence;
  167. COutputEvent m_OnPostIdleEndSequence;
  168. COutputEvent m_OnCancelSequence;
  169. COutputEvent m_OnCancelFailedSequence; // Fired when a scene is cancelled before it's ever run
  170. COutputEvent m_OnScriptEvent[MAX_SCRIPT_EVENTS];
  171. static void ScriptEntityCancel( CBaseEntity *pentCine, bool bPretendSuccess = false );
  172. static const char *GetSpawnPreIdleSequenceForScript( CBaseEntity *pTargetEntity );
  173. // Dynamic interactions
  174. // For now, store just a single one of these. To synchronize positions
  175. // with multiple other NPCs, this needs to be an array of NPCs & desired position matrices.
  176. VMatrix m_matInteractionPosition;
  177. EHANDLE m_hInteractionRelativeEntity;
  178. int m_iPlayerDeathBehavior;
  179. };
  180. #endif // SCRIPTED_H