void CFuncTankGun::Fire( int bulletCount, const Vector &barrelEnd, const Vector &forward, CBaseEntity *pAttacker ) { int i; for ( i = 0; i < bulletCount; i++ ) { switch( m_bulletType ) { case TANK_BULLET_SMALL: FireBullets( 1, barrelEnd, forward, gTankSpread[m_spread], MAX_TRACE_LENGTH, m_iSmallAmmoType, 1, -1, -1, m_iBulletDamage, pAttacker ); break; case TANK_BULLET_MEDIUM: FireBullets( 1, barrelEnd, forward, gTankSpread[m_spread], MAX_TRACE_LENGTH, m_iMediumAmmoType, 1, -1, -1, m_iBulletDamage, pAttacker ); break; case TANK_BULLET_LARGE: FireBullets( 1, barrelEnd, forward, gTankSpread[m_spread], MAX_TRACE_LENGTH, m_iLargeAmmoType, 1, -1, -1, m_iBulletDamage, pAttacker ); break; default: case TANK_BULLET_NONE: break; } } CFuncTank::Fire( bulletCount, barrelEnd, forward, pAttacker ); }
void CFuncTankGun::Fire(const Vector &barrelEnd, const Vector &forward, entvars_t *pevAttacker) { if (m_fireLast != 0) { UTIL_MakeAimVectors(pev->angles); int bulletCount = (int)((gpGlobals->time - m_fireLast) * m_fireRate); if (bulletCount > 0) { for (int i = 0; i < bulletCount; i++) { switch (m_bulletType) { case TANK_BULLET_9MM: FireBullets(1, barrelEnd, forward, gTankSpread[m_spread], 4096, BULLET_MONSTER_9MM, 1, m_iBulletDamage, pevAttacker); break; case TANK_BULLET_MP5: FireBullets(1, barrelEnd, forward, gTankSpread[m_spread], 4096, BULLET_MONSTER_MP5, 1, m_iBulletDamage, pevAttacker); break; case TANK_BULLET_12MM: FireBullets(1, barrelEnd, forward, gTankSpread[m_spread], 4096, BULLET_MONSTER_12MM, 1, m_iBulletDamage, pevAttacker); break; default: case TANK_BULLET_NONE: break; } } CFuncTank::Fire(barrelEnd, forward, pevAttacker); } } else CFuncTank::Fire(barrelEnd, forward, pevAttacker); }
//========================================================= // BarneyFirePistol - shoots one round from the pistol at // the enemy barney is facing. //========================================================= void CFriend :: BarneyFirePistol ( void ) { Vector vecShootOrigin; UTIL_MakeVectors(pev->angles); vecShootOrigin = pev->origin + Vector( 0, 0, 55 ); Vector vecShootDir = ShootAtEnemy( vecShootOrigin ); Vector angDir = UTIL_VecToAngles( vecShootDir ); SetBlending( 0, angDir.x ); pev->effects = EF_MUZZLEFLASH; if (pev->frags) { FireBullets(8, vecShootOrigin, vecShootDir, VECTOR_CONE_10DEGREES, 1024, BULLET_PLAYER_BUCKSHOT);//357 EMIT_SOUND( ENT(pev), CHAN_WEAPON, "weapons/shotgun/sbarrel1.wav", 1, ATTN_NORM ); } else { FireBullets(1, vecShootOrigin, vecShootDir, VECTOR_CONE_2DEGREES, 1024, BULLET_MONSTER_9MM ); int pitchShift = RANDOM_LONG( 0, 20 ); // Only shift about half the time if ( pitchShift > 10 ) pitchShift = 0; else pitchShift -= 5; EMIT_SOUND( ENT(pev), CHAN_WEAPON, "weapons/m16/m16_fire-1.wav", 1, ATTN_NORM ); } CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, 384, 0.3 ); // UNDONE: Reload? m_cAmmoLoaded--;// take away a bullet! // Teh_Freak: World Lighting! MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY ); WRITE_BYTE( TE_DLIGHT ); WRITE_COORD( vecShootOrigin.x ); // origin WRITE_COORD( vecShootOrigin.y ); WRITE_COORD( vecShootOrigin.z ); WRITE_BYTE( 16 ); // radius WRITE_BYTE( 255 ); // R WRITE_BYTE( 255 ); // G WRITE_BYTE( 128 ); // B WRITE_BYTE( 0 ); // life * 10 WRITE_BYTE( 0 ); // decay MESSAGE_END(); // Teh_Freak: World Lighting! CBaseEntity *pPlayer = UTIL_PlayerByIndex( 1 ); if (pPlayer->m_fSlowMotionOn) CBullet::Shoot( pev, vecShootOrigin, vecShootDir * 500 ); }
//----------------------------------------------------------------------------- // Purpose: // Input : pEvent - //----------------------------------------------------------------------------- void CNPC_Monk::HandleAnimEvent( animevent_t *pEvent ) { switch ( pEvent->event ) { case AE_MONK_FIRE_GUN: { Vector vecShootOrigin; QAngle vecAngles; GetAttachment( "muzzle", vecShootOrigin, vecAngles ); Vector vecShootDir = GetShootEnemyDir( vecShootOrigin ); CPASAttenuationFilter filter2( this, "NPC_Monk.Fire" ); EmitSound( filter2, entindex(), "NPC_Monk.Fire" ); UTIL_Smoke( vecShootOrigin, random->RandomInt(20, 30), 10 ); FireBullets( 1, vecShootOrigin, vecShootDir, vec3_origin, MAX_TRACE_LENGTH, m_nAmmoType, 0 ); m_fEffects |= EF_MUZZLEFLASH; break; } default: { BaseClass::HandleAnimEvent( pEvent ); } } }
//----------------------------------------------------------------------------- // Purpose: // Input : hand - //----------------------------------------------------------------------------- void CNPC_Assassin::FirePistol( int hand ) { if ( m_flNextShotTime > gpGlobals->curtime ) return; m_flNextShotTime = gpGlobals->curtime + random->RandomFloat( 0.05f, 0.15f ); Vector muzzlePos; QAngle muzzleAngle; const char *handName = ( hand ) ? "LeftMuzzle" : "RightMuzzle"; GetAttachment( handName, muzzlePos, muzzleAngle ); Vector muzzleDir; if ( GetEnemy() == NULL ) { AngleVectors( muzzleAngle, &muzzleDir ); } else { muzzleDir = GetEnemy()->BodyTarget( muzzlePos ) - muzzlePos; VectorNormalize( muzzleDir ); } int bulletType = GetAmmoDef()->Index( "Pistol" ); FireBullets( 1, muzzlePos, muzzleDir, VECTOR_CONE_5DEGREES, 1024, bulletType, 2 ); UTIL_MuzzleFlash( muzzlePos, muzzleAngle, 0.5f, 1 ); CPASAttenuationFilter filter( this ); EmitSound( filter, entindex(), "NPC_Assassin.ShootPistol" ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPropAPC::FireMachineGun( void ) { if ( m_flMachineGunTime > gpGlobals->curtime ) return; // If we're still firing the salvo, fire quickly m_iMachineGunBurstLeft--; if ( m_iMachineGunBurstLeft > 0 ) { m_flMachineGunTime = gpGlobals->curtime + MACHINE_GUN_BURST_TIME; } else { // Reload the salvo m_iMachineGunBurstLeft = MACHINE_GUN_BURST_SIZE; m_flMachineGunTime = gpGlobals->curtime + MACHINE_GUN_BURST_PAUSE_TIME; } Vector vecMachineGunShootPos; Vector vecMachineGunDir; GetAttachment( m_nMachineGunMuzzleAttachment, vecMachineGunShootPos, &vecMachineGunDir ); // Fire the round int bulletType = GetAmmoDef()->Index("AR2"); FireBullets( 1, vecMachineGunShootPos, vecMachineGunDir, VECTOR_CONE_8DEGREES, MAX_TRACE_LENGTH, bulletType, 1 ); DoMuzzleFlash(); EmitSound( "Weapon_AR2.Single" ); }
//========================================================= // BarneyFirePistol - shoots one round from the pistol at // the enemy barney is facing. //========================================================= void CBarney :: BarneyFirePistol ( void ) { Vector vecShootOrigin; UTIL_MakeVectors(pev->angles); vecShootOrigin = pev->origin + Vector( 0, 0, 55 ); Vector vecShootDir = ShootAtEnemy( vecShootOrigin ); Vector angDir = UTIL_VecToAngles( vecShootDir ); SetBlending( 0, angDir.x ); pev->effects = EF_MUZZLEFLASH; FireBullets(1, vecShootOrigin, vecShootDir, VECTOR_CONE_2DEGREES, 1024, BULLET_MONSTER_9MM ); int pitchShift = RANDOM_LONG( 0, 20 ); // Only shift about half the time if ( pitchShift > 10 ) pitchShift = 0; else pitchShift -= 5; EMIT_SOUND_DYN( ENT(pev), CHAN_WEAPON, "barney/ba_attack2.wav", 1, ATTN_NORM, 0, 100 + pitchShift ); CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, 384, 0.3 ); // UNDONE: Reload? m_cAmmoLoaded--;// take away a bullet! }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPropAirboat::FireGun( void ) { // Trace from eyes and see what we hit. Vector vecEyeDirection; m_hPlayer->EyeVectors( &vecEyeDirection, NULL, NULL ); Vector vecEndPos = m_hPlayer->EyePosition() + ( vecEyeDirection * MAX_TRACE_LENGTH ); trace_t trace; UTIL_TraceLine( m_hPlayer->EyePosition(), vecEndPos, MASK_SHOT, this, COLLISION_GROUP_NONE, &trace ); if ( trace.m_pEnt ) { // Get the gun position. Vector vecGunPosition; QAngle vecGunAngles; GetAttachment( LookupAttachment( "gun_barrel" ), vecGunPosition, vecGunAngles ); // Get a ray from the gun to the target. Vector vecRay = trace.endpos - vecGunPosition; VectorNormalize( vecRay ); CAmmoDef *pAmmoDef = GetAmmoDef(); int ammoType = pAmmoDef->Index( "MediumRound" ); FireBullets( 1, vecGunPosition, vecRay, vec3_origin, 4096, ammoType ); } }
//--------------------------------------------------------- // This starts the bullet state machine. The actual effects // of the bullet will happen later. This function schedules // those effects. // // fDirectShot indicates whether the bullet is a "direct shot" // that is - fired with the intent that it will strike the // enemy. Otherwise, the bullet is intended to strike a // decoy object or nothing at all in particular. //--------------------------------------------------------- bool CNPC_Combine_Cannon::FireBullet( const Vector &vecTarget, bool bDirectShot ) { Vector vecBulletOrigin = GetBulletOrigin(); Vector vecDir = ( vecTarget - vecBulletOrigin ); VectorNormalize( vecDir ); FireBulletsInfo_t info; info.m_iShots = 1; info.m_iTracerFreq = 1; info.m_vecDirShooting = vecDir; info.m_vecSrc = vecBulletOrigin; info.m_flDistance = MAX_TRACE_LENGTH; info.m_pAttacker = this; info.m_iAmmoType = m_iAmmoType; info.m_iPlayerDamage = 20; info.m_vecSpread = Vector( 0.015f, 0.015f, 0.015f ); // medium cone FireBullets( info ); EmitSound( "NPC_Combine_Cannon.FireBullet" ); // Don't attack for a certain amount of time SetNextAttack( gpGlobals->curtime + GetRefireTime() ); // Sniper had to be aiming here to fire here, so make it the cursor m_vecPaintCursor = vecTarget; LaserOff(); return true; }
void CCeilingTurret::Shoot(const Vector &vecSrc, const Vector &vecDirToEnemy) { //NDebugOverlay::Line( vecSrc, vecSrc + vecDirToEnemy * 512, 0, 255, 255, false, 0.1 ); FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, m_iAmmoType, 1 ); EmitSound( "CeilingTurret.Shoot" ); DoMuzzleFlash(); }
void CNPC_Sentry::Shoot(Vector &vecSrc, Vector &vecDirToEnemy) { FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, m_iAmmoType, 1 ); CPASAttenuationFilter filter( this ); EmitSound( filter, entindex(), "Sentry.Shoot" ); DoMuzzleFlash(); }
void World::Update(float dt) { if(mActive == true) { UpdateGameObjects(dt); SpawnEnemies(dt); FireBullets(); CheckCollision(); } }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CNPC_GroundTurret::Shoot() { FireBulletsInfo_t info; Vector vecSrc = EyePosition(); Vector vecDir; GetVectors( &vecDir, NULL, NULL ); for( int i = 0 ; i < 1 ; i++ ) { info.m_vecSrc = vecSrc; if( i > 0 || !GetEnemy()->IsPlayer() ) { // Subsequent shots or shots at non-players random GetVectors( &info.m_vecDirShooting, NULL, NULL ); info.m_vecSpread = m_vecSpread; } else { // First shot is at the enemy. info.m_vecDirShooting = GetActualShootTrajectory( vecSrc ); info.m_vecSpread = VECTOR_CONE_PRECALCULATED; } info.m_iTracerFreq = 1; info.m_iShots = 1; info.m_pAttacker = this; info.m_flDistance = MAX_COORD_RANGE; info.m_iAmmoType = m_iAmmoType; FireBullets( info ); } // Do the AR2 muzzle flash CEffectData data; data.m_nEntIndex = entindex(); data.m_nAttachmentIndex = LookupAttachment( "eyes" ); data.m_flScale = 1.0f; data.m_fFlags = MUZZLEFLASH_COMBINE; DispatchEffect( "MuzzleFlash", data ); EmitSound( "NPC_FloorTurret.ShotSounds", m_ShotSounds ); if( IsX360() ) { m_flTimeNextShoot = gpGlobals->curtime + 0.2; } else { m_flTimeNextShoot = gpGlobals->curtime + 0.09; } }
void CMiniTurret::Shoot(Vector &vecSrc, Vector &vecDirToEnemy) { FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_9MM, 1 ); switch(RANDOM_LONG(0,2)) { case 0: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/hks1.wav", 1, ATTN_NORM); break; case 1: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/hks2.wav", 1, ATTN_NORM); break; case 2: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/hks3.wav", 1, ATTN_NORM); break; } pev->effects = pev->effects | EF_MUZZLEFLASH; }
//----------------------------------------------------------------------------- // Purpose: Fire! //----------------------------------------------------------------------------- void CNPC_CeilingTurret::Shoot( const Vector &vecSrc, const Vector &vecDirToEnemy ) { if ( m_spawnflags & SF_CEILING_TURRET_OUT_OF_AMMO ) { EmitSound( "NPC_FloorTurret.DryFire"); EmitSound( "NPC_CeilingTurret.Activate" ); if ( RandomFloat( 0, 1 ) > 0.7 ) { m_flShotTime = gpGlobals->curtime + random->RandomFloat( 0.5, 1.5 ); } else { m_flShotTime = gpGlobals->curtime; } return; } FireBulletsInfo_t info; if ( GetEnemy() != NULL ) { Vector vecDir = GetActualShootTrajectory( vecSrc ); info.m_vecSrc = vecSrc; info.m_vecDirShooting = vecDir; info.m_iTracerFreq = 1; info.m_iShots = 1; info.m_pAttacker = this; info.m_vecSpread = VECTOR_CONE_PRECALCULATED; info.m_flDistance = MAX_COORD_RANGE; info.m_iAmmoType = m_iAmmoType; } else { // Just shoot where you're facing! Vector vecMuzzle, vecMuzzleDir; QAngle vecMuzzleAng; info.m_vecSrc = vecSrc; info.m_vecDirShooting = vecDirToEnemy; info.m_iTracerFreq = 1; info.m_iShots = 1; info.m_pAttacker = this; info.m_vecSpread = GetAttackSpread( NULL, NULL ); info.m_flDistance = MAX_COORD_RANGE; info.m_iAmmoType = m_iAmmoType; } FireBullets( info ); EmitSound( "NPC_CeilingTurret.ShotSounds" ); DoMuzzleFlash(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPropAPC2::FireMachineGun( void ) { if ( m_flMachineGunTime > gpGlobals->curtime ) return; // If we're still firing the salvo, fire quickly m_iMachineGunBurstLeft--; if ( m_iMachineGunBurstLeft > 0 ) { m_flMachineGunTime = gpGlobals->curtime + MACHINE_GUN_BURST_TIME; } else { // Reload the salvo m_iMachineGunBurstLeft = MACHINE_GUN_BURST_SIZE; m_flMachineGunTime = gpGlobals->curtime + MACHINE_GUN_BURST_PAUSE_TIME; } Vector vecMachineGunShootPos; QAngle vecMachineGunAngles; GetAttachment( m_nMachineGunMuzzleAttachment, vecMachineGunShootPos, vecMachineGunAngles ); Vector vecMachineGunDir; AngleVectors( vecMachineGunAngles, &vecMachineGunDir ); // Fire the round int bulletType = GetAmmoDef()->Index("StriderMiniGun"); FireBulletsInfo_t info; info.m_iShots = 1; info.m_vecSrc = vecMachineGunShootPos; info.m_vecDirShooting = vecMachineGunDir; info.m_vecSpread = VECTOR_CONE_8DEGREES; info.m_pAttacker = (CBaseEntity *) m_hPlayer; info.m_flDistance = MAX_TRACE_LENGTH; info.m_iAmmoType = bulletType; info.m_flDamage = 30; info.m_iPlayerDamage= 30; info.m_iTracerFreq = 1; FireBullets( info ); EntityMessageBegin( this, true ); WRITE_BYTE( APC_MSG_MACHINEGUN ); WRITE_VEC3COORD(vecMachineGunShootPos); WRITE_VEC3COORD(vecMachineGunDir); WRITE_VEC3COORD(VECTOR_CONE_8DEGREES); WRITE_BYTE( bulletType ); MessageEnd(); DoMuzzleFlash(); m_iAmmoCount--; EmitSound( "Weapon_AR2.Single" ); }
/* ================ W_FireShotgun ================ */ void W_FireShotgun() { vec3_t dir; sound( self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM ); g_globalvars.msg_entity = EDICT_TO_PROG( self ); trap_WriteByte( MSG_ONE, SVC_SMALLKICK ); if ( deathmatch != 4 ) self->s.v.currentammo = --( self->s.v.ammo_shells ); //dir = aim (self, 100000); aim( dir ); FireBullets( 6, dir, 0.04, 0.04, 0 ); }
//========================================================= // Shoot //========================================================= void CNPC_HAssassin::Shoot ( void ) { Vector vForward, vRight, vUp; Vector vecShootOrigin; QAngle vAngles; if ( GetEnemy() == NULL) { return; } GetAttachment( "guntip", vecShootOrigin, vAngles ); Vector vecShootDir = GetShootEnemyDir( vecShootOrigin ); if (m_flLastShot + 2 < gpGlobals->curtime) { m_flDiviation = 0.10; } else { m_flDiviation -= 0.01; if (m_flDiviation < 0.02) m_flDiviation = 0.02; } m_flLastShot = gpGlobals->curtime; AngleVectors( GetAbsAngles(), &vForward, &vRight, &vUp ); Vector vecShellVelocity = vRight * random->RandomFloat(40,90) + vUp * random->RandomFloat(75,200) + vForward * random->RandomFloat(-40, 40); EjectShell( GetAbsOrigin() + vUp * 32 + vForward * 12, vecShellVelocity, GetAbsAngles().y, 0 ); FireBullets( 1, vecShootOrigin, vecShootDir, Vector( m_flDiviation, m_flDiviation, m_flDiviation ), 2048, m_iAmmoType ); // shoot +-8 degrees //NDebugOverlay::Line( vecShootOrigin, vecShootOrigin + vecShootDir * 2048, 255, 0, 0, true, 2.0 ); CPASAttenuationFilter filter( this ); EmitSound( filter, entindex(), "HAssassin.Shot" ); DoMuzzleFlash(); VectorAngles( vecShootDir, vAngles ); SetPoseParameter( "shoot", vecShootDir.x ); m_cAmmoLoaded--; }
//========================================================= // Shoot //========================================================= void CHAssassin :: Shoot ( void ) { if (m_hEnemy == NULL) { return; } Vector vecShootOrigin = GetGunPosition(); Vector vecShootDir = ShootAtEnemy( vecShootOrigin ); if (m_flLastShot + 2 < gpGlobals->time) { m_flDiviation = 0.10; } else { m_flDiviation -= 0.01; if (m_flDiviation < 0.02) m_flDiviation = 0.02; } m_flLastShot = gpGlobals->time; UTIL_MakeVectors ( pev->angles ); Vector vecShellVelocity = gpGlobals->v_right * RANDOM_FLOAT(40,90) + gpGlobals->v_up * RANDOM_FLOAT(75,200) + gpGlobals->v_forward * RANDOM_FLOAT(-40, 40); EjectBrass ( pev->origin + gpGlobals->v_up * 32 + gpGlobals->v_forward * 12, vecShellVelocity, pev->angles.y, m_iShell, TE_BOUNCE_SHELL); FireBullets(1, vecShootOrigin, vecShootDir, Vector( m_flDiviation, m_flDiviation, m_flDiviation ), 2048, BULLET_MONSTER_9MM ); // shoot +-8 degrees switch(RANDOM_LONG(0,1)) { case 0: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/pl_gun1.wav", RANDOM_FLOAT(0.6, 0.8), ATTN_NORM); break; case 1: EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/pl_gun2.wav", RANDOM_FLOAT(0.6, 0.8), ATTN_NORM); break; } pev->effects |= EF_MUZZLEFLASH; Vector angDir = UTIL_VecToAngles( vecShootDir ); SetBlending( 0, angDir.x ); m_cAmmoLoaded--; }
/* ================ W_FireSuperShotgun ================ */ void W_FireSuperShotgun() { vec3_t dir; if ( self->s.v.currentammo == 1 ) { W_FireShotgun(); return; } sound( self, CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM ); g_globalvars.msg_entity = EDICT_TO_PROG( self ); trap_WriteByte( MSG_ONE, SVC_BIGKICK ); if ( deathmatch != 4 ) self->s.v.currentammo = self->s.v.ammo_shells = self->s.v.ammo_shells - 2; //dir = aim (self, 100000); aim( dir ); FireBullets( 14, dir, 0.14, 0.08, 0 ); }
//========================================================= // BarneyFirePistol - shoots one round from the pistol at // the enemy barney is facing. //========================================================= void CNPC_HL1Barney::BarneyFirePistol ( void ) { Vector vecShootOrigin; vecShootOrigin = GetAbsOrigin() + Vector( 0, 0, 55 ); Vector vecShootDir = GetShootEnemyDir( vecShootOrigin ); QAngle angDir; VectorAngles( vecShootDir, angDir ); // SetBlending( 0, angDir.x ); DoMuzzleFlash(); FireBullets(1, vecShootOrigin, vecShootDir, VECTOR_CONE_2DEGREES, 1024, m_iAmmoType ); int pitchShift = random->RandomInt( 0, 20 ); // Only shift about half the time if ( pitchShift > 10 ) pitchShift = 0; else pitchShift -= 5; CPASAttenuationFilter filter( this ); EmitSound_t params; params.m_pSoundName = "Barney.FirePistol"; params.m_flVolume = 1; params.m_nChannel= CHAN_WEAPON; params.m_SoundLevel = SNDLVL_NORM; params.m_nPitch = 100 + pitchShift; EmitSound( filter, entindex(), params ); CSoundEnt::InsertSound ( SOUND_COMBAT, GetAbsOrigin(), 384, 0.3 ); // UNDONE: Reload? m_cAmmoLoaded--;// take away a bullet! }
void QUA_helicopter::Dispara(void) { if (m_flWaitAttack<=gpGlobals->curtime) { Vector vecMachineGunShootPos; QAngle vecMachineGunAngles; GetAttachment( m_nMachineGunMuzzleAttachment, vecMachineGunShootPos, vecMachineGunAngles ); Vector vecMachineGunDir = DondeApuntaPlayer() - vecMachineGunShootPos; VectorNormalize(vecMachineGunDir); //AngleVectors( vecMachineGunAngles, &vecMachineGunDir ); // Fire the round FireBulletsInfo_t info; info.m_iShots = 1; info.m_vecSrc = vecMachineGunShootPos; info.m_vecDirShooting = vecMachineGunDir; info.m_vecSpread = VECTOR_CONE_PRECALCULATED; info.m_pAttacker = (CBaseEntity *) m_hPlayer; info.m_flDistance = MAX_TRACE_LENGTH; info.m_iAmmoType = m_iAmmoType; info.m_flDamage = 60; info.m_iPlayerDamage= 60; info.m_iTracerFreq = 1; FireBullets( info ); EntityMessageBegin( this, true ); WRITE_BYTE( HELICOPTER_MSG_MACHINEGUN ); WRITE_VEC3COORD(vecMachineGunShootPos); WRITE_VEC3COORD(vecMachineGunDir); WRITE_VEC3COORD(VECTOR_CONE_PRECALCULATED); WRITE_BYTE( m_iAmmoType ); MessageEnd(); DoMuzzleFlash(); m_iAmmoCount--; // Descontamos ametralladora. EmitSound( "Weapon_AR2.Single" ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CASW_PropJeep::FireCannon( void ) { //Don't fire again if it's been too soon if ( m_flCannonTime > gpGlobals->curtime ) return; if ( m_bUnableToFire ) return; m_flCannonTime = gpGlobals->curtime + 0.2f; m_bCannonCharging = false; //Find the direction the gun is pointing in Vector aimDir; GetCannonAim( &aimDir ); FireBulletsInfo_t info( 1, m_vecGunOrigin, aimDir, VECTOR_CONE_1DEGREES, MAX_TRACE_LENGTH, m_nAmmoType ); info.m_nFlags = FIRE_BULLETS_ALLOW_WATER_SURFACE_IMPACTS; info.m_pAttacker = m_hPlayer; FireBullets( info ); // Register a muzzleflash for the AI if ( m_hPlayer ) { m_hPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 0.5 ); } CPASAttenuationFilter sndFilter( this, "PropJeep.FireCannon" ); EmitSound( sndFilter, entindex(), "PropJeep.FireCannon" ); // make cylinders of gun spin a bit m_nSpinPos += JEEP_GUN_SPIN_RATE; //SetPoseParameter( JEEP_GUN_SPIN, m_nSpinPos ); //FIXME: Don't bother with this for E3, won't look right }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CHLMachineGun::PrimaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) return; // Abort here to handle burst and auto fire modes if ( (UsesClipsForAmmo1() && m_iClip1 == 0) || ( !UsesClipsForAmmo1() && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) ) return; m_nShotsFired++; pPlayer->DoMuzzleFlash(); // To make the firing framerate independent, we may have to fire more than one bullet here on low-framerate systems, // especially if the weapon we're firing has a really fast rate of fire. int iBulletsToFire = 0; float fireRate = GetFireRate(); // MUST call sound before removing a round from the clip of a CHLMachineGun while ( m_flNextPrimaryAttack <= gpGlobals->curtime ) { WeaponSound(SINGLE, m_flNextPrimaryAttack); m_flNextPrimaryAttack = m_flNextPrimaryAttack + fireRate; iBulletsToFire++; } // Make sure we don't fire more than the amount in the clip, if this weapon uses clips if ( UsesClipsForAmmo1() ) { if ( iBulletsToFire > m_iClip1 ) iBulletsToFire = m_iClip1; m_iClip1 -= iBulletsToFire; } m_iPrimaryAttacks++; gamestats->Event_WeaponFired( pPlayer, true, GetClassname() ); // Fire the bullets FireBulletsInfo_t info; info.m_iShots = iBulletsToFire; info.m_vecSrc = pPlayer->Weapon_ShootPosition( ); info.m_vecDirShooting = pPlayer->GetAutoaimVector( AUTOAIM_SCALE_DEFAULT ); info.m_vecSpread = pPlayer->GetAttackSpread( this ); info.m_flDistance = MAX_TRACE_LENGTH; info.m_iAmmoType = m_iPrimaryAmmoType; info.m_iTracerFreq = 2; FireBullets( info ); //Factor in the view kick AddViewKick(); CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_MACHINEGUN, 0.2, pPlayer ); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } SendWeaponAnim( GetPrimaryAttackActivity() ); pPlayer->SetAnimation( PLAYER_ATTACK1 ); // Register a muzzleflash for the AI pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 0.5 ); }
void CTurret::Shoot(Vector &vecSrc, Vector &vecDirToEnemy) { FireBullets( 1, vecSrc, vecDirToEnemy, TURRET_SPREAD, TURRET_RANGE, BULLET_MONSTER_12MM, 1 ); EMIT_SOUND(ENT(pev), CHAN_WEAPON, "turret/tu_fire1.wav", 1, 0.6); pev->effects = pev->effects | EF_MUZZLEFLASH; }
//----------------------------------------------------------------------------- // Fire on our target //----------------------------------------------------------------------------- bool CObjectSentrygun::Fire() { //NDebugOverlay::Cross3D( m_hEnemy->WorldSpaceCenter(), 10, 255, 0, 0, false, 0.1 ); Vector vecAimDir; // Level 3 Turrets fire rockets every 3 seconds if ( m_iUpgradeLevel == 3 && m_iAmmoRockets > 0 && m_flNextRocketAttack < gpGlobals->curtime ) { Vector vecSrc; QAngle vecAng; // alternate between the 2 rocket launcher ports. if ( m_iAmmoRockets & 1 ) { GetAttachment( m_iAttachments[SENTRYGUN_ATTACHMENT_ROCKET_L], vecSrc, vecAng ); } else { GetAttachment( m_iAttachments[SENTRYGUN_ATTACHMENT_ROCKET_R], vecSrc, vecAng ); } vecAimDir = m_hEnemy->WorldSpaceCenter() - vecSrc; vecAimDir.NormalizeInPlace(); // NOTE: vecAng is not actually set by GetAttachment!!! QAngle angDir; VectorAngles( vecAimDir, angDir ); EmitSound( "Building_Sentrygun.FireRocket" ); AddGesture( ACT_RANGE_ATTACK2 ); QAngle angAimDir; VectorAngles( vecAimDir, angAimDir ); CTFProjectile_SentryRocket *pProjectile = CTFProjectile_SentryRocket::Create( vecSrc, angAimDir, this, GetBuilder() ); if ( pProjectile ) { pProjectile->SetDamage( 100 ); } // Setup next rocket shot m_flNextRocketAttack = gpGlobals->curtime + 3; if ( !tf_sentrygun_ammocheat.GetBool() && !HasSpawnFlags( SF_SENTRY_INFINITE_AMMO ) ) { m_iAmmoRockets--; } if (m_iAmmoRockets == 10) ClientPrint( GetBuilder(), HUD_PRINTNOTIFY, "#Sentry_rocketslow"); if (m_iAmmoRockets == 0) ClientPrint( GetBuilder(), HUD_PRINTNOTIFY, "#Sentry_rocketsout"); } // All turrets fire shells if ( m_iAmmoShells > 0) { if ( !IsPlayingGesture( ACT_RANGE_ATTACK1 ) ) { RemoveGesture( ACT_RANGE_ATTACK1_LOW ); AddGesture( ACT_RANGE_ATTACK1 ); } Vector vecSrc; QAngle vecAng; int iAttachment; if ( m_iUpgradeLevel > 1 && (m_iAmmoShells & 1) ) { // level 2 and 3 turrets alternate muzzles each time they fizzy fizzy fire. iAttachment = m_iAttachments[SENTRYGUN_ATTACHMENT_MUZZLE_ALT]; } else { iAttachment = m_iAttachments[SENTRYGUN_ATTACHMENT_MUZZLE]; } GetAttachment( iAttachment, vecSrc, vecAng ); Vector vecMidEnemy = m_hEnemy->WorldSpaceCenter(); // If we cannot see their WorldSpaceCenter ( possible, as we do our target finding based // on the eye position of the target ) then fire at the eye position trace_t tr; UTIL_TraceLine( vecSrc, vecMidEnemy, MASK_SOLID, this, COLLISION_GROUP_NONE, &tr); if ( !tr.m_pEnt || tr.m_pEnt->IsWorld() ) { // Hack it lower a little bit.. // The eye position is not always within the hitboxes for a standing TF Player vecMidEnemy = m_hEnemy->EyePosition() + Vector(0,0,-5); } vecAimDir = vecMidEnemy - vecSrc; float flDistToTarget = vecAimDir.Length(); vecAimDir.NormalizeInPlace(); //NDebugOverlay::Cross3D( vecSrc, 10, 255, 0, 0, false, 0.1 ); FireBulletsInfo_t info; info.m_vecSrc = vecSrc; info.m_vecDirShooting = vecAimDir; info.m_iTracerFreq = 1; info.m_iShots = 1; info.m_pAttacker = GetBuilder(); info.m_vecSpread = vec3_origin; info.m_flDistance = flDistToTarget + 100; info.m_iAmmoType = m_iAmmoType; info.m_flDamage = tf_sentrygun_damage.GetFloat(); FireBullets( info ); //NDebugOverlay::Line( vecSrc, vecSrc + vecAimDir * 1000, 255, 0, 0, false, 0.1 ); CEffectData data; data.m_nEntIndex = entindex(); data.m_nAttachmentIndex = iAttachment; data.m_fFlags = m_iUpgradeLevel; data.m_vOrigin = vecSrc; DispatchEffect( "TF_3rdPersonMuzzleFlash_SentryGun", data ); switch( m_iUpgradeLevel ) { case 1: default: EmitSound( "Building_Sentrygun.Fire" ); break; case 2: EmitSound( "Building_Sentrygun.Fire2" ); break; case 3: EmitSound( "Building_Sentrygun.Fire3" ); break; } if ( !tf_sentrygun_ammocheat.GetBool() && !HasSpawnFlags( SF_SENTRY_INFINITE_AMMO ) ) { m_iAmmoShells--; } } else { if ( m_iUpgradeLevel > 1 ) { if ( !IsPlayingGesture( ACT_RANGE_ATTACK1_LOW ) ) { RemoveGesture( ACT_RANGE_ATTACK1 ); AddGesture( ACT_RANGE_ATTACK1_LOW ); } } // Out of ammo, play a click EmitSound( "Building_Sentrygun.Empty" ); m_flNextAttack = gpGlobals->curtime + 0.2; } return true; }
void CNPC_Portal_GroundTurret::Shoot() { FireBulletsInfo_t info; Vector vecSrc = EyePosition(); Vector vecDir; GetVectors( &vecDir, NULL, NULL ); for( int i = 0 ; i < 1 ; i++ ) { info.m_vecSrc = vecSrc; if( i > 0 || !GetEnemy()->IsPlayer() ) { // Subsequent shots or shots at non-players random GetVectors( &info.m_vecDirShooting, NULL, NULL ); info.m_vecSpread = m_vecSpread; } else { // First shot is at the enemy. info.m_vecDirShooting = GetActualShootTrajectory( vecSrc ); info.m_vecSpread = VECTOR_CONE_PRECALCULATED; } info.m_iTracerFreq = 1; info.m_iShots = 1; info.m_pAttacker = this; info.m_flDistance = MAX_COORD_RANGE; info.m_iAmmoType = m_iAmmoType; FireBullets( info ); trace_t tr; CTraceFilterSkipTwoEntities traceFilter( this, info.m_pAdditionalIgnoreEnt, COLLISION_GROUP_NONE ); Vector vecEnd = info.m_vecSrc + vecDir * info.m_flDistance; AI_TraceLine( info.m_vecSrc, vecEnd, MASK_SHOT, &traceFilter, &tr ); if ( tr.m_pEnt && !tr.m_pEnt->IsPlayer() && ( vecDir * info.m_flDistance * tr.fraction ).Length() < 16.0f ) { CTakeDamageInfo damageInfo; damageInfo.SetAttacker( this ); damageInfo.SetDamageType( DMG_BULLET ); damageInfo.SetDamage( 20.0f ); TakeDamage( damageInfo ); EmitSound( "NPC_FloorTurret.DryFire" ); } } // Do the AR2 muzzle flash CEffectData data; data.m_nEntIndex = entindex(); data.m_nAttachmentIndex = LookupAttachment( "eyes" ); data.m_flScale = 1.0f; data.m_fFlags = MUZZLEFLASH_COMBINE; DispatchEffect( "MuzzleFlash", data ); EmitSound( "NPC_FloorTurret.ShotSounds" ); m_flTimeNextShoot = gpGlobals->curtime + 0.09; }
BOOL CApache :: FireGun( ) { UTIL_MakeAimVectors( pev->angles ); Vector posGun, angGun; GetAttachment( 1, posGun, angGun ); Vector vecTarget = (m_posTarget - posGun).Normalize( ); Vector vecOut; vecOut.x = DotProduct( gpGlobals->v_forward, vecTarget ); vecOut.y = -DotProduct( gpGlobals->v_right, vecTarget ); vecOut.z = DotProduct( gpGlobals->v_up, vecTarget ); Vector angles = UTIL_VecToAngles (vecOut); angles.x = -angles.x; if (angles.y > 180) angles.y = angles.y - 360; if (angles.y < -180) angles.y = angles.y + 360; if (angles.x > 180) angles.x = angles.x - 360; if (angles.x < -180) angles.x = angles.x + 360; if (angles.x > m_angGun.x) m_angGun.x = min( angles.x, m_angGun.x + 12 ); if (angles.x < m_angGun.x) m_angGun.x = max( angles.x, m_angGun.x - 12 ); if (angles.y > m_angGun.y) m_angGun.y = min( angles.y, m_angGun.y + 12 ); if (angles.y < m_angGun.y) m_angGun.y = max( angles.y, m_angGun.y - 12 ); m_angGun.y = SetBoneController( 0, m_angGun.y ); m_angGun.x = SetBoneController( 1, m_angGun.x ); Vector posBarrel, angBarrel; GetAttachment( 0, posBarrel, angBarrel ); Vector vecGun = (posBarrel - posGun).Normalize( ); if (DotProduct( vecGun, vecTarget ) > 0.98) { #if 1 FireBullets( 1, posGun, vecGun, VECTOR_CONE_4DEGREES, 8192, BULLET_MONSTER_12MM, 1 ); EMIT_SOUND(ENT(pev), CHAN_WEAPON, "turret/tu_fire1.wav", 1, 0.3); #else static float flNext; TraceResult tr; UTIL_TraceLine( posGun, posGun + vecGun * 8192, dont_ignore_monsters, ENT( pev ), &tr ); if (!m_pBeam) { m_pBeam = CBeam::BeamCreate( "sprites/lgtning.spr", 80 ); m_pBeam->PointEntInit( pev->origin, entindex( ) ); m_pBeam->SetEndAttachment( 1 ); m_pBeam->SetColor( 255, 180, 96 ); m_pBeam->SetBrightness( 192 ); } if (flNext < gpGlobals->time) { flNext = gpGlobals->time + 0.5; m_pBeam->SetStartPos( tr.vecEndPos ); } #endif return TRUE; } else { if (m_pBeam) { UTIL_Remove( m_pBeam ); m_pBeam = NULL; } } return FALSE; }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CHL2MPMachineGun::PrimaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) return; // Abort here to handle burst and auto fire modes if ( (UsesClipsForAmmo1() && m_iClip1 == 0) || ( !UsesClipsForAmmo1() && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) ) return; m_nShotsFired++; // MUST call sound before removing a round from the clip of a CHLMachineGun // FIXME: only called once, will miss multiple sound events per frame if needed // FIXME: m_flNextPrimaryAttack is always in the past, it's not clear what'll happen with sounds WeaponSound(SINGLE, m_flNextPrimaryAttack); // Msg("%.3f\n", m_flNextPrimaryAttack.Get() ); pPlayer->DoMuzzleFlash(); // To make the firing framerate independent, we may have to fire more than one bullet here on low-framerate systems, // especially if the weapon we're firing has a really fast rate of fire. int iBulletsToFire = 0; float fireRate = GetFireRate(); while ( m_flNextPrimaryAttack <= gpGlobals->curtime ) { m_flNextPrimaryAttack = m_flNextPrimaryAttack + fireRate; iBulletsToFire++; } // Make sure we don't fire more than the amount in the clip, if this weapon uses clips if ( UsesClipsForAmmo1() ) { if ( iBulletsToFire > m_iClip1 ) iBulletsToFire = m_iClip1; m_iClip1 -= iBulletsToFire; } CHL2MP_Player *pHL2MPPlayer = ToHL2MPPlayer( pPlayer ); // Fire the bullets FireBulletsInfo_t info; info.m_iShots = iBulletsToFire; info.m_vecSrc = pHL2MPPlayer->Weapon_ShootPosition( ); info.m_vecDirShooting = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES ); info.m_vecSpread = pHL2MPPlayer->GetAttackSpread( this ); info.m_flDistance = MAX_TRACE_LENGTH; info.m_iAmmoType = m_iPrimaryAmmoType; info.m_iTracerFreq = 2; FireBullets( info ); //Factor in the view kick AddViewKick(); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } SendWeaponAnim( GetPrimaryAttackActivity() ); pPlayer->SetAnimation( PLAYER_ATTACK1 ); }
void C_QUA_Strider::ReceiveMessage( int classID, bf_read &msg ) { if ( classID != GetClientClass()->m_ClassID ) { // message is for subclass BaseClass::ReceiveMessage( classID, msg ); return; } int messageType = msg.ReadByte(); switch( messageType ) { case STRIDER_MSG_STREAKS: { Vector pos; msg.ReadBitVec3Coord( pos ); m_cannonFX.SetRenderOrigin( pos ); m_cannonFX.EffectInit( entindex(), LookupAttachment( "BigGun" ) ); m_cannonFX.LimitTime( STRIDERFX_BIG_SHOT_TIME ); } break; case STRIDER_MSG_BIG_SHOT: { Vector tmp; msg.ReadBitVec3Coord( tmp ); m_cannonFX.SetTime( STRIDERFX_BIG_SHOT_TIME ); m_cannonFX.LimitTime( STRIDERFX_END_ALL_TIME ); } break; case STRIDER_MSG_DEAD: { m_cannonFX.EffectShutdown(); } break; case STRIDER_MSG_MACHINEGUN: { // Necesario en MP, porque si no no se ven las balas. Vector muz,dir,spr; msg.ReadBitVec3Coord( muz ); msg.ReadBitVec3Coord( dir ); msg.ReadBitVec3Coord( spr ); int ammo = msg.ReadByte(); //Warning("x: %f,x: %f,x: %f,ammo: %i",muz.x,dir.x,spr.x,ammo); FireBulletsInfo_t info; info.m_iShots = 1; info.m_vecSrc = muz; info.m_vecDirShooting = dir; info.m_vecSpread = spr; info.m_pAttacker = (C_BaseEntity *) m_hPlayer; info.m_flDistance = MAX_TRACE_LENGTH; info.m_iAmmoType = ammo; info.m_flDamage = 75; info.m_iPlayerDamage = 150; info.m_iTracerFreq = 1; FireBullets(info); CEffectData data; data.m_nAttachmentIndex = LookupAttachment( "MiniGun" ); data.m_hEntity = entindex(); DispatchEffect("QUA_StriderMuzzleFlash",data ); } } }