Exemple #1
0
void CASW_Mine::Explode()
{
	if (asw_debug_mine.GetBool())
		Msg("OMG MINE ASPLODE!\n");
	CASW_Firewall_Piece* pFirewall = (CASW_Firewall_Piece *)CreateEntityByName( "asw_firewall_piece" );	
	if (pFirewall)
	{
		pFirewall->SetAbsAngles( GetAbsAngles() );
		if (GetOwnerEntity())
			Msg("Creating firewall with owner %s\n", GetOwnerEntity()->GetClassname());
		pFirewall->SetOwnerEntity(GetOwnerEntity());
		pFirewall->SetAbsOrigin( GetAbsOrigin() );			

		CASW_Marine *pMarine = dynamic_cast<CASW_Marine*>(GetOwnerEntity());
		if (!pMarine)
		{
			pFirewall->SetSideFire( 3 + m_iExtraFires , 3+ m_iExtraFires );
		}
		else
		{
			int iSideFires = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_MINES_FIRES) + m_iExtraFires;
			float fDuration = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_MINES_DURATION);
			pFirewall->SetSideFire(iSideFires,iSideFires);
			pFirewall->SetDuration(fDuration * m_flDurationScale);
		}

		pFirewall->m_hCreatorWeapon = m_hCreatorWeapon;
		pFirewall->Spawn();
		pFirewall->SetAbsVelocity( vec3_origin );
	}
	EmitSound("ASW_Mine.Explode");	
	UTIL_Remove( this );
}
void CNB_Spend_Skill_Points::OnThink()
{
	BaseClass::OnThink();

	CASW_Marine_Profile *pProfile = Briefing()->GetMarineProfileByProfileIndex( m_nProfileIndex );
	if ( pProfile )
	{
		char imagename[255];
		Q_snprintf( imagename, sizeof(imagename), "briefing/face_%s", pProfile->m_PortraitName );
		m_pSelectedMarine->SetImage( imagename );

		m_pMarineNameLabel->SetText( pProfile->GetShortName() );
		m_pBioLabel->SetText( pProfile->m_Bio );
		int nMouseOverSkill = -1;
		for ( int i = 0; i < NUM_SKILL_PANELS; i++ )
		{
			m_pSkillPanel[ i ]->SetSkillDetails( m_nProfileIndex, i, Briefing()->GetProfileSkillPoints( m_nProfileIndex, i ) );
			m_pSkillPanel[ i ]->m_bSpendPointsMode = true;
			if ( m_pSkillPanel[ i ]->IsCursorOver() )
			{
				nMouseOverSkill = i;
			}
		}	
		if ( nMouseOverSkill != -1 && MarineSkills() )
		{
			ASW_Skill nSkillIndex = pProfile->GetSkillMapping( nMouseOverSkill );		// translate from skill slot to skill index

			m_pSkillTitle->SetText( MarineSkills()->GetSkillName( nSkillIndex ) );
			m_pSkillDescription->SetText( MarineSkills()->GetSkillDescription( nSkillIndex ) );
		}
		m_pSpareSkillPointsLabel->SetText( VarArgs( "%d", Briefing()->GetProfileSkillPoints( m_nProfileIndex, ASW_SKILL_SLOT_SPARE ) ) );
	}
}
const char *CASW_Weapon::GetASWShootSound( int iIndex, int &iPitch )
{
	if ( iIndex == SINGLE || iIndex == SINGLE_NPC )
	{
		iIndex = IsCarriedByLocalPlayer() ? SINGLE : SINGLE_NPC;
	}

	if ( iIndex == WPN_DOUBLE || iIndex == DOUBLE_NPC )
	{
		iIndex = IsCarriedByLocalPlayer() ? WPN_DOUBLE : DOUBLE_NPC;
	}

	if ( iIndex == RELOAD || iIndex == RELOAD_NPC )
	{
		iIndex = IsCarriedByLocalPlayer() ? RELOAD : RELOAD_NPC;

		// play the weapon sound according to marine skill
		int iSkill = MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_RELOADING, ASW_MARINE_SUBSKILL_RELOADING_SOUND);
		switch (iSkill)
		{
		case 5: return GetWpnData().aShootSounds[ FAST_RELOAD ]; break;
		case 4: iPitch = 120; return GetWpnData().aShootSounds[ iIndex ]; break;
		case 3: iPitch = 115; return GetWpnData().aShootSounds[ iIndex ]; break;
		case 2: iPitch = 110; return GetWpnData().aShootSounds[ iIndex ]; break;
		case 1: iPitch = 105; return GetWpnData().aShootSounds[ iIndex ]; break;
		default: return GetWpnData().aShootSounds[ iIndex ]; break;
		};
	}
	return GetShootSound( iIndex );
}
void CASW_Weapon_Hornet_Barrage::FireRocket()
{
	CASW_Player *pPlayer = GetCommander();
	CASW_Marine *pMarine = GetMarine();
	if ( !pPlayer || !pMarine || pMarine->GetHealth() <= 0 )
	{
		m_iRocketsToFire = 0;
		return;
	}

	WeaponSound(SINGLE);

	// tell the marine to tell its weapon to draw the muzzle flash
	pMarine->DoMuzzleFlash();

	pMarine->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN_PRIMARY );

	Vector vecSrc	 = GetRocketFiringPosition();
	m_iRocketsToFire = m_iRocketsToFire.Get() - 1;
	m_flNextLaunchTime = gpGlobals->curtime + m_flFireInterval.Get();

#ifndef CLIENT_DLL
	float fGrenadeDamage = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_HORNET_DMG );

	CASW_Rocket::Create( fGrenadeDamage, vecSrc, GetRocketAngle(), pMarine, this );

	if ( ASWGameRules() )
	{
		ASWGameRules()->m_fLastFireTime = gpGlobals->curtime;
	}

	pMarine->OnWeaponFired( this, 1 );

#endif
}
int CASW_Weapon_Assault_Shotgun::GetNumPellets()
{
	if (GetMarine())
		return MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_VINDICATOR, ASW_MARINE_SUBSKILL_VINDICATOR_PELLETS);

	return GetWeaponInfo()->m_iNumPellets;
}
bool CASW_Weapon::ShouldAlienFlinch(CBaseEntity *pAlien, const CTakeDamageInfo &info)
{
	if (!GetWeaponInfo())
		return false;
	float fFlinchChance = GetWeaponInfo()->m_fFlinchChance;
	CASW_Marine *pMarine = dynamic_cast<CASW_Marine*>(GetOwner());
	if (asw_debug_alien_damage.GetBool())
		Msg("BaseFlinch chance %f ", fFlinchChance);
	if (pMarine && pMarine->GetMarineProfile() && pMarine->GetMarineProfile()->GetMarineClass() == MARINE_CLASS_SPECIAL_WEAPONS)
	{
		// this is a special weapons marine, so we need to add our flinch bonus onto it
		fFlinchChance += GetWeaponInfo()->m_fStoppingPowerFlinchBonus * MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_STOPPING_POWER);
		if (asw_debug_alien_damage.GetBool())
			Msg("Boosted by specialweaps to %f ", fFlinchChance);
	}

	//CALL_ATTRIB_HOOK_FLOAT( fFlinchChance, mod_stopping );

	if (pAlien)
	{
		int iHealth = pAlien->GetHealth();
		int iDamage = info.GetDamage();
		float fAlienHealth = float(iHealth + iDamage) / float(pAlien->GetMaxHealth());
		fFlinchChance *= fAlienHealth;
		if (asw_debug_alien_damage.GetBool())
			Msg("adjusted by alien health (%f) to %f ", fAlienHealth, fFlinchChance);
	}

	float f = random->RandomFloat();
	bool bResult = ( f < fFlinchChance);
	if (asw_debug_alien_damage.GetBool())
		Msg("random float is %f shouldflinch = %d\n", f, bResult);
	return bResult;
}
void CASW_Weapon_Hornet_Barrage::SetRocketsToFire()
{
	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine )
		return;

	m_iRocketsToFire = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_HORNET_COUNT );
}
float CASW_Weapon_Hornet_Barrage::GetRocketFireInterval()
{
	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine )
		return 0.5f;

	return MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_HORNET_INTERVAL );
}
bool CASW_Weapon_Shotgun::ShouldUseFastReloadAnim()
{
	if (GetMarine())
	{
		return (MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_RELOADING) < 1.06f);		
	}
	return true;
}
void CASW_Weapon_Smart_Bomb::SetRocketsToFire()
{
	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine )
		return;

	m_iRocketsToFire = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_SMART_BOMB_COUNT );
}
CASW_AOEGrenade_Projectile* CASW_Weapon_HealGrenade::CreateProjectile( const Vector &vecSrc, const QAngle &angles, const Vector &vecVel, 
																		const AngularImpulse &rotSpeed, CBaseEntity *pOwner )
{
	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine )
		return NULL;

	float flHealAmount = MarineSkills()->GetSkillBasedValueByMarine( pMarine, ASW_MARINE_SKILL_HEALING, ASW_MARINE_SUBSKILL_HEAL_GRENADE_HEAL_AMOUNT );
	float flDuration = 20.0f;
	float flRadius = 100.0f;

	float flHealthPerSecond = 3.0f;
	float flInfestationCureAmount = MarineSkills()->GetSkillBasedValueByMarine( pMarine, ASW_MARINE_SKILL_XENOWOUNDS ) / 100.0f;

	return CASW_HealGrenade_Projectile::Grenade_Projectile_Create( vecSrc, angles, vecVel, rotSpeed, pOwner,
		flHealthPerSecond, flInfestationCureAmount, flRadius, flDuration, flHealAmount );
}
float CASW_Weapon_Smart_Bomb::GetRocketFireInterval()
{
	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine )
		return 0.5f;

	return MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_SMART_BOMB_INTERVAL );
}
void CASW_Weapon_Freeze_Grenades::DelayedAttack( void )
{
	m_bShotDelayed = false;
	
	CASW_Player *pPlayer = GetCommander();
	if ( !pPlayer )
		return;

	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine || pMarine->GetWaterLevel() == 3 )
		return;
	
#ifndef CLIENT_DLL		
	Vector vecSrc = pMarine->GetOffhandThrowSource();

	Vector vecDest = pPlayer->GetCrosshairTracePos();
	Vector newVel = UTIL_LaunchVector( vecSrc, vecDest, GetThrowGravity() ) * 28.0f;
	
	float fGrenadeRadius = GetBoomRadius( pMarine );
	if (asw_debug_marine_damage.GetBool())
	{
		Msg( "Freeze grenade radius = %f \n", fGrenadeRadius );
	}
	pMarine->GetMarineSpeech()->Chatter( CHATTER_GRENADE );

	// freeze aliens completely, plus the freeze duration
	float flFreezeAmount = 1.0f + MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_FREEZE_DURATION);

	if (ASWGameRules())
		ASWGameRules()->m_fLastFireTime = gpGlobals->curtime;

	CASW_Grenade_Freeze *pGrenade = CASW_Grenade_Freeze::Freeze_Grenade_Create( 
		1.0f,
		flFreezeAmount,
		fGrenadeRadius,
		0,
		vecSrc, pMarine->EyeAngles(), newVel, AngularImpulse(0,0,0), pMarine, this );
	if ( pGrenade )
	{
		pGrenade->SetGravity( GetThrowGravity() );
		pGrenade->SetExplodeOnWorldContact( true );
	}
	
#endif
		// decrement ammo
	m_iClip1 -= 1;

#ifndef CLIENT_DLL
	DestroyIfEmpty( true );
#endif

	m_flSoonestPrimaryAttack = gpGlobals->curtime + ASW_FLARES_FASTEST_REFIRE_TIME;
	if (m_iClip1 > 0)		// only force the fire wait time if we have ammo for another shot
		m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate();
	else
		m_flNextPrimaryAttack = gpGlobals->curtime;
}
float CASW_Weapon_Autogun::GetWeaponDamage()
{
	float flDamage = GetWeaponInfo()->m_flBaseDamage;

	if ( GetMarine() )
	{
		flDamage += MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_AUTOGUN, ASW_MARINE_SUBSKILL_AUTOGUN_DMG);
	}

	return flDamage;
}
// traditional Swarm hacking
void CASW_Button_Area::MarineUsing(CASW_Marine* pMarine, float deltatime)
{
	if (m_bIsInUse && m_bIsLocked && ( asw_simple_hacking.GetBool() || !pMarine->IsInhabited() ) )
	{
		float fTime = (deltatime * (1.0f/((float)m_iHackLevel)));
		// boost fTime by the marine's hack skill
		fTime *= MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_HACKING, ASW_MARINE_SUBSKILL_HACKING_SPEED_SCALE);
		fTime *= asw_ai_button_hacking_scale.GetFloat();
		SetHackProgress(m_fHackProgress + fTime, pMarine);
	}
}
float CASW_Weapon_Sniper_Rifle::GetWeaponDamage()
{
	float flDamage = GetWeaponInfo()->m_flBaseDamage;

	if ( GetMarine() )
	{
		flDamage += MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_ACCURACY, ASW_MARINE_SUBSKILL_ACCURACY_SNIPER_RIFLE_DMG);
	}

	return flDamage;
}
	float CASW_Weapon_Medical_Satchel::GetInfestationCureAmount()
	{
		CASW_Marine *pMarine = GetMarine();
		if (!pMarine)
			return 0.0f;		

		float flCureAmount = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_XENOWOUNDS) / 100.0f;

		//CALL_ATTRIB_HOOK_FLOAT( flCureAmount, mod_xenowound_bonus );

		return flCureAmount;
	}
float CASW_Weapon_Minigun::GetMuzzleFlashScale( void )
{
	// if we haven't calculated the muzzle scale based on the carrying marine's skill yet, then do so
	if (m_fMuzzleFlashScale == -1)
	{
		C_ASW_Marine *pMarine = GetMarine();
		if (pMarine)
			m_fMuzzleFlashScale = 2.0f * MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_AUTOGUN, ASW_MARINE_SUBSKILL_AUTOGUN_MUZZLE);
		else
			return 2.0f;
	}
	return m_fMuzzleFlashScale;
}
float CASW_Weapon_Shotgun::GetWeaponDamage()
{
	float flDamage = GetWeaponInfo()->m_flBaseDamage;

	if ( GetMarine() )
	{
		flDamage += MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_ACCURACY, ASW_MARINE_SUBSKILL_ACCURACY_SHOTGUN_DMG);
	}

	//CALL_ATTRIB_HOOK_FLOAT( flDamage, mod_damage_done );

	return flDamage;
}
float CASW_Weapon_Assault_Shotgun::GetMuzzleFlashScale( void )
{
	// if we haven't calculated the muzzle scale based on the carrying marine's skill yet, then do so
	if (m_fMuzzleFlashScale == -1)
	{
		C_ASW_Marine *pMarine = GetMarine();
		if (pMarine)
			m_fMuzzleFlashScale = 1.5f * MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_VINDICATOR, ASW_MARINE_SUBSKILL_VINDICATOR_MUZZLE);
		else
			return 1.5f;
	}
	return m_fMuzzleFlashScale;
}
float CASW_Weapon_Minigun::GetWeaponDamage()
{
	//float flDamage = 7.0f;
	float flDamage = GetWeaponInfo()->m_flBaseDamage;

	if ( GetMarine() )
	{
		flDamage += MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_AUTOGUN, ASW_MARINE_SUBSKILL_AUTOGUN_DMG);
	}

	//CALL_ATTRIB_HOOK_FLOAT( flDamage, mod_damage_done );

	return flDamage;
}
int CASW_Weapon_Medical_Satchel::GetHealAmount()
{
	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine )
	{
		return 0;
	}

	float flHealAmount = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_HEALING, ASW_MARINE_SUBSKILL_HEALING_HPS);

	//CALL_ATTRIB_HOOK_FLOAT( flHealAmount, mod_heal_bonus );

	return flHealAmount;
}
int CASW_Weapon_Medkit::GetHealAmount()
{
	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine )
		return 0;

	// medics adjust heal amount by their skills
	if ( pMarine->GetMarineProfile() && pMarine->GetMarineProfile()->CanUseFirstAid() )
	{
		return MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_HEALING, ASW_MARINE_SUBSKILL_HEALING_MEDKIT_HPS);
	}

	return MEDKIT_HEAL_AMOUNT.GetInt();
}
float CASW_Weapon_Assault_Shotgun::GetWeaponDamage()
{
	//float flDamage = 7.0f;
	float flDamage = GetWeaponInfo()->m_flBaseDamage;

	if ( GetMarine() )
	{
		flDamage += MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_VINDICATOR, ASW_MARINE_SUBSKILL_VINDICATOR_DAMAGE);
	}

	//CALL_ATTRIB_HOOK_FLOAT( flDamage, mod_damage_done );

	return flDamage;
}
void CASW_Weapon_Stim::InjectStim()
{
	CASW_Marine *pMarine = GetMarine();

	if (pMarine)		// firing from a marine
	{
		//make the proper weapon sound
		WeaponSound(SINGLE);
#ifndef CLIENT_DLL
		bool bThisActive = (pMarine->GetActiveASWWeapon() == this);
#endif
		// sets the animation on the weapon model iteself
		SendWeaponAnim( GetPrimaryAttackActivity() );

		// sets the animation on the marine holding this weapon
		//pMarine->SetAnimation( PLAYER_ATTACK1 );
#ifndef CLIENT_DLL

		// make it cause the slow time
		float fDuration = MarineSkills()->GetBestSkillValue( ASW_MARINE_SKILL_DRUGS );
		if (fDuration < 0)
			fDuration = asw_stim_duration.GetFloat();

		//CALL_ATTRIB_HOOK_FLOAT( fDuration, mod_duration );

		ASWGameRules()->StartStim( fDuration, pMarine->GetCommander() );

		pMarine->OnWeaponFired( this, 1 );
#endif
		// decrement ammo
		m_iClip1 -= 1;

		m_flNextPrimaryAttack = gpGlobals->curtime + 4.0f;

		if (!m_iClip1 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0)
		{
			// stim weapon is lost when all stims are gone
#ifndef CLIENT_DLL
			if (pMarine)
			{
				pMarine->Weapon_Detach(this);
				if (bThisActive)
					pMarine->SwitchToNextBestWeapon(NULL);
			}
			Kill();
#endif
		}		
	}
}
float CASW_Weapon::GetReloadTime()
{
	// can adjust for marine's weapon skill here
	float fReloadTime = GetWeaponInfo()->flReloadTime;
	if (GetMarine())
	{
		float fSpeedScale = MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_RELOADING, ASW_MARINE_SUBSKILL_RELOADING_SPEED_SCALE);
		fReloadTime *= fSpeedScale;

		// riflemod: bots reload very fast because they are stupid to die 
		// during long reloads
		if ( !GetMarine()->IsInhabited() )
		{
			fReloadTime = 1.0f; 
		}
	}

	//CALL_ATTRIB_HOOK_FLOAT( fReloadTime, mod_reload_time );

	return fReloadTime;
}
bool CASW_Weapon::ASWReload( int iClipSize1, int iClipSize2, int iActivity )
{
	if ( m_bInReload )	// we're already reloading!
	{
		Msg("ASWReload already reloading\n");
		Assert(false);
		return true;
	}

	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine || !ASWGameRules() )
		return false;

	bool bReload = false;
	if ( m_bIsFiring )
	{
		OnStoppedFiring();
	}

	// If you don't have clips, then don't try to reload them.
	if ( UsesClipsForAmmo1() )
	{
		// need to reload primary clip?
		int primary	= MIN( iClipSize1 - m_iClip1, pMarine->GetAmmoCount( m_iPrimaryAmmoType ) );
		if ( primary != 0 )
		{
			bReload = true;
		}
		else
		{
			// check if we have an ammo bag we can take a clip from instead
			CASW_Weapon_Ammo_Bag* pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>( pMarine->GetASWWeapon( 0 ) );
			if ( !pAmmoBag )
			{
				pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>( pMarine->GetASWWeapon( 1 ) );
			}

			if ( pAmmoBag && pAmmoBag->CanGiveAmmoToWeapon( this ) )
			{
#ifdef CLIENT_DLL
				bReload = true;
#else
				pAmmoBag->GiveClipTo(pMarine, m_iPrimaryAmmoType, true);

				// now we've given a clip, check if we can reload
				primary	= MIN(iClipSize1 - m_iClip1, pMarine->GetAmmoCount(m_iPrimaryAmmoType));
				if ( primary != 0 )
				{
					bReload = true;
				}
#endif
			}
		}
	}

	if ( UsesClipsForAmmo2() )
	{
		// need to reload secondary clip?
		int secondary = MIN( iClipSize2 - m_iClip2, pMarine->GetAmmoCount( m_iSecondaryAmmoType ) );
		if ( secondary != 0 )
		{
			bReload = true;
		}
	}

	if ( !bReload )
		return false;

	m_bFastReloadSuccess = false;
	m_bFastReloadFailure = false;

#ifndef CLIENT_DLL
	if ( GetMaxClip1() > 1 )
	{
		// Fire event when a player reloads a weapon with more than a bullet per clip
		IGameEvent * event = gameeventmanager->CreateEvent( "weapon_reload" );
		if ( event )
		{		
			CASW_Player *pPlayer = NULL;
			pPlayer = pMarine->GetCommander();

			int nClipSize = GetMaxClip1();

			int nClips = pMarine->GetAmmoCount( m_iPrimaryAmmoType ) / nClipSize;
			CASW_Weapon_Ammo_Bag *pAmmoBag = dynamic_cast< CASW_Weapon_Ammo_Bag* >( pMarine->GetASWWeapon( 0 ) );
			if ( !pAmmoBag )
			{
				pAmmoBag = dynamic_cast< CASW_Weapon_Ammo_Bag* >( pMarine->GetASWWeapon( 1 ) );
			}
			if ( pAmmoBag && this != pAmmoBag )
			{
				nClips += pAmmoBag->NumClipsForWeapon( this );					
			}

			event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) );
			event->SetInt( "marine", pMarine->entindex() );
			event->SetInt( "lost", m_iClip1 );
			event->SetInt( "clipsize", nClipSize );
			event->SetInt( "clipsremaining", nClips - 1 );
			event->SetInt( "clipsmax", GetAmmoDef()->MaxCarry( m_iPrimaryAmmoType, pMarine ) / nClipSize );

			gameeventmanager->FireEvent( event );
		}
	}
#endif

	m_fReloadClearFiringTime = gpGlobals->curtime + GetFireRate();

	float fReloadTime = GetReloadTime();
	float flSequenceEndTime = gpGlobals->curtime + fReloadTime;
	pMarine->SetNextAttack( flSequenceEndTime );
	m_flNextPrimaryAttack = m_flNextSecondaryAttack = flSequenceEndTime;
	//Msg("  Setting nextprimary attack time to %f from aswreload\n", m_flNextPrimaryAttack);

	m_bInReload = true;	

	// set fast reload timings
	//  assuming 2.8 base reload time
	//    ~0.29 
	RandomSeed( CBaseEntity::GetPredictionRandomSeed() & 255 );	

	float flStartFraction = random->RandomFloat( 0.29f, 0.35f );

	// set width by difficulty
	float flFastReloadWidth = 0.12f;
	switch( ASWGameRules()->GetSkillLevel() )
	{
		default:
		case 1: 
		case 2: flFastReloadWidth = random->RandomFloat( 0.10f, 0.1f ); break;		// easy/normal
		case 3: flFastReloadWidth = random->RandomFloat( 0.08f, 0.12f ); break;		// hard
		case 4: flFastReloadWidth = random->RandomFloat( 0.06f, 0.10f ); break;		// insane
		case 5: flFastReloadWidth = random->RandomFloat( 0.055f, 0.09f ); break;		// imba
	}
	// scale by marine skills
	flFastReloadWidth *= MarineSkills()->GetSkillBasedValueByMarine( pMarine, ASW_MARINE_SKILL_RELOADING, ASW_MARINE_SUBSKILL_RELOADING_FAST_WIDTH_SCALE );
	
	m_fReloadStart = gpGlobals->curtime;
	m_fFastReloadStart = gpGlobals->curtime + flStartFraction * fReloadTime;
	m_fFastReloadEnd = m_fFastReloadStart + flFastReloadWidth * fReloadTime;

	SendReloadEvents();

#ifdef GAME_DLL
	pMarine->RemoveWeaponPowerup( this );
#endif

	return true;
}
void CASW_Weapon_Flechette::PrimaryAttack()
{
	// If my clip is empty (and I use clips) start reload
	if ( UsesClipsForAmmo1() && !m_iClip1 ) 
	{		
		Reload();
		return;
	}

	CASW_Player *pPlayer = GetCommander();
	CASW_Marine *pMarine = GetMarine();

	if (pMarine)		// firing from a marine
	{
		m_bIsFiring = true;

		// MUST call sound before removing a round from the clip of a CMachineGun
		WeaponSound(SINGLE);

		if (m_iClip1 <= AmmoClickPoint())
		{
			LowAmmoSound();
		}

		// tell the marine to tell its weapon to draw the muzzle flash
		pMarine->DoMuzzleFlash();

		// sets the animation on the weapon model iteself
		SendWeaponAnim( GetPrimaryAttackActivity() );

		Vector vecDir;
		Vector vecSrc	 = pMarine->Weapon_ShootPosition( );
		if ( pPlayer && pMarine->IsInhabited() )
		{
			vecDir = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount());	// 45 degrees = 0.707106781187
		}
		else
		{
#ifdef CLIENT_DLL
			Msg("Error, clientside firing of a weapon that's being controlled by an AI marine\n");
#else
			vecDir = pMarine->GetActualShootTrajectory( vecSrc );
#endif
		}
		
		int iShots = 1;

		// Make sure we don't fire more than the amount in the clip
		if ( UsesClipsForAmmo1() )
		{
			iShots = MIN( iShots, m_iClip1 );
			m_iClip1 -= iShots;

#ifdef GAME_DLL
			CASW_Marine *pMarine = GetMarine();
			if (pMarine && m_iClip1 <= 0 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
			{
				pMarine->OnWeaponOutOfAmmo(true);
			}
#endif
			

		}
		else
		{
			iShots = MIN( iShots, pMarine->GetAmmoCount( m_iPrimaryAmmoType ) );
			pMarine->RemoveAmmo( iShots, m_iPrimaryAmmoType );
		}

/*#ifndef CLIENT_DLL
		if (asw_debug_marine_damage.GetBool())
			Msg("Weapon dmg = %d\n", info.m_flDamage);
		info.m_flDamage *= pMarine->GetMarineResource()->OnFired_GetDamageScale();
#endif*/
				
		// increment shooting stats
#ifndef CLIENT_DLL
		float fGrenadeDamage = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_FLECHETTE_DMG);

		QAngle vecRocketAngle;
		VectorAngles(vecDir, vecRocketAngle);
		vecRocketAngle[YAW] += random->RandomFloat(-10, 10);
		CASW_Rocket::Create(fGrenadeDamage, vecSrc, vecRocketAngle, GetMarine());

		if (pMarine && pMarine->GetMarineResource())
		{
			pMarine->GetMarineResource()->UsedWeapon(this, iShots);
			pMarine->OnWeaponFired( this, iShots );
		}

		if (ASWGameRules())
			ASWGameRules()->m_fLastFireTime = gpGlobals->curtime;
#endif
		m_flNextPrimaryAttack = m_flNextPrimaryAttack + GetFireRate();
	}	
}
void CASW_Weapon_Welder::ItemPostFrame()
{
#ifndef CLIENT_DLL
	CASW_Marine *pMarine = GetMarine();
	if ( !pMarine || !pMarine->GetCommander() )
	{
		if ( m_bPlayingWelderSound )
		{
			m_bIsFiring = false;

			if ( pMarine->GetMarineResource() )
			{
				pMarine->GetMarineResource()->m_hWeldingDoor = NULL;
			}

			m_pWeldDoor = NULL;

			pMarine->OnWeldFinished();
			//Msg( "Clearing weld door as no marine\n" );
		}
		return BaseItemPostFrame();
	}

	if ( m_fWeldTime > 0 && m_pWeldDoor )
	{
		m_fWeldTime -= gpGlobals->frametime;

		if ( m_fWeldTime <= 0 )
		{
			m_bIsFiring = false;
			if ( pMarine->GetMarineResource() )
			{
				pMarine->GetMarineResource()->m_hWeldingDoor = NULL;
			}
		}

		float fSkillScale = MarineSkills()->GetHighestSkillValueNearby(pMarine->GetAbsOrigin(), ENGINEERING_AURA_RADIUS,
				ASW_MARINE_SKILL_ENGINEERING, ASW_MARINE_SUBSKILL_ENGINEERING_WELDING);

		CASW_Marine *pSkillMarine = MarineSkills()->GetLastSkillMarine();		
		if ( fSkillScale > 0.0f && pSkillMarine && pSkillMarine->GetMarineResource() )
		{
			pSkillMarine->m_fUsingEngineeringAura = gpGlobals->curtime;
			m_pWeldDoor->m_fSkillMarineHelping = gpGlobals->curtime;
		}
		else
		{
			m_pWeldDoor->m_fSkillMarineHelping = 0;
		}

		if ( fSkillScale < 1.0 )
		{
			fSkillScale = 0.6f;
		}

		float fSealAmount = gpGlobals->frametime * fSkillScale;
		m_pWeldDoor->WeldDoor( m_bWeldSeal, fSealAmount, pMarine );		// if the door is shut, we can weld
	}
#else
	if ( m_fWeldTime > 0 )
	{
		m_fWeldTime -= gpGlobals->frametime;
		if ( m_fWeldTime <= 0 )
		{
			m_bIsFiring = false;
		}
	}
#endif

	// check for ending automatic welding
	if ( m_bShotDelayed )
	{
		if ( m_pWeldDoor )
		{
			if ( ( m_iAutomaticWeldDirection > 0 && m_pWeldDoor->GetSealAmount() >= 1.0f ) ||
				 ( m_iAutomaticWeldDirection < 0 && m_pWeldDoor->GetSealAmount() <= 0.0f ) )
			{
				m_bShotDelayed = false;
#ifdef GAME_DLL
				if ( pMarine->GetMarineResource() )
				{
					pMarine->GetMarineResource()->m_hWeldingDoor = NULL;
				}
				m_pWeldDoor = NULL;
				pMarine->OnWeldFinished();
#endif
				m_bIsFiring = false;
			}
		}
		else
		{
			if ( !FindDoor() )
			{
				m_bShotDelayed = false;
#ifdef GAME_DLL
				if ( pMarine->GetMarineResource() )
				{
					pMarine->GetMarineResource()->m_hWeldingDoor = NULL;
				}
				m_pWeldDoor = NULL;
				pMarine->OnWeldFinished();
#endif
				m_bIsFiring = false;
			}
		}
	}

	BaseItemPostFrame();
}
Exemple #30
0
void CNB_Skill_Panel::OnThink()
{
	BaseClass::OnThink();

	if ( !MarineSkills() || !Briefing() )
		return;

	CASW_Marine_Profile *pProfile = Briefing()->GetMarineProfileByProfileIndex( m_nProfileIndex );
	if ( !pProfile )
		return;

	int nMaxSkillPoints = MarineSkills()->GetMaxSkillPoints( pProfile->GetSkillMapping( m_nSkillSlot ) );
	const char *szImageName = MarineSkills()->GetSkillImage( pProfile->GetSkillMapping( m_nSkillSlot ) );
	if ( Q_strcmp( m_szLastSkillImage, szImageName ) )
	{
		Q_snprintf( m_szLastSkillImage, sizeof( m_szLastSkillImage ), "%s", szImageName );
		char buffer[ 256 ];
		Q_snprintf( buffer, sizeof( buffer ), "vgui/%s", szImageName );
		
		color32 white;
		white.r = 255;
		white.g = 255;
		white.b = 255;
		white.a = 255;

		color32 dull;
		dull.r = 192;
		dull.g = 192;
		dull.b = 192;
		dull.a = 255;

		m_pSkillButton->SetImage( CBitmapButton::BUTTON_ENABLED, buffer, white );
		m_pSkillButton->SetImage( CBitmapButton::BUTTON_DISABLED, buffer, dull );
		m_pSkillButton->SetImage( CBitmapButton::BUTTON_PRESSED, buffer, white );

		Q_snprintf( buffer, sizeof( buffer ), "vgui/%s_over", szImageName );
		m_pSkillButton->SetImage( CBitmapButton::BUTTON_ENABLED_MOUSE_OVER, buffer, white );		
	}
	m_pSkillButton->SetEnabled( m_bSpendPointsMode && CanSpendPoint() );

	m_pSkillLabel->SetText( MarineSkills()->GetSkillName( pProfile->GetSkillMapping( m_nSkillSlot ) ) );

	wchar_t wszPointsBuffer[ 24 ];
	_snwprintf( wszPointsBuffer, sizeof( wszPointsBuffer ), L"%d / %d", m_nSkillPoints, nMaxSkillPoints );
	m_pSkillNumberLabel->SetText( wszPointsBuffer );

	m_pSkillBar->ClearMinMax();
	m_pSkillBar->AddMinMax( 0, nMaxSkillPoints );
	m_pSkillBar->Init( m_nSkillPoints, m_nSkillPoints, 0.1f, true, false );

	if ( IsCursorOver() )
	{
		if (!g_hBriefingTooltip.Get())
		{
			g_hBriefingTooltip = new BriefingTooltip(GetParent(), "MedalsTooltip");
		}	
		else if ( g_hBriefingTooltip->GetParent() != GetParent() )
		{
			g_hBriefingTooltip->SetParent( GetParent() );
		}

		if ( g_hBriefingTooltip.Get() && IsFullyVisible() &&
			g_hBriefingTooltip.Get()->GetTooltipPanel() != this )
		{	
			int tx, ty, w, h;
			tx = ty = 0;
			LocalToScreen(tx, ty);
			GetSize(w, h);
			tx += w * 0.5f;
			ty -= h * 0.01f;

			g_hBriefingTooltip.Get()->SetTooltip( this, MarineSkills()->GetSkillName( pProfile->GetSkillMapping( m_nSkillSlot ) ), MarineSkills()->GetSkillDescription( pProfile->GetSkillMapping( m_nSkillSlot ) ),
				tx, ty );
		}
	}
}