Advertisement
AniCator

Clipboard

Oct 7th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. void CEnvExplosion::InputExplode( inputdata_t &inputdata )
  2. {
  3. trace_t tr;
  4.  
  5. SetModelName( NULL_STRING );//invisible
  6. SetSolid( SOLID_NONE );// intangible
  7.  
  8. Vector vecSpot = GetAbsOrigin() + Vector( 0 , 0 , 8 );
  9. UTIL_TraceLine( vecSpot, vecSpot + Vector( 0, 0, -40 ), (MASK_SOLID_BRUSHONLY | MASK_WATER), this, COLLISION_GROUP_NONE, &tr );
  10.  
  11. // Pull out of the wall a bit. We used to move the explosion origin itself, but that seems unnecessary, not to mention a
  12. // little weird when you consider that it might be in hierarchy. Instead we just calculate a new virtual position at
  13. // which to place the explosion. We don't use that new position to calculate radius damage because according to Steve's
  14. // comment, that adversely affects the force vector imparted on explosion victims when they ragdoll.
  15. Vector vecExplodeOrigin = GetAbsOrigin();
  16. if ( tr.fraction != 1.0 )
  17. {
  18. vecExplodeOrigin = tr.endpos + (tr.plane.normal * 24 );
  19. }
  20.  
  21. // draw decal
  22. if (! ( m_spawnflags & SF_ENVEXPLOSION_NODECAL ))
  23. {
  24. if ( ! ( m_spawnflags & SF_ENVEXPLOSION_ICE ))
  25. UTIL_DecalTrace( &tr, "Scorch" );
  26. else
  27. UTIL_DecalTrace( &tr, "Ice_Explosion_Decal" );
  28. }
  29.  
  30.  
  31. // It's stupid that this entity's spawnflags and the flags for the
  32. // explosion temp ent don't match up. But because they don't, we
  33. // have to reinterpret some of the spawnflags to determine which
  34. // flags to pass to the temp ent.
  35. int nFlags = TE_EXPLFLAG_NONE;
  36.  
  37. if( m_spawnflags & SF_ENVEXPLOSION_NOFIREBALL )
  38. {
  39. nFlags |= TE_EXPLFLAG_NOFIREBALL;
  40. }
  41.  
  42. if( m_spawnflags & SF_ENVEXPLOSION_NOSOUND )
  43. {
  44. nFlags |= TE_EXPLFLAG_NOSOUND;
  45. }
  46.  
  47. if ( m_spawnflags & SF_ENVEXPLOSION_RND_ORIENT )
  48. {
  49. nFlags |= TE_EXPLFLAG_ROTATE;
  50. }
  51.  
  52. if ( m_nRenderMode == kRenderTransAlpha )
  53. {
  54. nFlags |= TE_EXPLFLAG_DRAWALPHA;
  55. }
  56. else if ( m_nRenderMode != kRenderTransAdd )
  57. {
  58. nFlags |= TE_EXPLFLAG_NOADDITIVE;
  59. }
  60.  
  61. if( m_spawnflags & SF_ENVEXPLOSION_NOPARTICLES )
  62. {
  63. nFlags |= TE_EXPLFLAG_NOPARTICLES;
  64. }
  65.  
  66. if( !(m_spawnflags & SF_ENVEXPLOSION_NODLIGHTS) )
  67. {
  68. nFlags |= TE_EXPLFLAG_DLIGHT;
  69. }
  70.  
  71. if ( m_spawnflags & SF_ENVEXPLOSION_NOFIREBALLSMOKE )
  72. {
  73. nFlags |= TE_EXPLFLAG_NOFIREBALLSMOKE;
  74. }
  75.  
  76. if ( m_spawnflags & SF_ENVEXPLOSION_ICE )
  77. {
  78. nFlags |= TE_EXPLFLAG_ICE;
  79. }
  80.  
  81. //Get the damage override if specified
  82. int iRadius = ( m_iRadiusOverride > 0 ) ? m_iRadiusOverride : ( m_iMagnitude * 2.5f );
  83.  
  84. CPASFilter filter( vecExplodeOrigin );
  85. te->Explosion( filter, 0.0,
  86. &vecExplodeOrigin,
  87. ( m_sFireballSprite < 1 ) ? g_sModelIndexFireball : m_sFireballSprite,
  88. !( m_spawnflags & SF_ENVEXPLOSION_NOFIREBALL ) ? ( m_spriteScale / 10.0 ) : 0.0,
  89. 15,
  90. nFlags,
  91. iRadius,
  92. m_iMagnitude );
  93.  
  94. // do damage
  95. if ( !( m_spawnflags & SF_ENVEXPLOSION_NODAMAGE ) )
  96. {
  97. CBaseEntity *pAttacker = GetOwnerEntity() ? GetOwnerEntity() : this;
  98.  
  99. // Only calculate damage type if we didn't get a custom one passed in
  100. int iDamageType = m_iCustomDamageType;
  101. if ( iDamageType == -1 )
  102. {
  103. iDamageType = HasSpawnFlags( SF_ENVEXPLOSION_GENERIC_DAMAGE ) ? DMG_GENERIC : DMG_BLAST;
  104. }
  105.  
  106. CTakeDamageInfo info( m_hInflictor ? m_hInflictor : this, pAttacker, m_iMagnitude, iDamageType );
  107.  
  108. if( HasSpawnFlags( SF_ENVEXPLOSION_SURFACEONLY ) )
  109. {
  110. info.AddDamageType( DMG_BLAST_SURFACE );
  111. }
  112.  
  113. if ( m_flDamageForce )
  114. {
  115. // Not the right direction, but it'll be fixed up by RadiusDamage.
  116. info.SetDamagePosition( GetAbsOrigin() );
  117. info.SetDamageForce( Vector( m_flDamageForce, 0, 0 ) );
  118. }
  119.  
  120. RadiusDamage( info, GetAbsOrigin(), iRadius, m_iClassIgnore, m_hEntityIgnore.Get() );
  121. }
  122.  
  123. SetThink( &CEnvExplosion::Smoke );
  124. SetNextThink( gpGlobals->curtime + 0.3 );
  125.  
  126. // Only do these effects if we're not submerged
  127. if ( UTIL_PointContents( GetAbsOrigin(), MASK_WATER ) & CONTENTS_WATER )
  128. {
  129. // draw sparks
  130. if ( !( m_spawnflags & SF_ENVEXPLOSION_NOSPARKS ) )
  131. {
  132. int sparkCount = random->RandomInt(0,3);
  133.  
  134. for ( int i = 0; i < sparkCount; i++ )
  135. {
  136. QAngle angles;
  137. VectorAngles( tr.plane.normal, angles );
  138. Create( "spark_shower", vecExplodeOrigin, angles, NULL );
  139. }
  140. }
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement