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.

462 lines
15 KiB

  1. //========= Copyright � 1996-2008, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Client handler for instruction players how to play
  4. //
  5. //=============================================================================//
  6. #ifndef _C_BASELESSON_H_
  7. #define _C_BASELESSON_H_
  8. #include "GameEventListener.h"
  9. #include "hud_locator_target.h"
  10. #define DECLARE_LESSON( _lessonClassName, _baseLessonClassName ) \
  11. typedef _baseLessonClassName BaseClass;\
  12. typedef _lessonClassName ThisClass;\
  13. _lessonClassName( const char *pchName, bool bIsDefaultHolder, bool bIsOpenOpportunity, int nSplitScreenSlot )\
  14. : _baseLessonClassName( pchName, bIsDefaultHolder, bIsOpenOpportunity, nSplitScreenSlot )\
  15. {\
  16. Init();\
  17. }
  18. enum LessonInstanceType
  19. {
  20. LESSON_INSTANCE_MULTIPLE,
  21. LESSON_INSTANCE_SINGLE_OPEN,
  22. LESSON_INSTANCE_FIXED_REPLACE,
  23. LESSON_INSTANCE_SINGLE_ACTIVE,
  24. LESSON_INSTANCE_TYPE_TOTAL
  25. };
  26. // This is used to solve a problem where bots can take the place of a player, where on or the other don't have valid entities on the client at the same time
  27. #define MAX_DELAYED_PLAYER_SWAPS 8
  28. struct delayed_player_swap_t
  29. {
  30. CHandle<C_BaseEntity> *phHandleToChange;
  31. int iNewUserID;
  32. delayed_player_swap_t( void )
  33. {
  34. phHandleToChange = NULL;
  35. iNewUserID = -1;
  36. }
  37. };
  38. abstract_class CBaseLesson : public CGameEventListener
  39. {
  40. public:
  41. CBaseLesson( const char *pchName, bool bIsDefaultHolder, bool bIsOpenOpportunity, int nSplitScreenSlot );
  42. virtual ~CBaseLesson( void );
  43. void AddPrerequisite( const char *pchLessonName );
  44. const CGameInstructorSymbol& GetNameSymbol( void ) const { return m_stringName; }
  45. const char * GetName( void ) const { return m_stringName.String(); }
  46. int GetPriority( void ) const { return m_iPriority; }
  47. const char * GetCloseReason( void ) const { return m_stringCloseReason.String(); }
  48. void SetCloseReason( const char *pchReason ) { m_stringCloseReason = pchReason; }
  49. CBaseLesson* GetRoot( void ) const { return m_pRoot; }
  50. void SetRoot( CBaseLesson *pRoot );
  51. const CUtlVector < CBaseLesson * >* GetChildren( void ) const { return &m_OpenOpportunities; }
  52. float GetInitTime( void ) { return m_fInitTime; }
  53. void SetStartTime( void ) { m_fStartTime = gpGlobals->curtime; }
  54. void ResetStartTime( void ) { m_fStartTime = 0.0f; m_bHasPlayedSound = false; }
  55. bool ShouldShowSpew( void );
  56. bool NoPriority( void ) const;
  57. bool IsDefaultHolder( void ) const { return m_bIsDefaultHolder; }
  58. bool IsOpenOpportunity( void ) const { return m_bIsOpenOpportunity; }
  59. bool IsLocked( void ) const;
  60. bool CanOpenWhenDead( void ) const { return m_bCanOpenWhenDead; }
  61. bool CanOpenOnceLearned( void ) const { return !m_bOnceLearnedNeverOpen; }
  62. bool IsUsableInMidair( void ) const { return m_bUsableInMidair; }
  63. bool IsInstructing( void ) const { return ( m_fStartTime > 0.0f ); }
  64. bool IsLearned( void ) const;
  65. bool PrerequisitesHaveBeenMet( void ) const;
  66. bool IsTimedOut( void );
  67. int InstanceType( void ) const { return m_iInstanceType; }
  68. const CGameInstructorSymbol& GetReplaceKeySymbol( void ) const { return m_stringReplaceKey; }
  69. const char* GetReplaceKey( void ) const { return m_stringReplaceKey.String(); }
  70. int GetFixedInstancesMax( void ) const { return m_iFixedInstancesMax; }
  71. bool ShouldReplaceOnlyWhenStopped( void ) const { return m_bReplaceOnlyWhenStopped; }
  72. void SetInstanceActive( bool bInstanceActive ) { m_bInstanceActive = bInstanceActive; }
  73. bool IsInstanceActive( void ) const { return m_bInstanceActive; }
  74. void ResetDisplaysAndSuccesses( void );
  75. bool IncDisplayCount( void );
  76. bool IncSuccessCount( void );
  77. void SetDisplayCount( int iDisplayCount ) { m_iDisplayCount = iDisplayCount; }
  78. void SetSuccessCount( int iSuccessCount ) { m_iSuccessCount = iSuccessCount; }
  79. int GetDisplayCount( void ) const { return m_iDisplayCount; }
  80. int GetSuccessCount( void ) const { return m_iSuccessCount; }
  81. int GetDisplayLimit( void ) const { return m_iDisplayLimit; }
  82. int GetSuccessLimit( void ) const { return m_iSuccessLimit; }
  83. void Init( void ); // NOT virtual, each constructor calls their own
  84. virtual void InitPrerequisites( void ) {};
  85. virtual void Start( void ) = 0;
  86. virtual void Stop( void ) = 0;
  87. virtual void OnOpen( void ) {};
  88. virtual void Update( void ) {};
  89. virtual void UpdateInactive( void ) {};
  90. virtual bool ShouldDisplay( void ) const { return true; }
  91. virtual bool IsVisible( void ) const { return true; }
  92. virtual bool WasDisplayed( void ) const { return m_bWasDisplayed ? true : false; }
  93. virtual void SwapOutPlayers( int iOldUserID, int iNewUserID ) {}
  94. virtual void TakePlaceOf( CBaseLesson *pLesson );
  95. int GetSplitScreenSlot() const { return m_nSplitScreenSlot; }
  96. const char *GetGroup() { return m_szLessonGroup.String(); }
  97. void SetEnabled( bool bEnabled ) { m_bDisabled = !bEnabled; }
  98. protected:
  99. void MarkSucceeded( void );
  100. void CloseOpportunity( const char *pchReason );
  101. bool DoDelayedPlayerSwaps( void ) const;
  102. private:
  103. CBaseLesson *m_pRoot;
  104. CUtlVector < CBaseLesson * > m_OpenOpportunities;
  105. CUtlVector < const CBaseLesson * > m_Prerequisites;
  106. CGameInstructorSymbol m_stringCloseReason;
  107. protected:
  108. CGameInstructorSymbol m_stringName;
  109. private:
  110. bool m_bInstanceActive : 1;
  111. bool m_bSuccessCounted : 1;
  112. bool m_bIsDefaultHolder : 1;
  113. bool m_bIsOpenOpportunity : 1;
  114. protected:
  115. LessonInstanceType m_iInstanceType;
  116. int m_iPriority;
  117. CGameInstructorSymbol m_stringReplaceKey;
  118. int m_iFixedInstancesMax;
  119. bool m_bReplaceOnlyWhenStopped;
  120. int m_iTeam;
  121. bool m_bOnlyKeyboard;
  122. bool m_bOnlyGamepad;
  123. bool m_bNoSplitscreen;
  124. int m_iDisplayLimit;
  125. int m_iDisplayCount;
  126. bool m_bWasDisplayed;
  127. int m_iSuccessLimit;
  128. int m_iSuccessCount;
  129. int m_nSplitScreenSlot;
  130. float m_fLockDuration;
  131. float m_fTimeout;
  132. float m_fInitTime;
  133. float m_fStartTime;
  134. float m_fLockTime;
  135. float m_fUpdateInterval;
  136. bool m_bHasPlayedSound;
  137. CGameInstructorSymbol m_szStartSound;
  138. CGameInstructorSymbol m_szLessonGroup;
  139. bool m_bCanOpenWhenDead;
  140. bool m_bBumpWithTimeoutWhenLearned;
  141. bool m_bOnceLearnedNeverOpen;
  142. bool m_bCanTimeoutWhileInactive;
  143. bool m_bDisabled;
  144. bool m_bUsableInMidair;
  145. // Right now we can only queue up 4 swaps...
  146. // this number can be increased if more entity handle scripted variables are added
  147. mutable delayed_player_swap_t m_pDelayedPlayerSwap[ MAX_DELAYED_PLAYER_SWAPS ];
  148. mutable int m_iNumDelayedPlayerSwaps;
  149. public:
  150. // Colors for console spew in verbose mode
  151. static Color m_rgbaVerboseHeader;
  152. static Color m_rgbaVerbosePlain;
  153. static Color m_rgbaVerboseName;
  154. static Color m_rgbaVerboseOpen;
  155. static Color m_rgbaVerboseClose;
  156. static Color m_rgbaVerboseSuccess;
  157. static Color m_rgbaVerboseUpdate;
  158. };
  159. class CTextLesson : public CBaseLesson
  160. {
  161. public:
  162. DECLARE_LESSON( CTextLesson, CBaseLesson );
  163. void Init( void ); // NOT virtual, each constructor calls their own
  164. virtual void Start( void );
  165. virtual void Stop( void );
  166. protected:
  167. CGameInstructorSymbol m_szDisplayText;
  168. CGameInstructorSymbol m_szDisplayParamText;
  169. CGameInstructorSymbol m_szBinding;
  170. CGameInstructorSymbol m_szGamepadBinding;
  171. };
  172. class CIconLesson : public CTextLesson
  173. {
  174. public:
  175. DECLARE_LESSON( CIconLesson, CTextLesson );
  176. void Init( void ); // NOT virtual, each constructor calls their own
  177. virtual void Start( void );
  178. virtual void Stop( void );
  179. virtual void Update( void );
  180. virtual void UpdateInactive( void );
  181. virtual bool ShouldDisplay( void ) const;
  182. virtual bool IsVisible( void ) const;
  183. virtual void SwapOutPlayers( int iOldUserID, int iNewUserID );
  184. virtual void TakePlaceOf( CBaseLesson *pLesson );
  185. void SetLocatorBinding( CLocatorTarget * pLocatorTarget );
  186. const char *GetCaptionColorString() { return m_szCaptionColor.String(); }
  187. bool IsPresentComplete( void );
  188. void PresentStart( void );
  189. void PresentEnd( void );
  190. private:
  191. virtual void UpdateLocatorTarget( CLocatorTarget *pLocatorTarget, C_BaseEntity *pIconTarget );
  192. protected:
  193. CHandle<C_BaseEntity> m_hIconTarget;
  194. CGameInstructorSymbol m_szVguiTargetName;
  195. CGameInstructorSymbol m_szVguiTargetLookup;
  196. int m_nVguiTargetEdge;
  197. float m_flUpOffset;
  198. float m_flRelativeUpOffset;
  199. float m_fFixedPositionX;
  200. float m_fFixedPositionY;
  201. int m_hLocatorTarget;
  202. int m_iFlags;
  203. float m_fRange;
  204. float m_fCurrentDistance;
  205. float m_fOnScreenStartTime;
  206. float m_fUpdateDistanceTime;
  207. CGameInstructorSymbol m_szOnscreenIcon;
  208. CGameInstructorSymbol m_szOffscreenIcon;
  209. CGameInstructorSymbol m_szCaptionColor;
  210. bool m_bFixedPosition;
  211. bool m_bNoIconTarget;
  212. bool m_bAllowNodrawTarget;
  213. bool m_bVisible;
  214. bool m_bShowWhenOccluded;
  215. bool m_bNoOffscreen;
  216. bool m_bForceCaption;
  217. };
  218. enum LessonAction
  219. {
  220. LESSON_ACTION_NONE,
  221. LESSON_ACTION_SCOPE_IN,
  222. LESSON_ACTION_SCOPE_OUT,
  223. LESSON_ACTION_CLOSE,
  224. LESSON_ACTION_SUCCESS,
  225. LESSON_ACTION_LOCK,
  226. LESSON_ACTION_PRESENT_COMPLETE,
  227. LESSON_ACTION_PRESENT_START,
  228. LESSON_ACTION_PRESENT_END,
  229. LESSON_ACTION_REFERENCE_OPEN,
  230. LESSON_ACTION_IS_MULTIPLAYER,
  231. LESSON_ACTION_SET,
  232. LESSON_ACTION_ADD,
  233. LESSON_ACTION_SUBTRACT,
  234. LESSON_ACTION_MULTIPLY,
  235. LESSON_ACTION_IS,
  236. LESSON_ACTION_LESS_THAN,
  237. LESSON_ACTION_HAS_PREFIX,
  238. LESSON_ACTION_HAS_BIT,
  239. LESSON_ACTION_BIT_COUNT_IS,
  240. LESSON_ACTION_BIT_COUNT_LESS_THAN,
  241. LESSON_ACTION_GET_DISTANCE,
  242. LESSON_ACTION_GET_ANGULAR_DISTANCE,
  243. LESSON_ACTION_GET_PLAYER_DISPLAY_NAME,
  244. LESSON_ACTION_CLASSNAME_IS,
  245. LESSON_ACTION_MODELNAME_IS,
  246. LESSON_ACTION_TEAM_IS,
  247. LESSON_ACTION_HEALTH_LESS_THAN,
  248. LESSON_ACTION_HEALTH_PERCENTAGE_LESS_THAN,
  249. LESSON_ACTION_GET_ACTIVE_WEAPON,
  250. LESSON_ACTION_WEAPON_IS,
  251. LESSON_ACTION_WEAPON_HAS,
  252. LESSON_ACTION_GET_ACTIVE_WEAPON_SLOT,
  253. LESSON_ACTION_GET_WEAPON_SLOT,
  254. LESSON_ACTION_GET_WEAPON_IN_SLOT,
  255. LESSON_ACTION_CLIP_PERCENTAGE_LESS_THAN,
  256. LESSON_ACTION_WEAPON_AMMO_LOW,
  257. LESSON_ACTION_WEAPON_AMMO_FULL,
  258. LESSON_ACTION_WEAPON_AMMO_EMPTY,
  259. LESSON_ACTION_WEAPON_CAN_USE,
  260. LESSON_ACTION_USE_TARGET_IS,
  261. LESSON_ACTION_GET_USE_TARGET,
  262. LESSON_ACTION_GET_POTENTIAL_USE_TARGET,
  263. // Enum continued in Mod_LessonAction
  264. LESSON_ACTION_MOD_START,
  265. };
  266. struct LessonElement_t
  267. {
  268. int iVariable;
  269. int iParamVarIndex;
  270. int iAction;
  271. _fieldtypes paramType;
  272. CGameInstructorSymbol szParam;
  273. bool bNot : 1;
  274. bool bOptionalParam : 1;
  275. LessonElement_t( int p_iVariable, int p_iAction, bool p_bNot, bool p_bOptionalParam, const char *pchParam, int p_iParamVarIndex, _fieldtypes p_paramType )
  276. {
  277. iVariable = p_iVariable;
  278. iAction = p_iAction;
  279. bNot = p_bNot;
  280. bOptionalParam = p_bOptionalParam;
  281. szParam = pchParam;
  282. iParamVarIndex = p_iParamVarIndex;
  283. paramType = p_paramType;
  284. }
  285. LessonElement_t( const LessonElement_t &p_LessonElement )
  286. {
  287. iVariable = p_LessonElement.iVariable;
  288. iAction = p_LessonElement.iAction;
  289. bNot = p_LessonElement.bNot;
  290. bOptionalParam = p_LessonElement.bOptionalParam;
  291. szParam = p_LessonElement.szParam;
  292. iParamVarIndex = p_LessonElement.iParamVarIndex;
  293. paramType = p_LessonElement.paramType;
  294. }
  295. };
  296. struct LessonEvent_t
  297. {
  298. CUtlVector< LessonElement_t > elements;
  299. CGameInstructorSymbol szEventName;
  300. };
  301. class CScriptedIconLesson : public CIconLesson
  302. {
  303. public:
  304. DECLARE_LESSON( CScriptedIconLesson, CIconLesson )
  305. DECLARE_SIMPLE_DATADESC();
  306. virtual ~CScriptedIconLesson( void );
  307. static void PreReadLessonsFromFile( void );
  308. static void Mod_PreReadLessonsFromFile( void );
  309. void Init( void ); // NOT virtual, each constructor calls their own
  310. virtual void InitPrerequisites( void );
  311. virtual void OnOpen( void );
  312. virtual void Update( void );
  313. virtual void SwapOutPlayers( int iOldUserID, int iNewUserID );
  314. virtual void FireGameEvent( IGameEvent *event );
  315. virtual void ProcessOpenGameEvents( const CScriptedIconLesson *pRootLesson, const char *name, IGameEvent *event );
  316. virtual void ProcessCloseGameEvents( const CScriptedIconLesson *pRootLesson, const char *name, IGameEvent *event );
  317. virtual void ProcessSuccessGameEvents( const CScriptedIconLesson *pRootLesson, const char *name, IGameEvent *event );
  318. CUtlVector< LessonEvent_t >& GetOpenEvents( void ) { return m_OpenEvents; }
  319. CUtlVector< LessonEvent_t >& GetCloseEvents( void ) { return m_CloseEvents; }
  320. CUtlVector< LessonEvent_t >& GetSuccessEvents( void ) { return m_SuccessEvents; }
  321. CUtlVector< LessonEvent_t >& GetOnOpenEvents( void ) { return m_OnOpenEvents; }
  322. CUtlVector< LessonEvent_t >& GetUpdateEvents( void ) { return m_UpdateEvents; }
  323. bool ProcessElements( IGameEvent *event, const CUtlVector< LessonElement_t > *pElements );
  324. private:
  325. void InitElementsFromKeys( CUtlVector< LessonElement_t > *pLessonElements, KeyValues *pKey );
  326. void InitElementsFromElements( CUtlVector< LessonElement_t > *pLessonElements, const CUtlVector< LessonElement_t > *pLessonElements2 );
  327. void InitFromKeys( KeyValues *pKey );
  328. bool ProcessElement( IGameEvent *event, const LessonElement_t *pLessonElement, bool bInFailedScope );
  329. bool ProcessElementAction( int iAction, bool bNot, const char *pchVarName, float &bVar, const CGameInstructorSymbol *pchParamName, float fParam );
  330. bool ProcessElementAction( int iAction, bool bNot, const char *pchVarName, int &bVar, const CGameInstructorSymbol *pchParamName, float fParam );
  331. bool ProcessElementAction( int iAction, bool bNot, const char *pchVarName, bool &bVar, const CGameInstructorSymbol *pchParamName, float fParam );
  332. bool ProcessElementAction( int iAction, bool bNot, const char *pchVarName, EHANDLE &hVar, const CGameInstructorSymbol *pchParamName, float fParam, C_BaseEntity *pParam, const char *pchParam );
  333. bool ProcessElementAction( int iAction, bool bNot, const char *pchVarName, CGameInstructorSymbol *pchVar, const CGameInstructorSymbol *pchParamName, const char *pchParam );
  334. // Implemented per mod so they can have custom actions
  335. bool Mod_ProcessElementAction( int iAction, bool bNot, const char *pchVarName, EHANDLE &hVar, const CGameInstructorSymbol *pchParamName, float fParam, C_BaseEntity *pParam, const char *pchParam, bool &bModHandled );
  336. LessonEvent_t * AddOpenEvent( void );
  337. LessonEvent_t * AddCloseEvent( void );
  338. LessonEvent_t * AddSuccessEvent( void );
  339. LessonEvent_t * AddOnOpenEvent( void );
  340. LessonEvent_t * AddUpdateEvent( void );
  341. private:
  342. static CUtlDict< int, int > LessonActionMap;
  343. EHANDLE m_hLocalPlayer;
  344. float m_fOutput;
  345. CHandle<C_BaseEntity> m_hEntity1;
  346. CHandle<C_BaseEntity> m_hEntity2;
  347. CGameInstructorSymbol m_szString1;
  348. CGameInstructorSymbol m_szString2;
  349. int m_iInteger1;
  350. int m_iInteger2;
  351. float m_fFloat1;
  352. float m_fFloat2;
  353. CUtlVector< CGameInstructorSymbol > m_PrerequisiteNames;
  354. CUtlVector< LessonEvent_t > m_OpenEvents;
  355. CUtlVector< LessonEvent_t > m_CloseEvents;
  356. CUtlVector< LessonEvent_t > m_SuccessEvents;
  357. CUtlVector< LessonEvent_t > m_OnOpenEvents;
  358. CUtlVector< LessonEvent_t > m_UpdateEvents;
  359. float m_fUpdateEventTime;
  360. CScriptedIconLesson *m_pDefaultHolder;
  361. int m_iScopeDepth;
  362. // Need this to get offsets to scripted variables
  363. friend class LessonVariableInfo;
  364. friend int LessonActionFromString( const char *pchName );
  365. };
  366. #endif // _C_BASELESSON_H_