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.

415 lines
9.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements visual effects entities: sprites, beams, bubbles, etc.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "EnvMessage.h"
  9. #include "engine/IEngineSound.h"
  10. #include "keyvalues.h"
  11. #include "filesystem.h"
  12. #include "color.h"
  13. #include "GameStats.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. LINK_ENTITY_TO_CLASS( env_message, CMessage );
  17. BEGIN_DATADESC( CMessage )
  18. DEFINE_KEYFIELD( m_iszMessage, FIELD_STRING, "message" ),
  19. DEFINE_KEYFIELD( m_sNoise, FIELD_SOUNDNAME, "messagesound" ),
  20. DEFINE_KEYFIELD( m_MessageAttenuation, FIELD_INTEGER, "messageattenuation" ),
  21. DEFINE_KEYFIELD( m_MessageVolume, FIELD_FLOAT, "messagevolume" ),
  22. DEFINE_FIELD( m_Radius, FIELD_FLOAT ),
  23. DEFINE_INPUTFUNC( FIELD_VOID, "ShowMessage", InputShowMessage ),
  24. DEFINE_OUTPUT(m_OnShowMessage, "OnShowMessage"),
  25. END_DATADESC()
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. //-----------------------------------------------------------------------------
  29. void CMessage::Spawn( void )
  30. {
  31. Precache();
  32. SetSolid( SOLID_NONE );
  33. SetMoveType( MOVETYPE_NONE );
  34. switch( m_MessageAttenuation )
  35. {
  36. case 1: // Medium radius
  37. m_Radius = ATTN_STATIC;
  38. break;
  39. case 2: // Large radius
  40. m_Radius = ATTN_NORM;
  41. break;
  42. case 3: //EVERYWHERE
  43. m_Radius = ATTN_NONE;
  44. break;
  45. default:
  46. case 0: // Small radius
  47. m_Radius = SNDLVL_IDLE;
  48. break;
  49. }
  50. m_MessageAttenuation = 0;
  51. // Remap volume from [0,10] to [0,1].
  52. m_MessageVolume *= 0.1;
  53. // No volume, use normal
  54. if ( m_MessageVolume <= 0 )
  55. {
  56. m_MessageVolume = 1.0;
  57. }
  58. }
  59. void CMessage::Precache( void )
  60. {
  61. if ( m_sNoise != NULL_STRING )
  62. {
  63. PrecacheScriptSound( STRING(m_sNoise) );
  64. }
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose: Input handler for showing the message and/or playing the sound.
  68. //-----------------------------------------------------------------------------
  69. void CMessage::InputShowMessage( inputdata_t &inputdata )
  70. {
  71. CBaseEntity *pPlayer = NULL;
  72. if ( m_spawnflags & SF_MESSAGE_ALL )
  73. {
  74. #ifdef CSTRIKE15
  75. UTIL_ClientPrintAll( HUD_PRINTCENTER, STRING( m_iszMessage ) );
  76. #else
  77. UTIL_ShowMessageAll( STRING( m_iszMessage ) );
  78. #endif
  79. }
  80. else
  81. {
  82. if ( inputdata.pActivator && inputdata.pActivator->IsPlayer() )
  83. {
  84. pPlayer = inputdata.pActivator;
  85. }
  86. else
  87. {
  88. pPlayer = (gpGlobals->maxClients > 1) ? NULL : UTIL_GetLocalPlayer();
  89. }
  90. if ( pPlayer && pPlayer->IsPlayer() )
  91. {
  92. #ifdef CSTRIKE15
  93. CRecipientFilter filterPlayer;
  94. filterPlayer.MakeReliable();
  95. filterPlayer.AddRecipient( ToBasePlayer( pPlayer ) );
  96. UTIL_ClientPrintFilter( filterPlayer, HUD_PRINTCENTER, STRING( m_iszMessage ) );
  97. filterPlayer.RemoveAllRecipients();
  98. #else
  99. UTIL_ShowMessage( STRING( m_iszMessage ), ToBasePlayer( pPlayer ) );
  100. #endif
  101. }
  102. }
  103. if ( m_sNoise != NULL_STRING )
  104. {
  105. CPASAttenuationFilter filter( this );
  106. EmitSound_t ep;
  107. ep.m_nChannel = CHAN_BODY;
  108. ep.m_pSoundName = (char*)STRING(m_sNoise);
  109. ep.m_flVolume = m_MessageVolume;
  110. ep.m_SoundLevel = ATTN_TO_SNDLVL( m_Radius );
  111. EmitSound( filter, entindex(), ep );
  112. }
  113. if ( m_spawnflags & SF_MESSAGE_ONCE )
  114. {
  115. UTIL_Remove( this );
  116. }
  117. m_OnShowMessage.FireOutput( inputdata.pActivator, this );
  118. }
  119. void CMessage::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
  120. {
  121. inputdata_t inputdata;
  122. inputdata.pActivator = NULL;
  123. inputdata.pCaller = NULL;
  124. InputShowMessage( inputdata );
  125. }
  126. class CCredits : public CPointEntity
  127. {
  128. public:
  129. DECLARE_CLASS( CMessage, CPointEntity );
  130. DECLARE_DATADESC();
  131. void Spawn( void );
  132. void InputRollCredits( inputdata_t &inputdata );
  133. void InputRollOutroCredits( inputdata_t &inputdata );
  134. void InputShowLogo( inputdata_t &inputdata );
  135. void InputSetLogoLength( inputdata_t &inputdata );
  136. COutputEvent m_OnCreditsDone;
  137. virtual void OnRestore();
  138. private:
  139. void RollOutroCredits();
  140. bool m_bRolledOutroCredits;
  141. float m_flLogoLength;
  142. };
  143. LINK_ENTITY_TO_CLASS( env_credits, CCredits );
  144. BEGIN_DATADESC( CCredits )
  145. DEFINE_INPUTFUNC( FIELD_VOID, "RollCredits", InputRollCredits ),
  146. DEFINE_INPUTFUNC( FIELD_VOID, "RollOutroCredits", InputRollOutroCredits ),
  147. DEFINE_INPUTFUNC( FIELD_VOID, "ShowLogo", InputShowLogo ),
  148. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetLogoLength", InputSetLogoLength ),
  149. DEFINE_OUTPUT( m_OnCreditsDone, "OnCreditsDone"),
  150. DEFINE_FIELD( m_bRolledOutroCredits, FIELD_BOOLEAN ),
  151. DEFINE_FIELD( m_flLogoLength, FIELD_FLOAT )
  152. END_DATADESC()
  153. void CCredits::Spawn( void )
  154. {
  155. SetSolid( SOLID_NONE );
  156. SetMoveType( MOVETYPE_NONE );
  157. }
  158. #ifndef PORTAL
  159. static void CreditsDone_f( void )
  160. {
  161. CCredits *pCredits = (CCredits*)gEntList.FindEntityByClassname( NULL, "env_credits" );
  162. if ( pCredits )
  163. {
  164. pCredits->m_OnCreditsDone.FireOutput( pCredits, pCredits );
  165. }
  166. }
  167. static ConCommand creditsdone("creditsdone", CreditsDone_f );
  168. #endif // PORTAL
  169. extern ConVar sv_unlockedchapters;
  170. void CCredits::OnRestore()
  171. {
  172. BaseClass::OnRestore();
  173. if ( m_bRolledOutroCredits )
  174. {
  175. // Roll them again so that the client .dll will send the "creditsdone" message and we'll
  176. // actually get back to the main menu
  177. RollOutroCredits();
  178. }
  179. }
  180. void CCredits::RollOutroCredits()
  181. {
  182. sv_unlockedchapters.SetValue( "15" );
  183. // Gurjeets - Not used in CSGO
  184. //CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  185. //CSingleUserRecipientFilter user( pPlayer );
  186. //user.MakeReliable();
  187. //UserMessageBegin( user, "CreditsMsg" );
  188. // WRITE_BYTE( 3 );
  189. //MessageEnd();
  190. }
  191. void CCredits::InputRollOutroCredits( inputdata_t &inputdata )
  192. {
  193. RollOutroCredits();
  194. // In case we save restore
  195. m_bRolledOutroCredits = true;
  196. #ifndef _GAMECONSOLE
  197. gamestats->Event_Credits();
  198. #endif
  199. }
  200. void CCredits::InputShowLogo( inputdata_t &inputdata )
  201. {
  202. ASSERT(0);
  203. // Gurjeets - Not used in CSGO
  204. //CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  205. //CSingleUserRecipientFilter user( pPlayer );
  206. //user.MakeReliable();
  207. //if ( m_flLogoLength )
  208. //{
  209. // UserMessageBegin( user, "LogoTimeMsg" );
  210. // WRITE_FLOAT( m_flLogoLength );
  211. // MessageEnd();
  212. //}
  213. //else
  214. //{
  215. // UserMessageBegin( user, "CreditsMsg" );
  216. // WRITE_BYTE( 1 );
  217. // MessageEnd();
  218. //}
  219. }
  220. void CCredits::InputSetLogoLength( inputdata_t &inputdata )
  221. {
  222. m_flLogoLength = inputdata.value.Float();
  223. }
  224. void CCredits::InputRollCredits( inputdata_t &inputdata )
  225. {
  226. // Gurjeets - Not used in CSGO
  227. //CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  228. //CSingleUserRecipientFilter user( pPlayer );
  229. //user.MakeReliable();
  230. //UserMessageBegin( user, "CreditsMsg" );
  231. // WRITE_BYTE( 2 );
  232. //MessageEnd();
  233. }
  234. //-----------------------------------------------------------------------------
  235. // Purpose: Play the outtro stats at the end of the campaign
  236. //-----------------------------------------------------------------------------
  237. class COuttroStats : public CPointEntity
  238. {
  239. public:
  240. DECLARE_CLASS( COuttroStats, CPointEntity );
  241. DECLARE_DATADESC();
  242. void Spawn( void );
  243. void InputRollCredits( inputdata_t &inputdata );
  244. void InputRollStatsCrawl( inputdata_t &inputdata );
  245. void InputSkipStateChanged( inputdata_t &inputdata );
  246. void SkipThink( void );
  247. void CalcSkipState( int &skippingPlayers, int &totalPlayers );
  248. COutputEvent m_OnOuttroStatsDone;
  249. };
  250. //-----------------------------------------------------------------------------
  251. LINK_ENTITY_TO_CLASS( env_outtro_stats, COuttroStats );
  252. BEGIN_DATADESC( COuttroStats )
  253. DEFINE_INPUTFUNC( FIELD_VOID, "RollStatsCrawl", InputRollStatsCrawl ),
  254. DEFINE_INPUTFUNC( FIELD_VOID, "RollCredits", InputRollCredits ),
  255. DEFINE_INPUTFUNC( FIELD_VOID, "SkipStateChanged", InputSkipStateChanged ),
  256. DEFINE_OUTPUT( m_OnOuttroStatsDone, "OnOuttroStatsDone"),
  257. END_DATADESC()
  258. //-----------------------------------------------------------------------------
  259. void COuttroStats::Spawn( void )
  260. {
  261. SetSolid( SOLID_NONE );
  262. SetMoveType( MOVETYPE_NONE );
  263. }
  264. //-----------------------------------------------------------------------------
  265. void COuttroStats::InputRollStatsCrawl( inputdata_t &inputdata )
  266. {
  267. // Gurjeets - Not used in CSGO
  268. //CReliableBroadcastRecipientFilter players;
  269. //UserMessageBegin( players, "StatsCrawlMsg" );
  270. //MessageEnd();
  271. SetThink( &COuttroStats::SkipThink );
  272. SetNextThink( gpGlobals->curtime + 1.0 );
  273. }
  274. //-----------------------------------------------------------------------------
  275. void COuttroStats::InputRollCredits( inputdata_t &inputdata )
  276. {
  277. ASSERT(0);
  278. // Gurjeets - Not used in CSGO
  279. //CReliableBroadcastRecipientFilter players;
  280. //UserMessageBegin( players, "creditsMsg" );
  281. //MessageEnd();
  282. }
  283. void COuttroStats::SkipThink( void )
  284. {
  285. // if all valid players are skipping, then end
  286. int iNumSkips = 0;
  287. int iNumPlayers = 0;
  288. CalcSkipState( iNumSkips, iNumPlayers );
  289. if ( iNumSkips >= iNumPlayers )
  290. {
  291. // TheDirector->StartScenarioExit();
  292. }
  293. else
  294. SetNextThink( gpGlobals->curtime + 1.0 );
  295. }
  296. void COuttroStats::CalcSkipState( int &skippingPlayers, int &totalPlayers )
  297. {
  298. // calc skip state
  299. skippingPlayers = 0;
  300. totalPlayers = 0;
  301. }
  302. void COuttroStats::InputSkipStateChanged( inputdata_t &inputdata )
  303. {
  304. int iNumSkips = 0;
  305. int iNumPlayers = 0;
  306. CalcSkipState( iNumSkips, iNumPlayers );
  307. DevMsg( "COuttroStats: Skip state changed. %d players, %d skips\n", iNumPlayers, iNumSkips );
  308. // Gurjeets - Not used in CSGO
  309. //// Don't send to players in singleplayer
  310. //if ( iNumPlayers > 1 )
  311. //{
  312. // CReliableBroadcastRecipientFilter players;
  313. // UserMessageBegin( players, "StatsSkipState" );
  314. // WRITE_BYTE( iNumSkips );
  315. // WRITE_BYTE( iNumPlayers );
  316. // MessageEnd();
  317. //}
  318. }
  319. void CC_Test_Outtro_Stats( const CCommand& args )
  320. {
  321. CBaseEntity *pOuttro = gEntList.FindEntityByClassname( NULL, "env_outtro_stats" );
  322. if ( pOuttro )
  323. {
  324. variant_t emptyVariant;
  325. pOuttro->AcceptInput( "RollStatsCrawl", NULL, NULL, emptyVariant, 0 );
  326. }
  327. }
  328. static ConCommand test_outtro_stats("test_outtro_stats", CC_Test_Outtro_Stats, 0, FCVAR_CHEAT);