//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CNPC_Ichthyosaur::Bite( void ) { //Don't allow another bite too soon if ( m_flNextBiteTime > gpGlobals->curtime ) return; CBaseEntity *pHurt; //FIXME: E3 HACK - Always damage bullseyes if we're scripted to hit them if ( ( GetEnemy() != NULL ) && ( GetEnemy()->Classify() == CLASS_BULLSEYE ) ) { pHurt = GetEnemy(); } else { pHurt = CheckTraceHullAttack( 108, Vector(-32,-32,-32), Vector(32,32,32), 0, DMG_CLUB ); } //Hit something if ( pHurt != NULL ) { CTakeDamageInfo info( this, this, sk_ichthyosaur_melee_dmg.GetInt(), DMG_CLUB ); if ( pHurt->IsPlayer() ) { CBasePlayer *pPlayer = ToBasePlayer( pHurt ); if ( pPlayer ) { if ( ( ( m_flHoldTime < gpGlobals->curtime ) && ( pPlayer->m_iHealth < (pPlayer->m_iMaxHealth*0.5f)) ) || ( pPlayer->GetWaterLevel() < 1 ) ) { //EnsnareVictim( pHurt ); } else { info.SetDamage( sk_ichthyosaur_melee_dmg.GetInt() * 3 ); } CalculateMeleeDamageForce( &info, GetAbsVelocity(), pHurt->GetAbsOrigin() ); pHurt->TakeDamage( info ); color32 red = {64, 0, 0, 255}; UTIL_ScreenFade( pPlayer, red, 0.5, 0, FFADE_IN ); //Disorient the player QAngle angles = pPlayer->GetLocalAngles(); angles.x += random->RandomInt( 60, 25 ); angles.y += random->RandomInt( 60, 25 ); angles.z = 0.0f; pPlayer->SetLocalAngles( angles ); pPlayer->SnapEyeAngles( angles ); } } else { CalculateMeleeDamageForce( &info, GetAbsVelocity(), pHurt->GetAbsOrigin() ); pHurt->TakeDamage( info ); } m_flNextBiteTime = gpGlobals->curtime + random->RandomFloat( 2.0f, 4.0f ); //Bubbles! UTIL_Bubbles( pHurt->GetAbsOrigin()+Vector(-32.0f,-32.0f,-32.0f), pHurt->GetAbsOrigin()+Vector(32.0f,32.0f,0.0f), random->RandomInt( 16, 32 ) ); // Play a random attack hit sound EmitSound( "NPC_Ichthyosaur.Bite" ); if ( GetActivity() == ACT_MELEE_ATTACK1 ) { SetActivity( (Activity) ACT_ICH_BITE_HIT ); } return; } //Play the miss animation and sound if ( GetActivity() == ACT_MELEE_ATTACK1 ) { SetActivity( (Activity) ACT_ICH_BITE_MISS ); } //Miss sound EmitSound( "NPC_Ichthyosaur.BiteMiss" ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CGrenadeBugBait::BugBaitTouch( CBaseEntity *pOther ) { Assert( pOther ); if ( !pOther->IsSolid() ) return; if ( m_pSporeTrail != NULL ) { m_pSporeTrail->m_bEmit = false; } //Do effect for the hit SporeExplosion *pSporeExplosion = SporeExplosion::CreateSporeExplosion(); if ( pSporeExplosion ) { Vector dir = -GetAbsVelocity(); VectorNormalize( dir ); QAngle angles; VectorAngles( dir, angles ); pSporeExplosion->SetLocalAngles( angles ); pSporeExplosion->SetLocalOrigin( GetAbsOrigin() ); pSporeExplosion->m_flSpawnRate = 1.0f; pSporeExplosion->m_flParticleLifetime = 2.0f; pSporeExplosion->SetRenderColor( 0.0f, 0.5f, 0.25f, 0.15f ); pSporeExplosion->m_flStartSize = 0.0f; pSporeExplosion->m_flEndSize = 32.0f; pSporeExplosion->m_flSpawnRadius = 2.0f; pSporeExplosion->SetLifetime( bugbait_distract_time.GetFloat() ); UTIL_Relink( pSporeExplosion ); } trace_t tr; Vector traceDir, tracePos; Vector directions[ NUM_SPLASHES ] = { Vector( 1, 0, 0 ), Vector( -1, 0, 0 ), Vector( 0, 1, 0 ), Vector( 0, -1, 0 ), Vector( 0, 0, 1 ), Vector( 0, 0, -1 ), }; //Splatter decals everywhere for ( int i = 0; i < NUM_SPLASHES; i++ ) { traceDir = directions[i]; tracePos = GetAbsOrigin() + ( traceDir * 64.0f ); UTIL_TraceLine( GetAbsOrigin(), tracePos, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction < 1.0f ) { UTIL_DecalTrace( &tr, "BeerSplash" ); //TODO: Use real decal } } //Make a splat sound CPASAttenuationFilter filter( this ); EmitSound( filter, entindex(), CHAN_WEAPON, "weapons/bugbait/splat.wav", 1.0f, ATTN_NORM ); //Attempt to activate any spawners in a radius around the bugbait CBaseEntity* pList[100]; Vector delta( 256, 256, 256 ); bool suppressCall = false; int count = UTIL_EntitiesInBox( pList, 100, GetAbsOrigin() - delta, GetAbsOrigin() + delta, 0 ); //Iterate over all the possible targets for ( i = 0; i < count; i++ ) { //See if this is a bugbait sensor if ( FClassnameIs( pList[i], "point_bugbait" ) ) { CBugBaitSensor *pSensor = dynamic_cast<CBugBaitSensor *>(pList[i]); if ( pSensor == NULL ) continue; //Make sure we're within range of the sensor if ( pSensor->GetRadius() > ( pSensor->GetAbsOrigin() - GetAbsOrigin() ).Length() ) { //Tell the sensor it's been hit pSensor->Baited( GetOwner() ); //If we're suppressing the call to antlions, then don't make a bugbait sound if ( pSensor->SuppressCall() ) { suppressCall = true; } } } } //Make sure we want to call antlions if ( suppressCall == false ) { //Alert any antlions around CSoundEnt::InsertSound( SOUND_BUGBAIT, GetAbsOrigin(), bugbait_hear_radius.GetInt(), bugbait_distract_time.GetFloat(), GetOwner() ); } //Go away UTIL_Remove( this ); }
//----------------------------------------------------------------------------- // Client-side obstacle avoidance //----------------------------------------------------------------------------- void C_BaseHLPlayer::PerformClientSideObstacleAvoidance( float flFrameTime, CUserCmd *pCmd ) { // Don't avoid if noclipping or in movetype none switch ( GetMoveType() ) { case MOVETYPE_NOCLIP: case MOVETYPE_NONE: case MOVETYPE_OBSERVER: return; default: break; } // Try to steer away from any objects/players we might interpenetrate Vector size = WorldAlignSize(); float radius = 0.7f * sqrt( size.x * size.x + size.y * size.y ); float curspeed = GetLocalVelocity().Length2D(); //int slot = 1; //engine->Con_NPrintf( slot++, "speed %f\n", curspeed ); //engine->Con_NPrintf( slot++, "radius %f\n", radius ); // If running, use a larger radius float factor = 1.0f; if ( curspeed > 150.0f ) { curspeed = MIN( 2048.0f, curspeed ); factor = ( 1.0f + ( curspeed - 150.0f ) / 150.0f ); //engine->Con_NPrintf( slot++, "scaleup (%f) to radius %f\n", factor, radius * factor ); radius = radius * factor; } Vector currentdir; Vector rightdir; QAngle vAngles = pCmd->viewangles; vAngles.x = 0; AngleVectors( vAngles, ¤tdir, &rightdir, NULL ); bool istryingtomove = false; bool ismovingforward = false; if ( fabs( pCmd->forwardmove ) > 0.0f || fabs( pCmd->sidemove ) > 0.0f ) { istryingtomove = true; if ( pCmd->forwardmove > 1.0f ) { ismovingforward = true; } } if ( istryingtomove == true ) radius *= 1.3f; CPlayerAndObjectEnumerator avoid( radius ); partition->EnumerateElementsInSphere( PARTITION_CLIENT_SOLID_EDICTS, GetAbsOrigin(), radius, false, &avoid ); // Okay, decide how to avoid if there's anything close by int c = avoid.GetObjectCount(); if ( c <= 0 ) return; //engine->Con_NPrintf( slot++, "moving %s forward %s\n", istryingtomove ? "true" : "false", ismovingforward ? "true" : "false" ); float adjustforwardmove = 0.0f; float adjustsidemove = 0.0f; for ( int i = 0; i < c; i++ ) { C_AI_BaseNPC *obj = dynamic_cast< C_AI_BaseNPC *>(avoid.GetObject( i )); if( !obj ) continue; Vector vecToObject = obj->GetAbsOrigin() - GetAbsOrigin(); float flDist = vecToObject.Length2D(); // Figure out a 2D radius for the object Vector vecWorldMins, vecWorldMaxs; obj->CollisionProp()->WorldSpaceAABB( &vecWorldMins, &vecWorldMaxs ); Vector objSize = vecWorldMaxs - vecWorldMins; float objectradius = 0.5f * sqrt( objSize.x * objSize.x + objSize.y * objSize.y ); //Don't run this code if the NPC is not moving UNLESS we are in stuck inside of them. if ( !obj->IsMoving() && flDist > objectradius ) continue; if ( flDist > objectradius && obj->IsEffectActive( EF_NODRAW ) ) { obj->RemoveEffects( EF_NODRAW ); } Vector vecNPCVelocity; obj->EstimateAbsVelocity( vecNPCVelocity ); float flNPCSpeed = VectorNormalize( vecNPCVelocity ); Vector vPlayerVel = GetAbsVelocity(); VectorNormalize( vPlayerVel ); float flHit1, flHit2; Vector vRayDir = vecToObject; VectorNormalize( vRayDir ); float flVelProduct = DotProduct( vecNPCVelocity, vPlayerVel ); float flDirProduct = DotProduct( vRayDir, vPlayerVel ); if ( !IntersectInfiniteRayWithSphere( GetAbsOrigin(), vRayDir, obj->GetAbsOrigin(), radius, &flHit1, &flHit2 ) ) continue; Vector dirToObject = -vecToObject; VectorNormalize( dirToObject ); float fwd = 0; float rt = 0; float sidescale = 2.0f; float forwardscale = 1.0f; bool foundResult = false; Vector vMoveDir = vecNPCVelocity; if ( flNPCSpeed > 0.001f ) { // This NPC is moving. First try deflecting the player left or right relative to the NPC's velocity. // Start with whatever side they're on relative to the NPC's velocity. Vector vecNPCTrajectoryRight = CrossProduct( vecNPCVelocity, Vector( 0, 0, 1) ); int iDirection = ( vecNPCTrajectoryRight.Dot( dirToObject ) > 0 ) ? 1 : -1; for ( int nTries = 0; nTries < 2; nTries++ ) { Vector vecTryMove = vecNPCTrajectoryRight * iDirection; VectorNormalize( vecTryMove ); Vector vTestPosition = GetAbsOrigin() + vecTryMove * radius * 2; if ( TestMove( vTestPosition, size.z * 2, radius * 2, obj->GetAbsOrigin(), vMoveDir ) ) { fwd = currentdir.Dot( vecTryMove ); rt = rightdir.Dot( vecTryMove ); //Msg( "PUSH DEFLECT fwd=%f, rt=%f\n", fwd, rt ); foundResult = true; break; } else { // Try the other direction. iDirection *= -1; } } } else { // the object isn't moving, so try moving opposite the way it's facing Vector vecNPCForward; obj->GetVectors( &vecNPCForward, NULL, NULL ); Vector vTestPosition = GetAbsOrigin() - vecNPCForward * radius * 2; if ( TestMove( vTestPosition, size.z * 2, radius * 2, obj->GetAbsOrigin(), vMoveDir ) ) { fwd = currentdir.Dot( -vecNPCForward ); rt = rightdir.Dot( -vecNPCForward ); if ( flDist < objectradius ) { obj->AddEffects( EF_NODRAW ); } //Msg( "PUSH AWAY FACE fwd=%f, rt=%f\n", fwd, rt ); foundResult = true; } } if ( !foundResult ) { // test if we can move in the direction the object is moving Vector vTestPosition = GetAbsOrigin() + vMoveDir * radius * 2; if ( TestMove( vTestPosition, size.z * 2, radius * 2, obj->GetAbsOrigin(), vMoveDir ) ) { fwd = currentdir.Dot( vMoveDir ); rt = rightdir.Dot( vMoveDir ); if ( flDist < objectradius ) { obj->AddEffects( EF_NODRAW ); } //Msg( "PUSH ALONG fwd=%f, rt=%f\n", fwd, rt ); foundResult = true; } else { // try moving directly away from the object Vector vTestPosition = GetAbsOrigin() - dirToObject * radius * 2; if ( TestMove( vTestPosition, size.z * 2, radius * 2, obj->GetAbsOrigin(), vMoveDir ) ) { fwd = currentdir.Dot( -dirToObject ); rt = rightdir.Dot( -dirToObject ); foundResult = true; //Msg( "PUSH AWAY fwd=%f, rt=%f\n", fwd, rt ); } } } if ( !foundResult ) { // test if we can move through the object Vector vTestPosition = GetAbsOrigin() - vMoveDir * radius * 2; fwd = currentdir.Dot( -vMoveDir ); rt = rightdir.Dot( -vMoveDir ); if ( flDist < objectradius ) { obj->AddEffects( EF_NODRAW ); } //Msg( "PUSH THROUGH fwd=%f, rt=%f\n", fwd, rt ); foundResult = true; } // If running, then do a lot more sideways veer since we're not going to do anything to // forward velocity if ( istryingtomove ) { sidescale = 6.0f; } if ( flVelProduct > 0.0f && flDirProduct > 0.0f ) { sidescale = 0.1f; } float force = 1.0f; float forward = forwardscale * fwd * force * AVOID_SPEED; float side = sidescale * rt * force * AVOID_SPEED; adjustforwardmove += forward; adjustsidemove += side; } pCmd->forwardmove += adjustforwardmove; pCmd->sidemove += adjustsidemove; // Clamp the move to within legal limits, preserving direction. This is a little // complicated because we have different limits for forward, back, and side //Msg( "PRECLAMP: forwardmove=%f, sidemove=%f\n", pCmd->forwardmove, pCmd->sidemove ); float flForwardScale = 1.0f; if ( pCmd->forwardmove > fabs( cl_forwardspeed.GetFloat() ) ) { flForwardScale = fabs( cl_forwardspeed.GetFloat() ) / pCmd->forwardmove; } else if ( pCmd->forwardmove < -fabs( cl_backspeed.GetFloat() ) ) { flForwardScale = fabs( cl_backspeed.GetFloat() ) / fabs( pCmd->forwardmove ); } float flSideScale = 1.0f; if ( fabs( pCmd->sidemove ) > fabs( cl_sidespeed.GetFloat() ) ) { flSideScale = fabs( cl_sidespeed.GetFloat() ) / fabs( pCmd->sidemove ); } float flScale = MIN( flForwardScale, flSideScale ); pCmd->forwardmove *= flScale; pCmd->sidemove *= flScale; //Msg( "POSTCLAMP: forwardmove=%f, sidemove=%f\n", pCmd->forwardmove, pCmd->sidemove ); }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CCrossbowBolt::BoltTouch( CBaseEntity *pOther ) { if ( pOther->IsSolidFlagSet(FSOLID_VOLUME_CONTENTS | FSOLID_TRIGGER) ) { // Some NPCs are triggers that can take damage (like antlion grubs). We should hit them. if ( ( pOther->m_takedamage == DAMAGE_NO ) || ( pOther->m_takedamage == DAMAGE_EVENTS_ONLY ) ) return; } if ( pOther->m_takedamage != DAMAGE_NO ) { trace_t tr, tr2; tr = BaseClass::GetTouchTrace(); Vector vecNormalizedVel = GetAbsVelocity(); ClearMultiDamage(); VectorNormalize( vecNormalizedVel ); #if defined(HL2_EPISODIC) //!!!HACKHACK - specific hack for ep2_outland_10 to allow crossbow bolts to pass through her bounding box when she's crouched in front of the player // (the player thinks they have clear line of sight because Alyx is crouching, but her BBOx is still full-height and blocks crossbow bolts. if( GetOwnerEntity() && GetOwnerEntity()->IsPlayer() && pOther->Classify() == CLASS_PLAYER_ALLY_VITAL && FStrEq(STRING(gpGlobals->mapname), "ep2_outland_10") ) { // Change the owner to stop further collisions with Alyx. We do this by making her the owner. // The player won't get credit for this kill but at least the bolt won't magically disappear! SetOwnerEntity( pOther ); return; } #endif//HL2_EPISODIC if( GetOwnerEntity() && GetOwnerEntity()->IsPlayer() && pOther->IsNPC() ) { CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), sk_plr_dmg_crossbow.GetFloat(), DMG_NEVERGIB ); dmgInfo.AdjustPlayerDamageInflictedForSkillLevel(); CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f ); dmgInfo.SetDamagePosition( tr.endpos ); pOther->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr ); CBasePlayer *pPlayer = ToBasePlayer( GetOwnerEntity() ); if ( pPlayer ) { gamestats->Event_WeaponHit( pPlayer, true, "weapon_crossbow", dmgInfo ); } } else { CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), sk_plr_dmg_crossbow.GetFloat(), DMG_BULLET | DMG_NEVERGIB ); CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f ); dmgInfo.SetDamagePosition( tr.endpos ); pOther->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr ); } ApplyMultiDamage(); //Adrian: keep going through the glass. if ( pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS ) return; /*if ( !pOther->IsAlive() ) { // We killed it! const surfacedata_t *pdata = physprops->GetSurfaceData( tr.surface.surfaceProps ); if ( pdata->game.material == CHAR_TEX_GLASS ) { return; } }*/ SetAbsVelocity( Vector( 0, 0, 0 ) ); // play body "thwack" sound EmitSound( "Weapon_Crossbow.BoltHitBody" ); Vector vForward; AngleVectors( GetAbsAngles(), &vForward ); VectorNormalize ( vForward ); UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + vForward * 128, MASK_BLOCKLOS, pOther, COLLISION_GROUP_NONE, &tr2 ); if ( tr2.fraction != 1.0f ) { // NDebugOverlay::Box( tr2.endpos, Vector( -16, -16, -16 ), Vector( 16, 16, 16 ), 0, 255, 0, 0, 10 ); // NDebugOverlay::Box( GetAbsOrigin(), Vector( -16, -16, -16 ), Vector( 16, 16, 16 ), 0, 0, 255, 0, 10 ); if ( tr2.m_pEnt == NULL || ( tr2.m_pEnt && tr2.m_pEnt->GetMoveType() == MOVETYPE_NONE ) ) { CEffectData data; data.m_vOrigin = tr2.endpos; data.m_vNormal = vForward; data.m_nEntIndex = tr2.fraction != 1.0f; DispatchEffect( "BoltImpact", data ); } } SetTouch( NULL ); SetThink( NULL ); if ( !g_pGameRules->IsMultiplayer() ) { UTIL_Remove( this ); } } else { trace_t tr; tr = BaseClass::GetTouchTrace(); // See if we struck the world if ( pOther->GetMoveType() == MOVETYPE_NONE && !( tr.surface.flags & SURF_SKY ) ) { EmitSound( "Weapon_Crossbow.BoltHitWorld" ); // if what we hit is static architecture, can stay around for a while. Vector vecDir = GetAbsVelocity(); float speed = VectorNormalize( vecDir ); // See if we should reflect off this surface float hitDot = DotProduct( tr.plane.normal, -vecDir ); if ( ( hitDot < 0.5f ) && ( speed > 100 ) ) { Vector vReflection = 2.0f * tr.plane.normal * hitDot + vecDir; QAngle reflectAngles; VectorAngles( vReflection, reflectAngles ); SetLocalAngles( reflectAngles ); SetAbsVelocity( vReflection * speed * 0.75f ); // Start to sink faster SetGravity( 1.0f ); } else { SetThink( &CCrossbowBolt::SUB_Remove ); SetNextThink( gpGlobals->curtime + 2.0f ); //FIXME: We actually want to stick (with hierarchy) to what we've hit SetMoveType( MOVETYPE_NONE ); Vector vForward; AngleVectors( GetAbsAngles(), &vForward ); VectorNormalize ( vForward ); CEffectData data; data.m_vOrigin = tr.endpos; data.m_vNormal = vForward; data.m_nEntIndex = 0; DispatchEffect( "BoltImpact", data ); UTIL_ImpactTrace( &tr, DMG_BULLET ); AddEffects( EF_NODRAW ); SetTouch( NULL ); SetThink( &CCrossbowBolt::SUB_Remove ); SetNextThink( gpGlobals->curtime + 2.0f ); if ( m_pGlowSprite != NULL ) { m_pGlowSprite->TurnOn(); m_pGlowSprite->FadeAndDie( 3.0f ); } } // Shoot some sparks if ( UTIL_PointContents( GetAbsOrigin() ) != CONTENTS_WATER) { g_pEffects->Sparks( GetAbsOrigin() ); } } else { // Put a mark unless we've hit the sky if ( ( tr.surface.flags & SURF_SKY ) == false ) { UTIL_ImpactTrace( &tr, DMG_BULLET ); } UTIL_Remove( this ); } } if ( g_pGameRules->IsMultiplayer() ) { // SetThink( &CCrossbowBolt::ExplodeThink ); // SetNextThink( gpGlobals->curtime + 0.1f ); } }
void CASW_Bait::BaitTouch( CBaseEntity *pOther ) { Assert( pOther ); if ( !pOther->IsSolid() ) return; if ( pOther && pOther->m_takedamage ) { Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity *= 0.1f; SetAbsVelocity( vecNewVelocity ); SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); SetGravity(1.0f); return; } else { // hit the world, check the material type here, see if the flare should stick. trace_t tr; tr = CBaseEntity::GetTouchTrace(); //Only do this on the first bounce if ( m_nBounces == 0 ) { surfacedata_t *pdata = physprops->GetSurfaceData( tr.surface.surfaceProps ); if ( pdata != NULL ) { //Only embed into concrete and wood (jdw: too obscure for players?) //if ( ( pdata->gameMaterial == 'C' ) || ( pdata->gameMaterial == 'W' ) ) { Vector impactDir = ( tr.endpos - tr.startpos ); VectorNormalize( impactDir ); float surfDot = tr.plane.normal.Dot( impactDir ); //Do not stick to ceilings or on shallow impacts if ( ( tr.plane.normal.z > -0.5f ) && ( surfDot < -0.9f ) ) { RemoveSolidFlags( FSOLID_NOT_SOLID ); AddSolidFlags( FSOLID_TRIGGER ); LayFlat(); UTIL_SetOrigin( this, tr.endpos + ( tr.plane.normal * 2.0f ) ); SetAbsVelocity( vec3_origin ); SetMoveType( MOVETYPE_NONE ); SetTouch( NULL ); return; } } } } // Change our flight characteristics SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); SetGravity( UTIL_ScaleForGravity( 640 ) ); m_nBounces++; //After the first bounce, smacking into whoever fired the flare is fair game SetOwnerEntity( NULL ); // Slow down Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity.x *= 0.8f; vecNewVelocity.y *= 0.8f; SetAbsVelocity( vecNewVelocity ); //Stopped? if ( GetAbsVelocity().Length() < 64.0f ) { LayFlat(); SetAbsVelocity( vec3_origin ); SetMoveType( MOVETYPE_NONE ); RemoveSolidFlags( FSOLID_NOT_SOLID ); AddSolidFlags( FSOLID_TRIGGER ); SetTouch( NULL ); } } }
//------------------------------------------------------------------------------ // Purpose : Move toward targetmap // Input : // Output : //------------------------------------------------------------------------------ void CGrenadeHomer::AimThink( void ) { // Blow up the missile if we have an explicit detonate time that // has been reached if (m_flDetonateTime != 0 && gpGlobals->curtime > m_flDetonateTime) { Detonate(); return; } PlayFlySound(); Vector vTargetPos = vec3_origin; Vector vTargetDir; float flCurHomingStrength = 0; // ------------------------------------------------ // If I'm homing // ------------------------------------------------ if (m_hTarget != NULL) { vTargetPos = m_hTarget->EyePosition(); vTargetDir = vTargetPos - GetAbsOrigin(); VectorNormalize(vTargetDir); // -------------------------------------------------- // If my target is far away do some primitive // obstacle avoidance // -------------------------------------------------- if ((vTargetPos - GetAbsOrigin()).Length() > 200) { Vector vTravelDir = GetAbsVelocity(); VectorNormalize(vTravelDir); vTravelDir *= 50; trace_t tr; UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + vTravelDir, MASK_SHOT, m_hTarget, COLLISION_GROUP_NONE, &tr ); if (tr.fraction != 1.0) { // Head off in normal float dotPr = DotProduct(vTravelDir,tr.plane.normal); Vector vBounce = -dotPr * tr.plane.normal; vBounce.z = 0; VectorNormalize(vBounce); vTargetDir += vBounce; VectorNormalize(vTargetDir); // DEBUG TOOL //NDebugOverlay::Line(GetOrigin(), GetOrigin()+vTravelDir, 255,0,0, true, 20); //NDebugOverlay::Line(GetOrigin(), GetOrigin()+(12*tr.plane.normal), 0,0,255, true, 20); //NDebugOverlay::Line(GetOrigin(), GetOrigin()+(vTargetDir), 0,255,0, true, 20); } } float flTargetSpeed = GetAbsVelocity().Length(); float flHomingRampUpStartTime = m_flHomingLaunchTime + m_flHomingDelay; float flHomingSustainStartTime = flHomingRampUpStartTime + m_flHomingRampUp; float flHomingRampDownStartTime = flHomingSustainStartTime + m_flHomingDuration; float flHomingEndHomingTime = flHomingRampDownStartTime + m_flHomingRampDown; // --------- // Delay // --------- if (gpGlobals->curtime < flHomingRampUpStartTime) { flCurHomingStrength = 0; flTargetSpeed = 0; } // ---------- // Ramp Up // ---------- else if (gpGlobals->curtime < flHomingSustainStartTime) { float flAge = gpGlobals->curtime - flHomingRampUpStartTime; flCurHomingStrength = m_flHomingStrength * (flAge/m_flHomingRampUp); flTargetSpeed = flCurHomingStrength * m_flHomingSpeed; } // ---------- // Sustain // ---------- else if (gpGlobals->curtime < flHomingRampDownStartTime) { flCurHomingStrength = m_flHomingStrength; flTargetSpeed = m_flHomingSpeed; } // ----------- // Ramp Down // ----------- else if (gpGlobals->curtime < flHomingEndHomingTime) { float flAge = gpGlobals->curtime - flHomingRampDownStartTime; flCurHomingStrength = m_flHomingStrength * (1-(flAge/m_flHomingRampDown)); flTargetSpeed = m_flHomingSpeed; } // --------------- // Set Homing // --------------- if (flCurHomingStrength > 0) { // ------------- // Smoke trail. // ------------- if (m_nRocketTrailType == HOMER_SMOKE_TRAIL_ON_HOMING) { UpdateRocketTrail(flCurHomingStrength); } // Extract speed and direction Vector vCurDir = GetAbsVelocity(); float flCurSpeed = VectorNormalize(vCurDir); flTargetSpeed = MAX(flTargetSpeed, flCurSpeed); // Add in homing direction Vector vecNewVelocity = GetAbsVelocity(); float flTimeToUse = gpGlobals->frametime; while (flTimeToUse > 0) { vecNewVelocity = (flCurHomingStrength * vTargetDir) + ((1 - flCurHomingStrength) * vCurDir); flTimeToUse = -0.1; } VectorNormalize(vecNewVelocity); vecNewVelocity *= flTargetSpeed; SetAbsVelocity( vecNewVelocity ); } } // ---------------------------------------------------------------------------------------- // Add time-coherent noise to the current velocity // ---------------------------------------------------------------------------------------- Vector vecImpulse( 0, 0, 0 ); if (m_flSpinMagnitude > 0) { vecImpulse.x += m_flSpinMagnitude*sin(m_flSpinSpeed * gpGlobals->curtime + m_flSpinOffset); vecImpulse.y += m_flSpinMagnitude*cos(m_flSpinSpeed * gpGlobals->curtime + m_flSpinOffset); vecImpulse.z -= m_flSpinMagnitude*cos(m_flSpinSpeed * gpGlobals->curtime + m_flSpinOffset); } // Add in gravity vecImpulse.z -= GetGravity() * GetCurrentGravity() * gpGlobals->frametime; ApplyAbsVelocityImpulse( vecImpulse ); QAngle angles; VectorAngles( GetAbsVelocity(), angles ); SetLocalAngles( angles ); #if 0 // BUBBLE if( gpGlobals->curtime > m_flNextWarnTime ) { // Make a bubble of warning sound in front of me. const float WARN_INTERVAL = 0.25f; float flSpeed = GetAbsVelocity().Length(); Vector vecWarnLocation; // warn a little bit ahead of us, please. vecWarnLocation = GetAbsOrigin() + GetAbsVelocity() * 0.75; // Make a bubble of warning ahead of the missile. CSoundEnt::InsertSound ( SOUND_DANGER, vecWarnLocation, flSpeed * WARN_INTERVAL, 0.5 ); #if 0 Vector vecRight, vecForward; AngleVectors( GetAbsAngles(), &vecForward, &vecRight, NULL ); NDebugOverlay::Line( vecWarnLocation, vecWarnLocation + vecForward * flSpeed * WARN_INTERVAL * 0.5, 255,255,0, true, 10); NDebugOverlay::Line( vecWarnLocation, vecWarnLocation - vecForward * flSpeed * WARN_INTERVAL * 0.5, 255,255,0, true, 10); NDebugOverlay::Line( vecWarnLocation, vecWarnLocation + vecRight * flSpeed * WARN_INTERVAL * 0.5, 255,255,0, true, 10); NDebugOverlay::Line( vecWarnLocation, vecWarnLocation - vecRight * flSpeed * WARN_INTERVAL * 0.5, 255,255,0, true, 10); #endif m_flNextWarnTime = gpGlobals->curtime + WARN_INTERVAL; } #endif // BUBBLE SetNextThink( gpGlobals->curtime + 0.1f ); }
void C_HL2MP_Player::AvoidPlayers( CUserCmd *pCmd ) { // This is only used in team play. if ( !HL2MPRules()->IsTeamplay() ) return; // Don't test if the player doesn't exist or is dead. if ( IsAlive() == false ) return; C_Team *pTeam = ( C_Team * )GetTeam(); if ( !pTeam ) return; // Up vector. static Vector vecUp( 0.0f, 0.0f, 1.0f ); Vector vecHL2MPPlayerCenter = GetAbsOrigin(); Vector vecHL2MPPlayerMin = GetPlayerMins(); Vector vecHL2MPPlayerMax = GetPlayerMaxs(); float flZHeight = vecHL2MPPlayerMax.z - vecHL2MPPlayerMin.z; vecHL2MPPlayerCenter.z += 0.5f * flZHeight; VectorAdd( vecHL2MPPlayerMin, vecHL2MPPlayerCenter, vecHL2MPPlayerMin ); VectorAdd( vecHL2MPPlayerMax, vecHL2MPPlayerCenter, vecHL2MPPlayerMax ); // Find an intersecting player or object. int nAvoidPlayerCount = 0; C_HL2MP_Player *pAvoidPlayerList[MAX_PLAYERS]; C_HL2MP_Player *pIntersectPlayer = NULL; float flAvoidRadius = 0.0f; Vector vecAvoidCenter, vecAvoidMin, vecAvoidMax; for ( int i = 0; i < pTeam->GetNumPlayers(); ++i ) { C_HL2MP_Player *pAvoidPlayer = static_cast< C_HL2MP_Player * >( pTeam->GetPlayer( i ) ); if ( pAvoidPlayer == NULL ) continue; // Is the avoid player me? if ( pAvoidPlayer == this ) continue; // Save as list to check against for objects. pAvoidPlayerList[nAvoidPlayerCount] = pAvoidPlayer; ++nAvoidPlayerCount; // Check to see if the avoid player is dormant. if ( pAvoidPlayer->IsDormant() ) continue; // Is the avoid player solid? if ( pAvoidPlayer->IsSolidFlagSet( FSOLID_NOT_SOLID ) ) continue; Vector t1, t2; vecAvoidCenter = pAvoidPlayer->GetAbsOrigin(); vecAvoidMin = pAvoidPlayer->GetPlayerMins(); vecAvoidMax = pAvoidPlayer->GetPlayerMaxs(); flZHeight = vecAvoidMax.z - vecAvoidMin.z; vecAvoidCenter.z += 0.5f * flZHeight; VectorAdd( vecAvoidMin, vecAvoidCenter, vecAvoidMin ); VectorAdd( vecAvoidMax, vecAvoidCenter, vecAvoidMax ); if ( IsBoxIntersectingBox( vecHL2MPPlayerMin, vecHL2MPPlayerMax, vecAvoidMin, vecAvoidMax ) ) { // Need to avoid this player. if ( !pIntersectPlayer ) { pIntersectPlayer = pAvoidPlayer; break; } } } // Anything to avoid? if ( !pIntersectPlayer ) return; // Calculate the push strength and direction. Vector vecDelta; // Avoid a player - they have precedence. if ( pIntersectPlayer ) { VectorSubtract( pIntersectPlayer->WorldSpaceCenter(), vecHL2MPPlayerCenter, vecDelta ); Vector vRad = pIntersectPlayer->WorldAlignMaxs() - pIntersectPlayer->WorldAlignMins(); vRad.z = 0; flAvoidRadius = vRad.Length(); } float flPushStrength = RemapValClamped( vecDelta.Length(), flAvoidRadius, 0, 0, hl2mp_max_separation_force.GetInt() ); //flPushScale; //Msg( "PushScale = %f\n", flPushStrength ); // Check to see if we have enough push strength to make a difference. if ( flPushStrength < 0.01f ) return; Vector vecPush; if ( GetAbsVelocity().Length2DSqr() > 0.1f ) { Vector vecVelocity = GetAbsVelocity(); vecVelocity.z = 0.0f; CrossProduct( vecUp, vecVelocity, vecPush ); VectorNormalize( vecPush ); } else { // We are not moving, but we're still intersecting. QAngle angView = pCmd->viewangles; angView.x = 0.0f; AngleVectors( angView, NULL, &vecPush, NULL ); } // Move away from the other player/object. Vector vecSeparationVelocity; if ( vecDelta.Dot( vecPush ) < 0 ) { vecSeparationVelocity = vecPush * flPushStrength; } else { vecSeparationVelocity = vecPush * -flPushStrength; } // Don't allow the max push speed to be greater than the max player speed. float flMaxPlayerSpeed = MaxSpeed(); float flCropFraction = 1.33333333f; if ( ( GetFlags() & FL_DUCKING ) && ( GetGroundEntity() != NULL ) ) { flMaxPlayerSpeed *= flCropFraction; } float flMaxPlayerSpeedSqr = flMaxPlayerSpeed * flMaxPlayerSpeed; if ( vecSeparationVelocity.LengthSqr() > flMaxPlayerSpeedSqr ) { vecSeparationVelocity.NormalizeInPlace(); VectorScale( vecSeparationVelocity, flMaxPlayerSpeed, vecSeparationVelocity ); } QAngle vAngles = pCmd->viewangles; vAngles.x = 0; Vector currentdir; Vector rightdir; AngleVectors( vAngles, ¤tdir, &rightdir, NULL ); Vector vDirection = vecSeparationVelocity; VectorNormalize( vDirection ); float fwd = currentdir.Dot( vDirection ); float rt = rightdir.Dot( vDirection ); float forward = fwd * flPushStrength; float side = rt * flPushStrength; //Msg( "fwd: %f - rt: %f - forward: %f - side: %f\n", fwd, rt, forward, side ); pCmd->forwardmove += forward; pCmd->sidemove += side; // Clamp the move to within legal limits, preserving direction. This is a little // complicated because we have different limits for forward, back, and side //Msg( "PRECLAMP: forwardmove=%f, sidemove=%f\n", pCmd->forwardmove, pCmd->sidemove ); float flForwardScale = 1.0f; if ( pCmd->forwardmove > fabs( cl_forwardspeed.GetFloat() ) ) { flForwardScale = fabs( cl_forwardspeed.GetFloat() ) / pCmd->forwardmove; } else if ( pCmd->forwardmove < -fabs( cl_backspeed.GetFloat() ) ) { flForwardScale = fabs( cl_backspeed.GetFloat() ) / fabs( pCmd->forwardmove ); } float flSideScale = 1.0f; if ( fabs( pCmd->sidemove ) > fabs( cl_sidespeed.GetFloat() ) ) { flSideScale = fabs( cl_sidespeed.GetFloat() ) / fabs( pCmd->sidemove ); } float flScale = min( flForwardScale, flSideScale ); pCmd->forwardmove *= flScale; pCmd->sidemove *= flScale; //Msg( "Pforwardmove=%f, sidemove=%f\n", pCmd->forwardmove, pCmd->sidemove ); }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void CBaseHelicopter::Flight( void ) { if( GetFlags() & FL_ONGROUND ) { //This would be really bad. RemoveFlag( FL_ONGROUND ); } // Generic speed up if (m_flGoalSpeed < m_flMaxSpeed) { m_flGoalSpeed += GetAcceleration(); } //NDebugOverlay::Line(GetAbsOrigin(), m_vecDesiredPosition, 0,0,255, true, 0.1); // tilt model 5 degrees (why?! sjb) QAngle vecAdj = QAngle( 5.0, 0, 0 ); // estimate where I'll be facing in one seconds Vector forward, right, up; AngleVectors( GetLocalAngles() + GetLocalAngularVelocity() * 2 + vecAdj, &forward, &right, &up ); // Vector vecEst1 = GetLocalOrigin() + GetAbsVelocity() + up * m_flForce - Vector( 0, 0, 384 ); // float flSide = DotProduct( m_vecDesiredPosition - vecEst1, right ); QAngle angVel = GetLocalAngularVelocity(); float flSide = DotProduct( m_vecDesiredFaceDir, right ); if (flSide < 0) { if (angVel.y < 60) { angVel.y += 8; } } else { if (angVel.y > -60) { angVel.y -= 8; } } angVel.y *= ( 0.98 ); // why?! (sjb) // estimate where I'll be in two seconds AngleVectors( GetLocalAngles() + angVel * 1 + vecAdj, NULL, NULL, &up ); Vector vecEst = GetAbsOrigin() + GetAbsVelocity() * 2.0 + up * m_flForce * 20 - Vector( 0, 0, 384 * 2 ); // add immediate force AngleVectors( GetLocalAngles() + vecAdj, &forward, &right, &up ); Vector vecImpulse( 0, 0, 0 ); vecImpulse.x += up.x * m_flForce; vecImpulse.y += up.y * m_flForce; vecImpulse.z += up.z * m_flForce; // add gravity vecImpulse.z -= 38.4; // 32ft/sec ApplyAbsVelocityImpulse( vecImpulse ); float flSpeed = GetAbsVelocity().Length(); float flDir = DotProduct( Vector( forward.x, forward.y, 0 ), Vector( GetAbsVelocity().x, GetAbsVelocity().y, 0 ) ); if (flDir < 0) { flSpeed = -flSpeed; } float flDist = DotProduct( GetDesiredPosition() - vecEst, forward ); // float flSlip = DotProduct( GetAbsVelocity(), right ); float flSlip = -DotProduct( GetDesiredPosition() - vecEst, right ); // fly sideways if (flSlip > 0) { if (GetLocalAngles().z > -30 && angVel.z > -15) angVel.z -= 4; else angVel.z += 2; } else { if (GetLocalAngles().z < 30 && angVel.z < 15) angVel.z += 4; else angVel.z -= 2; } // These functions contain code Ken wrote that used to be right here as part of the flight model, // but we want different helicopter vehicles to have different drag characteristics, so I made // them virtual functions (sjb) ApplySidewaysDrag( right ); ApplyGeneralDrag(); // apply power to stay correct height // FIXME: these need to be per class variables #define MAX_FORCE 80 #define FORCE_POSDELTA 12 #define FORCE_NEGDELTA 8 if (m_flForce < MAX_FORCE && vecEst.z < GetDesiredPosition().z) { m_flForce += FORCE_POSDELTA; } else if (m_flForce > 30) { if (vecEst.z > GetDesiredPosition().z) m_flForce -= FORCE_NEGDELTA; } // pitch forward or back to get to target //----------------------------------------- // Pitch is reversed since Half-Life! (sjb) //----------------------------------------- if (flDist > 0 && flSpeed < m_flGoalSpeed /* && flSpeed < flDist */ && GetLocalAngles().x + angVel.x < 40) { // ALERT( at_console, "F " ); // lean forward angVel.x += 12.0; } else if (flDist < 0 && flSpeed > -50 && GetLocalAngles().x + angVel.x > -20) { // ALERT( at_console, "B " ); // lean backward angVel.x -= 12.0; } else if (GetLocalAngles().x + angVel.x < 0) { // ALERT( at_console, "f " ); angVel.x += 4.0; } else if (GetLocalAngles().x + angVel.x > 0) { // ALERT( at_console, "b " ); angVel.x -= 4.0; } SetLocalAngularVelocity( angVel ); // ALERT( at_console, "%.0f %.0f : %.0f %.0f : %.0f %.0f : %.0f\n", GetAbsOrigin().x, GetAbsVelocity().x, flDist, flSpeed, GetLocalAngles().x, m_vecAngVelocity.x, m_flForce ); // ALERT( at_console, "%.0f %.0f : %.0f %0.f : %.0f\n", GetAbsOrigin().z, GetAbsVelocity().z, vecEst.z, m_vecDesiredPosition.z, m_flForce ); }
// Set the activity based on an event or current state void CHL2MP_Player::SetAnimation( PLAYER_ANIM playerAnim ) { int animDesired; float speed; speed = GetAbsVelocity().Length2D(); // bool bRunning = true; //Revisit! /* if ( ( m_nButtons & ( IN_FORWARD | IN_BACK | IN_MOVELEFT | IN_MOVERIGHT ) ) ) { if ( speed > 1.0f && speed < hl2_normspeed.GetFloat() - 20.0f ) { bRunning = false; } }*/ if ( GetFlags() & ( FL_FROZEN | FL_ATCONTROLS ) ) { speed = 0; playerAnim = PLAYER_IDLE; } Activity idealActivity = ACT_HL2MP_RUN; // This could stand to be redone. Why is playerAnim abstracted from activity? (sjb) if ( playerAnim == PLAYER_JUMP ) { idealActivity = ACT_HL2MP_JUMP; } else if ( playerAnim == PLAYER_DIE ) { if ( m_lifeState == LIFE_ALIVE ) { return; } } else if ( playerAnim == PLAYER_ATTACK1 ) { if ( GetActivity( ) == ACT_HOVER || GetActivity( ) == ACT_SWIM || GetActivity( ) == ACT_HOP || GetActivity( ) == ACT_LEAP || GetActivity( ) == ACT_DIESIMPLE ) { idealActivity = GetActivity( ); } else { idealActivity = ACT_HL2MP_GESTURE_RANGE_ATTACK; } } else if ( playerAnim == PLAYER_RELOAD ) { idealActivity = ACT_HL2MP_GESTURE_RELOAD; } else if ( playerAnim == PLAYER_IDLE || playerAnim == PLAYER_WALK ) { if ( !( GetFlags() & FL_ONGROUND ) && GetActivity( ) == ACT_HL2MP_JUMP ) // Still jumping { idealActivity = GetActivity( ); } /* else if ( GetWaterLevel() > 1 ) { if ( speed == 0 ) idealActivity = ACT_HOVER; else idealActivity = ACT_SWIM; } */ else { if ( GetFlags() & FL_DUCKING ) { if ( speed > 0 ) { idealActivity = ACT_HL2MP_WALK_CROUCH; } else { idealActivity = ACT_HL2MP_IDLE_CROUCH; } } else { if ( speed > 0 ) { /* if ( bRunning == false ) { idealActivity = ACT_WALK; } else */ { idealActivity = ACT_HL2MP_RUN; } } else { idealActivity = ACT_HL2MP_IDLE; } } } idealActivity = TranslateTeamActivity( idealActivity ); } if ( idealActivity == ACT_HL2MP_GESTURE_RANGE_ATTACK ) { RestartGesture( Weapon_TranslateActivity( idealActivity ) ); // FIXME: this seems a bit wacked Weapon_SetActivity( Weapon_TranslateActivity( ACT_RANGE_ATTACK1 ), 0 ); return; } else if ( idealActivity == ACT_HL2MP_GESTURE_RELOAD ) { RestartGesture( Weapon_TranslateActivity( idealActivity ) ); return; } else { SetActivity( idealActivity ); animDesired = SelectWeightedSequence( Weapon_TranslateActivity ( idealActivity ) ); if (animDesired == -1) { animDesired = SelectWeightedSequence( idealActivity ); if ( animDesired == -1 ) { animDesired = 0; } } // Already using the desired animation? if ( GetSequence() == animDesired ) return; m_flPlaybackRate = 1.0; ResetSequence( animDesired ); SetCycle( 0 ); return; } // Already using the desired animation? if ( GetSequence() == animDesired ) return; //Msg( "Set animation to %d\n", animDesired ); // Reset to first frame of desired animation ResetSequence( animDesired ); SetCycle( 0 ); }
//----------------------------------------------------------------------------- // Purpose: // Input : flInterval - // &m_LastMoveTarget - // eMoveType - //----------------------------------------------------------------------------- void CNPC_Ichthyosaur::DoMovement( float flInterval, const Vector &MoveTarget, int eMoveType ) { // dvs: something is setting this bit, causing us to stop moving and get stuck that way Forget( bits_MEMORY_TURNING ); Vector Steer, SteerAvoid, SteerRel; Vector forward, right, up; //Get our orientation vectors. GetVectors( &forward, &right, &up); if ( ( GetActivity() == ACT_MELEE_ATTACK1 ) && ( GetEnemy() != NULL ) ) { SteerSeek( Steer, GetEnemy()->GetAbsOrigin() ); } else { //If we are approaching our goal, use an arrival steering mechanism. if ( eMoveType == ICH_MOVETYPE_ARRIVE ) { SteerArrive( Steer, MoveTarget ); } else { //Otherwise use a seek steering mechanism. SteerSeek( Steer, MoveTarget ); } } #if FEELER_COLLISION Vector f, u, l, r, d; float probeLength = GetAbsVelocity().Length(); if ( probeLength < 150 ) probeLength = 150; if ( probeLength > 500 ) probeLength = 500; f = DoProbe( GetLocalOrigin() + (probeLength * forward) ); r = DoProbe( GetLocalOrigin() + (probeLength/3 * (forward+right)) ); l = DoProbe( GetLocalOrigin() + (probeLength/3 * (forward-right)) ); u = DoProbe( GetLocalOrigin() + (probeLength/3 * (forward+up)) ); d = DoProbe( GetLocalOrigin() + (probeLength/3 * (forward-up)) ); SteerAvoid = f+r+l+u+d; //NDebugOverlay::Line( GetLocalOrigin(), GetLocalOrigin()+SteerAvoid, 255, 255, 0, false, 0.1f ); if ( SteerAvoid.LengthSqr() ) { Steer = (SteerAvoid*0.5f); } m_vecVelocity = m_vecVelocity + (Steer*0.5f); VectorNormalize( m_vecVelocity ); SteerRel.x = forward.Dot( m_vecVelocity ); SteerRel.y = right.Dot( m_vecVelocity ); SteerRel.z = up.Dot( m_vecVelocity ); m_vecVelocity *= m_flGroundSpeed; #else //See if we need to avoid any obstacles. if ( SteerAvoidObstacles( SteerAvoid, GetAbsVelocity(), forward, right, up ) ) { //Take the avoidance vector Steer = SteerAvoid; } //Clamp our ideal steering vector to within our physical limitations. ClampSteer( Steer, SteerRel, forward, right, up ); ApplyAbsVelocityImpulse( Steer * flInterval ); #endif Vector vecNewVelocity = GetAbsVelocity(); float flLength = vecNewVelocity.Length(); //Clamp our final speed if ( flLength > m_flGroundSpeed ) { vecNewVelocity *= ( m_flGroundSpeed / flLength ); flLength = m_flGroundSpeed; } Vector workVelocity = vecNewVelocity; AddSwimNoise( &workVelocity ); // Pose the fish properly SetPoses( SteerRel, flLength ); //Drag our victim before moving if ( m_pVictim != NULL ) { DragVictim( (workVelocity*flInterval).Length() ); } //Move along the current velocity vector if ( WalkMove( workVelocity * flInterval, MASK_NPCSOLID ) == false ) { //Attempt a half-step if ( WalkMove( (workVelocity*0.5f) * flInterval, MASK_NPCSOLID) == false ) { //Restart the velocity //VectorNormalize( m_vecVelocity ); vecNewVelocity *= 0.5f; } else { //Cut our velocity in half vecNewVelocity *= 0.5f; } } SetAbsVelocity( vecNewVelocity ); }
//----------------------------------------------------------------------------- // Purpose: // Input : // Output : //----------------------------------------------------------------------------- void CBaseHelicopter::ApplyGeneralDrag( void ) { Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity *= 0.995; SetAbsVelocity( vecNewVelocity ); }
//----------------------------------------------------------------------------- // Purpose: Determines the pose parameters for the bending of the body and tail speed // Input : moveRel - the dot products for the deviation off of each direction (f,r,u) // speed - speed of the fish //----------------------------------------------------------------------------- void CNPC_Ichthyosaur::SetPoses( Vector moveRel, float speed ) { float movePerc, moveBase; //Find out how fast we're moving in our animations boundaries if ( GetIdealActivity() == ACT_WALK ) { moveBase = 0.5f; movePerc = moveBase * ( speed / ICH_SWIM_SPEED_WALK ); } else { moveBase = 1.0f; movePerc = moveBase * ( speed / ICH_SWIM_SPEED_RUN ); } Vector tailPosition; float flSwimSpeed = movePerc; //Forward deviation if ( moveRel.x > 0 ) { flSwimSpeed *= moveBase + (( moveRel.x / m_vecAccelerationMax.x )*moveBase); } else if ( moveRel.x < 0 ) { flSwimSpeed *= moveBase - (( moveRel.x / m_vecAccelerationMin.x )*moveBase); } //Vertical deviation if ( moveRel.z > 0 ) { tailPosition[PITCH] = -90.0f * ( moveRel.z / m_vecAccelerationMax.z ); } else if ( moveRel.z < 0 ) { tailPosition[PITCH] = 90.0f * ( moveRel.z / m_vecAccelerationMin.z ); } else { tailPosition[PITCH] = 0.0f; } //Lateral deviation if ( moveRel.y > 0 ) { tailPosition[ROLL] = 25 * moveRel.y / m_vecAccelerationMax.y; tailPosition[YAW] = -1.0f * moveRel.y / m_vecAccelerationMax.y; } else if ( moveRel.y < 0 ) { tailPosition[ROLL] = -25 * moveRel.y / m_vecAccelerationMin.y; tailPosition[YAW] = moveRel.y / m_vecAccelerationMin.y; } else { tailPosition[ROLL] = 0.0f; tailPosition[YAW] = 0.0f; } //Clamp flSwimSpeed = clamp( flSwimSpeed, 0.25f, 1.0f ); tailPosition[YAW] = clamp( tailPosition[YAW], -90.0f, 90.0f ); tailPosition[PITCH] = clamp( tailPosition[PITCH], -90.0f, 90.0f ); //Blend m_flTailYaw = ( m_flTailYaw * 0.8f ) + ( tailPosition[YAW] * 0.2f ); m_flTailPitch = ( m_flTailPitch * 0.8f ) + ( tailPosition[PITCH] * 0.2f ); m_flSwimSpeed = ( m_flSwimSpeed * 0.8f ) + ( flSwimSpeed * 0.2f ); //Pose the body SetPoseParameter( 0, m_flSwimSpeed ); SetPoseParameter( 1, m_flTailYaw ); SetPoseParameter( 2, m_flTailPitch ); //FIXME: Until the sequence info is reset properly after SetPoseParameter if ( ( GetActivity() == ACT_RUN ) || ( GetActivity() == ACT_WALK ) ) { ResetSequenceInfo(); } //Face our current velocity GetMotor()->SetIdealYawAndUpdate( UTIL_AngleMod( CalcIdealYaw( GetAbsOrigin() + GetAbsVelocity() ) ), AI_KEEP_YAW_SPEED ); float pitch = 0.0f; if ( speed != 0.0f ) { pitch = -RAD2DEG( asin( GetAbsVelocity().z / speed ) ); } //FIXME: Framerate dependant QAngle angles = GetLocalAngles(); angles.x = (angles.x * 0.8f) + (pitch * 0.2f); angles.z = (angles.z * 0.9f) + (tailPosition[ROLL] * 0.1f); SetLocalAngles( angles ); }
Vector CNPC_Ichthyosaur::DoProbe( const Vector &probe ) { trace_t tr; float fraction = 1.0f; bool collided = false; Vector normal = Vector( 0, 0, -1 ); float waterLevel = UTIL_WaterLevel( GetAbsOrigin(), GetAbsOrigin().z, GetAbsOrigin().z+150 ); waterLevel -= GetAbsOrigin().z; waterLevel /= 150; if ( waterLevel < 1.0f ) { collided = true; fraction = waterLevel; } AI_TraceHull( GetAbsOrigin(), probe, GetHullMins(), GetHullMaxs(), MASK_NPCSOLID, this, COLLISION_GROUP_NONE, &tr ); if ( ( collided == false ) || ( tr.fraction < fraction ) ) { fraction = tr.fraction; normal = tr.plane.normal; } if ( ( fraction < 1.0f ) && ( GetEnemy() == NULL || tr.u.ent != GetEnemy()->pev ) ) { #if FEELER_COLLISION_VISUALIZE NDebugOverlay::Line( GetLocalOrigin(), probe, 255, 0, 0, false, 0.1f ); #endif Vector probeDir = probe - GetLocalOrigin(); Vector normalToProbeAndWallNormal = probeDir.Cross( normal ); Vector steeringVector = normalToProbeAndWallNormal.Cross( probeDir ); Vector velDir = GetAbsVelocity(); VectorNormalize( velDir ); float steeringForce = m_flGroundSpeed * ( 1.0f - fraction ) * normal.Dot( velDir ); if ( steeringForce < 0.0f ) { steeringForce = -steeringForce; } velDir = steeringVector; VectorNormalize( velDir ); steeringVector = steeringForce * velDir; return steeringVector; } #if FEELER_COLLISION_VISUALIZE NDebugOverlay::Line( GetLocalOrigin(), probe, 0, 255, 0, false, 0.1f ); #endif return Vector( 0.0f, 0.0f, 0.0f ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CNPC_Ichthyosaur::PrescheduleThink( void ) { BaseClass::PrescheduleThink(); //Ambient sounds /* if ( random->RandomInt( 0, 20 ) == 10 ) { if ( random->RandomInt( 0, 1 ) ) { ENVELOPE_CONTROLLER.SoundChangeVolume( m_pSwimSound, random->RandomFloat( 0.0f, 0.5f ), 1.0f ); } else { ENVELOPE_CONTROLLER.SoundChangeVolume( m_pVoiceSound, random->RandomFloat( 0.0f, 0.5f ), 1.0f ); } } */ //Pings if ( m_flNextPingTime < gpGlobals->curtime ) { m_flNextPingTime = gpGlobals->curtime + random->RandomFloat( 3.0f, 8.0f ); } //Growls if ( ( m_NPCState == NPC_STATE_COMBAT || m_NPCState == NPC_STATE_ALERT ) && ( m_flNextGrowlTime < gpGlobals->curtime ) ) { m_flNextGrowlTime = gpGlobals->curtime + random->RandomFloat( 2.0f, 6.0f ); } //Randomly emit bubbles if ( random->RandomInt( 0, 10 ) == 0 ) { UTIL_Bubbles( GetAbsOrigin()+(GetHullMins()*0.5f), GetAbsOrigin()+(GetHullMaxs()*0.5f), 1 ); } //Check our water level if ( GetWaterLevel() != 3 ) { if ( GetWaterLevel() < 2 ) { DevMsg( 2, "Came out of water\n" ); if ( Beached() ) { SetSchedule( SCHED_ICH_THRASH ); Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity[2] = 8.0f; SetAbsVelocity( vecNewVelocity ); } } else { //TODO: Wake effects } } //If we have a victim, update them if ( m_pVictim != NULL ) { //See if it's time to release the victim if ( m_flHoldTime < gpGlobals->curtime ) { ReleaseVictim(); return; } Bite(); } }
//========================================================= // HandleAnimEvent - catches the monster-specific messages // that occur when tagged animation frames are played. //========================================================= void CNPC_Bullsquid::HandleAnimEvent( animevent_t *pEvent ) { switch( pEvent->event ) { case BSQUID_AE_SPIT: { Vector vSpitPos; GetAttachment("mouth", vSpitPos); vSpitPos.z += 40.0f; Vector vTarget; // If our enemy is looking at us and far enough away, lead him if (HasCondition(COND_ENEMY_FACING_ME) && UTIL_DistApprox(GetAbsOrigin(), GetEnemy()->GetAbsOrigin()) > (40 * 12)) { UTIL_PredictedPosition(GetEnemy(), 0.5f, &vTarget); vTarget.z = GetEnemy()->GetAbsOrigin().z; } else { // Otherwise he can't see us and he won't be able to dodge vTarget = GetEnemy()->BodyTarget(vSpitPos, true); } vTarget[2] += random->RandomFloat(0.0f, 32.0f); // Try and spit at our target Vector vecToss; if (GetSpitVector(vSpitPos, vTarget, &vecToss) == false) { DevMsg("GetSpitVector( vSpitPos, vTarget, &vecToss ) == false\n"); // Now try where they were if (GetSpitVector(vSpitPos, m_vSavePosition, &vecToss) == false) { DevMsg("GetSpitVector( vSpitPos, m_vSavePosition, &vecToss ) == false\n"); // Failing that, just shoot with the old velocity we calculated initially! vecToss = m_vecSaveSpitVelocity; } } // Find what our vertical theta is to estimate the time we'll impact the ground Vector vecToTarget = (vTarget - vSpitPos); VectorNormalize(vecToTarget); float flVelocity = VectorNormalize(vecToss); float flCosTheta = DotProduct(vecToTarget, vecToss); float flTime = (vSpitPos - vTarget).Length2D() / (flVelocity * flCosTheta); // Emit a sound where this is going to hit so that targets get a chance to act correctly CSoundEnt::InsertSound(SOUND_DANGER, vTarget, (15 * 12), flTime, this); // Don't fire again until this volley would have hit the ground (with some lag behind it) SetNextAttack(gpGlobals->curtime + flTime + random->RandomFloat(0.5f, 2.0f)); for (int i = 0; i < 6; i++) { CGrenadeSpit *pGrenade = (CGrenadeSpit*)CreateEntityByName("grenade_spit"); pGrenade->SetAbsOrigin(vSpitPos); pGrenade->SetAbsAngles(vec3_angle); DispatchSpawn(pGrenade); pGrenade->SetThrower(this); pGrenade->SetOwnerEntity(this); if (i == 0) { pGrenade->SetSpitSize(SPIT_LARGE); pGrenade->SetAbsVelocity(vecToss * flVelocity); } else { pGrenade->SetAbsVelocity((vecToss + RandomVector(-0.035f, 0.035f)) * flVelocity); pGrenade->SetSpitSize(random->RandomInt(SPIT_SMALL, SPIT_MEDIUM)); } // Tumble through the air pGrenade->SetLocalAngularVelocity(QAngle(random->RandomFloat(-250, -500), random->RandomFloat(-250, -500), random->RandomFloat(-250, -500))); } for (int i = 0; i < 8; i++) { DispatchParticleEffect("blood_impact_yellow_01", vSpitPos + RandomVector(-12.0f, 12.0f), RandomAngle(0, 360)); } EmitSound("NPC_Antlion.PoisonShoot"); } break; case BSQUID_AE_BITE: { // SOUND HERE! CBaseEntity *pHurt = CheckTraceHullAttack( 70, Vector(-16,-16,-16), Vector(16,16,16), sk_bullsquid_dmg_bite.GetFloat(), DMG_SLASH ); if ( pHurt ) { Vector forward, up; AngleVectors( GetAbsAngles(), &forward, NULL, &up ); pHurt->ApplyAbsVelocityImpulse( 100 * (up-forward) ); pHurt->SetGroundEntity( NULL ); } } break; case BSQUID_AE_WHIP_SND: { EmitSound( "NPC_Bullsquid.TailWhip" ); break; } /* case BSQUID_AE_TAILWHIP: { CBaseEntity *pHurt = CheckTraceHullAttack( 70, Vector(-16,-16,-16), Vector(16,16,16), sk_bullsquid_dmg_whip.GetFloat(), DMG_SLASH | DMG_ALWAYSGIB ); if ( pHurt ) { Vector right, up; AngleVectors( GetAbsAngles(), NULL, &right, &up ); if ( pHurt->GetFlags() & ( FL_NPC | FL_CLIENT ) ) pHurt->ViewPunch( QAngle( 20, 0, -20 ) ); pHurt->ApplyAbsVelocityImpulse( 100 * (up+2*right) ); } } break; */ case BSQUID_AE_BLINK: { // close eye. m_nSkin = 1; } break; case BSQUID_AE_HOP: { float flGravity = GetCurrentGravity(); // throw the squid up into the air on this frame. if ( GetFlags() & FL_ONGROUND ) { SetGroundEntity( NULL ); } // jump 40 inches into the air Vector vecVel = GetAbsVelocity(); vecVel.z += sqrt( flGravity * 2.0 * 40 ); SetAbsVelocity( vecVel ); } break; case BSQUID_AE_THROW: { // squid throws its prey IF the prey is a client. CBaseEntity *pHurt = CheckTraceHullAttack( 70, Vector(-16,-16,-16), Vector(16,16,16), 0, 0 ); if ( pHurt ) { pHurt->ViewPunch( QAngle(20,0,-20) ); // screeshake transforms the viewmodel as well as the viewangle. No problems with seeing the ends of the viewmodels. UTIL_ScreenShake( pHurt->GetAbsOrigin(), 25.0, 1.5, 0.7, 2, SHAKE_START ); // If the player, throw him around if ( pHurt->IsPlayer()) { Vector forward, up; AngleVectors( GetLocalAngles(), &forward, NULL, &up ); pHurt->ApplyAbsVelocityImpulse( forward * 300 + up * 300 ); } // If not the player see if has bullsquid throw interatcion else { CBaseCombatCharacter *pVictim = ToBaseCombatCharacter( pHurt ); if (pVictim) { if ( pVictim->DispatchInteraction( g_interactionBullsquidThrow, NULL, this ) ) { Vector forward, up; AngleVectors( GetLocalAngles(), &forward, NULL, &up ); pVictim->ApplyAbsVelocityImpulse( forward * 300 + up * 250 ); } } } } } break; default: BaseClass::HandleAnimEvent( pEvent ); } }
void CBaseGrenade::BounceTouch( CBaseEntity *pOther ) { if ( pOther->IsSolidFlagSet(FSOLID_TRIGGER | FSOLID_VOLUME_CONTENTS) ) return; // don't hit the guy that launched this grenade if ( pOther == GetThrower() ) return; // only do damage if we're moving fairly fast if ( (pOther->m_takedamage != DAMAGE_NO) && (m_flNextAttack < gpGlobals->curtime && GetAbsVelocity().Length() > 100)) { if (m_hThrower) { #if !defined( CLIENT_DLL ) trace_t tr; tr = CBaseEntity::GetTouchTrace( ); ClearMultiDamage( ); Vector forward; AngleVectors( GetLocalAngles(), &forward, NULL, NULL ); CTakeDamageInfo info( this, m_hThrower, 1, DMG_CLUB ); CalculateMeleeDamageForce( &info, GetAbsVelocity(), GetAbsOrigin() ); pOther->DispatchTraceAttack( info, forward, &tr ); ApplyMultiDamage(); #endif } m_flNextAttack = gpGlobals->curtime + 1.0; // debounce } Vector vecTestVelocity; // m_vecAngVelocity = Vector (300, 300, 300); // this is my heuristic for modulating the grenade velocity because grenades dropped purely vertical // or thrown very far tend to slow down too quickly for me to always catch just by testing velocity. // trimming the Z velocity a bit seems to help quite a bit. vecTestVelocity = GetAbsVelocity(); vecTestVelocity.z *= 0.45; if ( !m_bHasWarnedAI && vecTestVelocity.Length() <= 60 ) { // grenade is moving really slow. It's probably very close to where it will ultimately stop moving. // emit the danger sound. // register a radius louder than the explosion, so we make sure everyone gets out of the way #if !defined( CLIENT_DLL ) CSoundEnt::InsertSound ( SOUND_DANGER, GetAbsOrigin(), (int)(m_flDamage / 0.4), 0.3, this ); #endif m_bHasWarnedAI = true; } if (GetFlags() & FL_ONGROUND) { // add a bit of static friction // SetAbsVelocity( GetAbsVelocity() * 0.8 ); // SetSequence( random->RandomInt( 1, 1 ) ); // FIXME: missing tumble animations } else { // play bounce sound BounceSound(); } m_flPlaybackRate = GetAbsVelocity().Length() / 200.0; if (m_flPlaybackRate > 1.0) m_flPlaybackRate = 1; else if (m_flPlaybackRate < 0.5) m_flPlaybackRate = 0; }
void CGrenadeHomer::Detonate(void) { StopRocketTrail(); StopSound(entindex(), CHAN_BODY, STRING(m_sFlySound)); m_takedamage = DAMAGE_NO; CPASFilter filter( GetAbsOrigin() ); te->Explosion( filter, 0.0, &GetAbsOrigin(), g_sModelIndexFireball, 2.0, 15, TE_EXPLFLAG_NONE, m_DmgRadius, m_flDamage ); // int magnitude = 1.0; // int colorRamp = random->RandomInt( 128, 255 ); if ( m_nRocketTrailType == HOMER_SMOKE_TRAIL_ALIEN ) { // Add a shockring CBroadcastRecipientFilter filter3; te->BeamRingPoint( filter3, 0, GetAbsOrigin(), //origin 16, //start radius 1000, //end radius m_spriteTexture, //texture 0, //halo index 0, //start frame 2, //framerate 0.3f, //life 128, //width 16, //spread 0, //amplitude 100, //r 0, //g 200, //b 50, //a 128 //speed ); // Add a shockring CBroadcastRecipientFilter filter4; te->BeamRingPoint( filter4, 0, GetAbsOrigin(), //origin 16, //start radius 500, //end radius m_spriteTexture, //texture 0, //halo index 0, //start frame 2, //framerate 0.3f, //life 128, //width 16, //spread 0, //amplitude 200, //r 0, //g 100, //b 50, //a 128 //speed ); } Vector vecForward = GetAbsVelocity(); VectorNormalize(vecForward); trace_t tr; UTIL_TraceLine ( GetAbsOrigin(), GetAbsOrigin() + 60*vecForward, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, & tr); UTIL_DecalTrace( &tr, "Scorch" ); UTIL_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START ); RadiusDamage ( CTakeDamageInfo( this, GetOwnerEntity(), m_flDamage, DMG_BLAST ), GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL ); CPASAttenuationFilter filter2( this, "GrenadeHomer.StopSounds" ); EmitSound( filter2, entindex(), "GrenadeHomer.StopSounds" ); UTIL_Remove( this ); }
//------------------------------------------------------------------------------ // Purpose : // Input : // Output : //------------------------------------------------------------------------------ void CGrenadeBeam::GrenadeBeamTouch( CBaseEntity *pOther ) { //--------------------------------------------------------- // Make sure I'm not caught in a corner, if so remove me //--------------------------------------------------------- if (gpGlobals->curtime - m_flLastTouchTime < 0.01) { KillBeam(); return; } m_flLastTouchTime = gpGlobals->curtime; // --------------------------------------- // If I have room for another hit, add it // --------------------------------------- if (m_nNumHits < GRENADEBEAM_MAXHITS) { m_pHitLocation[m_nNumHits] = GetLocalOrigin(); m_nNumHits++; } // Otherwise copy over old hit, and force chaser into last hit position else { m_hBeamChaser->SetLocalOrigin( m_pHitLocation[0] ); for (int i=0;i<m_nNumHits-1;i++) { m_pHitLocation[i] = m_pHitLocation[i+1]; } m_pHitLocation[m_nNumHits-1]=GetLocalOrigin(); } UpdateBeams(); // -------------------------------------- // Smoke or bubbles effect // -------------------------------------- if (UTIL_PointContents ( GetAbsOrigin() ) & MASK_WATER) { UTIL_Bubbles(GetAbsOrigin()-Vector(3,3,3),GetAbsOrigin()+Vector(3,3,3),10); } else { UTIL_Smoke(GetAbsOrigin(), random->RandomInt(5, 10), 10); } // -------------------------------------------- // Play burn sounds // -------------------------------------------- if (pOther->m_takedamage) { pOther->TakeDamage( CTakeDamageInfo( this, this, m_flDamage, DMG_BURN ) ); KillBeam(); return; } EmitSound( "GrenadeBeam.HitSound" ); trace_t tr; Vector vDirection = GetAbsVelocity(); VectorNormalize(vDirection); UTIL_TraceLine( GetAbsOrigin()-vDirection, GetAbsOrigin()+vDirection, MASK_SOLID, NULL, COLLISION_GROUP_NONE, &tr ); UTIL_DecalTrace( &tr, "RedGlowFade" ); UTIL_ImpactTrace( &tr, DMG_ENERGYBEAM ); }
//========================================================= // HandleAnimEvent - catches the monster-specific messages // that occur when tagged animation frames are played. //========================================================= void CNPC_Bullsquid::HandleAnimEvent( animevent_t *pEvent ) { switch( pEvent->event ) { case BSQUID_AE_SPIT: { if ( GetEnemy() ) { Vector vecSpitOffset; Vector vecSpitDir; Vector vRight, vUp, vForward; AngleVectors ( GetAbsAngles(), &vForward, &vRight, &vUp ); // !!!HACKHACK - the spot at which the spit originates (in front of the mouth) was measured in 3ds and hardcoded here. // we should be able to read the position of bones at runtime for this info. vecSpitOffset = ( vRight * 8 + vForward * 60 + vUp * 50 ); vecSpitOffset = ( GetAbsOrigin() + vecSpitOffset ); vecSpitDir = ( ( GetEnemy()->BodyTarget( GetAbsOrigin() ) ) - vecSpitOffset ); VectorNormalize( vecSpitDir ); vecSpitDir.x += random->RandomFloat( -0.05, 0.05 ); vecSpitDir.y += random->RandomFloat( -0.05, 0.05 ); vecSpitDir.z += random->RandomFloat( -0.05, 0 ); AttackSound(); CSquidSpit::Shoot( this, vecSpitOffset, vecSpitDir * 900 ); } } break; case BSQUID_AE_BITE: { // SOUND HERE! CBaseEntity *pHurt = CheckTraceHullAttack( 70, Vector(-16,-16,-16), Vector(16,16,16), sk_bullsquid_dmg_bite.GetFloat(), DMG_SLASH ); if ( pHurt ) { Vector forward, up; AngleVectors( GetAbsAngles(), &forward, NULL, &up ); pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() - (forward * 100) ); pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() + (up * 100) ); pHurt->SetGroundEntity( NULL ); } } break; case BSQUID_AE_TAILWHIP: { CBaseEntity *pHurt = CheckTraceHullAttack( 70, Vector(-16,-16,-16), Vector(16,16,16), sk_bullsquid_dmg_whip.GetFloat(), DMG_SLASH | DMG_ALWAYSGIB ); if ( pHurt ) { Vector right, up; AngleVectors( GetAbsAngles(), NULL, &right, &up ); if ( pHurt->GetFlags() & ( FL_NPC | FL_CLIENT ) ) pHurt->ViewPunch( QAngle( 20, 0, -20 ) ); pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() + (right * 200) ); pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() + (up * 100) ); } } break; case BSQUID_AE_BLINK: { // close eye. m_nSkin = 1; } break; case BSQUID_AE_HOP: { float flGravity = sv_gravity.GetFloat(); // throw the squid up into the air on this frame. if ( GetFlags() & FL_ONGROUND ) { SetGroundEntity( NULL ); } // jump into air for 0.8 (24/30) seconds Vector vecVel = GetAbsVelocity(); vecVel.z += ( 0.625 * flGravity ) * 0.5; SetAbsVelocity( vecVel ); } break; case BSQUID_AE_THROW: { // squid throws its prey IF the prey is a client. CBaseEntity *pHurt = CheckTraceHullAttack( 70, Vector(-16,-16,-16), Vector(16,16,16), 0, 0 ); if ( pHurt ) { // croonchy bite sound CPASAttenuationFilter filter( this ); EmitSound( filter, entindex(), "Bullsquid.Bite" ); // screeshake transforms the viewmodel as well as the viewangle. No problems with seeing the ends of the viewmodels. UTIL_ScreenShake( pHurt->GetAbsOrigin(), 25.0, 1.5, 0.7, 2, SHAKE_START ); if ( pHurt->IsPlayer() ) { Vector forward, up; AngleVectors( GetAbsAngles(), &forward, NULL, &up ); pHurt->SetAbsVelocity( pHurt->GetAbsVelocity() + forward * 300 + up * 300 ); } } } break; default: BaseClass::HandleAnimEvent( pEvent ); } }
void CBaseGrenadeProjectile::ResolveFlyCollisionCustom( trace_t &trace, Vector &vecVelocity ) { //Assume all surfaces have the same elasticity float flSurfaceElasticity = 1.0; //Don't bounce off of players with perfect elasticity if( trace.m_pEnt && trace.m_pEnt->IsPlayer() ) { flSurfaceElasticity = 0.3; } // if its breakable glass and we kill it, don't bounce. // give some damage to the glass, and if it breaks, pass // through it. bool breakthrough = false; if( trace.m_pEnt && FClassnameIs( trace.m_pEnt, "func_breakable" ) ) { breakthrough = true; } if( trace.m_pEnt && FClassnameIs( trace.m_pEnt, "func_breakable_surf" ) ) { breakthrough = true; } if (breakthrough) { CTakeDamageInfo info( this, this, 10, DMG_CLUB ); trace.m_pEnt->DispatchTraceAttack( info, GetAbsVelocity(), &trace ); ApplyMultiDamage(); if( trace.m_pEnt->m_iHealth <= 0 ) { // slow our flight a little bit Vector vel = GetAbsVelocity(); vel *= 0.4; SetAbsVelocity( vel ); return; } } float flTotalElasticity = GetElasticity() * flSurfaceElasticity; flTotalElasticity = clamp( flTotalElasticity, 0.0f, 0.9f ); // NOTE: A backoff of 2.0f is a reflection Vector vecAbsVelocity; PhysicsClipVelocity( GetAbsVelocity(), trace.plane.normal, vecAbsVelocity, 2.0f ); vecAbsVelocity *= flTotalElasticity; // Get the total velocity (player + conveyors, etc.) VectorAdd( vecAbsVelocity, GetBaseVelocity(), vecVelocity ); float flSpeedSqr = DotProduct( vecVelocity, vecVelocity ); // Stop if on ground. if ( trace.plane.normal.z > 0.7f ) // Floor { // Verify that we have an entity. CBaseEntity *pEntity = trace.m_pEnt; Assert( pEntity ); SetAbsVelocity( vecAbsVelocity ); if ( flSpeedSqr < ( 30 * 30 ) ) { if ( pEntity->IsStandable() ) { SetGroundEntity( pEntity ); } // Reset velocities. SetAbsVelocity( vec3_origin ); SetLocalAngularVelocity( vec3_angle ); //align to the ground so we're not standing on end QAngle angle; VectorAngles( trace.plane.normal, angle ); // rotate randomly in yaw angle[1] = random->RandomFloat( 0, 360 ); // TODO: rotate around trace.plane.normal SetAbsAngles( angle ); } else { Vector vecDelta = GetBaseVelocity() - vecAbsVelocity; Vector vecBaseDir = GetBaseVelocity(); VectorNormalize( vecBaseDir ); float flScale = vecDelta.Dot( vecBaseDir ); VectorScale( vecAbsVelocity, ( 1.0f - trace.fraction ) * gpGlobals->frametime, vecVelocity ); VectorMA( vecVelocity, ( 1.0f - trace.fraction ) * gpGlobals->frametime, GetBaseVelocity() * flScale, vecVelocity ); PhysicsPushEntity( vecVelocity, &trace ); } } else { // If we get *too* slow, we'll stick without ever coming to rest because // we'll get pushed down by gravity faster than we can escape from the wall. if ( flSpeedSqr < ( 30 * 30 ) ) { // Reset velocities. SetAbsVelocity( vec3_origin ); SetLocalAngularVelocity( vec3_angle ); } else { SetAbsVelocity( vecAbsVelocity ); } } BounceSound(); }
void CTFBaseRocket::FlyThink( void ) { if ( gpGlobals->curtime > m_flCollideWithTeammatesTime && m_bCollideWithTeammates == false ) { m_bCollideWithTeammates = true; } if ( tf2c_homing_rockets.GetBool() || ( tf2c_homing_deflected_rockets.GetBool() && m_iDeflected ) ) { // Find the closest visible enemy player. CUtlVector<CTFPlayer *> vecPlayers; int count = CollectPlayers( &vecPlayers, TEAM_ANY, true ); float flClosest = FLT_MAX; Vector vecClosestTarget = vec3_origin; for ( int i = 0; i < count; i++ ) { CTFPlayer *pPlayer = vecPlayers[i]; if ( pPlayer == GetOwnerEntity() ) continue; if ( pPlayer->GetTeamNumber() == GetTeamNumber() && !TFGameRules()->IsDeathmatch() ) continue; Vector vecTarget; QAngle angTarget; if ( GetWeaponID() == TF_WEAPON_COMPOUND_BOW ) { int iBone = pPlayer->LookupBone( "bip_head" ); pPlayer->GetBonePosition( iBone, vecTarget, angTarget );; } else { vecTarget = pPlayer->EyePosition(); } if ( FVisible( vecTarget ) ) { float flDistSqr = ( vecTarget - GetAbsOrigin() ).LengthSqr(); if ( flDistSqr < flClosest ) { flClosest = flDistSqr; vecClosestTarget = vecTarget; } } } // Head towards him. if ( vecClosestTarget != vec3_origin ) { Vector vecTarget = vecClosestTarget; Vector vecDir = vecTarget - GetAbsOrigin(); VectorNormalize( vecDir ); float flSpeed = GetAbsVelocity().Length(); QAngle angForward; VectorAngles( vecDir, angForward ); SetAbsAngles( angForward ); SetAbsVelocity( vecDir * flSpeed ); } } SetNextThink( gpGlobals->curtime + 0.1f ); }
//----------------------------------------------------------------------------- // Purpose: // Input : *pOther - //----------------------------------------------------------------------------- void CFlare::FlareTouch( CBaseEntity *pOther ) { Assert( pOther ); if ( !pOther->IsSolid() ) return; if ( ( m_nBounces < 10 ) && ( GetWaterLevel() < 1 ) ) { // Throw some real chunks here g_pEffects->Sparks( GetAbsOrigin() ); } //If the flare hit a person or NPC, do damage here. if ( pOther && pOther->m_takedamage ) { /* The Flare is the iRifle round right now. No damage, just ignite. (sjb) //Damage is a function of how fast the flare is flying. int iDamage = GetAbsVelocity().Length() / 50.0f; if ( iDamage < 5 ) { //Clamp minimum damage iDamage = 5; } //Use m_pOwner, not GetOwnerEntity() pOther->TakeDamage( CTakeDamageInfo( this, m_pOwner, iDamage, (DMG_BULLET|DMG_BURN) ) ); m_flNextDamage = gpGlobals->curtime + 1.0f; */ CBaseAnimating *pAnim; pAnim = dynamic_cast<CBaseAnimating*>(pOther); if( pAnim ) { pAnim->Ignite( 30.0f ); } Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity *= 0.1f; SetAbsVelocity( vecNewVelocity ); SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); SetGravity(1.0f); Die( 0.5 ); return; } else { // hit the world, check the material type here, see if the flare should stick. trace_t tr; tr = CBaseEntity::GetTouchTrace(); //Only do this on the first bounce if ( m_nBounces == 0 ) { const surfacedata_t *pdata = physprops->GetSurfaceData( tr.surface.surfaceProps ); if ( pdata != NULL ) { //Only embed into concrete and wood (jdw: too obscure for players?) //if ( ( pdata->gameMaterial == 'C' ) || ( pdata->gameMaterial == 'W' ) ) { Vector impactDir = ( tr.endpos - tr.startpos ); VectorNormalize( impactDir ); float surfDot = tr.plane.normal.Dot( impactDir ); //Do not stick to ceilings or on shallow impacts if ( ( tr.plane.normal.z > -0.5f ) && ( surfDot < -0.9f ) ) { RemoveSolidFlags( FSOLID_NOT_SOLID ); AddSolidFlags( FSOLID_TRIGGER ); UTIL_SetOrigin( this, tr.endpos + ( tr.plane.normal * 2.0f ) ); SetAbsVelocity( vec3_origin ); SetMoveType( MOVETYPE_NONE ); SetTouch( &CFlare::FlareBurnTouch ); int index = decalsystem->GetDecalIndexForName( "SmallScorch" ); if ( index >= 0 ) { CBroadcastRecipientFilter filter; te->Decal( filter, 0.0, &tr.endpos, &tr.startpos, ENTINDEX( tr.m_pEnt ), tr.hitbox, index ); } CPASAttenuationFilter filter2( this, "Flare.Touch" ); EmitSound( filter2, entindex(), "Flare.Touch" ); return; } } } } //Scorch decal if ( GetAbsVelocity().LengthSqr() > (250*250) ) { int index = decalsystem->GetDecalIndexForName( "FadingScorch" ); if ( index >= 0 ) { CBroadcastRecipientFilter filter; te->Decal( filter, 0.0, &tr.endpos, &tr.startpos, ENTINDEX( tr.m_pEnt ), tr.hitbox, index ); } } // Change our flight characteristics SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); SetGravity( UTIL_ScaleForGravity( 640 ) ); m_nBounces++; //After the first bounce, smacking into whoever fired the flare is fair game SetOwnerEntity( this ); // Slow down Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity.x *= 0.8f; vecNewVelocity.y *= 0.8f; SetAbsVelocity( vecNewVelocity ); //Stopped? if ( GetAbsVelocity().Length() < 64.0f ) { SetAbsVelocity( vec3_origin ); SetMoveType( MOVETYPE_NONE ); RemoveSolidFlags( FSOLID_NOT_SOLID ); AddSolidFlags( FSOLID_TRIGGER ); SetTouch( &CFlare::FlareBurnTouch ); } } }
//--------------------------------------------------------- // This is the official way to add velocity to an element. // See SetElementVelocity() for explanation. //--------------------------------------------------------- void CBlobElement::AddElementVelocity( Vector vecVelocityAdd, bool bPlanarOnly ) { Vector vecSum = GetAbsVelocity() + vecVelocityAdd; SetAbsVelocity( vecSum ); }
void COsprey :: DyingThink( void ) { StudioFrameAdvance( ); SetNextThink( 0.1 ); Vector angVel = GetLocalAvelocity(); angVel *= 1.02; SetLocalAvelocity( angVel ); // still falling? if (m_startTime > gpGlobals->time ) { UTIL_MakeAimVectors( GetAbsAngles() ); ShowDamage( ); Vector vecSpot = GetAbsOrigin() + GetAbsVelocity() * 0.2; Vector vecVel = GetAbsVelocity(); // random explosions MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_EXPLOSION); // This just makes a dynamic light now WRITE_COORD( vecSpot.x + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( vecSpot.y + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( vecSpot.z + RANDOM_FLOAT( -150, -50 )); WRITE_SHORT( g_sModelIndexFireball ); WRITE_BYTE( RANDOM_LONG(0,29) + 30 ); // scale * 10 WRITE_BYTE( 12 ); // framerate WRITE_BYTE( TE_EXPLFLAG_NONE ); MESSAGE_END(); // lots of smoke MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_SMOKE ); WRITE_COORD( vecSpot.x + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( vecSpot.y + RANDOM_FLOAT( -150, 150 )); WRITE_COORD( vecSpot.z + RANDOM_FLOAT( -150, -50 )); WRITE_SHORT( g_sModelIndexSmoke ); WRITE_BYTE( 100 ); // scale * 10 WRITE_BYTE( 10 ); // framerate MESSAGE_END(); vecSpot = GetAbsOrigin() + (pev->mins + pev->maxs) * 0.5; MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_BREAKMODEL); // position WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z ); // size WRITE_COORD( 800 ); WRITE_COORD( 800 ); WRITE_COORD( 132 ); // velocity WRITE_COORD( vecVel.x ); WRITE_COORD( vecVel.y ); WRITE_COORD( vecVel.z ); // randomization WRITE_BYTE( 50 ); // Model WRITE_SHORT( m_iTailGibs ); //model id# // # of shards WRITE_BYTE( 8 ); // let client decide // duration WRITE_BYTE( 200 );// 10.0 seconds // flags WRITE_BYTE( BREAK_METAL ); MESSAGE_END(); // don't stop it we touch a entity pev->flags &= ~FL_ONGROUND; pev->nextthink = gpGlobals->time + 0.2; return; } else { Vector vecSpot = GetAbsOrigin() + (pev->mins + pev->maxs) * 0.5; /* MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY ); WRITE_BYTE( TE_EXPLOSION); // This just makes a dynamic light now WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z + 512 ); WRITE_SHORT( m_iExplode ); WRITE_BYTE( 250 ); // scale * 10 WRITE_BYTE( 10 ); // framerate MESSAGE_END(); */ // gibs MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_SPRITE ); WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z + 512 ); WRITE_SHORT( m_iExplode ); WRITE_BYTE( 250 ); // scale * 10 WRITE_BYTE( 255 ); // brightness MESSAGE_END(); /* MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY ); WRITE_BYTE( TE_SMOKE ); WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z + 300 ); WRITE_SHORT( g_sModelIndexSmoke ); WRITE_BYTE( 250 ); // scale * 10 WRITE_BYTE( 6 ); // framerate MESSAGE_END(); */ Vector vecOrigin = GetAbsOrigin(); // blast circle MESSAGE_BEGIN( MSG_PAS, SVC_TEMPENTITY, vecOrigin ); WRITE_BYTE( TE_BEAMCYLINDER ); WRITE_COORD( vecOrigin.x); WRITE_COORD( vecOrigin.y); WRITE_COORD( vecOrigin.z); WRITE_COORD( vecOrigin.x); WRITE_COORD( vecOrigin.y); WRITE_COORD( vecOrigin.z + 2000 ); // reach damage radius over .2 seconds WRITE_SHORT( m_iSpriteTexture ); WRITE_BYTE( 0 ); // startframe WRITE_BYTE( 0 ); // framerate WRITE_BYTE( 4 ); // life WRITE_BYTE( 32 ); // width WRITE_BYTE( 0 ); // noise WRITE_BYTE( 255 ); // r, g, b WRITE_BYTE( 255 ); // r, g, b WRITE_BYTE( 192 ); // r, g, b WRITE_BYTE( 128 ); // brightness WRITE_BYTE( 0 ); // speed MESSAGE_END(); EMIT_SOUND(ENT(pev), CHAN_STATIC, "weapons/mortarhit.wav", 1.0, 0.3); RadiusDamage( vecOrigin, pev, pev, 300, CLASS_NONE, DMG_BLAST ); // gibs vecSpot = vecOrigin + (pev->mins + pev->maxs) * 0.5; MESSAGE_BEGIN( MSG_PAS, SVC_TEMPENTITY, vecSpot ); WRITE_BYTE( TE_BREAKMODEL); // position WRITE_COORD( vecSpot.x ); WRITE_COORD( vecSpot.y ); WRITE_COORD( vecSpot.z + 64); // size WRITE_COORD( 800 ); WRITE_COORD( 800 ); WRITE_COORD( 128 ); // velocity WRITE_COORD( m_velocity.x ); WRITE_COORD( m_velocity.y ); WRITE_COORD( fabs( m_velocity.z ) * 0.25 ); // randomization WRITE_BYTE( 40 ); // Model WRITE_SHORT( m_iBodyGibs ); //model id# // # of shards WRITE_BYTE( 128 ); // duration WRITE_BYTE( 200 );// 10.0 seconds // flags WRITE_BYTE( BREAK_METAL ); MESSAGE_END(); UTIL_Remove( this ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPropAPC::Event_Killed( const CTakeDamageInfo &info ) { m_OnDeath.FireOutput( info.GetAttacker(), this ); Vector vecAbsMins, vecAbsMaxs; CollisionProp()->WorldSpaceAABB( &vecAbsMins, &vecAbsMaxs ); Vector vecNormalizedMins, vecNormalizedMaxs; CollisionProp()->WorldToNormalizedSpace( vecAbsMins, &vecNormalizedMins ); CollisionProp()->WorldToNormalizedSpace( vecAbsMaxs, &vecNormalizedMaxs ); Vector vecAbsPoint; CPASFilter filter( GetAbsOrigin() ); for (int i = 0; i < 5; i++) { CollisionProp()->RandomPointInBounds( vecNormalizedMins, vecNormalizedMaxs, &vecAbsPoint ); te->Explosion( filter, random->RandomFloat( 0.0, 1.0 ), &vecAbsPoint, g_sModelIndexFireball, random->RandomInt( 4, 10 ), random->RandomInt( 8, 15 ), ( i < 2 ) ? TE_EXPLFLAG_NODLIGHTS : TE_EXPLFLAG_NOPARTICLES | TE_EXPLFLAG_NOFIREBALLSMOKE | TE_EXPLFLAG_NODLIGHTS, 100, 0 ); } // TODO: make the gibs spawn in sync with the delayed explosions int nGibs = random->RandomInt( 1, 4 ); for ( int i = 0; i < nGibs; i++) { // Throw a flaming, smoking chunk. CGib *pChunk = CREATE_ENTITY( CGib, "gib" ); pChunk->Spawn( "models/gibs/hgibs.mdl" ); pChunk->SetBloodColor( DONT_BLEED ); QAngle vecSpawnAngles; vecSpawnAngles.Random( -90, 90 ); pChunk->SetAbsOrigin( vecAbsPoint ); pChunk->SetAbsAngles( vecSpawnAngles ); int nGib = random->RandomInt( 0, APC_MAX_CHUNKS - 1 ); pChunk->Spawn( s_pChunkModelName[nGib] ); pChunk->SetOwnerEntity( this ); pChunk->m_lifeTime = random->RandomFloat( 6.0f, 8.0f ); pChunk->SetCollisionGroup( COLLISION_GROUP_DEBRIS ); IPhysicsObject *pPhysicsObject = pChunk->VPhysicsInitNormal( SOLID_VPHYSICS, pChunk->GetSolidFlags(), false ); // Set the velocity if ( pPhysicsObject ) { pPhysicsObject->EnableMotion( true ); Vector vecVelocity; QAngle angles; angles.x = random->RandomFloat( -20, 20 ); angles.y = random->RandomFloat( 0, 360 ); angles.z = 0.0f; AngleVectors( angles, &vecVelocity ); vecVelocity *= random->RandomFloat( 300, 900 ); vecVelocity += GetAbsVelocity(); AngularImpulse angImpulse; angImpulse = RandomAngularImpulse( -180, 180 ); pChunk->SetAbsVelocity( vecVelocity ); pPhysicsObject->SetVelocity(&vecVelocity, &angImpulse ); } CEntityFlame *pFlame = CEntityFlame::Create( pChunk, false ); if ( pFlame != NULL ) { pFlame->SetLifetime( pChunk->m_lifeTime ); } } UTIL_ScreenShake( vecAbsPoint, 25.0, 150.0, 1.0, 750.0f, SHAKE_START ); if( hl2_episodic.GetBool() ) { // EP1 perf hit Ignite( 6, false ); } else { Ignite( 60, false ); } m_lifeState = LIFE_DYING; // Spawn a lesser amount if the player is close m_iRocketSalvoLeft = DEATH_VOLLEY_ROCKET_COUNT; m_flRocketTime = gpGlobals->curtime; }
//----------------------------------------------------------------------------- // Purpose: // Input : *pOther - //----------------------------------------------------------------------------- void CCrossbowBolt::BoltTouch( CBaseEntity *pOther ) { if ( !pOther->IsSolid() || pOther->IsSolidFlagSet(FSOLID_VOLUME_CONTENTS) ) return; if ( pOther->m_takedamage != DAMAGE_NO ) { trace_t tr, tr2; tr = BaseClass::GetTouchTrace(); Vector vecNormalizedVel = GetAbsVelocity(); ClearMultiDamage(); VectorNormalize( vecNormalizedVel ); if( GetOwnerEntity() && GetOwnerEntity()->IsPlayer() && pOther->IsNPC() ) { CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), m_iDamage, DMG_NEVERGIB ); dmgInfo.AdjustPlayerDamageInflictedForSkillLevel(); CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f ); dmgInfo.SetDamagePosition( tr.endpos ); pOther->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr ); } else { CTakeDamageInfo dmgInfo( this, GetOwnerEntity(), m_iDamage, DMG_BULLET | DMG_NEVERGIB ); CalculateMeleeDamageForce( &dmgInfo, vecNormalizedVel, tr.endpos, 0.7f ); dmgInfo.SetDamagePosition( tr.endpos ); pOther->DispatchTraceAttack( dmgInfo, vecNormalizedVel, &tr ); } ApplyMultiDamage(); //Adrian: keep going through the glass. if ( pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS ) return; SetAbsVelocity( Vector( 0, 0, 0 ) ); // play body "thwack" sound EmitSound( "Weapon_Crossbow.BoltHitBody" ); Vector vForward; AngleVectors( GetAbsAngles(), &vForward ); VectorNormalize ( vForward ); UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + vForward * 128, MASK_OPAQUE, pOther, COLLISION_GROUP_NONE, &tr2 ); if ( tr2.fraction != 1.0f ) { // NDebugOverlay::Box( tr2.endpos, Vector( -16, -16, -16 ), Vector( 16, 16, 16 ), 0, 255, 0, 0, 10 ); // NDebugOverlay::Box( GetAbsOrigin(), Vector( -16, -16, -16 ), Vector( 16, 16, 16 ), 0, 0, 255, 0, 10 ); if ( tr2.m_pEnt == NULL || ( tr2.m_pEnt && tr2.m_pEnt->GetMoveType() == MOVETYPE_NONE ) ) { CEffectData data; data.m_vOrigin = tr2.endpos; data.m_vNormal = vForward; data.m_nEntIndex = tr2.fraction != 1.0f; DispatchEffect( "BoltImpact", data ); } } SetTouch( NULL ); SetThink( NULL ); UTIL_Remove( this ); } else { trace_t tr; tr = BaseClass::GetTouchTrace(); // See if we struck the world if ( pOther->GetMoveType() == MOVETYPE_NONE && !( tr.surface.flags & SURF_SKY ) ) { EmitSound( "Weapon_Crossbow.BoltHitWorld" ); // if what we hit is static architecture, can stay around for a while. Vector vecDir = GetAbsVelocity(); float speed = VectorNormalize( vecDir ); // See if we should reflect off this surface float hitDot = DotProduct( tr.plane.normal, -vecDir ); if ( ( hitDot < 0.5f ) && ( speed > 100 ) ) { Vector vReflection = 2.0f * tr.plane.normal * hitDot + vecDir; QAngle reflectAngles; VectorAngles( vReflection, reflectAngles ); SetLocalAngles( reflectAngles ); SetAbsVelocity( vReflection * speed * 0.75f ); // Start to sink faster SetGravity( 1.0f ); } else { SetThink( &CCrossbowBolt::SUB_Remove ); SetNextThink( gpGlobals->curtime + 2.0f ); //FIXME: We actually want to stick (with hierarchy) to what we've hit SetMoveType( MOVETYPE_NONE ); Vector vForward; AngleVectors( GetAbsAngles(), &vForward ); VectorNormalize ( vForward ); CEffectData data; data.m_vOrigin = tr.endpos; data.m_vNormal = vForward; data.m_nEntIndex = 0; DispatchEffect( "BoltImpact", data ); UTIL_ImpactTrace( &tr, DMG_BULLET ); AddEffects( EF_NODRAW ); SetTouch( NULL ); SetThink( &CCrossbowBolt::SUB_Remove ); SetNextThink( gpGlobals->curtime + 2.0f ); if ( m_pGlowSprite != NULL ) { m_pGlowSprite->TurnOn(); m_pGlowSprite->FadeAndDie( 3.0f ); } } // Shoot some sparks if ( UTIL_PointContents( GetAbsOrigin() ) != CONTENTS_WATER) { g_pEffects->Sparks( GetAbsOrigin() ); } } else { // Put a mark unless we've hit the sky if ( ( tr.surface.flags & SURF_SKY ) == false ) { UTIL_ImpactTrace( &tr, DMG_BULLET ); } UTIL_Remove( this ); } } if ( g_pGameRules->IsMultiplayer() ) { // SetThink( &CCrossbowBolt::ExplodeThink ); // SetNextThink( gpGlobals->curtime + 0.1f ); } }
void CASW_Grenade_PRifle::Detonate() { if ( !ASWGameResource() ) return; m_takedamage = DAMAGE_NO; CPASFilter filter( GetAbsOrigin() ); Vector vecForward = GetAbsVelocity(); VectorNormalize(vecForward); trace_t tr; Vector vecDir = -vecForward; //te->GaussExplosion( filter, 0.0, //GetAbsOrigin(), vecDir, 0 ); CEffectData data; data.m_vOrigin = GetAbsOrigin(); DispatchEffect( "aswstunexplo", data ); EmitSound("ASW_Weapon_PRifle.StunGrenadeExplosion"); UTIL_TraceLine ( GetAbsOrigin(), GetAbsOrigin() + 60*vecForward, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr); if ((tr.m_pEnt != GetWorldEntity()) || (tr.hitbox != 0)) { // non-world needs smaller decals if( tr.m_pEnt && !tr.m_pEnt->IsNPC() ) { UTIL_DecalTrace( &tr, "SmallScorch" ); } } else { UTIL_DecalTrace( &tr, "Scorch" ); } UTIL_ASW_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START ); int nPreviousStunnedAliens = ASWGameResource()->m_iElectroStunnedAliens; // do just 1 damage... CTakeDamageInfo info( this, GetOwnerEntity(), 1, DMG_SHOCK ); info.SetWeapon( m_hCreatorWeapon ); RadiusDamage ( info , GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL ); // count as a shot fired CASW_Marine *pMarine = dynamic_cast<CASW_Marine*>(GetOwnerEntity()); if ( pMarine && pMarine->GetMarineResource() ) { CASW_Marine_Resource *pMR = pMarine->GetMarineResource(); pMR->UsedWeapon(NULL, 1); int nAliensStunned = ASWGameResource()->m_iElectroStunnedAliens - nPreviousStunnedAliens; if ( nAliensStunned >= 6 && pMR->IsInhabited() && pMR->GetCommander() ) { pMR->GetCommander()->AwardAchievement( ACHIEVEMENT_ASW_STUN_GRENADE ); pMR->m_bStunGrenadeMedal = true; } } UTIL_Remove( this ); }
void CGrenade::BounceTouch( CBaseEntity *pOther ) { // don't hit the guy that launched this grenade if ( pOther->edict() == pev->owner ) return; // only do damage if we're moving fairly fast if( m_flNextAttack < gpGlobals->time && GetAbsVelocity().Length() > 100 ) { entvars_t *pevOwner = VARS( pev->owner ); if( pevOwner ) { TraceResult tr = UTIL_GetGlobalTrace( ); ClearMultiDamage( ); pOther->TraceAttack( pevOwner, 1, gpGlobals->v_forward, &tr, DMG_CLUB ); ApplyMultiDamage( pev, pevOwner ); } m_flNextAttack = gpGlobals->time + 1.0; // debounce } Vector vecTestVelocity; // this is my heuristic for modulating the grenade velocity because grenades dropped purely vertical // or thrown very far tend to slow down too quickly for me to always catch just by testing velocity. // trimming the Z velocity a bit seems to help quite a bit. vecTestVelocity = GetAbsVelocity(); vecTestVelocity.z *= 0.45; if( !m_fRegisteredSound && vecTestVelocity.Length() <= 60 ) { //ALERT( at_console, "Grenade Registered!: %f\n", vecTestVelocity.Length() ); // grenade is moving really slow. It's probably very close to where it will ultimately stop moving. // go ahead and emit the danger sound. // register a radius louder than the explosion, so we make sure everyone gets out of the way CSoundEnt::InsertSound ( bits_SOUND_DANGER, GetAbsOrigin(), pev->dmg / 0.4, 0.3 ); m_fRegisteredSound = TRUE; } if( pev->flags & FL_ONGROUND ) { // add a bit of static friction Vector vecVelocity = GetAbsVelocity(); vecVelocity *= 0.8f; SetAbsVelocity( vecVelocity ); pev->sequence = RANDOM_LONG( 1, 1 ); } else { // play bounce sound BounceSound(); } pev->framerate = GetAbsVelocity().Length() / 200.0; if( pev->framerate > 1.0 ) pev->framerate = 1; else if( pev->framerate < 0.5 ) pev->framerate = 0; }
bool CBliinkPlayer::IsSprinting( void ) { float flVelSqr = GetAbsVelocity().LengthSqr(); return m_Shared.m_bIsSprinting && ( flVelSqr > 0.5f ); }
//----------------------------------------------------------------------------- // Purpose: Called every frame when the door is blocked while opening or closing. // Input : pOther - The blocking entity. //----------------------------------------------------------------------------- void CBaseDoor::Blocked( CBaseEntity *pOther ) { // Hurt the blocker a little. if ( m_flBlockDamage ) { // if the door is marked "force closed" or it has a negative wait, then there's nothing to do but // push/damage the object. // If block damage is set, but this object is a physics prop that can't be damaged, just // give up and disable collisions if ( (m_bForceClosed || m_flWait < 0) && pOther->GetMoveType() == MOVETYPE_VPHYSICS && (pOther->m_takedamage == DAMAGE_NO || pOther->m_takedamage == DAMAGE_EVENTS_ONLY) ) { EntityPhysics_CreateSolver( this, pOther, true, 4.0f ); } else { pOther->TakeDamage( CTakeDamageInfo( this, this, m_flBlockDamage, DMG_CRUSH ) ); } } // If we're set to force ourselves closed, keep going if ( m_bForceClosed ) return; // if a door has a negative wait, it would never come back if blocked, // so let it just squash the object to death real fast if (m_flWait >= 0) { if (m_toggle_state == TS_GOING_DOWN) { DoorGoUp(); } else { DoorGoDown(); } } // Block all door pieces with the same targetname here. if ( GetEntityName() != NULL_STRING ) { CBaseDoor *pDoorList[64]; int doorCount = GetDoorMovementGroup( pDoorList, ARRAYSIZE(pDoorList) ); for ( int i = 0; i < doorCount; i++ ) { CBaseDoor *pDoor = pDoorList[i]; if ( pDoor->m_flWait >= 0) { if (m_bDoorGroup && pDoor->m_vecMoveDir == m_vecMoveDir && pDoor->GetAbsVelocity() == GetAbsVelocity() && pDoor->GetLocalAngularVelocity() == GetLocalAngularVelocity()) { pDoor->m_nSimulationTick = m_nSimulationTick; // don't run simulation this frame if you haven't run yet // this is the most hacked, evil, bastardized thing I've ever seen. kjb if ( !pDoor->IsRotatingDoor() ) {// set origin to realign normal doors pDoor->SetLocalOrigin( GetLocalOrigin() ); pDoor->SetAbsVelocity( vec3_origin );// stop! } else {// set angles to realign rotating doors pDoor->SetLocalAngles( GetLocalAngles() ); pDoor->SetLocalAngularVelocity( vec3_angle ); } } if ( pDoor->m_toggle_state == TS_GOING_DOWN) pDoor->DoorGoUp(); else pDoor->DoorGoDown(); } } } }