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.

133 lines
4.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "c_baseentity.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. //-----------------------------------------------------------------------------
  11. // Purpose:
  12. //-----------------------------------------------------------------------------
  13. class C_PhysMagnet : public C_BaseAnimating
  14. {
  15. DECLARE_CLASS( C_PhysMagnet, C_BaseAnimating );
  16. public:
  17. DECLARE_CLIENTCLASS();
  18. C_PhysMagnet();
  19. virtual ~C_PhysMagnet();
  20. void PostDataUpdate( DataUpdateType_t updateType );
  21. bool GetShadowCastDirection( Vector *pDirection, ShadowType_t shadowType ) const;
  22. public:
  23. // Data received from the server
  24. CUtlVector< int > m_aAttachedObjectsFromServer;
  25. // Private list of entities on the magnet
  26. CUtlVector< EHANDLE > m_aAttachedObjects;
  27. };
  28. //-----------------------------------------------------------------------------
  29. // Purpose: RecvProxy that converts the Magnet's attached object entindexes to handles
  30. //-----------------------------------------------------------------------------
  31. void RecvProxy_MagnetAttachedObjectList( const CRecvProxyData *pData, void *pStruct, void *pOut )
  32. {
  33. C_PhysMagnet *pMagnet = (C_PhysMagnet*)pOut;
  34. pMagnet->m_aAttachedObjectsFromServer[pData->m_iElement] = pData->m_Value.m_Int;
  35. }
  36. void RecvProxyArrayLength_MagnetAttachedArray( void *pStruct, int objectID, int currentArrayLength )
  37. {
  38. C_PhysMagnet *pMagnet = (C_PhysMagnet*)pStruct;
  39. if ( pMagnet->m_aAttachedObjectsFromServer.Count() != currentArrayLength )
  40. pMagnet->m_aAttachedObjectsFromServer.SetSize( currentArrayLength );
  41. }
  42. IMPLEMENT_CLIENTCLASS_DT(C_PhysMagnet, DT_PhysMagnet, CPhysMagnet)
  43. // ROBIN: Disabled because we don't need it anymore
  44. /*
  45. RecvPropArray2(
  46. RecvProxyArrayLength_MagnetAttachedArray,
  47. RecvPropInt( "magnetattached_array_element", 0, SIZEOF_IGNORE, 0, RecvProxy_MagnetAttachedObjectList ),
  48. 128,
  49. 0,
  50. "magnetattached_array"
  51. )
  52. */
  53. END_RECV_TABLE()
  54. //-----------------------------------------------------------------------------
  55. // Purpose:
  56. //-----------------------------------------------------------------------------
  57. C_PhysMagnet::C_PhysMagnet()
  58. {
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. C_PhysMagnet::~C_PhysMagnet()
  64. {
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. void C_PhysMagnet::PostDataUpdate( DataUpdateType_t updateType )
  70. {
  71. BaseClass::PostDataUpdate( updateType );
  72. /*
  73. // First, detect any entities removed from the magnet and restore their shadows
  74. int iCount = m_aAttachedObjects.Count();
  75. int iServerCount = m_aAttachedObjectsFromServer.Count();
  76. for ( int i = 0; i < iCount; i++ )
  77. {
  78. int iEntIndex = m_aAttachedObjects[i]->entindex();
  79. for ( int j = 0; j < iServerCount; j++ )
  80. {
  81. if ( iEntIndex == m_aAttachedObjectsFromServer[j] )
  82. break;
  83. }
  84. if ( j == iServerCount )
  85. {
  86. // Ok, a previously attached object is no longer attached
  87. m_aAttachedObjects[i]->SetShadowUseOtherEntity( NULL );
  88. m_aAttachedObjects.Remove(i);
  89. }
  90. }
  91. // Make sure newly attached entities have vertical shadows too
  92. for ( i = 0; i < iServerCount; i++ )
  93. {
  94. C_BaseEntity *pEntity = cl_entitylist->GetEnt( m_aAttachedObjectsFromServer[i] );
  95. if ( m_aAttachedObjects.Find( pEntity ) == m_aAttachedObjects.InvalidIndex() )
  96. {
  97. pEntity->SetShadowUseOtherEntity( this );
  98. m_aAttachedObjects.AddToTail( pEntity );
  99. }
  100. }
  101. */
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Purpose: Return a per-entity shadow cast direction
  105. //-----------------------------------------------------------------------------
  106. bool C_PhysMagnet::GetShadowCastDirection( Vector *pDirection, ShadowType_t shadowType ) const
  107. {
  108. // Magnets shadow is more vertical than others
  109. //Vector vecDown = g_pClientShadowMgr->GetShadowDirection() - Vector(0,0,1);
  110. //VectorNormalize( vecDown );
  111. //*pDirection = vecDown;
  112. *pDirection = Vector(0,0,-1);
  113. return true;
  114. }