Counter Strike : Global Offensive Source Code
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.

203 lines
6.3 KiB

  1. //========= Copyright � 1996-2005, 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 SF_TRACKTRAIN_ALLOWROLL 0x0400
  26. #define TRAIN_ACTIVE 0x80
  27. #define TRAIN_NEW 0xc0
  28. #define TRAIN_OFF 0x00
  29. #define TRAIN_NEUTRAL 0x01
  30. #define TRAIN_SLOW 0x02
  31. #define TRAIN_MEDIUM 0x03
  32. #define TRAIN_FAST 0x04
  33. #define TRAIN_BACK 0x05
  34. enum TrainVelocityType_t
  35. {
  36. TrainVelocity_Instantaneous = 0,
  37. TrainVelocity_LinearBlend,
  38. TrainVelocity_EaseInEaseOut,
  39. };
  40. enum TrainOrientationType_t
  41. {
  42. TrainOrientation_Fixed = 0,
  43. TrainOrientation_AtPathTracks,
  44. TrainOrientation_LinearBlend,
  45. TrainOrientation_EaseInEaseOut,
  46. };
  47. class CFuncTrackTrain : public CBaseEntity
  48. {
  49. DECLARE_CLASS( CFuncTrackTrain, CBaseEntity );
  50. DECLARE_ENT_SCRIPTDESC();
  51. DECLARE_SERVERCLASS();
  52. public:
  53. CFuncTrackTrain();
  54. void Spawn( void );
  55. bool CreateVPhysics( void );
  56. void Precache( void );
  57. void UpdateOnRemove();
  58. void MoveDone();
  59. void Blocked( CBaseEntity *pOther );
  60. bool KeyValue( const char *szKeyName, const char *szValue );
  61. virtual int DrawDebugTextOverlays();
  62. void DrawDebugGeometryOverlays();
  63. void Next( void );
  64. void Find( void );
  65. void NearestPath( void );
  66. void DeadEnd( void );
  67. void SetTrack( CPathTrack *track ) { m_ppath = track->Nearest(GetLocalOrigin()); }
  68. void SetControls( CBaseEntity *pControls );
  69. bool OnControls( CBaseEntity *pControls );
  70. void SoundStop( void );
  71. void SoundUpdate( void );
  72. void Start( void );
  73. void Stop( void );
  74. bool IsDirForward();
  75. void SetDirForward( bool bForward );
  76. void SetSpeed( float flSpeed, bool bAccel = false );
  77. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  78. // Input handlers
  79. void InputSetSpeed( inputdata_t &inputdata );
  80. void InputSetMaxSpeed( inputdata_t &inputdata );
  81. void InputSetSpeedDir( inputdata_t &inputdata );
  82. void InputSetSpeedReal( inputdata_t &inputdata );
  83. void InputStop( inputdata_t &inputdata );
  84. void InputResume( inputdata_t &inputdata );
  85. void InputReverse( inputdata_t &inputdata );
  86. void InputStartForward( inputdata_t &inputdata );
  87. void InputStartBackward( inputdata_t &inputdata );
  88. void InputToggle( inputdata_t &inputdata );
  89. void InputSetSpeedDirAccel( inputdata_t &inputdata );
  90. void InputMoveToPathNode( inputdata_t &inputdata );
  91. void InputTeleportToPathNode( inputdata_t &inputdata );
  92. void InputLockOrientation( inputdata_t &inputdata );
  93. void InputUnlockOrientation( inputdata_t &inputdata );
  94. static CFuncTrackTrain *Instance( edict_t *pent );
  95. DECLARE_DATADESC();
  96. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() | FCAP_DIRECTIONAL_USE | FCAP_USE_ONGROUND; }
  97. virtual void OnRestore( void );
  98. float GetMaxSpeed() const { return m_maxSpeed; }
  99. float GetCurrentSpeed() const { return m_flSpeed; }
  100. float GetDesiredSpeed() const { return m_flDesiredSpeed;}
  101. virtual bool IsBaseTrain( void ) const { return true; }
  102. Vector ScriptGetFuturePosition( float flSeconds, float flMinSpeed );
  103. private:
  104. void ArriveAtNode( CPathTrack *pNode );
  105. void FirePassInputs( CPathTrack *pStart, CPathTrack *pEnd, bool forward );
  106. public:
  107. // UNDONE: Add accessors?
  108. CPathTrack *m_ppath;
  109. float m_length;
  110. private:
  111. TrainVelocityType_t GetTrainVelocityType();
  112. void UpdateTrainVelocity( CPathTrack *pnext, CPathTrack *pNextNext, const Vector &nextPos, float flInterval );
  113. TrainOrientationType_t GetTrainOrientationType();
  114. void UpdateTrainOrientation( CPathTrack *pnext, CPathTrack *pNextNext, const Vector &nextPos, float flInterval );
  115. void UpdateOrientationAtPathTracks( CPathTrack *pnext, CPathTrack *pNextNext, const Vector &nextPos, float flInterval );
  116. void UpdateOrientationBlend( TrainOrientationType_t eOrientationType, CPathTrack *pPrev, CPathTrack *pNext, const Vector &nextPos, float flInterval );
  117. void DoUpdateOrientation( const QAngle &curAngles, const QAngle &angles, float flInterval );
  118. void TeleportToPathTrack( CPathTrack *pTeleport );
  119. Vector m_controlMins;
  120. Vector m_controlMaxs;
  121. Vector m_lastBlockPos; // These are used to build a heuristic decision about being temporarily blocked by physics objects
  122. int m_lastBlockTick; // ^^^^^^^
  123. float m_flVolume;
  124. float m_flBank;
  125. float m_oldSpeed;
  126. float m_flBlockDamage; // Damage to inflict when blocked.
  127. float m_height;
  128. float m_maxSpeed;
  129. float m_dir;
  130. string_t m_iszSoundMove; // Looping sound to play while moving. Pitch shifted based on speed.
  131. string_t m_iszSoundMovePing; // Ping sound to play while moving. Interval decreased based on speed.
  132. string_t m_iszSoundStart; // Sound to play when starting to move.
  133. string_t m_iszSoundStop; // Sound to play when stopping.
  134. string_t m_strPathTarget; // Destination node
  135. float m_flMoveSoundMinTime; // The most often to play the move 'ping' sound (used at max speed)
  136. float m_flMoveSoundMaxTime; // The least often to play the move 'ping' sound (used approaching zero speed)
  137. float m_flNextMoveSoundTime;
  138. int m_nMoveSoundMinPitch; // The sound pitch to approach as we come to a stop
  139. int m_nMoveSoundMaxPitch; // The sound pitch to approach as we approach our max speed (actually, it's hardcoded to 1000 in/sec)
  140. TrainOrientationType_t m_eOrientationType;
  141. TrainVelocityType_t m_eVelocityType;
  142. bool m_bSoundPlaying;
  143. COutputEvent m_OnStart,m_OnNext;
  144. COutputEvent m_OnArrivedAtDestinationNode;
  145. bool m_bManualSpeedChanges; // set when we want to send entity IO to govern speed and obey our TrainVelocityType_t
  146. float m_flDesiredSpeed; // target speed, when m_bManualSpeedChanges is set
  147. float m_flSpeedChangeTime;
  148. float m_flAccelSpeed;
  149. float m_flDecelSpeed;
  150. bool m_bAccelToSpeed;
  151. float m_flNextMPSoundTime;
  152. };
  153. #endif // TRAINS_H