本文整理汇总了C++中CBaseEntity::DispatchTraceAttack方法的典型用法代码示例。如果您正苦于以下问题:C++ CBaseEntity::DispatchTraceAttack方法的具体用法?C++ CBaseEntity::DispatchTraceAttack怎么用?C++ CBaseEntity::DispatchTraceAttack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBaseEntity
的用法示例。
在下文中一共展示了CBaseEntity::DispatchTraceAttack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Hit
//------------------------------------------------------------------------------
// Purpose: Implement impact function
//------------------------------------------------------------------------------
void CWeaponCrowbar::Hit( void )
{
//Make sound for the AI
#ifndef CLIENT_DLL
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
CSoundEnt::InsertSound( SOUND_BULLET_IMPACT, m_traceHit.endpos, 400, 0.2f, pPlayer );
CBaseEntity *pHitEntity = m_traceHit.m_pEnt;
//Apply damage to a hit target
if ( pHitEntity != NULL )
{
Vector hitDirection;
pPlayer->EyeVectors( &hitDirection, NULL, NULL );
VectorNormalize( hitDirection );
ClearMultiDamage();
CTakeDamageInfo info( GetOwner(), GetOwner(), sk_plr_dmg_crowbar.GetFloat(), DMG_CLUB );
CalculateMeleeDamageForce( &info, hitDirection, m_traceHit.endpos );
pHitEntity->DispatchTraceAttack( info, hitDirection, &m_traceHit );
ApplyMultiDamage();
// Now hit all triggers along the ray that...
TraceAttackToTriggers( CTakeDamageInfo( GetOwner(), GetOwner(), sk_plr_dmg_crowbar.GetFloat(), DMG_CLUB ), m_traceHit.startpos, m_traceHit.endpos, hitDirection );
//Play an impact sound
ImpactSound( pHitEntity );
}
#endif
//Apply an impact effect
ImpactEffect();
}
示例2: TraceAttack
//-----------------------------------------------------------------------------
// Purpose: Pass on trace attack calls to the entity we're following
//-----------------------------------------------------------------------------
void CBoneFollower::TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr )
{
CBaseEntity *pOwner = GetOwnerEntity();
if ( pOwner )
{
pOwner->DispatchTraceAttack( info, vecDir, ptr );
return;
}
BaseClass::TraceAttack( info, vecDir, ptr );
}
示例3: Hit
//------------------------------------------------------------------------------
// Purpose: Implement impact function
//------------------------------------------------------------------------------
void CBaseSDKBludgeonWeapon::Hit( trace_t &traceHit, Activity nHitActivity, bool bIsSecondary )
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
//Do view kick
AddViewKick();
//Make sound for the AI
CSoundEnt::InsertSound( SOUND_BULLET_IMPACT, traceHit.endpos, 400, 0.2f, pPlayer );
// This isn't great, but it's something for when the crowbar hits.
pPlayer->RumbleEffect( RUMBLE_AR2, 0, RUMBLE_FLAG_RESTART );
CBaseEntity *pHitEntity = traceHit.m_pEnt;
//Apply damage to a hit target
if ( pHitEntity != NULL )
{
Vector hitDirection;
pPlayer->EyeVectors( &hitDirection, NULL, NULL );
VectorNormalize( hitDirection );
CTakeDamageInfo info( GetOwner(), GetOwner(), GetDamageForActivity( nHitActivity ), DMG_CLUB );
if( pPlayer && pHitEntity->IsNPC() )
{
// If bonking an NPC, adjust damage.
info.AdjustPlayerDamageInflictedForSkillLevel();
}
CalculateMeleeDamageForce( &info, hitDirection, traceHit.endpos );
pHitEntity->DispatchTraceAttack( info, hitDirection, &traceHit );
ApplyMultiDamage();
// Now hit all triggers along the ray that...
TraceAttackToTriggers( info, traceHit.startpos, traceHit.endpos, hitDirection );
if ( ToBaseCombatCharacter( pHitEntity ) )
{
gamestats->Event_WeaponHit( pPlayer, !bIsSecondary, GetClassname(), info );
}
}
// Apply an impact effect
ImpactEffect( traceHit );
}
示例4: info
//------------------------------------------------------------------------------
// Purpose: Implement impact function
//------------------------------------------------------------------------------
void CBaseHL2MPBludgeonWeapon::Hit( trace_t &traceHit, Activity nHitActivity )
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
//Do view kick
// AddViewKick();
CBaseEntity *pHitEntity = traceHit.m_pEnt;
//Apply damage to a hit target
if ( pHitEntity != NULL )
{
Vector hitDirection;
pPlayer->EyeVectors( &hitDirection, NULL, NULL );
VectorNormalize( hitDirection );
#ifndef CLIENT_DLL
CTakeDamageInfo info( GetOwner(), GetOwner(), GetDamageForActivity( nHitActivity ), DMG_CLUB );
if( pPlayer && pHitEntity->IsNPC() )
{
// If bonking an NPC, adjust damage.
info.AdjustPlayerDamageInflictedForSkillLevel();
}
CalculateMeleeDamageForce( &info, hitDirection, traceHit.endpos );
pHitEntity->DispatchTraceAttack( info, hitDirection, &traceHit );
ApplyMultiDamage();
// Now hit all triggers along the ray that...
TraceAttackToTriggers( info, traceHit.startpos, traceHit.endpos, hitDirection );
#endif
//DHL - Skillet
if ( pHitEntity->entindex() == 0 )
WeaponSound( MELEE_HIT_WORLD );
else
WeaponSound( MELEE_HIT );
}
// Apply an impact effect
ImpactEffect( traceHit );
}
示例5: BeamDamage
//-----------------------------------------------------------------------------
// Purpose: Damages anything in the beam.
// Input : ptr -
//-----------------------------------------------------------------------------
void CBeam::BeamDamage( trace_t *ptr )
{
RelinkBeam();
#if !defined( CLIENT_DLL )
if ( ptr->fraction != 1.0 && ptr->m_pEnt != NULL )
{
CBaseEntity *pHit = ptr->m_pEnt;
if ( pHit )
{
ClearMultiDamage();
Vector dir = ptr->endpos - GetAbsOrigin();
VectorNormalize( dir );
int nDamageType = DMG_ENERGYBEAM;
#ifndef HL1_DLL
if (m_nDissolveType == 0)
{
nDamageType = DMG_DISSOLVE;
}
else if ( m_nDissolveType > 0 )
{
nDamageType = DMG_DISSOLVE | DMG_SHOCK;
}
#endif
CTakeDamageInfo info( this, this, m_flDamage * (gpGlobals->curtime - m_flFireTime), nDamageType );
CalculateMeleeDamageForce( &info, dir, ptr->endpos );
pHit->DispatchTraceAttack( info, dir, ptr );
ApplyMultiDamage();
if ( HasSpawnFlags( SF_BEAM_DECALS ) )
{
if ( pHit->IsBSPModel() )
{
UTIL_DecalTrace( ptr, GetDecalName() );
}
}
}
}
#endif
m_flFireTime = gpGlobals->curtime;
}
示例6: ZapBeam
//=========================================================
// ZapBeam - heavy damage directly forward
//=========================================================
void CNPC_Vortigaunt::ZapBeam( int side )
{
Vector vecSrc, vecAim;
trace_t tr;
CBaseEntity *pEntity;
if ( m_iBeams >= VORTIGAUNT_MAX_BEAMS )
return;
Vector forward, right, up;
AngleVectors( GetAbsAngles(), &forward, &right, &up );
vecSrc = GetAbsOrigin() + up * 36;
vecAim = GetShootEnemyDir( vecSrc );
float deflection = 0.01;
vecAim = vecAim + side * right * random->RandomFloat( 0, deflection ) + up * random->RandomFloat( -deflection, deflection );
UTIL_TraceLine ( vecSrc, vecSrc + vecAim * 1024, MASK_SOLID, this, COLLISION_GROUP_NONE, &tr);
m_pBeam[m_iBeams] = CBeam::BeamCreate( "sprites/lgtning.vmt", 5.0f );
if ( m_pBeam[m_iBeams] == NULL )
return;
m_pBeam[m_iBeams]->PointEntInit( tr.endpos, this );
m_pBeam[m_iBeams]->SetEndAttachment( side < 0 ? 2 : 1 );
m_pBeam[m_iBeams]->SetColor( 180, 255, 96 );
m_pBeam[m_iBeams]->SetBrightness( 255 );
m_pBeam[m_iBeams]->SetNoise( 3.2f );
m_iBeams++;
pEntity = tr.m_pEnt;
if ( pEntity != NULL && m_takedamage )
{
CTakeDamageInfo info( this, this, sk_islave_dmg_zap.GetFloat(), DMG_SHOCK );
CalculateMeleeDamageForce( &info, vecAim, tr.endpos );
pEntity->DispatchTraceAttack( info, vecAim, &tr );
}
}
示例7: Fire
void CASW_Weapon_Chainsaw::Fire( const Vector &vecOrigSrc, const Vector &vecDir )
{
CASW_Marine *pMarine = GetMarine();
if ( !pMarine )
{
return;
}
StopAttackOffSound();
StartChainsawSound();
if ( m_flFireAnimTime < gpGlobals->curtime )
{
pMarine->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN_PRIMARY );
m_flFireAnimTime = gpGlobals->curtime + 0.1f;
}
Vector vecDest = vecOrigSrc + (vecDir * ASW_CHAINSAW_RANGE);
bool bDamageTime = m_flDmgTime < gpGlobals->curtime;
bool bHit = false;
Ray_t ray;
ray.Init( vecOrigSrc, vecDest, Vector( -5, -5, -5 ), Vector( 5, 5, 25 ) );
CBaseEntity *(pEntities[ 8 ]);
CHurtableEntitiesEnum hurtableEntities( pEntities, 8 );
partition->EnumerateElementsAlongRay( PARTITION_ENGINE_NON_STATIC_EDICTS | PARTITION_ENGINE_SOLID_EDICTS, ray, false, &hurtableEntities );
trace_t tr;
for ( int i = 0; i < hurtableEntities.GetCount(); ++i )
{
CBaseEntity *pEntity = pEntities[ i ];
if ( pEntity == NULL || pEntity == pMarine )
continue;
bHit = true;
if ( bDamageTime )
{
// wide mode does damage to the ent, and radius damage
if ( pEntity->m_takedamage != DAMAGE_NO )
{
CTraceFilterOnlyHitThis filter( pEntity );
UTIL_TraceHull( vecOrigSrc, vecDest, Vector( -5, -5, -2 ), Vector( 5, 5, 25 ), MASK_SHOT, &filter, &tr );
ClearMultiDamage();
float fDamage = 0.5f * GetWeaponInfo()->m_flBaseDamage + MarineSkills()->GetSkillBasedValueByMarine( pMarine, ASW_MARINE_SKILL_MELEE, ASW_MARINE_SUBSKILL_MELEE_DMG );
CTakeDamageInfo info( this, pMarine, fDamage * g_pGameRules->GetDamageMultiplier(), DMG_SLASH );
info.SetWeapon( this );
CalculateMeleeDamageForce( &info, vecDir, tr.endpos );
pEntity->DispatchTraceAttack( info, vecDir, &tr );
ApplyMultiDamage();
}
// radius damage a little more potent in multiplayer.
#ifndef CLIENT_DLL
//RadiusDamage( CTakeDamageInfo( this, pMarine, sk_plr_dmg_asw_ml.GetFloat() * g_pGameRules->GetDamageMultiplier() / 4, DMG_ENERGYBEAM | DMG_BLAST | DMG_ALWAYSGIB ), tr.endpos, 128, CLASS_NONE, NULL );
#endif
}
}
if ( bHit )
{
if ( bDamageTime )
{
m_bIsFiring = true;
m_flLastHitTime = gpGlobals->curtime;
m_flTargetChainsawPitch = 0.0f;
#ifndef CLIENT_DLL
pMarine->OnWeaponFired( this, 1 );
#endif
if ( !pMarine->IsAlive() )
return;
// uses 5 ammo/second
if ( gpGlobals->curtime >= m_flAmmoUseTime )
{
// chainsaw no longer uses ammo
m_flAmmoUseTime = gpGlobals->curtime + 0.2;
/*
// decrement ammo
//m_iClip1 -= 1;
#ifdef GAME_DLL
CASW_Marine *pMarine = GetMarine();
if (pMarine && m_iClip1 <= 0 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
{
// check he doesn't have ammo in an ammo bay
CASW_Weapon_Ammo_Bag* pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>(pMarine->GetASWWeapon(0));
if (!pAmmoBag)
pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>(pMarine->GetASWWeapon(1));
//.........这里部分代码省略.........
示例8: RadiusDamage
//.........这里部分代码省略.........
float flMass = pBlockingEntity->VPhysicsGetObject()->GetMass();
float scale = flMass / MASS_ABSORB_ALL_DAMAGE;
// Absorbed all the damage.
if( scale >= 1.0f )
{
continue;
}
ASSERT( scale > 0.0f );
flBlockedDamagePercent = scale;
//Msg(" Object (%s) weighing %fkg blocked %f percent of explosion damage\n", pBlockingEntity->GetClassname(), flMass, scale * 100.0f);
}
else
{
// Some object that's not the world and not physics. Generically block 25% damage
flBlockedDamagePercent = 0.25f;
}
}
}
}
// decrease damage for an ent that's farther from the bomb.
flAdjustedDamage = ( vecSrc - tr.endpos ).Length() * falloff;
flAdjustedDamage = info.GetDamage() - flAdjustedDamage;
if ( flAdjustedDamage <= 0 )
{
continue;
}
// the explosion can 'see' this entity, so hurt them!
if (tr.startsolid)
{
// if we're stuck inside them, fixup the position and distance
tr.endpos = vecSrc;
tr.fraction = 0.0;
}
CTakeDamageInfo adjustedInfo = info;
//Msg("%s: Blocked damage: %f percent (in:%f out:%f)\n", pEntity->GetClassname(), flBlockedDamagePercent * 100, flAdjustedDamage, flAdjustedDamage - (flAdjustedDamage * flBlockedDamagePercent) );
adjustedInfo.SetDamage( flAdjustedDamage - (flAdjustedDamage * flBlockedDamagePercent) );
// Now make a consideration for skill level!
if( info.GetAttacker() && info.GetAttacker()->IsPlayer() && pEntity->IsNPC() )
{
// An explosion set off by the player is harming an NPC. Adjust damage accordingly.
adjustedInfo.AdjustPlayerDamageInflictedForSkillLevel();
}
Vector dir = vecSpot - vecSrc;
VectorNormalize( dir );
// If we don't have a damage force, manufacture one
if ( adjustedInfo.GetDamagePosition() == vec3_origin || adjustedInfo.GetDamageForce() == vec3_origin )
{
if ( !( adjustedInfo.GetDamageType() & DMG_PREVENT_PHYSICS_FORCE ) )
{
CalculateExplosiveDamageForce( &adjustedInfo, dir, vecSrc );
}
}
else
{
// Assume the force passed in is the maximum force. Decay it based on falloff.
float flForce = adjustedInfo.GetDamageForce().Length() * falloff;
adjustedInfo.SetDamageForce( dir * flForce );
adjustedInfo.SetDamagePosition( vecSrc );
}
if ( tr.fraction != 1.0 && pEntity == tr.m_pEnt )
{
ClearMultiDamage( );
pEntity->DispatchTraceAttack( adjustedInfo, dir, &tr );
ApplyMultiDamage();
}
else
{
pEntity->TakeDamage( adjustedInfo );
}
// Now hit all triggers along the way that respond to damage...
pEntity->TraceAttackToTriggers( adjustedInfo, vecSrc, tr.endpos, dir );
#if defined( GAME_DLL )
if ( info.GetAttacker() && info.GetAttacker()->IsPlayer() && ToBaseCombatCharacter( tr.m_pEnt ) )
{
// This is a total hack!!!
bool bIsPrimary = true;
CBasePlayer *player = ToBasePlayer( info.GetAttacker() );
CBaseCombatWeapon *pWeapon = player->GetActiveWeapon();
if ( pWeapon && FClassnameIs( pWeapon, "weapon_smg1" ) )
{
bIsPrimary = false;
}
//gamestats->Event_WeaponHit( player, bIsPrimary, (pWeapon != NULL) ? player->GetActiveWeapon()->GetClassname() : "NULL", info );
}
#endif
}
}
示例9: Fire
//=========================================================
// Disparo
//=========================================================
void CWeaponGaussGun::Fire()
{
CBasePlayer *pOwner = ToBasePlayer(GetOwner());
// ¿El jugador no ha sido creado?
if ( !pOwner )
return;
m_bCharging = false;
if ( m_hViewModel == NULL )
{
CBaseViewModel *vm = pOwner->GetViewModel();
if ( vm )
m_hViewModel.Set(vm);
}
Vector startPos = pOwner->Weapon_ShootPosition();
Vector aimDir = pOwner->GetAutoaimVector(AUTOAIM_5DEGREES);
Vector vecUp, vecRight;
VectorVectors(aimDir, vecRight, vecUp);
float x, y, z;
//Gassian spread
do {
x = random->RandomFloat(-0.5,0.5) + random->RandomFloat(-0.5,0.5);
y = random->RandomFloat(-0.5,0.5) + random->RandomFloat(-0.5,0.5);
z = x*x+y*y;
} while (z > 1);
aimDir = aimDir + x * GetBulletSpread().x * vecRight + y * GetBulletSpread().y * vecUp;
Vector endPos = startPos + (aimDir * MAX_TRACE_LENGTH);
// Shoot a shot straight out
trace_t tr;
UTIL_TraceLine(startPos, endPos, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr);
#ifndef CLIENT_DLL
ClearMultiDamage();
CBaseEntity *pHit = tr.m_pEnt;
CTakeDamageInfo dmgInfo(this, pOwner, sk_plr_dmg_gauss.GetFloat(), DMG_SHOCK | DMG_DISSOLVE);
if ( pHit != NULL )
{
CalculateBulletDamageForce(&dmgInfo, m_iPrimaryAmmoType, aimDir, tr.endpos);
pHit->DispatchTraceAttack(dmgInfo, aimDir, &tr);
}
if ( tr.DidHitWorld() )
{
float hitAngle = -DotProduct( tr.plane.normal, aimDir );
if ( hitAngle < 0.5f )
{
Vector vReflection;
vReflection = 2.0 * tr.plane.normal * hitAngle + aimDir;
startPos = tr.endpos;
endPos = startPos + (vReflection * MAX_TRACE_LENGTH);
// Draw beam to reflection point
DrawBeam(tr.startpos, tr.endpos, 15, true);
CPVSFilter filter(tr.endpos);
te->GaussExplosion(filter, 0.0f, tr.endpos, tr.plane.normal, 0);
UTIL_ImpactTrace(&tr, GetAmmoDef()->DamageType(m_iPrimaryAmmoType), "ImpactGauss");
//Find new reflection end position
UTIL_TraceLine(startPos, endPos, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr);
if ( tr.m_pEnt != NULL )
{
dmgInfo.SetDamageForce(GetAmmoDef()->DamageForce(m_iPrimaryAmmoType) * vReflection);
dmgInfo.SetDamagePosition(tr.endpos);
tr.m_pEnt->DispatchTraceAttack(dmgInfo, vReflection, &tr);
}
// Connect reflection point to end
DrawBeam(tr.startpos, tr.endpos, 10);
}
else
DrawBeam(tr.startpos, tr.endpos, 15, true);
}
else
DrawBeam(tr.startpos, tr.endpos, 15, true);
ApplyMultiDamage();
#endif
UTIL_ImpactTrace(&tr, GetAmmoDef()->DamageType(m_iPrimaryAmmoType), "ImpactGauss");
//.........这里部分代码省略.........
示例10: ChargedFire
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponGaussGun::ChargedFire()
{
if ( InGameRules()->IsMultiplayer() )
{
}
CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
if ( !pOwner )
return;
bool penetrated = false;
//Play shock sounds
WeaponSound( SINGLE );
WeaponSound( SPECIAL2 );
SendWeaponAnim( ACT_VM_SECONDARYATTACK );
StopChargeSound();
m_bCharging = false;
m_bChargeIndicated = false;
m_flNextPrimaryAttack = gpGlobals->curtime + 0.2f;
m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f;
//Shoot a shot straight out
Vector startPos= pOwner->Weapon_ShootPosition();
Vector aimDir = pOwner->GetAutoaimVector( AUTOAIM_5DEGREES );
Vector endPos = startPos + ( aimDir * MAX_TRACE_LENGTH );
trace_t tr;
UTIL_TraceLine( startPos, endPos, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr );
#ifndef CLIENT_DLL
ClearMultiDamage();
//Find how much damage to do
float flChargeAmount = ( gpGlobals->curtime - m_flChargeStartTime ) / MAX_GAUSS_CHARGE_TIME;
//Clamp this
if ( flChargeAmount > 1.0f )
flChargeAmount = 1.0f;
//Determine the damage amount
float flDamage = sk_plr_dmg_gauss.GetFloat() + ( ( sk_plr_max_dmg_gauss.GetFloat() - sk_plr_dmg_gauss.GetFloat() ) * flChargeAmount );
#endif
CBaseEntity *pHit = tr.m_pEnt;
if ( tr.DidHitWorld() )
{
//Try wall penetration
UTIL_ImpactTrace( &tr, GetAmmoDef()->DamageType(m_iPrimaryAmmoType), "ImpactGauss" );
UTIL_DecalTrace( &tr, "RedGlowFade" );
CPVSFilter filter( tr.endpos );
te->GaussExplosion( filter, 0.0f, tr.endpos, tr.plane.normal, 0 );
Vector testPos = tr.endpos + ( aimDir * 48.0f );
UTIL_TraceLine( testPos, tr.endpos, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr );
if ( tr.allsolid == false )
{
UTIL_DecalTrace( &tr, "RedGlowFade" );
penetrated = true;
}
}
#ifndef CLIENT_DLL
else if ( pHit != NULL )
{
CTakeDamageInfo dmgInfo( this, pOwner, flDamage, DMG_SHOCK | DMG_DISSOLVE );
CalculateBulletDamageForce( &dmgInfo, m_iPrimaryAmmoType, aimDir, tr.endpos );
//Do direct damage to anything in our path
pHit->DispatchTraceAttack( dmgInfo, aimDir, &tr );
}
ApplyMultiDamage();
#endif
UTIL_ImpactTrace( &tr, GetAmmoDef()->DamageType(m_iPrimaryAmmoType), "ImpactGauss" );
QAngle viewPunch;
viewPunch.x = random->RandomFloat( -4.0f, -8.0f );
viewPunch.y = random->RandomFloat( -0.25f, 0.25f );
viewPunch.z = 0;
pOwner->ViewPunch( viewPunch );
DrawBeam( startPos, tr.endpos, 25, true );
//.........这里部分代码省略.........
示例11: VPhysicsCollision
void CGETKnife::VPhysicsCollision( int index, gamevcollisionevent_t *pEvent )
{
// Call the baseclass first so we don't interfere with the normal running of things
BaseClass::VPhysicsCollision( index, pEvent );
// Grab what we hit
CBaseEntity *pOther = pEvent->pEntities[!index];
if ( !pOther->IsSolid() || pOther->IsSolidFlagSet(FSOLID_VOLUME_CONTENTS) )
return;
if ( !PassServerEntityFilter( this, pOther) )
return;
if ( !g_pGameRules->ShouldCollide( GetCollisionGroup(), pOther->GetCollisionGroup() ) )
return;
trace_t tr;
CollisionEventToTrace( index, pEvent, tr );
Vector vecAiming = pEvent->preVelocity[index];
VectorNormalize( vecAiming );
if ( pOther->m_takedamage != DAMAGE_NO && (pOther->IsPlayer() || pOther->IsNPC()) )
{
ClearMultiDamage();
CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), GetDamage(), DMG_SLASH | DMG_NEVERGIB );
CalculateMeleeDamageForce( &dmgInfo, vecAiming, tr.endpos, TKNIFE_FORCE_SCALE );
dmgInfo.SetDamagePosition( tr.endpos );
if ( this->GetOwnerEntity() && this->GetOwnerEntity()->IsPlayer() )
{
CBasePlayer *pPlayer = ToBasePlayer( this->GetOwnerEntity() );
dmgInfo.SetWeapon( pPlayer->Weapon_OwnsThisType( "weapon_throwing_knife" ) );
}
pOther->DispatchTraceAttack( dmgInfo, vecAiming, &tr );
ApplyMultiDamage();
PhysCallbackSetVelocity( pEvent->pObjects[index], vec3_origin );
SetTouch( NULL );
SetThink( NULL );
PhysCallbackRemove( this->NetworkProp() );
}
else
{
if ( pOther->IsWorld() )
{
// We hit the world, we have to check if this is sky
trace_t tr2;
Vector origin;
pEvent->pInternalData->GetContactPoint( origin );
UTIL_TraceLine( origin, origin + (vecAiming * 4), MASK_SOLID, this, COLLISION_GROUP_NONE, &tr2 );
if ( tr2.surface.flags & SURF_SKY )
{
// We hit sky, remove us NOW
SetTouch( NULL );
SetThink( NULL );
PhysCallbackRemove( this->NetworkProp() );
return;
}
}
m_bInAir = false;
CollisionProp()->UseTriggerBounds( true, 24 );
g_PostSimulationQueue.QueueCall( this, &CBaseEntity::SetOwnerEntity, (CBaseEntity*)NULL );
// const CBaseEntity *host = te->GetSuppressHost();
// te->SetSuppressHost( NULL );
// StopParticleEffects( this );
// te->SetSuppressHost( (CBaseEntity*)host );
SetTouch( &CGETKnife::PickupTouch );
SetThink( &CGETKnife::RemoveThink );
g_PostSimulationQueue.QueueCall(this, &CBaseEntity::SetCollisionGroup, COLLISION_GROUP_DROPPEDWEAPON);
SetNextThink( gpGlobals->curtime + 10.0f );
}
}
示例12: EffectUpdate
void CWeaponGravityGun::EffectUpdate( void )
{
Vector start, angles, forward, right;
trace_t tr;
CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
if ( !pOwner )
return;
m_viewModelIndex = pOwner->entindex();
// Make sure I've got a view model
CBaseViewModel *vm = pOwner->GetViewModel();
if ( vm )
{
m_viewModelIndex = vm->entindex();
}
pOwner->EyeVectors( &forward, &right, NULL );
start = pOwner->Weapon_ShootPosition();
Vector end = start + forward * 4096;
UTIL_TraceLine( start, end, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr );
end = tr.endpos;
float distance = tr.fraction * 4096;
if ( tr.fraction != 1 )
{
// too close to the player, drop the object
if ( distance < 36 )
{
DetachObject();
return;
}
}
if ( m_hObject == NULL && tr.DidHitNonWorldEntity() )
{
CBaseEntity *pEntity = tr.m_pEnt;
// inform the object what was hit
ClearMultiDamage();
pEntity->DispatchTraceAttack( CTakeDamageInfo( pOwner, pOwner, 0, DMG_PHYSGUN ), forward, &tr );
ApplyMultiDamage();
AttachObject( pEntity, start, tr.endpos, distance );
m_lastYaw = pOwner->EyeAngles().y;
}
// Add the incremental player yaw to the target transform
matrix3x4_t curMatrix, incMatrix, nextMatrix;
QAngle ang(0.0f, pOwner->EyeAngles().y - m_lastYaw, 0.0f);
AngleMatrix( m_gravCallback.m_targetRotation, curMatrix );
AngleMatrix( ang, incMatrix );
ConcatTransforms( incMatrix, curMatrix, nextMatrix );
MatrixAngles( nextMatrix, m_gravCallback.m_targetRotation );
m_lastYaw = pOwner->EyeAngles().y;
CBaseEntity *pObject = m_hObject;
if ( pObject )
{
if ( m_useDown )
{
if ( pOwner->m_afButtonPressed & IN_USE )
{
m_useDown = false;
}
}
else
{
if ( pOwner->m_afButtonPressed & IN_USE )
{
m_useDown = true;
}
}
if ( m_useDown )
{
pOwner->SetPhysicsFlag( PFLAG_DIROVERRIDE, true );
if ( pOwner->m_nButtons & IN_FORWARD )
{
m_distance = UTIL_Approach( 1024, m_distance, gpGlobals->frametime * 100 );
}
if ( pOwner->m_nButtons & IN_BACK )
{
m_distance = UTIL_Approach( 40, m_distance, gpGlobals->frametime * 100 );
}
}
if ( pOwner->m_nButtons & IN_WEAPON1 )
{
m_distance = UTIL_Approach( 1024, m_distance, m_distance * 0.1 );
}
if ( pOwner->m_nButtons & IN_WEAPON2 )
{
m_distance = UTIL_Approach( 40, m_distance, m_distance * 0.1 );
}
// Send the object a physics damage message (0 damage). Some objects interpret this
// as something else being in control of their physics temporarily.
pObject->TakeDamage( CTakeDamageInfo( this, pOwner, 0, DMG_PHYSGUN ) );
Vector newPosition = start + forward * m_distance;
//.........这里部分代码省略.........
示例13: HuntThink
void CNPC_ControllerHeadBall::HuntThink( void )
{
SetNextThink( gpGlobals->curtime + 0.1 );
if( !m_pSprite )
{
Assert(0);
return;
}
m_pSprite->SetBrightness( m_pSprite->GetBrightness() - 5, 0.1f );
CBroadcastRecipientFilter filter;
te->DynamicLight( filter, 0.0, &GetAbsOrigin(), 255, 255, 255, 0, m_pSprite->GetBrightness() / 16, 0.2, 0 );
// check world boundaries
if (gpGlobals->curtime - m_flSpawnTime > 5 || m_pSprite->GetBrightness() < 64 /*|| GetEnemy() == NULL || m_hOwner == NULL*/ || !IsInWorld() )
{
SetTouch( NULL );
SetThink( &CNPC_ControllerHeadBall::KillThink );
SetNextThink( gpGlobals->curtime );
return;
}
if( !GetEnemy() )
return;
MovetoTarget( GetEnemy()->GetAbsOrigin() );
if ((GetEnemy()->WorldSpaceCenter() - GetAbsOrigin()).Length() < 64)
{
trace_t tr;
UTIL_TraceLine( GetAbsOrigin(), GetEnemy()->WorldSpaceCenter(), MASK_ALL, this, COLLISION_GROUP_NONE, &tr );
CBaseEntity *pEntity = tr.m_pEnt;
if (pEntity != NULL && pEntity->m_takedamage == DAMAGE_YES)
{
ClearMultiDamage( );
Vector dir = GetAbsVelocity();
VectorNormalize( dir );
CTakeDamageInfo info( this, this, sk_controller_dmgball.GetFloat(), DMG_SHOCK );
CalculateMeleeDamageForce( &info, dir, tr.endpos );
pEntity->DispatchTraceAttack( info, dir, &tr );
ApplyMultiDamage();
int haloindex = 0;
int fadelength = 0;
int amplitude = 0;
const Vector vecEnd = tr.endpos;
te->BeamEntPoint( filter, 0.0, entindex(), NULL, 0, &(tr.m_pEnt->GetAbsOrigin()),
g_sModelIndexLaser, haloindex /* no halo */, 0, 10, 3, 20, 20, fadelength,
amplitude, 255, 255, 255, 255, 10 );
}
UTIL_EmitAmbientSound( GetSoundSourceIndex(), GetAbsOrigin(), "Controller.ElectroSound", 0.5, SNDLVL_NORM, 0, 100 );
SetNextAttack( gpGlobals->curtime + 3.0 );
SetThink( &CNPC_ControllerHeadBall::KillThink );
SetNextThink( gpGlobals->curtime + 0.3 );
}
}
示例14: FireChargedCannon
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CASW_PropJeep::FireChargedCannon( void )
{
bool penetrated = false;
m_bCannonCharging = false;
m_flCannonTime = gpGlobals->curtime + 0.5f;
StopChargeSound();
CPASAttenuationFilter sndFilter( this, "PropJeep.FireChargedCannon" );
EmitSound( sndFilter, entindex(), "PropJeep.FireChargedCannon" );
//Find the direction the gun is pointing in
Vector aimDir;
GetCannonAim( &aimDir );
Vector endPos = m_vecGunOrigin + ( aimDir * MAX_TRACE_LENGTH );
//Shoot a shot straight out
trace_t tr;
UTIL_TraceLine( m_vecGunOrigin, endPos, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr );
ClearMultiDamage();
//Find how much damage to do
float flChargeAmount = ( gpGlobals->curtime - m_flCannonChargeStartTime ) / MAX_GAUSS_CHARGE_TIME;
//Clamp this
if ( flChargeAmount > 1.0f )
{
flChargeAmount = 1.0f;
}
//Determine the damage amount
//FIXME: Use ConVars!
float flDamage = 15 + ( ( 250 - 15 ) * flChargeAmount );
CBaseEntity *pHit = tr.m_pEnt;
//Look for wall penetration
if ( tr.DidHitWorld() && !(tr.surface.flags & SURF_SKY) )
{
//Try wall penetration
UTIL_ImpactTrace( &tr, m_nBulletType, "ImpactJeep" );
UTIL_DecalTrace( &tr, "RedGlowFade" );
CPVSFilter filter( tr.endpos );
te->GaussExplosion( filter, 0.0f, tr.endpos, tr.plane.normal, 0 );
Vector testPos = tr.endpos + ( aimDir * 48.0f );
UTIL_TraceLine( testPos, tr.endpos, MASK_SHOT, GetDriver(), COLLISION_GROUP_NONE, &tr );
if ( tr.allsolid == false )
{
UTIL_DecalTrace( &tr, "RedGlowFade" );
penetrated = true;
}
}
else if ( pHit != NULL )
{
CTakeDamageInfo dmgInfo( this, GetDriver(), flDamage, DMG_SHOCK );
CalculateBulletDamageForce( &dmgInfo, GetAmmoDef()->Index("GaussEnergy"), aimDir, tr.endpos, 1.0f + flChargeAmount * 4.0f );
//Do direct damage to anything in our path
pHit->DispatchTraceAttack( dmgInfo, aimDir, &tr );
}
ApplyMultiDamage();
//Kick up an effect
if ( !(tr.surface.flags & SURF_SKY) )
{
UTIL_ImpactTrace( &tr, m_nBulletType, "ImpactJeep" );
//Do a gauss explosion
CPVSFilter filter( tr.endpos );
te->GaussExplosion( filter, 0.0f, tr.endpos, tr.plane.normal, 0 );
}
//Show the effect
DrawBeam( m_vecGunOrigin, tr.endpos, 9.6 );
// Register a muzzleflash for the AI
if ( m_hPlayer )
{
m_hPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 0.5f );
}
//Rock the car
IPhysicsObject *pObj = VPhysicsGetObject();
if ( pObj != NULL )
{
Vector shoveDir = aimDir * -( flDamage * 500.0f );
//.........这里部分代码省略.........
示例15: Fire
void CWeaponEgon::Fire( const Vector &vecOrigSrc, const Vector &vecDir )
{
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
if ( !pPlayer )
{
return;
}
//CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), 450, 0.1 );
WeaponSound( SINGLE );
Vector vecDest = vecOrigSrc + (vecDir * MAX_TRACE_LENGTH);
trace_t tr;
UTIL_TraceLine( vecOrigSrc, vecDest, MASK_SHOT, pPlayer, COLLISION_GROUP_NONE, &tr );
if ( tr.allsolid )
return;
CBaseEntity *pEntity = tr.m_pEnt;
if ( pEntity == NULL )
return;
if ( g_pGameRules->IsMultiplayer() )
{
if ( m_hSprite )
{
if ( pEntity->m_takedamage != DAMAGE_NO )
{
m_hSprite->TurnOn();
}
else
{
m_hSprite->TurnOff();
}
}
}
if ( m_flDmgTime < gpGlobals->curtime )
{
// wide mode does damage to the ent, and radius damage
if ( pEntity->m_takedamage != DAMAGE_NO )
{
ClearMultiDamage();
CTakeDamageInfo info(this, pPlayer, sk_plr_dmg_egon_wide.GetFloat() * g_pGameRules->GetDamageMultiplier(), DMG_ENERGYBEAM | DMG_ALWAYSGIB | DMG_CRUSH);
CalculateMeleeDamageForce( &info, vecDir, tr.endpos );
pEntity->DispatchTraceAttack( info, vecDir, &tr );
ApplyMultiDamage();
}
if ( g_pGameRules->IsMultiplayer() )
{
// radius damage a little more potent in multiplayer.
#ifndef CLIENT_DLL
RadiusDamage(CTakeDamageInfo(this, pPlayer, sk_plr_dmg_egon_wide.GetFloat() * g_pGameRules->GetDamageMultiplier() / 4, DMG_ENERGYBEAM | DMG_BLAST | DMG_ALWAYSGIB | DMG_CRUSH), tr.endpos, 128, CLASS_NONE, NULL);
#endif
}
if ( !pPlayer->IsAlive() )
return;
if ( g_pGameRules->IsMultiplayer() )
{
//multiplayer uses 5 ammo/second
if ( gpGlobals->curtime >= m_flAmmoUseTime )
{
UseAmmo( 1 );
m_flAmmoUseTime = gpGlobals->curtime + 0.2;
}
}
else
{
// Wide mode uses 10 charges per second in single player
if ( gpGlobals->curtime >= m_flAmmoUseTime )
{
UseAmmo( 1 );
m_flAmmoUseTime = gpGlobals->curtime + 0.1;
}
}
m_flDmgTime = gpGlobals->curtime + EGON_DISCHARGE_INTERVAL;
if ( m_flShakeTime < gpGlobals->curtime )
{
#ifndef CLIENT_DLL
UTIL_ScreenShake( tr.endpos, 5.0, 150.0, 0.75, 250.0, SHAKE_START );
#endif
m_flShakeTime = gpGlobals->curtime + 1.5;
}
}
Vector vecUp, vecRight;
QAngle angDir;
VectorAngles( vecDir, angDir );
AngleVectors( angDir, NULL, &vecRight, &vecUp );
Vector tmpSrc = vecOrigSrc + (vecUp * -8) + (vecRight * 3);
UpdateEffect( tmpSrc, tr.endpos );
}