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.

164 lines
5.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TF_QUEST_RESTRICTION_H
  8. #define TF_QUEST_RESTRICTION_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tf_shareddefs.h"
  13. #ifdef CLIENT_DLL
  14. #define CTFPlayer C_TFPlayer
  15. #endif // CLIENT_DLL
  16. class CTFQuestEvaluator;
  17. class CTFPlayer;
  18. enum EInvalidReasons_t
  19. {
  20. INVALID_QUEST_REASON_WRONG_MAP = 0,
  21. INVALID_QUEST_REASON_WRONG_CLASS,
  22. INVALID_QUEST_REASON_WRONG_GAME_MODE,
  23. INVALID_QUEST_REASON_NOT_ENOUGH_PLAYERS,
  24. INVALID_QUEST_REASON_VALVE_SERVERS_ONLY,
  25. INVALID_QUEST_REASON_NO_MVM,
  26. NUM_INVALID_REASONS,
  27. };
  28. struct InvalidReason
  29. {
  30. InvalidReason() {}
  31. bool IsValid() const
  32. {
  33. return m_bits.IsAllClear();
  34. }
  35. CBitVec< NUM_INVALID_REASONS > m_bits;
  36. };
  37. typedef InvalidReason InvalidReasonsContainer_t;
  38. void GetInvalidReasonsNames( const InvalidReasonsContainer_t&, CUtlVector< CUtlString >& vecStrings );
  39. //-----------------------------------------------------------------------------
  40. // Purpose: base quest condition
  41. //-----------------------------------------------------------------------------
  42. class CTFQuestCondition
  43. {
  44. public:
  45. DECLARE_CLASS_NOBASE( CTFQuestCondition )
  46. CTFQuestCondition();
  47. virtual ~CTFQuestCondition();
  48. virtual const char *GetBaseName() const = 0;
  49. virtual const char *GetConditionName() const { return m_pszTypeName; }
  50. virtual const char *GetValueString() const { return ""; }
  51. virtual bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors /* = NULL */ );
  52. virtual void PrintDebugText() const;
  53. virtual const CTFPlayer *GetQuestOwner() const;
  54. virtual bool IsValidForPlayer( const CTFPlayer *pOwner, InvalidReasonsContainer_t& invalidReasons ) const;
  55. virtual bool IsOperator() const { return false; }
  56. virtual bool IsEvaluator() const { return false; }
  57. void SetParent( CTFQuestCondition *pParent ) { m_pParent = pParent; }
  58. CTFQuestCondition *GetParent() const { return m_pParent; }
  59. virtual CTFQuestCondition* AddChildByName( const char *pszChildName ) { Assert( 0 ); return NULL; }
  60. virtual int GetChildren( CUtlVector< CTFQuestCondition* >& vecChildren ) { return 0; }
  61. virtual bool RemoveAndDeleteChild( CTFQuestCondition *pChild ) { return false; }
  62. virtual void GetRequiredParamKeys( KeyValues *pRequiredKeys ) {}
  63. virtual void GetOutputKeyValues( KeyValues *pOutputKeys ) {}
  64. virtual void GetValidTypes( CUtlVector< const char* >& vecOutValidChildren ) const = 0;
  65. virtual void GetValidChildren( CUtlVector< const char* >& vecOutValidChildren ) const = 0;
  66. virtual int GetMaxInputCount() const { return 0; }
  67. virtual const char* GetEventName() const { Assert( 0 ); return NULL; }
  68. virtual void SetEventName( const char *pszEventName ) { Assert( 0 ); }
  69. void SetFieldName( const char* pszFieldName ) { m_pszFieldName = pszFieldName; }
  70. void SetTypeName( const char* pszTypeName ) { m_pszTypeName = pszTypeName; }
  71. protected:
  72. void GetValidRestrictions( CUtlVector< const char* >& vecOutValidChildren ) const;
  73. void GetValidEvaluators( CUtlVector< const char* >& vecOutValidChildren ) const;
  74. const char *m_pszFieldName;
  75. const char *m_pszTypeName;
  76. private:
  77. CTFQuestCondition *m_pParent;
  78. };
  79. //-----------------------------------------------------------------------------
  80. // Purpose: base quest restriction
  81. //-----------------------------------------------------------------------------
  82. class CTFQuestRestriction : public CTFQuestCondition
  83. {
  84. public:
  85. DECLARE_CLASS( CTFQuestRestriction, CTFQuestCondition )
  86. virtual const char *GetBaseName() const OVERRIDE { return "restriction"; }
  87. virtual bool PassesRestrictions( IGameEvent *pEvent ) const = 0;
  88. void SetEventName( const char *pszEventName ) OVERRIDE { m_pszEventName = pszEventName; }
  89. virtual const char* GetEventName() const OVERRIDE { return m_pszEventName; }
  90. virtual void GetValidTypes( CUtlVector< const char* >& vecOutValidChildren ) const OVERRIDE;
  91. virtual void GetValidChildren( CUtlVector< const char* >& vecOutValidChildren ) const OVERRIDE;
  92. protected:
  93. const char *m_pszEventName;
  94. };
  95. //-----------------------------------------------------------------------------
  96. // Purpose: base quest evaluator
  97. //-----------------------------------------------------------------------------
  98. class CTFQuestEvaluator : public CTFQuestCondition
  99. {
  100. public:
  101. CTFQuestEvaluator();
  102. virtual const char *GetBaseName() const OVERRIDE { return "evaluator"; }
  103. virtual bool IsEvaluator() const OVERRIDE { return true; }
  104. virtual void EvaluateCondition( CTFQuestEvaluator *pSender, int nScore ) = 0;
  105. virtual void ResetCondition() = 0;
  106. virtual void GetRequiredParamKeys( KeyValues *pRequiredKeys ) OVERRIDE;
  107. virtual void GetOutputKeyValues( KeyValues *pOutputKeys ) OVERRIDE;
  108. virtual void GetValidTypes( CUtlVector< const char* >& vecOutValidChildren ) const OVERRIDE;
  109. virtual void GetValidChildren( CUtlVector< const char* >& vecOutValidChildren ) const OVERRIDE;
  110. void SetAction( const char *pszAction ) { m_pszAction = pszAction; }
  111. const char *GetAction() const { return m_pszAction; }
  112. private:
  113. const char *m_pszAction;
  114. };
  115. CTFQuestRestriction *CreateRestrictionByName( const char *pszName, CTFQuestCondition* pParent );
  116. CTFQuestEvaluator *CreateEvaluatorByName( const char *pszName, CTFQuestCondition*);
  117. #endif // TF_QUEST_RESTRICTION_H