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.

163 lines
4.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Dissolve entity to be attached to target entity. Serves two purposes:
  4. //
  5. // 1) An entity that can be placed by a level designer and triggered
  6. // to ignite a target entity.
  7. //
  8. // 2) An entity that can be created at runtime to ignite a target entity.
  9. //
  10. //=============================================================================//
  11. #include "cbase.h"
  12. #include "EntityFreezing.h"
  13. #include "baseanimating.h"
  14. #include "ai_basenpc.h"
  15. #include "dt_utlvector_send.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. static const char *s_pElectroThinkContext = "ElectroThinkContext";
  19. //-----------------------------------------------------------------------------
  20. // Model
  21. //-----------------------------------------------------------------------------
  22. #define FREEZING_SPRITE_NAME "sprites/blueglow1.vmt"
  23. //-----------------------------------------------------------------------------
  24. // Save/load
  25. //-----------------------------------------------------------------------------
  26. BEGIN_DATADESC( CEntityFreezing )
  27. DEFINE_FIELD( m_vFreezingOrigin, FIELD_VECTOR ),
  28. DEFINE_AUTO_ARRAY( m_flFrozenPerHitbox, FIELD_FLOAT ),
  29. DEFINE_KEYFIELD( m_flFrozen, FIELD_FLOAT, "frozen" ),
  30. DEFINE_FIELD( m_bFinishFreezing, FIELD_BOOLEAN ),
  31. DEFINE_INPUTFUNC( FIELD_STRING, "Freeze", InputFreeze ),
  32. END_DATADESC()
  33. //-----------------------------------------------------------------------------
  34. // Networking
  35. //-----------------------------------------------------------------------------
  36. IMPLEMENT_SERVERCLASS_ST( CEntityFreezing, DT_EntityFreezing )
  37. SendPropVector( SENDINFO(m_vFreezingOrigin), 0, SPROP_NOSCALE ),
  38. SendPropArray3( SENDINFO_ARRAY3(m_flFrozenPerHitbox), SendPropFloat( SENDINFO_ARRAY(m_flFrozenPerHitbox) ) ),
  39. SendPropFloat( SENDINFO( m_flFrozen ) ),
  40. SendPropBool( SENDINFO( m_bFinishFreezing ) ),
  41. END_SEND_TABLE()
  42. LINK_ENTITY_TO_CLASS( env_entity_freezing, CEntityFreezing );
  43. PRECACHE_REGISTER( env_entity_freezing );
  44. //-----------------------------------------------------------------------------
  45. // Precache
  46. //-----------------------------------------------------------------------------
  47. void CEntityFreezing::Precache()
  48. {
  49. if ( NULL_STRING != GetModelName() )
  50. {
  51. PrecacheModel( STRING( GetModelName() ) );
  52. }
  53. #ifdef USE_BLOBULATOR
  54. PrecacheMaterial( "models/weapons/w_icegun/ice_surface" );
  55. #endif
  56. }
  57. //-----------------------------------------------------------------------------
  58. // Spawn
  59. //-----------------------------------------------------------------------------
  60. void CEntityFreezing::Spawn()
  61. {
  62. BaseClass::Spawn();
  63. Precache();
  64. UTIL_SetModel( this, STRING( GetModelName() ) );
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. // Input : inputdata -
  69. //-----------------------------------------------------------------------------
  70. void CEntityFreezing::InputFreeze( inputdata_t &inputdata )
  71. {
  72. string_t strTarget = inputdata.value.StringID();
  73. if (strTarget == NULL_STRING)
  74. {
  75. strTarget = m_target;
  76. }
  77. CBaseEntity *pTarget = NULL;
  78. while ((pTarget = gEntList.FindEntityGeneric(pTarget, STRING(strTarget), this, inputdata.pActivator)) != NULL)
  79. {
  80. CBaseAnimating *pBaseAnim = pTarget->GetBaseAnimating();
  81. if ( pBaseAnim )
  82. {
  83. pBaseAnim->Freeze( m_flFrozen );
  84. }
  85. }
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Purpose: Creates a flame and attaches it to a target entity.
  89. // Input : pTarget -
  90. //-----------------------------------------------------------------------------
  91. CEntityFreezing *CEntityFreezing::Create( CBaseAnimating *pTarget )
  92. {
  93. if ( pTarget )
  94. {
  95. if ( pTarget->IsPlayer() )
  96. {
  97. // Simply immediately kill the player.
  98. CBasePlayer *pPlayer = assert_cast< CBasePlayer* >( pTarget );
  99. pPlayer->SetArmorValue( 0 );
  100. CTakeDamageInfo info( pPlayer, pPlayer, pPlayer->GetHealth(), DMG_GENERIC | DMG_REMOVENORAGDOLL | DMG_PREVENT_PHYSICS_FORCE );
  101. pPlayer->TakeDamage( info );
  102. return NULL;
  103. }
  104. }
  105. CEntityFreezing *pFreezing = (CEntityFreezing *) CreateEntityByName( "env_entity_freezing" );
  106. if ( pFreezing == NULL )
  107. return NULL;
  108. if ( pTarget )
  109. {
  110. pFreezing->AttachToEntity( pTarget );
  111. pFreezing->SetModelName( pTarget->GetModelName() );
  112. pFreezing->SetFrozen( pTarget->GetFrozenAmount() );
  113. }
  114. DispatchSpawn( pFreezing );
  115. // Send to the client even though we don't have a model
  116. pFreezing->AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
  117. return pFreezing;
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Purpose: Attaches the flame to an entity and moves with it
  121. // Input : pTarget - target entity to attach to
  122. //-----------------------------------------------------------------------------
  123. void CEntityFreezing::AttachToEntity( CBaseEntity *pTarget )
  124. {
  125. // So our dissolver follows the entity around on the server.
  126. SetParent( pTarget );
  127. SetLocalOrigin( vec3_origin );
  128. SetLocalAngles( vec3_angle );
  129. }