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.

115 lines
3.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ====
  2. //
  3. // Defines a logical entity which passes achievement related events to the gamerules system.
  4. #include "cbase.h"
  5. #include "gamerules.h"
  6. #include "entityinput.h"
  7. #include "entityoutput.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. // Allows map logic to send achievement related events.
  11. class CLogicAchievement : public CLogicalEntity
  12. {
  13. public:
  14. DECLARE_CLASS( CLogicAchievement, CLogicalEntity );
  15. CLogicAchievement();
  16. protected:
  17. // Inputs
  18. void InputFireEvent( inputdata_t &inputdata );
  19. void InputEnable( inputdata_t &inputdata );
  20. void InputDisable( inputdata_t &inputdata );
  21. void InputToggle( inputdata_t &inputdata );
  22. void InputSetTargetPlayer( inputdata_t &inputdata );
  23. bool m_bDisabled;
  24. string_t m_iszAchievementName; // Which achievement event this entity marks
  25. EHANDLE m_hActivatingPlayer;
  26. COutputEvent m_OnFired;
  27. DECLARE_DATADESC();
  28. };
  29. LINK_ENTITY_TO_CLASS( logic_achievement, CLogicAchievement );
  30. BEGIN_DATADESC( CLogicAchievement )
  31. DEFINE_KEYFIELD( m_bDisabled, FIELD_BOOLEAN, "StartDisabled" ),
  32. DEFINE_KEYFIELD( m_iszAchievementName, FIELD_STRING, "achievementname" ),
  33. DEFINE_FIELD( m_hActivatingPlayer, FIELD_EHANDLE ),
  34. // Inputs
  35. DEFINE_INPUTFUNC( FIELD_VOID, "FireEvent", InputFireEvent ),
  36. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  37. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  38. DEFINE_INPUTFUNC( FIELD_VOID, "Toggle", InputToggle ),
  39. DEFINE_INPUTFUNC( FIELD_VOID, "SetTargetPlayer", InputSetTargetPlayer ),
  40. // Outputs
  41. DEFINE_OUTPUT( m_OnFired, "OnFired" ),
  42. END_DATADESC()
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Constructor.
  45. //-----------------------------------------------------------------------------
  46. CLogicAchievement::CLogicAchievement(void)
  47. {
  48. m_hActivatingPlayer = NULL;
  49. m_iszAchievementName = NULL_STRING;
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose: Sends the achievement event to the achievement marking system.
  53. //-----------------------------------------------------------------------------
  54. void CLogicAchievement::InputFireEvent( inputdata_t &inputdata )
  55. {
  56. // If we're active, and our string matched a valid achievement ID
  57. CBasePlayer *pPlayer = (CBasePlayer*)m_hActivatingPlayer.Get();
  58. if ( !m_bDisabled && m_iszAchievementName != NULL_STRING )
  59. {
  60. UTIL_RecordAchievementEvent( m_iszAchievementName.ToCStr(), pPlayer );
  61. m_OnFired.FireOutput( inputdata.pActivator, this );
  62. }
  63. }
  64. //------------------------------------------------------------------------------
  65. // Purpose: Turns on the relay, allowing it to fire outputs.
  66. //------------------------------------------------------------------------------
  67. void CLogicAchievement::InputEnable( inputdata_t &inputdata )
  68. {
  69. m_bDisabled = false;
  70. }
  71. //------------------------------------------------------------------------------
  72. // Purpose: Turns off the relay, preventing it from firing outputs.
  73. //------------------------------------------------------------------------------
  74. void CLogicAchievement::InputDisable( inputdata_t &inputdata )
  75. {
  76. m_bDisabled = true;
  77. }
  78. void CLogicAchievement::InputToggle( inputdata_t &inputdata )
  79. {
  80. m_bDisabled = !m_bDisabled;
  81. }
  82. void CLogicAchievement::InputSetTargetPlayer( inputdata_t &inputdata )
  83. {
  84. m_hActivatingPlayer = inputdata.value.Entity();
  85. }