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.

134 lines
3.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Fires an output when the map spawns (or respawns if not set to
  4. // only fire once). It can be set to check a global state before firing.
  5. //
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "entityinput.h"
  10. #include "entityoutput.h"
  11. #include "eventqueue.h"
  12. #include "mathlib/mathlib.h"
  13. #include "globalstate.h"
  14. #include "GameEventListener.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. const int SF_AUTO_FIREONCE = 0x01;
  18. const int SF_AUTO_FIREONRELOAD = 0x02;
  19. class CLogicAuto : public CBaseEntity, public CGameEventListener
  20. {
  21. public:
  22. DECLARE_CLASS( CLogicAuto, CBaseEntity );
  23. void Activate(void);
  24. void Think(void);
  25. int ObjectCaps(void) { return BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
  26. virtual void FireGameEvent( IGameEvent *event ); // incoming event processing
  27. DECLARE_DATADESC();
  28. private:
  29. // fired no matter why the map loaded
  30. COutputEvent m_OnMapSpawn;
  31. // fired for specified types of map loads
  32. COutputEvent m_OnNewGame;
  33. COutputEvent m_OnLoadGame;
  34. COutputEvent m_OnMapTransition;
  35. COutputEvent m_OnBackgroundMap;
  36. COutputEvent m_OnMultiNewMap;
  37. COutputEvent m_OnMultiNewRound;
  38. string_t m_globalstate;
  39. };
  40. LINK_ENTITY_TO_CLASS(logic_auto, CLogicAuto);
  41. BEGIN_DATADESC( CLogicAuto )
  42. DEFINE_KEYFIELD(m_globalstate, FIELD_STRING, "globalstate"),
  43. // Outputs
  44. DEFINE_OUTPUT(m_OnMapSpawn, "OnMapSpawn"),
  45. DEFINE_OUTPUT(m_OnNewGame, "OnNewGame"),
  46. DEFINE_OUTPUT(m_OnLoadGame, "OnLoadGame"),
  47. DEFINE_OUTPUT(m_OnMapTransition, "OnMapTransition"),
  48. DEFINE_OUTPUT(m_OnBackgroundMap, "OnBackgroundMap"),
  49. DEFINE_OUTPUT(m_OnMultiNewMap, "OnMultiNewMap" ),
  50. DEFINE_OUTPUT(m_OnMultiNewRound, "OnMultiNewRound" ),
  51. END_DATADESC()
  52. //------------------------------------------------------------------------------
  53. // Purpose : Fire my outputs here if I fire on map reload
  54. //------------------------------------------------------------------------------
  55. void CLogicAuto::Activate(void)
  56. {
  57. ListenForGameEvent( "round_start" );
  58. ListenForGameEvent( "teamplay_round_start" );
  59. BaseClass::Activate();
  60. SetNextThink( gpGlobals->curtime + 0.2 );
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose: Called shortly after level spawn. Checks the global state and fires
  64. // targets if the global state is set or if there is not global state
  65. // to check.
  66. //-----------------------------------------------------------------------------
  67. void CLogicAuto::Think(void)
  68. {
  69. if (!m_globalstate || GlobalEntity_GetState(m_globalstate) == GLOBAL_ON)
  70. {
  71. if (gpGlobals->eLoadType == MapLoad_Transition)
  72. {
  73. m_OnMapTransition.FireOutput(NULL, this);
  74. }
  75. else if (gpGlobals->eLoadType == MapLoad_NewGame)
  76. {
  77. m_OnNewGame.FireOutput(NULL, this);
  78. }
  79. else if (gpGlobals->eLoadType == MapLoad_LoadGame)
  80. {
  81. m_OnLoadGame.FireOutput(NULL, this);
  82. }
  83. else if (gpGlobals->eLoadType == MapLoad_Background)
  84. {
  85. m_OnBackgroundMap.FireOutput(NULL, this);
  86. }
  87. m_OnMapSpawn.FireOutput(NULL, this);
  88. if ( g_pGameRules->IsMultiplayer() )
  89. {
  90. m_OnMultiNewMap.FireOutput(NULL, this);
  91. }
  92. if (m_spawnflags & SF_AUTO_FIREONCE)
  93. {
  94. UTIL_Remove(this);
  95. }
  96. }
  97. }
  98. void CLogicAuto::FireGameEvent( IGameEvent *gameEvent )
  99. {
  100. if ( FStrEq( gameEvent->GetName(), "round_start" ) || FStrEq( gameEvent->GetName(), "teamplay_round_start" ) )
  101. {
  102. if ( g_pGameRules->IsMultiplayer() )
  103. {
  104. m_OnMultiNewRound.FireOutput(NULL, this);
  105. }
  106. }
  107. }