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.

158 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef PATHTRACK_H
  7. #define PATHTRACK_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "entityoutput.h"
  12. #include "shareddefs.h"
  13. //-----------------------------------------------------------------------------
  14. // Spawnflag for CPathTrack
  15. //-----------------------------------------------------------------------------
  16. #define SF_PATH_DISABLED 0x00000001
  17. //#define SF_PATH_FIREONCE 0x00000002
  18. #define SF_PATH_ALTREVERSE 0x00000004
  19. #define SF_PATH_DISABLE_TRAIN 0x00000008
  20. #define SF_PATH_TELEPORT 0x00000010
  21. #define SF_PATH_UPHILL 0x00000020
  22. #define SF_PATH_DOWNHILL 0x00000040
  23. #define SF_PATH_ALTERNATE 0x00008000
  24. enum TrackOrientationType_t
  25. {
  26. TrackOrientation_Fixed = 0,
  27. TrackOrientation_FacePath,
  28. TrackOrientation_FacePathAngles,
  29. };
  30. //-----------------------------------------------------------------------------
  31. // Paths!
  32. //-----------------------------------------------------------------------------
  33. class CPathTrack : public CPointEntity
  34. {
  35. DECLARE_CLASS( CPathTrack, CPointEntity );
  36. public:
  37. CPathTrack();
  38. void Spawn( void );
  39. void Activate( void );
  40. void DrawDebugGeometryOverlays();
  41. void ToggleAlternatePath( void );
  42. void EnableAlternatePath( void );
  43. void DisableAlternatePath( void );
  44. bool HasAlternathPath() const;
  45. void TogglePath( void );
  46. void EnablePath( void );
  47. void DisablePath( void );
  48. static CPathTrack *ValidPath( CPathTrack *ppath, int testFlag = true ); // Returns ppath if enabled, NULL otherwise
  49. CPathTrack *GetNextInDir( bool bForward );
  50. CPathTrack *GetNext( void );
  51. CPathTrack *GetPrevious( void );
  52. CPathTrack *Nearest( const Vector &origin );
  53. //CPathTrack *LookAhead( Vector &origin, float dist, int move );
  54. CPathTrack *LookAhead( Vector &origin, float dist, int move, CPathTrack **pNextNext = NULL );
  55. TrackOrientationType_t GetOrientationType();
  56. QAngle GetOrientation( bool bForwardDir );
  57. CHandle<CPathTrack> m_pnext;
  58. CHandle<CPathTrack> m_pprevious;
  59. CHandle<CPathTrack> m_paltpath;
  60. float GetRadius() const { return m_flRadius; }
  61. // These four methods help for circular path checking. Call BeginIteration
  62. // before iterating, EndInteration afterwards. Call Visit on each path in the
  63. // list. Then you can use HasBeenVisited to see if you've visited the node
  64. // already, which means you've got a circular or lasso path. You can use the
  65. // macro BEGIN_PATH_TRACK_ITERATION below to simplify the calls to
  66. // BeginInteration + EndIteration.
  67. static void BeginIteration();
  68. static void EndIteration();
  69. void Visit();
  70. bool HasBeenVisited() const;
  71. bool IsUpHill(){ return ( FBitSet( m_spawnflags, SF_PATH_UPHILL ) ) ? true : false; }
  72. bool IsDownHill(){ return ( FBitSet( m_spawnflags, SF_PATH_DOWNHILL ) ) ? true : false; }
  73. int GetHillType()
  74. {
  75. int iRetVal = HILL_TYPE_NONE;
  76. if ( IsUpHill() )
  77. {
  78. iRetVal = HILL_TYPE_UPHILL;
  79. }
  80. else if ( IsDownHill() )
  81. {
  82. iRetVal = HILL_TYPE_DOWNHILL;
  83. }
  84. return iRetVal;
  85. }
  86. bool IsDisabled( void ){ return FBitSet( m_spawnflags, SF_PATH_DISABLED ); }
  87. void InputPass( inputdata_t &inputdata );
  88. void InputTeleport( inputdata_t &inputdata );
  89. void InputToggleAlternatePath( inputdata_t &inputdata );
  90. void InputEnableAlternatePath( inputdata_t &inputdata );
  91. void InputDisableAlternatePath( inputdata_t &inputdata );
  92. void InputTogglePath( inputdata_t &inputdata );
  93. void InputEnablePath( inputdata_t &inputdata );
  94. void InputDisablePath( inputdata_t &inputdata );
  95. private:
  96. void Project( CPathTrack *pstart, CPathTrack *pend, Vector &origin, float dist );
  97. void SetPrevious( CPathTrack *pprevious );
  98. void Link( void );
  99. static CPathTrack *Instance( edict_t *pent );
  100. DECLARE_DATADESC();
  101. float m_flRadius;
  102. float m_length;
  103. string_t m_altName;
  104. int m_nIterVal;
  105. TrackOrientationType_t m_eOrientationType;
  106. COutputEvent m_OnPass;
  107. COutputEvent m_OnTeleport;
  108. static int s_nCurrIterVal;
  109. static bool s_bIsIterating;
  110. };
  111. //-----------------------------------------------------------------------------
  112. // Used to make sure circular iteration works all nice
  113. //-----------------------------------------------------------------------------
  114. #define BEGIN_PATH_TRACK_ITERATION() CPathTrackVisitor _visit
  115. class CPathTrackVisitor
  116. {
  117. public:
  118. CPathTrackVisitor() { CPathTrack::BeginIteration(); }
  119. ~CPathTrackVisitor() { CPathTrack::EndIteration(); }
  120. };
  121. #endif // PATHTRACK_H