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.

220 lines
7.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: An entity for creating instructor hints entirely with map logic
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "baseentity.h"
  9. #include "world.h"
  10. #ifdef INFESTED_DLL
  11. #include "asw_marine.h"
  12. #include "asw_player.h"
  13. #endif
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. //-----------------------------------------------------------------------------
  19. class CEnvInstructorHint : public CPointEntity
  20. {
  21. public:
  22. DECLARE_CLASS( CEnvInstructorHint, CPointEntity );
  23. DECLARE_DATADESC();
  24. private:
  25. void InputShowHint( inputdata_t &inputdata );
  26. void InputEndHint( inputdata_t &inputdata );
  27. string_t m_iszReplace_Key;
  28. string_t m_iszHintTargetEntity;
  29. int m_iTimeout;
  30. string_t m_iszIcon_Onscreen;
  31. string_t m_iszIcon_Offscreen;
  32. string_t m_iszCaption;
  33. string_t m_iszActivatorCaption;
  34. color32 m_Color;
  35. float m_fIconOffset;
  36. float m_fRange;
  37. uint8 m_iPulseOption;
  38. uint8 m_iAlphaOption;
  39. uint8 m_iShakeOption;
  40. bool m_bStatic;
  41. bool m_bNoOffscreen;
  42. bool m_bForceCaption;
  43. string_t m_iszBinding;
  44. string_t m_iszGamepadBinding;
  45. bool m_bAllowNoDrawTarget;
  46. bool m_bLocalPlayerOnly;
  47. };
  48. LINK_ENTITY_TO_CLASS( env_instructor_hint, CEnvInstructorHint );
  49. BEGIN_DATADESC( CEnvInstructorHint )
  50. DEFINE_KEYFIELD( m_iszReplace_Key, FIELD_STRING, "hint_replace_key" ),
  51. DEFINE_KEYFIELD( m_iszHintTargetEntity, FIELD_STRING, "hint_target" ),
  52. DEFINE_KEYFIELD( m_iTimeout, FIELD_INTEGER, "hint_timeout" ),
  53. DEFINE_KEYFIELD( m_iszIcon_Onscreen, FIELD_STRING, "hint_icon_onscreen" ),
  54. DEFINE_KEYFIELD( m_iszIcon_Offscreen, FIELD_STRING, "hint_icon_offscreen" ),
  55. DEFINE_KEYFIELD( m_iszCaption, FIELD_STRING, "hint_caption" ),
  56. DEFINE_KEYFIELD( m_iszActivatorCaption, FIELD_STRING, "hint_activator_caption" ),
  57. DEFINE_KEYFIELD( m_Color, FIELD_COLOR32, "hint_color" ),
  58. DEFINE_KEYFIELD( m_fIconOffset, FIELD_FLOAT, "hint_icon_offset" ),
  59. DEFINE_KEYFIELD( m_fRange, FIELD_FLOAT, "hint_range" ),
  60. DEFINE_KEYFIELD( m_iPulseOption, FIELD_CHARACTER, "hint_pulseoption" ),
  61. DEFINE_KEYFIELD( m_iAlphaOption, FIELD_CHARACTER, "hint_alphaoption" ),
  62. DEFINE_KEYFIELD( m_iShakeOption, FIELD_CHARACTER, "hint_shakeoption" ),
  63. DEFINE_KEYFIELD( m_bStatic, FIELD_BOOLEAN, "hint_static" ),
  64. DEFINE_KEYFIELD( m_bNoOffscreen, FIELD_BOOLEAN, "hint_nooffscreen" ),
  65. DEFINE_KEYFIELD( m_bForceCaption, FIELD_BOOLEAN, "hint_forcecaption" ),
  66. DEFINE_KEYFIELD( m_iszBinding, FIELD_STRING, "hint_binding" ),
  67. DEFINE_KEYFIELD( m_iszGamepadBinding, FIELD_STRING, "hint_gamepad_binding" ),
  68. DEFINE_KEYFIELD( m_bAllowNoDrawTarget, FIELD_BOOLEAN, "hint_allow_nodraw_target" ),
  69. DEFINE_KEYFIELD( m_bLocalPlayerOnly, FIELD_BOOLEAN, "hint_local_player_only" ),
  70. DEFINE_INPUTFUNC( FIELD_STRING, "ShowHint", InputShowHint ),
  71. DEFINE_INPUTFUNC( FIELD_VOID, "EndHint", InputEndHint ),
  72. END_DATADESC()
  73. #define LOCATOR_ICON_FX_PULSE_SLOW 0x00000001
  74. #define LOCATOR_ICON_FX_ALPHA_SLOW 0x00000008
  75. #define LOCATOR_ICON_FX_SHAKE_NARROW 0x00000040
  76. #define LOCATOR_ICON_FX_STATIC 0x00000100 // This icon draws at a fixed location on the HUD.
  77. //-----------------------------------------------------------------------------
  78. // Purpose: Input handler for showing the message and/or playing the sound.
  79. //-----------------------------------------------------------------------------
  80. void CEnvInstructorHint::InputShowHint( inputdata_t &inputdata )
  81. {
  82. static int s_InstructorServerHintEventCreate = 0;
  83. IGameEvent * event = gameeventmanager->CreateEvent( "instructor_server_hint_create", false, &s_InstructorServerHintEventCreate );
  84. if ( event )
  85. {
  86. CBaseEntity *pTargetEntity = gEntList.FindEntityByName( NULL, m_iszHintTargetEntity );
  87. if( pTargetEntity == NULL )
  88. pTargetEntity = inputdata.pActivator;
  89. if( pTargetEntity == NULL )
  90. pTargetEntity = GetWorldEntity();
  91. char szColorString[128];
  92. Q_snprintf( szColorString, sizeof( szColorString ), "%.3d,%.3d,%.3d", m_Color.r, m_Color.g, m_Color.b );
  93. int iFlags = 0;
  94. iFlags |= (m_iPulseOption == 0) ? 0 : (LOCATOR_ICON_FX_PULSE_SLOW << (m_iPulseOption - 1));
  95. iFlags |= (m_iAlphaOption == 0) ? 0 : (LOCATOR_ICON_FX_ALPHA_SLOW << (m_iAlphaOption - 1));
  96. iFlags |= (m_iShakeOption == 0) ? 0 : (LOCATOR_ICON_FX_SHAKE_NARROW << (m_iShakeOption - 1));
  97. iFlags |= m_bStatic ? LOCATOR_ICON_FX_STATIC : 0;
  98. CBasePlayer *pActivator = NULL;
  99. bool bFilterByActivator = m_bLocalPlayerOnly;
  100. if ( bFilterByActivator )
  101. pActivator = dynamic_cast<CBasePlayer*>( inputdata.pActivator );
  102. #ifdef INFESTED_DLL
  103. CASW_Marine *pMarine = dynamic_cast<CASW_Marine*>( inputdata.pActivator );
  104. if ( pMarine )
  105. {
  106. pActivator = pMarine->GetCommander();
  107. }
  108. #else
  109. if ( inputdata.value.StringID() != NULL_STRING )
  110. {
  111. CBaseEntity *pTarget = gEntList.FindEntityByName( NULL, inputdata.value.String() );
  112. pActivator = dynamic_cast<CBasePlayer*>( pTarget );
  113. if ( pActivator )
  114. {
  115. bFilterByActivator = true;
  116. }
  117. }
  118. else
  119. {
  120. if ( GameRules()->IsMultiplayer() == false )
  121. {
  122. pActivator = UTIL_GetLocalPlayer();
  123. }
  124. else
  125. {
  126. if ( !pTargetEntity )
  127. {
  128. Warning( "Failed to play server side instructor hint: no player specified for hint\n" );
  129. Assert( 0 );
  130. }
  131. }
  132. }
  133. #endif
  134. const char *pActivatorCaption = m_iszActivatorCaption.ToCStr();
  135. if ( !pActivatorCaption || pActivatorCaption[ 0 ] == '\0' )
  136. {
  137. pActivatorCaption = m_iszCaption.ToCStr();
  138. }
  139. event->SetString( "hint_name", GetEntityName().ToCStr() );
  140. event->SetString( "hint_replace_key", m_iszReplace_Key.ToCStr() );
  141. event->SetInt( "hint_target", pTargetEntity->entindex() );
  142. event->SetInt( "hint_activator_userid", ( pActivator ? pActivator->GetUserID() : 0 ) );
  143. event->SetInt( "hint_timeout", m_iTimeout );
  144. event->SetString( "hint_icon_onscreen", m_iszIcon_Onscreen.ToCStr() );
  145. event->SetString( "hint_icon_offscreen", m_iszIcon_Offscreen.ToCStr() );
  146. event->SetString( "hint_caption", m_iszCaption.ToCStr() );
  147. event->SetString( "hint_activator_caption", pActivatorCaption );
  148. event->SetString( "hint_color", szColorString );
  149. event->SetFloat( "hint_icon_offset", m_fIconOffset );
  150. event->SetFloat( "hint_range", m_fRange );
  151. event->SetInt( "hint_flags", iFlags );
  152. event->SetString( "hint_binding", m_iszBinding.ToCStr() );
  153. event->SetString( "hint_gamepad_binding", m_iszGamepadBinding.ToCStr() );
  154. event->SetBool( "hint_allow_nodraw_target", m_bAllowNoDrawTarget );
  155. event->SetBool( "hint_nooffscreen", m_bNoOffscreen );
  156. event->SetBool( "hint_forcecaption", m_bForceCaption );
  157. event->SetBool( "hint_local_player_only", bFilterByActivator );
  158. gameeventmanager->FireEvent( event );
  159. }
  160. }
  161. //-----------------------------------------------------------------------------
  162. //-----------------------------------------------------------------------------
  163. void CEnvInstructorHint::InputEndHint( inputdata_t &inputdata )
  164. {
  165. static int s_InstructorServerHintEventStop = 0;
  166. IGameEvent * event = gameeventmanager->CreateEvent( "instructor_server_hint_stop", false, &s_InstructorServerHintEventStop );
  167. if ( event )
  168. {
  169. event->SetString( "hint_name", GetEntityName().ToCStr() );
  170. gameeventmanager->FireEvent( event );
  171. }
  172. }
  173. //-----------------------------------------------------------------------------
  174. // Purpose: A generic target entity that gets replicated to the client for instructor hint targetting
  175. //-----------------------------------------------------------------------------
  176. class CInfoInstructorHintTarget : public CPointEntity
  177. {
  178. public:
  179. DECLARE_CLASS( CInfoInstructorHintTarget, CPointEntity );
  180. virtual int UpdateTransmitState( void ) // set transmit filter to transmit always
  181. {
  182. return SetTransmitState( FL_EDICT_ALWAYS );
  183. }
  184. DECLARE_DATADESC();
  185. };
  186. LINK_ENTITY_TO_CLASS( info_target_instructor_hint, CInfoInstructorHintTarget );
  187. BEGIN_DATADESC( CInfoInstructorHintTarget )
  188. END_DATADESC()