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.

185 lines
5.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef OBSTACLE_PUSHAWAY_H
  7. #define OBSTACLE_PUSHAWAY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "props_shared.h"
  12. #ifndef CLIENT_DLL
  13. #include "func_breakablesurf.h"
  14. #include "BasePropDoor.h"
  15. #include "doors.h"
  16. #endif // CLIENT_DLL
  17. //--------------------------------------------------------------------------------------------------------------
  18. bool IsPushAwayEntity( CBaseEntity *pEnt );
  19. bool IsPushableEntity( CBaseEntity *pEnt );
  20. //--------------------------------------------------------------------------------------------------------------
  21. bool IsBreakableEntity( CBaseEntity *pEnt );
  22. //--------------------------------------------------------------------------------------------------------------
  23. class CPushAwayEnumerator : public IPartitionEnumerator
  24. {
  25. public:
  26. // Forced constructor
  27. CPushAwayEnumerator(CBaseEntity **ents, int nMaxEnts)
  28. {
  29. m_nAlreadyHit = 0;
  30. m_AlreadyHit = ents;
  31. m_nMaxHits = nMaxEnts;
  32. }
  33. // Actual work code
  34. virtual IterationRetval_t EnumElement( IHandleEntity *pHandleEntity )
  35. {
  36. #ifdef CLIENT_DLL
  37. CBaseEntity *pEnt = ClientEntityList().GetBaseEntityFromHandle( pHandleEntity->GetRefEHandle() );
  38. #else
  39. CBaseEntity *pEnt = gEntList.GetBaseEntity( pHandleEntity->GetRefEHandle() );
  40. #endif // CLIENT_DLL
  41. if ( IsPushAwayEntity( pEnt ) && m_nAlreadyHit < m_nMaxHits )
  42. {
  43. m_AlreadyHit[m_nAlreadyHit] = pEnt;
  44. m_nAlreadyHit++;
  45. }
  46. return ITERATION_CONTINUE;
  47. }
  48. public:
  49. CBaseEntity **m_AlreadyHit;
  50. int m_nAlreadyHit;
  51. int m_nMaxHits;
  52. };
  53. #ifndef CLIENT_DLL
  54. //--------------------------------------------------------------------------------------------------------------
  55. /**
  56. * This class will collect breakable objects in a volume. Physics props that can be damaged, func_breakable*, etc
  57. * are all collected by this class.
  58. */
  59. class CBotBreakableEnumerator : public CPushAwayEnumerator
  60. {
  61. public:
  62. CBotBreakableEnumerator(CBaseEntity **ents, int nMaxEnts) : CPushAwayEnumerator(ents, nMaxEnts)
  63. {
  64. }
  65. virtual IterationRetval_t EnumElement( IHandleEntity *pHandleEntity )
  66. {
  67. CBaseEntity *pEnt = gEntList.GetBaseEntity( pHandleEntity->GetRefEHandle() );
  68. if ( !IsBreakableEntity( pEnt ) )
  69. return ITERATION_CONTINUE;
  70. // ignore breakables parented to doors
  71. if ( pEnt->GetParent() &&
  72. ( FClassnameIs( pEnt->GetParent(), "func_door*" ) ||
  73. FClassnameIs( pEnt, "prop_door*" ) ) )
  74. return ITERATION_CONTINUE;
  75. if ( m_nAlreadyHit < m_nMaxHits )
  76. {
  77. m_AlreadyHit[m_nAlreadyHit] = pEnt;
  78. m_nAlreadyHit++;
  79. }
  80. return ITERATION_CONTINUE;
  81. }
  82. };
  83. //--------------------------------------------------------------------------------------------------------------
  84. /**
  85. * This class will collect door objects in a volume.
  86. */
  87. class CBotDoorEnumerator : public CPushAwayEnumerator
  88. {
  89. public:
  90. CBotDoorEnumerator(CBaseEntity **ents, int nMaxEnts) : CPushAwayEnumerator(ents, nMaxEnts)
  91. {
  92. }
  93. virtual IterationRetval_t EnumElement( IHandleEntity *pHandleEntity )
  94. {
  95. CBaseEntity *pEnt = gEntList.GetBaseEntity( pHandleEntity->GetRefEHandle() );
  96. if ( pEnt == NULL )
  97. return ITERATION_CONTINUE;
  98. if ( ( pEnt->ObjectCaps() & FCAP_IMPULSE_USE ) == 0 )
  99. {
  100. return ITERATION_CONTINUE;
  101. }
  102. if ( FClassnameIs( pEnt, "func_door*" ) )
  103. {
  104. CBaseDoor *door = dynamic_cast<CBaseDoor *>(pEnt);
  105. if ( !door )
  106. {
  107. return ITERATION_CONTINUE;
  108. }
  109. if ( door->m_toggle_state == TS_GOING_UP || door->m_toggle_state == TS_GOING_DOWN )
  110. {
  111. return ITERATION_CONTINUE;
  112. }
  113. }
  114. else if ( FClassnameIs( pEnt, "prop_door*" ) )
  115. {
  116. CBasePropDoor *door = dynamic_cast<CBasePropDoor *>(pEnt);
  117. if ( !door )
  118. {
  119. return ITERATION_CONTINUE;
  120. }
  121. if ( door->IsDoorOpening() || door->IsDoorClosing() )
  122. {
  123. return ITERATION_CONTINUE;
  124. }
  125. }
  126. else
  127. {
  128. return ITERATION_CONTINUE;
  129. }
  130. if ( m_nAlreadyHit < m_nMaxHits )
  131. {
  132. m_AlreadyHit[m_nAlreadyHit] = pEnt;
  133. m_nAlreadyHit++;
  134. }
  135. return ITERATION_CONTINUE;
  136. }
  137. };
  138. //--------------------------------------------------------------------------------------------------------------
  139. /**
  140. * Returns an entity that matches the filter that is along the line segment
  141. */
  142. CBaseEntity * CheckForEntitiesAlongSegment( const Vector &start, const Vector &end, const Vector &mins, const Vector &maxs, CPushAwayEnumerator *enumerator );
  143. #endif // CLIENT_DLL
  144. //--------------------------------------------------------------------------------------------------------------
  145. // Retrieves physics objects near pPushingEntity
  146. void AvoidPushawayProps( CBaseCombatCharacter *pPlayer, CUserCmd *pCmd );
  147. int GetPushawayEnts( CBaseCombatCharacter *pPushingEntity, CBaseEntity **ents, int nMaxEnts, float flPlayerExpand, int PartitionMask, CPushAwayEnumerator *enumerator = NULL );
  148. //--------------------------------------------------------------------------------------------------------------
  149. // Pushes physics objects away from the entity
  150. void PerformObstaclePushaway( CBaseCombatCharacter *pPushingEntity );
  151. #endif // OBSTACLE_PUSHAWAY_H