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.

219 lines
6.2 KiB

  1. //========= Copyright � 1996-2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: First-class cube entity so we can query by type and generally make inferences
  4. // that are harder to do without an entity of that type.
  5. //
  6. //=====================================================================================//
  7. #include "cbase.h"
  8. #include "props.h"
  9. #include "ai_utils.h"
  10. #include "physics_saverestore.h"
  11. #include "phys_controller.h"
  12. #include "portal_base2d.h"
  13. #include "datacache/imdlcache.h"
  14. #include "func_portal_detector.h"
  15. #include "player_pickup_paint_power_user.h"
  16. DECLARE_AUTO_LIST( IPropWeightedCubeAutoList );
  17. enum WeightedCubeType_e
  18. {
  19. CUBE_STANDARD,
  20. CUBE_COMPANION,
  21. CUBE_REFLECTIVE,
  22. CUBE_SPHERE,
  23. CUBE_ANTIQUE,
  24. CUBE_SCHRODINGER,
  25. };
  26. //
  27. // Tip controller
  28. //
  29. class CCubeRotationController : public CPointEntity, public IMotionEvent
  30. {
  31. DECLARE_CLASS( CCubeRotationController, CPointEntity );
  32. DECLARE_DATADESC();
  33. public:
  34. ~CCubeRotationController( void );
  35. void Spawn( void );
  36. void Activate( void );
  37. void Enable( bool state = true );
  38. void Suspend( float time );
  39. float SuspendedTill( void );
  40. void SetAlignmentVector( const Vector &vecAlign );
  41. Vector GetAlignmentVector( void ) { return m_worldGoalAxis; }
  42. void SuspendAfter( float flTime );
  43. bool Enabled( void );
  44. static CCubeRotationController *CreateRotationController( CBaseEntity *pOwner );
  45. // IMotionEvent
  46. virtual simresult_e Simulate( IPhysicsMotionController *pController, IPhysicsObject *pObject, float deltaTime, Vector &linear, AngularImpulse &angular );
  47. private:
  48. bool m_bEnabled;
  49. float m_flSuspendTime;
  50. Vector m_worldGoalAxis;
  51. Vector m_localTestAxis;
  52. IPhysicsMotionController *m_pController;
  53. float m_angularLimit;
  54. CBaseEntity *m_pParent;
  55. };
  56. class CPropWeightedCube : public PlayerPickupPaintPowerUser< CPhysicsProp >, public IPropWeightedCubeAutoList
  57. {
  58. public:
  59. DECLARE_CLASS( CPropWeightedCube, PlayerPickupPaintPowerUser< CPhysicsProp > );
  60. DECLARE_SERVERCLASS();
  61. IMPLEMENT_AUTO_LIST_GET();
  62. CPropWeightedCube();
  63. virtual void Spawn( void );
  64. virtual void Activate( void );
  65. virtual void Precache( void );
  66. virtual int ObjectCaps( void );
  67. virtual void OnFizzled( void )
  68. {
  69. // Handle the special Summer Sale achievement case
  70. // If a cube ever fizzles on the "red racer" map, the achievement is lost
  71. if ( V_stricmp( STRING(gpGlobals->mapname), "mp_coop_paint_red_racer" ) == 0 )
  72. {
  73. CBaseEntity *pEntity = gEntList.FindEntityByName( NULL, "@glados" );
  74. if ( pEntity )
  75. {
  76. pEntity->RunScript( "CoopCubeFizzle()", "OnFizzled" );
  77. }
  78. }
  79. m_OnFizzled.FireOutput( this, this );
  80. }
  81. virtual bool HasPreferredCarryAnglesForPlayer( CBasePlayer *pPlayer );
  82. virtual QAngle PreferredCarryAngles( void );
  83. virtual void OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  84. virtual void OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t reason );
  85. virtual void UpdateOnRemove( void );
  86. virtual void NotifySystemEvent(CBaseEntity *pNotify, notify_system_event_t eventType, const notify_system_event_params_t &params );
  87. virtual void StartTouch( CBaseEntity *pOther );
  88. virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  89. void SetSkin( int skinNum );
  90. void SetActivated( bool bActivate );
  91. // instead of getting which model it uses, we can just ask this
  92. WeightedCubeType_e GetCubeType( void ) { return m_nCubeType; }
  93. #ifndef CLIENT_DLL
  94. CPropWeightedCube* GetSchrodingerTwin( void );
  95. #endif
  96. void SetLaser( CBaseEntity *pLaser );
  97. CBaseEntity* GetLaser()
  98. {
  99. return m_hLaser.Get();
  100. }
  101. bool HasLaser( void )
  102. {
  103. return m_hLaser.Get() != NULL;
  104. }
  105. virtual int UpdateTransmitState();
  106. virtual void Paint( PaintPowerType paintType, const Vector &worldContactPt );
  107. void UpdateSchrodingerSound( void );
  108. void SchrodingerThink( void );
  109. void DisabledThink( void );
  110. bool IsMovementDisabled() const { return m_bMovementDisabled; }
  111. bool ShouldEnterDisabledState( void );
  112. void EnterDisabledState( void );
  113. void ExitDisabledState( void );
  114. void OnEnteredTractorBeam( void );
  115. void OnExitedTractorBeam( void );
  116. void TractorBeamThink( void );
  117. void ExitTractorBeamThink( void );
  118. bool WasTouchedByPlayer() { return m_bTouchedByPlayer; }
  119. #ifndef CLIENT_DLL
  120. #define CREATE_CUBE_AT_POSITION false
  121. static void CreatePortalWeightedCube( WeightedCubeType_e objectType, bool bAtCursorPosition = true, const Vector &position = vec3_origin );
  122. #endif
  123. private:
  124. void ConvertOldSkins( void );
  125. void SetCubeType( void );
  126. void SetPaintedMaterial( PaintPowerType paintType );
  127. void SetCubeSkin( void );
  128. void InputDissolve( inputdata_t &in );
  129. void InputSilentDissolve( inputdata_t &in );
  130. void InputPreDissolveJoke( inputdata_t &in );
  131. QAngle CalculatePreferredAngles( CBasePlayer *pPlayer );
  132. void UpdatePreferredAngles( CBasePlayer *pPlayer );
  133. COutputEvent m_OnFizzled;
  134. COutputEvent m_OnBluePickUp;
  135. COutputEvent m_OnOrangePickUp;
  136. COutputEvent m_OnPainted;
  137. QAngle m_vecCarryAngles;
  138. CHandle<CCubeRotationController> m_pController;
  139. EHANDLE m_hLaser;
  140. int m_nBouncyMaterialIndex;
  141. void InputDisablePortalFunnel( inputdata_t &in );
  142. void InputEnablePortalFunnel( inputdata_t &in );
  143. void InputExitDisabledState( inputdata_t &in );
  144. void InputSetPaint( inputdata_t &in );
  145. void InputDisablePickup( inputdata_t &in );
  146. void InputEnablePickup( inputdata_t &in );
  147. DECLARE_DATADESC();
  148. CSoundPatch *m_pSchrodingerSound;
  149. WeightedCubeType_e m_nCubeType;
  150. bool m_bRusted;
  151. bool m_bActivated;
  152. bool m_bNewSkins;
  153. PaintPowerType m_nCurrentPaintedType;
  154. float m_flDisabledNudgeStartTime;
  155. bool m_bMovementDisabled;
  156. bool m_bTouchedByPlayer;
  157. bool m_bPickupDisabled;
  158. #ifndef CLIENT_DLL
  159. // Schrodinger's Balls
  160. CHandle< CPropWeightedCube > m_hSchrodingerTwin;
  161. static CHandle< CPropWeightedCube > m_hSchrodingerDangling;
  162. #endif
  163. };
  164. bool UTIL_IsReflectiveCube( CBaseEntity *pEntity );
  165. bool UTIL_IsWeightedCube( CBaseEntity *pEntity );
  166. #ifndef CLIENT_DLL
  167. bool UTIL_IsSchrodinger( CBaseEntity *pEntity );
  168. CPropWeightedCube* UTIL_GetSchrodingerTwin( CBaseEntity *pEntity );
  169. #endif