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.

222 lines
6.2 KiB

  1. //========= Copyright � 1996-2009, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements the PaintPowerInfo structure for storing information about
  4. // the paint powers used.
  5. //
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "debugoverlay_shared.h"
  9. #include "paint_power_info.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //BEGIN_SEND_TABLE_NOBASE( PaintPowerInfo_t, DT_PaintPowerInfo_t )
  13. // SendPropEHandle( SENDINFO( m_HandleToOther ) ),
  14. // SendPropVector( SENDINFO( m_SurfaceNormal ) ),
  15. //END_SEND_TABLE()
  16. #if defined( CLIENT_DLL )
  17. BEGIN_PREDICTION_DATA_NO_BASE( PaintPowerInfo_t )
  18. DEFINE_PRED_FIELD( m_HandleToOther, FIELD_EHANDLE, 0 ),
  19. DEFINE_PRED_FIELD( m_SurfaceNormal, FIELD_VECTOR, 0 ),
  20. DEFINE_PRED_FIELD( m_ContactPoint, FIELD_VECTOR, 0 ),
  21. DEFINE_PRED_FIELD( m_State, FIELD_INTEGER, 0 ),
  22. DEFINE_PRED_FIELD( m_PaintPowerType, FIELD_INTEGER, 0 ),
  23. DEFINE_PRED_FIELD( m_IsOnThinSurface, FIELD_BOOLEAN, 0 )
  24. END_PREDICTION_DATA()
  25. #endif
  26. IMPLEMENT_NULL_SIMPLE_DATADESC( PaintPowerInfo_t );
  27. const Vector DEFAULT_PAINT_SURFACE_NORMAL = Vector(0.0f, 0.0f, 1.0f); // Flat ground
  28. PaintPowerInfo_t::PaintPowerInfo_t()
  29. : m_SurfaceNormal( DEFAULT_PAINT_SURFACE_NORMAL ),
  30. m_ContactPoint( 0.0f, 0.0f, 0.0f ),
  31. m_PaintPowerType( NO_POWER ),
  32. m_HandleToOther( 0 ),
  33. m_State( INACTIVE_PAINT_POWER ),
  34. m_IsOnThinSurface( false )
  35. {}
  36. PaintPowerInfo_t::PaintPowerInfo_t( const Vector &normal,
  37. const Vector &contactPt,
  38. CBaseEntity* pOther,
  39. PaintPowerType power,
  40. bool isOnThinSurface )
  41. : m_SurfaceNormal( normal ),
  42. m_ContactPoint( contactPt ),
  43. m_PaintPowerType( power ),
  44. m_State( INACTIVE_PAINT_POWER ),
  45. m_IsOnThinSurface( isOnThinSurface )
  46. {
  47. m_HandleToOther.Set( pOther );
  48. }
  49. #define PAINT_POWER_CPP_INLINE
  50. PAINT_POWER_CPP_INLINE bool AreSamePower( const PaintPowerInfo_t& powerA, const PaintPowerInfo_t& powerB )
  51. {
  52. return powerA.m_PaintPowerType == powerB.m_PaintPowerType &&
  53. powerA.m_HandleToOther == powerB.m_HandleToOther &&
  54. AlmostEqual( DotProduct( powerA.m_SurfaceNormal, powerB.m_SurfaceNormal ), 1.f );
  55. }
  56. PAINT_POWER_CPP_INLINE bool AreDifferentPowers( const PaintPowerInfo_t& powerA, const PaintPowerInfo_t& powerB )
  57. {
  58. return !AreSamePower( powerA, powerB );
  59. }
  60. PAINT_POWER_CPP_INLINE bool IsSpeedPower( const PaintPowerInfo_t& power )
  61. {
  62. return power.m_PaintPowerType == SPEED_POWER;
  63. }
  64. PAINT_POWER_CPP_INLINE bool IsBouncePower( const PaintPowerInfo_t& power )
  65. {
  66. return power.m_PaintPowerType == BOUNCE_POWER;
  67. }
  68. PAINT_POWER_CPP_INLINE bool IsReflectPower( const PaintPowerInfo_t& power )
  69. {
  70. return power.m_PaintPowerType == REFLECT_POWER;
  71. }
  72. PAINT_POWER_CPP_INLINE bool IsPortalPower( const PaintPowerInfo_t& power )
  73. {
  74. return power.m_PaintPowerType == PORTAL_POWER;
  75. }
  76. PAINT_POWER_CPP_INLINE bool IsNoPower( const PaintPowerInfo_t& power )
  77. {
  78. return power.m_PaintPowerType == NO_POWER;
  79. }
  80. PAINT_POWER_CPP_INLINE bool IsActivatingPower( const PaintPowerInfo_t& power )
  81. {
  82. return power.m_State == ACTIVATING_PAINT_POWER;
  83. }
  84. PAINT_POWER_CPP_INLINE bool IsActivePower( const PaintPowerInfo_t& power )
  85. {
  86. return power.m_State == ACTIVE_PAINT_POWER;
  87. }
  88. PAINT_POWER_CPP_INLINE bool IsDeactivatingPower( const PaintPowerInfo_t& power )
  89. {
  90. return power.m_State == DEACTIVATING_PAINT_POWER;
  91. }
  92. PAINT_POWER_CPP_INLINE bool IsInactivePower( const PaintPowerInfo_t& power )
  93. {
  94. return power.m_State == INACTIVE_PAINT_POWER;
  95. }
  96. char const *const PowerTypeToString( const PaintPowerInfo_t& powerInfo )
  97. {
  98. return PowerTypeToString( powerInfo.m_PaintPowerType );
  99. }
  100. char const *const PowerTypeToString( PaintPowerType type )
  101. {
  102. switch( type )
  103. {
  104. case BOUNCE_POWER:
  105. return "Bounce";
  106. case SPEED_POWER:
  107. return "Speed";
  108. case REFLECT_POWER:
  109. return "Speed";// FIXME: Bring this back for DLC2 "Reflect";
  110. case PORTAL_POWER:
  111. return "Portal";
  112. case NO_POWER:
  113. return "No"; // Yes
  114. default:
  115. return "Invalid power or hasn't been added to PowerTypeToString() in paint_power_info.cpp";
  116. }
  117. }
  118. char const *const PowerStateToString( const PaintPowerInfo_t& powerInfo )
  119. {
  120. return PowerStateToString( powerInfo.m_State );
  121. }
  122. char const *const PowerStateToString( PaintPowerState state )
  123. {
  124. switch( state )
  125. {
  126. case ACTIVATING_PAINT_POWER:
  127. return "Activating";
  128. case ACTIVE_PAINT_POWER:
  129. return "Active";
  130. case DEACTIVATING_PAINT_POWER:
  131. return "Deactivating";
  132. case INACTIVE_PAINT_POWER:
  133. return "Inactive";
  134. default:
  135. return "Invalid state or hasn't been added to PowerStateToString() in paint_power_info.cpp";
  136. }
  137. }
  138. void PrintPowerInfoDebugMsg( const PaintPowerInfo_t& powerInfo )
  139. {
  140. DevMsg( "Contact Point:\t(%f, %f, %f)\n", XYZ(powerInfo.m_ContactPoint) );
  141. DevMsg( "Surface Normal:\t(%f, %f, %f)\n", XYZ(powerInfo.m_SurfaceNormal) );
  142. DevMsg( "Paint Power: %s Power\n", PowerTypeToString(powerInfo.m_PaintPowerType) );
  143. // Non-const because CBaseEntity::GetClassname() is non-const because someone is lame.
  144. // Rebuilding every project in main to fix a const-correctness mistake is incredibly annoying.
  145. CBaseEntity* pOther;
  146. pOther = powerInfo.m_HandleToOther.Get() != NULL ? EntityFromEntityHandle( powerInfo.m_HandleToOther.Get() ) : NULL;
  147. DevMsg( "Other Class: %s\n", pOther != NULL ? pOther->GetClassname() : "Null" );
  148. DevMsg( "State: %s\n", PowerStateToString( powerInfo.m_State ) );
  149. }
  150. void DrawPaintPowerContactInfo( const PaintPowerInfo_t& powerInfo, const Color& color, float duration, bool noDepthTest )
  151. {
  152. NDebugOverlay::Sphere( powerInfo.m_ContactPoint, 5.0f, color.r(), color.g(), color.b(), noDepthTest, duration );
  153. NDebugOverlay::Line( powerInfo.m_ContactPoint, powerInfo.m_ContactPoint + 20.0f * powerInfo.m_SurfaceNormal, color.r(), color.g(), color.b(), noDepthTest, duration );
  154. }
  155. int DescendingPaintPriorityCompare( const PaintPowerInfo_t* a, const PaintPowerInfo_t* b )
  156. {
  157. return a->m_PaintPowerType - b->m_PaintPowerType;
  158. }
  159. int AscendingPaintPriorityCompare( const PaintPowerInfo_t* a, const PaintPowerInfo_t* b )
  160. {
  161. return b->m_PaintPowerType - a->m_PaintPowerType;
  162. }