int CGERocket::OnTakeDamage( const CTakeDamageInfo &inputInfo ) { if ( m_takedamage == DAMAGE_NO ) return 0; // Manually apply vphysics because BaseCombatCharacter takedamage doesn't call back to CBaseEntity OnTakeDamage VPhysicsTakeDamage( inputInfo ); // Rockets take Blast AND Bullet damage, though blast damage requires more. if ((inputInfo.GetDamageType() & DMG_BLAST && inputInfo.GetDamage() > 80) || inputInfo.GetDamageType() & DMG_BULLET) { m_iHealth -= inputInfo.GetDamage(); if (m_iHealth <= 0) { if (inputInfo.GetAttacker()->IsPlayer()) { SetThrower(inputInfo.GetAttacker()->MyCombatCharacterPointer()); } else if (inputInfo.GetAttacker()->IsNPC()) { CNPC_GEBase *npc = (CNPC_GEBase*)inputInfo.GetAttacker(); if (npc->GetBotPlayer()) SetThrower(npc->GetBotPlayer()); } Explode(); } return inputInfo.GetDamage(); } return 0; }
int CGEGrenade::OnTakeDamage( const CTakeDamageInfo &inputInfo ) { if ( m_takedamage == DAMAGE_NO ) return 0; // Manually apply vphysics because BaseCombatCharacter takedamage doesn't call back to CBaseEntity OnTakeDamage VPhysicsTakeDamage( inputInfo ); // Grenades take Blast AND Bullet damage if ((inputInfo.GetDamage() > 160 && inputInfo.GetDamageType() & DMG_BLAST) || inputInfo.GetDamageType() & DMG_BULLET) { // Bullet damage transfers ownership to the attacker instead of the thrower m_iHealth -= inputInfo.GetDamage(); if ( m_iHealth <= 0 ) { if ( inputInfo.GetAttacker()->IsPlayer() ) { SetThrower( inputInfo.GetAttacker()->MyCombatCharacterPointer() ); } else if ( inputInfo.GetAttacker()->IsNPC() ) { CNPC_GEBase *npc = (CNPC_GEBase*) inputInfo.GetAttacker(); if ( npc->GetBotPlayer() ) SetThrower( npc->GetBotPlayer() ); } Explode(); } return inputInfo.GetDamage(); } return 0; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFWeaponBaseGrenadeProj::Deflected( CBaseEntity *pDeflectedBy, Vector &vecDir ) { IPhysicsObject *pPhysicsObject = VPhysicsGetObject(); if ( pPhysicsObject ) { Vector vecOldVelocity, vecVelocity; pPhysicsObject->GetVelocity( &vecOldVelocity, NULL ); float flVel = vecOldVelocity.Length(); vecVelocity = vecDir; vecVelocity *= flVel; AngularImpulse angVelocity( ( 600, random->RandomInt( -1200, 1200 ), 0 ) ); // Now change grenade's direction. pPhysicsObject->SetVelocityInstantaneous( &vecVelocity, &angVelocity ); } CBaseCombatCharacter *pBCC = pDeflectedBy->MyCombatCharacterPointer(); IncremenentDeflected(); m_hDeflectOwner = pDeflectedBy; SetThrower( pBCC ); ChangeTeam( pDeflectedBy->GetTeamNumber() ); if ( !TFGameRules()->IsDeathmatch() ) m_nSkin = pDeflectedBy->GetTeamNumber() - 2; // TODO: Live TF2 adds white trail to reflected pipes and stickies. We need one as well. }
void CGrenadeFrag::OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason ) { #ifdef HL2MP SetTimer( FRAG_GRENADE_GRACE_TIME_AFTER_PICKUP, FRAG_GRENADE_GRACE_TIME_AFTER_PICKUP / 2); SetThrower( pPhysGunUser ); BlipSound(); m_flNextBlipTime = gpGlobals->curtime + FRAG_GRENADE_BLIP_FAST_FREQUENCY; m_bHasWarnedAI = true; #endif #ifdef HL2_EPISODIC SetThrower( pPhysGunUser ); SetPunted( true ); #endif BaseClass::OnPhysGunPickup( pPhysGunUser, reason ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFWeaponBaseGrenadeProj::InitGrenade( const Vector &velocity, const AngularImpulse &angVelocity, CBaseCombatCharacter *pOwner, const CTFWeaponInfo &weaponInfo ) { // We can't use OwnerEntity for grenades, because then the owner can't shoot them with his hitscan weapons (due to collide rules) // Thrower is used to store the person who threw the grenade, for damage purposes. SetOwnerEntity( NULL ); SetThrower( pOwner ); SetupInitialTransmittedGrenadeVelocity( velocity ); SetGravity( 0.4f/*BaseClass::GetGrenadeGravity()*/ ); SetFriction( 0.2f/*BaseClass::GetGrenadeFriction()*/ ); SetElasticity( 0.45f/*BaseClass::GetGrenadeElasticity()*/ ); SetDamage( weaponInfo.GetWeaponData( TF_WEAPON_PRIMARY_MODE ).m_nDamage ); SetDamageRadius( weaponInfo.m_flDamageRadius ); ChangeTeam( pOwner->GetTeamNumber() ); IPhysicsObject *pPhysicsObject = VPhysicsGetObject(); if ( pPhysicsObject ) { pPhysicsObject->AddVelocity( &velocity, &angVelocity ); } }