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.

111 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Condition Objects
  4. //
  5. //=============================================================================
  6. #ifndef TF_CONDITION_H
  7. #define TF_CONDITION_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "utlvector.h"
  12. #include "utlstack.h"
  13. #include "tf_shareddefs.h"
  14. #ifdef CLIENT_DLL
  15. // Avoid redef warnings
  16. #undef CTFPlayer
  17. #define CTFPlayer C_TFPlayer
  18. class C_TFPlayer;
  19. #endif
  20. class CTFPlayer;
  21. class CTFCondition;
  22. class CTFConditionList
  23. {
  24. public:
  25. DECLARE_EMBEDDED_NETWORKVAR();
  26. DECLARE_CLASS_NOBASE( CTFConditionList );
  27. DECLARE_PREDICTABLE();
  28. CTFConditionList();
  29. bool Add( ETFCond type, float duration, CTFPlayer* outer, CBaseEntity* provider = NULL );
  30. bool _Add( ETFCond type, float duration, CTFPlayer* outer, CBaseEntity* provider = NULL );
  31. bool Remove( ETFCond type, bool ignore_duration=false );
  32. bool _Remove( ETFCond type, bool ignore_duration=false );
  33. void RemoveAll();
  34. bool InCond( ETFCond type ) const;
  35. CBaseEntity *GetProvider( ETFCond type ) const;
  36. void Think();
  37. void ServerThink();
  38. #ifdef CLIENT_DLL
  39. // Forwarded from player shared.
  40. virtual void OnPreDataChanged( void );
  41. virtual void OnDataChanged( CTFPlayer* outer );
  42. void UpdateClientConditions( CTFPlayer* outer );
  43. #endif
  44. private:
  45. CUtlVector< CTFCondition* > _conditions;
  46. CNetworkVar( int, _condition_bits ); // Bitfield of set conditions for fast checking.
  47. int _old_condition_bits;
  48. };
  49. class CTFCondition
  50. {
  51. public:
  52. CTFCondition( ETFCond type, float duration, CTFPlayer* outer, CBaseEntity* provider = NULL );
  53. virtual ~CTFCondition();
  54. virtual void Add( float duration );
  55. virtual void OnAdded() = 0;
  56. virtual void OnRemoved() = 0;
  57. virtual void OnThink() = 0;
  58. virtual void OnServerThink() = 0;
  59. // Condition Traits
  60. virtual bool IsHealable() { return false; }
  61. virtual bool UsesMinDuration() { return false; }
  62. ETFCond GetType() { return _type; }
  63. float GetMaxDuration() { return _max_duration; }
  64. void SetMaxDuration( float val ) { _max_duration = val; }
  65. float GetMinDuration() { return _min_duration; }
  66. void SetMinDuration( float val ) { if ( UsesMinDuration() ) { _min_duration = val; } }
  67. CTFPlayer* GetOuter() { return _outer; }
  68. void SetProvider( CBaseEntity *provider ) { _provider = provider; }
  69. CBaseEntity* GetProvider() { return _provider; }
  70. private:
  71. float _min_duration;
  72. float _max_duration;
  73. const ETFCond _type;
  74. CTFPlayer* _outer;
  75. CHandle< CBaseEntity > _provider;
  76. };
  77. class CTFCondition_CritBoost : public CTFCondition
  78. {
  79. public:
  80. CTFCondition_CritBoost( ETFCond type, float duration, CTFPlayer* outer, CBaseEntity* provider = NULL );
  81. virtual void OnAdded();
  82. virtual void OnRemoved();
  83. virtual void OnThink();
  84. virtual void OnServerThink();
  85. // Condition Traits
  86. virtual bool IsHealable() { return false; }
  87. virtual bool UsesMinDuration() { return true; }
  88. };
  89. #endif