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.

217 lines
6.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef TRAINS_H
  7. #define TRAINS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "entityoutput.h"
  12. #include "pathtrack.h"
  13. // Spawnflags of CPathCorner
  14. #define SF_CORNER_WAITFORTRIG 0x001
  15. #define SF_CORNER_TELEPORT 0x002
  16. // Tracktrain spawn flags
  17. #define SF_TRACKTRAIN_NOPITCH 0x0001
  18. #define SF_TRACKTRAIN_NOCONTROL 0x0002
  19. #define SF_TRACKTRAIN_FORWARDONLY 0x0004
  20. #define SF_TRACKTRAIN_PASSABLE 0x0008
  21. #define SF_TRACKTRAIN_FIXED_ORIENTATION 0x0010
  22. #define SF_TRACKTRAIN_HL1TRAIN 0x0080
  23. #define SF_TRACKTRAIN_USE_MAXSPEED_FOR_PITCH 0x0100
  24. #define SF_TRACKTRAIN_UNBLOCKABLE_BY_PLAYER 0x0200
  25. #define TRAIN_ACTIVE 0x80
  26. #define TRAIN_NEW 0xc0
  27. #define TRAIN_OFF 0x00
  28. #define TRAIN_NEUTRAL 0x01
  29. #define TRAIN_SLOW 0x02
  30. #define TRAIN_MEDIUM 0x03
  31. #define TRAIN_FAST 0x04
  32. #define TRAIN_BACK 0x05
  33. enum TrainVelocityType_t
  34. {
  35. TrainVelocity_Instantaneous = 0,
  36. TrainVelocity_LinearBlend,
  37. TrainVelocity_EaseInEaseOut,
  38. };
  39. enum TrainOrientationType_t
  40. {
  41. TrainOrientation_Fixed = 0,
  42. TrainOrientation_AtPathTracks,
  43. TrainOrientation_LinearBlend,
  44. TrainOrientation_EaseInEaseOut,
  45. };
  46. class CFuncTrackTrain : public CBaseEntity
  47. {
  48. DECLARE_CLASS( CFuncTrackTrain, CBaseEntity );
  49. DECLARE_SERVERCLASS();
  50. public:
  51. CFuncTrackTrain();
  52. void Spawn( void );
  53. bool CreateVPhysics( void );
  54. void Precache( void );
  55. void UpdateOnRemove();
  56. void MoveDone();
  57. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  58. void Blocked( CBaseEntity *pOther );
  59. bool KeyValue( const char *szKeyName, const char *szValue );
  60. virtual int DrawDebugTextOverlays();
  61. void DrawDebugGeometryOverlays();
  62. void Next( void );
  63. void Find( void );
  64. void NearestPath( void );
  65. void DeadEnd( void );
  66. void SetTrack( CPathTrack *track ) { m_ppath = track->Nearest(GetLocalOrigin()); }
  67. void SetControls( CBaseEntity *pControls );
  68. bool OnControls( CBaseEntity *pControls );
  69. void SoundStop( void );
  70. void SoundUpdate( void );
  71. void Start( void );
  72. void Stop( void );
  73. bool IsDirForward();
  74. void SetDirForward( bool bForward );
  75. void SetSpeed( float flSpeed, bool bAccel = false );
  76. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  77. void SetSpeedDirAccel( float flNewSpeed );
  78. // Input handlers
  79. void InputSetSpeed( inputdata_t &inputdata );
  80. void InputSetSpeedDir( inputdata_t &inputdata );
  81. void InputSetSpeedReal( inputdata_t &inputdata );
  82. void InputStop( inputdata_t &inputdata );
  83. void InputResume( inputdata_t &inputdata );
  84. void InputReverse( inputdata_t &inputdata );
  85. void InputStartForward( inputdata_t &inputdata );
  86. void InputStartBackward( inputdata_t &inputdata );
  87. void InputToggle( inputdata_t &inputdata );
  88. void InputSetSpeedDirAccel( inputdata_t &inputdata );
  89. void InputTeleportToPathTrack( inputdata_t &inputdata );
  90. void InputSetSpeedForwardModifier( inputdata_t &inputdata );
  91. static CFuncTrackTrain *Instance( edict_t *pent );
  92. #ifdef TF_DLL
  93. int UpdateTransmitState()
  94. {
  95. return SetTransmitState( FL_EDICT_ALWAYS );
  96. }
  97. #endif
  98. DECLARE_DATADESC();
  99. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() | FCAP_DIRECTIONAL_USE | FCAP_USE_ONGROUND; }
  100. virtual void OnRestore( void );
  101. float GetMaxSpeed() const { return m_maxSpeed; }
  102. float GetCurrentSpeed() const { return m_flSpeed; }
  103. float GetDesiredSpeed() const { return m_flDesiredSpeed;}
  104. virtual bool IsBaseTrain( void ) const { return true; }
  105. void SetSpeedForwardModifier( float flModifier );
  106. void SetBlockDamage( float flDamage ) { m_flBlockDamage = flDamage; }
  107. void SetDamageChild( bool bDamageChild ) { m_bDamageChild = bDamageChild; }
  108. private:
  109. void ArriveAtNode( CPathTrack *pNode );
  110. void FirePassInputs( CPathTrack *pStart, CPathTrack *pEnd, bool forward );
  111. public:
  112. // UNDONE: Add accessors?
  113. CPathTrack *m_ppath;
  114. float m_length;
  115. #ifdef HL1_DLL
  116. bool m_bOnTrackChange; // we don't want to find a new node if we restore while
  117. // riding on a func_trackchange
  118. #endif
  119. private:
  120. TrainVelocityType_t GetTrainVelocityType();
  121. void UpdateTrainVelocity( CPathTrack *pnext, CPathTrack *pNextNext, const Vector &nextPos, float flInterval );
  122. TrainOrientationType_t GetTrainOrientationType();
  123. void UpdateTrainOrientation( CPathTrack *pnext, CPathTrack *pNextNext, const Vector &nextPos, float flInterval );
  124. void UpdateOrientationAtPathTracks( CPathTrack *pnext, CPathTrack *pNextNext, const Vector &nextPos, float flInterval );
  125. void UpdateOrientationBlend( TrainOrientationType_t eOrientationType, CPathTrack *pPrev, CPathTrack *pNext, const Vector &nextPos, float flInterval );
  126. void DoUpdateOrientation( const QAngle &curAngles, const QAngle &angles, float flInterval );
  127. void TeleportToPathTrack( CPathTrack *pTeleport );
  128. Vector m_controlMins;
  129. Vector m_controlMaxs;
  130. Vector m_lastBlockPos; // These are used to build a heuristic decision about being temporarily blocked by physics objects
  131. int m_lastBlockTick; // ^^^^^^^
  132. float m_flVolume;
  133. float m_flBank;
  134. float m_oldSpeed;
  135. float m_flBlockDamage; // Damage to inflict when blocked.
  136. float m_height;
  137. float m_maxSpeed;
  138. float m_dir;
  139. string_t m_iszSoundMove; // Looping sound to play while moving. Pitch shifted based on speed.
  140. string_t m_iszSoundMovePing; // Ping sound to play while moving. Interval decreased based on speed.
  141. string_t m_iszSoundStart; // Sound to play when starting to move.
  142. string_t m_iszSoundStop; // Sound to play when stopping.
  143. float m_flMoveSoundMinTime; // The most often to play the move 'ping' sound (used at max speed)
  144. float m_flMoveSoundMaxTime; // The least often to play the move 'ping' sound (used approaching zero speed)
  145. float m_flNextMoveSoundTime;
  146. int m_nMoveSoundMinPitch; // The sound pitch to approach as we come to a stop
  147. int m_nMoveSoundMaxPitch; // The sound pitch to approach as we approach our max speed (actually, it's hardcoded to 1000 in/sec)
  148. TrainOrientationType_t m_eOrientationType;
  149. TrainVelocityType_t m_eVelocityType;
  150. bool m_bSoundPlaying;
  151. COutputEvent m_OnStart,m_OnNext;
  152. bool m_bManualSpeedChanges; // set when we want to send entity IO to govern speed and obey our TrainVelocityType_t
  153. float m_flDesiredSpeed; // target speed, when m_bManualSpeedChanges is set
  154. float m_flSpeedChangeTime;
  155. float m_flAccelSpeed;
  156. float m_flDecelSpeed;
  157. bool m_bAccelToSpeed;
  158. float m_flNextMPSoundTime;
  159. float m_flSpeedForwardModifier;
  160. float m_flUnmodifiedDesiredSpeed;
  161. bool m_bDamageChild;
  162. };
  163. #endif // TRAINS_H