//=============================================================================================================== // Power Projectile //=============================================================================================================== //----------------------------------------------------------------------------- // Purpose: Create a power projectile //----------------------------------------------------------------------------- CPowerPlasmaProjectile *CPowerPlasmaProjectile::Create( const Vector &vecOrigin, const Vector &vecForward, int damageType, CBaseEntity *pOwner = NULL ) { CPowerPlasmaProjectile *pMissile = (CPowerPlasmaProjectile*)CreateEntityByName("powerplasmaprojectile"); pMissile->SetupProjectile( vecOrigin, vecForward, damageType, pOwner ); pMissile->SetPower( 1.0 ); return pMissile; }
CPowerPlasmaProjectile *CPowerPlasmaProjectile::CreatePredicted( const Vector &vecOrigin, const Vector &vecForward, const Vector& gunOffset, int damageType, CBasePlayer *pOwner ) { CPowerPlasmaProjectile *pMissile = (CPowerPlasmaProjectile*)CREATE_PREDICTED_ENTITY("powerplasmaprojectile"); if ( pMissile ) { pMissile->SetOwnerEntity( pOwner ); pMissile->SetPlayerSimulated( pOwner ); pMissile->SetupProjectile( vecOrigin, vecForward, damageType, pOwner ); pMissile->SetPower( 1.0 ); pMissile->m_vecGunOriginOffset = gunOffset; } return pMissile; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponCombatBurstRifle::PrimaryAttack( void ) { CBaseTFPlayer *pPlayer = (CBaseTFPlayer*)GetOwner(); if (!pPlayer) return; WeaponSound(SINGLE); // Fire the bullets Vector vecSrc = pPlayer->Weapon_ShootPosition( ); Vector vecSpread = GetBulletSpread(); Vector vecAiming, vecRight, vecUp; pPlayer->EyeVectors( &vecAiming, &vecRight, &vecUp ); // Add some inaccuracy int seed = 0; float x, y, z; do { float x1, x2, y1, y2; // Note the additional seed because otherwise we get the same set of random #'s and will get stuck // in an infinite loop here potentially // FIXME: Can we use a gaussian random # function instead? ywb x1 = SHARED_RANDOMFLOAT_SEED( -0.5, 0.5, ++seed ); x2 = SHARED_RANDOMFLOAT_SEED( -0.5, 0.5, ++seed ); y1 = SHARED_RANDOMFLOAT_SEED( -0.5, 0.5, ++seed ); y2 = SHARED_RANDOMFLOAT_SEED( -0.5, 0.5, ++seed ); x = x1 + x2; y = y1 + y2; z = x*x+y*y; } while (z > 1); Vector vecDir = vecAiming + x * vecSpread.x * vecRight + y * vecSpread.y * vecUp; PlayAttackAnimation( GetPrimaryAttackActivity() ); // Shift it down a bit so the firer can see it Vector right, forward; AngleVectors( pPlayer->EyeAngles() + pPlayer->m_Local.m_vecPunchAngle, &forward, &right, NULL ); Vector vecStartSpot = vecSrc; // Get the firing position #ifdef CLIENT_DLL // On our client, grab the viewmodel's firing position Vector vecWorldOffset = vecStartSpot + Vector(0,0,-8) + right * 12 + forward * 16; #else // For everyone else, grab the weapon model's position /* Vector vecWorldOffset; QAngle angIgnore; GetAttachment( LookupAttachment( "muzzle" ), vecWorldOffset, angIgnore ); */ Vector vecWorldOffset = vecStartSpot + Vector(0,0,-8) + right * 12 + forward * 16; #endif Vector gunOffset = vecWorldOffset - vecStartSpot; CPowerPlasmaProjectile *pPlasma = CPowerPlasmaProjectile::CreatePredicted( vecStartSpot, vecDir, gunOffset, DMG_ENERGYBEAM, pPlayer ); if ( pPlasma ) { pPlasma->SetDamage( weapon_combat_burstrifle_damage.GetFloat() ); pPlasma->m_hOwner = pPlayer; pPlasma->SetPower( 2.0 ); pPlasma->SetMaxRange( weapon_combat_burstrifle_range.GetFloat() ); pPlasma->Activate(); } m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate(); m_iClip1 = m_iClip1 - 1; }