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.

285 lines
9.8 KiB

  1. //========= Copyright � 1996-2008, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Client handler implementations for instruction players how to play
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "c_gameinstructor.h"
  8. #include "c_baselesson.h"
  9. #include "c_cs_player.h"
  10. #include "cs_gamerules.h"
  11. #include "gametypes.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. extern CUtlDict< int, int > g_LessonActionMap;
  15. extern ConVar gameinstructor_verbose;
  16. enum Mod_LessonAction
  17. {
  18. // Enum starts from end of LessonAction
  19. LESSON_ACTION_GAME_TYPE_IS = LESSON_ACTION_MOD_START,
  20. LESSON_ACTION_GAME_MODE_IS,
  21. LESSON_ACTION_CASUAL_OR_TRAINING,
  22. LESSON_ACTION_HAS_DEFUSER,
  23. LESSON_ACTION_HAS_ANY_ITEMS,
  24. LESSON_ACTION_HAS_MULTIPLE_ITEMS,
  25. LESSON_ACTION_HAS_MULTIPLE_WEAPONS,
  26. LESSON_ACTION_HAS_BUYMENU_OPEN,
  27. LESSON_ACTION_ROUND_STATE_IS,
  28. LESSON_ACTION_TOTAL
  29. };
  30. void CScriptedIconLesson::Mod_PreReadLessonsFromFile( void )
  31. {
  32. // Add custom actions to the map
  33. CScriptedIconLesson::LessonActionMap.Insert( "game type is", LESSON_ACTION_GAME_TYPE_IS );
  34. CScriptedIconLesson::LessonActionMap.Insert( "game mode is", LESSON_ACTION_GAME_MODE_IS );
  35. CScriptedIconLesson::LessonActionMap.Insert( "is casual or training", LESSON_ACTION_CASUAL_OR_TRAINING );
  36. CScriptedIconLesson::LessonActionMap.Insert( "has defuser", LESSON_ACTION_HAS_DEFUSER );
  37. CScriptedIconLesson::LessonActionMap.Insert( "has any items", LESSON_ACTION_HAS_ANY_ITEMS );
  38. CScriptedIconLesson::LessonActionMap.Insert( "has multiple items", LESSON_ACTION_HAS_MULTIPLE_ITEMS );
  39. CScriptedIconLesson::LessonActionMap.Insert( "has multiple weapons", LESSON_ACTION_HAS_MULTIPLE_WEAPONS );
  40. CScriptedIconLesson::LessonActionMap.Insert( "is buymenu open", LESSON_ACTION_HAS_BUYMENU_OPEN );
  41. CScriptedIconLesson::LessonActionMap.Insert( "round state is", LESSON_ACTION_ROUND_STATE_IS ); //0=freezetime; 1=mid-round; 2=round is over;
  42. }
  43. bool CScriptedIconLesson::Mod_ProcessElementAction( int iAction, bool bNot, const char *pchVarName, EHANDLE &hVar, const CGameInstructorSymbol *pchParamName, float fParam, C_BaseEntity *pParam, const char *pchParam, bool &bModHandled )
  44. {
  45. // Assume we're going to handle the action
  46. bModHandled = true;
  47. C_BaseEntity *pVar = hVar.Get();
  48. switch ( iAction )
  49. {
  50. case LESSON_ACTION_GAME_TYPE_IS:
  51. {
  52. return ( bNot ) ? ( g_pGameTypes->GetCurrentGameType() != fParam ) : ( g_pGameTypes->GetCurrentGameType() == fParam );
  53. break;
  54. }
  55. case LESSON_ACTION_GAME_MODE_IS:
  56. {
  57. return ( bNot ) ? ( g_pGameTypes->GetCurrentGameMode() != fParam ) : ( g_pGameTypes->GetCurrentGameMode() == fParam );
  58. break;
  59. }
  60. case LESSON_ACTION_CASUAL_OR_TRAINING:
  61. {
  62. return ( (g_pGameTypes->GetCurrentGameType() == CS_GameType_Classic && g_pGameTypes->GetCurrentGameMode() == CS_GameMode::Classic_Casual) || g_pGameTypes->GetCurrentGameType() == CS_GameType_Training );
  63. break;
  64. }
  65. case LESSON_ACTION_HAS_DEFUSER:
  66. {
  67. C_CSPlayer *pPlayer = dynamic_cast< C_CSPlayer* >( pVar );
  68. if ( !pPlayer )
  69. {
  70. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  71. {
  72. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasDefuser()", pchVarName );
  73. ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
  74. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
  75. ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as CSPlayer returned NULL!\n" );
  76. }
  77. return false;
  78. }
  79. bool bHasDefuser = pPlayer->HasDefuser();
  80. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  81. {
  82. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasSpareWeapon()", pchVarName );
  83. ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bHasDefuser ? "true" : "false" ) );
  84. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
  85. }
  86. return ( bNot ) ? ( !bHasDefuser ) : ( bHasDefuser );
  87. }
  88. case LESSON_ACTION_HAS_ANY_ITEMS:
  89. {
  90. C_CSPlayer *pPlayer = dynamic_cast< C_CSPlayer* >( pVar );
  91. if ( !pPlayer )
  92. {
  93. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  94. {
  95. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->GetCSWeapon( ITEM )", pchVarName );
  96. ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
  97. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
  98. ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as CSPlayer returned NULL!\n" );
  99. }
  100. return false;
  101. }
  102. bool bHasItem = false;
  103. for ( int i = ITEM_FIRST; i <= ITEM_MAX; i = i + 1 )
  104. {
  105. if ( pPlayer->GetCSWeapon( (CSWeaponID)i ) )
  106. {
  107. bHasItem = true;
  108. break;
  109. }
  110. }
  111. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  112. {
  113. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->GetCSWeapon( ITEM )", pchVarName );
  114. ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bHasItem ? "true" : "false" ) );
  115. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
  116. }
  117. return ( bNot ) ? ( !bHasItem ) : ( bHasItem );
  118. }
  119. case LESSON_ACTION_HAS_MULTIPLE_ITEMS:
  120. {
  121. C_CSPlayer *pPlayer = dynamic_cast< C_CSPlayer* >( pVar );
  122. if ( !pPlayer )
  123. {
  124. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  125. {
  126. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s] item count ", pchVarName );
  127. ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
  128. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
  129. ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as CSPlayer returned NULL!\n" );
  130. }
  131. return false;
  132. }
  133. int nItems = 0;
  134. for ( int i = ITEM_FIRST; i <= ITEM_MAX; i++ )
  135. if ( pPlayer->GetCSWeapon( (CSWeaponID)i ) )
  136. nItems++;
  137. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  138. {
  139. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s] item count ", pchVarName );
  140. ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%d ", ( nItems ) );
  141. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
  142. }
  143. return ( bNot ) ? ( nItems < 2 ) : ( nItems >= 2 );
  144. }
  145. case LESSON_ACTION_HAS_MULTIPLE_WEAPONS:
  146. {
  147. C_CSPlayer *pPlayer = dynamic_cast< C_CSPlayer* >( pVar );
  148. if ( !pPlayer )
  149. {
  150. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  151. {
  152. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s] weapon count ", pchVarName );
  153. ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
  154. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
  155. ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as CSPlayer returned NULL!\n" );
  156. }
  157. return false;
  158. }
  159. int nWeapons = 0;
  160. for ( int i = WEAPON_FIRST; i <= WEAPON_LAST; i++ )
  161. {
  162. if ( pPlayer->GetCSWeapon( (CSWeaponID)i ) )
  163. nWeapons++;
  164. }
  165. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  166. {
  167. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s] weapon count ", pchVarName );
  168. ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%d ", ( nWeapons ) );
  169. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
  170. }
  171. return ( bNot ) ? ( nWeapons < 2 ) : ( nWeapons >= 2 );
  172. }
  173. case LESSON_ACTION_HAS_BUYMENU_OPEN:
  174. {
  175. C_CSPlayer *pPlayer = dynamic_cast< C_CSPlayer* >( pVar );
  176. if ( !pPlayer )
  177. {
  178. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  179. {
  180. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->IsBuyMenuOpen()", pchVarName );
  181. ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " );
  182. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
  183. ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as CSPlayer returned NULL!\n" );
  184. }
  185. return false;
  186. }
  187. bool bHasMenuOpen = pPlayer->IsBuyMenuOpen();
  188. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  189. {
  190. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->IsBuyMenuOpen()", pchVarName );
  191. ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bHasMenuOpen ? "true" : "false" ) );
  192. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) );
  193. }
  194. return ( bNot ) ? ( !bHasMenuOpen ) : ( bHasMenuOpen );
  195. }
  196. case LESSON_ACTION_ROUND_STATE_IS:
  197. {
  198. int RoundState;
  199. if ( CSGameRules()->IsFreezePeriod() )
  200. {
  201. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  202. {
  203. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t Round is in freeze time.\n" );
  204. }
  205. RoundState = 0;// freeze time
  206. }
  207. else if ( CSGameRules()->IsRoundOver() )
  208. {
  209. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  210. {
  211. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t Round is over.\n" );
  212. }
  213. RoundState = 2;// round is over
  214. }
  215. else
  216. {
  217. if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
  218. {
  219. ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t Round is in progress.\n" );
  220. }
  221. RoundState = 1;// in the round
  222. }
  223. return ( bNot ) ? ( RoundState != fParam ) : ( RoundState == fParam );
  224. }
  225. default:
  226. // Didn't handle this action
  227. bModHandled = false;
  228. break;
  229. }
  230. return false;
  231. }
  232. bool C_GameInstructor::Mod_HiddenByOtherElements( void )
  233. {
  234. //C_ASW_Marine *pLocalMarine = C_ASW_Marine::GetLocalMarine();
  235. //if ( pLocalMarine && pLocalMarine->IsControllingTurret() )
  236. //{
  237. // return true;
  238. //}
  239. return false;
  240. }