Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.32 KB | None | 0 0
  1. //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: The flag entity for Ivan's Secrets
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "projectile_base.h"
  9. #include "particle_parse.h"
  10. #include "debugoverlay_shared.h"
  11. #include "explode.h"
  12.  
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15.  
  16. LINK_ENTITY_TO_CLASS(projectile,CProjectileBase);
  17. // Start of our data description for the class
  18.  
  19. BEGIN_DATADESC( CProjectileBase )
  20.  
  21.  
  22.     // Declare our think function
  23.     DEFINE_ENTITYFUNC( FlyTouch ),
  24.     DEFINE_THINKFUNC( FlyThink ),
  25.  
  26.  
  27. END_DATADESC()
  28.  
  29. // Server data table describing networked member variables (SendProps)
  30. // DO NOT create this in the header! Put it in the main CPP file.
  31. IMPLEMENT_SERVERCLASS_ST( CProjectileBase, DT_ProjectileBase )
  32.     SendPropInt( SENDINFO( m_bEmit ), 1, SPROP_UNSIGNED ),
  33.     SendPropInt( SENDINFO( m_bEmitSplash), 1, SPROP_UNSIGNED ),
  34.     SendPropString( SENDINFO( m_szParticle) ),
  35. END_SEND_TABLE()
  36.  
  37. void CProjectileBase::SetParticle(const char* name)
  38. {
  39.     Q_strncpy( m_szParticle.GetForModify(), name, MAX_TEAM_NAME_LENGTH );
  40. }
  41. CProjectileBase::CProjectileBase()
  42. {
  43.     memset( m_szParticle.GetForModify(), 0, sizeof(m_szParticle) );
  44.  
  45.     SetPredictionEligible(true);
  46. }
  47.  
  48. CProjectileBase *CProjectileBase::ProjectileCreate( CBaseEntity *pentOwner, const char* pParticle, const Vector &vecAiming, const Vector &vecOrigin, const QAngle &angAngles,
  49.     const float &flSpeed, const float &flGravity,const int  &iDamage,const int  &iPenetration,const bool    &bSplash ,const float &flRadius,const char* pSplashEffect,const char* pSplashSound, const bool &bPush)
  50. {
  51.     // Create a new entity with CCrossbowBolt private data
  52.     CProjectileBase *pProj = (CProjectileBase *)CreateEntityByName( "projectile" );
  53.     UTIL_SetOrigin( pProj, vecOrigin );
  54.     pProj->m_vecTemp = vecAiming;
  55.     pProj->SetAbsAngles( angAngles );
  56.     //setup the info
  57.     pProj->SetGravity(flGravity);
  58.     pProj->SetProjectileDamage(iDamage);
  59.     pProj->SetSpeed(flSpeed);
  60.     pProj->SetParticle(pParticle);
  61.  
  62.     pProj->m_iPenetration = iPenetration;
  63.  
  64.     //Splash
  65.     pProj->SetSplashRadius(flRadius);
  66.     pProj->SetSplash(bSplash);
  67.     pProj->SetSplashParticle(pSplashEffect);
  68.     pProj->SetSplashSound(pSplashSound);
  69.     pProj->SetPush( bPush );
  70.  
  71.     pProj->Spawn();
  72.     pProj->SetOwnerEntity( pentOwner );
  73.     pProj->m_bEmit = true;
  74.     pProj->m_bEmitSplash = false;
  75.  
  76.     return pProj;
  77. }
  78. void CProjectileBase::Precache()
  79. {
  80.     //PrecacheScriptSound( GetSplashSound() );
  81.     PrecacheParticleSystem(GetParticle());
  82.  
  83.     if (GetSplash())
  84.         PrecacheParticleSystem(GetSplashParticle());
  85.  
  86. }
  87. void CProjectileBase::Spawn()
  88. {
  89.     Precache( );
  90.  
  91.     if (!GetGravity() == 0.0)
  92.     SetMoveType( MOVETYPE_FLYGRAVITY );
  93.     else
  94.     SetMoveType( MOVETYPE_FLY );
  95.  
  96.     SetGravity(GetGravity());
  97.  
  98.     UTIL_SetSize( this, -Vector(1.0f,1.0f,1.0f), Vector(1.0f,1.0f,1.0f) );
  99.  
  100.     SetSolid( SOLID_BBOX );
  101.  
  102.     SetTouch( &CProjectileBase::FlyTouch );
  103.     SetThink( &CProjectileBase::FlyThink );
  104.  
  105.     AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
  106.  
  107.     SetAbsVelocity( m_vecTemp * GetSpeed() );
  108.  
  109.     BaseClass::Spawn();
  110.  
  111.     SetNextThink( gpGlobals->curtime + 0.01f );
  112. }
  113. void CProjectileBase::FlyThink( void  )
  114. {
  115.     SetNextThink( gpGlobals->curtime + 0.01f );
  116. }
  117. bool CProjectileBase::GetPenetrationTrace( Vector &Start )
  118. {
  119.     // Move through the glass until we're at the other side
  120.     float MAX_PENETRATION = 64.0f;
  121.     Vector  testPos = GetAbsOrigin() + ( m_vecTemp * MAX_PENETRATION );
  122.  
  123.     trace_t penetrationTrace;
  124.  
  125.     // Re-trace as if the bullet had passed right through
  126.     UTIL_TraceLine( testPos, GetAbsOrigin(), MASK_SHOT, this, COLLISION_GROUP_DEBRIS, &penetrationTrace );
  127.  
  128.     Start = penetrationTrace.endpos;
  129.     //debugoverlay->AddLineOverlay(penetrationTrace.startpos,penetrationTrace.endpos,0,0,255,false,8);
  130.  
  131.     // Put a mark on the other side.
  132.     if ( ( penetrationTrace.surface.flags & SURF_SKY ) == false )
  133.     {
  134.         UTIL_ImpactTrace( &penetrationTrace, DMG_BULLET );
  135.     }
  136.  
  137.     // See if we found the surface again
  138.     if ( penetrationTrace.startsolid || penetrationTrace.fraction == 1.0f )
  139.     {
  140.         return false;
  141.     }
  142.  
  143.     SetAbsOrigin(penetrationTrace.startpos + m_vecTemp * 24);
  144.     SetAbsAngles(angles);
  145.  
  146.     //Half damage.
  147.     m_iDamage *= 0.5;
  148.  
  149.     SetThink( &CProjectileBase::FlyThink );
  150.     SetNextThink( gpGlobals->curtime + 0.01f );
  151.  
  152.     return true;
  153. }
  154. void CProjectileBase::FlyTouch(CBaseEntity *pObj)
  155. {
  156.     if ( !pObj->IsSolid() )
  157.         return;
  158.    
  159.         if ( pObj->m_takedamage != DAMAGE_NO )
  160.         {
  161.             //Do damage.
  162.             if (!GetSplash())
  163.             {
  164.                 trace_t tr, tr2;
  165.                 tr = BaseClass::GetTouchTrace();
  166.                 Vector  vecNormalizedVel = GetAbsVelocity();
  167.  
  168.                 ClearMultiDamage();
  169.                 VectorNormalize( vecNormalizedVel );
  170.  
  171.                 CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), GetProjectileDamage(), DMG_ENERGYBEAM );
  172.                 CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f );
  173.                 dmgInfo.SetDamagePosition( tr.endpos );
  174.                 pObj->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr );
  175.  
  176.                 ApplyMultiDamage();
  177.  
  178.                 SetTouch( NULL );
  179.             }
  180.         }
  181.         if (GetSplash())
  182.         {
  183.             CPASFilter filter( GetAbsOrigin() );
  184.             filter.MakeReliable();
  185.  
  186.             //te->ParticleSplash( filter, 0, &GetAbsOrigin(), 0, GetSplashParticle() );
  187.             EmitSound( filter,entindex(),GetSplashSound());
  188.  
  189.             //      ExplosionCreate( GetAbsOrigin(), GetAbsAngles(), GetOwnerEntity(), GetDamage(), GetSplashRadius(),
  190.             //SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE | SF_ENVEXPLOSION_NOSOUND |
  191.             //SF_ENVEXPLOSION_NODAMAGE | SF_ENVEXPLOSION_NODECAL, 0.0f, this);
  192.            
  193.                
  194.                 if (GetPush())
  195.                 {
  196.                     DoPush();
  197.                 }
  198.  
  199.                 CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), GetProjectileDamage(), DMG_ENERGYBEAM );
  200.                 RadiusDamage( dmgInfo, GetAbsOrigin(), GetSplashRadius(), CLASS_NONE, NULL );
  201.  
  202.                
  203.         }      
  204.         else
  205.         {
  206.             trace_t tr;
  207.             tr = BaseClass::GetTouchTrace();
  208.  
  209.             // Put a mark unless we've hit the sky
  210.             if ( ( tr.surface.flags & SURF_SKY ) == false )
  211.             {
  212.                 UTIL_ImpactTrace( &tr, DMG_BULLET );
  213.             }
  214.         }
  215.  
  216.        
  217.         //Get the positions
  218.     Vector start;
  219.     if (GetPenetrationTrace(start))
  220.     {
  221.         m_iPenetration--;
  222.     }
  223.     else
  224.     {
  225.         m_iPenetration = 0;
  226.     }
  227.  
  228.     //debugoverlay->AddBoxOverlay(GetAbsOrigin(),Vector(-1,-1,-1),Vector(1,1,1),GetLocalAngles(),255,0,0,255,5);
  229.  
  230.     if (m_iPenetration == 0)
  231.     {
  232.         UTIL_Remove( this );
  233.     }
  234. }
  235. void CProjectileBase::DoPush(void)
  236. {
  237.         CBaseEntity *ent = NULL;
  238.  
  239.                 for ( CEntitySphereQuery sphere( GetAbsOrigin(), 256 ); (ent = sphere.GetCurrentEntity()) != NULL; sphere.NextEntity() )
  240.                 {
  241.                     if ( ent->IsPlayer() )
  242.                     {
  243.                    
  244.                         CBasePlayer *pPlayer = ToBasePlayer( ent );
  245.                         if (pPlayer)
  246.                         {
  247.  
  248.                             Vector vecExplode = pPlayer->GetAbsOrigin() - GetAbsOrigin();// Get the vector from the explosion to the player
  249.                             float dist = vecExplode.LengthSqr(); // Get the length
  250.                             DevMsg("Explosion was %f units away\n", dist); //print the length
  251.  
  252.  
  253.                             if (dist <= 8000.0f)
  254.                             {
  255.                                 DevMsg("Rocket push!\n");
  256.                                                        
  257.                                 // Make sure the player moves
  258.                                 if ( vecExplode.z > 0 && ( pPlayer->GetFlags() & FL_ONGROUND) )
  259.                                 {
  260.                                     pPlayer->SetGroundEntity( NULL );
  261.                                 }
  262.  
  263.                                 pPlayer->SetBaseVelocity( 20 * vecExplode );
  264.                                 pPlayer->AddFlag( FL_BASEVELOCITY );
  265.  
  266.                             }
  267.                         }
  268.                     }
  269.                 }
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement