Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
- //
- // Purpose: The flag entity for Ivan's Secrets
- //
- // $NoKeywords: $
- //=============================================================================//
- #include "cbase.h"
- #include "projectile_base.h"
- #include "particle_parse.h"
- #include "debugoverlay_shared.h"
- #include "explode.h"
- // memdbgon must be the last include file in a .cpp file!!!
- #include "tier0/memdbgon.h"
- LINK_ENTITY_TO_CLASS(projectile,CProjectileBase);
- // Start of our data description for the class
- BEGIN_DATADESC( CProjectileBase )
- // Declare our think function
- DEFINE_ENTITYFUNC( FlyTouch ),
- DEFINE_THINKFUNC( FlyThink ),
- END_DATADESC()
- // Server data table describing networked member variables (SendProps)
- // DO NOT create this in the header! Put it in the main CPP file.
- IMPLEMENT_SERVERCLASS_ST( CProjectileBase, DT_ProjectileBase )
- SendPropInt( SENDINFO( m_bEmit ), 1, SPROP_UNSIGNED ),
- SendPropInt( SENDINFO( m_bEmitSplash), 1, SPROP_UNSIGNED ),
- SendPropString( SENDINFO( m_szParticle) ),
- END_SEND_TABLE()
- void CProjectileBase::SetParticle(const char* name)
- {
- Q_strncpy( m_szParticle.GetForModify(), name, MAX_TEAM_NAME_LENGTH );
- }
- CProjectileBase::CProjectileBase()
- {
- memset( m_szParticle.GetForModify(), 0, sizeof(m_szParticle) );
- SetPredictionEligible(true);
- }
- CProjectileBase *CProjectileBase::ProjectileCreate( CBaseEntity *pentOwner, const char* pParticle, const Vector &vecAiming, const Vector &vecOrigin, const QAngle &angAngles,
- 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)
- {
- // Create a new entity with CCrossbowBolt private data
- CProjectileBase *pProj = (CProjectileBase *)CreateEntityByName( "projectile" );
- UTIL_SetOrigin( pProj, vecOrigin );
- pProj->m_vecTemp = vecAiming;
- pProj->SetAbsAngles( angAngles );
- //setup the info
- pProj->SetGravity(flGravity);
- pProj->SetProjectileDamage(iDamage);
- pProj->SetSpeed(flSpeed);
- pProj->SetParticle(pParticle);
- pProj->m_iPenetration = iPenetration;
- //Splash
- pProj->SetSplashRadius(flRadius);
- pProj->SetSplash(bSplash);
- pProj->SetSplashParticle(pSplashEffect);
- pProj->SetSplashSound(pSplashSound);
- pProj->SetPush( bPush );
- pProj->Spawn();
- pProj->SetOwnerEntity( pentOwner );
- pProj->m_bEmit = true;
- pProj->m_bEmitSplash = false;
- return pProj;
- }
- void CProjectileBase::Precache()
- {
- //PrecacheScriptSound( GetSplashSound() );
- PrecacheParticleSystem(GetParticle());
- if (GetSplash())
- PrecacheParticleSystem(GetSplashParticle());
- }
- void CProjectileBase::Spawn()
- {
- Precache( );
- if (!GetGravity() == 0.0)
- SetMoveType( MOVETYPE_FLYGRAVITY );
- else
- SetMoveType( MOVETYPE_FLY );
- SetGravity(GetGravity());
- UTIL_SetSize( this, -Vector(1.0f,1.0f,1.0f), Vector(1.0f,1.0f,1.0f) );
- SetSolid( SOLID_BBOX );
- SetTouch( &CProjectileBase::FlyTouch );
- SetThink( &CProjectileBase::FlyThink );
- AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
- SetAbsVelocity( m_vecTemp * GetSpeed() );
- BaseClass::Spawn();
- SetNextThink( gpGlobals->curtime + 0.01f );
- }
- void CProjectileBase::FlyThink( void )
- {
- SetNextThink( gpGlobals->curtime + 0.01f );
- }
- bool CProjectileBase::GetPenetrationTrace( Vector &Start )
- {
- // Move through the glass until we're at the other side
- float MAX_PENETRATION = 64.0f;
- Vector testPos = GetAbsOrigin() + ( m_vecTemp * MAX_PENETRATION );
- trace_t penetrationTrace;
- // Re-trace as if the bullet had passed right through
- UTIL_TraceLine( testPos, GetAbsOrigin(), MASK_SHOT, this, COLLISION_GROUP_DEBRIS, &penetrationTrace );
- Start = penetrationTrace.endpos;
- //debugoverlay->AddLineOverlay(penetrationTrace.startpos,penetrationTrace.endpos,0,0,255,false,8);
- // Put a mark on the other side.
- if ( ( penetrationTrace.surface.flags & SURF_SKY ) == false )
- {
- UTIL_ImpactTrace( &penetrationTrace, DMG_BULLET );
- }
- // See if we found the surface again
- if ( penetrationTrace.startsolid || penetrationTrace.fraction == 1.0f )
- {
- return false;
- }
- SetAbsOrigin(penetrationTrace.startpos + m_vecTemp * 24);
- SetAbsAngles(angles);
- //Half damage.
- m_iDamage *= 0.5;
- SetThink( &CProjectileBase::FlyThink );
- SetNextThink( gpGlobals->curtime + 0.01f );
- return true;
- }
- void CProjectileBase::FlyTouch(CBaseEntity *pObj)
- {
- if ( !pObj->IsSolid() )
- return;
- if ( pObj->m_takedamage != DAMAGE_NO )
- {
- //Do damage.
- if (!GetSplash())
- {
- trace_t tr, tr2;
- tr = BaseClass::GetTouchTrace();
- Vector vecNormalizedVel = GetAbsVelocity();
- ClearMultiDamage();
- VectorNormalize( vecNormalizedVel );
- CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), GetProjectileDamage(), DMG_ENERGYBEAM );
- CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f );
- dmgInfo.SetDamagePosition( tr.endpos );
- pObj->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr );
- ApplyMultiDamage();
- SetTouch( NULL );
- }
- }
- if (GetSplash())
- {
- CPASFilter filter( GetAbsOrigin() );
- filter.MakeReliable();
- //te->ParticleSplash( filter, 0, &GetAbsOrigin(), 0, GetSplashParticle() );
- EmitSound( filter,entindex(),GetSplashSound());
- // ExplosionCreate( GetAbsOrigin(), GetAbsAngles(), GetOwnerEntity(), GetDamage(), GetSplashRadius(),
- //SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS | SF_ENVEXPLOSION_NOSMOKE | SF_ENVEXPLOSION_NOSOUND |
- //SF_ENVEXPLOSION_NODAMAGE | SF_ENVEXPLOSION_NODECAL, 0.0f, this);
- if (GetPush())
- {
- DoPush();
- }
- CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), GetProjectileDamage(), DMG_ENERGYBEAM );
- RadiusDamage( dmgInfo, GetAbsOrigin(), GetSplashRadius(), CLASS_NONE, NULL );
- }
- else
- {
- trace_t tr;
- tr = BaseClass::GetTouchTrace();
- // Put a mark unless we've hit the sky
- if ( ( tr.surface.flags & SURF_SKY ) == false )
- {
- UTIL_ImpactTrace( &tr, DMG_BULLET );
- }
- }
- //Get the positions
- Vector start;
- if (GetPenetrationTrace(start))
- {
- m_iPenetration--;
- }
- else
- {
- m_iPenetration = 0;
- }
- //debugoverlay->AddBoxOverlay(GetAbsOrigin(),Vector(-1,-1,-1),Vector(1,1,1),GetLocalAngles(),255,0,0,255,5);
- if (m_iPenetration == 0)
- {
- UTIL_Remove( this );
- }
- }
- void CProjectileBase::DoPush(void)
- {
- CBaseEntity *ent = NULL;
- for ( CEntitySphereQuery sphere( GetAbsOrigin(), 256 ); (ent = sphere.GetCurrentEntity()) != NULL; sphere.NextEntity() )
- {
- if ( ent->IsPlayer() )
- {
- CBasePlayer *pPlayer = ToBasePlayer( ent );
- if (pPlayer)
- {
- Vector vecExplode = pPlayer->GetAbsOrigin() - GetAbsOrigin();// Get the vector from the explosion to the player
- float dist = vecExplode.LengthSqr(); // Get the length
- DevMsg("Explosion was %f units away\n", dist); //print the length
- if (dist <= 8000.0f)
- {
- DevMsg("Rocket push!\n");
- // Make sure the player moves
- if ( vecExplode.z > 0 && ( pPlayer->GetFlags() & FL_ONGROUND) )
- {
- pPlayer->SetGroundEntity( NULL );
- }
- pPlayer->SetBaseVelocity( 20 * vecExplode );
- pPlayer->AddFlag( FL_BASEVELOCITY );
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement