Team Fortress 2 Source Code as on 22/4/2020
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.

181 lines
5.8 KiB

  1. //========= Copyright 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. /*
  11. These are the string choices in the FGD:
  12. ACHIEVEMENT_EVENT_HL2_HIT_CANCOP_WITHCAN
  13. ACHIEVEMENT_EVENT_HL2_ESCAPE_APARTMENTRAID
  14. ACHIEVEMENT_EVENT_HL2_FIND_ONEGMAN
  15. ACHIEVEMENT_EVENT_HL2_BREAK_MINITELEPORTER
  16. ACHIEVEMENT_EVENT_HL2_GET_PISTOL
  17. ACHIEVEMENT_EVENT_HL2_GET_AIRBOAT
  18. ACHIEVEMENT_EVENT_HL2_GET_AIRBOATGUN
  19. ACHIEVEMENT_EVENT_HL2_FIND_VORTIGAUNTCAVE
  20. ACHIEVEMENT_EVENT_HL2_KILL_CHOPPER
  21. ACHIEVEMENT_EVENT_HL2_FIND_HEVFACEPLATE
  22. ACHIEVEMENT_EVENT_HL2_GET_GRAVITYGUN
  23. ACHIEVEMENT_EVENT_HL2_MAKEABASKET
  24. ACHIEVEMENT_EVENT_HL2_BEAT_RAVENHOLM_NOWEAPONS_START
  25. ACHIEVEMENT_EVENT_HL2_BEAT_RAVENHOLM_NOWEAPONS_END
  26. ACHIEVEMENT_EVENT_HL2_BEAT_CEMETERY
  27. ACHIEVEMENT_EVENT_HL2_KILL_ENEMIES_WITHCRANE
  28. ACHIEVEMENT_EVENT_HL2_PIN_SOLDIER_TOBILLBOARD
  29. ACHIEVEMENT_EVENT_HL2_KILL_ODESSAGUNSHIP
  30. ACHIEVEMENT_EVENT_HL2_BEAT_DONTTOUCHSAND
  31. ACHIEVEMENT_EVENT_HL2_ENTER_NOVAPROSPEKT,
  32. ACHIEVEMENT_EVENT_HL2_BEAT_TURRETSTANDOFF2
  33. ACHIEVEMENT_EVENT_HL2_BEAT_NOVAPROSPEKT
  34. ACHIEVEMENT_EVENT_HL2_BEAT_TOXICTUNNEL
  35. ACHIEVEMENT_EVENT_HL2_BEAT_PLAZASTANDOFF
  36. ACHIEVEMENT_EVENT_HL2_KILL_ALLC17SNIPERS
  37. ACHIEVEMENT_EVENT_HL2_BEAT_SUPRESSIONDEVICE
  38. ACHIEVEMENT_EVENT_HL2_BEAT_C17STRIDERSTANDOFF
  39. ACHIEVEMENT_EVENT_HL2_REACH_BREENSOFFICE
  40. ACHIEVEMENT_EVENT_HL2_FIND_LAMDACACHE
  41. // EP1
  42. ACHIEVEMENT_EVENT_EP1_BEAT_MAINELEVATOR
  43. ACHIEVEMENT_EVENT_EP1_BEAT_CITADELCORE
  44. ACHIEVEMENT_EVENT_EP1_BEAT_CITADELCORE_NOSTALKERKILLS
  45. ACHIEVEMENT_EVENT_EP1_BEAT_GARAGEELEVATORSTANDOFF
  46. ACHIEVEMENT_EVENT_EP1_KILL_ENEMIES_WITHSNIPERALYX
  47. ACHIEVEMENT_EVENT_EP1_BEAT_HOSPITALATTICGUNSHIP
  48. ACHIEVEMENT_EVENT_EP1_BEAT_CITIZENESCORT_NOCITIZENDEATHS
  49. // EP2
  50. ACHIEVEMENT_EVENT_EP2_BREAK_ALLWEBS
  51. ACHIEVEMENT_EVENT_EP2_BEAT_ANTLIONINVASION
  52. ACHIEVEMENT_EVENT_EP2_BEAT_ANTLIONGUARDS
  53. ACHIEVEMENT_EVENT_EP2_BEAT_HUNTERAMBUSH
  54. ACHIEVEMENT_EVENT_EP2_KILL_COMBINECANNON
  55. ACHIEVEMENT_EVENT_EP2_FIND_RADAR_CACHE
  56. ACHIEVEMENT_EVENT_EP2_BEAT_RACEWITHDOG
  57. ACHIEVEMENT_EVENT_EP2_BEAT_ROCKETCACHEPUZZLE
  58. ACHIEVEMENT_EVENT_EP2_BEAT_WHITEFORESTINN
  59. ACHIEVEMENT_EVENT_EP2_PUT_ITEMINROCKET
  60. ACHIEVEMENT_EVENT_EP2_BEAT_MISSILESILO2
  61. ACHIEVEMENT_EVENT_EP2_BEAT_OUTLAND12_NOBUILDINGSDESTROYED
  62. // PORTAL
  63. ACHIEVEMENT_EVENT_PORTAL_GET_PORTALGUNS
  64. ACHIEVEMENT_EVENT_PORTAL_KILL_COMPANIONCUBE
  65. ACHIEVEMENT_EVENT_PORTAL_ESCAPE_TESTCHAMBERS
  66. ACHIEVEMENT_EVENT_PORTAL_BEAT_GAME
  67. */
  68. // Allows map logic to send achievement related events to the achievement system.
  69. class CLogicAchievement : public CLogicalEntity
  70. {
  71. public:
  72. DECLARE_CLASS( CLogicAchievement, CLogicalEntity );
  73. CLogicAchievement();
  74. protected:
  75. // Inputs
  76. void InputFireEvent( inputdata_t &inputdata );
  77. void InputEnable( inputdata_t &inputdata );
  78. void InputDisable( inputdata_t &inputdata );
  79. void InputToggle( inputdata_t &inputdata );
  80. bool m_bDisabled;
  81. string_t m_iszAchievementEventID; // Which achievement event this entity marks
  82. COutputEvent m_OnFired;
  83. DECLARE_DATADESC();
  84. };
  85. LINK_ENTITY_TO_CLASS( logic_achievement, CLogicAchievement );
  86. BEGIN_DATADESC( CLogicAchievement )
  87. DEFINE_KEYFIELD( m_bDisabled, FIELD_BOOLEAN, "StartDisabled" ),
  88. DEFINE_KEYFIELD( m_iszAchievementEventID, FIELD_STRING, "AchievementEvent" ),
  89. // Inputs
  90. DEFINE_INPUTFUNC( FIELD_VOID, "FireEvent", InputFireEvent ),
  91. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  92. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  93. DEFINE_INPUTFUNC( FIELD_VOID, "Toggle", InputToggle ),
  94. // Outputs
  95. DEFINE_OUTPUT( m_OnFired, "OnFired" ),
  96. END_DATADESC()
  97. //-----------------------------------------------------------------------------
  98. // Purpose: Constructor.
  99. //-----------------------------------------------------------------------------
  100. CLogicAchievement::CLogicAchievement(void)
  101. {
  102. m_iszAchievementEventID = NULL_STRING;
  103. }
  104. #define ACHIEVEMENT_PREFIX "ACHIEVEMENT_EVENT_"
  105. //-----------------------------------------------------------------------------
  106. // Purpose: Sends the achievement event to the achievement marking system.
  107. //-----------------------------------------------------------------------------
  108. void CLogicAchievement::InputFireEvent( inputdata_t &inputdata )
  109. {
  110. // If we're active, and our string matched a valid achievement ID
  111. if ( !m_bDisabled && m_iszAchievementEventID != NULL_STRING)
  112. {
  113. m_OnFired.FireOutput( inputdata.pActivator, this );
  114. char const *pchName = STRING( m_iszAchievementEventID );
  115. int nPrefixLen = Q_strlen( ACHIEVEMENT_PREFIX );
  116. if ( !Q_strnicmp( pchName, ACHIEVEMENT_PREFIX, nPrefixLen ) )
  117. {
  118. // Skip the prefix
  119. pchName += nPrefixLen;
  120. if ( pchName && *pchName )
  121. {
  122. CBroadcastRecipientFilter filter;
  123. g_pGameRules->MarkAchievement( filter, pchName );
  124. }
  125. }
  126. }
  127. }
  128. //------------------------------------------------------------------------------
  129. // Purpose: Turns on the relay, allowing it to fire outputs.
  130. //------------------------------------------------------------------------------
  131. void CLogicAchievement::InputEnable( inputdata_t &inputdata )
  132. {
  133. m_bDisabled = false;
  134. }
  135. //------------------------------------------------------------------------------
  136. // Purpose: Turns off the relay, preventing it from firing outputs.
  137. //------------------------------------------------------------------------------
  138. void CLogicAchievement::InputDisable( inputdata_t &inputdata )
  139. {
  140. m_bDisabled = true;
  141. }
  142. //------------------------------------------------------------------------------
  143. // Purpose: Toggles the enabled/disabled state of the relay.
  144. //------------------------------------------------------------------------------
  145. void CLogicAchievement::InputToggle( inputdata_t &inputdata )
  146. {
  147. m_bDisabled = !m_bDisabled;
  148. }